bankjournal.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  1. <?php
  2. /* Copyright (C) 2007-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2007-2010 Jean Heimburger <jean@tiaris.info>
  4. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2012 Regis Houssin <regis@dolibarr.fr>
  6. * Copyright (C) 2013 Christophe Battarel <christophe.battarel@altairis.fr>
  7. * Copyright (C) 2013-2017 Alexandre Spangaro <aspangaro@zendsi.com>
  8. * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
  9. * Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \file htdocs/accountancy/journal/bankjournal.php
  26. * \ingroup Advanced accountancy
  27. * \brief Page with bank journal
  28. */
  29. require '../../main.inc.php';
  30. // Class
  31. require_once DOL_DOCUMENT_ROOT . '/core/lib/report.lib.php';
  32. require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
  33. require_once DOL_DOCUMENT_ROOT . '/core/lib/bank.lib.php';
  34. require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
  35. require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
  36. require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
  37. require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php';
  38. require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
  39. require_once DOL_DOCUMENT_ROOT . '/compta/sociales/class/chargesociales.class.php';
  40. require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php';
  41. require_once DOL_DOCUMENT_ROOT . '/don/class/paymentdonation.class.php';
  42. require_once DOL_DOCUMENT_ROOT . '/compta/tva/class/tva.class.php';
  43. require_once DOL_DOCUMENT_ROOT . '/compta/salaries/class/paymentsalary.class.php';
  44. require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
  45. require_once DOL_DOCUMENT_ROOT . '/fourn/class/paiementfourn.class.php';
  46. require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
  47. require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.class.php';
  48. require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
  49. require_once DOL_DOCUMENT_ROOT . '/societe/class/client.class.php';
  50. require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php';
  51. require_once DOL_DOCUMENT_ROOT . '/expensereport/class/paymentexpensereport.class.php';
  52. // Langs
  53. $langs->load("companies");
  54. $langs->load("other");
  55. $langs->load("compta");
  56. $langs->load("banks");
  57. $langs->load('bills');
  58. $langs->load('donations');
  59. $langs->load("accountancy");
  60. $langs->load("trips");
  61. $langs->load("hrm");
  62. // Old system menu
  63. $id_bank_account = GETPOST('id_account', 'int');
  64. // Multi journal
  65. $code_journal = GETPOST('code_journal', 'alpha');
  66. $date_startmonth = GETPOST('date_startmonth');
  67. $date_startday = GETPOST('date_startday');
  68. $date_startyear = GETPOST('date_startyear');
  69. $date_endmonth = GETPOST('date_endmonth');
  70. $date_endday = GETPOST('date_endday');
  71. $date_endyear = GETPOST('date_endyear');
  72. $action = GETPOST('action','aZ09');
  73. $now = dol_now();
  74. // Security check
  75. if ($user->societe_id > 0 && empty($id_bank_account))
  76. accessforbidden();
  77. /*
  78. * Actions
  79. */
  80. $error = 0;
  81. $year_current = strftime("%Y", dol_now());
  82. $pastmonth = strftime("%m", dol_now()) - 1;
  83. $pastmonthyear = $year_current;
  84. if ($pastmonth == 0) {
  85. $pastmonth = 12;
  86. $pastmonthyear --;
  87. }
  88. $date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
  89. $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
  90. if (empty($date_start) || empty($date_end)) // We define date_start and date_end
  91. {
  92. $date_start = dol_get_first_day($pastmonthyear, $pastmonth, false);
  93. $date_end = dol_get_last_day($pastmonthyear, $pastmonth, false);
  94. }
  95. $p = explode(":", $conf->global->MAIN_INFO_SOCIETE_COUNTRY);
  96. $idpays = $p[0];
  97. $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,";
  98. $sql .= " ba.courant, ba.ref as baref, ba.account_number,";
  99. $sql .= " soc.code_compta, soc.code_compta_fournisseur, soc.rowid as socid, soc.nom as name, bu1.type as typeop,";
  100. $sql .= " u.accountancy_code, u.rowid as userid, u.lastname as name, u.firstname as firstname, bu2.type as typeop";
  101. $sql .= " FROM " . MAIN_DB_PREFIX . "bank as b";
  102. $sql .= " JOIN " . MAIN_DB_PREFIX . "bank_account as ba on b.fk_account=ba.rowid";
  103. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'";
  104. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu2 ON bu2.fk_bank = b.rowid AND bu2.type='user'";
  105. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as soc on bu1.url_id=soc.rowid";
  106. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "user as u on bu2.url_id=u.rowid";
  107. $sql .= " WHERE ba.rowid=" . $id_bank_account;
  108. $sql .= ' AND ba.entity IN ('.getEntity('bank_account', 0).')'; // We don't share object for accountancy
  109. if ($date_start && $date_end)
  110. $sql .= " AND b.dateo >= '" . $db->idate($date_start) . "' AND b.dateo <= '" . $db->idate($date_end) . "'";
  111. $sql .= " ORDER BY b.datev";
  112. $object = new Account($db);
  113. $paymentstatic = new Paiement($db);
  114. $paymentsupplierstatic = new PaiementFourn($db);
  115. $societestatic = new Societe($db);
  116. $userstatic = new User($db);
  117. $chargestatic = new ChargeSociales($db);
  118. $paymentdonstatic = new PaymentDonation($db);
  119. $paymentvatstatic = new TVA($db);
  120. $paymentsalstatic = new PaymentSalary($db);
  121. $paymentexpensereportstatic = new PaymentExpenseReport($db);
  122. // Get code of finance journal
  123. $journal = '';
  124. $bankstatic = new Account($db);
  125. $bankstatic->fetch($id_bank_account);
  126. $bankstatic->rowid;
  127. $bankstatic->label;
  128. $bankstatic->fk_accountancy_journal;
  129. $accountingjournalstatic = new AccountingJournal($db);
  130. if(! empty($id_bank_account) {
  131. $accountingjournalstatic->fetch($bankstatic->fk_accountancy_journal);
  132. } else {
  133. $accountingjournalstatic->fetch('',$code_journal);
  134. }
  135. $journal = $accountingjournalstatic->code;
  136. dol_syslog("accountancy/journal/bankjournal.php", LOG_DEBUG);
  137. $result = $db->query($sql);
  138. if ($result) {
  139. $num = $db->num_rows($result);
  140. // Variables
  141. $account_supplier = (! empty($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) ? $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER : $langs->trans("CodeNotDef"));
  142. $account_customer = (! empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : $langs->trans("CodeNotDef"));
  143. $account_employee = (! empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) ? $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT : $langs->trans("CodeNotDef"));
  144. $account_pay_vat = (! empty($conf->global->ACCOUNTING_VAT_PAY_ACCOUNT) ? $conf->global->ACCOUNTING_VAT_PAY_ACCOUNT : $langs->trans("CodeNotDef"));
  145. $account_pay_donation = (! empty($conf->global->DONATION_ACCOUNTINGACCOUNT) ? $conf->global->DONATION_ACCOUNTINGACCOUNT : $langs->trans("CodeNotDef"));
  146. $account_transfer = (! empty($conf->global->ACCOUNTING_ACCOUNT_TRANSFER_CASH) ? $conf->global->ACCOUNTING_ACCOUNT_TRANSFER_CASH : $langs->trans("CodeNotDef"));
  147. $tabcompany = array();
  148. $tabuser = array();
  149. $tabpay = array ();
  150. $tabbq = array ();
  151. $tabtp = array ();
  152. $tabtype = array ();
  153. // Loop on each line into bank account. For each line, we should get:
  154. // on line tabpay = line into bank
  155. // one line for bank jounral = tabbq
  156. // one line for thirdparty journal = tabtp
  157. $i = 0;
  158. while ( $i < $num )
  159. {
  160. $obj = $db->fetch_object($result);
  161. // Set accountancy code (for bank and thirdparty)
  162. $compta_bank = $obj->account_number;
  163. if ($obj->label == '(SupplierInvoicePayment)')
  164. $compta_soc = (! empty($obj->code_compta_fournisseur) ? $obj->code_compta_fournisseur : $account_supplier);
  165. if ($obj->label == '(CustomerInvoicePayment)')
  166. $compta_soc = (! empty($obj->code_compta) ? $obj->code_compta : $account_customer);
  167. $tabcompany[$obj->rowid] = array (
  168. 'id' => $obj->socid,
  169. 'name' => $obj->name,
  170. 'code_compta' => $compta_soc,
  171. );
  172. $compta_user = (! empty($obj->accountancy_code) ? $obj->accountancy_code : $account_employee);
  173. $tabuser[$obj->rowid] = array (
  174. 'id' => $obj->userid,
  175. 'lastname' => $obj->lastname,
  176. 'firstname' => $obj->firstname,
  177. 'accountancy_code' => $compta_user,
  178. );
  179. // Variable bookkeeping
  180. $tabpay[$obj->rowid]["date"] = $obj->do;
  181. $tabpay[$obj->rowid]["type_payment"] = $obj->fk_type;
  182. $tabpay[$obj->rowid]["ref"] = $obj->label;
  183. $tabpay[$obj->rowid]["fk_bank"] = $obj->rowid;
  184. if (preg_match('/^\((.*)\)$/i', $obj->label, $reg)) {
  185. $tabpay[$obj->rowid]["lib"] = $langs->trans($reg[1]);
  186. } else {
  187. $tabpay[$obj->rowid]["lib"] = dol_trunc($obj->label, 60);
  188. }
  189. $links = $object->get_url($obj->rowid);
  190. // get_url may return -1 which is not traversable
  191. if (is_array($links)) {
  192. // Now loop on each link of record in bank.
  193. foreach ( $links as $key => $val ) {
  194. if (in_array($links[$key]['type'], array('sc', 'payment_sc', 'payment', 'payment_supplier', 'payment_vat', 'payment_expensereport', 'banktransfert'))) // So we excluded 'company' here
  195. {
  196. // We save tabtype for a future use, to remember what kind of payment it is
  197. $tabtype[$obj->rowid] = $links[$key]['type'];
  198. }
  199. if ($links[$key]['type'] == 'payment') {
  200. $paymentstatic->id = $links[$key]['url_id'];
  201. $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentstatic->getNomUrl(2);
  202. $tabpay[$obj->rowid]["paymentid"] = $paymentstatic->id;
  203. } else if ($links[$key]['type'] == 'payment_supplier') {
  204. $paymentsupplierstatic->id = $links[$key]['url_id'];
  205. $paymentsupplierstatic->ref = $links[$key]['url_id'];
  206. $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentsupplierstatic->getNomUrl(2);
  207. $tabpay[$obj->rowid]["paymentsupplierid"] = $paymentsupplierstatic->id;
  208. } else if ($links[$key]['type'] == 'company') {
  209. $societestatic->id = $links[$key]['url_id'];
  210. $societestatic->name = $links[$key]['label'];
  211. $tabpay[$obj->rowid]["soclib"] = $societestatic->getNomUrl(1, '', 30);
  212. $tabtp[$obj->rowid][$compta_soc] += $obj->amount;
  213. } else if ($links[$key]['type'] == 'user') {
  214. $userstatic->id = $links[$key]['url_id'];
  215. $userstatic->name = $links[$key]['label'];
  216. $tabpay[$obj->rowid]["soclib"] = $userstatic->getNomUrl(1, '', 30);
  217. $tabtp[$obj->rowid][$compta_user] += $obj->amount;
  218. } else if ($links[$key]['type'] == 'sc') {
  219. $chargestatic->id = $links[$key]['url_id'];
  220. $chargestatic->ref = $links[$key]['url_id'];
  221. $tabpay[$obj->rowid]["lib"] .= ' ' . $chargestatic->getNomUrl(2);
  222. if (preg_match('/^\((.*)\)$/i', $links[$key]['label'], $reg)) {
  223. if ($reg[1] == 'socialcontribution')
  224. $reg[1] = 'SocialContribution';
  225. $chargestatic->lib = $langs->trans($reg[1]);
  226. } else {
  227. $chargestatic->lib = $links[$key]['label'];
  228. }
  229. $chargestatic->ref = $chargestatic->lib;
  230. $tabpay[$obj->rowid]["soclib"] = $chargestatic->getNomUrl(1, 30);
  231. $sqlmid = 'SELECT cchgsoc.accountancy_code';
  232. $sqlmid .= " FROM " . MAIN_DB_PREFIX . "c_chargesociales cchgsoc ";
  233. $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "chargesociales as chgsoc ON chgsoc.fk_type=cchgsoc.id";
  234. $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementcharge as paycharg ON paycharg.fk_charge=chgsoc.rowid";
  235. $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "bank_url as bkurl ON bkurl.url_id=paycharg.rowid";
  236. $sqlmid .= " WHERE bkurl.fk_bank=" . $obj->rowid;
  237. dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
  238. $resultmid = $db->query($sqlmid);
  239. if ($resultmid) {
  240. $objmid = $db->fetch_object($resultmid);
  241. $tabtp[$obj->rowid][$objmid->accountancy_code] += $obj->amount;
  242. }
  243. } else if ($links[$key]['type'] == 'payment_donation') {
  244. $paymentdonstatic->id = $links[$key]['url_id'];
  245. $paymentdonstatic->fk_donation = $links[$key]['url_id'];
  246. $tabpay[$obj->rowid]["lib"] .= ' ' . $langs->trans("PaymentDonation");
  247. $tabtp[$obj->rowid][$account_pay_donation] += $obj->amount;
  248. } else if ($links[$key]['type'] == 'payment_vat') {
  249. $paymentvatstatic->id = $links[$key]['url_id'];
  250. $paymentvatstatic->ref = $links[$key]['url_id'];
  251. $paymentvatstatic->label = $links[$key]['label'];
  252. $tabpay[$obj->rowid]["lib"] .= ' ' . $langs->trans("PaymentVat");
  253. $tabtp[$obj->rowid][$account_pay_vat] += $obj->amount;
  254. } else if ($links[$key]['type'] == 'payment_salary') {
  255. $paymentsalstatic->id = $links[$key]['url_id'];
  256. $paymentsalstatic->ref = $links[$key]['url_id'];
  257. $paymentsalstatic->label = $links[$key]['label'];
  258. $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentsalstatic->getNomUrl(2);
  259. // $tabtp[$obj->rowid][$account_employee] += $obj->amount;
  260. } else if ($links[$key]['type'] == 'payment_expensereport') {
  261. $paymentexpensereportstatic->id = $links[$key]['url_id'];
  262. $paymentexpensereportstatic->fk_expensereport = $links[$key]['url_id'];
  263. $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentexpensereportstatic->getNomUrl(2);
  264. $tabpay[$obj->rowid]["fk_expensereport"] = $paymentexpensereportstatic->id;
  265. } else if ($links[$key]['type'] == 'banktransfert') {
  266. $tabpay[$obj->rowid]["lib"] .= ' ' . $langs->trans("BankTransfer");
  267. $tabtp[$obj->rowid][$account_transfer] += $obj->amount;
  268. }
  269. }
  270. }
  271. $tabbq[$obj->rowid][$compta_bank] += $obj->amount;
  272. // Check account number is ok
  273. /*if ($action == 'writebookkeeping') // Make test now in such a case
  274. {
  275. reset($tabbq[$obj->rowid]);
  276. $first_key_tabbq = key($tabbq[$obj->rowid]);
  277. if (empty($first_key_tabbq))
  278. {
  279. $error++;
  280. setEventMessages($langs->trans('ErrorAccountancyCodeOnBankAccountNotDefined', $obj->baref), null, 'errors');
  281. }
  282. reset($tabtp[$obj->rowid]);
  283. $first_key_tabtp = key($tabtp[$obj->rowid]);
  284. if (empty($first_key_tabtp))
  285. {
  286. $error++;
  287. setEventMessages($langs->trans('ErrorAccountancyCodeOnThirdPartyNotDefined'), null, 'errors');
  288. }
  289. }*/
  290. // if($obj->socid)$tabtp[$obj->rowid][$compta_soc] += $obj->amount;
  291. $i ++;
  292. }
  293. } else {
  294. dol_print_error($db);
  295. }
  296. /*
  297. var_dump($tabpay);
  298. var_dump($tabbq);
  299. var_dump($tabtp);
  300. */
  301. // Write bookkeeping
  302. if (! $error && $action == 'writebookkeeping') {
  303. $now = dol_now();
  304. $error = 0;
  305. foreach ( $tabpay as $key => $val ) { // $key is rowid into llx_bank
  306. $errorforline = 0;
  307. $db->begin();
  308. // Bank
  309. if (! $errorforline)
  310. {
  311. // Line into bank account
  312. foreach ( $tabbq[$key] as $k => $mt )
  313. {
  314. if ($mt) {
  315. $bookkeeping = new BookKeeping($db);
  316. $bookkeeping->doc_date = $val["date"];
  317. $bookkeeping->doc_ref = $val["ref"];
  318. $bookkeeping->doc_type = 'bank';
  319. $bookkeeping->fk_doc = $key;
  320. $bookkeeping->fk_docdet = $val["fk_bank"];
  321. $bookkeeping->numero_compte = $k;
  322. $bookkeeping->label_compte = $compte->label;
  323. $bookkeeping->montant = ($mt < 0 ? - $mt : $mt);
  324. $bookkeeping->sens = ($mt >= 0) ? 'D' : 'C';
  325. $bookkeeping->debit = ($mt >= 0 ? $mt : 0);
  326. $bookkeeping->credit = ($mt < 0 ? - $mt : 0);
  327. $bookkeeping->code_journal = $journal;
  328. $bookkeeping->fk_user_author = $user->id;
  329. $bookkeeping->date_create = $now;
  330. if ($tabtype[$key] == 'payment') {
  331. $bookkeeping->code_tiers = $tabcompany[$key]['code_compta'];
  332. $sqlmid = 'SELECT fac.facnumber';
  333. $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture fac";
  334. $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid";
  335. $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid";
  336. $sqlmid .= " WHERE pay.fk_bank=" . $key;
  337. dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
  338. $resultmid = $db->query($sqlmid);
  339. if ($resultmid) {
  340. $objmid = $db->fetch_object($resultmid);
  341. $bookkeeping->doc_ref = $objmid->facnumber; // Ref of invoice
  342. }
  343. } else if ($tabtype[$key] == 'payment_supplier') {
  344. $bookkeeping->code_tiers = $tabcompany[$key]['code_compta'];
  345. $sqlmid = 'SELECT facf.ref_supplier, facf.ref';
  346. $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf";
  347. $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid";
  348. $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid";
  349. $sqlmid .= " WHERE payf.fk_bank=" . $key;
  350. dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
  351. $resultmid = $db->query($sqlmid);
  352. if ($resultmid) {
  353. $objmid = $db->fetch_object($resultmid);
  354. $bookkeeping->doc_ref = $objmid->ref_supplier . ' (' . $objmid->ref . ')'; // Ref on invoice
  355. }
  356. } else if ($tabtype[$key] == 'payment_expensereport') {
  357. $bookkeeping->code_tiers = $tabuser[$key]['accountancy_code'];
  358. $sqlmid = 'SELECT e.ref';
  359. $sqlmid .= " FROM " . MAIN_DB_PREFIX . "expensereport as e";
  360. $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "payment_expensereport as payer ON payer.fk_expensereport=e.rowid";
  361. $sqlmid .= " WHERE payer.fk_expensereport=" . $val["fk_expensereport"];
  362. dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
  363. $resultmid = $db->query($sqlmid);
  364. if ($resultmid) {
  365. $objmid = $db->fetch_object($resultmid);
  366. $bookkeeping->doc_ref = $objmid->ref; // Ref of expensereport
  367. }
  368. }
  369. $result = $bookkeeping->create($user);
  370. if ($result < 0) {
  371. if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
  372. {
  373. $error++;
  374. $errorforline++;
  375. //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
  376. }
  377. else
  378. {
  379. $error++;
  380. $errorforline++;
  381. setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
  382. }
  383. }
  384. }
  385. }
  386. }
  387. // Third party
  388. if (! $errorforline)
  389. {
  390. // Line into thirdparty account
  391. foreach ( $tabtp[$key] as $k => $mt ) {
  392. if ($mt) {
  393. $bookkeeping = new BookKeeping($db);
  394. $bookkeeping->doc_date = $val["date"];
  395. $bookkeeping->doc_ref = $val["ref"];
  396. $bookkeeping->doc_type = 'bank';
  397. $bookkeeping->fk_doc = $key;
  398. $bookkeeping->fk_docdet = $val["fk_bank"];
  399. $bookkeeping->label_compte = $tabcompany[$key]['name'];
  400. $bookkeeping->montant = ($mt < 0 ? - $mt : $mt);
  401. $bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
  402. $bookkeeping->debit = ($mt < 0 ? - $mt : 0);
  403. $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
  404. $bookkeeping->code_journal = $journal;
  405. $bookkeeping->fk_user_author = $user->id;
  406. $bookkeeping->date_create = $now;
  407. if (in_array($tabtype[$key], array('sc', 'payment_sc'))) { // If payment is payment of social contribution
  408. $bookkeeping->code_tiers = '';
  409. $bookkeeping->numero_compte = $k;
  410. } else if ($tabtype[$key] == 'payment') { // If payment is payment of customer invoice, we get ref of invoice
  411. $sqlmid = 'SELECT fac.facnumber';
  412. $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture fac ";
  413. $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid";
  414. $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid";
  415. $sqlmid .= " WHERE pay.fk_bank=" . $key;
  416. dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
  417. $resultmid = $db->query($sqlmid);
  418. if ($resultmid) {
  419. $objmid = $db->fetch_object($resultmid);
  420. $bookkeeping->doc_ref = $objmid->facnumber;
  421. }
  422. $bookkeeping->code_tiers = $tabcompany[$key]['code_compta'];
  423. $bookkeeping->numero_compte = $k;
  424. } else if ($tabtype[$key] == 'payment_supplier') { // If payment is payment of supplier invoice, we get ref of invoice
  425. $sqlmid = 'SELECT facf.ref_supplier,facf.ref';
  426. $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf ";
  427. $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid";
  428. $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid";
  429. $sqlmid .= " WHERE payf.fk_bank=" . $key;
  430. dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
  431. $resultmid = $db->query($sqlmid);
  432. if ($resultmid) {
  433. $objmid = $db->fetch_object($resultmid);
  434. $bookkeeping->doc_ref = $objmid->ref_supplier . ' (' . $objmid->ref . ')';
  435. }
  436. $bookkeeping->code_tiers = $tabcompany[$key]['code_compta'];
  437. $bookkeeping->numero_compte = $k;
  438. } else if ($tabtype[$key] == 'banktransfert') {
  439. $bookkeeping->code_tiers = '';
  440. $bookkeeping->numero_compte = $k;
  441. } else {
  442. // FIXME Should be a temporary account ???
  443. $bookkeeping->doc_ref = $k;
  444. //$bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
  445. $bookkeeping->numero_compte = 'CodeNotDef';
  446. }
  447. $result = $bookkeeping->create($user);
  448. if ($result < 0) {
  449. if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
  450. {
  451. $error++;
  452. $errorforline++;
  453. //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
  454. }
  455. else
  456. {
  457. $error++;
  458. $errorforline++;
  459. setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
  460. }
  461. }
  462. }
  463. }
  464. }
  465. if (! $errorforline)
  466. {
  467. $db->commit();
  468. }
  469. else
  470. {
  471. $db->rollback();
  472. }
  473. }
  474. if (empty($error)) {
  475. setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
  476. }
  477. elseif (count($tabpay) == $error)
  478. {
  479. setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings');
  480. }
  481. else
  482. {
  483. setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings');
  484. }
  485. $action = '';
  486. }
  487. // Export
  488. /*
  489. if ($action == 'export_csv') {
  490. $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
  491. include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php';
  492. $companystatic = new Client($db);
  493. $userstatic = new User($db);
  494. // Model Cegid Expert Export
  495. if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2)
  496. {
  497. $sep = ";";
  498. foreach ( $tabpay as $key => $val ) {
  499. $date = dol_print_date($db->jdate($val["date"]), '%d%m%Y');
  500. $reflabel = $val["ref"];
  501. if ($reflabel == '(SupplierInvoicePayment)') {
  502. $reflabel = $langs->trans('Supplier');
  503. }
  504. if ($reflabel == '(CustomerInvoicePayment)') {
  505. $reflabel = $langs->trans('Customer');
  506. }
  507. if ($reflabel == '(SocialContributionPayment)') {
  508. $reflabel = $langs->trans('SocialContribution');
  509. }
  510. if ($reflabel == '(DonationPayment)') {
  511. $reflabel = $langs->trans('Donation');
  512. }
  513. if ($reflabel == '(SubscriptionPayment)') {
  514. $reflabel = $langs->trans('Subscription');
  515. }
  516. if ($reflabel == '(ExpenseReportPayment)') {
  517. $reflabel = $langs->trans('Employee');
  518. }
  519. $companystatic->id = $tabcompany[$key]['id'];
  520. $companystatic->name = $tabcompany[$key]['name'];
  521. $userstatic->id = $tabuser[$key]['id'];
  522. $userstatic->lastname = $tabuser[$key]['lastname'];
  523. $userstatic->firstname = $tabuser[$key]['firstname'];
  524. // Bank
  525. foreach ( $tabbq[$key] as $k => $mt ) {
  526. print $date . $sep;
  527. print $journal . $sep;
  528. print length_accountg(html_entity_decode($k)) . $sep;
  529. print $sep;
  530. print ($mt < 0 ? 'C' : 'D') . $sep;
  531. print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
  532. if ($companystatic->name == '') {
  533. print $langs->trans('Bank')." - ". utf8_decode($val["ref"]) . $sep;
  534. } else {
  535. print $langs->trans("Bank") .' - '.utf8_decode($companystatic->name) . $sep;
  536. }
  537. print utf8_decode($reflabel) . $sep;
  538. print "\n";
  539. }
  540. // Third party
  541. if (is_array($tabtp[$key])) {
  542. foreach ( $tabtp[$key] as $k => $mt ) {
  543. if ($mt) {
  544. print $date . $sep;
  545. print $journal . $sep;
  546. if ($tabtype[$key] == 'payment') {
  547. print length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) . $sep;
  548. print length_accounta(html_entity_decode($k)) . $sep;
  549. } else if ($tabtype[$key] == 'payment_supplier') {
  550. print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) . $sep;
  551. print length_accounta(html_entity_decode($k)) . $sep;
  552. } else {
  553. print length_accountg(html_entity_decode($k)) . $sep;
  554. print $sep;
  555. }
  556. print ($mt < 0 ? 'D' : 'C') . $sep;
  557. print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
  558. if ($companystatic->name == '') {
  559. print $langs->trans('ThirdParty')." - ". utf8_decode($val["ref"]) . $sep;
  560. } else {
  561. print $langs->trans('ThirdParty')." - ". utf8_decode($companystatic->name) . $sep;
  562. }
  563. print utf8_decode($reflabel) . $sep;
  564. print "\n";
  565. }
  566. }
  567. } else {
  568. foreach ( $tabbq[$key] as $k => $mt ) {
  569. print $date . $sep;
  570. print $journal . $sep;
  571. print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) . $sep;
  572. print $sep;
  573. print ($mt < 0 ? 'D' : 'C') . $sep;
  574. print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
  575. if ($companystatic->name == '') {
  576. print $langs->trans('ThirdParty')." - ". utf8_decode($val["ref"]) . $sep;
  577. } else {
  578. print $langs->trans('ThirdParty')." - ". utf8_decode($companystatic->name) . $sep;
  579. }
  580. print utf8_decode($reflabel) . $sep;
  581. print "\n";
  582. }
  583. }
  584. }
  585. } else {
  586. // Model Classic Export
  587. foreach ( $tabpay as $key => $val ) {
  588. $date = dol_print_date($db->jdate($val["date"]), 'day');
  589. $companystatic->id = $tabcompany[$key]['id'];
  590. $companystatic->name = $tabcompany[$key]['name'];
  591. // Bank
  592. foreach ( $tabbq[$key] as $k => $mt ) {
  593. print '"' . $journal . '"' . $sep;
  594. print '"' . $date . '"' . $sep;
  595. print '"' . $val["type_payment"] . '"' . $sep;
  596. print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
  597. if ($companystatic->name == '') {
  598. print '"' . $langs->trans('Bank') . " - " . utf8_decode($val["ref"]) . '"' . $sep;
  599. } else {
  600. print '"' . $langs->trans("Bank") . ' - ' . utf8_decode($companystatic->name) . '"' . $sep;
  601. }
  602. print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
  603. print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
  604. print "\n";
  605. }
  606. // Third party
  607. if (is_array($tabtp[$key])) {
  608. foreach ( $tabtp[$key] as $k => $mt ) {
  609. if ($mt) {
  610. print '"' . $journal . '"' . $sep;
  611. print '"' . $date . '"' . $sep;
  612. print '"' . $val["type_payment"] . '"' . $sep;
  613. print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
  614. if ($companystatic->name == '') {
  615. print '"' . $langs->trans('ThirdParty') . " - " . utf8_decode($val["ref"]) . '"' . $sep;
  616. } else {
  617. print '"' . $langs->trans('ThirdParty') . " - " . utf8_decode($companystatic->name) . '"' . $sep;
  618. }
  619. print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
  620. print '"' . ($mt >= 0 ? price($mt) : '') . '"';
  621. print "\n";
  622. }
  623. }
  624. } else {
  625. foreach ( $tabbq[$key] as $k => $mt ) {
  626. print '"' . $journal . '"' . $sep;
  627. print '"' . $date . '"' . $sep;
  628. print '"' . $val["ref"] . '"' . $sep;
  629. print '"' . length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) . '"' . $sep;
  630. if ($companystatic->name == '') {
  631. print '"' . $langs->trans("Bank") . ' - ' . utf8_decode($val["ref"]) . '"' . $sep;
  632. } else {
  633. print '"' . $langs->trans("Bank") . ' - ' . utf8_decode($companystatic->name) . '"' . $sep;
  634. }
  635. print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
  636. print '"' . ($mt >= 0 ? price($mt) : '') . '"';
  637. print "\n";
  638. }
  639. }
  640. }
  641. }
  642. }
  643. */
  644. /*
  645. * View
  646. */
  647. $form = new Form($db);
  648. if (empty($action) || $action == 'view') {
  649. $invoicestatic = new Facture($db);
  650. $invoicesupplierstatic = new FactureFournisseur($db);
  651. $expensereportstatic = new ExpenseReport($db);
  652. llxHeader('', $langs->trans("FinanceJournal"));
  653. $nom = $langs->trans("FinanceJournal") . ' - ' . $bankstatic->getNomUrl(1);
  654. $builddate = time();
  655. //$description = $langs->trans("DescFinanceJournal") . '<br>';
  656. $description.= $langs->trans("DescJournalOnlyBindedVisible").'<br>';
  657. $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);
  658. $varlink = 'id_account=' . $id_bank_account;
  659. journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink);
  660. /*if ($conf->global->ACCOUNTING_EXPORT_MODELCSV != 1 && $conf->global->ACCOUNTING_EXPORT_MODELCSV != 2) {
  661. print '<input type="button" class="butActionRefused" style="float: right;" value="' . $langs->trans('Export') . '" disabled="disabled" title="' . $langs->trans('ExportNotSupported') . '"/>';
  662. } else {
  663. print '<input type="button" class="butAction" style="float: right;" value="' . $langs->trans("Export") . '" onclick="launch_export();" />';
  664. }*/
  665. print '<div class="tabsAction">';
  666. print '<input type="button" class="butAction" value="' . $langs->trans("WriteBookKeeping") . '" onclick="writebookkeeping();" />';
  667. print '</div>';
  668. // TODO Avoid using js. We can use a direct link with $param
  669. print '
  670. <script type="text/javascript">
  671. function launch_export() {
  672. console.log("Set value into form and submit");
  673. $("div.fiche div.tabBar form input[name=\"action\"]").val("export_csv");
  674. $("div.fiche div.tabBar form input[type=\"submit\"]").click();
  675. $("div.fiche div.tabBar form input[name=\"action\"]").val("");
  676. }
  677. function writebookkeeping() {
  678. console.log("Set value into form and submit");
  679. $("div.fiche div.tabBar form input[name=\"action\"]").val("writebookkeeping");
  680. $("div.fiche div.tabBar form input[type=\"submit\"]").click();
  681. $("div.fiche div.tabBar form input[name=\"action\"]").val("");
  682. }
  683. </script>';
  684. /*
  685. * Show result array
  686. */
  687. print '<br>';
  688. $i = 0;
  689. print "<table class=\"noborder\" width=\"100%\">";
  690. print "<tr class=\"liste_titre\">";
  691. print "<td></td>";
  692. print "<td>" . $langs->trans("Date") . "</td>";
  693. print "<td>" . $langs->trans("Piece") . ' (' . $langs->trans("InvoiceRef") . ")</td>";
  694. print "<td>" . $langs->trans("AccountAccounting") . "</td>";
  695. print "<td>" . $langs->trans("Type") . "</td>";
  696. print "<td>" . $langs->trans("PaymentMode") . "</td>";
  697. print "<td align='right'>" . $langs->trans("Debit") . "</td>";
  698. print "<td align='right'>" . $langs->trans("Credit") . "</td>";
  699. print "</tr>\n";
  700. $r = '';
  701. foreach ( $tabpay as $key => $val ) { // $key is rowid in llx_bank
  702. $date = dol_print_date($db->jdate($val["date"]), 'day');
  703. $reflabel = $val["ref"];
  704. if ($reflabel == '(SupplierInvoicePayment)') {
  705. $reflabel = $langs->trans('Supplier');
  706. }
  707. if ($reflabel == '(CustomerInvoicePayment)') {
  708. $reflabel = $langs->trans('Customer');
  709. }
  710. if ($reflabel == '(SocialContributionPayment)') {
  711. $reflabel = $langs->trans('SocialContribution');
  712. }
  713. if ($reflabel == '(DonationPayment)') {
  714. $reflabel = $langs->trans('Donation');
  715. }
  716. if ($reflabel == '(SubscriptionPayment)') {
  717. $reflabel = $langs->trans('Subscription');
  718. }
  719. if ($reflabel == '(ExpenseReportPayment)') {
  720. $reflabel = $langs->trans('Employee');
  721. }
  722. $ref=$reflabel;
  723. if ($tabtype[$key] == 'payment')
  724. {
  725. $sqlmid = 'SELECT payfac.fk_facture as id';
  726. $sqlmid .= " FROM ".MAIN_DB_PREFIX."paiement_facture as payfac";
  727. $sqlmid .= " WHERE payfac.fk_paiement=" . $val["paymentid"];
  728. dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG);
  729. $resultmid = $db->query($sqlmid);
  730. if ($resultmid) {
  731. $objmid = $db->fetch_object($resultmid);
  732. $invoicestatic->fetch($objmid->id);
  733. $ref=$langs->trans("Invoice").' '.$invoicestatic->getNomUrl(1);
  734. }
  735. else dol_print_error($db);
  736. }
  737. elseif ($tabtype[$key] == 'payment_supplier')
  738. {
  739. $sqlmid = 'SELECT payfac.fk_facturefourn as id';
  740. $sqlmid .= " FROM " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfac";
  741. $sqlmid .= " WHERE payfac.fk_paiementfourn=" . $val["paymentsupplierid"];
  742. dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG);
  743. $resultmid = $db->query($sqlmid);
  744. if ($resultmid) {
  745. $objmid = $db->fetch_object($resultmid);
  746. $invoicesupplierstatic->fetch($objmid->id);
  747. $ref=$langs->trans("SupplierInvoice").' '.$invoicesupplierstatic->getNomUrl(1);
  748. }
  749. else dol_print_error($db);
  750. }
  751. elseif ($tabtype[$key] == 'payment_expensereport')
  752. {
  753. $sqlmid = 'SELECT payer.fk_expensereport as id';
  754. $sqlmid .= " FROM " . MAIN_DB_PREFIX . "payment_expensereport as payer";
  755. $sqlmid .= " WHERE payer.fk_expensereport=" . $val["fk_expensereport"];
  756. dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG);
  757. $resultmid = $db->query($sqlmid);
  758. if ($resultmid) {
  759. $objmid = $db->fetch_object($resultmid);
  760. $expensereportstatic->fetch($objmid->id);
  761. $ref=$langs->trans("ExpenseReport").' '.$expensereportstatic->getNomUrl(1);
  762. }
  763. else dol_print_error($db);
  764. }
  765. /*$invoicestatic->id = $key;
  766. $invoicestatic->ref = $val["ref"];
  767. $invoicestatic->type = $val["type"];*/
  768. // Bank
  769. foreach ( $tabbq[$key] as $k => $mt )
  770. {
  771. print '<tr class="oddeven">';
  772. print "<td><!-- Bank bank.rowid=".$key."--></td>";
  773. print "<td>" . $date . "</td>";
  774. print "<td>" . $ref . "</td>";
  775. print "<td>";
  776. $accountoshow = length_accountg($k);
  777. if (empty($accountoshow) || $accountoshow == 'NotDefined')
  778. {
  779. print '<span class="error">'.$langs->trans("BankAccountNotDefined").'</span>';
  780. }
  781. else print $accountoshow;
  782. print "</td>";
  783. if ($val['soclib'] == '') {
  784. print "<td>" . $bank_code_journal->label . " - " . $val["ref"] . "</td>";
  785. } else {
  786. print "<td>" . $bank_code_journal->label . " - " . $val['soclib'] . "</td>";
  787. }
  788. print "<td>" . $val["type_payment"] . "</td>";
  789. print "<td align='right'>" . ($mt >= 0 ? price($mt) : '') . "</td>";
  790. print "<td align='right'>" . ($mt < 0 ? price(- $mt) : '') . "</td>";
  791. print "</tr>";
  792. }
  793. // Third party
  794. if (is_array($tabtp[$key])) {
  795. foreach ( $tabtp[$key] as $k => $mt ) {
  796. if ($k != 'type') {
  797. print '<tr class="oddeven">';
  798. print "<td><!-- Thirdparty bank.rowid=".$key." --></td>";
  799. print "<td>" . $date . "</td>";
  800. print "<td>" . $ref . "</td>";
  801. print "<td>";
  802. $accountoshow = length_accounta($k);
  803. if (empty($accountoshow) || $accountoshow == 'NotDefined')
  804. {
  805. print '<span class="error">'.$langs->trans("ThirdpartyAccountNotDefined").'</span>';
  806. }
  807. else print $accountoshow;
  808. print "</td>";
  809. print "<td>" . $reflabel . ' ' . $val['soclib'] . "</td>";
  810. print "<td>" . $val["type_payment"] . "</td>";
  811. print "<td align='right'>" . ($mt < 0 ? price(- $mt) : '') . "</td>";
  812. print "<td align='right'>" . ($mt >= 0 ? price($mt) : '') . "</td>";
  813. print "</tr>";
  814. }
  815. }
  816. } else {
  817. foreach ( $tabbq[$key] as $k => $mt ) {
  818. print '<tr class="oddeven">';
  819. print "<td><!-- Wait bank.rowid=".$key." --></td>";
  820. print "<td>" . $date . "</td>";
  821. print "<td>" . $ref . "</td>";
  822. print "<td>";
  823. if (empty($accountoshow) || $accountoshow == 'NotDefined')
  824. {
  825. print '<span class="error">'.$langs->trans("WaitAccountNotDefined").'</span>';
  826. }
  827. else print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE);
  828. print "</td>";
  829. print "<td>" . $reflabel . "</td>";
  830. print "<td>&nbsp;</td>";
  831. print "<td align='right'>" . ($mt < 0 ? price(- $mt) : '') . "</td>";
  832. print "<td align='right'>" . ($mt >= 0 ? price($mt) : '') . "</td>";
  833. print "</tr>";
  834. }
  835. }
  836. }
  837. print "</table>";
  838. llxFooter();
  839. }
  840. $db->close();