dolibarr 24.0.0-beta
bankjournal.php
Go to the documentation of this file.
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.houssin@inodbox.com>
6 * Copyright (C) 2013 Christophe Battarel <christophe.battarel@altairis.fr>
7 * Copyright (C) 2013-2022 Open-DSI <support@open-dsi.fr>
8 * Copyright (C) 2013-2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
9 * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
10 * Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
11 * Copyright (C) 2017-2026 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
13 * Copyright (C) 2018-2024 Eric Seigne <eric.seigne@cap-rel.fr>
14 * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
15 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 3 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <https://www.gnu.org/licenses/>.
29 */
30
36require '../../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
42require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
43require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
44require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
45require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
46require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
47require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
48require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
49require_once DOL_DOCUMENT_ROOT.'/don/class/paymentdonation.class.php';
50require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
51require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php';
52require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
53require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
54require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
55require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
56require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php';
57require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
58require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
59require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php';
60require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
61require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
62require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
63require_once DOL_DOCUMENT_ROOT.'/loan/class/paymentloan.class.php';
64require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
65
74// Load translation files required by the page
75$langs->loadLangs(array("companies", "other", "compta", "banks", "bills", "donations", "loan", "accountancy", "trips", "salaries", "hrm", "members"));
76
77// Multi journal
78$id_journal = GETPOSTINT('id_journal');
79
80$date_startmonth = GETPOSTINT('date_startmonth');
81$date_startday = GETPOSTINT('date_startday');
82$date_startyear = GETPOSTINT('date_startyear');
83$date_endmonth = GETPOSTINT('date_endmonth');
84$date_endday = GETPOSTINT('date_endday');
85$date_endyear = GETPOSTINT('date_endyear');
86$in_bookkeeping = GETPOST('in_bookkeeping', 'aZ09');
87
88$only_rappro = GETPOSTINT('only_rappro');
89if ($only_rappro == 0) {
90 //GET page for the first time, use default settings
91 $only_rappro = getDolGlobalInt('ACCOUNTING_BANK_CONCILIATED');
92}
93
94$now = dol_now();
95
96$action = GETPOST('action', 'aZ09');
97
98if ($in_bookkeeping == '') {
99 $in_bookkeeping = 'notyet';
100}
101
102
103// Security check
104if (!isModEnabled('accounting')) {
106}
107if ($user->socid > 0) {
109}
110if (!$user->hasRight('accounting', 'bind', 'write')) {
112}
113
114
115/*
116 * Actions
117 */
118
119$error = 0;
120
121$date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
122$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
123
124$pastmonth = null; // Initialise for static analysis (could be really unseg)
125$pastmonthyear = null;
126
127if (empty($date_startmonth)) {
128 // Period by default on transfer
130 $date_start = $dates['date_start'];
131 $pastmonthyear = $dates['pastmonthyear'];
132 $pastmonth = $dates['pastmonth'];
133}
134if (empty($date_endmonth)) {
135 // Period by default on transfer
137 $date_end = $dates['date_end'];
138 $pastmonthyear = $dates['pastmonthyear'];
139 $pastmonth = $dates['pastmonth'];
140}
141
142if (!GETPOSTISSET('date_startmonth') && (empty($date_start) || empty($date_end))) { // We define date_start and date_end, only if we did not submit the form
143 $date_start = dol_get_first_day((int) $pastmonthyear, (int) $pastmonth, false);
144 $date_end = dol_get_last_day((int) $pastmonthyear, (int) $pastmonth, false);
145}
146
147// Get all bank lines
148//-------------------------------------
149$sql = "SELECT b.rowid, b.dateo as do, b.datev as dv, b.amount, b.amount_main_currency, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type, b.fk_account, b.numero_compte,";
150$sql .= " ba.courant, ba.ref as baref, ba.account_number, ba.fk_accountancy_journal,";
151$sql .= " soc.rowid as socid, soc.nom as name, soc.email as email, bu1.type as typeop_company,";
152if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
153 $sql .= " spe.accountancy_code_customer_general,";
154 $sql .= " spe.accountancy_code_customer as code_compta_client,";
155 $sql .= " spe.accountancy_code_supplier_general,";
156 $sql .= " spe.accountancy_code_supplier as code_compta_fournisseur,";
157} else {
158 $sql .= " soc.accountancy_code_customer_general,";
159 $sql .= " soc.code_compta as code_compta_client,";
160 $sql .= " soc.accountancy_code_supplier_general,";
161 $sql .= " soc.code_compta_fournisseur,";
162}
163$sql .= " u.accountancy_code_user_general, u.accountancy_code, u.rowid as userid, u.lastname as lastname, u.firstname as firstname, u.email as useremail, u.statut as userstatus,";
164$sql .= " bu2.type as typeop_user,";
165$sql .= " bu3.type as typeop_payment, bu4.type as typeop_payment_supplier";
166$sql .= " FROM ".$db->prefix()."bank as b";
167$sql .= " JOIN ".$db->prefix()."bank_account as ba on b.fk_account = ba.rowid";
168$sql .= " LEFT JOIN ".$db->prefix()."bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'";
169$sql .= " LEFT JOIN ".$db->prefix()."bank_url as bu2 ON bu2.fk_bank = b.rowid AND bu2.type='user'";
170$sql .= " LEFT JOIN ".$db->prefix()."bank_url as bu3 ON bu3.fk_bank = b.rowid AND bu3.type='payment'";
171$sql .= " LEFT JOIN ".$db->prefix()."bank_url as bu4 ON bu4.fk_bank = b.rowid AND bu4.type='payment_supplier'";
172$sql .= " LEFT JOIN ".$db->prefix()."societe as soc on bu1.url_id=soc.rowid";
173if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
174 $sql .= " LEFT JOIN " . $db->prefix() . "societe_perentity as spe ON spe.fk_soc = soc.rowid AND spe.entity = " . ((int) $conf->entity);
175}
176$sql .= " LEFT JOIN ".$db->prefix()."user as u on bu2.url_id=u.rowid";
177$sql .= " WHERE ba.fk_accountancy_journal=".((int) $id_journal);
178$sql .= " AND b.amount <> 0 AND ba.entity IN (".getEntity('bank_account', 0).")"; // We don't share object for accountancy
179if ($date_start && $date_end) {
180 $sql .= " AND b.dateo >= '".$db->idate($date_start)."' AND b.dateo <= '".$db->idate($date_end)."'";
181}
182// Define begin binding date
183if (getDolGlobalInt('ACCOUNTING_DATE_START_BINDING')) {
184 $sql .= " AND b.dateo >= '".$db->idate(getDolGlobalInt('ACCOUNTING_DATE_START_BINDING'))."'";
185}
186// Already in bookkeeping or not
187if ($in_bookkeeping == 'already') {
188 $sql .= " AND (b.rowid IN (SELECT fk_doc FROM ".$db->prefix()."accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
189}
190if ($in_bookkeeping == 'notyet') {
191 $sql .= " AND (b.rowid NOT IN (SELECT fk_doc FROM ".$db->prefix()."accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
192}
193if ($only_rappro == 2) {
194 $sql .= " AND (b.rappro = '1')";
195}
196$sql .= " ORDER BY b.datev";
197//print $sql;
198
199// Preload payment account codes by payment type from c_paiement
200$accountancy_code_by_payment = array();
201$sql2 = "SELECT code, accountancy_code";
202$sql2 .= " FROM ".MAIN_DB_PREFIX."c_paiement";
203$sql2 .= " WHERE entity IN (".getEntity('c_paiement').")";
204$sql2 .= " AND active = 1";
205$resql = $db->query($sql2);
206if ($resql) {
207 while ($objp = $db->fetch_object($resql)) {
208 if (!empty($objp->code) && !empty($objp->accountancy_code)) {
209 $accountancy_code_by_payment[$objp->code] = $objp->accountancy_code;
210 }
211 }
212}
213
214$object = new Account($db);
215$paymentstatic = new Paiement($db);
216$paymentsupplierstatic = new PaiementFourn($db);
217$societestatic = new Societe($db);
218$userstatic = new User($db);
219$bankaccountstatic = new Account($db);
220$chargestatic = new ChargeSociales($db);
221$paymentdonstatic = new PaymentDonation($db);
222$paymentvatstatic = new Tva($db);
223$paymentsalstatic = new PaymentSalary($db);
224$paymentexpensereportstatic = new PaymentExpenseReport($db);
225$paymentvariousstatic = new PaymentVarious($db);
226$paymentloanstatic = new PaymentLoan($db);
227$accountLinestatic = new AccountLine($db);
228$paymentsubscriptionstatic = new Subscription($db);
229
230$tmppayment = new Paiement($db);
231$tmpinvoice = new Facture($db);
232
233$accountingaccount = new AccountingAccount($db);
234$account_transfer = 'NotDefined'; // For static analysis, NotDefined is a reserved word
235
236// Get code of finance journal
237$accountingjournalstatic = new AccountingJournal($db);
238$accountingjournalstatic->fetch($id_journal);
239$journal = $accountingjournalstatic->code;
240$journal_label = $accountingjournalstatic->label;
241
242$tabcompany = array();
243$tabuser = array();
244$tabpay = array();
245$tabbq = array();
246$tabtp = array();
247$tabtype = array();
248$tabmoreinfo = array();
249
250'
251@phan-var-force array<array{id:mixed,name:mixed,code_compta_client:string,email:string}> $tabcompany
252@phan-var-force array<array{id:int,name:string,lastname:string,firstname:string,email:string,accountancy_code:string,status:int> $tabuser
253@phan-var-force array<int,array{date:string,type_payment:string,ref:string,fk_bank:int,ban_account_ref:string,fk_bank_account:int,lib:string,type:string}> $tabpay
254@phan-var-force array<array{lib:string,date?:int|string,type_payment?:string,ref?:string,fk_bank?:int,ban_account_ref?:string,fk_bank_account?:int,type?:string,bank_account_ref?:string,paymentid?:int,paymentsupplierid?:int,soclib?:string,paymentscid?:int,paymentdonationid?:int,paymentsubscriptionid?:int,paymentvatid?:int,paymentsalid?:int,paymentexpensereport?:int,paymentvariousid?:int,account_various?:string,paymentloanid?:int}> $tabtp
255';
256
257$account_customer = 'NotDefined';
258$account_supplier = 'NotDefined';
259$account_employee = 'NotDefined';
260
261//print $sql;
262dol_syslog("accountancy/journal/bankjournal.php", LOG_DEBUG);
263$result = $db->query($sql);
264if ($result) {
265 $num = $db->num_rows($result);
266 //print $sql;
267
268 // Variables
269 $account_supplier = getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER', 'NotDefined'); // NotDefined is a reserved word
270 $account_customer = getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER', 'NotDefined'); // NotDefined is a reserved word
271 $account_employee = getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT', 'NotDefined'); // NotDefined is a reserved word
272 $account_expensereport = getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT', 'NotDefined'); // NotDefined is a reserved word
273 $account_pay_vat = getDolGlobalString('ACCOUNTING_VAT_PAY_ACCOUNT', 'NotDefined'); // NotDefined is a reserved word
274 $account_pay_donation = getDolGlobalString('DONATION_ACCOUNTINGACCOUNT', 'NotDefined'); // NotDefined is a reserved word
275 $account_pay_subscription = getDolGlobalString('ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT', 'NotDefined'); // NotDefined is a reserved word
276 $account_transfer = getDolGlobalString('ACCOUNTING_ACCOUNT_TRANSFER_CASH', 'NotDefined'); // NotDefined is a reserved word
277
278 // Loop on each line into the llx_bank table. For each line, we should get:
279 // one line tabpay = line into bank
280 // one line for bank record = tabbq
281 // one line for thirdparty record = tabtp
282 // Note: tabcompany is used to store the subledger account
283 $i = 0;
284 while ($i < $num) {
285 $obj = $db->fetch_object($result);
286
287 $lineisapurchase = -1;
288 $lineisasale = -1;
289 // Old method to detect if it's a sale or purchase
290 if ($obj->label == '(SupplierInvoicePayment)' || $obj->label == '(SupplierInvoicePaymentBack)') {
291 $lineisapurchase = 1;
292 }
293 if ($obj->label == '(CustomerInvoicePayment)' || $obj->label == '(CustomerInvoicePaymentBack)') {
294 $lineisasale = 1;
295 }
296 // Try a more reliable method to detect if record is a supplier payment or a customer payment
297 if ($lineisapurchase < 0) {
298 if ($obj->typeop_payment_supplier == 'payment_supplier') {
299 $lineisapurchase = 1;
300 }
301 }
302 if ($lineisasale < 0) {
303 if ($obj->typeop_payment == 'payment') {
304 $lineisasale = 1;
305 }
306 }
307 //var_dump($obj->type_payment); //var_dump($obj->type_payment_supplier);
308 //var_dump($lineisapurchase); //var_dump($lineisasale);
309
310 // Set accountancy code for bank
311 $compta_bank = $obj->account_number;
312
313 // Determining the bank account by payment method
314 if (!empty($obj->fk_type) && !empty($accountancy_code_by_payment[$obj->fk_type])) {
315 $compta_bank = $accountancy_code_by_payment[$obj->fk_type];
316 }
317
318 // Set accountancy code for thirdparty (example: '411CU...' or '411' if no subledger account defined on customer)
319 $compta_soc = 'NotDefined';
320 $accountancy_code_general = 'NotDefined';
321 if ($lineisapurchase > 0) {
322 $accountancy_code_general = (!empty($obj->accountancy_code_supplier_general) && $obj->accountancy_code_supplier_general != '-1') ? $obj->accountancy_code_supplier_general : $account_supplier;
323 $compta_soc = (($obj->code_compta_fournisseur != "") ? $obj->code_compta_fournisseur : $account_supplier);
324 }
325 if ($lineisasale > 0) {
326 $accountancy_code_general = (!empty($obj->accountancy_code_customer_general) && $obj->accountancy_code_customer_general != '-1') ? $obj->accountancy_code_customer_general : $account_customer;
327 $compta_soc = (!empty($obj->code_compta_client) ? $obj->code_compta_client : $account_customer);
328 }
329
330 $tabcompany[$obj->rowid] = array(
331 'id' => $obj->socid,
332 'name' => $obj->name,
333 'code_compta' => $compta_soc,
334 'accountancy_code_general' => $accountancy_code_general,
335 'email' => $obj->email
336 );
337
338 // Set accountancy code for user
339 // $obj->accountancy_code is the accountancy_code of table u=user (but it is defined only if
340 // a link with type 'user' exists and user as a subledger account)
341 $accountancy_code_user_general = (!empty($obj->accountancy_code_user_general)) ? $obj->accountancy_code_user_general : $account_employee;
342 $compta_user = (!empty($obj->accountancy_code) ? $obj->accountancy_code : '');
343
344 $tabuser[$obj->rowid] = array(
345 'id' => $obj->userid,
346 'name' => dolGetFirstLastname($obj->firstname, $obj->lastname),
347 'lastname' => $obj->lastname,
348 'firstname' => $obj->firstname,
349 'email' => $obj->useremail,
350 'accountancy_code_general' => $accountancy_code_user_general,
351 'accountancy_code' => $compta_user,
352 'status' => $obj->userstatus
353 );
354
355 // Variable bookkeeping ($obj->rowid is Bank Id)
356 $tabpay[$obj->rowid]["date"] = $db->jdate($obj->do);
357 $tabpay[$obj->rowid]["type_payment"] = $obj->fk_type; // CHQ, VIR, LIQ, CB, ...
358 $tabpay[$obj->rowid]["ref"] = $obj->label; // By default. Not unique. May be changed later
359 $tabpay[$obj->rowid]["fk_bank"] = $obj->rowid;
360 $tabpay[$obj->rowid]["bank_account_ref"] = $obj->baref;
361 $tabpay[$obj->rowid]["fk_bank_account"] = $obj->fk_account;
362 $reg = array();
363 if (preg_match('/^\‍((.*)\‍)$/i', $obj->label, $reg)) {
364 $tabpay[$obj->rowid]["lib"] = $langs->trans($reg[1]);
365 } else {
366 $tabpay[$obj->rowid]["lib"] = dol_trunc($obj->label, 60);
367 }
368
369 // Load of url links to the line into llx_bank (so load llx_bank_url)
370 $links = $object->get_url($obj->rowid); // Get an array('url'=>, 'url_id'=>, 'label'=>, 'type'=> 'fk_bank'=> )
371 // print '<p>' . json_encode($object) . "</p>";//exit;
372 // print '<p>' . json_encode($links) . "</p>";//exit;
373
374 // By default
375 $tabpay[$obj->rowid]['type'] = 'unknown'; // Can be SOLD, miscellaneous entry, payment of patient, or any old record with no links in bank_url.
376 $tabtype[$obj->rowid] = 'unknown';
377 $tabmoreinfo[$obj->rowid] = array();
378
379 $amounttouse = $obj->amount;
380 if (!empty($obj->amount_main_currency)) {
381 // If $obj->amount_main_currency is set, it means that $obj->amount is not in same currency, we must use $obj->amount_main_currency
382 $amounttouse = $obj->amount_main_currency;
383 }
384
385 // in case option FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS is on, payment could be for more than one third-partie
386 // so we have to find which part of the payment is affected to each third-parties
387 // (because in this case $obj-amount = the total of the paiement and not the paiement for each third-parties)
388 if (getDolGlobalString('FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS') && ($lineisapurchase == 1 || $lineisasale == 1)) {
389 if ($lineisapurchase == 1) {
390 $sqlamount = "SELECT SUM(pf.amount) as amount";
391 $sqlamount .= " FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn AS pf";
392 $sqlamount .= " INNER JOIN ".MAIN_DB_PREFIX."paiementfourn AS p ON pf.fk_paiementfourn = p.rowid";
393 $sqlamount .= " RIGHT JOIN ".MAIN_DB_PREFIX."facture AS f ON pf.fk_facturefourn = f.rowid";
394 $sqlamount .= " WHERE p.fk_bank = ".((int) $obj->rowid);
395 $sqlamount .= " AND f.fk_soc = ".((int) $obj->socid);
396 } else {
397 $sqlamount = "SELECT SUM(pf.amount) as amount";
398 $sqlamount .= " FROM ".MAIN_DB_PREFIX."paiement_facture AS pf";
399 $sqlamount .= " INNER JOIN ".MAIN_DB_PREFIX."paiement AS p ON pf.fk_paiement = p.rowid";
400 $sqlamount .= " RIGHT JOIN ".MAIN_DB_PREFIX."facture AS f ON pf.fk_facture = f.rowid";
401 $sqlamount .= " WHERE p.fk_bank = ".((int) $obj->rowid);
402 $sqlamount .= " AND f.fk_soc = ".((int) $obj->socid);
403 }
404 $resultamount = $db->query($sqlamount);
405 if ($resultamount) {
406 $objamount = $db->fetch_object($resultamount);
407 if (!empty($objamount->amount)) {
408 $amounttouse = $objamount->amount;
409 }
410 }
411 }
412
413 // get_url may return -1 which is not traversable
414 if (is_array($links) && count($links) > 0) {
415 // Test if entry is for a social contribution, salary or expense report.
416 // In such a case, we will ignore the bank url line for user
417 $is_sc = false;
418 $is_salary = false;
419 $is_expensereport = false;
420 foreach ($links as $v) {
421 if ($v['type'] == 'sc') {
422 $is_sc = true;
423 break;
424 }
425 if ($v['type'] == 'payment_salary') {
426 $is_salary = true;
427 break;
428 }
429 if ($v['type'] == 'payment_expensereport') {
430 $is_expensereport = true;
431 break;
432 }
433 }
434
435 // Now loop on each link of record in bank (code similar to bankentries_list.php)
436 foreach ($links as $key => $val) {
437 if ($links[$key]['type'] == 'user' && !$is_sc && !$is_salary && !$is_expensereport) {
438 // We must avoid as much as possible this "continue". If we want to jump to next loop, it means we don't want to process
439 // the case the link is user (often because managed by hard coded code into another link), and we must avoid this.
440 continue;
441 }
442 if (in_array($links[$key]['type'], array('sc', 'payment_sc', 'payment', 'payment_supplier', 'payment_vat', 'payment_expensereport', 'banktransfert', 'payment_donation', 'member', 'payment_loan', 'payment_salary', 'payment_various'))) {
443 // So we excluded 'company' and 'user' here. We want only payment lines
444
445 // We save tabtype for a future use, to remember what kind of payment it is
446 $tabpay[$obj->rowid]['type'] = $links[$key]['type'];
447 $tabtype[$obj->rowid] = $links[$key]['type'];
448 /* phpcs:disable -- Code does nothing at this moment -> commented
449 } elseif (in_array($links[$key]['type'], array('company', 'user'))) {
450 if ($tabpay[$obj->rowid]['type'] == 'unknown') {
451 // We can guess here it is a bank record for a thirdparty company or a user.
452 // 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.
453 }
454 */ // phpcs::enable
455 }
456
457 // Special case to ask later to add more request to get information for old links without company link.
458 if ($links[$key]['type'] == 'withdraw') {
459 $tabmoreinfo[$obj->rowid]['withdraw'] = 1;
460 }
461
462 if ($links[$key]['type'] == 'payment') {
463 $paymentstatic->id = $links[$key]['url_id'];
464 $paymentstatic->ref = (string) $links[$key]['url_id'];
465 $tabpay[$obj->rowid]["lib"] .= ' '.$paymentstatic->getNomUrl(2, '', ''); // TODO Do not include list of invoice in tooltip, the dol_string_nohtmltag is ko with this
466 $tabpay[$obj->rowid]["paymentid"] = $paymentstatic->id;
467 } elseif ($links[$key]['type'] == 'payment_supplier') {
468 $paymentsupplierstatic->id = $links[$key]['url_id'];
469 $paymentsupplierstatic->ref = (string) $links[$key]['url_id'];
470 $tabpay[$obj->rowid]["lib"] .= ' '.$paymentsupplierstatic->getNomUrl(2);
471 $tabpay[$obj->rowid]["paymentsupplierid"] = $paymentsupplierstatic->id;
472 } elseif ($links[$key]['type'] == 'company') {
473 $societestatic->id = $links[$key]['url_id'];
474 $societestatic->name = $links[$key]['label'];
475 $societestatic->email = $tabcompany[$obj->rowid]['email'];
476 $tabpay[$obj->rowid]["soclib"] = $societestatic->getNomUrl(1, '', 30);
477 if ($compta_soc) {
478 // because we are in 2 loop (loop on the line from the sql queries and loop on $links)
479 // and in case of option FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS is on,
480 // we will pass here n times for each payment line
481 // so we have to add $amoutouse only if the line $links[$key] correspond to the payment line we are in used ( socid correspondinf at the payment line $links)
482 // if FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS is off we add $amounttouse
483 if (!getDolGlobalString('FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS') || $obj->socid == $links[$key]['url_id']) {
484 if (empty($tabtp[$obj->rowid][$compta_soc])) {
485 $tabtp[$obj->rowid][$compta_soc] = $amounttouse;
486 } else {
487 $tabtp[$obj->rowid][$compta_soc] += $amounttouse;
488 }
489 }
490 }
491 } elseif ($links[$key]['type'] == 'user') {
492 $userstatic->id = $links[$key]['url_id'];
493 $userstatic->name = $links[$key]['label'];
494 $userstatic->email = $tabuser[$obj->rowid]['email'];
495 $userstatic->firstname = $tabuser[$obj->rowid]['firstname'];
496 $userstatic->lastname = $tabuser[$obj->rowid]['lastname'];
497 $userstatic->status = $tabuser[$obj->rowid]['status'];
498 $userstatic->accountancy_code_user_general = $tabuser[$obj->rowid]['accountancy_code_general'];
499 $userstatic->accountancy_code = $tabuser[$obj->rowid]['accountancy_code'];
500
501 // For a payment of social contribution, we have a link sc + user.
502 // but we already fill the $tabpay[$obj->rowid]["soclib"] in the line 'sc'.
503 // If we fill it here to, we must concat.
504 if ($userstatic->id > 0) {
505 if ($is_sc) {
506 $tabpay[$obj->rowid]["soclib"] .= ' '.$userstatic->getNomUrl(-1, 'accountancy', 0);
507 } else {
508 $tabpay[$obj->rowid]["soclib"] = $userstatic->getNomUrl(-1, 'accountancy', 0);
509 }
510 } else {
511 $tabpay[$obj->rowid]["soclib"] = '???'; // Should not happen, but happens with old data when id of user was not saved on expense report payment.
512 }
513
514 if ($compta_user) {
515 if ($is_sc) {
516 //$tabcompany[$obj->rowid][$compta_user] += $amounttouse;
517 } else {
518 $tabtp[$obj->rowid][$compta_user] += $amounttouse;
519 }
520 }
521 } elseif ($links[$key]['type'] == 'sc') {
522 $chargestatic->id = $links[$key]['url_id'];
523 $chargestatic->ref = (string) $links[$key]['url_id'];
524
525 $tabpay[$obj->rowid]["lib"] .= ' '.$chargestatic->getNomUrl(2);
526 $reg = array();
527 if (preg_match('/^\‍((.*)\‍)$/i', $links[$key]['label'], $reg)) {
528 if ($reg[1] == 'socialcontribution') {
529 $reg[1] = 'SocialContribution';
530 }
531 $chargestatic->label = $langs->trans($reg[1]);
532 } else {
533 $chargestatic->label = $links[$key]['label'];
534 }
535 $chargestatic->ref = $chargestatic->label;
536
537 // Retrieve the accounting code of the social contribution of the payment from link of payment.
538 // Note: We have the social contribution id, it can be faster to get accounting code from social contribution id.
539 /*
540 $sqlmid = "SELECT cchgsoc.accountancy_code";
541 $sqlmid .= " FROM ".MAIN_DB_PREFIX."c_chargesociales cchgsoc";
542 $sqlmid .= " INNER JOIN ".MAIN_DB_PREFIX."chargesociales as chgsoc ON chgsoc.fk_type = cchgsoc.id";
543 $sqlmid .= " INNER JOIN ".MAIN_DB_PREFIX."paiementcharge as paycharg ON paycharg.fk_charge = chgsoc.rowid";
544 $sqlmid .= " INNER JOIN ".MAIN_DB_PREFIX."bank_url as bkurl ON bkurl.url_id=paycharg.rowid AND bkurl.type = 'payment_sc'";
545 $sqlmid .= " WHERE bkurl.fk_bank = ".((int) $obj->rowid);
546
547 dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);
548 $resultmid = $db->query($sqlmid);
549 if ($resultmid) {
550 $objmid = $db->fetch_object($resultmid);
551 $tabtp[$obj->rowid][$objmid->accountancy_code] = isset($tabtp[$obj->rowid][$objmid->accountancy_code]) ? $tabtp[$obj->rowid][$objmid->accountancy_code] + $amounttouse : $amounttouse;
552 }*/
553 $tmpcharge = new ChargeSociales($db);
554 $resultmid = $tmpcharge->fetch($chargestatic->id);
555 if ($resultmid) {
556 $chargestatic->type_label = $tmpcharge->type_label;
557 $chargestatic->type_code = $tmpcharge->type_code;
558 $chargestatic->type_accountancy_code = $tmpcharge->type_accountancy_code;
559
560 $tabtp[$obj->rowid][$tmpcharge->type_accountancy_code] = isset($tabtp[$obj->rowid][$tmpcharge->type_accountancy_code]) ? $tabtp[$obj->rowid][$tmpcharge->type_accountancy_code] + $amounttouse : $amounttouse;
561 }
562
563 $tabpay[$obj->rowid]["soclib"] = $chargestatic->getNomUrl(1, '30');
564 $tabpay[$obj->rowid]["paymentscid"] = $chargestatic->id;
565 } elseif ($links[$key]['type'] == 'payment_donation') {
566 $paymentdonstatic->id = $links[$key]['url_id'];
567 $paymentdonstatic->ref = (string) $links[$key]['url_id'];
568 $paymentdonstatic->fk_donation = $links[$key]['url_id'];
569 $tabpay[$obj->rowid]["lib"] .= ' '.$paymentdonstatic->getNomUrl(2);
570 $tabpay[$obj->rowid]["paymentdonationid"] = $paymentdonstatic->id;
571 $tabtp[$obj->rowid][$account_pay_donation] = isset($tabtp[$obj->rowid][$account_pay_donation]) ? $tabtp[$obj->rowid][$account_pay_donation] + $amounttouse : $amounttouse;
572 } elseif ($links[$key]['type'] == 'member') {
573 $paymentsubscriptionstatic->id = $links[$key]['url_id'];
574 $paymentsubscriptionstatic->ref = (string) $links[$key]['url_id'];
575 $paymentsubscriptionstatic->label = $links[$key]['label'];
576 $tabpay[$obj->rowid]["lib"] .= ' '.$paymentsubscriptionstatic->getNomUrl(2);
577 $tabpay[$obj->rowid]["paymentsubscriptionid"] = $paymentsubscriptionstatic->id;
578 $paymentsubscriptionstatic->fetch($paymentsubscriptionstatic->id);
579 $tabtp[$obj->rowid][$account_pay_subscription] = isset($tabtp[$obj->rowid][$account_pay_subscription]) ? $tabtp[$obj->rowid][$account_pay_subscription] + $amounttouse : $amounttouse;
580 } elseif ($links[$key]['type'] == 'payment_vat') { // Payment VAT
581 $paymentvatstatic->id = $links[$key]['url_id'];
582 $paymentvatstatic->ref = (string) $links[$key]['url_id'];
583 $paymentvatstatic->label = $links[$key]['label'];
584 $tabpay[$obj->rowid]["lib"] .= ' '.$paymentvatstatic->getNomUrl(2);
585 $tabpay[$obj->rowid]["paymentvatid"] = $paymentvatstatic->id;
586 $tabtp[$obj->rowid][$account_pay_vat] = isset($tabtp[$obj->rowid][$account_pay_vat]) ? $tabtp[$obj->rowid][$account_pay_vat] + $amounttouse : $amounttouse;
587 } elseif ($links[$key]['type'] == 'payment_salary') {
588 $paymentsalstatic->id = $links[$key]['url_id'];
589 $paymentsalstatic->ref = (string) $links[$key]['url_id'];
590 $paymentsalstatic->label = $links[$key]['label'];
591 $tabpay[$obj->rowid]["lib"] .= ' '.$paymentsalstatic->getNomUrl(2);
592 $tabpay[$obj->rowid]["paymentsalid"] = $paymentsalstatic->id;
593
594 // This part of code is no more required. it is here to solve case where a link were missing (with v14.0.0) and keep writing in accountancy complete.
595 // Note: A better way to fix this is to delete payment of salary and recreate it, or to fix the bookkeeping table manually after.
596 if (getDolGlobalString('ACCOUNTANCY_AUTOFIX_MISSING_LINK_TO_USER_ON_SALARY_BANK_PAYMENT')) {
597 $tmpsalary = new Salary($db);
598 $tmpsalary->fetch($paymentsalstatic->id);
599 $tmpsalary->fetch_user($tmpsalary->fk_user);
600
601 $userstatic->id = $tmpsalary->user->id;
602 $userstatic->name = $tmpsalary->user->name;
603 $userstatic->email = $tmpsalary->user->email;
604 $userstatic->firstname = $tmpsalary->user->firstname;
605 $userstatic->lastname = $tmpsalary->user->lastname;
606 $userstatic->status = $tmpsalary->user->status;
607 $userstatic->accountancy_code = $tmpsalary->user->accountancy_code;
608
609 if ($userstatic->id > 0) {
610 $tabpay[$obj->rowid]["soclib"] = $userstatic->getNomUrl(1, 'accountancy', 0);
611 } else {
612 $tabpay[$obj->rowid]["soclib"] = '???'; // Should not happen
613 }
614
615 if (empty($obj->typeop_user)) { // Add test to avoid adding amount twice if a link already exists also on user.
616 $accountancy_code_user_general = (!empty($obj->accountancy_code_user_general)) ? $obj->accountancy_code_user_general : $account_employee;
617 $compta_user = $userstatic->accountancy_code;
618 if ($compta_user) {
619 $tabtp[$obj->rowid][$compta_user] += $amounttouse;
620 $tabuser[$obj->rowid] = array(
621 'id' => $userstatic->id,
622 'name' => dolGetFirstLastname($userstatic->firstname, $userstatic->lastname),
623 'lastname' => $userstatic->lastname,
624 'firstname' => $userstatic->firstname,
625 'email' => $userstatic->email,
626 'accountancy_code_general' => $accountancy_code_user_general,
627 'accountancy_code' => $compta_user,
628 'status' => $userstatic->status
629 );
630 }
631 }
632 }
633 } elseif ($links[$key]['type'] == 'payment_expensereport') {
634 $paymentexpensereportstatic->id = $links[$key]['url_id'];
635 $tabpay[$obj->rowid]["lib"] .= $paymentexpensereportstatic->getNomUrl(2);
636 $tabpay[$obj->rowid]["paymentexpensereport"] = $paymentexpensereportstatic->id;
637 } elseif ($links[$key]['type'] == 'payment_various') {
638 $paymentvariousstatic->id = $links[$key]['url_id'];
639 $paymentvariousstatic->ref = (string) $links[$key]['url_id'];
640 $paymentvariousstatic->label = $links[$key]['label'];
641 $tabpay[$obj->rowid]["lib"] .= ' '.$paymentvariousstatic->getNomUrl(2);
642 $tabpay[$obj->rowid]["paymentvariousid"] = $paymentvariousstatic->id;
643 $paymentvariousstatic->fetch($paymentvariousstatic->id);
644 $account_various = (!empty($paymentvariousstatic->accountancy_code) ? $paymentvariousstatic->accountancy_code : (!empty($obj->numero_compte) ? $obj->numero_compte : 'NotDefined')); // NotDefined is a reserved word
645 $account_subledger = (!empty($paymentvariousstatic->subledger_account) ? $paymentvariousstatic->subledger_account : ''); // NotDefined is a reserved word
646 $tabpay[$obj->rowid]["account_various"] = $account_various;
647 $tabtp[$obj->rowid][$account_subledger] = isset($tabtp[$obj->rowid][$account_subledger]) ? $tabtp[$obj->rowid][$account_subledger] + $amounttouse : $amounttouse;
648 } elseif ($links[$key]['type'] == 'payment_loan') {
649 $paymentloanstatic->id = $links[$key]['url_id'];
650 $paymentloanstatic->ref = (string) $links[$key]['url_id'];
651 $paymentloanstatic->fk_loan = $links[$key]['url_id'];
652 $tabpay[$obj->rowid]["lib"] .= ' '.$paymentloanstatic->getNomUrl(2);
653 $tabpay[$obj->rowid]["paymentloanid"] = $paymentloanstatic->id;
654 //$tabtp[$obj->rowid][$account_pay_loan] += $amounttouse;
655 $sqlmid = 'SELECT pl.amount_capital, pl.amount_insurance, pl.amount_interest, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest';
656 $sqlmid .= ' FROM '.MAIN_DB_PREFIX.'payment_loan as pl, '.MAIN_DB_PREFIX.'loan as l';
657 $sqlmid .= ' WHERE l.rowid = pl.fk_loan AND pl.fk_bank = '.((int) $obj->rowid);
658
659 dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);
660 $resultmid = $db->query($sqlmid);
661 if ($resultmid) {
662 $objmid = $db->fetch_object($resultmid);
663 $tabtp[$obj->rowid][$objmid->accountancy_account_capital] = isset($objmid->amount_capital) ? ($tabtp[$obj->rowid][$objmid->accountancy_account_capital] ?? 0) - $objmid->amount_capital : 0;
664 $tabtp[$obj->rowid][$objmid->accountancy_account_insurance] = isset($objmid->amount_insurance) ? ($tabtp[$obj->rowid][$objmid->accountancy_account_insurance] ?? 0) - $objmid->amount_insurance : 0;
665 $tabtp[$obj->rowid][$objmid->accountancy_account_interest] = isset($objmid->amount_interest) ? ($tabtp[$obj->rowid][$objmid->accountancy_account_interest] ?? 0) - $objmid->amount_interest : 0;
666 }
667 } elseif ($links[$key]['type'] == 'banktransfert') {
668 $accountLinestatic->fetch($links[$key]['url_id']);
669 $tabpay[$obj->rowid]["lib"] .= ' '.$langs->trans("BankTransfer").' '.$accountLinestatic ->getNomUrl(1);
670 $tabtp[$obj->rowid][$account_transfer] = isset($tabtp[$obj->rowid][$account_transfer]) ? $tabtp[$obj->rowid][$account_transfer] + $amounttouse : $amounttouse;
671 $bankaccountstatic->fetch($tabpay[$obj->rowid]['fk_bank_account']);
672 $tabpay[$obj->rowid]["soclib"] = $bankaccountstatic->getNomUrl(2);
673 }
674 }
675 }
676
677 if (empty($tabbq[$obj->rowid][$compta_bank])) {
678 $tabbq[$obj->rowid][$compta_bank] = $amounttouse;
679 } else {
680 $tabbq[$obj->rowid][$compta_bank] += $amounttouse;
681 }
682
683 // If no links were found to know the amount on thirdparty, we try to guess it.
684 // This may happen on bank entries without the links lines to 'company'.
685 if (empty($tabtp[$obj->rowid]) && !empty($tabmoreinfo[$obj->rowid]['withdraw'])) { // If we don't find 'company' link because it is an old 'withdraw' record
686 foreach ($links as $key => $val) {
687 if ($links[$key]['type'] == 'payment') {
688 // Get thirdparty
689 $tmppayment->fetch($links[$key]['url_id']);
690 $arrayofamounts = $tmppayment->getAmountsArray();
691 if (is_array($arrayofamounts)) {
692 foreach ($arrayofamounts as $invoiceid => $amount) {
693 $tmpinvoice->fetch($invoiceid);
694 $tmpinvoice->fetch_thirdparty();
695 if ($tmpinvoice->thirdparty->code_compta_client) {
696 $tabtp[$obj->rowid][$tmpinvoice->thirdparty->code_compta_client] += $amount;
697 }
698 }
699 }
700 }
701 }
702 }
703
704 // If no links were found to know the amount on thirdparty/user, we init it to account 'NotDefined'.
705 if (empty($tabtp[$obj->rowid])) {
706 $tabtp[$obj->rowid]['NotDefined'] = $tabbq[$obj->rowid][$compta_bank];
707 }
708
709 // if($obj->socid)$tabtp[$obj->rowid][$compta_soc] += $amounttouse;
710
711 $i++;
712 }
713} else {
715}
716
717// Write bookkeeping
718if (!$error && $action == 'writebookkeeping' && $user->hasRight('accounting', 'bind', 'write')) {
719 $now = dol_now();
720
721 $accountingaccountcustomer = new AccountingAccount($db);
722 $accountingaccountcustomer->fetch(0, getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER'), true);
723
724 $accountingaccountsupplier = new AccountingAccount($db);
725 $accountingaccountsupplier->fetch(0, getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER'), true);
726
727 $accountingaccountpayment = new AccountingAccount($db);
728 $accountingaccountpayment->fetch(0, getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT'), true);
729
730 $accountingaccountexpensereport = new AccountingAccount($db);
731 $accountingaccountexpensereport->fetch(0, getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT'), true);
732
733 $accountingaccountsuspense = new AccountingAccount($db);
734 $accountingaccountsuspense->fetch(0, getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE'), true);
735
736 $error = 0;
737 foreach ($tabpay as $key => $val) { // $key is rowid into llx_bank
738 $date = dol_print_date($val["date"], 'day');
739
740 $ref = getSourceDocRef($val, $tabtype[$key]);
741
742 $errorforline = 0;
743
744 $totalcredit = 0;
745 $totaldebit = 0;
746
747 $db->begin();
748
749 // Introduce a protection. Total of tabtp must be total of tabbq
750
751 // Bank
752 if (is_array($tabbq[$key])) {
753 // Line into bank account
754 foreach ($tabbq[$key] as $k => $mt) {
755 if ($mt) {
756 if (empty($conf->cache['accountingaccountincurrententity'][$k])) {
757 $accountingaccount = new AccountingAccount($db);
758 $accountingaccount->fetch(0, $k, true); // $k is accounting account of the bank.
759 $conf->cache['accountingaccountincurrententity'][$k] = $accountingaccount;
760 } else {
761 $accountingaccount = $conf->cache['accountingaccountincurrententity'][$k];
762 }
763
764 $account_label = $accountingaccount->label;
765
766 $reflabel = '';
767 if (!empty($val['lib'])) {
768 $reflabel .= dol_string_nohtmltag($val['lib'])." / ";
769 }
770 $reflabel .= $langs->trans("Bank").' '.dol_string_nohtmltag($val['bank_account_ref']);
771 if (!empty($val['soclib'])) {
772 $reflabel .= " / ".dol_string_nohtmltag($val['soclib']);
773 }
774
775 $bookkeeping = new BookKeeping($db);
776 $bookkeeping->doc_date = $val["date"];
777 $bookkeeping->doc_ref = $ref;
778 $bookkeeping->doc_type = 'bank';
779 $bookkeeping->fk_doc = (int) $key;
780 $bookkeeping->fk_docdet = $val["fk_bank"];
781
782 $bookkeeping->numero_compte = $k;
783 $bookkeeping->label_compte = $account_label;
784
785 $bookkeeping->label_operation = $reflabel;
786 $bookkeeping->montant = $mt;
787 $bookkeeping->sens = ($mt >= 0) ? 'D' : 'C';
788 $bookkeeping->debit = ($mt >= 0 ? $mt : 0);
789 $bookkeeping->credit = ($mt < 0 ? -$mt : 0);
790 $bookkeeping->code_journal = $journal;
791 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
792 $bookkeeping->fk_user_author = $user->id;
793 $bookkeeping->date_creation = $now;
794
795 // No subledger_account value for the bank line but add a specific label_operation
796 $bookkeeping->subledger_account = '';
797 $bookkeeping->label_operation = $reflabel;
798 $bookkeeping->entity = $conf->entity;
799
800 $totaldebit += $bookkeeping->debit;
801 $totalcredit += $bookkeeping->credit;
802
803 $result = $bookkeeping->create($user);
804 if ($result < 0) {
805 if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists
806 $error++;
807 $errorforline++;
808 setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
809 } else {
810 $error++;
811 $errorforline++;
812 setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
813 }
814 }
815 }
816 }
817 }
818
819 // Third party
820 if (!$errorforline) {
821 if (is_array($tabtp[$key])) {
822 // Line into thirdparty account
823 foreach ($tabtp[$key] as $k => $mt) {
824 if ($mt) {
825 $lettering = false;
826
827 $reflabel = '';
828 if (!empty($val['lib'])) {
829 $reflabel .= dol_string_nohtmltag($val['lib']).(!empty($val['soclib']) ? " / " : "");
830 }
831 if ($tabtype[$key] == 'banktransfert') {
832 $reflabel .= dol_string_nohtmltag($langs->transnoentitiesnoconv('TransitionalAccount').' '.$account_transfer);
833 } else {
834 $reflabel .= dol_string_nohtmltag($val['soclib'] ?? '');
835 }
836
837 $bookkeeping = new BookKeeping($db);
838 $bookkeeping->doc_date = $val["date"];
839 $bookkeeping->doc_ref = $ref;
840 $bookkeeping->doc_type = 'bank';
841 $bookkeeping->fk_doc = (int) $key;
842 $bookkeeping->fk_docdet = $val["fk_bank"];
843
844 $bookkeeping->label_operation = $reflabel;
845 $bookkeeping->montant = $mt;
846 $bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
847 $bookkeeping->debit = ($mt < 0 ? -$mt : 0);
848 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
849 $bookkeeping->code_journal = $journal;
850 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
851 $bookkeeping->fk_user_author = $user->id;
852 $bookkeeping->date_creation = $now;
853
854 if ($tabtype[$key] == 'payment') { // If payment is payment of customer invoice, we get ref of invoice
855 $lettering = true;
856 $bookkeeping->subledger_account = $k; // For payment, the subledger account is stored as $key of $tabtp
857 $bookkeeping->subledger_label = $tabcompany[$key]['name']; // $tabcompany is defined only if we are sure there is 1 thirdparty for the bank transaction
858 $bookkeeping->numero_compte = $tabcompany[$key]['accountancy_code_general'];
859 $bookkeeping->label_compte = $accountingaccountcustomer->label;
860 } elseif ($tabtype[$key] == 'payment_supplier') { // If payment is payment of supplier invoice, we get ref of invoice
861 $lettering = true;
862 $bookkeeping->subledger_account = $k; // For payment, the subledger account is stored as $key of $tabtp
863 $bookkeeping->subledger_label = $tabcompany[$key]['name']; // $tabcompany is defined only if we are sure there is 1 thirdparty for the bank transaction
864 $bookkeeping->numero_compte = $tabcompany[$key]['accountancy_code_general'];
865 $bookkeeping->label_compte = $accountingaccountsupplier->label;
866 } elseif ($tabtype[$key] == 'payment_expensereport') {
867 $bookkeeping->subledger_account = $tabuser[$key]['accountancy_code'];
868 $bookkeeping->subledger_label = $tabuser[$key]['name'];
869 $bookkeeping->numero_compte = getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT');
870 $bookkeeping->label_compte = $accountingaccountexpensereport->label;
871 } elseif ($tabtype[$key] == 'payment_salary') {
872 $bookkeeping->subledger_account = $tabuser[$key]['accountancy_code'];
873 $bookkeeping->subledger_label = $tabuser[$key]['name'];
874 $bookkeeping->numero_compte = $tabuser[$key]['accountancy_code_general'];
875 $bookkeeping->label_compte = $accountingaccountpayment->label;
876 } elseif (in_array($tabtype[$key], array('sc', 'payment_sc'))) { // If payment is payment of social contribution
877 $bookkeeping->subledger_account = '';
878 $bookkeeping->subledger_label = '';
879 if (empty($conf->cache['accountingaccountincurrententity'][$k])) {
880 $accountingaccount = new AccountingAccount($db);
881 $accountingaccount->fetch(0, $k, true);
882 $conf->cache['accountingaccountincurrententity'][$k] = $accountingaccount;
883 } else {
884 $accountingaccount = $conf->cache['accountingaccountincurrententity'][$k];
885 }
886 $bookkeeping->numero_compte = $k;
887 $bookkeeping->label_compte = $accountingaccount->label;
888 } elseif ($tabtype[$key] == 'payment_vat') {
889 $bookkeeping->subledger_account = '';
890 $bookkeeping->subledger_label = '';
891 if (empty($conf->cache['accountingaccountincurrententity'][$k])) {
892 $accountingaccount = new AccountingAccount($db);
893 $accountingaccount->fetch(0, $k, true);
894 $conf->cache['accountingaccountincurrententity'][$k] = $accountingaccount;
895 } else {
896 $accountingaccount = $conf->cache['accountingaccountincurrententity'][$k];
897 }
898 $bookkeeping->numero_compte = $k;
899 $bookkeeping->label_compte = $accountingaccount->label;
900 } elseif ($tabtype[$key] == 'payment_donation') {
901 $bookkeeping->subledger_account = '';
902 $bookkeeping->subledger_label = '';
903 if (empty($conf->cache['accountingaccountincurrententity'][$k])) {
904 $accountingaccount = new AccountingAccount($db);
905 $accountingaccount->fetch(0, $k, true);
906 $conf->cache['accountingaccountincurrententity'][$k] = $accountingaccount;
907 } else {
908 $accountingaccount = $conf->cache['accountingaccountincurrententity'][$k];
909 }
910 $bookkeeping->numero_compte = $k;
911 $bookkeeping->label_compte = $accountingaccount->label;
912 } elseif ($tabtype[$key] == 'member') {
913 $bookkeeping->subledger_account = '';
914 $bookkeeping->subledger_label = '';
915 if (empty($conf->cache['accountingaccountincurrententity'][$k])) {
916 $accountingaccount = new AccountingAccount($db);
917 $accountingaccount->fetch(0, $k, true);
918 $conf->cache['accountingaccountincurrententity'][$k] = $accountingaccount;
919 } else {
920 $accountingaccount = $conf->cache['accountingaccountincurrententity'][$k];
921 }
922 $bookkeeping->numero_compte = $k;
923 $bookkeeping->label_compte = $accountingaccount->label;
924 } elseif ($tabtype[$key] == 'payment_loan') {
925 $bookkeeping->subledger_account = '';
926 $bookkeeping->subledger_label = '';
927 if (empty($conf->cache['accountingaccountincurrententity'][$k])) {
928 $accountingaccount = new AccountingAccount($db);
929 $accountingaccount->fetch(0, $k, true);
930 $conf->cache['accountingaccountincurrententity'][$k] = $accountingaccount;
931 } else {
932 $accountingaccount = $conf->cache['accountingaccountincurrententity'][$k];
933 }
934 $bookkeeping->numero_compte = $k;
935 $bookkeeping->label_compte = $accountingaccount->label;
936 } elseif ($tabtype[$key] == 'payment_various') {
937 $bookkeeping->subledger_account = $k;
938 $bookkeeping->subledger_label = $tabcompany[$key]['name'];
939 if (empty($conf->cache['accountingaccountincurrententity'][$tabpay[$key]["account_various"]])) {
940 $accountingaccount = new AccountingAccount($db);
941 $accountingaccount->fetch(0, $tabpay[$key]["account_various"], true);
942 $conf->cache['accountingaccountincurrententity'][$tabpay[$key]["account_various"]] = $accountingaccount;
943 } else {
944 $accountingaccount = $conf->cache['accountingaccountincurrententity'][$tabpay[$key]["account_various"]];
945 }
946 $bookkeeping->numero_compte = $tabpay[$key]["account_various"];
947 $bookkeeping->label_compte = $accountingaccount->label;
948 } elseif ($tabtype[$key] == 'banktransfert') {
949 $bookkeeping->subledger_account = '';
950 $bookkeeping->subledger_label = '';
951 if (empty($conf->cache['accountingaccountincurrententity'][$k])) {
952 $accountingaccount = new AccountingAccount($db);
953 $accountingaccount->fetch(0, $k, true);
954 $conf->cache['accountingaccountincurrententity'][$k] = $accountingaccount;
955 } else {
956 $accountingaccount = $conf->cache['accountingaccountincurrententity'][$k];
957 }
958 $bookkeeping->numero_compte = $k;
959 $bookkeeping->label_compte = $accountingaccount->label;
960 } else {
961 if ($tabtype[$key] == 'unknown') { // Unknown transaction, we will use a waiting account for thirdparty.
962 // Temporary account
963 $bookkeeping->subledger_account = '';
964 $bookkeeping->subledger_label = '';
965 $bookkeeping->numero_compte = getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE');
966 $bookkeeping->label_compte = $accountingaccountsuspense->label;
967 }
968 }
969 $bookkeeping->label_operation = $reflabel;
970 $bookkeeping->entity = $conf->entity;
971
972 $totaldebit += $bookkeeping->debit;
973 $totalcredit += $bookkeeping->credit;
974
975 $result = $bookkeeping->create($user);
976 if ($result < 0) {
977 if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists
978 $error++;
979 $errorforline++;
980 setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
981 } else {
982 $error++;
983 $errorforline++;
984 setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
985 }
986 } else {
987 if ($lettering && getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && getDolGlobalInt('ACCOUNTING_ENABLE_AUTOLETTERING')) {
988 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/lettering.class.php';
989 $lettering_static = new Lettering($db);
990 $nb_lettering = $lettering_static->bookkeepingLetteringAll(array($bookkeeping->id));
991 }
992 }
993 }
994 }
995 } else { // If thirdparty unknown, output the waiting account
996 foreach ($tabbq[$key] as $k => $mt) {
997 if ($mt) {
998 $reflabel = '';
999 if (!empty($val['lib'])) {
1000 $reflabel .= dol_string_nohtmltag($val['lib'])." / ";
1001 }
1002 $reflabel .= dol_string_nohtmltag('WaitingAccount');
1003
1004 $bookkeeping = new BookKeeping($db);
1005 $bookkeeping->doc_date = $val["date"];
1006 $bookkeeping->doc_ref = $ref;
1007 $bookkeeping->doc_type = 'bank';
1008 $bookkeeping->fk_doc = (int) $key;
1009 $bookkeeping->fk_docdet = $val["fk_bank"];
1010 $bookkeeping->montant = $mt;
1011 $bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
1012 $bookkeeping->debit = ($mt < 0 ? -$mt : 0);
1013 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
1014 $bookkeeping->code_journal = $journal;
1015 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
1016 $bookkeeping->fk_user_author = $user->id;
1017 $bookkeeping->date_creation = $now;
1018 $bookkeeping->label_compte = '';
1019 $bookkeeping->label_operation = $reflabel;
1020 $bookkeeping->entity = $conf->entity;
1021
1022 $totaldebit += $bookkeeping->debit;
1023 $totalcredit += $bookkeeping->credit;
1024
1025 $result = $bookkeeping->create($user);
1026
1027 if ($result < 0) {
1028 if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists
1029 $error++;
1030 $errorforline++;
1031 setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
1032 } else {
1033 $error++;
1034 $errorforline++;
1035 setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
1036 }
1037 }
1038 }
1039 }
1040 }
1041 }
1042
1043 if (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT')) {
1044 $error++;
1045 $errorforline++;
1046 setEventMessages('We tried to insert a non balanced transaction in book for '.$ref.'. Canceled. Surely a bug.', null, 'errors');
1047 }
1048
1049 if (!$errorforline) {
1050 $db->commit();
1051 } else {
1052 //print 'KO for line '.$key.' '.$error.'<br>';
1053 $db->rollback();
1054
1055 $MAXNBERRORS = 5;
1056 if ($error >= $MAXNBERRORS) {
1057 setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped").' (>'.$MAXNBERRORS.')', null, 'errors');
1058 break; // Break in the foreach
1059 }
1060 }
1061 }
1062
1063 if (empty($error) && count($tabpay) > 0) {
1064 setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
1065 } elseif (count($tabpay) == $error) {
1066 setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings');
1067 } else {
1068 setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings');
1069 }
1070
1071 $action = '';
1072
1073 // Must reload data, so we make a redirect
1074 if (count($tabpay) != $error) {
1075 $param = 'id_journal='.$id_journal;
1076 $param .= '&date_startday='.$date_startday;
1077 $param .= '&date_startmonth='.$date_startmonth;
1078 $param .= '&date_startyear='.$date_startyear;
1079 $param .= '&date_endday='.$date_endday;
1080 $param .= '&date_endmonth='.$date_endmonth;
1081 $param .= '&date_endyear='.$date_endyear;
1082 $param .= '&in_bookkeeping='.$in_bookkeeping;
1083 header("Location: ".$_SERVER['PHP_SELF'].($param ? '?'.$param : ''));
1084 exit;
1085 }
1086}
1087
1088
1089
1090// Export
1091if ($action == 'exportcsv' && $user->hasRight('accounting', 'bind', 'write')) { // ISO and not UTF8 !
1092 $sep = getDolGlobalString('ACCOUNTING_EXPORT_SEPARATORCSV');
1093
1094 $filename = 'journal';
1095 $type_export = 'journal';
1096 include DOL_DOCUMENT_ROOT.'/accountancy/tpl/export_journal.tpl.php';
1097
1098 // CSV header line
1099 print '"'.$langs->transnoentitiesnoconv("BankId").'"'.$sep;
1100 print '"'.$langs->transnoentitiesnoconv("Date").'"'.$sep;
1101 print '"'.$langs->transnoentitiesnoconv("PaymentMode").'"'.$sep;
1102 print '"'.$langs->transnoentitiesnoconv("AccountAccounting").'"'.$sep;
1103 print '"'.$langs->transnoentitiesnoconv("SubledgerAccount").'"'.$sep;
1104 print '"'.$langs->transnoentitiesnoconv("Label").'"'.$sep;
1105 print '"'.$langs->transnoentitiesnoconv("AccountingDebit").'"'.$sep;
1106 print '"'.$langs->transnoentitiesnoconv("AccountingCredit").'"'.$sep;
1107 print '"'.$langs->transnoentitiesnoconv("Journal").'"'.$sep;
1108 print '"'.$langs->transnoentitiesnoconv("Note").'"'.$sep;
1109 print "\n";
1110
1111 foreach ($tabpay as $key => $val) {
1112 $date = dol_print_date($val["date"], 'day');
1113
1114 $ref = getSourceDocRef($val, $tabtype[$key]);
1115
1116 // Bank
1117 foreach ($tabbq[$key] as $k => $mt) {
1118 if ($mt) {
1119 $reflabel = '';
1120 if (!empty($val['lib'])) {
1121 $reflabel .= dol_string_nohtmltag($val['lib'])." / ";
1122 }
1123 $reflabel .= $langs->trans("Bank").' '.dol_string_nohtmltag($val['bank_account_ref']);
1124 if (!empty($val['soclib'])) {
1125 $reflabel .= " / ".dol_string_nohtmltag($val['soclib']);
1126 }
1127
1128 print '"'.$key.'"'.$sep;
1129 print '"'.$date.'"'.$sep;
1130 print '"'.$val["type_payment"].'"'.$sep;
1131 print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
1132 print " ".$sep;
1133 print '"'.$reflabel.'"'.$sep;
1134 print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
1135 print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
1136 print '"'.$journal.'"'.$sep;
1137 print '"'.dol_string_nohtmltag($ref).'"'.$sep;
1138 print "\n";
1139 }
1140 }
1141
1142 // Third party
1143 if (is_array($tabtp[$key])) {
1144 foreach ($tabtp[$key] as $k => $mt) {
1145 if ($mt) {
1146 $reflabel = '';
1147 if (!empty($val['lib'])) {
1148 $reflabel .= dol_string_nohtmltag($val['lib']).(!empty($val['soclib']) ? " / " : "");
1149 }
1150 if ($tabtype[$key] == 'banktransfert') {
1151 $reflabel .= dol_string_nohtmltag($langs->transnoentitiesnoconv('TransitionalAccount').' '.$account_transfer);
1152 } else {
1153 $reflabel .= dol_string_nohtmltag($val['soclib'] ?? '');
1154 }
1155
1156 print '"'.$key.'"'.$sep;
1157 print '"'.$date.'"'.$sep;
1158 print '"'.$val["type_payment"].'"'.$sep;
1159 if ($tabtype[$key] == 'payment_supplier') {
1160 $account_ledger = (!empty($obj->accountancy_code_supplier_general)) ? $obj->accountancy_code_supplier_general : $account_supplier;
1161 print '"'.length_accountg($account_ledger).'"'.$sep;
1162 } elseif ($tabtype[$key] == 'payment') {
1163 $account_ledger = (!empty($obj->accountancy_code_customer_general)) ? $obj->accountancy_code_customer_general : $account_customer;
1164 print '"'.length_accountg($account_ledger).'"'.$sep;
1165 } elseif ($tabtype[$key] == 'payment_expensereport') {
1166 print '"'.length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT')).'"'.$sep;
1167 } elseif ($tabtype[$key] == 'payment_salary') {
1168 $account_ledger = (!empty($obj->accountancy_code_user_general)) ? $obj->accountancy_code_user_general : $account_employee;
1169 print '"'.length_accountg($account_ledger).'"'.$sep;
1170 } else {
1171 print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
1172 }
1173 print '"'.length_accounta(html_entity_decode($k)).'"'.$sep;
1174 print '"'.$reflabel.'"'.$sep;
1175 print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
1176 print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
1177 print '"'.$journal.'"'.$sep;
1178 print '"'.dol_string_nohtmltag($ref).'"'.$sep;
1179 print "\n";
1180 }
1181 }
1182 } else { // If thirdparty unknown, output the waiting account
1183 foreach ($tabbq[$key] as $k => $mt) {
1184 if ($mt) {
1185 $reflabel = '';
1186 if (!empty($val['lib'])) {
1187 $reflabel .= dol_string_nohtmltag($val['lib'])." / ";
1188 }
1189 $reflabel .= dol_string_nohtmltag('WaitingAccount');
1190
1191 print '"'.$key.'"'.$sep;
1192 print '"'.$date.'"'.$sep;
1193 print '"'.$val["type_payment"].'"'.$sep;
1194 print '"'.length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE')).'"'.$sep;
1195 print $sep;
1196 print '"'.$reflabel.'"'.$sep;
1197 print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
1198 print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
1199 print '"'.$journal.'"'.$sep;
1200 print '"'.dol_string_nohtmltag($ref).'"'.$sep;
1201 print "\n";
1202 }
1203 }
1204 }
1205 }
1206}
1207
1208
1209/*
1210 * View
1211 */
1212
1213$form = new Form($db);
1214
1215if (empty($action) || $action == 'view') {
1216 $invoicestatic = new Facture($db);
1217 $invoicesupplierstatic = new FactureFournisseur($db);
1218 $expensereportstatic = new ExpenseReport($db);
1219 $vatstatic = new Tva($db);
1220 $donationstatic = new Don($db);
1221 $loanstatic = new Loan($db);
1222 $salarystatic = new Salary($db);
1223 $variousstatic = new PaymentVarious($db);
1224
1225 $title = $langs->trans("GenerationOfAccountingEntries").' - '.$accountingjournalstatic->getNomUrl(0, 2, 1, '', 1);
1226 $help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilit&eacute;_en_Partie_Double#G&eacute;n&eacute;ration_des_&eacute;critures_en_comptabilit&eacute;';
1227 llxHeader('', dol_string_nohtmltag($title), $help_url, '', 0, 0, '', '', '', 'mod-accountancy accountancy-generation page-bankjournal');
1228
1229 $nom = $title;
1230 $builddate = dol_now();
1231 //$description = $langs->trans("DescFinanceJournal") . '<br>';
1232 $description = $langs->trans("DescJournalOnlyBindedVisible").'<br>';
1233
1234 $listofchoices = array(
1235 'notyet' => $langs->trans("NotYetInGeneralLedger"),
1236 'already' => $langs->trans("AlreadyInGeneralLedger")
1237 );
1238 $period = $form->selectDate($date_start ? $date_start : -1, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end ? $date_end : -1, 'date_end', 0, 0, 0, '', 1, 0);
1239 $period .= '<span class="valignmiddle"> - '.$langs->trans("JournalizationInLedgerStatus").' </span>'.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1, 0, 0, '', 0, 0, 0, '', 'minwidth75 valignmiddle');
1240
1241 $varlink = 'id_journal='.$id_journal;
1242 $periodlink = '';
1243 $exportlink = '';
1244
1245 $listofchoices = array(
1246 1 => $langs->trans("TransfertAllBankLines"),
1247 2 => $langs->trans("TransfertOnlyConciliatedBankLine")
1248 );
1249 $moreoptions = [ "BankLineConciliated" => $form->selectarray('only_rappro', $listofchoices, $only_rappro, 0, 0, 0, '', 0, 0, 0, '', 'minwidth75 valignmiddle')];
1250
1251 journalHead($nom, '', $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink, $moreoptions);
1252
1253 $desc = '';
1254
1255 if (getDolGlobalString('ACCOUNTANCY_FISCAL_PERIOD_MODE') != 'blockedonclosed') {
1256 // Test that setup is complete (we are in accounting, so test on entity is always on $conf->entity only, no sharing allowed)
1257 // Fiscal period test
1258 $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_fiscalyear WHERE entity = ".((int) $conf->entity);
1259 $resql = $db->query($sql);
1260 if ($resql) {
1261 $obj = $db->fetch_object($resql);
1262 if ($obj->nb == 0) {
1263 print '<br><div class="warning">'.img_warning().' '.$langs->trans("TheFiscalPeriodIsNotDefined");
1264 $desc = ' : '.$langs->trans("AccountancyAreaDescFiscalPeriod", 4, '{link}');
1265 $desc = str_replace('{link}', '<strong>'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("FiscalPeriod").'</strong>', $desc);
1266 print $desc;
1267 print '</div>';
1268 }
1269 } else {
1271 }
1272 }
1273
1274 // Bank test
1275 $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."bank_account WHERE entity = ".((int) $conf->entity)." AND fk_accountancy_journal IS NULL AND clos=0";
1276 $resql = $db->query($sql);
1277 if ($resql) {
1278 $obj = $db->fetch_object($resql);
1279 if ($obj->nb > 0) {
1280 print '<br><div class="warning">'.img_warning().' '.$langs->trans("TheJournalCodeIsNotDefinedOnSomeBankAccount");
1281 $desc = ' : '.$langs->trans("AccountancyAreaDescBank", 6, '{link}');
1282 $desc = str_replace('{link}', '<strong>'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("BankAccounts").'</strong>', $desc);
1283 print $desc;
1284 print '</div>';
1285 }
1286 } else {
1288 }
1289
1290
1291 // Button to write into Ledger
1292 if (getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER') == "" || getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER') == '-1'
1293 || getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER') == "" || getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER') == '-1'
1294 || (isModEnabled("salaries") && (getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT') == "" || getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT') == '-1'))
1295 || (isModEnabled("expensereport") && (getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT') == "" || getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT') == '-1'))) {
1296
1297
1298 print($desc ? '' : '<br>').'<div class="warning">'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone");
1299 $desc = ' : '.$langs->trans("AccountancyAreaDescMisc", 4, '{link}');
1300 $desc = str_replace('{link}', '<strong>'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'</strong>', $desc);
1301 print $desc;
1302 print '</div>';
1303 }
1304
1305
1306 print '<br><div class="tabsAction tabsActionNoBottom centerimp">';
1307
1308 if (getDolGlobalString('ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping == 'notyet') {
1309 print '<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans("ExportDraftJournal").'" onclick="launch_export();" />';
1310 }
1311
1312 if (getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER') == "" || getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER') == '-1'
1313 || getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER') == "" || getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER') == '-1') {
1314 print '<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("SomeMandatoryStepsOfSetupWereNotDone")).'" value="'.$langs->trans("WriteBookKeeping").'" />';
1315 } else {
1316 if ($in_bookkeeping == 'notyet') {
1317 print '<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans("WriteBookKeeping").'" onclick="writebookkeeping();" />';
1318 } else {
1319 print '<a class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans("WriteBookKeeping").'</a>';
1320 }
1321 }
1322
1323 print '</div>';
1324
1325 // TODO Avoid using js. We can use a direct link with $param
1326 print '
1327 <script type="text/javascript">
1328 function launch_export() {
1329 console.log("Set value into form and submit");
1330 $("div.fiche form input[name=\"action\"]").val("exportcsv");
1331 $("div.fiche form input[type=\"submit\"]").click();
1332 $("div.fiche form input[name=\"action\"]").val("");
1333 }
1334 function writebookkeeping() {
1335 console.log("Set value into form and submit");
1336 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
1337 $("div.fiche form input[type=\"submit\"]").click();
1338 $("div.fiche form input[name=\"action\"]").val("");
1339 }
1340 </script>';
1341
1342 /*
1343 * Show result array
1344 */
1345 print '<br>';
1346
1347 $i = 0;
1348 print '<div class="div-table-responsive">';
1349 print '<table class="noborder centpercent">';
1350 print '<tr class="liste_titre">';
1351 print "<td>".$langs->trans("Date")."</td>";
1352 print "<td>".$langs->trans("Piece").' ('.$langs->trans("ObjectsRef").")</td>";
1353 print "<td>".$langs->trans("AccountAccounting")."</td>";
1354 print "<td>".$langs->trans("SubledgerAccount")."</td>";
1355 print "<td>".$langs->trans("LabelOperation")."</td>";
1356 print '<td class="center">'.$langs->trans("PaymentMode")."</td>";
1357 print '<td class="right">'.$langs->trans("AccountingDebit")."</td>";
1358 print '<td class="right">'.$langs->trans("AccountingCredit")."</td>";
1359 print "</tr>\n";
1360
1361 foreach ($tabpay as $key => $val) { // $key is rowid in llx_bank
1362 $date = dol_print_date($val["date"], 'day');
1363
1364 $ref = getSourceDocRef($val, $tabtype[$key]);
1365
1366 // Bank
1367 foreach ($tabbq[$key] as $k => $mt) {
1368 if ($mt) {
1369 $reflabel = '';
1370 if (!empty($val['lib'])) {
1371 $reflabel .= $val['lib']." / ";
1372 }
1373 $reflabel .= $langs->trans("Bank").' '.$val['bank_account_ref'];
1374 if (!empty($val['soclib'])) {
1375 $reflabel .= " / ".$val['soclib'];
1376 }
1377
1378 //var_dump($tabpay[$key]);
1379 print '<!-- Bank bank.rowid='.$key.'=accounting_bookkeeping.fk_doc (accounting_bookkeeping.doc_type=\'bank\') type='.$tabpay[$key]['type'].' ref='.$tabpay[$key]['ref'].' -->';
1380 print '<tr class="oddeven">';
1381
1382 // Date
1383 print "<td>".$date."</td>";
1384
1385 // Ref
1386 print '<td class="maxwidth300 nopaddingtopimp nopaddingbottomimp">'.dol_escape_htmltag($ref)."</td>";
1387
1388 // Ledger account
1389 $accounttoshow = length_accountg($k);
1390 if (empty($accounttoshow) || $accounttoshow == 'NotDefined') {
1391 $accounttoshow = '<span class="error">'.$langs->trans("BankAccountNotDefined").'</span>';
1392 }
1393 print '<td class="maxwidth300" title="'.dol_escape_htmltag(dol_string_nohtmltag($accounttoshow)).'">';
1394 print $accounttoshow;
1395 print "</td>";
1396
1397 // Subledger account
1398 print '<td class="maxwidth300">';
1399 /*$accounttoshow = length_accountg($k);
1400 if (empty($accounttoshow) || $accounttoshow == 'NotDefined')
1401 {
1402 print '<span class="error">'.$langs->trans("BankAccountNotDefined").'</span>';
1403 }
1404 else print $accounttoshow;*/
1405 print "</td>";
1406
1407 // Label operation
1408 print '<td class="maxwidth300 nopaddingtopimp nopaddingbottomimp">';
1409 print $reflabel; // This is already html escaped content
1410 print "</td>";
1411
1412 print '<td class="center">'.$val["type_payment"]."</td>";
1413 print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
1414 print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
1415 print "</tr>";
1416
1417 $i++;
1418 }
1419 }
1420
1421 // Third party
1422 if (is_array($tabtp[$key])) {
1423 foreach ($tabtp[$key] as $k => $mt) {
1424 if ($mt) {
1425 $reflabel = '';
1426 if (!empty($val['lib'])) {
1427 $reflabel .= $val['lib'].(!empty($val['soclib']) ? " / " : "");
1428 }
1429 if ($tabtype[$key] == 'banktransfert') {
1430 $reflabel .= $langs->trans('TransitionalAccount').' '.$account_transfer;
1431 } else {
1432 $reflabel .= isset($val['soclib']) ? $val['soclib'] : "";
1433 }
1434
1435 print '<!-- Thirdparty bank.rowid='.$key.'=accounting_bookkeeping.fk_doc (accounting_bookkeeping.doc_type=\'bank\') type='.$tabpay[$key]['type'].' ref='.$tabpay[$key]['ref'].' -->';
1436 print '<tr class="oddeven">';
1437
1438 // Date
1439 print "<td>".$date."</td>";
1440
1441 // Ref / Piece
1442 print '<td class="nopaddingtopimp nopaddingbottomimp">'.dol_escape_htmltag($ref)."</td>";
1443
1444
1445 // Ledger account
1446 $account_ledger = $k;
1447 // Try to force general ledger account depending on type
1448 if ($tabtype[$key] == 'payment') {
1449 $account_ledger = (!empty($obj->accountancy_code_customer_general)) ? $obj->accountancy_code_customer_general : $account_customer;
1450 }
1451 if ($tabtype[$key] == 'payment_supplier') {
1452 $account_ledger = (!empty($obj->accountancy_code_supplier_general)) ? $obj->accountancy_code_supplier_general : $account_supplier;
1453 }
1454 if ($tabtype[$key] == 'payment_expensereport') {
1455 $account_ledger = getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT');
1456 }
1457 if ($tabtype[$key] == 'payment_salary') {
1458 $account_ledger = (!empty($obj->accountancy_code_user_general)) ? $obj->accountancy_code_user_general : $account_employee;
1459 }
1460 if ($tabtype[$key] == 'payment_vat') {
1461 $account_ledger = getDolGlobalString('ACCOUNTING_VAT_PAY_ACCOUNT');
1462 }
1463 if ($tabtype[$key] == 'member') {
1464 $account_ledger = getDolGlobalString('ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT');
1465 }
1466 if ($tabtype[$key] == 'payment_various') {
1467 $account_ledger = $tabpay[$key]["account_various"];
1468 }
1469 $accounttoshow = length_accountg($account_ledger);
1470 if (empty($accounttoshow) || $accounttoshow == 'NotDefined') {
1471 if ($tabtype[$key] == 'unknown') {
1472 // We will accept writing, but into a waiting account
1473 if (!getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE') || getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE') == '-1') {
1474 $accounttoshow = '<span class="error small">'.$langs->trans('UnknownAccountForThirdpartyAndWaitingAccountNotDefinedBlocking').'</span>';
1475 } else {
1476 $accounttoshow = '<span class="warning small">'.$langs->trans('UnknownAccountForThirdparty', length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE'))).'</span>'; // We will use a waiting account
1477 }
1478 } else {
1479 // We will refuse writing
1480 $errorstring = 'UnknownAccountForThirdpartyBlocking';
1481 if ($tabtype[$key] == 'payment') {
1482 $errorstring = 'MainAccountForCustomersNotDefined';
1483 }
1484 if ($tabtype[$key] == 'payment_supplier') {
1485 $errorstring = 'MainAccountForSuppliersNotDefined';
1486 }
1487 if ($tabtype[$key] == 'payment_expensereport') {
1488 $errorstring = 'MainAccountForUsersNotDefined';
1489 }
1490 if ($tabtype[$key] == 'payment_salary') {
1491 $errorstring = 'MainAccountForUsersNotDefined';
1492 }
1493 if ($tabtype[$key] == 'payment_vat') {
1494 $errorstring = 'MainAccountForVatPaymentNotDefined';
1495 }
1496 if ($tabtype[$key] == 'member') {
1497 $errorstring = 'MainAccountForSubscriptionPaymentNotDefined';
1498 }
1499 $accounttoshow = '<span class="error small">'.$langs->trans($errorstring).'</span>';
1500 }
1501 }
1502 print '<td class="maxwidth300" title="'.dol_escape_htmltag(dol_string_nohtmltag($accounttoshow)).'">';
1503 print $accounttoshow; // This is a HTML string
1504 print "</td>";
1505
1506 // Subledger account
1507 $accounttoshowsubledger = '';
1508 if (in_array($tabtype[$key], array('payment', 'payment_supplier', 'payment_expensereport', 'payment_salary', 'payment_various'))) { // Type of payments that uses a subledger
1509 $accounttoshowsubledger = length_accounta($k);
1510 if ($accounttoshow != $accounttoshowsubledger) {
1511 if (empty($accounttoshowsubledger) || $accounttoshowsubledger == 'NotDefined') {
1512 //print '<span class="error">'.$langs->trans("ThirdpartyAccountNotDefined").'</span>';
1513 if (!empty($tabcompany[$key]['code_compta'])) {
1514 if (in_array($tabtype[$key], array('payment_various'))) {
1515 // For such case, if subledger is not defined, we won't use subledger accounts.
1516 $accounttoshowsubledger = '<span class="warning small twolinesmax">'.$langs->trans("ThirdpartyAccountNotDefinedOrThirdPartyUnknownSubledgerIgnored").'</span>';
1517 } elseif (in_array($tabtype[$key], array('payment_salary'))) {
1518 $accounttoshowsubledger = '<span class="warning small twolinesmax">'.$langs->trans("ThirdpartyAccountNotDefinedOrThirdPartyUnknownSubledgerIgnored2").'</span>';
1519 } else {
1520 $accounttoshowsubledger = '<span class="warning small twolinesmax">'.$langs->trans("ThirdpartyAccountNotDefinedOrThirdPartyUnknown", $tabcompany[$key]['code_compta']).'</span>';
1521 }
1522 } else {
1523 $accounttoshowsubledger = '<span class="error small twolinesmax">'.$langs->trans("ThirdpartyAccountNotDefinedOrThirdPartyUnknownBlocking").'</span>';
1524 }
1525 }
1526 } else {
1527 $accounttoshowsubledger = '';
1528 }
1529 }
1530 print '<td class="maxwidth300 nopaddingtopimp nopaddingbottomimp" title="'.dolPrintHTMLForAttribute(dol_string_nohtmltag($accounttoshowsubledger)).'">';
1531 print $accounttoshowsubledger; // This is a html string
1532 print "</td>";
1533
1534 // Label operation
1535 print '<td class="nopaddingtopimpo paddingbottomimp">';
1536 print $reflabel; // This is a html string
1537 print "</td>";
1538
1539 print '<td class="center">'.$val["type_payment"]."</td>";
1540
1541 print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
1542
1543 print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
1544
1545 print "</tr>";
1546
1547 $i++;
1548 }
1549 }
1550 } else { // Waiting account
1551 foreach ($tabbq[$key] as $k => $mt) {
1552 if ($mt) {
1553 $reflabel = '';
1554 if (!empty($val['lib'])) {
1555 $reflabel .= $val['lib']." / ";
1556 }
1557 $reflabel .= 'WaitingAccount';
1558
1559 print '<!-- Wait bank.rowid='.$key.' -->';
1560 print '<tr class="oddeven">';
1561 print "<td>".$date."</td>";
1562 print "<td>".$ref."</td>";
1563 // Ledger account
1564 print "<td>";
1565 /*if (empty($accounttoshow) || $accounttoshow == 'NotDefined')
1566 {
1567 print '<span class="error">'.$langs->trans("WaitAccountNotDefined").'</span>';
1568 }
1569 else */
1570 print length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE'));
1571 print "</td>";
1572 // Subledger account
1573 print "<td>";
1574 print "</td>";
1575 print "<td>".dol_escape_htmltag($reflabel)."</td>";
1576 print '<td class="center">'.$val["type_payment"]."</td>";
1577 print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
1578 print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
1579 print "</tr>";
1580
1581 $i++;
1582 }
1583 }
1584 }
1585 }
1586
1587 if (!$i) {
1588 $colspan = 8;
1589 print '<tr class="oddeven"><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1590 }
1591
1592 print "</table>";
1593 print '</div>';
1594
1595 llxFooter();
1596}
1597
1598$db->close();
1599
1600
1601
1609function getSourceDocRef($val, $typerecord)
1610{
1611 global $db, $langs;
1612
1613 // Defined the docref into $ref (We start with $val['ref'] by default and we complete according to other data)
1614 // WE MUST HAVE SAME REF FOR ALL LINES WE WILL RECORD INTO THE BOOKKEEPING
1615 $ref = $val['ref'];
1616 if ($ref == '(SupplierInvoicePayment)' || $ref == '(SupplierInvoicePaymentBack)') {
1617 $ref = $langs->transnoentitiesnoconv('Supplier');
1618 }
1619 if ($ref == '(CustomerInvoicePayment)' || $ref == '(CustomerInvoicePaymentBack)') {
1620 $ref = $langs->transnoentitiesnoconv('Customer');
1621 }
1622 if ($ref == '(SocialContributionPayment)') {
1623 $ref = $langs->transnoentitiesnoconv('SocialContribution');
1624 }
1625 if ($ref == '(DonationPayment)') {
1626 $ref = $langs->transnoentitiesnoconv('Donation');
1627 }
1628 if ($ref == '(SubscriptionPayment)') {
1629 $ref = $langs->transnoentitiesnoconv('Subscription');
1630 }
1631 if ($ref == '(ExpenseReportPayment)') {
1632 $ref = $langs->transnoentitiesnoconv('Employee');
1633 }
1634 if ($ref == '(LoanPayment)') {
1635 $ref = $langs->transnoentitiesnoconv('Loan');
1636 }
1637 if ($ref == '(payment_salary)') {
1638 $ref = $langs->transnoentitiesnoconv('Employee');
1639 }
1640
1641 $sqlmid = '';
1642 if ($typerecord == 'payment') {
1643 if (getDolGlobalInt('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
1644 $sqlmid = "SELECT payfac.fk_facture as id, ".$db->ifsql('f1.rowid IS NULL', 'f.ref', 'f1.ref')." as ref";
1645 $sqlmid .= " FROM ".$db->prefix()."paiement_facture as payfac";
1646 $sqlmid .= " LEFT JOIN ".$db->prefix()."facture as f ON f.rowid = payfac.fk_facture";
1647 $sqlmid .= " LEFT JOIN ".$db->prefix()."societe_remise_except as sre ON sre.fk_facture_source = payfac.fk_facture";
1648 $sqlmid .= " LEFT JOIN ".$db->prefix()."facture as f1 ON f1.rowid = sre.fk_facture";
1649 $sqlmid .= " WHERE payfac.fk_paiement=".((int) $val['paymentid']);
1650 } else {
1651 $sqlmid = "SELECT payfac.fk_facture as id, f.ref as ref";
1652 $sqlmid .= " FROM ".$db->prefix()."paiement_facture as payfac";
1653 $sqlmid .= " INNER JOIN ".$db->prefix()."facture as f ON f.rowid = payfac.fk_facture";
1654 $sqlmid .= " WHERE payfac.fk_paiement=".((int) $val['paymentid']);
1655 }
1656 $ref = $langs->transnoentitiesnoconv("Invoice");
1657 } elseif ($typerecord == 'payment_supplier') {
1658 $sqlmid = 'SELECT payfac.fk_facturefourn as id, f.ref';
1659 $sqlmid .= " FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn as payfac, ".MAIN_DB_PREFIX."facture_fourn as f";
1660 $sqlmid .= " WHERE payfac.fk_facturefourn = f.rowid AND payfac.fk_paiementfourn=".((int) $val["paymentsupplierid"]);
1661 $ref = $langs->transnoentitiesnoconv("SupplierInvoice");
1662 } elseif ($typerecord == 'payment_expensereport') {
1663 $sqlmid = 'SELECT e.rowid as id, e.ref';
1664 $sqlmid .= " FROM ".MAIN_DB_PREFIX."payment_expensereport as pe, ".MAIN_DB_PREFIX."expensereport as e";
1665 $sqlmid .= " WHERE pe.rowid=".((int) $val["paymentexpensereport"])." AND pe.fk_expensereport = e.rowid";
1666 $ref = $langs->transnoentitiesnoconv("ExpenseReport");
1667 } elseif ($typerecord == 'payment_salary') {
1668 $sqlmid = 'SELECT s.rowid as ref';
1669 $sqlmid .= " FROM ".MAIN_DB_PREFIX."payment_salary as s";
1670 $sqlmid .= " WHERE s.rowid=".((int) $val["paymentsalid"]);
1671 $ref = $langs->transnoentitiesnoconv("SalaryPayment");
1672 } elseif ($typerecord == 'sc') {
1673 $sqlmid = 'SELECT sc.rowid as ref';
1674 $sqlmid .= " FROM ".MAIN_DB_PREFIX."paiementcharge as sc";
1675 $sqlmid .= " WHERE sc.rowid=".((int) $val["paymentscid"]);
1676 $ref = $langs->transnoentitiesnoconv("SocialContribution");
1677 } elseif ($typerecord == 'payment_vat') {
1678 $sqlmid = 'SELECT v.rowid as ref';
1679 $sqlmid .= " FROM ".MAIN_DB_PREFIX."tva as v";
1680 $sqlmid .= " WHERE v.rowid=".((int) $val["paymentvatid"]);
1681 $ref = $langs->transnoentitiesnoconv("PaymentVat");
1682 } elseif ($typerecord == 'payment_donation') {
1683 $sqlmid = 'SELECT payd.fk_donation as ref';
1684 $sqlmid .= " FROM ".MAIN_DB_PREFIX."payment_donation as payd";
1685 $sqlmid .= " WHERE payd.fk_donation=".((int) $val["paymentdonationid"]);
1686 $ref = $langs->transnoentitiesnoconv("Donation");
1687 } elseif ($typerecord == 'payment_loan') {
1688 $sqlmid = 'SELECT l.rowid as ref';
1689 $sqlmid .= " FROM ".MAIN_DB_PREFIX."payment_loan as l";
1690 $sqlmid .= " WHERE l.rowid=".((int) $val["paymentloanid"]);
1691 $ref = $langs->transnoentitiesnoconv("LoanPayment");
1692 } elseif ($typerecord == 'payment_various') {
1693 $sqlmid = 'SELECT v.rowid as ref';
1694 $sqlmid .= " FROM ".MAIN_DB_PREFIX."payment_various as v";
1695 $sqlmid .= " WHERE v.rowid=".((int) $val["paymentvariousid"]);
1696 $ref = $langs->transnoentitiesnoconv("VariousPayment");
1697 }
1698 // Add warning
1699 if (empty($sqlmid)) {
1700 dol_syslog("Found a typerecord=".$typerecord." not supported", LOG_WARNING);
1701 }
1702
1703 if ($sqlmid) {
1704 dol_syslog("accountancy/journal/bankjournal.php::sqlmid=".$sqlmid, LOG_DEBUG);
1705 $resultmid = $db->query($sqlmid);
1706 if ($resultmid) {
1707 while ($objmid = $db->fetch_object($resultmid)) {
1708 $ref .= ' '.$objmid->ref;
1709 }
1710 } else {
1712 }
1713 }
1714
1715 $ref = dol_trunc($langs->transnoentitiesnoconv("BankId").' '.$val['fk_bank'].' - '.$ref, 295); // 295 + 3 dots (...) is < than max size of 300
1716 return $ref;
1717}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
journalHead($nom, $variant, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='', $moreoptions=array())
Show header of a page used to transfer/dispatch data in accounting.
getDefaultDatesForTransfer()
Return Default dates for transfer based on periodicity option in accountancy setup.
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
getSourceDocRef($val, $typerecord)
Return source for doc_ref of a bank transaction.
Class to manage bank accounts.
Class to manage bank transaction lines.
Class to manage accounting accounts.
Class to manage accounting journals.
Class to manage Ledger (General Ledger and Subledger)
Class for managing the social charges.
Class to manage donations.
Definition don.class.php:41
Class to manage Trips and Expenses.
Class to manage suppliers invoices.
Class to manage invoices.
Class to manage generation of HTML components Only common components must be here.
Class Lettering.
Loan.
Class to manage payments for supplier invoices.
Class to manage payments of customer invoices.
Class to manage payments of donations.
Class to manage payments of expense report.
Class to manage payments of loans.
Class to manage payments of salaries.
Class to manage various payments.
Class to manage salary payments.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage subscriptions of foundation members.
Class to manage VAT - Value-added tax (also known in French as TVA)
Definition tva.class.php:39
Class to manage Dolibarr users.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:604
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:623
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.