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_general,";
144 $sql .=
" spe.accountancy_code_customer as code_compta_client,";
145 $sql .=
" spe.accountancy_code_supplier_general,";
146 $sql .=
" spe.accountancy_code_supplier as code_compta_fournisseur,";
148 $sql .=
" soc.accountancy_code_customer_general,";
149 $sql .=
" soc.code_compta as code_compta_client,";
150 $sql .=
" soc.accountancy_code_supplier_general,";
151 $sql .=
" soc.code_compta_fournisseur,";
153$sql .=
" u.accountancy_code, u.rowid as userid, u.lastname as lastname, u.firstname as firstname, u.email as useremail, u.statut as userstatus,";
154$sql .=
" bu2.type as typeop_user,";
155$sql .=
" bu3.type as typeop_payment, bu4.type as typeop_payment_supplier";
156$sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
157$sql .=
" JOIN ".MAIN_DB_PREFIX.
"bank_account as ba on b.fk_account=ba.rowid";
158$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'";
159$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON bu2.fk_bank = b.rowid AND bu2.type='user'";
160$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu3 ON bu3.fk_bank = b.rowid AND bu3.type='payment'";
161$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu4 ON bu4.fk_bank = b.rowid AND bu4.type='payment_supplier'";
162$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as soc on bu1.url_id=soc.rowid";
164 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = soc.rowid AND spe.entity = " . ((int) $conf->entity);
166$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on bu2.url_id=u.rowid";
167$sql .=
" WHERE ba.fk_accountancy_journal=".((int) $id_journal);
168$sql .=
' AND b.amount <> 0 AND ba.entity IN ('.getEntity(
'bank_account', 0).
')';
169if ($date_start && $date_end) {
170 $sql .=
" AND b.dateo >= '".$db->idate($date_start).
"' AND b.dateo <= '".$db->idate($date_end).
"'";
174 $sql .=
" AND b.dateo >= '".$db->idate(
getDolGlobalInt(
'ACCOUNTING_DATE_START_BINDING')).
"'";
177if ($in_bookkeeping ==
'already') {
178 $sql .=
" AND (b.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
180if ($in_bookkeeping ==
'notyet') {
181 $sql .=
" AND (b.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
183if ($only_rappro == 2) {
184 $sql .=
" AND (b.rappro = '1')";
186$sql .=
" ORDER BY b.datev";
192$societestatic =
new Societe($db);
193$userstatic =
new User($db);
194$bankaccountstatic =
new Account($db);
197$paymentvatstatic =
new Tva($db);
209$account_transfer =
'NotDefined';
213$accountingjournalstatic->fetch($id_journal);
214$journal = $accountingjournalstatic->code;
215$journal_label = $accountingjournalstatic->label;
217$tabcompany = array();
223$tabmoreinfo = array();
226@phan-var-force array<array{id:mixed,name:mixed,code_compta_client:string,email:string}> $tabcompany
227@phan-var-force array<array{id:int,name:string,lastname:string,firstname:string,email:string,accountancy_code:string,status:int> $tabuser
228@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
229@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
232$account_customer =
'NotDefined';
233$account_supplier =
'NotDefined';
236dol_syslog(
"accountancy/journal/bankjournal.php", LOG_DEBUG);
237$result = $db->query($sql);
239 $num = $db->num_rows($result);
245 $account_employee =
getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT',
'NotDefined');
246 $account_expensereport =
getDolGlobalString(
'ACCOUNTING_ACCOUNT_EXPENSEREPORT',
'NotDefined');
248 $account_pay_donation =
getDolGlobalString(
'DONATION_ACCOUNTINGACCOUNT',
'NotDefined');
249 $account_pay_subscription =
getDolGlobalString(
'ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT',
'NotDefined');
250 $account_transfer =
getDolGlobalString(
'ACCOUNTING_ACCOUNT_TRANSFER_CASH',
'NotDefined');
259 $obj = $db->fetch_object($result);
261 $lineisapurchase = -1;
264 if ($obj->label ==
'(SupplierInvoicePayment)' || $obj->label ==
'(SupplierInvoicePaymentBack)') {
265 $lineisapurchase = 1;
267 if ($obj->label ==
'(CustomerInvoicePayment)' || $obj->label ==
'(CustomerInvoicePaymentBack)') {
271 if ($lineisapurchase < 0) {
272 if ($obj->typeop_payment_supplier ==
'payment_supplier') {
273 $lineisapurchase = 1;
276 if ($lineisasale < 0) {
277 if ($obj->typeop_payment ==
'payment') {
285 $compta_bank = $obj->account_number;
288 $compta_soc =
'NotDefined';
289 $accountancy_code_general =
'NotDefined';
290 if ($lineisapurchase > 0) {
291 $accountancy_code_general = (!empty($obj->accountancy_code_supplier_general)) ? $obj->accountancy_code_supplier_general : $account_supplier;
292 $compta_soc = (($obj->code_compta_fournisseur !=
"") ? $obj->code_compta_fournisseur : $account_supplier);
294 if ($lineisasale > 0) {
295 $accountancy_code_general = (!empty($obj->accountancy_code_customer_general)) ? $obj->accountancy_code_customer_general : $account_customer;
296 $compta_soc = (!empty($obj->code_compta_client) ? $obj->code_compta_client : $account_customer);
299 $tabcompany[$obj->rowid] = array(
301 'name' => $obj->name,
302 'code_compta' => $compta_soc,
303 'accountancy_code_general' => $accountancy_code_general,
304 'email' => $obj->email
310 $compta_user = (!empty($obj->accountancy_code) ? $obj->accountancy_code :
'');
312 $tabuser[$obj->rowid] = array(
313 'id' => $obj->userid,
315 'lastname' => $obj->lastname,
316 'firstname' => $obj->firstname,
317 'email' => $obj->useremail,
318 'accountancy_code' => $compta_user,
319 'status' => $obj->userstatus
323 $tabpay[$obj->rowid][
"date"] = $db->jdate($obj->do);
324 $tabpay[$obj->rowid][
"type_payment"] = $obj->fk_type;
325 $tabpay[$obj->rowid][
"ref"] = $obj->label;
326 $tabpay[$obj->rowid][
"fk_bank"] = $obj->rowid;
327 $tabpay[$obj->rowid][
"bank_account_ref"] = $obj->baref;
328 $tabpay[$obj->rowid][
"fk_bank_account"] = $obj->fk_account;
330 if (preg_match(
'/^\((.*)\)$/i', $obj->label, $reg)) {
331 $tabpay[$obj->rowid][
"lib"] = $langs->trans($reg[1]);
333 $tabpay[$obj->rowid][
"lib"] =
dol_trunc($obj->label, 60);
337 $links =
$object->get_url($obj->rowid);
342 $tabpay[$obj->rowid][
'type'] =
'unknown';
343 $tabtype[$obj->rowid] =
'unknown';
344 $tabmoreinfo[$obj->rowid] = array();
346 $amounttouse = $obj->amount;
347 if (!empty($obj->amount_main_currency)) {
349 $amounttouse = $obj->amount_main_currency;
353 if (is_array($links) && count($links) > 0) {
358 $is_expensereport =
false;
359 foreach ($links as $v) {
360 if ($v[
'type'] ==
'sc') {
364 if ($v[
'type'] ==
'payment_salary') {
368 if ($v[
'type'] ==
'payment_expensereport') {
369 $is_expensereport =
true;
375 foreach ($links as $key => $val) {
376 if ($links[$key][
'type'] ==
'user' && !$is_sc && !$is_salary && !$is_expensereport) {
381 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'))) {
385 $tabpay[$obj->rowid][
'type'] = $links[$key][
'type'];
386 $tabtype[$obj->rowid] = $links[$key][
'type'];
397 if ($links[$key][
'type'] ==
'withdraw') {
398 $tabmoreinfo[$obj->rowid][
'withdraw'] = 1;
401 if ($links[$key][
'type'] ==
'payment') {
402 $paymentstatic->id = $links[$key][
'url_id'];
403 $paymentstatic->ref = (string) $links[$key][
'url_id'];
404 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentstatic->getNomUrl(2,
'',
'');
405 $tabpay[$obj->rowid][
"paymentid"] = $paymentstatic->id;
406 } elseif ($links[$key][
'type'] ==
'payment_supplier') {
407 $paymentsupplierstatic->id = $links[$key][
'url_id'];
408 $paymentsupplierstatic->ref = (string) $links[$key][
'url_id'];
409 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentsupplierstatic->getNomUrl(2);
410 $tabpay[$obj->rowid][
"paymentsupplierid"] = $paymentsupplierstatic->id;
411 } elseif ($links[$key][
'type'] ==
'company') {
412 $societestatic->id = $links[$key][
'url_id'];
413 $societestatic->name = $links[$key][
'label'];
414 $societestatic->email = $tabcompany[$obj->rowid][
'email'];
415 $tabpay[$obj->rowid][
"soclib"] = $societestatic->getNomUrl(1,
'', 30);
417 if (empty($tabtp[$obj->rowid][$compta_soc])) {
418 $tabtp[$obj->rowid][$compta_soc] = $amounttouse;
420 $tabtp[$obj->rowid][$compta_soc] += $amounttouse;
423 } elseif ($links[$key][
'type'] ==
'user') {
424 $userstatic->id = $links[$key][
'url_id'];
425 $userstatic->name = $links[$key][
'label'];
426 $userstatic->email = $tabuser[$obj->rowid][
'email'];
427 $userstatic->firstname = $tabuser[$obj->rowid][
'firstname'];
428 $userstatic->lastname = $tabuser[$obj->rowid][
'lastname'];
429 $userstatic->status = $tabuser[$obj->rowid][
'status'];
430 $userstatic->accountancy_code = $tabuser[$obj->rowid][
'accountancy_code'];
435 if ($userstatic->id > 0) {
437 $tabpay[$obj->rowid][
"soclib"] .=
' '.$userstatic->getNomUrl(1,
'accountancy', 0);
439 $tabpay[$obj->rowid][
"soclib"] = $userstatic->getNomUrl(1,
'accountancy', 0);
442 $tabpay[$obj->rowid][
"soclib"] =
'???';
449 $tabtp[$obj->rowid][$compta_user] += $amounttouse;
452 } elseif ($links[$key][
'type'] ==
'sc') {
453 $chargestatic->id = $links[$key][
'url_id'];
454 $chargestatic->ref = (string) $links[$key][
'url_id'];
456 $tabpay[$obj->rowid][
"lib"] .=
' '.$chargestatic->getNomUrl(2);
458 if (preg_match(
'/^\((.*)\)$/i', $links[$key][
'label'], $reg)) {
459 if ($reg[1] ==
'socialcontribution') {
460 $reg[1] =
'SocialContribution';
462 $chargestatic->label = $langs->trans($reg[1]);
464 $chargestatic->label = $links[$key][
'label'];
466 $chargestatic->ref = $chargestatic->label;
469 $tabpay[$obj->rowid][
"soclib"] = $chargestatic->getNomUrl(1, 30);
470 $tabpay[$obj->rowid][
"paymentscid"] = $chargestatic->id;
474 $sqlmid =
"SELECT cchgsoc.accountancy_code";
475 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales cchgsoc";
476 $sqlmid .=
" INNER JOIN ".MAIN_DB_PREFIX.
"chargesociales as chgsoc ON chgsoc.fk_type = cchgsoc.id";
477 $sqlmid .=
" INNER JOIN ".MAIN_DB_PREFIX.
"paiementcharge as paycharg ON paycharg.fk_charge = chgsoc.rowid";
478 $sqlmid .=
" INNER JOIN ".MAIN_DB_PREFIX.
"bank_url as bkurl ON bkurl.url_id=paycharg.rowid AND bkurl.type = 'payment_sc'";
479 $sqlmid .=
" WHERE bkurl.fk_bank = ".((int) $obj->rowid);
481 dol_syslog(
"accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);
482 $resultmid = $db->query($sqlmid);
484 $objmid = $db->fetch_object($resultmid);
485 $tabtp[$obj->rowid][$objmid->accountancy_code] = isset($tabtp[$obj->rowid][$objmid->accountancy_code]) ? $tabtp[$obj->rowid][$objmid->accountancy_code] + $amounttouse : $amounttouse;
487 } elseif ($links[$key][
'type'] ==
'payment_donation') {
488 $paymentdonstatic->id = $links[$key][
'url_id'];
489 $paymentdonstatic->ref = (string) $links[$key][
'url_id'];
490 $paymentdonstatic->fk_donation = $links[$key][
'url_id'];
491 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentdonstatic->getNomUrl(2);
492 $tabpay[$obj->rowid][
"paymentdonationid"] = $paymentdonstatic->id;
493 $tabtp[$obj->rowid][$account_pay_donation] = isset($tabtp[$obj->rowid][$account_pay_donation]) ? $tabtp[$obj->rowid][$account_pay_donation] + $amounttouse : $amounttouse;
494 } elseif ($links[$key][
'type'] ==
'member') {
495 $paymentsubscriptionstatic->id = $links[$key][
'url_id'];
496 $paymentsubscriptionstatic->ref = (string) $links[$key][
'url_id'];
497 $paymentsubscriptionstatic->label = $links[$key][
'label'];
498 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentsubscriptionstatic->getNomUrl(2);
499 $tabpay[$obj->rowid][
"paymentsubscriptionid"] = $paymentsubscriptionstatic->id;
500 $paymentsubscriptionstatic->fetch($paymentsubscriptionstatic->id);
501 $tabtp[$obj->rowid][$account_pay_subscription] = isset($tabtp[$obj->rowid][$account_pay_subscription]) ? $tabtp[$obj->rowid][$account_pay_subscription] + $amounttouse : $amounttouse;
502 } elseif ($links[$key][
'type'] ==
'payment_vat') {
503 $paymentvatstatic->id = $links[$key][
'url_id'];
504 $paymentvatstatic->ref = (string) $links[$key][
'url_id'];
505 $paymentvatstatic->label = $links[$key][
'label'];
506 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentvatstatic->getNomUrl(2);
507 $tabpay[$obj->rowid][
"paymentvatid"] = $paymentvatstatic->id;
508 $tabtp[$obj->rowid][$account_pay_vat] = isset($tabtp[$obj->rowid][$account_pay_vat]) ? $tabtp[$obj->rowid][$account_pay_vat] + $amounttouse : $amounttouse;
509 } elseif ($links[$key][
'type'] ==
'payment_salary') {
510 $paymentsalstatic->id = $links[$key][
'url_id'];
511 $paymentsalstatic->ref = (string) $links[$key][
'url_id'];
512 $paymentsalstatic->label = $links[$key][
'label'];
513 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentsalstatic->getNomUrl(2);
514 $tabpay[$obj->rowid][
"paymentsalid"] = $paymentsalstatic->id;
518 if (
getDolGlobalString(
'ACCOUNTANCY_AUTOFIX_MISSING_LINK_TO_USER_ON_SALARY_BANK_PAYMENT')) {
519 $tmpsalary =
new Salary($db);
520 $tmpsalary->fetch($paymentsalstatic->id);
521 $tmpsalary->fetch_user($tmpsalary->fk_user);
523 $userstatic->id = $tmpsalary->user->id;
524 $userstatic->name = $tmpsalary->user->name;
525 $userstatic->email = $tmpsalary->user->email;
526 $userstatic->firstname = $tmpsalary->user->firstname;
527 $userstatic->lastname = $tmpsalary->user->lastname;
528 $userstatic->status = $tmpsalary->user->status;
529 $userstatic->accountancy_code = $tmpsalary->user->accountancy_code;
531 if ($userstatic->id > 0) {
532 $tabpay[$obj->rowid][
"soclib"] = $userstatic->getNomUrl(1,
'accountancy', 0);
534 $tabpay[$obj->rowid][
"soclib"] =
'???';
537 if (empty($obj->typeop_user)) {
538 $compta_user = $userstatic->accountancy_code;
540 $tabtp[$obj->rowid][$compta_user] += $amounttouse;
541 $tabuser[$obj->rowid] = array(
542 'id' => $userstatic->id,
544 'lastname' => $userstatic->lastname,
545 'firstname' => $userstatic->firstname,
546 'email' => $userstatic->email,
547 'accountancy_code' => $compta_user,
548 'status' => $userstatic->status
553 } elseif ($links[$key][
'type'] ==
'payment_expensereport') {
554 $paymentexpensereportstatic->id = $links[$key][
'url_id'];
555 $tabpay[$obj->rowid][
"lib"] .= $paymentexpensereportstatic->getNomUrl(2);
556 $tabpay[$obj->rowid][
"paymentexpensereport"] = $paymentexpensereportstatic->id;
557 } elseif ($links[$key][
'type'] ==
'payment_various') {
558 $paymentvariousstatic->id = $links[$key][
'url_id'];
559 $paymentvariousstatic->ref = (string) $links[$key][
'url_id'];
560 $paymentvariousstatic->label = $links[$key][
'label'];
561 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentvariousstatic->getNomUrl(2);
562 $tabpay[$obj->rowid][
"paymentvariousid"] = $paymentvariousstatic->id;
563 $paymentvariousstatic->fetch($paymentvariousstatic->id);
564 $account_various = (!empty($paymentvariousstatic->accountancy_code) ? $paymentvariousstatic->accountancy_code :
'NotDefined');
565 $account_subledger = (!empty($paymentvariousstatic->subledger_account) ? $paymentvariousstatic->subledger_account :
'');
566 $tabpay[$obj->rowid][
"account_various"] = $account_various;
567 $tabtp[$obj->rowid][$account_subledger] = isset($tabtp[$obj->rowid][$account_subledger]) ? $tabtp[$obj->rowid][$account_subledger] + $amounttouse : $amounttouse;
568 } elseif ($links[$key][
'type'] ==
'payment_loan') {
569 $paymentloanstatic->id = $links[$key][
'url_id'];
570 $paymentloanstatic->ref = (string) $links[$key][
'url_id'];
571 $paymentloanstatic->fk_loan = $links[$key][
'url_id'];
572 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentloanstatic->getNomUrl(2);
573 $tabpay[$obj->rowid][
"paymentloanid"] = $paymentloanstatic->id;
575 $sqlmid =
'SELECT pl.amount_capital, pl.amount_insurance, pl.amount_interest, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest';
576 $sqlmid .=
' FROM '.MAIN_DB_PREFIX.
'payment_loan as pl, '.MAIN_DB_PREFIX.
'loan as l';
577 $sqlmid .=
' WHERE l.rowid = pl.fk_loan AND pl.fk_bank = '.((int) $obj->rowid);
579 dol_syslog(
"accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);
580 $resultmid = $db->query($sqlmid);
582 $objmid = $db->fetch_object($resultmid);
583 $tabtp[$obj->rowid][$objmid->accountancy_account_capital] = isset($objmid->amount_capital) ? $tabtp[$obj->rowid][$objmid->accountancy_account_capital] - $objmid->amount_capital : 0;
584 $tabtp[$obj->rowid][$objmid->accountancy_account_insurance] = isset($objmid->amount_insurance) ? $tabtp[$obj->rowid][$objmid->accountancy_account_insurance] - $objmid->amount_insurance : 0;
585 $tabtp[$obj->rowid][$objmid->accountancy_account_interest] = isset($objmid->amount_interest) ? $tabtp[$obj->rowid][$objmid->accountancy_account_interest] - $objmid->amount_interest : 0;
587 } elseif ($links[$key][
'type'] ==
'banktransfert') {
588 $accountLinestatic->fetch($links[$key][
'url_id']);
589 $tabpay[$obj->rowid][
"lib"] .=
' '.$langs->trans(
"BankTransfer").
'- '.$accountLinestatic ->getNomUrl(1);
590 $tabtp[$obj->rowid][$account_transfer] = isset($tabtp[$obj->rowid][$account_transfer]) ? $tabtp[$obj->rowid][$account_transfer] + $amounttouse : $amounttouse;
591 $bankaccountstatic->fetch($tabpay[$obj->rowid][
'fk_bank_account']);
592 $tabpay[$obj->rowid][
"soclib"] = $bankaccountstatic->getNomUrl(2);
597 if (empty($tabbq[$obj->rowid][$compta_bank])) {
598 $tabbq[$obj->rowid][$compta_bank] = $amounttouse;
600 $tabbq[$obj->rowid][$compta_bank] += $amounttouse;
605 if (empty($tabtp[$obj->rowid]) && !empty($tabmoreinfo[$obj->rowid][
'withdraw'])) {
606 foreach ($links as $key => $val) {
607 if ($links[$key][
'type'] ==
'payment') {
609 $tmppayment->fetch($links[$key][
'url_id']);
610 $arrayofamounts = $tmppayment->getAmountsArray();
611 if (is_array($arrayofamounts)) {
612 foreach ($arrayofamounts as $invoiceid => $amount) {
613 $tmpinvoice->fetch($invoiceid);
614 $tmpinvoice->fetch_thirdparty();
615 if ($tmpinvoice->thirdparty->code_compta_client) {
616 $tabtp[$obj->rowid][$tmpinvoice->thirdparty->code_compta_client] += $amount;
625 if (empty($tabtp[$obj->rowid])) {
626 $tabtp[$obj->rowid][
'NotDefined'] = $tabbq[$obj->rowid][$compta_bank];
638if (!$error && $action ==
'writebookkeeping' && $user->hasRight(
'accounting',
'bind',
'write')) {
642 $accountingaccountcustomer->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'),
true);
645 $accountingaccountsupplier->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUPPLIER'),
true);
648 $accountingaccountpayment->fetch(0,
getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT'),
true);
651 $accountingaccountexpensereport->fetch(0, $conf->global->ACCOUNTING_ACCOUNT_EXPENSEREPORT,
true);
654 $accountingaccountsuspense->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUSPENSE'),
true);
657 foreach ($tabpay as $key => $val) {
672 if (!$errorforline && is_array($tabbq[$key])) {
674 foreach ($tabbq[$key] as $k => $mt) {
676 if (empty($conf->cache[
'accountingaccountincurrententity'][$k])) {
678 $accountingaccount->fetch(0, $k,
true);
679 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
681 $accountingaccount = $conf->cache[
'accountingaccountincurrententity'][$k];
684 $account_label = $accountingaccount->label;
687 if (!empty($val[
'lib'])) {
691 if (!empty($val[
'soclib'])) {
692 $reflabel .=
" - ".dol_string_nohtmltag($val[
'soclib']);
696 $bookkeeping->doc_date = $val[
"date"];
697 $bookkeeping->doc_ref = $ref;
698 $bookkeeping->doc_type =
'bank';
699 $bookkeeping->fk_doc = $key;
700 $bookkeeping->fk_docdet = $val[
"fk_bank"];
702 $bookkeeping->numero_compte = $k;
703 $bookkeeping->label_compte = $account_label;
705 $bookkeeping->label_operation = $reflabel;
706 $bookkeeping->montant = $mt;
707 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
708 $bookkeeping->debit = ($mt >= 0 ? $mt : 0);
709 $bookkeeping->credit = ($mt < 0 ? -$mt : 0);
710 $bookkeeping->code_journal = $journal;
711 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
712 $bookkeeping->fk_user_author = $user->id;
713 $bookkeeping->date_creation = $now;
716 $bookkeeping->subledger_account =
'';
717 $bookkeeping->label_operation = $reflabel;
718 $bookkeeping->entity = $conf->entity;
720 $totaldebit += $bookkeeping->debit;
721 $totalcredit += $bookkeeping->credit;
723 $result = $bookkeeping->create($user);
725 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
728 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded',
null,
'warnings');
740 if (!$errorforline) {
741 if (is_array($tabtp[$key])) {
743 foreach ($tabtp[$key] as $k => $mt) {
748 if (!empty($val[
'lib'])) {
751 if ($tabtype[$key] ==
'banktransfert') {
752 $reflabel .=
dol_string_nohtmltag($langs->transnoentitiesnoconv(
'TransitionalAccount').
' '.$account_transfer);
758 $bookkeeping->doc_date = $val[
"date"];
759 $bookkeeping->doc_ref = $ref;
760 $bookkeeping->doc_type =
'bank';
761 $bookkeeping->fk_doc = $key;
762 $bookkeeping->fk_docdet = $val[
"fk_bank"];
764 $bookkeeping->label_operation = $reflabel;
765 $bookkeeping->montant = $mt;
766 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
767 $bookkeeping->debit = ($mt < 0 ? -$mt : 0);
768 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
769 $bookkeeping->code_journal = $journal;
770 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
771 $bookkeeping->fk_user_author = $user->id;
772 $bookkeeping->date_creation = $now;
774 if ($tabtype[$key] ==
'payment') {
776 $bookkeeping->subledger_account = $k;
777 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
779 $bookkeeping->label_compte = $accountingaccountcustomer->label;
780 } elseif ($tabtype[$key] ==
'payment_supplier') {
782 $bookkeeping->subledger_account = $k;
783 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
785 $bookkeeping->label_compte = $accountingaccountsupplier->label;
786 } elseif ($tabtype[$key] ==
'payment_expensereport') {
787 $bookkeeping->subledger_account = $tabuser[$key][
'accountancy_code'];
788 $bookkeeping->subledger_label = $tabuser[$key][
'name'];
790 $bookkeeping->label_compte = $accountingaccountexpensereport->label;
791 } elseif ($tabtype[$key] ==
'payment_salary') {
792 $bookkeeping->subledger_account = $tabuser[$key][
'accountancy_code'];
793 $bookkeeping->subledger_label = $tabuser[$key][
'name'];
794 $bookkeeping->numero_compte =
getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT');
795 $bookkeeping->label_compte = $accountingaccountpayment->label;
796 } elseif (in_array($tabtype[$key], array(
'sc',
'payment_sc'))) {
797 $bookkeeping->subledger_account =
'';
798 $bookkeeping->subledger_label =
'';
799 $accountingaccount->fetch(0, $k,
true);
800 $bookkeeping->numero_compte = $k;
801 $bookkeeping->label_compte = $accountingaccount->label;
802 } elseif ($tabtype[$key] ==
'payment_vat') {
803 $bookkeeping->subledger_account =
'';
804 $bookkeeping->subledger_label =
'';
805 $accountingaccount->fetch(0, $k,
true);
806 $bookkeeping->numero_compte = $k;
807 $bookkeeping->label_compte = $accountingaccount->label;
808 } elseif ($tabtype[$key] ==
'payment_donation') {
809 $bookkeeping->subledger_account =
'';
810 $bookkeeping->subledger_label =
'';
811 $accountingaccount->fetch(0, $k,
true);
812 $bookkeeping->numero_compte = $k;
813 $bookkeeping->label_compte = $accountingaccount->label;
814 } elseif ($tabtype[$key] ==
'member') {
815 $bookkeeping->subledger_account =
'';
816 $bookkeeping->subledger_label =
'';
817 $accountingaccount->fetch(0, $k,
true);
818 $bookkeeping->numero_compte = $k;
819 $bookkeeping->label_compte = $accountingaccount->label;
820 } elseif ($tabtype[$key] ==
'payment_loan') {
821 $bookkeeping->subledger_account =
'';
822 $bookkeeping->subledger_label =
'';
823 $accountingaccount->fetch(0, $k,
true);
824 $bookkeeping->numero_compte = $k;
825 $bookkeeping->label_compte = $accountingaccount->label;
826 } elseif ($tabtype[$key] ==
'payment_various') {
827 $bookkeeping->subledger_account = $k;
828 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
829 $accountingaccount->fetch(0, $tabpay[$key][
"account_various"],
true);
830 $bookkeeping->numero_compte = $tabpay[$key][
"account_various"];
831 $bookkeeping->label_compte = $accountingaccount->label;
832 } elseif ($tabtype[$key] ==
'banktransfert') {
833 $bookkeeping->subledger_account =
'';
834 $bookkeeping->subledger_label =
'';
835 $accountingaccount->fetch(0, $k,
true);
836 $bookkeeping->numero_compte = $k;
837 $bookkeeping->label_compte = $accountingaccount->label;
839 if ($tabtype[$key] ==
'unknown') {
841 $bookkeeping->subledger_account =
'';
842 $bookkeeping->subledger_label =
'';
844 $bookkeeping->label_compte = $accountingaccountsuspense->label;
847 $bookkeeping->label_operation = $reflabel;
848 $bookkeeping->entity = $conf->entity;
850 $totaldebit += $bookkeeping->debit;
851 $totalcredit += $bookkeeping->credit;
853 $result = $bookkeeping->create($user);
855 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
858 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded',
null,
'warnings');
866 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/lettering.class.php';
868 $nb_lettering = $lettering_static->bookkeepingLetteringAll(array($bookkeeping->id));
874 foreach ($tabbq[$key] as $k => $mt) {
877 if (!empty($val[
'lib'])) {
883 $bookkeeping->doc_date = $val[
"date"];
884 $bookkeeping->doc_ref = $ref;
885 $bookkeeping->doc_type =
'bank';
886 $bookkeeping->fk_doc = $key;
887 $bookkeeping->fk_docdet = $val[
"fk_bank"];
888 $bookkeeping->montant = $mt;
889 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
890 $bookkeeping->debit = ($mt < 0 ? -$mt : 0);
891 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
892 $bookkeeping->code_journal = $journal;
893 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
894 $bookkeeping->fk_user_author = $user->id;
895 $bookkeeping->date_creation = $now;
896 $bookkeeping->label_compte =
'';
897 $bookkeeping->label_operation = $reflabel;
898 $bookkeeping->entity = $conf->entity;
900 $totaldebit += $bookkeeping->debit;
901 $totalcredit += $bookkeeping->credit;
903 $result = $bookkeeping->create($user);
906 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
909 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded',
null,
'warnings');
924 setEventMessages(
'We tried to insert a non balanced transaction in book for '.$ref.
'. Canceled. Surely a bug.',
null,
'errors');
927 if (!$errorforline) {
934 if ($error >= $MAXNBERRORS) {
935 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped").
' (>'.$MAXNBERRORS.
')',
null,
'errors');
941 if (empty($error) && count($tabpay) > 0) {
943 } elseif (count($tabpay) == $error) {
946 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
952 if (count($tabpay) != $error) {
953 $param =
'id_journal='.$id_journal;
954 $param .=
'&date_startday='.$date_startday;
955 $param .=
'&date_startmonth='.$date_startmonth;
956 $param .=
'&date_startyear='.$date_startyear;
957 $param .=
'&date_endday='.$date_endday;
958 $param .=
'&date_endmonth='.$date_endmonth;
959 $param .=
'&date_endyear='.$date_endyear;
960 $param .=
'&in_bookkeeping='.$in_bookkeeping;
961 header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
969if ($action ==
'exportcsv' && $user->hasRight(
'accounting',
'bind',
'write')) {
972 $filename =
'journal';
973 $type_export =
'journal';
974 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
977 print
'"'.$langs->transnoentitiesnoconv(
"BankId").
'"'.$sep;
978 print
'"'.$langs->transnoentitiesnoconv(
"Date").
'"'.$sep;
979 print
'"'.$langs->transnoentitiesnoconv(
"PaymentMode").
'"'.$sep;
980 print
'"'.$langs->transnoentitiesnoconv(
"AccountAccounting").
'"'.$sep;
981 print
'"'.$langs->transnoentitiesnoconv(
"LedgerAccount").
'"'.$sep;
982 print
'"'.$langs->transnoentitiesnoconv(
"SubledgerAccount").
'"'.$sep;
983 print
'"'.$langs->transnoentitiesnoconv(
"Label").
'"'.$sep;
984 print
'"'.$langs->transnoentitiesnoconv(
"AccountingDebit").
'"'.$sep;
985 print
'"'.$langs->transnoentitiesnoconv(
"AccountingCredit").
'"'.$sep;
986 print
'"'.$langs->transnoentitiesnoconv(
"Journal").
'"'.$sep;
987 print
'"'.$langs->transnoentitiesnoconv(
"Note").
'"'.$sep;
990 foreach ($tabpay as $key => $val) {
996 foreach ($tabbq[$key] as $k => $mt) {
999 if (!empty($val[
'lib'])) {
1003 if (!empty($val[
'soclib'])) {
1004 $reflabel .=
" - ".dol_string_nohtmltag($val[
'soclib']);
1007 print
'"'.$key.
'"'.$sep;
1008 print
'"'.$date.
'"'.$sep;
1009 print
'"'.$val[
"type_payment"].
'"'.$sep;
1010 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1011 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
1013 print
'"'.$reflabel.
'"'.$sep;
1014 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1015 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1016 print
'"'.$journal.
'"'.$sep;
1017 print
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
1023 if (is_array($tabtp[$key])) {
1024 foreach ($tabtp[$key] as $k => $mt) {
1027 if (!empty($val[
'lib'])) {
1030 if ($tabtype[$key] ==
'banktransfert') {
1031 $reflabel .=
dol_string_nohtmltag($langs->transnoentitiesnoconv(
'TransitionalAccount').
' '.$account_transfer);
1036 print
'"'.$key.
'"'.$sep;
1037 print
'"'.$date.
'"'.$sep;
1038 print
'"'.$val[
"type_payment"].
'"'.$sep;
1039 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1040 if ($tabtype[$key] ==
'payment_supplier') {
1041 $account_ledger = (!empty($obj->accountancy_code_supplier_general)) ? $obj->accountancy_code_supplier_general : $account_supplier;
1042 print
'"'.$account_ledger.
'"'.$sep;
1043 } elseif ($tabtype[$key] ==
'payment') {
1044 $account_ledger = (!empty($obj->accountancy_code_customer_general)) ? $obj->accountancy_code_customer_general : $account_customer;
1045 print
'"'.$account_ledger.
'"'.$sep;
1046 } elseif ($tabtype[$key] ==
'payment_expensereport') {
1047 print
'"'.getDolGlobalString(
'ACCOUNTING_ACCOUNT_EXPENSEREPORT').
'"'.$sep;
1048 } elseif ($tabtype[$key] ==
'payment_salary') {
1049 print
'"'.getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT').
'"'.$sep;
1051 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1053 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
1054 print
'"'.$reflabel.
'"'.$sep;
1055 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1056 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1057 print
'"'.$journal.
'"'.$sep;
1058 print
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
1063 foreach ($tabbq[$key] as $k => $mt) {
1066 if (!empty($val[
'lib'])) {
1071 print
'"'.$key.
'"'.$sep;
1072 print
'"'.$date.
'"'.$sep;
1073 print
'"'.$val[
"type_payment"].
'"'.$sep;
1074 print
'"'.length_accountg(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUSPENSE')).
'"'.$sep;
1075 print
'"'.length_accounta(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUSPENSE')).
'"'.$sep;
1077 print
'"'.$reflabel.
'"'.$sep;
1078 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1079 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1080 print
'"'.$journal.
'"'.$sep;
1081 print
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
1094$form =
new Form($db);
1096if (empty($action) || $action ==
'view') {
1097 $invoicestatic =
new Facture($db);
1100 $vatstatic =
new Tva($db);
1101 $donationstatic =
new Don($db);
1102 $loanstatic =
new Loan($db);
1103 $salarystatic =
new Salary($db);
1106 $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1,
'', 1);
1107 $help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
1113 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
1115 $listofchoices = array(
1116 'notyet' => $langs->trans(
"NotYetInGeneralLedger"),
1117 'already' => $langs->trans(
"AlreadyInGeneralLedger")
1119 $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);
1120 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
1122 $varlink =
'id_journal='.$id_journal;
1126 $listofchoices = array(
1127 1 => $langs->trans(
"TransfertAllBankLines"),
1128 2 => $langs->trans(
"TransfertOnlyConciliatedBankLine")
1130 $moreoptions = [
"BankLineConciliated" => $form->selectarray(
'only_rappro', $listofchoices, $only_rappro)];
1132 journalHead($nom,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink, $moreoptions);
1139 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_fiscalyear WHERE entity = ".((int) $conf->entity);
1140 $resql = $db->query($sql);
1142 $obj = $db->fetch_object($resql);
1143 if ($obj->nb == 0) {
1144 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheFiscalPeriodIsNotDefined");
1145 $desc =
' : '.$langs->trans(
"AccountancyAreaDescFiscalPeriod", 4,
'{link}');
1146 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"FiscalPeriod").
'</strong>', $desc);
1156 $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";
1157 $resql = $db->query($sql);
1159 $obj = $db->fetch_object($resql);
1161 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheJournalCodeIsNotDefinedOnSomeBankAccount");
1162 $desc =
' : '.$langs->trans(
"AccountancyAreaDescBank", 6,
'{link}');
1163 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"BankAccounts").
'</strong>', $desc);
1179 print($desc ?
'' :
'<br>').
'<div class="warning">'.
img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
1180 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
1181 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
1187 print
'<br><div class="tabsAction tabsActionNoBottom centerimp">';
1189 if (
getDolGlobalString(
'ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping ==
'notyet') {
1190 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
1195 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
1197 if ($in_bookkeeping ==
'notyet') {
1198 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
1200 print
'<a class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
1208 <script type="text/javascript">
1209 function launch_export() {
1210 console.log("Set value into form and submit");
1211 $("div.fiche form input[name=\"action\"]").val("exportcsv");
1212 $("div.fiche form input[type=\"submit\"]").click();
1213 $("div.fiche form input[name=\"action\"]").val("");
1215 function writebookkeeping() {
1216 console.log("Set value into form and submit");
1217 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
1218 $("div.fiche form input[type=\"submit\"]").click();
1219 $("div.fiche form input[name=\"action\"]").val("");
1229 print
'<div class="div-table-responsive">';
1230 print
'<table class="noborder centpercent">';
1231 print
'<tr class="liste_titre">';
1232 print
"<td>".$langs->trans(
"Date").
"</td>";
1233 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"ObjectsRef").
")</td>";
1234 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
1235 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
1236 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
1237 print
'<td class="center">'.$langs->trans(
"PaymentMode").
"</td>";
1238 print
'<td class="right">'.$langs->trans(
"AccountingDebit").
"</td>";
1239 print
'<td class="right">'.$langs->trans(
"AccountingCredit").
"</td>";
1244 foreach ($tabpay as $key => $val) {
1250 foreach ($tabbq[$key] as $k => $mt) {
1253 if (!empty($val[
'lib'])) {
1254 $reflabel .= $val[
'lib'].
" - ";
1256 $reflabel .= $langs->trans(
"Bank").
' '.$val[
'bank_account_ref'];
1257 if (!empty($val[
'soclib'])) {
1258 $reflabel .=
" - ".$val[
'soclib'];
1262 print
'<!-- Bank bank.rowid='.$key.
' type='.$tabpay[$key][
'type'].
' ref='.$tabpay[$key][
'ref'].
'-->';
1263 print
'<tr class="oddeven">';
1266 print
"<td>".$date.
"</td>";
1269 print
"<td>".dol_escape_htmltag($ref).
"</td>";
1273 if (empty($accounttoshow) || $accounttoshow ==
'NotDefined') {
1274 $accounttoshow =
'<span class="error">'.$langs->trans(
"BankAccountNotDefined").
'</span>';
1276 print
'<td class="maxwidth300" title="'.dol_escape_htmltag(
dol_string_nohtmltag($accounttoshow)).
'">';
1277 print $accounttoshow;
1281 print
'<td class="maxwidth300">';
1295 print
'<td class="center">'.$val[
"type_payment"].
"</td>";
1296 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1297 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1305 if (is_array($tabtp[$key])) {
1306 foreach ($tabtp[$key] as $k => $mt) {
1309 if (!empty($val[
'lib'])) {
1310 $reflabel .= $val[
'lib'].(isset($val[
'soclib']) ?
" - " :
"");
1312 if ($tabtype[$key] ==
'banktransfert') {
1313 $reflabel .= $langs->trans(
'TransitionalAccount').
' '.$account_transfer;
1315 $reflabel .= isset($val[
'soclib']) ? $val[
'soclib'] :
"";
1318 print
'<!-- Thirdparty bank.rowid='.$key.
' -->';
1319 print
'<tr class="oddeven">';
1322 print
"<td>".$date.
"</td>";
1325 print
"<td>".dol_escape_htmltag($ref).
"</td>";
1328 $account_ledger = $k;
1330 if ($tabtype[$key] ==
'payment') {
1333 if ($tabtype[$key] ==
'payment_supplier') {
1336 if ($tabtype[$key] ==
'payment_expensereport') {
1339 if ($tabtype[$key] ==
'payment_salary') {
1342 if ($tabtype[$key] ==
'payment_vat') {
1345 if ($tabtype[$key] ==
'member') {
1348 if ($tabtype[$key] ==
'payment_various') {
1349 $account_ledger = $tabpay[$key][
"account_various"];
1352 if (empty($accounttoshow) || $accounttoshow ==
'NotDefined') {
1353 if ($tabtype[$key] ==
'unknown') {
1356 $accounttoshow =
'<span class="error small">'.$langs->trans(
'UnknownAccountForThirdpartyAndWaitingAccountNotDefinedBlocking').
'</span>';
1358 $accounttoshow =
'<span class="warning small">'.$langs->trans(
'UnknownAccountForThirdparty',
length_accountg(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUSPENSE'))).
'</span>';
1362 $errorstring =
'UnknownAccountForThirdpartyBlocking';
1363 if ($tabtype[$key] ==
'payment') {
1364 $errorstring =
'MainAccountForCustomersNotDefined';
1366 if ($tabtype[$key] ==
'payment_supplier') {
1367 $errorstring =
'MainAccountForSuppliersNotDefined';
1369 if ($tabtype[$key] ==
'payment_expensereport') {
1370 $errorstring =
'MainAccountForUsersNotDefined';
1372 if ($tabtype[$key] ==
'payment_salary') {
1373 $errorstring =
'MainAccountForUsersNotDefined';
1375 if ($tabtype[$key] ==
'payment_vat') {
1376 $errorstring =
'MainAccountForVatPaymentNotDefined';
1378 if ($tabtype[$key] ==
'member') {
1379 $errorstring =
'MainAccountForSubscriptionPaymentNotDefined';
1381 $accounttoshow =
'<span class="error small">'.$langs->trans($errorstring).
'</span>';
1384 print
'<td class="maxwidth300" title="'.dol_escape_htmltag(
dol_string_nohtmltag($accounttoshow)).
'">';
1385 print $accounttoshow;
1389 $accounttoshowsubledger =
'';
1390 if (in_array($tabtype[$key], array(
'payment',
'payment_supplier',
'payment_expensereport',
'payment_salary',
'payment_various'))) {
1392 if ($accounttoshow != $accounttoshowsubledger) {
1393 if (empty($accounttoshowsubledger) || $accounttoshowsubledger ==
'NotDefined') {
1395 if (!empty($tabcompany[$key][
'code_compta'])) {
1396 if (in_array($tabtype[$key], array(
'payment_various',
'payment_salary'))) {
1398 $accounttoshowsubledger =
'<span class="warning small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknownSubledgerIgnored").
'</span>';
1400 $accounttoshowsubledger =
'<span class="warning small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknown", $tabcompany[$key][
'code_compta']).
'</span>';
1403 $accounttoshowsubledger =
'<span class="error small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknownBlocking").
'</span>';
1407 $accounttoshowsubledger =
'';
1410 print
'<td class="maxwidth300">';
1411 print $accounttoshowsubledger;
1414 print
"<td>".$reflabel.
"</td>";
1416 print
'<td class="center">'.$val[
"type_payment"].
"</td>";
1418 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1420 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1428 foreach ($tabbq[$key] as $k => $mt) {
1431 if (!empty($val[
'lib'])) {
1432 $reflabel .= $val[
'lib'].
" - ";
1434 $reflabel .=
'WaitingAccount';
1436 print
'<!-- Wait bank.rowid='.$key.
' -->';
1437 print
'<tr class="oddeven">';
1438 print
"<td>".$date.
"</td>";
1439 print
"<td>".$ref.
"</td>";
1452 print
"<td>".dol_escape_htmltag($reflabel).
"</td>";
1453 print
'<td class="center">'.$val[
"type_payment"].
"</td>";
1454 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1455 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1466 print
'<tr class="oddeven"><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
1493 if ($ref ==
'(SupplierInvoicePayment)' || $ref ==
'(SupplierInvoicePaymentBack)') {
1494 $ref = $langs->transnoentitiesnoconv(
'Supplier');
1496 if ($ref ==
'(CustomerInvoicePayment)' || $ref ==
'(CustomerInvoicePaymentBack)') {
1497 $ref = $langs->transnoentitiesnoconv(
'Customer');
1499 if ($ref ==
'(SocialContributionPayment)') {
1500 $ref = $langs->transnoentitiesnoconv(
'SocialContribution');
1502 if ($ref ==
'(DonationPayment)') {
1503 $ref = $langs->transnoentitiesnoconv(
'Donation');
1505 if ($ref ==
'(SubscriptionPayment)') {
1506 $ref = $langs->transnoentitiesnoconv(
'Subscription');
1508 if ($ref ==
'(ExpenseReportPayment)') {
1509 $ref = $langs->transnoentitiesnoconv(
'Employee');
1511 if ($ref ==
'(LoanPayment)') {
1512 $ref = $langs->transnoentitiesnoconv(
'Loan');
1514 if ($ref ==
'(payment_salary)') {
1515 $ref = $langs->transnoentitiesnoconv(
'Employee');
1519 if ($typerecord ==
'payment') {
1521 $sqlmid =
"SELECT payfac.fk_facture as id, ".$db->ifsql(
'f1.rowid IS NULL',
'f.ref',
'f1.ref').
" as ref";
1522 $sqlmid .=
" FROM ".$db->prefix().
"paiement_facture as payfac";
1523 $sqlmid .=
" LEFT JOIN ".$db->prefix().
"facture as f ON f.rowid = payfac.fk_facture";
1524 $sqlmid .=
" LEFT JOIN ".$db->prefix().
"societe_remise_except as sre ON sre.fk_facture_source = payfac.fk_facture";
1525 $sqlmid .=
" LEFT JOIN ".$db->prefix().
"facture as f1 ON f1.rowid = sre.fk_facture";
1526 $sqlmid .=
" WHERE payfac.fk_paiement=".((int) $val[
'paymentid']);
1528 $sqlmid =
"SELECT payfac.fk_facture as id, f.ref as ref";
1529 $sqlmid .=
" FROM ".$db->prefix().
"paiement_facture as payfac";
1530 $sqlmid .=
" INNER JOIN ".$db->prefix().
"facture as f ON f.rowid = payfac.fk_facture";
1531 $sqlmid .=
" WHERE payfac.fk_paiement=".((int) $val[
'paymentid']);
1533 $ref = $langs->transnoentitiesnoconv(
"Invoice");
1534 } elseif ($typerecord ==
'payment_supplier') {
1535 $sqlmid =
'SELECT payfac.fk_facturefourn as id, f.ref';
1536 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as payfac, ".MAIN_DB_PREFIX.
"facture_fourn as f";
1537 $sqlmid .=
" WHERE payfac.fk_facturefourn = f.rowid AND payfac.fk_paiementfourn=".((int) $val[
"paymentsupplierid"]);
1538 $ref = $langs->transnoentitiesnoconv(
"SupplierInvoice");
1539 } elseif ($typerecord ==
'payment_expensereport') {
1540 $sqlmid =
'SELECT e.rowid as id, e.ref';
1541 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_expensereport as pe, ".MAIN_DB_PREFIX.
"expensereport as e";
1542 $sqlmid .=
" WHERE pe.rowid=".((int) $val[
"paymentexpensereport"]).
" AND pe.fk_expensereport = e.rowid";
1543 $ref = $langs->transnoentitiesnoconv(
"ExpenseReport");
1544 } elseif ($typerecord ==
'payment_salary') {
1545 $sqlmid =
'SELECT s.rowid as ref';
1546 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as s";
1547 $sqlmid .=
" WHERE s.rowid=".((int) $val[
"paymentsalid"]);
1548 $ref = $langs->transnoentitiesnoconv(
"SalaryPayment");
1549 } elseif ($typerecord ==
'sc') {
1550 $sqlmid =
'SELECT sc.rowid as ref';
1551 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"paiementcharge as sc";
1552 $sqlmid .=
" WHERE sc.rowid=".((int) $val[
"paymentscid"]);
1553 $ref = $langs->transnoentitiesnoconv(
"SocialContribution");
1554 } elseif ($typerecord ==
'payment_vat') {
1555 $sqlmid =
'SELECT v.rowid as ref';
1556 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"tva as v";
1557 $sqlmid .=
" WHERE v.rowid=".((int) $val[
"paymentvatid"]);
1558 $ref = $langs->transnoentitiesnoconv(
"PaymentVat");
1559 } elseif ($typerecord ==
'payment_donation') {
1560 $sqlmid =
'SELECT payd.fk_donation as ref';
1561 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_donation as payd";
1562 $sqlmid .=
" WHERE payd.fk_donation=".((int) $val[
"paymentdonationid"]);
1563 $ref = $langs->transnoentitiesnoconv(
"Donation");
1564 } elseif ($typerecord ==
'payment_loan') {
1565 $sqlmid =
'SELECT l.rowid as ref';
1566 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_loan as l";
1567 $sqlmid .=
" WHERE l.rowid=".((int) $val[
"paymentloanid"]);
1568 $ref = $langs->transnoentitiesnoconv(
"LoanPayment");
1569 } elseif ($typerecord ==
'payment_various') {
1570 $sqlmid =
'SELECT v.rowid as ref';
1571 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_various as v";
1572 $sqlmid .=
" WHERE v.rowid=".((int) $val[
"paymentvariousid"]);
1573 $ref = $langs->transnoentitiesnoconv(
"VariousPayment");
1576 if (empty($sqlmid)) {
1577 dol_syslog(
"Found a typerecord=".$typerecord.
" not supported", LOG_WARNING);
1581 dol_syslog(
"accountancy/journal/bankjournal.php::sqlmid=".$sqlmid, LOG_DEBUG);
1582 $resultmid = $db->query($sqlmid);
1584 while ($objmid = $db->fetch_object($resultmid)) {
1585 $ref .=
' '.$objmid->ref;
1592 $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.