From 0763d15b4c5d4418b1a1e9126928697208042ff2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 15 Jul 2017 12:37:31 +0200 Subject: [PATCH] Debug journalization Debug edition of user BAN. --- .../journal/expensereportsjournal.php | 166 ++++++---- .../accountancy/journal/purchasesjournal.php | 228 ++++++++------ htdocs/accountancy/journal/sellsjournal.php | 297 ++++++++++-------- htdocs/core/menus/standard/eldy.lib.php | 6 +- htdocs/core/modules/modAccounting.class.php | 2 +- htdocs/core/modules/modSalaries.class.php | 12 +- htdocs/user/bank.php | 97 ++++-- htdocs/user/class/userbankaccount.class.php | 3 +- 8 files changed, 487 insertions(+), 324 deletions(-) diff --git a/htdocs/accountancy/journal/expensereportsjournal.php b/htdocs/accountancy/journal/expensereportsjournal.php index 0002bca413f..fb1e77d1c5c 100644 --- a/htdocs/accountancy/journal/expensereportsjournal.php +++ b/htdocs/accountancy/journal/expensereportsjournal.php @@ -36,12 +36,7 @@ require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php'; require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php'; require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php'; -$langs->load("compta"); -$langs->load("bills"); -$langs->load("other"); -$langs->load("main"); -$langs->load("accountancy"); -$langs->load("trips"); +$langs->loadLangs(array("commercial", "compta","bills","other","accountancy","trips","errors")); $id_journal = GETPOST('id_journal', 'int'); $action = GETPOST('action','aZ09'); @@ -91,7 +86,7 @@ if (empty($date_start) || empty($date_end)) // We define date_start and date_end $idpays = $mysoc->country_id; $sql = "SELECT er.rowid, er.ref, er.date_debut as de,"; -$sql .= " erd.rowid as erdid, erd.comments, erd.total_ttc, erd.tva_tx, erd.total_ht, erd.total_tva, erd.fk_code_ventilation, erd.vat_src_code, "; +$sql .= " erd.rowid as erdid, erd.comments, erd.total_ht, erd.total_tva, erd.total_localtax1, erd.total_localtax2, erd.tva_tx, erd.total_ttc, erd.fk_code_ventilation, erd.vat_src_code, "; $sql .= " u.rowid as uid, u.firstname, u.lastname, u.accountancy_code as user_accountancy_account,"; $sql .= " f.accountancy_code, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte"; //$sql .= " ct.accountancy_code_buy as account_tva"; @@ -112,22 +107,25 @@ if ($in_bookkeeping == 'notyet') $sql .= " AND er.rowid NOT IN (SELECT fk_doc FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab WHERE ab.doc_type='expense_report')"; $sql .= " ORDER BY er.date_debut"; -dol_syslog('accountancy/journal/expensereportsjournal.php:: $sql=' . $sql); +dol_syslog('accountancy/journal/expensereportsjournal.php', LOG_DEBUG); $result = $db->query($sql); if ($result) { - $num = $db->num_rows($result); - - // Variables - $account_salary = (! empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT)) ? $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT : 'NotDefined'; - $account_vat = (! empty($conf->global->ACCOUNTING_VAT_BUY_ACCOUNT)) ? $conf->global->ACCOUNTING_VAT_BUY_ACCOUNT : 'NotDefined'; $taber = array (); $tabht = array (); $tabtva = array (); $def_tva = array (); $tabttc = array (); + $tablocaltax1 = array (); + $tablocaltax2 = array (); $tabuser = array (); + $num = $db->num_rows($result); + + // Variables + $account_salary = (! empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT)) ? $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT : 'NotDefined'; + $account_vat = (! empty($conf->global->ACCOUNTING_VAT_BUY_ACCOUNT)) ? $conf->global->ACCOUNTING_VAT_BUY_ACCOUNT : 'NotDefined'; + $i = 0; while ( $i < $num ) { $obj = $db->fetch_object($result); @@ -138,7 +136,9 @@ if ($result) { $vatdata = getTaxesFromId($obj->tva_tx.($obj->vat_src_code?' ('.$obj->vat_src_code.')':''), $mysoc, $mysoc, 0); $compta_tva = (! empty($vatdata['accountancy_code_sell']) ? $vatdata['accountancy_code_sell'] : $account_vat); - + $compta_localtax1 = (! empty($vatdata['accountancy_code_sell']) ? $vatdata['accountancy_code_sell'] : $cpttva); + $compta_localtax2 = (! empty($vatdata['accountancy_code_sell']) ? $vatdata['accountancy_code_sell'] : $cpttva); + // Define array to display all VAT rates that use this accounting account $compta_tva if (price2num($obj->tva_tx) || ! empty($obj->vat_src_code)) { @@ -149,9 +149,19 @@ if ($result) { $taber[$obj->rowid]["ref"] = $obj->ref; $taber[$obj->rowid]["comments"] = $obj->comments; $taber[$obj->rowid]["fk_expensereportdet"] = $obj->erdid; + + // Avoid warnings + if (! isset($tabttc[$obj->rowid][$compta_user])) $tabttc[$obj->rowid][$compta_user] = 0; + if (! isset($tabht[$obj->rowid][$compta_fees])) $tabht[$obj->rowid][$compta_fees] = 0; + if (! isset($tabtva[$obj->rowid][$compta_tva])) $tabtva[$obj->rowid][$compta_tva] = 0; + if (! isset($tablocaltax1[$obj->rowid][$compta_localtax1])) $tablocaltax1[$obj->rowid][$compta_localtax1] = 0; + if (! isset($tablocaltax2[$obj->rowid][$compta_localtax2])) $tablocaltax2[$obj->rowid][$compta_localtax2] = 0; + $tabttc[$obj->rowid][$compta_user] += $obj->total_ttc; $tabht[$obj->rowid][$compta_fees] += $obj->total_ht; $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva; + $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1; + $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2; $tabuser[$obj->rowid] = array ( 'id' => $obj->uid, 'name' => dolGetFirstLastname($obj->firstname, $obj->lastname), @@ -169,7 +179,7 @@ if ($action == 'writebookkeeping') { $now = dol_now(); $error = 0; - foreach ($taber as $key => $val) + foreach ($taber as $key => $val) // Loop on each expense report { $errorforline = 0; @@ -180,7 +190,6 @@ if ($action == 'writebookkeeping') { { foreach ( $tabttc[$key] as $k => $mt ) { if ($mt) { - // get compte id and label $bookkeeping = new BookKeeping($db); $bookkeeping->doc_date = $val["date"]; $bookkeeping->doc_ref = $val["ref"]; @@ -190,8 +199,8 @@ if ($action == 'writebookkeeping') { $bookkeeping->fk_docdet = $val["fk_expensereportdet"]; $bookkeeping->subledger_account = $tabuser[$key]['user_accountancy_code']; $bookkeeping->subledger_label = $tabuser[$key]['user_accountancy_code']; - $bookkeeping->label_operation = $tabuser[$key]['name']; $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT; + $bookkeeping->label_operation = $tabuser[$key]['name']; $bookkeeping->montant = $mt; $bookkeeping->sens = ($mt >= 0) ? 'C' : 'D'; $bookkeeping->debit = ($mt <= 0) ? $mt : 0; @@ -223,8 +232,6 @@ if ($action == 'writebookkeeping') { if (! $errorforline) { foreach ( $tabht[$key] as $k => $mt ) { - $accountingaccount = new AccountingAccount($db); - $accountingaccount->fetch(null, $k, true); if ($mt) { // get compte id and label $accountingaccount = new AccountingAccount($db); @@ -238,8 +245,8 @@ if ($action == 'writebookkeeping') { $bookkeeping->fk_docdet = $val["fk_expensereportdet"]; $bookkeeping->subledger_account = ''; $bookkeeping->subledger_label = ''; - $bookkeeping->label_operation = $accountingaccount->label; $bookkeeping->numero_compte = $k; + $bookkeeping->label_operation = $accountingaccount->label; $bookkeeping->montant = $mt; $bookkeeping->sens = ($mt < 0) ? 'C' : 'D'; $bookkeeping->debit = ($mt > 0) ? $mt : 0; @@ -271,9 +278,15 @@ if ($action == 'writebookkeeping') { // VAT if (! $errorforline) { - // var_dump($tabtva); - foreach ( $tabtva[$key] as $k => $mt ) { - if ($mt) { + $listoftax=array(0, 1, 2); + foreach($listoftax as $numtax) + { + $arrayofvat = $tabtva; + if ($numtax == 1) $arrayofvat = $tablocaltax1; + if ($numtax == 2) $arrayofvat = $tablocaltax2; + + foreach ( $arrayofvat[$key] as $k => $mt ) { + if ($mt) { // get compte id and label $bookkeeping = new BookKeeping($db); $bookkeeping->doc_date = $val["date"]; @@ -284,8 +297,8 @@ if ($action == 'writebookkeeping') { $bookkeeping->fk_docdet = $val["fk_expensereportdet"]; $bookkeeping->subledger_account = ''; $bookkeeping->subledger_label = ''; - $bookkeeping->label_operation = $langs->trans("VAT"). ' '.join(', ',$def_tva[$key][$k]); $bookkeeping->numero_compte = $k; + $bookkeeping->label_operation = $langs->trans("VAT"). ' '.join(', ',$def_tva[$key][$k]); $bookkeeping->montant = $mt; $bookkeeping->sens = ($mt < 0) ? 'C' : 'D'; $bookkeeping->debit = ($mt > 0) ? $mt : 0; @@ -309,6 +322,7 @@ if ($action == 'writebookkeeping') { setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); } } + } } } } @@ -329,7 +343,7 @@ if ($action == 'writebookkeeping') { } } - if (empty($error) && count($tabpay)) { + if (empty($error) && count($tabpay) > 0) { setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs'); } elseif (count($tabpay) == $error) @@ -353,7 +367,7 @@ $form = new Form($db); $userstatic = new User($db); // Export -/*if ($action == 'export_csv') { +/*if ($action == 'exportcsv') { $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php'; @@ -479,20 +493,25 @@ if (empty($action) || $action == 'view') { journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink); - /*if ($conf->global->ACCOUNTING_EXPORT_MODELCSV != 1 && $conf->global->ACCOUNTING_EXPORT_MODELCSV != 2) { - print ''; - } else { - print ''; - }*/ - + // Button to write into Ledger + if (empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) || $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT == '-1') { + print img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone"); + print ' : '.$langs->trans("AccountancyAreaDescMisc", 4, ''.$langs->transnoentitiesnoconv("MenuFinancial").'-'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").''); + } print '
'; - print ''; + if (empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) || $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT == '-1') { + print ''; + } + else { + print ''; + } + //print ''; print '
'; print '