diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 9dcba514ae19d5868207c600dbc3b06d066694fb..2e6c300d004594b3a9b054ff057f381a40e5a5eb 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -1,7 +1,7 @@ <?php /* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> * Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com> - * Copyright (C) 2013-2014 Alexandre Spangaro <alexandre.spangaro@gmail.com> + * Copyright (C) 2013-2015 Alexandre Spangaro <alexandre.spangaro@gmail.com> * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro> * * This program is free software; you can redistribute it and/or modify @@ -225,6 +225,8 @@ class BookKeeping */ function create($user='') { + global $conf; + $this->piece_num = 0; // first check if line not yet in bookkeeping @@ -278,13 +280,45 @@ class BookKeeping $this->date_create = $now; } - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_bookkeeping (doc_date, "; - $sql .= "doc_type, doc_ref,fk_doc,fk_docdet,code_tiers,numero_compte,label_compte,"; - $sql .= "debit,credit,montant,sens,fk_user_author,import_key,code_journal,piece_num)"; - $sql .= " VALUES ('" . $this->doc_date . "','" . $this->doc_type . "','" . $this->doc_ref . "'," . $this->fk_doc . ","; - $sql .= $this->fk_docdet . ",'" . $this->code_tiers . "','" . $this->numero_compte . "','" . $this->db->escape($this->label_compte) . "',"; - $sql .= $this->debit . "," . $this->credit . "," . $this->montant . ",'" . $this->sens . "'," . $user->id . ", '"; - $sql .= $this->date_create . "','" . $this->code_journal . "'," . $this->piece_num . ")"; + $sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_bookkeeping ("; + + $sql .= "doc_date"; + $sql .= ", doc_type"; + $sql .= ", doc_ref"; + $sql .= ", fk_doc"; + $sql .= ", fk_docdet"; + $sql .= ", code_tiers"; + $sql .= ", numero_compte"; + $sql .= ", label_compte"; + $sql .= ", debit"; + $sql .= ", credit"; + $sql .= ", montant"; + $sql .= ", sens"; + $sql .= ", fk_user_author"; + $sql .= ", import_key"; + $sql .= ", code_journal"; + $sql .= ", piece_num"; + + $sql .= ") VALUES ("; + + $sql .= "'" . $this->doc_date . "'"; + $sql .= ",'" . $this->doc_type . "'"; + $sql .= ",'" . $this->doc_ref . "'"; + $sql .= "," . $this->fk_doc; + $sql .= "," . $this->fk_docdet; + $sql .= ",'" . $this->code_tiers . "'"; + $sql .= ",'" . $this->numero_compte . "'"; + $sql .= ",'" . $this->db->escape($this->label_compte) . "'"; + $sql .= "," . $this->debit; + $sql .= "," . $this->credit; + $sql .= "," . $this->montant; + $sql .= ",'" . $this->sens . "'"; + $sql .= ",'" . $this->fk_user_author."'"; + $sql .= ",'" . $this->date_create . "'"; + $sql .= ",'" . $this->code_journal . "'"; + $sql .= "," . $this->piece_num; + + $sql .= ")"; dol_syslog(get_class($this) . ":: create sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); @@ -296,19 +330,19 @@ class BookKeeping $result = 0; } else { $result = - 2; - dol_syslog("BookKeeping::Create Erreur $result lecture ID"); + dol_syslog("BookKeeping::Create Error $result lecture ID"); } } else { $result = - 1; - dol_syslog("BookKeeping::Create Erreur $result INSERT Mysql"); + dol_syslog("BookKeeping::Create Error $result INSERT Mysql"); } } else { $result = - 3; - dol_syslog("BookKeeping::Create Erreur $result SELECT Mysql"); + dol_syslog("BookKeeping::Create Error $result SELECT Mysql"); } } else { $result = - 5; - dol_syslog("BookKeeping::Create Erreur $result SELECT Mysql"); + dol_syslog("BookKeeping::Create Error $result SELECT Mysql"); } return $result; diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index 8125f6ef14d2177da5fc93af2f690d97950e01ba..c97cde97b1409278fc751cc1f1a4dd318344af19 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -286,6 +286,7 @@ if ($action == 'writeBookKeeping') $bookkeeping->debit = ($mt >= 0 ? $mt : 0); $bookkeeping->credit = ($mt < 0 ? - $mt : 0); $bookkeeping->code_journal = $conf->global->ACCOUNTING_BANK_JOURNAL; + $bookkeeping->fk_user_author = $user->id; if ($tabtype[$key] == 'payment') { @@ -336,6 +337,7 @@ if ($action == 'writeBookKeeping') $bookkeeping->debit = ($mt < 0 ? - $mt : 0); $bookkeeping->credit = ($mt >= 0) ? $mt : 0; $bookkeeping->code_journal = $conf->global->ACCOUNTING_BANK_JOURNAL; + $bookkeeping->fk_user_author = $user->id; if ($tabtype[$key] == 'sc') { $bookkeeping->code_tiers = ''; @@ -400,7 +402,7 @@ if ($action == 'writeBookKeeping') } if (empty($error)) { - setEventMessage($langs->trans('Success'), 'mesgs'); + setEventMessage($langs->trans("GeneralLedgerIsWritten"),'mesgs'); } } // Export diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php index 8b9b7929db85ab9e74080d1e624ed8555660946d..14e77e20f3f39d6c8fe1c7fcaba2849c53253e6c 100644 --- a/htdocs/accountancy/journal/purchasesjournal.php +++ b/htdocs/accountancy/journal/purchasesjournal.php @@ -157,6 +157,7 @@ if ($result) { // Bookkeeping Write if ($action == 'writebookkeeping') { $now = dol_now(); + $error = 0; foreach ( $tabfac as $key => $val ) { foreach ( $tabttc[$key] as $k => $mt ) { @@ -177,8 +178,13 @@ if ($action == 'writebookkeeping') { $bookkeeping->debit = ($mt <= 0) ? $mt : 0; $bookkeeping->credit = ($mt > 0) ? $mt : 0; $bookkeeping->code_journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL; + $bookkeeping->fk_user_author = $user->id; - $bookkeeping->create(); + $result = $bookkeeping->create(); + if ($result < 0) { + $error ++; + setEventMessage($object->errors, 'errors'); + } } // Product / Service @@ -202,8 +208,13 @@ if ($action == 'writebookkeeping') { $bookkeeping->debit = ($mt > 0) ? $mt : 0; $bookkeeping->credit = ($mt <= 0) ? $mt : 0; $bookkeeping->code_journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL; + $bookkeeping->fk_user_author = $user->id; - $bookkeeping->create(); + $result = $bookkeeping->create(); + if ($result < 0) { + $error ++; + setEventMessage($object->errors, 'errors'); + } } } } @@ -228,11 +239,20 @@ if ($action == 'writebookkeeping') { $bookkeeping->debit = ($mt > 0) ? $mt : 0; $bookkeeping->credit = ($mt <= 0) ? $mt : 0; $bookkeeping->code_journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL; + $bookkeeping->fk_user_author = $user->id; - $bookkeeping->create(); + $result = $bookkeeping->create(); + if ($result < 0) { + $error ++; + setEventMessage($object->errors, 'errors'); + } } } } + + if (empty($error)) { + setEventMessage($langs->trans("GeneralLedgerIsWritten"),'mesgs'); + } } diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php index d80e8f3656289b8a9670a509fc369988b979c9bc..9eb6d67f56be2343c49967f6ac97ed3deacd7e4d 100644 --- a/htdocs/accountancy/journal/sellsjournal.php +++ b/htdocs/accountancy/journal/sellsjournal.php @@ -170,6 +170,7 @@ if ($result) { // Bookkeeping Write if ($action == 'writebookkeeping') { $now = dol_now(); + $error = 0; foreach ( $tabfac as $key => $val ) { foreach ( $tabttc[$key] as $k => $mt ) { @@ -188,8 +189,13 @@ if ($action == 'writebookkeeping') { $bookkeeping->debit = ($mt >= 0) ? $mt : 0; $bookkeeping->credit = ($mt < 0) ? $mt : 0; $bookkeeping->code_journal = $conf->global->ACCOUNTING_SELL_JOURNAL; + $bookkeeping->fk_user_author = $user->id; - $bookkeeping->create(); + $result = $bookkeeping->create(); + if ($result < 0) { + $error ++; + setEventMessage($object->errors, 'errors'); + } } // Product / Service @@ -213,8 +219,13 @@ if ($action == 'writebookkeeping') { $bookkeeping->debit = ($mt < 0) ? $mt : 0; $bookkeeping->credit = ($mt >= 0) ? $mt : 0; $bookkeeping->code_journal = $conf->global->ACCOUNTING_SELL_JOURNAL; + $bookkeeping->fk_user_author = $user->id; - $bookkeeping->create(); + $result = $bookkeeping->create(); + if ($result < 0) { + $error ++; + setEventMessage($object->errors, 'errors'); + } } } } @@ -238,11 +249,20 @@ if ($action == 'writebookkeeping') { $bookkeeping->debit = ($mt < 0) ? $mt : 0; $bookkeeping->credit = ($mt >= 0) ? $mt : 0; $bookkeeping->code_journal = $conf->global->ACCOUNTING_SELL_JOURNAL; + $bookkeeping->fk_user_author = $user->id; - $bookkeeping->create(); + $result = $bookkeeping->create(); + if ($result < 0) { + $error ++; + setEventMessage($object->errors, 'errors'); + } } } } + + if (empty($error)) { + setEventMessage($langs->trans("GeneralLedgerIsWritten"),'mesgs'); + } } // Export if ($action == 'export_csv') { diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index b09dab7f7645a53dd4fe777216189f054c8b221a..57ce6b09201f613ca88b94de23ce8a57f8a70420 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -157,4 +157,5 @@ ValidateHistory=Validate Automatically ErrorAccountancyCodeIsAlreadyUse=Error, you cannot delete this accounting account because it is used -FicheVentilation=Breakdown card \ No newline at end of file +FicheVentilation=Breakdown card +GeneralLedgerIsWritten=Operations are written in the general ledger \ No newline at end of file