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