From 8edf3c65c6ba67a532c300b411f0de178b6762ae Mon Sep 17 00:00:00 2001 From: Florian HENRY <florian.henry@open-concept.pro> Date: Fri, 11 Dec 2015 11:46:22 +0100 Subject: [PATCH] work on accounting --- htdocs/accountancy/admin/account.php | 4 +-- htdocs/accountancy/admin/card.php | 4 +-- htdocs/accountancy/bookkeeping/list.php | 31 +++++++++++++++++-- htdocs/accountancy/customer/list.php | 15 ++++----- htdocs/accountancy/journal/bankjournal.php | 30 +++++++++++------- .../accountancy/journal/purchasesjournal.php | 12 +++---- htdocs/accountancy/journal/sellsjournal.php | 8 ++--- htdocs/accountancy/supplier/list.php | 4 +-- 8 files changed, 71 insertions(+), 37 deletions(-) diff --git a/htdocs/accountancy/admin/account.php b/htdocs/accountancy/admin/account.php index 0bf37a7753e..c46e07893a3 100644 --- a/htdocs/accountancy/admin/account.php +++ b/htdocs/accountancy/admin/account.php @@ -76,7 +76,7 @@ if ($action == 'disable') { $action = 'update'; if ($result < 0) { - setEventMessage($accounting->error, 'errors'); + setEventMessages($accounting->error, $accounting->errors, 'errors'); } } else if ($action == 'enable') { if ($accounting->fetch($id)) { @@ -84,7 +84,7 @@ if ($action == 'disable') { } $action = 'update'; if ($result < 0) { - setEventMessage($accounting->error, 'errors'); + setEventMessages($accounting->error, $accounting->errors, 'errors'); } } diff --git a/htdocs/accountancy/admin/card.php b/htdocs/accountancy/admin/card.php index 51c6a5c6715..99eb49949e7 100644 --- a/htdocs/accountancy/admin/card.php +++ b/htdocs/accountancy/admin/card.php @@ -125,7 +125,7 @@ else if ($action == 'delete') } if ($result < 0) { - setEventMessage($accounting->error, 'errors'); + setEventMessages($accounting->error, $accounting->errors, 'errors'); } } @@ -139,7 +139,7 @@ $htmlacc = new FormVentilation($db); if ($action == 'create') { - print_fiche_titre($langs->trans('NewAccount')); + print load_fiche_titre($langs->trans('NewAccount')); print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n"; print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index d9b6d66b503..851b095baff 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -30,6 +30,7 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; require_once DOL_DOCUMENT_ROOT.'/accountancy/class/html.formventilation.class.php'; require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; // Langs $langs->load("accountancy"); @@ -52,6 +53,7 @@ if ($sortfield == "") $offset = $conf->liste_limit * $page; $formventilation = new FormVentilation($db); +$formother = new FormOther($db); if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers { @@ -74,7 +76,20 @@ if ($action == 'delbookkeeping') { $result = $object->delete_by_importkey($import_key); Header("Location: list.php"); if ($result < 0) { - setEventMessage($object->errors, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); + } + } +} +elseif ($action == 'delbookkeepingyear') { + + $delyear = GETPOST('delyear', 'int'); + + if (! empty($delyear)) { + $object = new BookKeeping($db); + $result = $object->delete_by_year($delyear); + Header("Location: list.php"); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); } } } // Export @@ -86,7 +101,7 @@ else if ($action == 'export_csv') { $object = new BookKeeping($db); $result = $object->export_bookkeping('ebp'); if ($result < 0) { - setEventMessage($object->errors, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } foreach ( $object->linesexport as $line ) { @@ -147,7 +162,7 @@ else { print_barre_liste($langs->trans("Bookkeeping"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num); - print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">'; + /*print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">'; print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; print '<input type="hidden" name="action" value="delbookkeeping">'; @@ -155,6 +170,16 @@ else { print '<div class="inline-block divButAction"><input type="submit" class="butAction" value="' . $langs->trans("DelBookKeeping") . '" /></div>'; + print '</form>';*/ + + print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">'; + print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; + print '<input type="hidden" name="action" value="delbookkeepingyear">'; + + print $formother->select_year(GETPOST('delyear'),'delyear'); + + print '<div class="inline-block divButAction"><input type="submit" class="butAction" value="' . $langs->trans("DelBookKeeping") . '" /></div>'; + print '</form>'; print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">'; diff --git a/htdocs/accountancy/customer/list.php b/htdocs/accountancy/customer/list.php index c03afd3bcde..321bc5b483b 100644 --- a/htdocs/accountancy/customer/list.php +++ b/htdocs/accountancy/customer/list.php @@ -87,10 +87,9 @@ if (! $user->rights->accounting->ventilation->dispatch) accessforbidden(); $formventilation = new FormVentilation($db); - $accounting = new AccountingAccount($db); -$aarowid_s = $accounting->fetch('', ACCOUNTING_SERVICE_SOLD_ACCOUNT); -$aarowid_p = $accounting->fetch('', ACCOUNTING_PRODUCT_SOLD_ACCOUNT); +$aarowid_s = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT,1); +$aarowid_p = $accounting->fetch('',$conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT,1); // Purge search criteria if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) { @@ -242,7 +241,7 @@ if ($result) { print_liste_field_titre($langs->trans("Description"), $_SERVER["PHP_SELF"], "l.description", "", $param, '', $sortfield, $sortorder); print_liste_field_titre($langs->trans("Amount"), $_SERVER["PHP_SELF"],"l.total_ht","",$param,'align="center"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("VATRate"), $_SERVER["PHP_SELF"], "l.tva_tx", "", $param, 'align="center"', $sortfield, $sortorder); - print_liste_field_titre($langs->trans("AccountAccounting"), '', '', '', '', 'align="center"'); + print_liste_field_titre($langs->trans("AccountAccountingSuggest"), '', '', '', '', 'align="center"'); print_liste_field_titre($langs->trans("IntoAccount"), '', '', '', '', 'align="center"'); print_liste_field_titre(''); print_liste_field_titre($langs->trans("Ventilate") . '<br><label id="select-all">' . $langs->trans('All') . '</label>/<label id="unselect-all">' . $langs->trans('None') . '</label>', '', '', '', '', 'align="center"'); @@ -292,12 +291,14 @@ if ($result) { } if ($objp->type_l == 1) { $objp->code_sell_l = (! empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef")); - if ($objp->aarowid == '') + if ($objp->aarowid == '') { $objp->aarowid_suggest = $aarowid_s; + } } elseif ($objp->type_l == 0) { $objp->code_sell_l = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans("CodeNotDef")); - if ($objp->aarowid == '') + if ($objp->aarowid == '') { $objp->aarowid_suggest = $aarowid_p; + } } if ($objp->code_sell_l != $objp->code_sell_p) $code_sell_p_l_differ = 'color:red'; @@ -333,7 +334,7 @@ if ($result) { if ($objp->code_sell_l == $objp->code_sell_p) { print $objp->code_sell_l; } else { - print 'lines=' . $objp->code_sell_l . '<br />product=' . $objp->code_sell_p; + print $langs->trans("Purchase") . ' = ' . $objp->code_sell_l . '<br />' . $langs->trans("Sell") . ' = ' . $objp->code_sell_p; } print '</td>'; diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index b08391495c1..0f08c38ad65 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -25,7 +25,7 @@ /** * \file htdocs/accountancy/journal/bankjournal.php * \ingroup Accounting Expert - * \brief Page with sells journal + * \brief Page with bank journal */ require '../../main.inc.php'; @@ -66,6 +66,8 @@ $date_endday = GETPOST('date_endday'); $date_endyear = GETPOST('date_endyear'); $action = GETPOST('action'); +$now = dol_now(); + // Security check if ($user->societe_id > 0 && empty($id_bank_account)) accessforbidden(); @@ -121,7 +123,7 @@ $bank_code_journal = new Account($db); $result=$bank_code_journal->fetch($id_bank_account); $journal=$bank_code_journal->accountancy_journal; -dol_syslog("accountancy/journal/bankjournal.php:: sql=" . $sql, LOG_DEBUG); +dol_syslog("accountancy/journal/bankjournal.php", LOG_DEBUG); $result = $db->query($sql); if ($result) { @@ -280,6 +282,8 @@ if ($result) { // Write bookkeeping if ($action == 'writebookkeeping') { + $now=dol_now(); + $error = 0; foreach ( $tabpay as $key => $val ) { @@ -301,6 +305,7 @@ if ($action == 'writebookkeeping') $bookkeeping->credit = ($mt < 0 ? - $mt : 0); $bookkeeping->code_journal = $journal; $bookkeeping->fk_user_author = $user->id; + $bookkeeping->date_create=$now; if ($tabtype[$key] == 'payment') { @@ -317,7 +322,7 @@ if ($action == 'writebookkeeping') } } else if ($tabtype[$key] == 'payment_supplier') { - $sqlmid = 'SELECT facf.facnumber'; + $sqlmid = 'SELECT facf.ref_supplier,facf.ref'; $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf "; $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid"; $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid"; @@ -326,14 +331,14 @@ if ($action == 'writebookkeeping') $resultmid = $db->query($sqlmid); if ($resultmid) { $objmid = $db->fetch_object($resultmid); - $bookkeeping->doc_ref = $objmid->facnumber; + $bookkeeping->doc_ref = $objmid->ref_supplier.' ('.$objmid->ref.')';; } } $result = $bookkeeping->create(); if ($result < 0) { $error ++; - setEventMessage($object->errors, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } // Third party @@ -352,6 +357,7 @@ if ($action == 'writebookkeeping') $bookkeeping->credit = ($mt >= 0) ? $mt : 0; $bookkeeping->code_journal = $journal; $bookkeeping->fk_user_author = $user->id; + $bookkeeping->date_create=$now; if ($tabtype[$key] == 'sc') { $bookkeeping->code_tiers = ''; @@ -373,7 +379,7 @@ if ($action == 'writebookkeeping') $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER; } else if ($tabtype[$key] == 'payment_supplier') { - $sqlmid = 'SELECT facf.facnumber'; + $sqlmid = 'SELECT facf.ref_supplier,facf.ref'; $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf "; $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid"; $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid"; @@ -382,7 +388,7 @@ if ($action == 'writebookkeeping') $resultmid = $db->query($sqlmid); if ($resultmid) { $objmid = $db->fetch_object($resultmid); - $bookkeeping->doc_ref = $objmid->facnumber; + $bookkeeping->doc_ref = $objmid->ref_supplier.' ('.$objmid->ref.')'; } $bookkeeping->code_tiers = $k; $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER; @@ -410,17 +416,18 @@ if ($action == 'writebookkeeping') $result = $bookkeeping->create(); if ($result < 0) { $error ++; - setEventMessage($object->errors, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } } if (empty($error)) { - setEventMessage($langs->trans("GeneralLedgerIsWritten"),'mesgs'); + setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs'); } } // Export -if ($action == 'export_csv') { +if ($action == 'export_csv') +{ $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; header('Content-Type: text/csv'); @@ -497,7 +504,8 @@ if ($action == 'export_csv') { } } } - } else { // Model Classic Export + } else // Model Classic Export + { foreach ( $tabpay as $key => $val ) { $date = dol_print_date($db->jdate($val["date"]), 'day'); diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php index 5844700748a..90443eb4bc1 100644 --- a/htdocs/accountancy/journal/purchasesjournal.php +++ b/htdocs/accountancy/journal/purchasesjournal.php @@ -84,7 +84,7 @@ if (empty($date_start) || empty($date_end)) // We define date_start and date_end $p = explode(":", $conf->global->MAIN_INFO_SOCIETE_COUNTRY); $idpays = $p[0]; -$sql = "SELECT f.rowid, f.ref, f.type, f.datef as df, f.libelle,"; +$sql = "SELECT f.rowid, f.ref, f.type, f.datef as df, f.libelle,f.ref_supplier,"; $sql .= " fd.rowid as fdid, fd.description, fd.total_ttc, fd.tva_tx, fd.total_ht, fd.tva as total_tva, fd.product_type,"; $sql .= " s.rowid as socid, s.nom as name, s.code_compta_fournisseur, s.fournisseur,"; $sql .= " s.code_compta_fournisseur, p.accountancy_code_buy , ct.accountancy_code_buy as account_tva, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte"; @@ -135,7 +135,7 @@ if ($result) { $compta_tva = (! empty($obj->account_tva) ? $obj->account_tva : $cpttva); $tabfac[$obj->rowid]["date"] = $obj->df; - $tabfac[$obj->rowid]["ref"] = $obj->ref; + $tabfac[$obj->rowid]["ref"] = $obj->ref_supplier.' ('.$obj->ref.')'; $tabfac[$obj->rowid]["type"] = $obj->type; $tabfac[$obj->rowid]["description"] = $obj->description; $tabfac[$obj->rowid]["fk_facturefourndet"] = $obj->fdid; @@ -183,7 +183,7 @@ if ($action == 'writebookkeeping') { $result = $bookkeeping->create(); if ($result < 0) { $error ++; - setEventMessage($object->errors, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } @@ -213,7 +213,7 @@ if ($action == 'writebookkeeping') { $result = $bookkeeping->create(); if ($result < 0) { $error ++; - setEventMessage($object->errors, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } } @@ -244,14 +244,14 @@ if ($action == 'writebookkeeping') { $result = $bookkeeping->create(); if ($result < 0) { $error ++; - setEventMessage($object->errors, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } } } if (empty($error)) { - setEventMessage($langs->trans("GeneralLedgerIsWritten"),'mesgs'); + setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs'); } } diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php index 8535e59aa26..38d9c26dcb1 100644 --- a/htdocs/accountancy/journal/sellsjournal.php +++ b/htdocs/accountancy/journal/sellsjournal.php @@ -218,7 +218,7 @@ if ($action == 'writebookkeeping') $result = $bookkeeping->create(); if ($result < 0) { $error ++; - setEventMessage($object->errors, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } @@ -248,7 +248,7 @@ if ($action == 'writebookkeeping') $result = $bookkeeping->create(); if ($result < 0) { $error ++; - setEventMessage($object->errors, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } } @@ -280,14 +280,14 @@ if ($action == 'writebookkeeping') $result = $bookkeeping->create(); if ($result < 0) { $error ++; - setEventMessage($object->errors, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } } } if (empty($error)) { - setEventMessage($langs->trans("GeneralLedgerIsWritten"),'mesgs'); + setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs'); } } diff --git a/htdocs/accountancy/supplier/list.php b/htdocs/accountancy/supplier/list.php index e261dfff350..ea2ed8de0eb 100644 --- a/htdocs/accountancy/supplier/list.php +++ b/htdocs/accountancy/supplier/list.php @@ -94,8 +94,8 @@ $formventilation = new FormVentilation($db); $accounting = new AccountingAccount($db); // TODO: we should need to check if result is a really exist accountaccount rowid..... -$aarowid_s = $accounting->fetch('', ACCOUNTING_SERVICE_BUY_ACCOUNT); -$aarowid_p = $accounting->fetch('', ACCOUNTING_PRODUCT_BUY_ACCOUNT); +$aarowid_s = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT,1); +$aarowid_p = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT,1); // Purge search criteria if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers -- GitLab