bankjournal.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  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->number;
  128. $bankstatic->label;
  129. $bankstatic->fk_accountancy_journal;
  130. $accountingjournalstatic = new AccountingJournal($db);
  131. if(! empty($id_bank_account)) {
  132. $accountingjournalstatic->fetch($bankstatic->fk_accountancy_journal);
  133. } else {
  134. $accountingjournalstatic->fetch('',$code_journal);
  135. }
  136. $journal = $accountingjournalstatic->code;
  137. dol_syslog("accountancy/journal/bankjournal.php", LOG_DEBUG);
  138. $result = $db->query($sql);
  139. if ($result) {
  140. $num = $db->num_rows($result);
  141. // Variables
  142. $account_supplier = (! empty($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) ? $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER : $langs->trans("CodeNotDef"));
  143. $account_customer = (! empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : $langs->trans("CodeNotDef"));
  144. $account_employee = (! empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) ? $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT : $langs->trans("CodeNotDef"));
  145. $account_pay_vat = (! empty($conf->global->ACCOUNTING_VAT_PAY_ACCOUNT) ? $conf->global->ACCOUNTING_VAT_PAY_ACCOUNT : $langs->trans("CodeNotDef"));
  146. $account_pay_donation = (! empty($conf->global->DONATION_ACCOUNTINGACCOUNT) ? $conf->global->DONATION_ACCOUNTINGACCOUNT : $langs->trans("CodeNotDef"));
  147. $account_transfer = (! empty($conf->global->ACCOUNTING_ACCOUNT_TRANSFER_CASH) ? $conf->global->ACCOUNTING_ACCOUNT_TRANSFER_CASH : $langs->trans("CodeNotDef"));
  148. $tabcompany = array();
  149. $tabuser = array();
  150. $tabpay = array ();
  151. $tabbq = array ();
  152. $tabtp = array ();
  153. $tabtype = array ();
  154. // Loop on each line into bank account. For each line, we should get:
  155. // on line tabpay = line into bank
  156. // one line for bank jounral = tabbq
  157. // one line for thirdparty journal = tabtp
  158. $i = 0;
  159. while ( $i < $num )
  160. {
  161. $obj = $db->fetch_object($result);
  162. // Set accountancy code (for bank and thirdparty)
  163. $compta_bank = $obj->account_number;
  164. if ($obj->label == '(SupplierInvoicePayment)')
  165. $compta_soc = (! empty($obj->code_compta_fournisseur) ? $obj->code_compta_fournisseur : $account_supplier);
  166. if ($obj->label == '(CustomerInvoicePayment)')
  167. $compta_soc = (! empty($obj->code_compta) ? $obj->code_compta : $account_customer);
  168. $tabcompany[$obj->rowid] = array (
  169. 'id' => $obj->socid,
  170. 'name' => $obj->name,
  171. 'code_compta' => $compta_soc,
  172. );
  173. $compta_user = (! empty($obj->accountancy_code) ? $obj->accountancy_code : $account_employee);
  174. $tabuser[$obj->rowid] = array (
  175. 'id' => $obj->userid,
  176. 'lastname' => $obj->lastname,
  177. 'firstname' => $obj->firstname,
  178. 'accountancy_code' => $compta_user,
  179. );
  180. // Variable bookkeeping
  181. $tabpay[$obj->rowid]["date"] = $obj->do;
  182. $tabpay[$obj->rowid]["type_payment"] = $obj->fk_type;
  183. $tabpay[$obj->rowid]["ref"] = $obj->label;
  184. $tabpay[$obj->rowid]["fk_bank"] = $obj->rowid;
  185. if (preg_match('/^\((.*)\)$/i', $obj->label, $reg)) {
  186. $tabpay[$obj->rowid]["lib"] = $langs->trans($reg[1]);
  187. } else {
  188. $tabpay[$obj->rowid]["lib"] = dol_trunc($obj->label, 60);
  189. }
  190. $links = $object->get_url($obj->rowid);
  191. // get_url may return -1 which is not traversable
  192. if (is_array($links)) {
  193. // Now loop on each link of record in bank.
  194. foreach ( $links as $key => $val ) {
  195. if (in_array($links[$key]['type'], array('sc', 'payment_sc', 'payment', 'payment_supplier', 'payment_vat', 'payment_expensereport', 'banktransfert'))) // So we excluded 'company' here
  196. {
  197. // We save tabtype for a future use, to remember what kind of payment it is
  198. $tabtype[$obj->rowid] = $links[$key]['type'];
  199. }
  200. if ($links[$key]['type'] == 'payment') {
  201. $paymentstatic->id = $links[$key]['url_id'];
  202. $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentstatic->getNomUrl(2);
  203. $tabpay[$obj->rowid]["paymentid"] = $paymentstatic->id;
  204. } else if ($links[$key]['type'] == 'payment_supplier') {
  205. $paymentsupplierstatic->id = $links[$key]['url_id'];
  206. $paymentsupplierstatic->ref = $links[$key]['url_id'];
  207. $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentsupplierstatic->getNomUrl(2);
  208. $tabpay[$obj->rowid]["paymentsupplierid"] = $paymentsupplierstatic->id;
  209. } else if ($links[$key]['type'] == 'company') {
  210. $societestatic->id = $links[$key]['url_id'];
  211. $societestatic->name = $links[$key]['label'];
  212. $tabpay[$obj->rowid]["soclib"] = $societestatic->getNomUrl(1, '', 30);
  213. $tabtp[$obj->rowid][$compta_soc] += $obj->amount;
  214. } else if ($links[$key]['type'] == 'user') {
  215. $userstatic->id = $links[$key]['url_id'];
  216. $userstatic->name = $links[$key]['label'];
  217. $tabpay[$obj->rowid]["soclib"] = $userstatic->getNomUrl(1, '', 30);
  218. $tabtp[$obj->rowid][$compta_user] += $obj->amount;
  219. } else if ($links[$key]['type'] == 'sc') {
  220. $chargestatic->id = $links[$key]['url_id'];
  221. $chargestatic->ref = $links[$key]['url_id'];
  222. $tabpay[$obj->rowid]["lib"] .= ' ' . $chargestatic->getNomUrl(2);
  223. if (preg_match('/^\((.*)\)$/i', $links[$key]['label'], $reg)) {
  224. if ($reg[1] == 'socialcontribution')
  225. $reg[1] = 'SocialContribution';
  226. $chargestatic->lib = $langs->trans($reg[1]);
  227. } else {
  228. $chargestatic->lib = $links[$key]['label'];
  229. }
  230. $chargestatic->ref = $chargestatic->lib;
  231. $tabpay[$obj->rowid]["soclib"] = $chargestatic->getNomUrl(1, 30);
  232. $sqlmid = 'SELECT cchgsoc.accountancy_code';
  233. $sqlmid .= " FROM " . MAIN_DB_PREFIX . "c_chargesociales cchgsoc ";
  234. $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "chargesociales as chgsoc ON chgsoc.fk_type=cchgsoc.id";
  235. $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementcharge as paycharg ON paycharg.fk_charge=chgsoc.rowid";
  236. $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "bank_url as bkurl ON bkurl.url_id=paycharg.rowid";
  237. $sqlmid .= " WHERE bkurl.fk_bank=" . $obj->rowid;
  238. dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
  239. $resultmid = $db->query($sqlmid);
  240. if ($resultmid) {
  241. $objmid = $db->fetch_object($resultmid);
  242. $tabtp[$obj->rowid][$objmid->accountancy_code] += $obj->amount;
  243. }
  244. } else if ($links[$key]['type'] == 'payment_donation') {
  245. $paymentdonstatic->id = $links[$key]['url_id'];
  246. $paymentdonstatic->fk_donation = $links[$key]['url_id'];
  247. $tabpay[$obj->rowid]["lib"] .= ' ' . $langs->trans("PaymentDonation");
  248. $tabtp[$obj->rowid][$account_pay_donation] += $obj->amount;
  249. } else if ($links[$key]['type'] == 'payment_vat') {
  250. $paymentvatstatic->id = $links[$key]['url_id'];
  251. $paymentvatstatic->ref = $links[$key]['url_id'];
  252. $paymentvatstatic->label = $links[$key]['label'];
  253. $tabpay[$obj->rowid]["lib"] .= ' ' . $langs->trans("PaymentVat");
  254. $tabtp[$obj->rowid][$account_pay_vat] += $obj->amount;
  255. } else if ($links[$key]['type'] == 'payment_salary') {
  256. $paymentsalstatic->id = $links[$key]['url_id'];
  257. $paymentsalstatic->ref = $links[$key]['url_id'];
  258. $paymentsalstatic->label = $links[$key]['label'];
  259. $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentsalstatic->getNomUrl(2);
  260. // $tabtp[$obj->rowid][$account_employee] += $obj->amount;
  261. } else if ($links[$key]['type'] == 'payment_expensereport') {
  262. $paymentexpensereportstatic->id = $links[$key]['url_id'];
  263. $paymentexpensereportstatic->fk_expensereport = $links[$key]['url_id'];
  264. $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentexpensereportstatic->getNomUrl(2);
  265. $tabpay[$obj->rowid]["fk_expensereport"] = $paymentexpensereportstatic->id;
  266. } else if ($links[$key]['type'] == 'banktransfert') {
  267. $tabpay[$obj->rowid]["lib"] .= ' ' . $langs->trans("BankTransfer");
  268. $tabtp[$obj->rowid][$account_transfer] += $obj->amount;
  269. }
  270. }
  271. }
  272. $tabbq[$obj->rowid][$compta_bank] += $obj->amount;
  273. // Check account number is ok
  274. /*if ($action == 'writebookkeeping') // Make test now in such a case
  275. {
  276. reset($tabbq[$obj->rowid]);
  277. $first_key_tabbq = key($tabbq[$obj->rowid]);
  278. if (empty($first_key_tabbq))
  279. {
  280. $error++;
  281. setEventMessages($langs->trans('ErrorAccountancyCodeOnBankAccountNotDefined', $obj->baref), null, 'errors');
  282. }
  283. reset($tabtp[$obj->rowid]);
  284. $first_key_tabtp = key($tabtp[$obj->rowid]);
  285. if (empty($first_key_tabtp))
  286. {
  287. $error++;
  288. setEventMessages($langs->trans('ErrorAccountancyCodeOnThirdPartyNotDefined'), null, 'errors');
  289. }
  290. }*/
  291. // if($obj->socid)$tabtp[$obj->rowid][$compta_soc] += $obj->amount;
  292. $i ++;
  293. }
  294. } else {
  295. dol_print_error($db);
  296. }
  297. /*
  298. var_dump($tabpay);
  299. var_dump($tabbq);
  300. var_dump($tabtp);
  301. */
  302. // Write bookkeeping
  303. if (! $error && $action == 'writebookkeeping') {
  304. $now = dol_now();
  305. $error = 0;
  306. foreach ( $tabpay as $key => $val ) { // $key is rowid into llx_bank
  307. $errorforline = 0;
  308. $db->begin();
  309. // Bank
  310. if (! $errorforline)
  311. {
  312. // Line into bank account
  313. foreach ( $tabbq[$key] as $k => $mt )
  314. {
  315. if ($mt) {
  316. $bookkeeping = new BookKeeping($db);
  317. $bookkeeping->doc_date = $val["date"];
  318. $bookkeeping->doc_ref = $val["ref"];
  319. $bookkeeping->doc_type = 'bank';
  320. $bookkeeping->fk_doc = $key;
  321. $bookkeeping->fk_docdet = $val["fk_bank"];
  322. $bookkeeping->numero_compte = $k;
  323. $bookkeeping->label_compte = $compte->label;
  324. $bookkeeping->montant = ($mt < 0 ? - $mt : $mt);
  325. $bookkeeping->sens = ($mt >= 0) ? 'D' : 'C';
  326. $bookkeeping->debit = ($mt >= 0 ? $mt : 0);
  327. $bookkeeping->credit = ($mt < 0 ? - $mt : 0);
  328. $bookkeeping->code_journal = $journal;
  329. $bookkeeping->fk_user_author = $user->id;
  330. $bookkeeping->date_create = $now;
  331. if ($tabtype[$key] == 'payment') {
  332. $bookkeeping->code_tiers = $tabcompany[$key]['code_compta'];
  333. $sqlmid = 'SELECT fac.facnumber';
  334. $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture fac";
  335. $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid";
  336. $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid";
  337. $sqlmid .= " WHERE pay.fk_bank=" . $key;
  338. dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
  339. $resultmid = $db->query($sqlmid);
  340. if ($resultmid) {
  341. $objmid = $db->fetch_object($resultmid);
  342. $bookkeeping->doc_ref = $objmid->facnumber; // Ref of invoice
  343. }
  344. } else if ($tabtype[$key] == 'payment_supplier') {
  345. $bookkeeping->code_tiers = $tabcompany[$key]['code_compta'];
  346. $sqlmid = 'SELECT facf.ref_supplier, facf.ref';
  347. $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf";
  348. $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid";
  349. $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid";
  350. $sqlmid .= " WHERE payf.fk_bank=" . $key;
  351. dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
  352. $resultmid = $db->query($sqlmid);
  353. if ($resultmid) {
  354. $objmid = $db->fetch_object($resultmid);
  355. $bookkeeping->doc_ref = $objmid->ref_supplier . ' (' . $objmid->ref . ')'; // Ref on invoice
  356. }
  357. } else if ($tabtype[$key] == 'payment_expensereport') {
  358. $bookkeeping->code_tiers = $tabuser[$key]['accountancy_code'];
  359. $sqlmid = 'SELECT e.ref';
  360. $sqlmid .= " FROM " . MAIN_DB_PREFIX . "expensereport as e";
  361. $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "payment_expensereport as payer ON payer.fk_expensereport=e.rowid";
  362. $sqlmid .= " WHERE payer.fk_expensereport=" . $val["fk_expensereport"];
  363. dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
  364. $resultmid = $db->query($sqlmid);
  365. if ($resultmid) {
  366. $objmid = $db->fetch_object($resultmid);
  367. $bookkeeping->doc_ref = $objmid->ref; // Ref of expensereport
  368. }
  369. }
  370. $result = $bookkeeping->create($user);
  371. if ($result < 0) {
  372. if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
  373. {
  374. $error++;
  375. $errorforline++;
  376. //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
  377. }
  378. else
  379. {
  380. $error++;
  381. $errorforline++;
  382. setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
  383. }
  384. }
  385. }
  386. }
  387. }
  388. // Third party
  389. if (! $errorforline)
  390. {
  391. // Line into thirdparty account
  392. foreach ( $tabtp[$key] as $k => $mt ) {
  393. if ($mt) {
  394. $bookkeeping = new BookKeeping($db);
  395. $bookkeeping->doc_date = $val["date"];
  396. $bookkeeping->doc_ref = $val["ref"];
  397. $bookkeeping->doc_type = 'bank';
  398. $bookkeeping->fk_doc = $key;
  399. $bookkeeping->fk_docdet = $val["fk_bank"];
  400. $bookkeeping->label_compte = $tabcompany[$key]['name'];
  401. $bookkeeping->montant = ($mt < 0 ? - $mt : $mt);
  402. $bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
  403. $bookkeeping->debit = ($mt < 0 ? - $mt : 0);
  404. $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
  405. $bookkeeping->code_journal = $journal;
  406. $bookkeeping->fk_user_author = $user->id;
  407. $bookkeeping->date_create = $now;
  408. if (in_array($tabtype[$key], array('sc', 'payment_sc'))) { // If payment is payment of social contribution
  409. $bookkeeping->code_tiers = '';
  410. $bookkeeping->numero_compte = $k;
  411. } else if ($tabtype[$key] == 'payment') { // If payment is payment of customer invoice, we get ref of invoice
  412. $sqlmid = 'SELECT fac.facnumber';
  413. $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture fac ";
  414. $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid";
  415. $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid";
  416. $sqlmid .= " WHERE pay.fk_bank=" . $key;
  417. dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
  418. $resultmid = $db->query($sqlmid);
  419. if ($resultmid) {
  420. $objmid = $db->fetch_object($resultmid);
  421. $bookkeeping->doc_ref = $objmid->facnumber;
  422. }
  423. $bookkeeping->code_tiers = $tabcompany[$key]['code_compta'];
  424. $bookkeeping->numero_compte = $k;
  425. } else if ($tabtype[$key] == 'payment_supplier') { // If payment is payment of supplier invoice, we get ref of invoice
  426. $sqlmid = 'SELECT facf.ref_supplier,facf.ref';
  427. $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf ";
  428. $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid";
  429. $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid";
  430. $sqlmid .= " WHERE payf.fk_bank=" . $key;
  431. dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
  432. $resultmid = $db->query($sqlmid);
  433. if ($resultmid) {
  434. $objmid = $db->fetch_object($resultmid);
  435. $bookkeeping->doc_ref = $objmid->ref_supplier . ' (' . $objmid->ref . ')';
  436. }
  437. $bookkeeping->code_tiers = $tabcompany[$key]['code_compta'];
  438. $bookkeeping->numero_compte = $k;
  439. } else if ($tabtype[$key] == 'banktransfert') {
  440. $bookkeeping->code_tiers = '';
  441. $bookkeeping->numero_compte = $k;
  442. } else {
  443. // FIXME Should be a temporary account ???
  444. $bookkeeping->doc_ref = $k;
  445. //$bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
  446. $bookkeeping->numero_compte = 'CodeNotDef';
  447. }
  448. $result = $bookkeeping->create($user);
  449. if ($result < 0) {
  450. if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
  451. {
  452. $error++;
  453. $errorforline++;
  454. //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
  455. }
  456. else
  457. {
  458. $error++;
  459. $errorforline++;
  460. setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
  461. }
  462. }
  463. }
  464. }
  465. }
  466. if (! $errorforline)
  467. {
  468. $db->commit();
  469. }
  470. else
  471. {
  472. $db->rollback();
  473. }
  474. }
  475. if (empty($error)) {
  476. setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
  477. }
  478. elseif (count($tabpay) == $error)
  479. {
  480. setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings');
  481. }
  482. else
  483. {
  484. setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings');
  485. }
  486. $action = '';
  487. }
  488. // Export
  489. /*
  490. if ($action == 'export_csv') {
  491. $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
  492. include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php';
  493. $companystatic = new Client($db);
  494. $userstatic = new User($db);
  495. // Model Cegid Expert Export
  496. if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2)
  497. {
  498. $sep = ";";
  499. foreach ( $tabpay as $key => $val ) {
  500. $date = dol_print_date($db->jdate($val["date"]), '%d%m%Y');
  501. $reflabel = $val["ref"];
  502. if ($reflabel == '(SupplierInvoicePayment)') {
  503. $reflabel = $langs->trans('Supplier');
  504. }
  505. if ($reflabel == '(CustomerInvoicePayment)') {
  506. $reflabel = $langs->trans('Customer');
  507. }
  508. if ($reflabel == '(SocialContributionPayment)') {
  509. $reflabel = $langs->trans('SocialContribution');
  510. }
  511. if ($reflabel == '(DonationPayment)') {
  512. $reflabel = $langs->trans('Donation');
  513. }
  514. if ($reflabel == '(SubscriptionPayment)') {
  515. $reflabel = $langs->trans('Subscription');
  516. }
  517. if ($reflabel == '(ExpenseReportPayment)') {
  518. $reflabel = $langs->trans('Employee');
  519. }
  520. $companystatic->id = $tabcompany[$key]['id'];
  521. $companystatic->name = $tabcompany[$key]['name'];
  522. $userstatic->id = $tabuser[$key]['id'];
  523. $userstatic->lastname = $tabuser[$key]['lastname'];
  524. $userstatic->firstname = $tabuser[$key]['firstname'];
  525. // Bank
  526. foreach ( $tabbq[$key] as $k => $mt ) {
  527. print $date . $sep;
  528. print $journal . $sep;
  529. print length_accountg(html_entity_decode($k)) . $sep;
  530. print $sep;
  531. print ($mt < 0 ? 'C' : 'D') . $sep;
  532. print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
  533. if ($companystatic->name == '') {
  534. print $langs->trans('Bank')." - ". utf8_decode($val["ref"]) . $sep;
  535. } else {
  536. print $langs->trans("Bank") .' - '.utf8_decode($companystatic->name) . $sep;
  537. }
  538. print utf8_decode($reflabel) . $sep;
  539. print "\n";
  540. }
  541. // Third party
  542. if (is_array($tabtp[$key])) {
  543. foreach ( $tabtp[$key] as $k => $mt ) {
  544. if ($mt) {
  545. print $date . $sep;
  546. print $journal . $sep;
  547. if ($tabtype[$key] == 'payment') {
  548. print length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) . $sep;
  549. print length_accounta(html_entity_decode($k)) . $sep;
  550. } else if ($tabtype[$key] == 'payment_supplier') {
  551. print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) . $sep;
  552. print length_accounta(html_entity_decode($k)) . $sep;
  553. } else {
  554. print length_accountg(html_entity_decode($k)) . $sep;
  555. print $sep;
  556. }
  557. print ($mt < 0 ? 'D' : 'C') . $sep;
  558. print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
  559. if ($companystatic->name == '') {
  560. print $langs->trans('ThirdParty')." - ". utf8_decode($val["ref"]) . $sep;
  561. } else {
  562. print $langs->trans('ThirdParty')." - ". utf8_decode($companystatic->name) . $sep;
  563. }
  564. print utf8_decode($reflabel) . $sep;
  565. print "\n";
  566. }
  567. }
  568. } else {
  569. foreach ( $tabbq[$key] as $k => $mt ) {
  570. print $date . $sep;
  571. print $journal . $sep;
  572. print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) . $sep;
  573. print $sep;
  574. print ($mt < 0 ? 'D' : 'C') . $sep;
  575. print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
  576. if ($companystatic->name == '') {
  577. print $langs->trans('ThirdParty')." - ". utf8_decode($val["ref"]) . $sep;
  578. } else {
  579. print $langs->trans('ThirdParty')." - ". utf8_decode($companystatic->name) . $sep;
  580. }
  581. print utf8_decode($reflabel) . $sep;
  582. print "\n";
  583. }
  584. }
  585. }
  586. } else {
  587. // Model Classic Export
  588. foreach ( $tabpay as $key => $val ) {
  589. $date = dol_print_date($db->jdate($val["date"]), 'day');
  590. $companystatic->id = $tabcompany[$key]['id'];
  591. $companystatic->name = $tabcompany[$key]['name'];
  592. // Bank
  593. foreach ( $tabbq[$key] as $k => $mt ) {
  594. print '"' . $journal . '"' . $sep;
  595. print '"' . $date . '"' . $sep;
  596. print '"' . $val["type_payment"] . '"' . $sep;
  597. print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
  598. if ($companystatic->name == '') {
  599. print '"' . $langs->trans('Bank') . " - " . utf8_decode($val["ref"]) . '"' . $sep;
  600. } else {
  601. print '"' . $langs->trans("Bank") . ' - ' . utf8_decode($companystatic->name) . '"' . $sep;
  602. }
  603. print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
  604. print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
  605. print "\n";
  606. }
  607. // Third party
  608. if (is_array($tabtp[$key])) {
  609. foreach ( $tabtp[$key] as $k => $mt ) {
  610. if ($mt) {
  611. print '"' . $journal . '"' . $sep;
  612. print '"' . $date . '"' . $sep;
  613. print '"' . $val["type_payment"] . '"' . $sep;
  614. print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
  615. if ($companystatic->name == '') {
  616. print '"' . $langs->trans('ThirdParty') . " - " . utf8_decode($val["ref"]) . '"' . $sep;
  617. } else {
  618. print '"' . $langs->trans('ThirdParty') . " - " . utf8_decode($companystatic->name) . '"' . $sep;
  619. }
  620. print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
  621. print '"' . ($mt >= 0 ? price($mt) : '') . '"';
  622. print "\n";
  623. }
  624. }
  625. } else {
  626. foreach ( $tabbq[$key] as $k => $mt ) {
  627. print '"' . $journal . '"' . $sep;
  628. print '"' . $date . '"' . $sep;
  629. print '"' . $val["ref"] . '"' . $sep;
  630. print '"' . length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) . '"' . $sep;
  631. if ($companystatic->name == '') {
  632. print '"' . $langs->trans("Bank") . ' - ' . utf8_decode($val["ref"]) . '"' . $sep;
  633. } else {
  634. print '"' . $langs->trans("Bank") . ' - ' . utf8_decode($companystatic->name) . '"' . $sep;
  635. }
  636. print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
  637. print '"' . ($mt >= 0 ? price($mt) : '') . '"';
  638. print "\n";
  639. }
  640. }
  641. }
  642. }
  643. }
  644. */
  645. /*
  646. * View
  647. */
  648. $form = new Form($db);
  649. if (empty($action) || $action == 'view') {
  650. $invoicestatic = new Facture($db);
  651. $invoicesupplierstatic = new FactureFournisseur($db);
  652. $expensereportstatic = new ExpenseReport($db);
  653. llxHeader('', $langs->trans("FinanceJournal"));
  654. $nom = $langs->trans("FinanceJournal") . ' - ' . $bankstatic->getNomUrl(1);
  655. $builddate = time();
  656. //$description = $langs->trans("DescFinanceJournal") . '<br>';
  657. $description.= $langs->trans("DescJournalOnlyBindedVisible").'<br>';
  658. $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);
  659. $varlink = 'id_account=' . $id_bank_account;
  660. journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink);
  661. /*if ($conf->global->ACCOUNTING_EXPORT_MODELCSV != 1 && $conf->global->ACCOUNTING_EXPORT_MODELCSV != 2) {
  662. print '<input type="button" class="butActionRefused" style="float: right;" value="' . $langs->trans('Export') . '" disabled="disabled" title="' . $langs->trans('ExportNotSupported') . '"/>';
  663. } else {
  664. print '<input type="button" class="butAction" style="float: right;" value="' . $langs->trans("Export") . '" onclick="launch_export();" />';
  665. }*/
  666. print '<div class="tabsAction">';
  667. print '<input type="button" class="butAction" value="' . $langs->trans("WriteBookKeeping") . '" onclick="writebookkeeping();" />';
  668. print '</div>';
  669. // TODO Avoid using js. We can use a direct link with $param
  670. print '
  671. <script type="text/javascript">
  672. function launch_export() {
  673. console.log("Set value into form and submit");
  674. $("div.fiche div.tabBar form input[name=\"action\"]").val("export_csv");
  675. $("div.fiche div.tabBar form input[type=\"submit\"]").click();
  676. $("div.fiche div.tabBar form input[name=\"action\"]").val("");
  677. }
  678. function writebookkeeping() {
  679. console.log("Set value into form and submit");
  680. $("div.fiche div.tabBar form input[name=\"action\"]").val("writebookkeeping");
  681. $("div.fiche div.tabBar form input[type=\"submit\"]").click();
  682. $("div.fiche div.tabBar form input[name=\"action\"]").val("");
  683. }
  684. </script>';
  685. /*
  686. * Show result array
  687. */
  688. print '<br>';
  689. $i = 0;
  690. print "<table class=\"noborder\" width=\"100%\">";
  691. print "<tr class=\"liste_titre\">";
  692. print "<td></td>";
  693. print "<td>" . $langs->trans("Date") . "</td>";
  694. print "<td>" . $langs->trans("Piece") . ' (' . $langs->trans("InvoiceRef") . ")</td>";
  695. print "<td>" . $langs->trans("AccountAccounting") . "</td>";
  696. print "<td>" . $langs->trans("Type") . "</td>";
  697. print "<td>" . $langs->trans("PaymentMode") . "</td>";
  698. print "<td align='right'>" . $langs->trans("Debit") . "</td>";
  699. print "<td align='right'>" . $langs->trans("Credit") . "</td>";
  700. print "</tr>\n";
  701. $r = '';
  702. foreach ( $tabpay as $key => $val ) { // $key is rowid in llx_bank
  703. $date = dol_print_date($db->jdate($val["date"]), 'day');
  704. $reflabel = $val["ref"];
  705. if ($reflabel == '(SupplierInvoicePayment)') {
  706. $reflabel = $langs->trans('Supplier');
  707. }
  708. if ($reflabel == '(CustomerInvoicePayment)') {
  709. $reflabel = $langs->trans('Customer');
  710. }
  711. if ($reflabel == '(SocialContributionPayment)') {
  712. $reflabel = $langs->trans('SocialContribution');
  713. }
  714. if ($reflabel == '(DonationPayment)') {
  715. $reflabel = $langs->trans('Donation');
  716. }
  717. if ($reflabel == '(SubscriptionPayment)') {
  718. $reflabel = $langs->trans('Subscription');
  719. }
  720. if ($reflabel == '(ExpenseReportPayment)') {
  721. $reflabel = $langs->trans('Employee');
  722. }
  723. $ref=$reflabel;
  724. if ($tabtype[$key] == 'payment')
  725. {
  726. $sqlmid = 'SELECT payfac.fk_facture as id';
  727. $sqlmid .= " FROM ".MAIN_DB_PREFIX."paiement_facture as payfac";
  728. $sqlmid .= " WHERE payfac.fk_paiement=" . $val["paymentid"];
  729. dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG);
  730. $resultmid = $db->query($sqlmid);
  731. if ($resultmid) {
  732. $objmid = $db->fetch_object($resultmid);
  733. $invoicestatic->fetch($objmid->id);
  734. $ref=$langs->trans("Invoice").' '.$invoicestatic->getNomUrl(1);
  735. }
  736. else dol_print_error($db);
  737. }
  738. elseif ($tabtype[$key] == 'payment_supplier')
  739. {
  740. $sqlmid = 'SELECT payfac.fk_facturefourn as id';
  741. $sqlmid .= " FROM " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfac";
  742. $sqlmid .= " WHERE payfac.fk_paiementfourn=" . $val["paymentsupplierid"];
  743. dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG);
  744. $resultmid = $db->query($sqlmid);
  745. if ($resultmid) {
  746. $objmid = $db->fetch_object($resultmid);
  747. $invoicesupplierstatic->fetch($objmid->id);
  748. $ref=$langs->trans("SupplierInvoice").' '.$invoicesupplierstatic->getNomUrl(1);
  749. }
  750. else dol_print_error($db);
  751. }
  752. elseif ($tabtype[$key] == 'payment_expensereport')
  753. {
  754. $sqlmid = 'SELECT payer.fk_expensereport as id';
  755. $sqlmid .= " FROM " . MAIN_DB_PREFIX . "payment_expensereport as payer";
  756. $sqlmid .= " WHERE payer.fk_expensereport=" . $val["fk_expensereport"];
  757. dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG);
  758. $resultmid = $db->query($sqlmid);
  759. if ($resultmid) {
  760. $objmid = $db->fetch_object($resultmid);
  761. $expensereportstatic->fetch($objmid->id);
  762. $ref=$langs->trans("ExpenseReport").' '.$expensereportstatic->getNomUrl(1);
  763. }
  764. else dol_print_error($db);
  765. }
  766. /*$invoicestatic->id = $key;
  767. $invoicestatic->ref = $val["ref"];
  768. $invoicestatic->type = $val["type"];*/
  769. // Bank
  770. foreach ( $tabbq[$key] as $k => $mt )
  771. {
  772. print '<tr class="oddeven">';
  773. print "<td><!-- Bank bank.rowid=".$key."--></td>";
  774. print "<td>" . $date . "</td>";
  775. print "<td>" . $ref . "</td>";
  776. print "<td>";
  777. $accountoshow = length_accountg($k);
  778. if (empty($accountoshow) || $accountoshow == 'NotDefined')
  779. {
  780. print '<span class="error">'.$langs->trans("BankAccountNotDefined").'</span>';
  781. }
  782. else print $accountoshow;
  783. print "</td>";
  784. if ($val['soclib'] == '') {
  785. print "<td>" . $bankstatic->label . " - " . $val["ref"] . "</td>";
  786. } else {
  787. print "<td>" . $bankstatic->label . " - " . $val['soclib'] . "</td>";
  788. }
  789. print "<td>" . $val["type_payment"] . "</td>";
  790. print "<td align='right'>" . ($mt >= 0 ? price($mt) : '') . "</td>";
  791. print "<td align='right'>" . ($mt < 0 ? price(- $mt) : '') . "</td>";
  792. print "</tr>";
  793. }
  794. // Third party
  795. if (is_array($tabtp[$key])) {
  796. foreach ( $tabtp[$key] as $k => $mt ) {
  797. if ($k != 'type') {
  798. print '<tr class="oddeven">';
  799. print "<td><!-- Thirdparty bank.rowid=".$key." --></td>";
  800. print "<td>" . $date . "</td>";
  801. print "<td>" . $ref . "</td>";
  802. print "<td>";
  803. $accountoshow = length_accounta($k);
  804. if (empty($accountoshow) || $accountoshow == 'NotDefined')
  805. {
  806. print '<span class="error">'.$langs->trans("ThirdpartyAccountNotDefined").'</span>';
  807. }
  808. else print $accountoshow;
  809. print "</td>";
  810. print "<td>" . $reflabel . ' ' . $val['soclib'] . "</td>";
  811. print "<td>" . $val["type_payment"] . "</td>";
  812. print "<td align='right'>" . ($mt < 0 ? price(- $mt) : '') . "</td>";
  813. print "<td align='right'>" . ($mt >= 0 ? price($mt) : '') . "</td>";
  814. print "</tr>";
  815. }
  816. }
  817. } else {
  818. foreach ( $tabbq[$key] as $k => $mt ) {
  819. print '<tr class="oddeven">';
  820. print "<td><!-- Wait bank.rowid=".$key." --></td>";
  821. print "<td>" . $date . "</td>";
  822. print "<td>" . $ref . "</td>";
  823. print "<td>";
  824. if (empty($accountoshow) || $accountoshow == 'NotDefined')
  825. {
  826. print '<span class="error">'.$langs->trans("WaitAccountNotDefined").'</span>';
  827. }
  828. else print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE);
  829. print "</td>";
  830. print "<td>" . $reflabel . "</td>";
  831. print "<td>&nbsp;</td>";
  832. print "<td align='right'>" . ($mt < 0 ? price(- $mt) : '') . "</td>";
  833. print "<td align='right'>" . ($mt >= 0 ? price($mt) : '') . "</td>";
  834. print "</tr>";
  835. }
  836. }
  837. }
  838. print "</table>";
  839. llxFooter();
  840. }
  841. $db->close();