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';
67$langs->loadLangs(array(
"companies",
"other",
"compta",
"banks",
"bills",
"donations",
"loan",
"accountancy",
"trips",
"salaries",
"hrm",
"members"));
72$date_startmonth =
GETPOSTINT(
'date_startmonth');
78$in_bookkeeping =
GETPOST(
'in_bookkeeping',
'aZ09');
81if ($only_rappro == 0) {
88$action =
GETPOST(
'action',
'aZ09');
90if ($in_bookkeeping ==
'') {
91 $in_bookkeeping =
'notyet';
96if (!isModEnabled(
'accounting')) {
99if ($user->socid > 0) {
102if (!$user->hasRight(
'accounting',
'bind',
'write')) {
113$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
114$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
117$pastmonthyear =
null;
119if (empty($date_startmonth)) {
122 $date_start = $dates[
'date_start'];
123 $pastmonthyear = $dates[
'pastmonthyear'];
124 $pastmonth = $dates[
'pastmonth'];
126if (empty($date_endmonth)) {
129 $date_end = $dates[
'date_end'];
130 $pastmonthyear = $dates[
'pastmonthyear'];
131 $pastmonth = $dates[
'pastmonth'];
134if (!GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end))) {
139$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,";
140$sql .=
" ba.courant, ba.ref as baref, ba.account_number, ba.fk_accountancy_journal,";
141$sql .=
" soc.rowid as socid, soc.nom as name, soc.email as email, bu1.type as typeop_company,";
143 $sql .=
" spe.accountancy_code_customer as code_compta_client,";
144 $sql .=
" spe.accountancy_code_supplier as code_compta_fournisseur,";
146 $sql .=
" soc.code_compta as code_compta_client,";
147 $sql .=
" soc.code_compta_fournisseur,";
149$sql .=
" u.accountancy_code, u.rowid as userid, u.lastname as lastname, u.firstname as firstname, u.email as useremail, u.statut as userstatus,";
150$sql .=
" bu2.type as typeop_user,";
151$sql .=
" bu3.type as typeop_payment, bu4.type as typeop_payment_supplier";
152$sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
153$sql .=
" JOIN ".MAIN_DB_PREFIX.
"bank_account as ba on b.fk_account=ba.rowid";
154$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'";
155$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON bu2.fk_bank = b.rowid AND bu2.type='user'";
156$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu3 ON bu3.fk_bank = b.rowid AND bu3.type='payment'";
157$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu4 ON bu4.fk_bank = b.rowid AND bu4.type='payment_supplier'";
158$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as soc on bu1.url_id=soc.rowid";
160 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = soc.rowid AND spe.entity = " . ((int) $conf->entity);
162$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on bu2.url_id=u.rowid";
163$sql .=
" WHERE ba.fk_accountancy_journal=".((int) $id_journal);
164$sql .=
' AND b.amount <> 0 AND ba.entity IN ('.getEntity(
'bank_account', 0).
')';
165if ($date_start && $date_end) {
166 $sql .=
" AND b.dateo >= '".$db->idate($date_start).
"' AND b.dateo <= '".$db->idate($date_end).
"'";
170 $sql .=
" AND b.dateo >= '".$db->idate(
getDolGlobalInt(
'ACCOUNTING_DATE_START_BINDING')).
"'";
173if ($in_bookkeeping ==
'already') {
174 $sql .=
" AND (b.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
176if ($in_bookkeeping ==
'notyet') {
177 $sql .=
" AND (b.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
179if ($only_rappro == 2) {
180 $sql .=
" AND (b.rappro = '1')";
182$sql .=
" ORDER BY b.datev";
188$societestatic =
new Societe($db);
189$userstatic =
new User($db);
190$bankaccountstatic =
new Account($db);
193$paymentvatstatic =
new Tva($db);
205$account_transfer =
'NotDefined';
209$accountingjournalstatic->fetch($id_journal);
210$journal = $accountingjournalstatic->code;
211$journal_label = $accountingjournalstatic->label;
213$tabcompany = array();
219$tabmoreinfo = array();
222@phan-var-force array<array{id:mixed,name:mixed,code_compta_client:string,email:string}> $tabcompany
223@phan-var-force array<array{id:int,name:string,lastname:string,firstname:string,email:string,accountancy_code:string,status:int> $tabuser
224@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
225@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
229dol_syslog(
"accountancy/journal/bankjournal.php", LOG_DEBUG);
230$result = $db->query($sql);
232 $num = $db->num_rows($result);
238 $account_employee =
getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT',
'NotDefined');
239 $account_expensereport =
getDolGlobalString(
'ACCOUNTING_ACCOUNT_EXPENSEREPORT',
'NotDefined');
241 $account_pay_donation =
getDolGlobalString(
'DONATION_ACCOUNTINGACCOUNT',
'NotDefined');
242 $account_pay_subscription =
getDolGlobalString(
'ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT',
'NotDefined');
243 $account_transfer =
getDolGlobalString(
'ACCOUNTING_ACCOUNT_TRANSFER_CASH',
'NotDefined');
252 $obj = $db->fetch_object($result);
254 $lineisapurchase = -1;
257 if ($obj->label ==
'(SupplierInvoicePayment)' || $obj->label ==
'(SupplierInvoicePaymentBack)') {
258 $lineisapurchase = 1;
260 if ($obj->label ==
'(CustomerInvoicePayment)' || $obj->label ==
'(CustomerInvoicePaymentBack)') {
264 if ($lineisapurchase < 0) {
265 if ($obj->typeop_payment_supplier ==
'payment_supplier') {
266 $lineisapurchase = 1;
269 if ($lineisasale < 0) {
270 if ($obj->typeop_payment ==
'payment') {
278 $compta_bank = $obj->account_number;
281 $compta_soc =
'NotDefined';
282 if ($lineisapurchase > 0) {
283 $compta_soc = (($obj->code_compta_fournisseur !=
"") ? $obj->code_compta_fournisseur : $account_supplier);
285 if ($lineisasale > 0) {
286 $compta_soc = (!empty($obj->code_compta_client) ? $obj->code_compta_client : $account_customer);
289 $tabcompany[$obj->rowid] = array(
291 'name' => $obj->name,
292 'code_compta' => $compta_soc,
293 'email' => $obj->email
299 $compta_user = (!empty($obj->accountancy_code) ? $obj->accountancy_code :
'');
301 $tabuser[$obj->rowid] = array(
302 'id' => $obj->userid,
304 'lastname' => $obj->lastname,
305 'firstname' => $obj->firstname,
306 'email' => $obj->useremail,
307 'accountancy_code' => $compta_user,
308 'status' => $obj->userstatus
312 $tabpay[$obj->rowid][
"date"] = $db->jdate($obj->do);
313 $tabpay[$obj->rowid][
"type_payment"] = $obj->fk_type;
314 $tabpay[$obj->rowid][
"ref"] = $obj->label;
315 $tabpay[$obj->rowid][
"fk_bank"] = $obj->rowid;
316 $tabpay[$obj->rowid][
"bank_account_ref"] = $obj->baref;
317 $tabpay[$obj->rowid][
"fk_bank_account"] = $obj->fk_account;
319 if (preg_match(
'/^\((.*)\)$/i', $obj->label, $reg)) {
320 $tabpay[$obj->rowid][
"lib"] = $langs->trans($reg[1]);
322 $tabpay[$obj->rowid][
"lib"] =
dol_trunc($obj->label, 60);
326 $links =
$object->get_url($obj->rowid);
331 $tabpay[$obj->rowid][
'type'] =
'unknown';
332 $tabtype[$obj->rowid] =
'unknown';
333 $tabmoreinfo[$obj->rowid] = array();
335 $amounttouse = $obj->amount;
336 if (!empty($obj->amount_main_currency)) {
338 $amounttouse = $obj->amount_main_currency;
342 if (is_array($links) && count($links) > 0) {
347 $is_expensereport =
false;
348 foreach ($links as $v) {
349 if ($v[
'type'] ==
'sc') {
353 if ($v[
'type'] ==
'payment_salary') {
357 if ($v[
'type'] ==
'payment_expensereport') {
358 $is_expensereport =
true;
364 foreach ($links as $key => $val) {
365 if ($links[$key][
'type'] ==
'user' && !$is_sc && !$is_salary && !$is_expensereport) {
370 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'))) {
374 $tabpay[$obj->rowid][
'type'] = $links[$key][
'type'];
375 $tabtype[$obj->rowid] = $links[$key][
'type'];
386 if ($links[$key][
'type'] ==
'withdraw') {
387 $tabmoreinfo[$obj->rowid][
'withdraw'] = 1;
390 if ($links[$key][
'type'] ==
'payment') {
391 $paymentstatic->id = $links[$key][
'url_id'];
392 $paymentstatic->ref = $links[$key][
'url_id'];
393 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentstatic->getNomUrl(2,
'',
'');
394 $tabpay[$obj->rowid][
"paymentid"] = $paymentstatic->id;
395 } elseif ($links[$key][
'type'] ==
'payment_supplier') {
396 $paymentsupplierstatic->id = $links[$key][
'url_id'];
397 $paymentsupplierstatic->ref = $links[$key][
'url_id'];
398 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentsupplierstatic->getNomUrl(2);
399 $tabpay[$obj->rowid][
"paymentsupplierid"] = $paymentsupplierstatic->id;
400 } elseif ($links[$key][
'type'] ==
'company') {
401 $societestatic->id = $links[$key][
'url_id'];
402 $societestatic->name = $links[$key][
'label'];
403 $societestatic->email = $tabcompany[$obj->rowid][
'email'];
404 $tabpay[$obj->rowid][
"soclib"] = $societestatic->getNomUrl(1,
'', 30);
406 if (empty($tabtp[$obj->rowid][$compta_soc])) {
407 $tabtp[$obj->rowid][$compta_soc] = $amounttouse;
409 $tabtp[$obj->rowid][$compta_soc] += $amounttouse;
412 } elseif ($links[$key][
'type'] ==
'user') {
413 $userstatic->id = $links[$key][
'url_id'];
414 $userstatic->name = $links[$key][
'label'];
415 $userstatic->email = $tabuser[$obj->rowid][
'email'];
416 $userstatic->firstname = $tabuser[$obj->rowid][
'firstname'];
417 $userstatic->lastname = $tabuser[$obj->rowid][
'lastname'];
418 $userstatic->status = $tabuser[$obj->rowid][
'status'];
419 $userstatic->accountancy_code = $tabuser[$obj->rowid][
'accountancy_code'];
424 if ($userstatic->id > 0) {
426 $tabpay[$obj->rowid][
"soclib"] .=
' '.$userstatic->getNomUrl(1,
'accountancy', 0);
428 $tabpay[$obj->rowid][
"soclib"] = $userstatic->getNomUrl(1,
'accountancy', 0);
431 $tabpay[$obj->rowid][
"soclib"] =
'???';
438 $tabtp[$obj->rowid][$compta_user] += $amounttouse;
441 } elseif ($links[$key][
'type'] ==
'sc') {
442 $chargestatic->id = $links[$key][
'url_id'];
443 $chargestatic->ref = $links[$key][
'url_id'];
445 $tabpay[$obj->rowid][
"lib"] .=
' '.$chargestatic->getNomUrl(2);
447 if (preg_match(
'/^\((.*)\)$/i', $links[$key][
'label'], $reg)) {
448 if ($reg[1] ==
'socialcontribution') {
449 $reg[1] =
'SocialContribution';
451 $chargestatic->label = $langs->trans($reg[1]);
453 $chargestatic->label = $links[$key][
'label'];
455 $chargestatic->ref = $chargestatic->label;
458 $tabpay[$obj->rowid][
"soclib"] = $chargestatic->getNomUrl(1, 30);
459 $tabpay[$obj->rowid][
"paymentscid"] = $chargestatic->id;
463 $sqlmid =
"SELECT cchgsoc.accountancy_code";
464 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales cchgsoc";
465 $sqlmid .=
" INNER JOIN ".MAIN_DB_PREFIX.
"chargesociales as chgsoc ON chgsoc.fk_type = cchgsoc.id";
466 $sqlmid .=
" INNER JOIN ".MAIN_DB_PREFIX.
"paiementcharge as paycharg ON paycharg.fk_charge = chgsoc.rowid";
467 $sqlmid .=
" INNER JOIN ".MAIN_DB_PREFIX.
"bank_url as bkurl ON bkurl.url_id=paycharg.rowid AND bkurl.type = 'payment_sc'";
468 $sqlmid .=
" WHERE bkurl.fk_bank = ".((int) $obj->rowid);
470 dol_syslog(
"accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);
471 $resultmid = $db->query($sqlmid);
473 $objmid = $db->fetch_object($resultmid);
474 $tabtp[$obj->rowid][$objmid->accountancy_code] = isset($tabtp[$obj->rowid][$objmid->accountancy_code]) ? $tabtp[$obj->rowid][$objmid->accountancy_code] + $amounttouse : $amounttouse;
476 } elseif ($links[$key][
'type'] ==
'payment_donation') {
477 $paymentdonstatic->id = $links[$key][
'url_id'];
478 $paymentdonstatic->ref = $links[$key][
'url_id'];
479 $paymentdonstatic->fk_donation = $links[$key][
'url_id'];
480 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentdonstatic->getNomUrl(2);
481 $tabpay[$obj->rowid][
"paymentdonationid"] = $paymentdonstatic->id;
482 $tabtp[$obj->rowid][$account_pay_donation] = isset($tabtp[$obj->rowid][$account_pay_donation]) ? $tabtp[$obj->rowid][$account_pay_donation] + $amounttouse : $amounttouse;
483 } elseif ($links[$key][
'type'] ==
'member') {
484 $paymentsubscriptionstatic->id = $links[$key][
'url_id'];
485 $paymentsubscriptionstatic->ref = $links[$key][
'url_id'];
486 $paymentsubscriptionstatic->label = $links[$key][
'label'];
487 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentsubscriptionstatic->getNomUrl(2);
488 $tabpay[$obj->rowid][
"paymentsubscriptionid"] = $paymentsubscriptionstatic->id;
489 $paymentsubscriptionstatic->fetch($paymentsubscriptionstatic->id);
490 $tabtp[$obj->rowid][$account_pay_subscription] = isset($tabtp[$obj->rowid][$account_pay_subscription]) ? $tabtp[$obj->rowid][$account_pay_subscription] + $amounttouse : $amounttouse;
491 } elseif ($links[$key][
'type'] ==
'payment_vat') {
492 $paymentvatstatic->id = $links[$key][
'url_id'];
493 $paymentvatstatic->ref = $links[$key][
'url_id'];
494 $paymentvatstatic->label = $links[$key][
'label'];
495 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentvatstatic->getNomUrl(2);
496 $tabpay[$obj->rowid][
"paymentvatid"] = $paymentvatstatic->id;
497 $tabtp[$obj->rowid][$account_pay_vat] = isset($tabtp[$obj->rowid][$account_pay_vat]) ? $tabtp[$obj->rowid][$account_pay_vat] + $amounttouse : $amounttouse;
498 } elseif ($links[$key][
'type'] ==
'payment_salary') {
499 $paymentsalstatic->id = $links[$key][
'url_id'];
500 $paymentsalstatic->ref = $links[$key][
'url_id'];
501 $paymentsalstatic->label = $links[$key][
'label'];
502 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentsalstatic->getNomUrl(2);
503 $tabpay[$obj->rowid][
"paymentsalid"] = $paymentsalstatic->id;
507 if (
getDolGlobalString(
'ACCOUNTANCY_AUTOFIX_MISSING_LINK_TO_USER_ON_SALARY_BANK_PAYMENT')) {
508 $tmpsalary =
new Salary($db);
509 $tmpsalary->fetch($paymentsalstatic->id);
510 $tmpsalary->fetch_user($tmpsalary->fk_user);
512 $userstatic->id = $tmpsalary->user->id;
513 $userstatic->name = $tmpsalary->user->name;
514 $userstatic->email = $tmpsalary->user->email;
515 $userstatic->firstname = $tmpsalary->user->firstname;
516 $userstatic->lastname = $tmpsalary->user->lastname;
517 $userstatic->status = $tmpsalary->user->status;
518 $userstatic->accountancy_code = $tmpsalary->user->accountancy_code;
520 if ($userstatic->id > 0) {
521 $tabpay[$obj->rowid][
"soclib"] = $userstatic->getNomUrl(1,
'accountancy', 0);
523 $tabpay[$obj->rowid][
"soclib"] =
'???';
526 if (empty($obj->typeop_user)) {
527 $compta_user = $userstatic->accountancy_code;
529 $tabtp[$obj->rowid][$compta_user] += $amounttouse;
530 $tabuser[$obj->rowid] = array(
531 'id' => $userstatic->id,
533 'lastname' => $userstatic->lastname,
534 'firstname' => $userstatic->firstname,
535 'email' => $userstatic->email,
536 'accountancy_code' => $compta_user,
537 'status' => $userstatic->status
542 } elseif ($links[$key][
'type'] ==
'payment_expensereport') {
543 $paymentexpensereportstatic->id = $links[$key][
'url_id'];
544 $tabpay[$obj->rowid][
"lib"] .= $paymentexpensereportstatic->getNomUrl(2);
545 $tabpay[$obj->rowid][
"paymentexpensereport"] = $paymentexpensereportstatic->id;
546 } elseif ($links[$key][
'type'] ==
'payment_various') {
547 $paymentvariousstatic->id = $links[$key][
'url_id'];
548 $paymentvariousstatic->ref = $links[$key][
'url_id'];
549 $paymentvariousstatic->label = $links[$key][
'label'];
550 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentvariousstatic->getNomUrl(2);
551 $tabpay[$obj->rowid][
"paymentvariousid"] = $paymentvariousstatic->id;
552 $paymentvariousstatic->fetch($paymentvariousstatic->id);
553 $account_various = (!empty($paymentvariousstatic->accountancy_code) ? $paymentvariousstatic->accountancy_code :
'NotDefined');
554 $account_subledger = (!empty($paymentvariousstatic->subledger_account) ? $paymentvariousstatic->subledger_account :
'');
555 $tabpay[$obj->rowid][
"account_various"] = $account_various;
556 $tabtp[$obj->rowid][$account_subledger] = isset($tabtp[$obj->rowid][$account_subledger]) ? $tabtp[$obj->rowid][$account_subledger] + $amounttouse : $amounttouse;
557 } elseif ($links[$key][
'type'] ==
'payment_loan') {
558 $paymentloanstatic->id = $links[$key][
'url_id'];
559 $paymentloanstatic->ref = $links[$key][
'url_id'];
560 $paymentloanstatic->fk_loan = $links[$key][
'url_id'];
561 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentloanstatic->getNomUrl(2);
562 $tabpay[$obj->rowid][
"paymentloanid"] = $paymentloanstatic->id;
564 $sqlmid =
'SELECT pl.amount_capital, pl.amount_insurance, pl.amount_interest, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest';
565 $sqlmid .=
' FROM '.MAIN_DB_PREFIX.
'payment_loan as pl, '.MAIN_DB_PREFIX.
'loan as l';
566 $sqlmid .=
' WHERE l.rowid = pl.fk_loan AND pl.fk_bank = '.((int) $obj->rowid);
568 dol_syslog(
"accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);
569 $resultmid = $db->query($sqlmid);
571 $objmid = $db->fetch_object($resultmid);
572 $tabtp[$obj->rowid][$objmid->accountancy_account_capital] = isset($tabtp[$obj->rowid][$objmid->accountancy_account_capital]) ? $tabtp[$obj->rowid][$objmid->accountancy_account_capital] - $objmid->amount_capital : $amounttouse;
573 $tabtp[$obj->rowid][$objmid->accountancy_account_insurance] = isset($tabtp[$obj->rowid][$objmid->accountancy_account_insurance]) ? $tabtp[$obj->rowid][$objmid->accountancy_account_insurance] - $objmid->amount_insurance : $amounttouse;
574 $tabtp[$obj->rowid][$objmid->accountancy_account_interest] = isset($tabtp[$obj->rowid][$objmid->accountancy_account_interest]) ? $tabtp[$obj->rowid][$objmid->accountancy_account_interest] - $objmid->amount_interes : $amounttouse;
576 } elseif ($links[$key][
'type'] ==
'banktransfert') {
577 $accountLinestatic->fetch($links[$key][
'url_id']);
578 $tabpay[$obj->rowid][
"lib"] .=
' '.$langs->trans(
"BankTransfer").
'- '.$accountLinestatic ->getNomUrl(1);
579 $tabtp[$obj->rowid][$account_transfer] = isset($tabtp[$obj->rowid][$account_transfer]) ? $tabtp[$obj->rowid][$account_transfer] + $amounttouse : $amounttouse;
580 $bankaccountstatic->fetch($tabpay[$obj->rowid][
'fk_bank_account']);
581 $tabpay[$obj->rowid][
"soclib"] = $bankaccountstatic->getNomUrl(2);
586 if (empty($tabbq[$obj->rowid][$compta_bank])) {
587 $tabbq[$obj->rowid][$compta_bank] = $amounttouse;
589 $tabbq[$obj->rowid][$compta_bank] += $amounttouse;
594 if (empty($tabtp[$obj->rowid]) && !empty($tabmoreinfo[$obj->rowid][
'withdraw'])) {
595 foreach ($links as $key => $val) {
596 if ($links[$key][
'type'] ==
'payment') {
598 $tmppayment->fetch($links[$key][
'url_id']);
599 $arrayofamounts = $tmppayment->getAmountsArray();
600 if (is_array($arrayofamounts)) {
601 foreach ($arrayofamounts as $invoiceid => $amount) {
602 $tmpinvoice->fetch($invoiceid);
603 $tmpinvoice->fetch_thirdparty();
604 if ($tmpinvoice->thirdparty->code_compta_client) {
605 $tabtp[$obj->rowid][$tmpinvoice->thirdparty->code_compta_client] += $amount;
614 if (empty($tabtp[$obj->rowid])) {
615 $tabtp[$obj->rowid][
'NotDefined'] = $tabbq[$obj->rowid][$compta_bank];
627if (!$error && $action ==
'writebookkeeping' && $user->hasRight(
'accounting',
'bind',
'write')) {
631 $accountingaccountcustomer->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'),
true);
634 $accountingaccountsupplier->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUPPLIER'),
true);
637 $accountingaccountpayment->fetch(0,
getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT'),
true);
640 $accountingaccountexpensereport->fetch(0, $conf->global->ACCOUNTING_ACCOUNT_EXPENSEREPORT,
true);
643 $accountingaccountsuspense->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUSPENSE'),
true);
646 foreach ($tabpay as $key => $val) {
661 if (!$errorforline && is_array($tabbq[$key])) {
663 foreach ($tabbq[$key] as $k => $mt) {
665 if (empty($conf->cache[
'accountingaccountincurrententity'][$k])) {
667 $accountingaccount->fetch(0, $k,
true);
668 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
670 $accountingaccount = $conf->cache[
'accountingaccountincurrententity'][$k];
673 $account_label = $accountingaccount->label;
676 if (!empty($val[
'lib'])) {
680 if (!empty($val[
'soclib'])) {
681 $reflabel .=
" - ".dol_string_nohtmltag($val[
'soclib']);
685 $bookkeeping->doc_date = $val[
"date"];
686 $bookkeeping->doc_ref = $ref;
687 $bookkeeping->doc_type =
'bank';
688 $bookkeeping->fk_doc = $key;
689 $bookkeeping->fk_docdet = $val[
"fk_bank"];
691 $bookkeeping->numero_compte = $k;
692 $bookkeeping->label_compte = $account_label;
694 $bookkeeping->label_operation = $reflabel;
695 $bookkeeping->montant = $mt;
696 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
697 $bookkeeping->debit = ($mt >= 0 ? $mt : 0);
698 $bookkeeping->credit = ($mt < 0 ? -$mt : 0);
699 $bookkeeping->code_journal = $journal;
700 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
701 $bookkeeping->fk_user_author = $user->id;
702 $bookkeeping->date_creation = $now;
705 $bookkeeping->subledger_account =
'';
706 $bookkeeping->label_operation = $reflabel;
707 $bookkeeping->entity = $conf->entity;
709 $totaldebit += $bookkeeping->debit;
710 $totalcredit += $bookkeeping->credit;
712 $result = $bookkeeping->create($user);
714 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
717 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded',
null,
'warnings');
729 if (!$errorforline) {
730 if (is_array($tabtp[$key])) {
732 foreach ($tabtp[$key] as $k => $mt) {
737 if (!empty($val[
'lib'])) {
740 if ($tabtype[$key] ==
'banktransfert') {
741 $reflabel .=
dol_string_nohtmltag($langs->transnoentitiesnoconv(
'TransitionalAccount').
' '.$account_transfer);
747 $bookkeeping->doc_date = $val[
"date"];
748 $bookkeeping->doc_ref = $ref;
749 $bookkeeping->doc_type =
'bank';
750 $bookkeeping->fk_doc = $key;
751 $bookkeeping->fk_docdet = $val[
"fk_bank"];
753 $bookkeeping->label_operation = $reflabel;
754 $bookkeeping->montant = $mt;
755 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
756 $bookkeeping->debit = ($mt < 0 ? -$mt : 0);
757 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
758 $bookkeeping->code_journal = $journal;
759 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
760 $bookkeeping->fk_user_author = $user->id;
761 $bookkeeping->date_creation = $now;
763 if ($tabtype[$key] ==
'payment') {
765 $bookkeeping->subledger_account = $k;
766 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
768 $bookkeeping->label_compte = $accountingaccountcustomer->label;
769 } elseif ($tabtype[$key] ==
'payment_supplier') {
771 $bookkeeping->subledger_account = $k;
772 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
774 $bookkeeping->label_compte = $accountingaccountsupplier->label;
775 } elseif ($tabtype[$key] ==
'payment_expensereport') {
776 $bookkeeping->subledger_account = $tabuser[$key][
'accountancy_code'];
777 $bookkeeping->subledger_label = $tabuser[$key][
'name'];
779 $bookkeeping->label_compte = $accountingaccountexpensereport->label;
780 } elseif ($tabtype[$key] ==
'payment_salary') {
781 $bookkeeping->subledger_account = $tabuser[$key][
'accountancy_code'];
782 $bookkeeping->subledger_label = $tabuser[$key][
'name'];
783 $bookkeeping->numero_compte =
getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT');
784 $bookkeeping->label_compte = $accountingaccountpayment->label;
785 } elseif (in_array($tabtype[$key], array(
'sc',
'payment_sc'))) {
786 $bookkeeping->subledger_account =
'';
787 $bookkeeping->subledger_label =
'';
788 $accountingaccount->fetch(0, $k,
true);
789 $bookkeeping->numero_compte = $k;
790 $bookkeeping->label_compte = $accountingaccount->label;
791 } elseif ($tabtype[$key] ==
'payment_vat') {
792 $bookkeeping->subledger_account =
'';
793 $bookkeeping->subledger_label =
'';
794 $accountingaccount->fetch(0, $k,
true);
795 $bookkeeping->numero_compte = $k;
796 $bookkeeping->label_compte = $accountingaccount->label;
797 } elseif ($tabtype[$key] ==
'payment_donation') {
798 $bookkeeping->subledger_account =
'';
799 $bookkeeping->subledger_label =
'';
800 $accountingaccount->fetch(0, $k,
true);
801 $bookkeeping->numero_compte = $k;
802 $bookkeeping->label_compte = $accountingaccount->label;
803 } elseif ($tabtype[$key] ==
'member') {
804 $bookkeeping->subledger_account =
'';
805 $bookkeeping->subledger_label =
'';
806 $accountingaccount->fetch(0, $k,
true);
807 $bookkeeping->numero_compte = $k;
808 $bookkeeping->label_compte = $accountingaccount->label;
809 } elseif ($tabtype[$key] ==
'payment_loan') {
810 $bookkeeping->subledger_account =
'';
811 $bookkeeping->subledger_label =
'';
812 $accountingaccount->fetch(0, $k,
true);
813 $bookkeeping->numero_compte = $k;
814 $bookkeeping->label_compte = $accountingaccount->label;
815 } elseif ($tabtype[$key] ==
'payment_various') {
816 $bookkeeping->subledger_account = $k;
817 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
818 $accountingaccount->fetch(0, $tabpay[$key][
"account_various"],
true);
819 $bookkeeping->numero_compte = $tabpay[$key][
"account_various"];
820 $bookkeeping->label_compte = $accountingaccount->label;
821 } elseif ($tabtype[$key] ==
'banktransfert') {
822 $bookkeeping->subledger_account =
'';
823 $bookkeeping->subledger_label =
'';
824 $accountingaccount->fetch(0, $k,
true);
825 $bookkeeping->numero_compte = $k;
826 $bookkeeping->label_compte = $accountingaccount->label;
828 if ($tabtype[$key] ==
'unknown') {
830 $bookkeeping->subledger_account =
'';
831 $bookkeeping->subledger_label =
'';
833 $bookkeeping->label_compte = $accountingaccountsuspense->label;
836 $bookkeeping->label_operation = $reflabel;
837 $bookkeeping->entity = $conf->entity;
839 $totaldebit += $bookkeeping->debit;
840 $totalcredit += $bookkeeping->credit;
842 $result = $bookkeeping->create($user);
844 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
847 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded',
null,
'warnings');
855 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/lettering.class.php';
857 $nb_lettering = $lettering_static->bookkeepingLetteringAll(array($bookkeeping->id));
863 foreach ($tabbq[$key] as $k => $mt) {
866 if (!empty($val[
'lib'])) {
872 $bookkeeping->doc_date = $val[
"date"];
873 $bookkeeping->doc_ref = $ref;
874 $bookkeeping->doc_type =
'bank';
875 $bookkeeping->fk_doc = $key;
876 $bookkeeping->fk_docdet = $val[
"fk_bank"];
877 $bookkeeping->montant = $mt;
878 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
879 $bookkeeping->debit = ($mt < 0 ? -$mt : 0);
880 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
881 $bookkeeping->code_journal = $journal;
882 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
883 $bookkeeping->fk_user_author = $user->id;
884 $bookkeeping->date_creation = $now;
885 $bookkeeping->label_compte =
'';
886 $bookkeeping->label_operation = $reflabel;
887 $bookkeeping->entity = $conf->entity;
889 $totaldebit += $bookkeeping->debit;
890 $totalcredit += $bookkeeping->credit;
892 $result = $bookkeeping->create($user);
895 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
898 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded',
null,
'warnings');
913 setEventMessages(
'We tried to insert a non balanced transaction in book for '.$ref.
'. Canceled. Surely a bug.',
null,
'errors');
916 if (!$errorforline) {
923 if ($error >= $MAXNBERRORS) {
924 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped").
' (>'.$MAXNBERRORS.
')',
null,
'errors');
930 if (empty($error) && count($tabpay) > 0) {
932 } elseif (count($tabpay) == $error) {
935 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
941 if (count($tabpay) != $error) {
942 $param =
'id_journal='.$id_journal;
943 $param .=
'&date_startday='.$date_startday;
944 $param .=
'&date_startmonth='.$date_startmonth;
945 $param .=
'&date_startyear='.$date_startyear;
946 $param .=
'&date_endday='.$date_endday;
947 $param .=
'&date_endmonth='.$date_endmonth;
948 $param .=
'&date_endyear='.$date_endyear;
949 $param .=
'&in_bookkeeping='.$in_bookkeeping;
950 header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
958if ($action ==
'exportcsv' && $user->hasRight(
'accounting',
'bind',
'write')) {
961 $filename =
'journal';
962 $type_export =
'journal';
963 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
966 print
'"'.$langs->transnoentitiesnoconv(
"BankId").
'"'.$sep;
967 print
'"'.$langs->transnoentitiesnoconv(
"Date").
'"'.$sep;
968 print
'"'.$langs->transnoentitiesnoconv(
"PaymentMode").
'"'.$sep;
969 print
'"'.$langs->transnoentitiesnoconv(
"AccountAccounting").
'"'.$sep;
970 print
'"'.$langs->transnoentitiesnoconv(
"LedgerAccount").
'"'.$sep;
971 print
'"'.$langs->transnoentitiesnoconv(
"SubledgerAccount").
'"'.$sep;
972 print
'"'.$langs->transnoentitiesnoconv(
"Label").
'"'.$sep;
973 print
'"'.$langs->transnoentitiesnoconv(
"AccountingDebit").
'"'.$sep;
974 print
'"'.$langs->transnoentitiesnoconv(
"AccountingCredit").
'"'.$sep;
975 print
'"'.$langs->transnoentitiesnoconv(
"Journal").
'"'.$sep;
976 print
'"'.$langs->transnoentitiesnoconv(
"Note").
'"'.$sep;
979 foreach ($tabpay as $key => $val) {
985 foreach ($tabbq[$key] as $k => $mt) {
988 if (!empty($val[
'lib'])) {
992 if (!empty($val[
'soclib'])) {
993 $reflabel .=
" - ".dol_string_nohtmltag($val[
'soclib']);
996 print
'"'.$key.
'"'.$sep;
997 print
'"'.$date.
'"'.$sep;
998 print
'"'.$val[
"type_payment"].
'"'.$sep;
999 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1000 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
1002 print
'"'.$reflabel.
'"'.$sep;
1003 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1004 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1005 print
'"'.$journal.
'"'.$sep;
1006 print
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
1012 if (is_array($tabtp[$key])) {
1013 foreach ($tabtp[$key] as $k => $mt) {
1016 if (!empty($val[
'lib'])) {
1019 if ($tabtype[$key] ==
'banktransfert') {
1020 $reflabel .=
dol_string_nohtmltag($langs->transnoentitiesnoconv(
'TransitionalAccount').
' '.$account_transfer);
1025 print
'"'.$key.
'"'.$sep;
1026 print
'"'.$date.
'"'.$sep;
1027 print
'"'.$val[
"type_payment"].
'"'.$sep;
1028 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1029 if ($tabtype[$key] ==
'payment_supplier') {
1030 print
'"'.getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUPPLIER').
'"'.$sep;
1031 } elseif ($tabtype[$key] ==
'payment') {
1032 print
'"'.getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER').
'"'.$sep;
1033 } elseif ($tabtype[$key] ==
'payment_expensereport') {
1034 print
'"'.getDolGlobalString(
'ACCOUNTING_ACCOUNT_EXPENSEREPORT').
'"'.$sep;
1035 } elseif ($tabtype[$key] ==
'payment_salary') {
1036 print
'"'.getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT').
'"'.$sep;
1038 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1040 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
1041 print
'"'.$reflabel.
'"'.$sep;
1042 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1043 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1044 print
'"'.$journal.
'"'.$sep;
1045 print
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
1050 foreach ($tabbq[$key] as $k => $mt) {
1053 if (!empty($val[
'lib'])) {
1058 print
'"'.$key.
'"'.$sep;
1059 print
'"'.$date.
'"'.$sep;
1060 print
'"'.$val[
"type_payment"].
'"'.$sep;
1061 print
'"'.length_accountg(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUSPENSE')).
'"'.$sep;
1062 print
'"'.length_accounta(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUSPENSE')).
'"'.$sep;
1064 print
'"'.$reflabel.
'"'.$sep;
1065 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1066 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1067 print
'"'.$journal.
'"'.$sep;
1068 print
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
1081$form =
new Form($db);
1083if (empty($action) || $action ==
'view') {
1084 $invoicestatic =
new Facture($db);
1087 $vatstatic =
new Tva($db);
1088 $donationstatic =
new Don($db);
1089 $loanstatic =
new Loan($db);
1090 $salarystatic =
new Salary($db);
1093 $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1,
'', 1);
1094 $help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
1100 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
1102 $listofchoices = array(
1103 'notyet' => $langs->trans(
"NotYetInGeneralLedger"),
1104 'already' => $langs->trans(
"AlreadyInGeneralLedger")
1106 $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);
1107 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
1109 $varlink =
'id_journal='.$id_journal;
1113 $listofchoices = array(
1114 1 => $langs->trans(
"TransfertAllBankLines"),
1115 2 => $langs->trans(
"TransfertOnlyConciliatedBankLine")
1117 $moreoptions = [
"BankLineConciliated" => $form->selectarray(
'only_rappro', $listofchoices, $only_rappro)];
1119 journalHead($nom,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink, $moreoptions);
1126 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_fiscalyear WHERE entity = ".((int) $conf->entity);
1127 $resql = $db->query($sql);
1129 $obj = $db->fetch_object($resql);
1130 if ($obj->nb == 0) {
1131 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheFiscalPeriodIsNotDefined");
1132 $desc =
' : '.$langs->trans(
"AccountancyAreaDescFiscalPeriod", 4,
'{link}');
1133 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"FiscalPeriod").
'</strong>', $desc);
1143 $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";
1144 $resql = $db->query($sql);
1146 $obj = $db->fetch_object($resql);
1148 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheJournalCodeIsNotDefinedOnSomeBankAccount");
1149 $desc =
' : '.$langs->trans(
"AccountancyAreaDescBank", 6,
'{link}');
1150 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"BankAccounts").
'</strong>', $desc);
1166 print($desc ?
'' :
'<br>').
'<div class="warning">'.
img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
1167 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
1168 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
1174 print
'<br><div class="tabsAction tabsActionNoBottom centerimp">';
1176 if (
getDolGlobalString(
'ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping ==
'notyet') {
1177 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
1182 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
1184 if ($in_bookkeeping ==
'notyet') {
1185 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
1187 print
'<a class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
1195 <script type="text/javascript">
1196 function launch_export() {
1197 console.log("Set value into form and submit");
1198 $("div.fiche form input[name=\"action\"]").val("exportcsv");
1199 $("div.fiche form input[type=\"submit\"]").click();
1200 $("div.fiche form input[name=\"action\"]").val("");
1202 function writebookkeeping() {
1203 console.log("Set value into form and submit");
1204 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
1205 $("div.fiche form input[type=\"submit\"]").click();
1206 $("div.fiche form input[name=\"action\"]").val("");
1216 print
'<div class="div-table-responsive">';
1217 print
'<table class="noborder centpercent">';
1218 print
'<tr class="liste_titre">';
1219 print
"<td>".$langs->trans(
"Date").
"</td>";
1220 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"ObjectsRef").
")</td>";
1221 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
1222 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
1223 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
1224 print
'<td class="center">'.$langs->trans(
"PaymentMode").
"</td>";
1225 print
'<td class="right">'.$langs->trans(
"AccountingDebit").
"</td>";
1226 print
'<td class="right">'.$langs->trans(
"AccountingCredit").
"</td>";
1231 foreach ($tabpay as $key => $val) {
1237 foreach ($tabbq[$key] as $k => $mt) {
1240 if (!empty($val[
'lib'])) {
1241 $reflabel .= $val[
'lib'].
" - ";
1243 $reflabel .= $langs->trans(
"Bank").
' '.$val[
'bank_account_ref'];
1244 if (!empty($val[
'soclib'])) {
1245 $reflabel .=
" - ".$val[
'soclib'];
1249 print
'<!-- Bank bank.rowid='.$key.
' type='.$tabpay[$key][
'type'].
' ref='.$tabpay[$key][
'ref'].
'-->';
1250 print
'<tr class="oddeven">';
1253 print
"<td>".$date.
"</td>";
1256 print
"<td>".dol_escape_htmltag($ref).
"</td>";
1260 if (empty($accounttoshow) || $accounttoshow ==
'NotDefined') {
1261 $accounttoshow =
'<span class="error">'.$langs->trans(
"BankAccountNotDefined").
'</span>';
1263 print
'<td class="maxwidth300" title="'.dol_escape_htmltag(
dol_string_nohtmltag($accounttoshow)).
'">';
1264 print $accounttoshow;
1268 print
'<td class="maxwidth300">';
1282 print
'<td class="center">'.$val[
"type_payment"].
"</td>";
1283 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1284 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1292 if (is_array($tabtp[$key])) {
1293 foreach ($tabtp[$key] as $k => $mt) {
1296 if (!empty($val[
'lib'])) {
1297 $reflabel .= $val[
'lib'].(isset($val[
'soclib']) ?
" - " :
"");
1299 if ($tabtype[$key] ==
'banktransfert') {
1300 $reflabel .= $langs->trans(
'TransitionalAccount').
' '.$account_transfer;
1302 $reflabel .= isset($val[
'soclib']) ? $val[
'soclib'] :
"";
1305 print
'<!-- Thirdparty bank.rowid='.$key.
' -->';
1306 print
'<tr class="oddeven">';
1309 print
"<td>".$date.
"</td>";
1312 print
"<td>".dol_escape_htmltag($ref).
"</td>";
1315 $account_ledger = $k;
1317 if ($tabtype[$key] ==
'payment') {
1320 if ($tabtype[$key] ==
'payment_supplier') {
1323 if ($tabtype[$key] ==
'payment_expensereport') {
1326 if ($tabtype[$key] ==
'payment_salary') {
1329 if ($tabtype[$key] ==
'payment_vat') {
1332 if ($tabtype[$key] ==
'member') {
1335 if ($tabtype[$key] ==
'payment_various') {
1336 $account_ledger = $tabpay[$key][
"account_various"];
1339 if (empty($accounttoshow) || $accounttoshow ==
'NotDefined') {
1340 if ($tabtype[$key] ==
'unknown') {
1343 $accounttoshow =
'<span class="error small">'.$langs->trans(
'UnknownAccountForThirdpartyAndWaitingAccountNotDefinedBlocking').
'</span>';
1345 $accounttoshow =
'<span class="warning small">'.$langs->trans(
'UnknownAccountForThirdparty',
length_accountg(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUSPENSE'))).
'</span>';
1349 $errorstring =
'UnknownAccountForThirdpartyBlocking';
1350 if ($tabtype[$key] ==
'payment') {
1351 $errorstring =
'MainAccountForCustomersNotDefined';
1353 if ($tabtype[$key] ==
'payment_supplier') {
1354 $errorstring =
'MainAccountForSuppliersNotDefined';
1356 if ($tabtype[$key] ==
'payment_expensereport') {
1357 $errorstring =
'MainAccountForUsersNotDefined';
1359 if ($tabtype[$key] ==
'payment_salary') {
1360 $errorstring =
'MainAccountForUsersNotDefined';
1362 if ($tabtype[$key] ==
'payment_vat') {
1363 $errorstring =
'MainAccountForVatPaymentNotDefined';
1365 if ($tabtype[$key] ==
'member') {
1366 $errorstring =
'MainAccountForSubscriptionPaymentNotDefined';
1368 $accounttoshow =
'<span class="error small">'.$langs->trans($errorstring).
'</span>';
1371 print
'<td class="maxwidth300" title="'.dol_escape_htmltag(
dol_string_nohtmltag($accounttoshow)).
'">';
1372 print $accounttoshow;
1376 $accounttoshowsubledger =
'';
1377 if (in_array($tabtype[$key], array(
'payment',
'payment_supplier',
'payment_expensereport',
'payment_salary',
'payment_various'))) {
1379 if ($accounttoshow != $accounttoshowsubledger) {
1380 if (empty($accounttoshowsubledger) || $accounttoshowsubledger ==
'NotDefined') {
1382 if (!empty($tabcompany[$key][
'code_compta'])) {
1383 if (in_array($tabtype[$key], array(
'payment_various',
'payment_salary'))) {
1385 $accounttoshowsubledger =
'<span class="warning small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknownSubledgerIgnored").
'</span>';
1387 $accounttoshowsubledger =
'<span class="warning small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknown", $tabcompany[$key][
'code_compta']).
'</span>';
1390 $accounttoshowsubledger =
'<span class="error small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknownBlocking").
'</span>';
1394 $accounttoshowsubledger =
'';
1397 print
'<td class="maxwidth300">';
1398 print $accounttoshowsubledger;
1401 print
"<td>".$reflabel.
"</td>";
1403 print
'<td class="center">'.$val[
"type_payment"].
"</td>";
1405 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1407 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1415 foreach ($tabbq[$key] as $k => $mt) {
1418 if (!empty($val[
'lib'])) {
1419 $reflabel .= $val[
'lib'].
" - ";
1421 $reflabel .=
'WaitingAccount';
1423 print
'<!-- Wait bank.rowid='.$key.
' -->';
1424 print
'<tr class="oddeven">';
1425 print
"<td>".$date.
"</td>";
1426 print
"<td>".$ref.
"</td>";
1439 print
"<td>".dol_escape_htmltag($reflabel).
"</td>";
1440 print
'<td class="center">'.$val[
"type_payment"].
"</td>";
1441 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1442 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1453 print
'<tr class="oddeven"><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
1480 if ($ref ==
'(SupplierInvoicePayment)' || $ref ==
'(SupplierInvoicePaymentBack)') {
1481 $ref = $langs->transnoentitiesnoconv(
'Supplier');
1483 if ($ref ==
'(CustomerInvoicePayment)' || $ref ==
'(CustomerInvoicePaymentBack)') {
1484 $ref = $langs->transnoentitiesnoconv(
'Customer');
1486 if ($ref ==
'(SocialContributionPayment)') {
1487 $ref = $langs->transnoentitiesnoconv(
'SocialContribution');
1489 if ($ref ==
'(DonationPayment)') {
1490 $ref = $langs->transnoentitiesnoconv(
'Donation');
1492 if ($ref ==
'(SubscriptionPayment)') {
1493 $ref = $langs->transnoentitiesnoconv(
'Subscription');
1495 if ($ref ==
'(ExpenseReportPayment)') {
1496 $ref = $langs->transnoentitiesnoconv(
'Employee');
1498 if ($ref ==
'(LoanPayment)') {
1499 $ref = $langs->transnoentitiesnoconv(
'Loan');
1501 if ($ref ==
'(payment_salary)') {
1502 $ref = $langs->transnoentitiesnoconv(
'Employee');
1506 if ($typerecord ==
'payment') {
1508 $sqlmid =
"SELECT payfac.fk_facture as id, ".$db->ifsql(
'f1.rowid IS NULL',
'f.ref',
'f1.ref').
" as ref";
1509 $sqlmid .=
" FROM ".$db->prefix().
"paiement_facture as payfac";
1510 $sqlmid .=
" LEFT JOIN ".$db->prefix().
"facture as f ON f.rowid = payfac.fk_facture";
1511 $sqlmid .=
" LEFT JOIN ".$db->prefix().
"societe_remise_except as sre ON sre.fk_facture_source = payfac.fk_facture";
1512 $sqlmid .=
" LEFT JOIN ".$db->prefix().
"facture as f1 ON f1.rowid = sre.fk_facture";
1513 $sqlmid .=
" WHERE payfac.fk_paiement=".((int) $val[
'paymentid']);
1515 $sqlmid =
"SELECT payfac.fk_facture as id, f.ref as ref";
1516 $sqlmid .=
" FROM ".$db->prefix().
"paiement_facture as payfac";
1517 $sqlmid .=
" INNER JOIN ".$db->prefix().
"facture as f ON f.rowid = payfac.fk_facture";
1518 $sqlmid .=
" WHERE payfac.fk_paiement=".((int) $val[
'paymentid']);
1520 $ref = $langs->transnoentitiesnoconv(
"Invoice");
1521 } elseif ($typerecord ==
'payment_supplier') {
1522 $sqlmid =
'SELECT payfac.fk_facturefourn as id, f.ref';
1523 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as payfac, ".MAIN_DB_PREFIX.
"facture_fourn as f";
1524 $sqlmid .=
" WHERE payfac.fk_facturefourn = f.rowid AND payfac.fk_paiementfourn=".((int) $val[
"paymentsupplierid"]);
1525 $ref = $langs->transnoentitiesnoconv(
"SupplierInvoice");
1526 } elseif ($typerecord ==
'payment_expensereport') {
1527 $sqlmid =
'SELECT e.rowid as id, e.ref';
1528 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_expensereport as pe, ".MAIN_DB_PREFIX.
"expensereport as e";
1529 $sqlmid .=
" WHERE pe.rowid=".((int) $val[
"paymentexpensereport"]).
" AND pe.fk_expensereport = e.rowid";
1530 $ref = $langs->transnoentitiesnoconv(
"ExpenseReport");
1531 } elseif ($typerecord ==
'payment_salary') {
1532 $sqlmid =
'SELECT s.rowid as ref';
1533 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as s";
1534 $sqlmid .=
" WHERE s.rowid=".((int) $val[
"paymentsalid"]);
1535 $ref = $langs->transnoentitiesnoconv(
"SalaryPayment");
1536 } elseif ($typerecord ==
'sc') {
1537 $sqlmid =
'SELECT sc.rowid as ref';
1538 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"paiementcharge as sc";
1539 $sqlmid .=
" WHERE sc.rowid=".((int) $val[
"paymentscid"]);
1540 $ref = $langs->transnoentitiesnoconv(
"SocialContribution");
1541 } elseif ($typerecord ==
'payment_vat') {
1542 $sqlmid =
'SELECT v.rowid as ref';
1543 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"tva as v";
1544 $sqlmid .=
" WHERE v.rowid=".((int) $val[
"paymentvatid"]);
1545 $ref = $langs->transnoentitiesnoconv(
"PaymentVat");
1546 } elseif ($typerecord ==
'payment_donation') {
1547 $sqlmid =
'SELECT payd.fk_donation as ref';
1548 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_donation as payd";
1549 $sqlmid .=
" WHERE payd.fk_donation=".((int) $val[
"paymentdonationid"]);
1550 $ref = $langs->transnoentitiesnoconv(
"Donation");
1551 } elseif ($typerecord ==
'payment_loan') {
1552 $sqlmid =
'SELECT l.rowid as ref';
1553 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_loan as l";
1554 $sqlmid .=
" WHERE l.rowid=".((int) $val[
"paymentloanid"]);
1555 $ref = $langs->transnoentitiesnoconv(
"LoanPayment");
1556 } elseif ($typerecord ==
'payment_various') {
1557 $sqlmid =
'SELECT v.rowid as ref';
1558 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_various as v";
1559 $sqlmid .=
" WHERE v.rowid=".((int) $val[
"paymentvariousid"]);
1560 $ref = $langs->transnoentitiesnoconv(
"VariousPayment");
1563 if (empty($sqlmid)) {
1564 dol_syslog(
"Found a typerecord=".$typerecord.
" not supported", LOG_WARNING);
1568 dol_syslog(
"accountancy/journal/bankjournal.php::sqlmid=".$sqlmid, LOG_DEBUG);
1569 $resultmid = $db->query($sqlmid);
1571 while ($objmid = $db->fetch_object($resultmid)) {
1572 $ref .=
' '.$objmid->ref;
1579 $ref =
dol_trunc($langs->transnoentitiesnoconv(
"BankId").
' '.$val[
'fk_bank'].
' - '.$ref, 295);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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.
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.
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.
Class to manage Trips and Expenses.
Class to manage suppliers invoices.
Class to manage invoices.
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 - Taxe sur la valeur ajoutée)
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.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
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.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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_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.
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.