diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index 0d9832cb802..93968644a8f 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -1,8 +1,8 @@ - * Copyright (C) 2013-2016 Florian Henry - * Copyright (C) 2013-2017 Alexandre Spangaro - * Copyright (C) 2016 Laurent Destailleur +/* Copyright (C) 2013-2016 Olivier Geffroy + * Copyright (C) 2013-2016 Florian Henry + * Copyright (C) 2013-2017 Alexandre Spangaro + * Copyright (C) 2016-2017 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,6 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * */ /** @@ -377,28 +376,28 @@ print ''; print ''; print ''; print '
'; -print $langs->trans('From') . ': '; +print $langs->trans('From') . ' '; print $form->select_date($search_date_start, 'date_start', 0, 0, 1); print '
'; print '
'; -print $langs->trans('to') . ': '; +print $langs->trans('to') . ' '; print $form->select_date($search_date_end, 'date_end', 0, 0, 1); print '
'; print ''; print ''; print ''; print '
'; -print $langs->trans('From'); +print $langs->trans('From').' '; print $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array (), 1, 1, 'maxwidth200'); print '
'; print '
'; -print $langs->trans('to'); +print $langs->trans('to').' '; print $formaccounting->select_account($search_accountancy_code_end, 'search_accountancy_code_end', 1, array (), 1, 1, 'maxwidth200'); print '
'; print ''; print ''; print '
'; -print $langs->trans('From'); +print $langs->trans('From').' '; // TODO For the moment we keep a fre input text instead of a combo. The select_auxaccount has problem because it does not // use setup of keypress to select thirdparty and this hang browser on large database. if (! empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) @@ -411,7 +410,7 @@ else } print '
'; print '
'; -print $langs->trans('to'); +print $langs->trans('to').' '; // TODO For the moment we keep a fre input text instead of a combo. The select_auxaccount has problem because it does not // use setup of keypress to select thirdparty and this hang browser on large database. if (! empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) @@ -455,7 +454,10 @@ print "\n"; $total_debit = 0; $total_credit = 0; -foreach ($object->lines as $line ) { +$i=0; +while ($i < min($num, $limit)) +{ + $line = $object->lines[$i]; $total_debit += $line->debit; $total_credit += $line->credit; @@ -481,6 +483,8 @@ foreach ($object->lines as $line ) { print '' . img_delete() . ''; print ''; print "\n"; + + $i++; } print ''; diff --git a/htdocs/accountancy/bookkeeping/listbyaccount.php b/htdocs/accountancy/bookkeeping/listbyaccount.php index 4e9e7bd56e7..1f43964bd0a 100644 --- a/htdocs/accountancy/bookkeeping/listbyaccount.php +++ b/htdocs/accountancy/bookkeeping/listbyaccount.php @@ -92,7 +92,7 @@ if (! empty($search_doc_date)) { } -if (!GETPOST('button_removefilter_x','alpha') && !GETPOST('button_removefilter','alpha')) // Both test are required to be compatible with all browsers +if (! GETPOST('button_removefilter_x','alpha') && ! GETPOST('button_removefilter.x','alpha') && ! GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers { if (! empty($search_accountancy_code_start)) { $filter['t.numero_compte'] = $search_accountancy_code_start; @@ -160,7 +160,6 @@ $title_page = $langs->trans("Bookkeeping") . ' ' . strtolower($langs->trans("By" llxHeader('', $title_page); // List - $nbtotalofrecords = ''; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $nbtotalofrecords = $object->fetchAllByAccount($sortorder, $sortfield, 0, 0, $filter); @@ -173,7 +172,9 @@ $result = $object->fetchAllByAccount($sortorder, $sortfield, $limit, $offset, $f if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } -$nbtotalofrecords = $result; + +$num=count($object->lines); + if ($action == 'delmouv') { $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?mvt_num=' . GETPOST('mvt_num'), $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt'), 'delmouvconfirm', '', 0, 1); @@ -204,7 +205,7 @@ if ($action == 'delbookkeepingyear') { -print '
'; +print ''; $viewflat = ' ' . $langs->trans("ViewFlatList") . ''; @@ -236,7 +237,7 @@ print ''; print ' '; print ' '; -print ''; +print ''; print ''; $searchpicto=$form->showFilterAndCheckAddButtons(0); print $searchpicto; @@ -250,7 +251,7 @@ print_liste_field_titre($langs->trans("Docref"), $_SERVER['PHP_SELF'], "t.doc_re print_liste_field_titre($langs->trans("Label")); print_liste_field_titre($langs->trans("Debit"), $_SERVER['PHP_SELF'], "t.debit", "", $options, 'align="right"', $sortfield, $sortorder); print_liste_field_titre($langs->trans("Credit"), $_SERVER['PHP_SELF'], "t.credit", "", $options, 'align="right"', $sortfield, $sortorder); -print_liste_field_titre($langs->trans("Codejournal"), $_SERVER['PHP_SELF'], "t.code_journal", "", $options, 'align="right"', $sortfield, $sortorder); +print_liste_field_titre($langs->trans("Codejournal"), $_SERVER['PHP_SELF'], "t.code_journal", "", $options, 'align="center"', $sortfield, $sortorder); print_liste_field_titre('', $_SERVER["PHP_SELF"], "", $options, "", 'width="60" align="center"', $sortfield, $sortorder); print "\n"; @@ -263,7 +264,10 @@ $sous_total_debit = 0; $sous_total_credit = 0; $displayed_account_number = null; // Start with undefined to be able to distinguish with empty -foreach ( $object->lines as $line ) { +$i=0; +while ($i < min($num, $limit)) +{ + $line = $object->lines[$i]; $total_debit += $line->debit; $total_credit += $line->credit; @@ -323,10 +327,11 @@ foreach ( $object->lines as $line ) { print ''; print "\n"; - // Comptabilise le sous-total - $sous_total_debit += $line->debit; - $sous_total_credit += $line->credit; + // Comptabilise le sous-total + $sous_total_debit += $line->debit; + $sous_total_credit += $line->credit; + $i++; } // Affiche un Sous-Total du dernier compte comptable affiché diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 5c5fb022de9..1431df9f8a2 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -176,7 +176,7 @@ class BookKeeping extends CommonObject if (empty($this->credit)) $this->credit = 0; // Check parameters - if (empty($this->numero_compte) || $this->numero_compte == '-1') + if (empty($this->numero_compte) || $this->numero_compte == '-1' || $this->numero_compte == 'NotDefined') { $langs->load("errors"); if (in_array($this->doc_type, array('bank', 'expense_report'))) @@ -803,7 +803,7 @@ class BookKeeping extends CommonObject if (! empty($limit)) { $sql .= ' ' . $this->db->plimit($limit + 1, $offset); } - $this->lines = array (); + $this->lines = array(); $resql = $this->db->query($sql); if ($resql) { diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index 14307185ac6..d5746eb63e5 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -1,4 +1,6 @@ * Copyright (C) 2007-2010 Jean Heimburger * Copyright (C) 2011 Juanjo Menent @@ -51,28 +53,21 @@ require_once DOL_DOCUMENT_ROOT . '/societe/class/client.class.php'; require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php'; require_once DOL_DOCUMENT_ROOT . '/expensereport/class/paymentexpensereport.class.php'; require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/paymentvarious.class.php'; +require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php'; -$langs->load("companies"); -$langs->load("other"); -$langs->load("compta"); -$langs->load("banks"); -$langs->load('bills'); -$langs->load('donations'); -$langs->load("accountancy"); -$langs->load("trips"); -$langs->load("salaries"); -$langs->load("hrm"); +$langs->loadLangs(array("companies","other","compta","banks",'bills','donations',"accountancy","trips","salaries","hrm")); // Multi journal $id_journal = GETPOST('id_journal', 'int'); -$date_startmonth = GETPOST('date_startmonth'); -$date_startday = GETPOST('date_startday'); -$date_startyear = GETPOST('date_startyear'); -$date_endmonth = GETPOST('date_endmonth'); -$date_endday = GETPOST('date_endday'); -$date_endyear = GETPOST('date_endyear'); -$in_bookkeeping = GETPOST('in_bookkeeping'); +$date_startmonth = GETPOST('date_startmonth','int'); +$date_startday = GETPOST('date_startday','int'); +$date_startyear = GETPOST('date_startyear','int'); +$date_endmonth = GETPOST('date_endmonth','int'); +$date_endday = GETPOST('date_endday','int'); +$date_endyear = GETPOST('date_endyear','int'); +$in_bookkeeping = GETPOST('in_bookkeeping','aZ09'); +if ($in_bookkeeping == '') $in_bookkeeping = 'notyet'; $now = dol_now(); $action = GETPOST('action','aZ09'); @@ -107,7 +102,7 @@ if (empty($date_start) || empty($date_end)) // We define date_start and date_end $idpays = $mysoc->country_id; -$sql = "SELECT b.rowid, b.dateo as do, b.datev as dv, b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type,"; +$sql = "SELECT b.rowid, b.dateo as do, b.datev as dv, b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type, b.fk_account,"; $sql .= " ba.courant, ba.ref as baref, ba.account_number, ba.fk_accountancy_journal,"; $sql .= " soc.code_compta, soc.code_compta_fournisseur, soc.rowid as socid, soc.nom as name, bu1.type as typeop,"; $sql .= " u.accountancy_code, u.rowid as userid, u.lastname as lastname, u.firstname as firstname, bu2.type as typeop"; @@ -118,18 +113,22 @@ $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu2 ON bu2.fk_bank = b.row $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as soc on bu1.url_id=soc.rowid"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "user as u on bu2.url_id=u.rowid"; $sql .= " WHERE ba.fk_accountancy_journal=" . $id_journal; -$sql .= ' AND ba.entity IN ('.getEntity('bank_account', 0).')'; // We don't share object for accountancy +$sql .= ' AND b.amount != 0 AND ba.entity IN ('.getEntity('bank_account', 0).')'; // We don't share object for accountancy if ($date_start && $date_end) $sql .= " AND b.dateo >= '" . $db->idate($date_start) . "' AND b.dateo <= '" . $db->idate($date_end) . "'"; -if ($in_bookkeeping == 'yes') +if ($in_bookkeeping == 'already') + $sql .= " AND (b.rowid IN (SELECT fk_doc FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab WHERE ab.doc_type='bank') )"; +if ($in_bookkeeping == 'notyet') $sql .= " AND (b.rowid NOT IN (SELECT fk_doc FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab WHERE ab.doc_type='bank') )"; $sql .= " ORDER BY b.datev"; +//print $sql; $object = new Account($db); $paymentstatic = new Paiement($db); $paymentsupplierstatic = new PaiementFourn($db); $societestatic = new Societe($db); $userstatic = new User($db); +$bankaccountstatic = new Account($db); $chargestatic = new ChargeSociales($db); $paymentdonstatic = new PaymentDonation($db); $paymentvatstatic = new TVA($db); @@ -150,12 +149,12 @@ if ($result) { $num = $db->num_rows($result); // Variables - $account_supplier = (! empty($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) ? $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER : $langs->trans("CodeNotDef")); - $account_customer = (! empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : $langs->trans("CodeNotDef")); - $account_employee = (! empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) ? $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT : $langs->trans("CodeNotDef")); - $account_pay_vat = (! empty($conf->global->ACCOUNTING_VAT_PAY_ACCOUNT) ? $conf->global->ACCOUNTING_VAT_PAY_ACCOUNT : $langs->trans("CodeNotDef")); - $account_pay_donation = (! empty($conf->global->DONATION_ACCOUNTINGACCOUNT) ? $conf->global->DONATION_ACCOUNTINGACCOUNT : $langs->trans("CodeNotDef")); - $account_transfer = (! empty($conf->global->ACCOUNTING_ACCOUNT_TRANSFER_CASH) ? $conf->global->ACCOUNTING_ACCOUNT_TRANSFER_CASH : $langs->trans("CodeNotDef")); + $account_supplier = (! empty($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) ? $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER : 'NotDefined'); // NotDefined is a reserved word + $account_customer = (! empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : 'NotDefined'); // NotDefined is a reserved word + $account_employee = (! empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) ? $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT : 'NotDefined'); // NotDefined is a reserved word + $account_pay_vat = (! empty($conf->global->ACCOUNTING_VAT_PAY_ACCOUNT) ? $conf->global->ACCOUNTING_VAT_PAY_ACCOUNT : 'NotDefined'); // NotDefined is a reserved word + $account_pay_donation = (! empty($conf->global->DONATION_ACCOUNTINGACCOUNT) ? $conf->global->DONATION_ACCOUNTINGACCOUNT : 'NotDefined'); // NotDefined is a reserved word + $account_transfer = (! empty($conf->global->ACCOUNTING_ACCOUNT_TRANSFER_CASH) ? $conf->global->ACCOUNTING_ACCOUNT_TRANSFER_CASH : 'NotDefined'); // NotDefined is a reserved word $tabcompany = array(); $tabuser = array(); @@ -164,10 +163,10 @@ if ($result) { $tabtp = array (); $tabtype = array (); - // Loop on each line into bank account. For each line, we should get: - // on line tabpay = line into bank - // one line for bank jounral = tabbq - // one line for thirdparty journal = tabtp + // Loop on each line into llx_bank table. For each line, we should get: + // one line tabpay = line into bank + // one line for bank record = tabbq + // one line for thirdparty record = tabtp $i = 0; while ( $i < $num ) { @@ -175,6 +174,8 @@ if ($result) { // Set accountancy code (for bank and thirdparty) $compta_bank = $obj->account_number; + + $compta_soc = 'NotDefined'; if ($obj->label == '(SupplierInvoicePayment)' || $obj->label == '(SupplierInvoicePaymentBack)') $compta_soc = (! empty($obj->code_compta_fournisseur) ? $obj->code_compta_fournisseur : $account_supplier); if ($obj->label == '(CustomerInvoicePayment)' || $obj->label == '(CustomerInvoicePaymentBack)') @@ -198,9 +199,10 @@ if ($result) { // Variable bookkeeping $tabpay[$obj->rowid]["date"] = $obj->do; - $tabpay[$obj->rowid]["type_payment"] = $obj->fk_type; - $tabpay[$obj->rowid]["ref"] = $obj->label; + $tabpay[$obj->rowid]["type_payment"] = $obj->fk_type; // CHQ, VIR, LIQ, CB, ... + $tabpay[$obj->rowid]["ref"] = $obj->label; // By default. Not unique. May be changed later $tabpay[$obj->rowid]["fk_bank"] = $obj->rowid; + $tabpay[$obj->rowid]["fk_bank_account"] = $obj->fk_account; if (preg_match('/^\((.*)\)$/i', $obj->label, $reg)) { $tabpay[$obj->rowid]["lib"] = $langs->trans($reg[1]); } else { @@ -208,16 +210,35 @@ if ($result) { } $links = $object->get_url($obj->rowid); - // get_url may return -1 which is not traversable - if (is_array($links)) { - // Now loop on each link of record in bank. - foreach ( $links as $key => $val ) { + //var_dump($i); + //var_dump($tabpay); - if (in_array($links[$key]['type'], array('sc', 'payment_sc', 'payment', 'payment_supplier', 'payment_vat', 'payment_expensereport', 'banktransfert', 'payment_donation', 'payment_salary', 'payment_various'))) // So we excluded 'company' here + // By default + $tabpay[$obj->rowid]['type'] = 'unknown'; // Can be SOLD, miscellaneous entry, payment of patient, or old record with no links in bank_url. + $tabtype[$obj->rowid] = 'unknown'; + + // get_url may return -1 which is not traversable + if (is_array($links) && count($links) > 0) { + + // Now loop on each link of record in bank. + foreach ($links as $key => $val) { + + if (in_array($links[$key]['type'], array('sc', 'payment_sc', 'payment', 'payment_supplier', 'payment_vat', 'payment_expensereport', 'banktransfert', 'payment_donation', 'payment_salary', 'payment_various'))) { + // So we excluded 'company' and 'user' here. We want only payment lines + // We save tabtype for a future use, to remember what kind of payment it is + $tabpay[$obj->rowid]['type'] = $links[$key]['type']; $tabtype[$obj->rowid] = $links[$key]['type']; } + elseif (in_array($links[$key]['type'], array('company', 'user'))) + { + if ($tabpay[$obj->rowid]['type'] == 'unknown') + { + // We can guess here it is a bank record for a thirdparty company or a user. + // But we won't be able to record somewhere else than into a waiting account, because there is no other journal to record the contreparty. + } + } if ($links[$key]['type'] == 'payment') { $paymentstatic->id = $links[$key]['url_id']; @@ -232,12 +253,13 @@ if ($result) { $societestatic->id = $links[$key]['url_id']; $societestatic->name = $links[$key]['label']; $tabpay[$obj->rowid]["soclib"] = $societestatic->getNomUrl(1, '', 30); - $tabtp[$obj->rowid][$compta_soc] += $obj->amount; + if ($compta_soc) $tabtp[$obj->rowid][$compta_soc] += $obj->amount; } else if ($links[$key]['type'] == 'user') { $userstatic->id = $links[$key]['url_id']; $userstatic->name = $links[$key]['label']; - $tabpay[$obj->rowid]["soclib"] = $userstatic->getNomUrl(1, '', 30); - $tabtp[$obj->rowid][$compta_user] += $obj->amount; + if ($userstatic->id > 0) $tabpay[$obj->rowid]["soclib"] = $userstatic->getNomUrl(1, '', 30); + else $tabpay[$obj->rowid]["soclib"] = '???'; // Should not happen, but happens with old data when id of user was not saved on expense report payment. + if ($compta_user) $tabtp[$obj->rowid][$compta_user] += $obj->amount; } else if ($links[$key]['type'] == 'sc') { $chargestatic->id = $links[$key]['url_id']; $chargestatic->ref = $links[$key]['url_id']; @@ -287,9 +309,8 @@ if ($result) { $tabpay[$obj->rowid]["paymentsalid"] = $paymentsalstatic->id; } else if ($links[$key]['type'] == 'payment_expensereport') { $paymentexpensereportstatic->id = $links[$key]['url_id']; - $paymentexpensereportstatic->fk_expensereport = $links[$key]['url_id']; $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentexpensereportstatic->getNomUrl(2); - $tabpay[$obj->rowid]["fk_expensereport"] = $paymentexpensereportstatic->id; + $tabpay[$obj->rowid]["paymentexpensereport"] = $paymentexpensereportstatic->id; } else if ($links[$key]['type'] == 'payment_various') { $paymentvariousstatic->id = $links[$key]['url_id']; $paymentvariousstatic->ref = $links[$key]['url_id']; @@ -297,17 +318,21 @@ if ($result) { $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentvariousstatic->getNomUrl(2); $tabpay[$obj->rowid]["paymentvariousid"] = $paymentvariousstatic->id; $paymentvariousstatic->fetch($paymentvariousstatic->id); - $account_various = (! empty($paymentvariousstatic->accountancy_code) ? $paymentvariousstatic->accountancy_code : $langs->trans("CodeNotDef")); + $account_various = (! empty($paymentvariousstatic->accountancy_code) ? $paymentvariousstatic->accountancy_code : 'NotDefined'); // NotDefined is a reserved word $tabtp[$obj->rowid][$account_various] += $obj->amount; } else if ($links[$key]['type'] == 'banktransfert') { $tabpay[$obj->rowid]["lib"] .= ' ' . $langs->trans("BankTransfer"); $tabtp[$obj->rowid][$account_transfer] += $obj->amount; + $bankaccountstatic->fetch($tabpay[$obj->rowid]['fk_bank_account']); + $tabpay[$obj->rowid]["soclib"] = $bankaccountstatic->getNomUrl(2); } } } $tabbq[$obj->rowid][$compta_bank] += $obj->amount; + // If not links were found to know amount on thirdparty, we init it. + if (empty($tabtp[$obj->rowid])) $tabtp[$obj->rowid]['NotDefined']= $tabbq[$obj->rowid][$compta_bank]; // Check account number is ok /*if ($action == 'writebookkeeping') // Make test now in such a case @@ -330,7 +355,7 @@ if ($result) { // if($obj->socid)$tabtp[$obj->rowid][$compta_soc] += $obj->amount; - $i ++; + $i++; } } else { dol_print_error($db); @@ -349,12 +374,19 @@ if (! $error && $action == 'writebookkeeping') { $error = 0; foreach ( $tabpay as $key => $val ) { // $key is rowid into llx_bank + $ref = getSourceDocRef($val, $tabtype[$key]); + $errorforline = 0; $db->begin(); + // Introduce a protection. Total of tabtp must be total of tabbq + /*var_dump($tabpay); + var_dump($tabtp); + var_dump($tabbq);exit;*/ + // Bank - if (! $errorforline) + if (! $errorforline && is_array($tabbq[$key])) { // Line into bank account foreach ( $tabbq[$key] as $k => $mt ) @@ -362,7 +394,7 @@ if (! $error && $action == 'writebookkeeping') { if ($mt) { $bookkeeping = new BookKeeping($db); $bookkeeping->doc_date = $val["date"]; - $bookkeeping->doc_ref = $val["ref"]; + $bookkeeping->doc_ref = $ref; $bookkeeping->doc_type = 'bank'; $bookkeeping->fk_doc = $key; $bookkeeping->fk_docdet = $val["fk_bank"]; @@ -378,60 +410,24 @@ if (! $error && $action == 'writebookkeeping') { $bookkeeping->fk_user_author = $user->id; $bookkeeping->date_create = $now; + // No subledger_account value for the bank line if ($tabtype[$key] == 'payment') { - $bookkeeping->subledger_account = $tabcompany[$key]['code_compta']; - - $sqlmid = 'SELECT fac.facnumber'; - $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture fac"; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid"; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid"; - $sqlmid .= " WHERE pay.fk_bank=" . $key; - dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $bookkeeping->doc_ref = $objmid->facnumber; // Ref of invoice - } + $bookkeeping->subledger_account = ''; } else if ($tabtype[$key] == 'payment_supplier') { - $bookkeeping->subledger_account = $tabcompany[$key]['code_compta']; - - $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"; - $sqlmid .= " WHERE payf.fk_bank=" . $key; - dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $bookkeeping->doc_ref = $objmid->ref_supplier . ' (' . $objmid->ref . ')'; // Ref on invoice - } + $bookkeeping->subledger_account = ''; } else if ($tabtype[$key] == 'payment_expensereport') { - $bookkeeping->subledger_account = $tabuser[$key]['accountancy_code']; - - $sqlmid = 'SELECT e.ref'; - $sqlmid .= " FROM " . MAIN_DB_PREFIX . "expensereport as e"; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "payment_expensereport as payer ON payer.fk_expensereport=e.rowid"; - $sqlmid .= " WHERE payer.fk_expensereport=" . $val["fk_expensereport"]; - dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $bookkeeping->doc_ref = $objmid->ref; // Ref of expensereport - } - } else if ($tabtype[$key] == 'payment_vat') { $bookkeeping->subledger_account = ''; - $bookkeeping->doc_ref = $langs->trans("PaymentVat") . ' (' . $val["paymentvatid"] . ')'; // Rowid of vat payment - } else if ($tabtype[$key] == 'payment_donation') { - $bookkeeping->subledger_account = ''; - $bookkeeping->doc_ref = $langs->trans("Donation") . ' (' . $val["paymentdonationid"] . ')'; // Rowid of donation } else if ($tabtype[$key] == 'payment_salary') { $bookkeeping->subledger_account = ''; - $bookkeeping->label_operation = $tabuser[$key]['name']; - $bookkeeping->doc_ref = $langs->trans("SalaryPayment") . ' (' . $val["paymentsalid"] . ')'; // Ref of salary payment + } else if ($tabtype[$key] == 'payment_vat') { + $bookkeeping->subledger_account = ''; + } else if ($tabtype[$key] == 'payment_donation') { + $bookkeeping->subledger_account = ''; } else if ($tabtype[$key] == 'payment_various') { $bookkeeping->subledger_account = ''; - $bookkeeping->doc_ref = $langs->trans("VariousPayment") . ' (' . $val["paymentvariousid"] . ')'; // Ref of various payment + } else if ($tabtype[$key] == 'unknown') { + // ??? + $bookkeeping->subledger_account = ''; } $result = $bookkeeping->create($user); @@ -440,7 +436,7 @@ if (! $error && $action == 'writebookkeeping') { { $error++; $errorforline++; - //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); + setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); } else { @@ -454,14 +450,14 @@ if (! $error && $action == 'writebookkeeping') { } // Third party - if (! $errorforline) + if (! $errorforline && is_array($tabtp[$key])) { // Line into thirdparty account foreach ( $tabtp[$key] as $k => $mt ) { if ($mt) { $bookkeeping = new BookKeeping($db); $bookkeeping->doc_date = $val["date"]; - $bookkeeping->doc_ref = $val["ref"]; + $bookkeeping->doc_ref = $ref; $bookkeeping->doc_type = 'bank'; $bookkeeping->fk_doc = $key; $bookkeeping->fk_docdet = $val["fk_bank"]; @@ -475,90 +471,70 @@ if (! $error && $action == 'writebookkeeping') { $bookkeeping->fk_user_author = $user->id; $bookkeeping->date_create = $now; - if (in_array($tabtype[$key], array('sc', 'payment_sc'))) { // If payment is payment of social contribution - $sqlmid = 'SELECT ch.libelle, t.libelle as labelc'; - $sqlmid .= " FROM " . MAIN_DB_PREFIX . "chargesociales ch "; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementcharge as paych ON paych.fk_charge=ch.rowid"; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "c_chargesociales as t ON ch.fk_type=t.id"; - $sqlmid .= " WHERE paych.fk_bank=" . $key; - dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $bookkeeping->label_compte = $objmid->labelc; - $bookkeeping->doc_ref = $objmid->libelle ; - } - $bookkeeping->subledger_account = ''; - $bookkeeping->numero_compte = $k; - } else if ($tabtype[$key] == 'payment') { // If payment is payment of customer invoice, we get ref of invoice - $sqlmid = 'SELECT fac.facnumber'; - $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture fac "; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid"; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid"; - $sqlmid .= " WHERE pay.fk_bank=" . $key; - dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $bookkeeping->doc_ref = $objmid->facnumber; - } + if ($tabtype[$key] == 'payment') { // If payment is payment of customer invoice, we get ref of invoice + $bookkeeping->label_operation = ''; $bookkeeping->subledger_account = $tabcompany[$key]['code_compta']; $bookkeeping->subledger_label = $tabcompany[$key]['name']; $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER; + $bookkeeping->label_compte = ''; } else if ($tabtype[$key] == 'payment_supplier') { // If payment is payment of supplier invoice, we get ref of invoice - $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"; - $sqlmid .= " WHERE payf.fk_bank=" . $key; - dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $bookkeeping->doc_ref = $objmid->ref_supplier . ' (' . $objmid->ref . ')'; - } + $bookkeeping->label_operation = ''; $bookkeeping->subledger_account = $tabcompany[$key]['code_compta']; $bookkeeping->subledger_label = $tabcompany[$key]['name']; $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER; + $bookkeeping->label_compte = ''; } else if ($tabtype[$key] == 'payment_expensereport') { + $bookkeeping->label_operation = $tabuser[$key]['name']; $bookkeeping->subledger_account = $tabuser[$key]['accountancy_code']; $bookkeeping->subledger_label = $tabuser[$key]['name']; $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT; - $bookkeeping->label_operation = $tabuser[$key]['name']; - $sqlmid = 'SELECT e.ref'; - $sqlmid .= " FROM " . MAIN_DB_PREFIX . "expensereport as e"; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "payment_expensereport as payer ON payer.fk_expensereport=e.rowid"; - $sqlmid .= " WHERE payer.fk_expensereport=" . $val["fk_expensereport"]; - dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $bookkeeping->doc_ref = $objmid->ref; // Ref of expensereport - } - } else if ($tabtype[$key] == 'payment_vat') { - $bookkeeping->subledger_account = ''; - $bookkeeping->numero_compte = $k; - $bookkeeping->doc_ref = $langs->trans("PaymentVat") . ' (' . $val["paymentvatid"] . ')'; // Rowid of vat - } else if ($tabtype[$key] == 'payment_donation') { - $bookkeeping->subledger_account = ''; - $bookkeeping->numero_compte = $k; - $bookkeeping->doc_ref = $langs->trans("Donation") . ' (' . $val["paymentdonationid"] . ')'; // Rowid of donation + $bookkeeping->label_compte = ''; } else if ($tabtype[$key] == 'payment_salary') { - $bookkeeping->subledger_account = $tabuser[$key]['accountancy_code']; - $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT; $bookkeeping->label_operation = $tabuser[$key]['name']; - $bookkeeping->doc_ref = $langs->trans("SalaryPayment") . ' (' . $val["paymentsalid"] . ')'; // Rowid of salary payment + $bookkeeping->subledger_account = $tabuser[$key]['accountancy_code']; + $bookkeeping->subledger_label = $tabuser[$key]['name']; + $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT; + $bookkeeping->label_compte = ''; + } else if (in_array($tabtype[$key], array('sc', 'payment_sc'))) { // If payment is payment of social contribution + $bookkeeping->label_operation = ''; + $bookkeeping->subledger_account = ''; + $bookkeeping->subledger_label = ''; + $bookkeeping->numero_compte = $k; + $bookkeeping->label_compte = $objmid->labelc; + } else if ($tabtype[$key] == 'payment_vat') { + $bookkeeping->label_operation = ''; + $bookkeeping->subledger_account = ''; + $bookkeeping->subledger_label = ''; + $bookkeeping->numero_compte = $k; + $bookkeeping->label_compte = ''; + } else if ($tabtype[$key] == 'payment_donation') { + $bookkeeping->label_operation = ''; + $bookkeeping->subledger_account = ''; + $bookkeeping->subledger_label = ''; + $bookkeeping->numero_compte = $k; + $bookkeeping->label_compte = ''; } else if ($tabtype[$key] == 'payment_various') { + $bookkeeping->label_operation = ''; $bookkeeping->subledger_account = ''; + $bookkeeping->subledger_label = ''; $bookkeeping->numero_compte = $k; - $bookkeeping->doc_ref = $langs->trans("VariousPayment") . ' (' . $val["paymentvariousid"] . ')'; // Rowid of various payment + $bookkeeping->label_compte = ''; } else if ($tabtype[$key] == 'banktransfert') { + $bookkeeping->label_operation = ''; $bookkeeping->subledger_account = ''; + $bookkeeping->subledger_label = ''; $bookkeeping->numero_compte = $k; + $bookkeeping->label_compte = ''; } else { - // Temporary account - $bookkeeping->doc_ref = $k; - $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE; + if ($tabtype[$key] == 'unknown') // Unknown transaction, we will use a waiting account for thirdparty. + { + // Temporary account + $bookkeeping->label_operation = ''; + $bookkeeping->subledger_account = ''; + $bookkeeping->subledger_label = ''; + $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE; + $bookkeeping->label_compte = ''; + } } $result = $bookkeeping->create($user); @@ -567,7 +543,7 @@ if (! $error && $action == 'writebookkeeping') { { $error++; $errorforline++; - //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); + setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); } else { @@ -586,17 +562,19 @@ if (! $error && $action == 'writebookkeeping') { } else { + //print 'KO for line '.$key.' '.$error.'
'; $db->rollback(); - if ($error >= 10) + $MAXNBERRORS=5; + if ($error >= $MAXNBERRORS) { - setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped"), null, 'errors'); + setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped").' (>'.$MAXNBERRORS.')', null, 'errors'); break; // Break in the foreach } } } - if (empty($error)) { + if (empty($error) && count($tabpay) > 0) { setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs'); } elseif (count($tabpay) == $error) @@ -609,10 +587,25 @@ if (! $error && $action == 'writebookkeeping') { } $action = ''; + + // Must reload data, so we make a redirect + if (count($tabpay) != $error) + { + $param='id_journal='.$id_journal; + $param.='&date_startday='.$date_startday; + $param.='&date_startmonth='.$date_startmonth; + $param.='&date_startyear='.$date_startyear; + $param.='&date_endday='.$date_endday; + $param.='&date_endmonth='.$date_endmonth; + $param.='&date_endyear='.$date_endyear; + $param.='&in_bookeeping='.$in_bookeeping; + header("Location: ".$_SERVER['PHP_SELF'].($param?'?'.$param:'')); + exit; + } } // Export -if ($action == 'exportcsv') { +if ($action == 'exportcsv') { // ISO and not UTF8 ! $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php'; @@ -620,32 +613,34 @@ if ($action == 'exportcsv') { $companystatic = new Client($db); $userstatic = new User($db); - // Bank foreach ( $tabpay as $key => $val ) { $date = dol_print_date($db->jdate($val["date"]), 'day'); - $reflabel = $val["ref"]; - if ($reflabel == '(SupplierInvoicePayment)' || $reflabel == '(SupplierInvoicePaymentBack)') { - $reflabel = $langs->trans('Supplier'); - } - if ($reflabel == '(CustomerInvoicePayment)' || $reflabel == '(CustomerInvoicePaymentBack)') { - $reflabel = $langs->trans('Customer'); - } - if ($reflabel == '(SocialContributionPayment)') { - $reflabel = $langs->trans('SocialContribution'); - } - if ($reflabel == '(DonationPayment)') { - $reflabel = $langs->trans('Donation'); - } - if ($reflabel == '(SubscriptionPayment)') { - $reflabel = $langs->trans('Subscription'); - } - if ($reflabel == '(ExpenseReportPayment)') { - $reflabel = $langs->trans('Employee'); - } + $ref = getSourceDocRef($val, $tabtype[$key]); - $companystatic->id = $tabcompany[$key]['id']; - $companystatic->name = $tabcompany[$key]['name']; + // + if (! empty($tabcompany[$key]['id'])) + { + $companystatic->id = $tabcompany[$key]['id']; + $companystatic->name = $tabcompany[$key]['name']; + } + else + { + $companystatic->id = 0; + $companystatic->name = ''; + } + if (! empty($tabuser[$key]['id'])) + { + $userstatic->id = $tabuser[$key]['id']; + $userstatic->lastname = $tabuser[$key]['lastname']; + $userstatic->firstname = $tabuser[$key]['firstname']; + } + else + { + $userstatic->id = 0; + $userstatic->lastname = ''; + $userstatic->firstname = ''; + } // Bank foreach ( $tabbq[$key] as $k => $mt ) { @@ -673,7 +668,6 @@ if ($action == 'exportcsv') { print '"' . $date . '"' . $sep; print '"' . $val["type_payment"] . '"' . $sep; print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; - if ($tabtype[$key] == 'payment_supplier') { print '"' . $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER . '"' . $sep; } else if($tabtype[$key] == 'payment') { @@ -681,9 +675,6 @@ if ($action == 'exportcsv') { } else { print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; } - - - print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; if ($companystatic->name == '') { print '"' . $langs->trans('ThirdParty') . " - " . utf8_decode($reflabel) . '"' . $sep; @@ -699,7 +690,7 @@ if ($action == 'exportcsv') { foreach ( $tabbq[$key] as $k => $mt ) { print '"' . $journal . '"' . $sep; print '"' . $date . '"' . $sep; - print '"' . $val["ref"] . '"' . $sep; + print '"' . $val["type_payment"] . '"' . $sep; print '"' . length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) . '"' . $sep; print '"' . length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) . '"' . $sep; print " " . $sep; @@ -738,17 +729,22 @@ if (empty($action) || $action == 'view') { $builddate = time(); //$description = $langs->trans("DescFinanceJournal") . '
'; $description.= $langs->trans("DescJournalOnlyBindedVisible").'
'; - $period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1). ' - ' .$langs->trans("AlreadyInGeneralLedger").' '. $form->selectyesno('in_bookkeeping',$in_bookkeeping,0); + + $listofchoices=array('already'=>$langs->trans("AlreadyInGeneralLedger"), 'notyet'=>$langs->trans("NotYetInGeneralLedger")); + $period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1). ' - ' .$langs->trans("JournalizationInLedgerStatus").' '. $form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1); $varlink = 'id_journal=' . $id_journal; 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->ACCOUNTING_ACCOUNT_CUSTOMER) || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1' + || empty($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER == '-1' + || 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 ''; @@ -782,9 +778,10 @@ if (empty($action) || $action == 'view') { print ""; print ""; print "" . $langs->trans("Date") . ""; - print "" . $langs->trans("Piece") . ' (' . $langs->trans("InvoiceRef") . ")"; + print "" . $langs->trans("Piece") . ' (' . $langs->trans("ObjectsRef") . ")"; print "" . $langs->trans("AccountAccounting") . ""; - print "" . $langs->trans("Type") . ""; + print "" . $langs->trans("SubledgerAccount") . ""; + print "" . $langs->trans("Label") . ""; print "" . $langs->trans("PaymentMode") . ""; print "" . $langs->trans("Debit") . ""; print "" . $langs->trans("Credit") . ""; @@ -795,132 +792,8 @@ if (empty($action) || $action == 'view') { foreach ( $tabpay as $key => $val ) { // $key is rowid in llx_bank $date = dol_print_date($db->jdate($val["date"]), 'day'); - $reflabel = $val["ref"]; - if ($reflabel == '(SupplierInvoicePayment)' || $reflabel == '(SupplierInvoicePaymentBack)') { - $reflabel = $langs->trans('Supplier'); - } - if ($reflabel == '(CustomerInvoicePayment)' || $reflabel == '(CustomerInvoicePaymentBack)') { - $reflabel = $langs->trans('Customer'); - } - if ($reflabel == '(SocialContributionPayment)') { - $reflabel = $langs->trans('SocialContribution'); - } - if ($reflabel == '(DonationPayment)') { - $reflabel = $langs->trans('Donation'); - } - if ($reflabel == '(SubscriptionPayment)') { - $reflabel = $langs->trans('Subscription'); - } - if ($reflabel == '(ExpenseReportPayment)') { - $reflabel = $langs->trans('Employee'); - } - if ($reflabel == '(payment_salary)') { - $reflabel = $langs->trans('Employee'); - } + $ref = getSourceDocRef($val, $tabtype[$key]); - $ref=$reflabel; - if ($tabtype[$key] == 'payment') - { - $sqlmid = 'SELECT payfac.fk_facture as id'; - $sqlmid .= " FROM ".MAIN_DB_PREFIX."paiement_facture as payfac"; - $sqlmid .= " WHERE payfac.fk_paiement=" . $val["paymentid"]; - dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $invoicestatic->fetch($objmid->id); - $ref=$langs->trans("Invoice").' '.$invoicestatic->getNomUrl(1); - } - else dol_print_error($db); - } - elseif ($tabtype[$key] == 'payment_supplier') - { - $sqlmid = 'SELECT payfac.fk_facturefourn as id'; - $sqlmid .= " FROM " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfac"; - $sqlmid .= " WHERE payfac.fk_paiementfourn=" . $val["paymentsupplierid"]; - dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $invoicesupplierstatic->fetch($objmid->id); - $ref=$langs->trans("SupplierInvoice").' '.$invoicesupplierstatic->getNomUrl(1); - } - else dol_print_error($db); - } - elseif ($tabtype[$key] == 'payment_expensereport') - { - $sqlmid = 'SELECT payer.fk_expensereport as id'; - $sqlmid .= " FROM " . MAIN_DB_PREFIX . "payment_expensereport as payer"; - $sqlmid .= " WHERE payer.fk_expensereport=" . $val["fk_expensereport"]; - dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $expensereportstatic->fetch($objmid->id); - $ref=$langs->trans("ExpenseReport").' '.$expensereportstatic->getNomUrl(1); - } - else dol_print_error($db); - } - elseif ($tabtype[$key] == 'payment_vat') - { - $sqlmid = 'SELECT v.rowid as id'; - $sqlmid .= " FROM " . MAIN_DB_PREFIX . "tva as v"; - $sqlmid .= " WHERE v.rowid=" . $val["paymentvatid"]; - dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $vatstatic->fetch($objmid->id); - $ref=$langs->trans("PaymentVat").' '.$vatstatic->getNomUrl(1); - } - else dol_print_error($db); - } - elseif ($tabtype[$key] == 'payment_donation') - { - $sqlmid = 'SELECT payd.fk_donation as id'; - $sqlmid .= " FROM " . MAIN_DB_PREFIX . "payment_donation as payd"; - $sqlmid .= " WHERE payd.fk_donation=" . $val["paymentdonationid"]; - dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $donationstatic->fetch($objmid->id); - $ref=$langs->trans("Donation").' '.$donationstatic->getNomUrl(1); - } - else dol_print_error($db); - } - elseif ($tabtype[$key] == 'payment_salary') - { - $sqlmid = 'SELECT s.rowid as id'; - $sqlmid .= " FROM " . MAIN_DB_PREFIX . "payment_salary as s"; - $sqlmid .= " WHERE s.rowid=" . $val["paymentsalid"]; - dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $salarystatic->fetch($objmid->id); - $ref=$langs->trans("SalaryPayment").' '.$salarystatic->getNomUrl(1); - } - else dol_print_error($db); - } - elseif ($tabtype[$key] == 'payment_various') - { - $sqlmid = 'SELECT v.rowid as id'; - $sqlmid .= " FROM " . MAIN_DB_PREFIX . "payment_various as v"; - $sqlmid .= " WHERE v.rowid=" . $val["paymentvariousid"]; - dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $variousstatic->fetch($objmid->id); - $ref=$langs->trans("VariousPayment").' '.$variousstatic->getNomUrl(1); - } - else dol_print_error($db); - } - - /*$invoicestatic->id = $key; - $invoicestatic->ref = $val["ref"]; - $invoicestatic->type = $val["type"];*/ // Bank foreach ( $tabbq[$key] as $k => $mt ) { @@ -928,18 +801,28 @@ if (empty($action) || $action == 'view') { print ""; print "" . $date . ""; print "" . $ref . ""; + // Ledger account print ""; - $accountoshow = length_accountg($k); - if (empty($accountoshow) || $accountoshow == 'NotDefined') + $accounttoshow = length_accountg($k); + if (empty($accounttoshow) || $accounttoshow == 'NotDefined') { print ''.$langs->trans("BankAccountNotDefined").''; } - else print $accountoshow; + else print $accounttoshow; + print ""; + // Subledger account + print ""; + /*$accounttoshow = length_accountg($k); + if (empty($accounttoshow) || $accounttoshow == 'NotDefined') + { + print ''.$langs->trans("BankAccountNotDefined").''; + } + else print $accounttoshow;*/ print ""; if ($val['soclib'] == '') { - print "" . $bankstatic->label . " - " . $reflabel . ""; + print "" . $langs->trans("Bank") . " - " . $reflabel . ""; } else { - print "" . $bankstatic->label . " - " . $val['soclib'] . ""; + print "" . $langs->trans("Bank") . " - " . $val['soclib'] . ""; } print "" . $val["type_payment"] . ""; print "" . ($mt >= 0 ? price($mt) : '') . ""; @@ -955,13 +838,51 @@ if (empty($action) || $action == 'view') { print ""; print "" . $date . ""; print "" . $ref . ""; + // Ledger account print ""; - $accountoshow = length_accounta($k); - if (empty($accountoshow) || $accountoshow == 'NotDefined') + $account_ledger = $k; + + if ($tabtype[$key] == 'payment') $account_ledger = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER; + if ($tabtype[$key] == 'payment_supplier') $account_ledger = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER; + if ($tabtype[$key] == 'payment_expensereport') $account_ledger = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT; + if ($tabtype[$key] == 'payment_salary') $account_ledger = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT; + if ($tabtype[$key] == 'payment_vat') $account_ledger = $conf->global->ACCOUNTING_VAT_PAY_ACCOUNT; + $accounttoshow = length_accounta($account_ledger); + if (empty($accounttoshow) || $accounttoshow == 'NotDefined') { - print ''.$langs->trans("ThirdpartyAccountNotDefined").''; + if ($tabtype[$key] == 'unknown') + { + // We will accept writing, but into a waiting account + print ''.$langs->trans('UnknownAccountForThirdparty', length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE)).''; // We will a waiting account + } + else + { + // We will refuse writing + $errorstring='UnknownAccountForThirdpartyBlocking'; + if ($tabtype[$key] == 'payment') $errorstring='MainAccountForCustomersNotDefined'; + if ($tabtype[$key] == 'payment_supplier') $errorstring='MainAccountForSuppliersNotDefined'; + if ($tabtype[$key] == 'payment_expensereport') $errorstring='MainAccountForUsersNotDefined'; + if ($tabtype[$key] == 'payment_salary') $errorstring='MainAccountForUsersNotDefined'; + if ($tabtype[$key] == 'payment_vat') $errorstring='MainAccountForVatPaymentNotDefined'; + print ''.$langs->trans($errorstring).''; + } + } + else print $accounttoshow; + print ""; + // Subledger account + print ""; + if (in_array($tabtype[$key], array('payment', 'payment_supplier', 'payment_expensereport', 'payment_salary'))) // Type of payment with subledger + { + $accounttoshowsubledger = length_accounta($k); + if ($accounttoshow != $accounttoshowsubledger) + { + if (empty($accounttoshowsubledger) || $accounttoshowsubledger == 'NotDefined') + { + print ''.$langs->trans("ThirdpartyAccountNotDefined").''; + } + else print $accounttoshowsubledger; + } } - else print $accountoshow; print ""; print "" . $reflabel . ' ' . $val['soclib'] . ""; print "" . $val["type_payment"] . ""; @@ -976,15 +897,25 @@ if (empty($action) || $action == 'view') { print ""; print "" . $date . ""; print "" . $ref . ""; + // Ledger account print ""; - if (empty($accountoshow) || $accountoshow == 'NotDefined') + /*if (empty($accounttoshow) || $accounttoshow == 'NotDefined') + { + print ''.$langs->trans("WaitAccountNotDefined").''; + } + else */ print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE); + print ""; + // Subledger account + print ""; + /*if (empty($accounttoshowsubledger) || $accounttoshowsubledger == 'NotDefined') { print ''.$langs->trans("WaitAccountNotDefined").''; } else print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE); + */ print ""; print "" . $reflabel . ""; - print " "; + print "" . $val["type_payment"] . ""; print "" . ($mt < 0 ? price(- $mt) : '') . ""; print "" . ($mt >= 0 ? price($mt) : '') . ""; print ""; @@ -998,3 +929,157 @@ if (empty($action) || $action == 'view') { } $db->close(); + + + +/** + * Return source for doc_ref of a bank transaction + * + * @param string $val Array of val + * @param string $typerecord Type of record + * @return string|unknown + */ +function getSourceDocRef($val, $typerecord) +{ + global $db, $langs; + + // Defined the docref into $ref (We start with $val['ref'] by default and we complete according to other data) + // WE MUST HAVE SAME REF FOR ALL LINES WE WILL RECORD INTO THE BOOKKEEPING + $reflabel = $val['ref']; + if ($reflabel == '(SupplierInvoicePayment)' || $reflabel == '(SupplierInvoicePaymentBack)') { + $reflabel = $langs->trans('Supplier'); + } + if ($reflabel == '(CustomerInvoicePayment)' || $reflabel == '(CustomerInvoicePaymentBack)') { + $reflabel = $langs->trans('Customer'); + } + if ($reflabel == '(SocialContributionPayment)') { + $reflabel = $langs->trans('SocialContribution'); + } + if ($reflabel == '(DonationPayment)') { + $reflabel = $langs->trans('Donation'); + } + if ($reflabel == '(SubscriptionPayment)') { + $reflabel = $langs->trans('Subscription'); + } + if ($reflabel == '(ExpenseReportPayment)') { + $reflabel = $langs->trans('Employee'); + } + if ($reflabel == '(payment_salary)') { + $reflabel = $langs->trans('Employee'); + } + $ref=$reflabel; + if ($typerecord == 'payment') + { + $sqlmid = 'SELECT payfac.fk_facture as id, f.facnumber as ref'; + $sqlmid .= " FROM ".MAIN_DB_PREFIX."paiement_facture as payfac, ".MAIN_DB_PREFIX."facture as f"; + $sqlmid .= " WHERE payfac.fk_facture = f.rowid AND payfac.fk_paiement=" . $val["paymentid"]; + dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); + $resultmid = $db->query($sqlmid); + if ($resultmid) { + $ref=$langs->trans("Invoice"); + while ($objmid = $db->fetch_object($resultmid)) + { + $ref.=' '.$objmid->ref; + } + } + else dol_print_error($db); + } + elseif ($typerecord == 'payment_supplier') + { + $sqlmid = 'SELECT payfac.fk_facturefourn as id, f.ref'; + $sqlmid .= " FROM " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfac, ".MAIN_DB_PREFIX."facture_fourn as f"; + $sqlmid .= " WHERE payfac.fk_facturefourn = f.rowid AND payfac.fk_paiementfourn=" . $val["paymentsupplierid"]; + dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); + $resultmid = $db->query($sqlmid); + if ($resultmid) { + $ref=$langs->trans("SupplierInvoice"); + while($objmid = $db->fetch_object($resultmid)) + { + $ref.=' '.$objmid->ref; + } + } + else dol_print_error($db); + } + elseif ($typerecord == 'payment_expensereport') + { + $sqlmid = 'SELECT e.rowid as id, e.ref'; + $sqlmid .= " FROM " . MAIN_DB_PREFIX . "payment_expensereport as pe, " . MAIN_DB_PREFIX . "expensereport as e"; + $sqlmid .= " WHERE pe.rowid=" . $val["paymentexpensereport"]." AND pe.fk_expensereport = e.rowid"; + dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); + $resultmid = $db->query($sqlmid); + if ($resultmid) { + $ref=$langs->trans("ExpenseReport"); + while($objmid = $db->fetch_object($resultmid)) + { + $ref.=' '.$objmid->ref; + } + } + else dol_print_error($db); + } + elseif ($typerecord == 'payment_salary') + { + $sqlmid = 'SELECT s.rowid as ref'; + $sqlmid .= " FROM " . MAIN_DB_PREFIX . "payment_salary as s"; + $sqlmid .= " WHERE s.rowid=" . $val["paymentsalid"]; + dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); + $resultmid = $db->query($sqlmid); + if ($resultmid) { + $ref=$langs->trans("SalaryPayment"); + while ($objmid = $db->fetch_object($resultmid)) + { + $ref.=' '.$objmid->ref; + } + } + else dol_print_error($db); + } + elseif ($typerecord == 'payment_vat') + { + $sqlmid = 'SELECT v.rowid as ref'; + $sqlmid .= " FROM " . MAIN_DB_PREFIX . "tva as v"; + $sqlmid .= " WHERE v.rowid=" . $val["paymentvatid"]; + dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); + $resultmid = $db->query($sqlmid); + if ($resultmid) { + $ref=$langs->trans("PaymentVat"); + while ($objmid = $db->fetch_object($resultmid)) + { + $ref.=' '.$objmid->ref; + } + } + else dol_print_error($db); + } + elseif ($typerecord == 'payment_donation') + { + $sqlmid = 'SELECT payd.fk_donation as ref'; + $sqlmid .= " FROM " . MAIN_DB_PREFIX . "payment_donation as payd"; + $sqlmid .= " WHERE payd.fk_donation=" . $val["paymentdonationid"]; + dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); + $resultmid = $db->query($sqlmid); + if ($resultmid) { + $ref=$langs->trans("Donation").' '; + while ($objmid = $db->fetch_object($resultmid)) + { + $ref.=' '.$objmid->ref; + } + } + else dol_print_error($db); + } + elseif ($typerecord == 'payment_various') + { + $sqlmid = 'SELECT v.rowid as ref'; + $sqlmid .= " FROM " . MAIN_DB_PREFIX . "payment_various as v"; + $sqlmid .= " WHERE v.rowid=" . $val["paymentvariousid"]; + dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); + $resultmid = $db->query($sqlmid); + if ($resultmid) { + $ref=$langs->trans("VariousPayment"); + while ($objmid = $db->fetch_object($resultmid)) + { + $ref.=' '.$objmid->ref; + } + } + else dol_print_error($db); + } + + return $ref; +} diff --git a/htdocs/accountancy/journal/expensereportsjournal.php b/htdocs/accountancy/journal/expensereportsjournal.php index e0341b5fa9c..1907cfe7dae 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'); @@ -53,6 +48,7 @@ $date_endmonth = GETPOST('date_endmonth'); $date_endday = GETPOST('date_endday'); $date_endyear = GETPOST('date_endyear'); $in_bookkeeping = GETPOST('in_bookkeeping'); +if ($in_bookkeeping == '') $in_bookkeeping = 'notyet'; $now = dol_now(); @@ -90,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"; @@ -105,26 +101,31 @@ $sql .= " AND erd.fk_code_ventilation > 0"; $sql .= " AND er.entity IN (" . getEntity('expensereport', 0) . ")"; // We don't share object for accountancy if ($date_start && $date_end) $sql .= " AND er.date_debut >= '" . $db->idate($date_start) . "' AND er.date_debut <= '" . $db->idate($date_end) . "'"; -if ($in_bookkeeping == 'yes') +if ($in_bookkeeping == 'already') + $sql .= " AND er.rowid IN (SELECT fk_doc FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab WHERE ab.doc_type='expense_report')"; +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 : $langs->trans("CodeNotDef"); - $account_vat = (! empty($conf->global->ACCOUNTING_VAT_BUY_ACCOUNT)) ? $conf->global->ACCOUNTING_VAT_BUY_ACCOUNT : $langs->trans("CodeNotDef"); $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); @@ -135,6 +136,8 @@ 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)) @@ -146,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), @@ -166,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; @@ -177,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"]; @@ -187,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; @@ -203,7 +215,7 @@ if ($action == 'writebookkeeping') { { $error++; $errorforline++; - //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); + //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); } else { @@ -220,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); @@ -235,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; @@ -251,7 +261,7 @@ if ($action == 'writebookkeeping') { { $error++; $errorforline++; - //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); + //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); } else { @@ -268,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"]; @@ -281,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; @@ -297,7 +313,7 @@ if ($action == 'writebookkeeping') { { $error++; $errorforline++; - //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); + //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); } else { @@ -306,6 +322,7 @@ if ($action == 'writebookkeeping') { setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); } } + } } } } @@ -326,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) @@ -339,6 +356,21 @@ if ($action == 'writebookkeeping') { } $action=''; + + // Must reload data, so we make a redirect + if (count($tabpay) != $error) + { + $param='id_journal='.$id_journal; + $param.='&date_startday='.$date_startday; + $param.='&date_startmonth='.$date_startmonth; + $param.='&date_startyear='.$date_startyear; + $param.='&date_endday='.$date_endday; + $param.='&date_endmonth='.$date_endmonth; + $param.='&date_endyear='.$date_endyear; + $param.='&in_bookeeping='.$in_bookeeping; + header("Location: ".$_SERVER['PHP_SELF'].($param?'?'.$param:'')); + exit; + } } /* @@ -350,7 +382,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'; @@ -469,26 +501,32 @@ if (empty($action) || $action == 'view') { $builddate = time(); $description.= $langs->trans("DescJournalOnlyBindedVisible").'
'; - $period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1). ' - ' .$langs->trans("AlreadyInGeneralLedger").' '. $form->selectyesno('in_bookkeeping',$in_bookkeeping,0); + $listofchoices=array('already'=>$langs->trans("AlreadyInGeneralLedger"), 'notyet'=>$langs->trans("NotYetInGeneralLedger")); + $period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1). ' - ' .$langs->trans("AlreadyInGeneralLedger").' '. $form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1); $varlink = 'id_journal=' . $id_journal; 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 '