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';
75$langs->loadLangs(array(
"companies",
"other",
"compta",
"banks",
"bills",
"donations",
"loan",
"accountancy",
"trips",
"salaries",
"hrm",
"members"));
80$date_startmonth =
GETPOSTINT(
'date_startmonth');
86$in_bookkeeping =
GETPOST(
'in_bookkeeping',
'aZ09');
89if ($only_rappro == 0) {
96$action =
GETPOST(
'action',
'aZ09');
98if ($in_bookkeeping ==
'') {
99 $in_bookkeeping =
'notyet';
104if (!isModEnabled(
'accounting')) {
107if ($user->socid > 0) {
110if (!$user->hasRight(
'accounting',
'bind',
'write')) {
121$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
122$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
125$pastmonthyear =
null;
127if (empty($date_startmonth)) {
130 $date_start = $dates[
'date_start'];
131 $pastmonthyear = $dates[
'pastmonthyear'];
132 $pastmonth = $dates[
'pastmonth'];
134if (empty($date_endmonth)) {
137 $date_end = $dates[
'date_end'];
138 $pastmonthyear = $dates[
'pastmonthyear'];
139 $pastmonth = $dates[
'pastmonth'];
142if (!GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end))) {
147$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,";
148$sql .=
" ba.courant, ba.ref as baref, ba.account_number, ba.fk_accountancy_journal,";
149$sql .=
" soc.rowid as socid, soc.nom as name, soc.email as email, bu1.type as typeop_company,";
151 $sql .=
" spe.accountancy_code_customer_general,";
152 $sql .=
" spe.accountancy_code_customer as code_compta_client,";
153 $sql .=
" spe.accountancy_code_supplier_general,";
154 $sql .=
" spe.accountancy_code_supplier as code_compta_fournisseur,";
156 $sql .=
" soc.accountancy_code_customer_general,";
157 $sql .=
" soc.code_compta as code_compta_client,";
158 $sql .=
" soc.accountancy_code_supplier_general,";
159 $sql .=
" soc.code_compta_fournisseur,";
161$sql .=
" u.accountancy_code_user_general, u.accountancy_code, u.rowid as userid, u.lastname as lastname, u.firstname as firstname, u.email as useremail, u.statut as userstatus,";
162$sql .=
" bu2.type as typeop_user,";
163$sql .=
" bu3.type as typeop_payment, bu4.type as typeop_payment_supplier";
164$sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
165$sql .=
" JOIN ".MAIN_DB_PREFIX.
"bank_account as ba on b.fk_account=ba.rowid";
166$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'";
167$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON bu2.fk_bank = b.rowid AND bu2.type='user'";
168$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu3 ON bu3.fk_bank = b.rowid AND bu3.type='payment'";
169$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu4 ON bu4.fk_bank = b.rowid AND bu4.type='payment_supplier'";
170$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as soc on bu1.url_id=soc.rowid";
172 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = soc.rowid AND spe.entity = " . ((int)
$conf->entity);
174$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on bu2.url_id=u.rowid";
175$sql .=
" WHERE ba.fk_accountancy_journal=".((int) $id_journal);
176$sql .=
' AND b.amount <> 0 AND ba.entity IN ('.getEntity(
'bank_account', 0).
')';
177if ($date_start && $date_end) {
178 $sql .=
" AND b.dateo >= '".$db->idate($date_start).
"' AND b.dateo <= '".$db->idate($date_end).
"'";
182 $sql .=
" AND b.dateo >= '".$db->idate(
getDolGlobalInt(
'ACCOUNTING_DATE_START_BINDING')).
"'";
185if ($in_bookkeeping ==
'already') {
186 $sql .=
" AND (b.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
188if ($in_bookkeeping ==
'notyet') {
189 $sql .=
" AND (b.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
191if ($only_rappro == 2) {
192 $sql .=
" AND (b.rappro = '1')";
194$sql .=
" ORDER BY b.datev";
200$societestatic =
new Societe($db);
201$userstatic =
new User($db);
202$bankaccountstatic =
new Account($db);
205$paymentvatstatic =
new Tva($db);
217$account_transfer =
'NotDefined';
221$accountingjournalstatic->fetch($id_journal);
222$journal = $accountingjournalstatic->code;
223$journal_label = $accountingjournalstatic->label;
225$tabcompany = array();
231$tabmoreinfo = array();
234@phan-var-force array<array{id:mixed,name:mixed,code_compta_client:string,email:string}> $tabcompany
235@phan-var-force array<array{id:int,name:string,lastname:string,firstname:string,email:string,accountancy_code:string,status:int> $tabuser
236@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
237@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
240$account_customer =
'NotDefined';
241$account_supplier =
'NotDefined';
242$account_employee =
'NotDefined';
245dol_syslog(
"accountancy/journal/bankjournal.php", LOG_DEBUG);
246$result = $db->query($sql);
248 $num = $db->num_rows($result);
254 $account_employee =
getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT',
'NotDefined');
255 $account_expensereport =
getDolGlobalString(
'ACCOUNTING_ACCOUNT_EXPENSEREPORT',
'NotDefined');
257 $account_pay_donation =
getDolGlobalString(
'DONATION_ACCOUNTINGACCOUNT',
'NotDefined');
258 $account_pay_subscription =
getDolGlobalString(
'ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT',
'NotDefined');
259 $account_transfer =
getDolGlobalString(
'ACCOUNTING_ACCOUNT_TRANSFER_CASH',
'NotDefined');
268 $obj = $db->fetch_object($result);
270 $lineisapurchase = -1;
273 if ($obj->label ==
'(SupplierInvoicePayment)' || $obj->label ==
'(SupplierInvoicePaymentBack)') {
274 $lineisapurchase = 1;
276 if ($obj->label ==
'(CustomerInvoicePayment)' || $obj->label ==
'(CustomerInvoicePaymentBack)') {
280 if ($lineisapurchase < 0) {
281 if ($obj->typeop_payment_supplier ==
'payment_supplier') {
282 $lineisapurchase = 1;
285 if ($lineisasale < 0) {
286 if ($obj->typeop_payment ==
'payment') {
294 $compta_bank = $obj->account_number;
297 $compta_soc =
'NotDefined';
298 $accountancy_code_general =
'NotDefined';
299 if ($lineisapurchase > 0) {
300 $accountancy_code_general = (!empty($obj->accountancy_code_supplier_general)) ? $obj->accountancy_code_supplier_general : $account_supplier;
301 $compta_soc = (($obj->code_compta_fournisseur !=
"") ? $obj->code_compta_fournisseur : $account_supplier);
303 if ($lineisasale > 0) {
304 $accountancy_code_general = (!empty($obj->accountancy_code_customer_general)) ? $obj->accountancy_code_customer_general : $account_customer;
305 $compta_soc = (!empty($obj->code_compta_client) ? $obj->code_compta_client : $account_customer);
308 $tabcompany[$obj->rowid] = array(
310 'name' => $obj->name,
311 'code_compta' => $compta_soc,
312 'accountancy_code_general' => $accountancy_code_general,
313 'email' => $obj->email
319 $accountancy_code_user_general = (!empty($obj->accountancy_code_user_general)) ? $obj->accountancy_code_user_general : $account_employee;
320 $compta_user = (!empty($obj->accountancy_code) ? $obj->accountancy_code :
'');
322 $tabuser[$obj->rowid] = array(
323 'id' => $obj->userid,
325 'lastname' => $obj->lastname,
326 'firstname' => $obj->firstname,
327 'email' => $obj->useremail,
328 'accountancy_code_general' => $accountancy_code_user_general,
329 'accountancy_code' => $compta_user,
330 'status' => $obj->userstatus
334 $tabpay[$obj->rowid][
"date"] = $db->jdate($obj->do);
335 $tabpay[$obj->rowid][
"type_payment"] = $obj->fk_type;
336 $tabpay[$obj->rowid][
"ref"] = $obj->label;
337 $tabpay[$obj->rowid][
"fk_bank"] = $obj->rowid;
338 $tabpay[$obj->rowid][
"bank_account_ref"] = $obj->baref;
339 $tabpay[$obj->rowid][
"fk_bank_account"] = $obj->fk_account;
341 if (preg_match(
'/^\((.*)\)$/i', $obj->label, $reg)) {
342 $tabpay[$obj->rowid][
"lib"] = $langs->trans($reg[1]);
344 $tabpay[$obj->rowid][
"lib"] =
dol_trunc($obj->label, 60);
348 $links =
$object->get_url($obj->rowid);
353 $tabpay[$obj->rowid][
'type'] =
'unknown';
354 $tabtype[$obj->rowid] =
'unknown';
355 $tabmoreinfo[$obj->rowid] = array();
357 $amounttouse = $obj->amount;
358 if (!empty($obj->amount_main_currency)) {
360 $amounttouse = $obj->amount_main_currency;
364 if (is_array($links) && count($links) > 0) {
369 $is_expensereport =
false;
370 foreach ($links as $v) {
371 if ($v[
'type'] ==
'sc') {
375 if ($v[
'type'] ==
'payment_salary') {
379 if ($v[
'type'] ==
'payment_expensereport') {
380 $is_expensereport =
true;
386 foreach ($links as $key => $val) {
387 if ($links[$key][
'type'] ==
'user' && !$is_sc && !$is_salary && !$is_expensereport) {
392 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'))) {
396 $tabpay[$obj->rowid][
'type'] = $links[$key][
'type'];
397 $tabtype[$obj->rowid] = $links[$key][
'type'];
408 if ($links[$key][
'type'] ==
'withdraw') {
409 $tabmoreinfo[$obj->rowid][
'withdraw'] = 1;
412 if ($links[$key][
'type'] ==
'payment') {
413 $paymentstatic->id = $links[$key][
'url_id'];
414 $paymentstatic->ref = (string) $links[$key][
'url_id'];
415 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentstatic->getNomUrl(2,
'',
'');
416 $tabpay[$obj->rowid][
"paymentid"] = $paymentstatic->id;
417 } elseif ($links[$key][
'type'] ==
'payment_supplier') {
418 $paymentsupplierstatic->id = $links[$key][
'url_id'];
419 $paymentsupplierstatic->ref = (string) $links[$key][
'url_id'];
420 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentsupplierstatic->getNomUrl(2);
421 $tabpay[$obj->rowid][
"paymentsupplierid"] = $paymentsupplierstatic->id;
422 } elseif ($links[$key][
'type'] ==
'company') {
423 $societestatic->id = $links[$key][
'url_id'];
424 $societestatic->name = $links[$key][
'label'];
425 $societestatic->email = $tabcompany[$obj->rowid][
'email'];
426 $tabpay[$obj->rowid][
"soclib"] = $societestatic->getNomUrl(1,
'', 30);
428 if (empty($tabtp[$obj->rowid][$compta_soc])) {
429 $tabtp[$obj->rowid][$compta_soc] = $amounttouse;
431 $tabtp[$obj->rowid][$compta_soc] += $amounttouse;
434 } elseif ($links[$key][
'type'] ==
'user') {
435 $userstatic->id = $links[$key][
'url_id'];
436 $userstatic->name = $links[$key][
'label'];
437 $userstatic->email = $tabuser[$obj->rowid][
'email'];
438 $userstatic->firstname = $tabuser[$obj->rowid][
'firstname'];
439 $userstatic->lastname = $tabuser[$obj->rowid][
'lastname'];
440 $userstatic->status = $tabuser[$obj->rowid][
'status'];
441 $userstatic->accountancy_code_user_general = $tabuser[$obj->rowid][
'accountancy_code_general'];
442 $userstatic->accountancy_code = $tabuser[$obj->rowid][
'accountancy_code'];
447 if ($userstatic->id > 0) {
449 $tabpay[$obj->rowid][
"soclib"] .=
' '.$userstatic->getNomUrl(1,
'accountancy', 0);
451 $tabpay[$obj->rowid][
"soclib"] = $userstatic->getNomUrl(1,
'accountancy', 0);
454 $tabpay[$obj->rowid][
"soclib"] =
'???';
461 $tabtp[$obj->rowid][$compta_user] += $amounttouse;
464 } elseif ($links[$key][
'type'] ==
'sc') {
465 $chargestatic->id = $links[$key][
'url_id'];
466 $chargestatic->ref = (string) $links[$key][
'url_id'];
468 $tabpay[$obj->rowid][
"lib"] .=
' '.$chargestatic->getNomUrl(2);
470 if (preg_match(
'/^\((.*)\)$/i', $links[$key][
'label'], $reg)) {
471 if ($reg[1] ==
'socialcontribution') {
472 $reg[1] =
'SocialContribution';
474 $chargestatic->label = $langs->trans($reg[1]);
476 $chargestatic->label = $links[$key][
'label'];
478 $chargestatic->ref = $chargestatic->label;
481 $tabpay[$obj->rowid][
"soclib"] = $chargestatic->getNomUrl(1, 30);
482 $tabpay[$obj->rowid][
"paymentscid"] = $chargestatic->id;
486 $sqlmid =
"SELECT cchgsoc.accountancy_code";
487 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales cchgsoc";
488 $sqlmid .=
" INNER JOIN ".MAIN_DB_PREFIX.
"chargesociales as chgsoc ON chgsoc.fk_type = cchgsoc.id";
489 $sqlmid .=
" INNER JOIN ".MAIN_DB_PREFIX.
"paiementcharge as paycharg ON paycharg.fk_charge = chgsoc.rowid";
490 $sqlmid .=
" INNER JOIN ".MAIN_DB_PREFIX.
"bank_url as bkurl ON bkurl.url_id=paycharg.rowid AND bkurl.type = 'payment_sc'";
491 $sqlmid .=
" WHERE bkurl.fk_bank = ".((int) $obj->rowid);
493 dol_syslog(
"accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);
494 $resultmid = $db->query($sqlmid);
496 $objmid = $db->fetch_object($resultmid);
497 $tabtp[$obj->rowid][$objmid->accountancy_code] = isset($tabtp[$obj->rowid][$objmid->accountancy_code]) ? $tabtp[$obj->rowid][$objmid->accountancy_code] + $amounttouse : $amounttouse;
499 } elseif ($links[$key][
'type'] ==
'payment_donation') {
500 $paymentdonstatic->id = $links[$key][
'url_id'];
501 $paymentdonstatic->ref = (string) $links[$key][
'url_id'];
502 $paymentdonstatic->fk_donation = $links[$key][
'url_id'];
503 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentdonstatic->getNomUrl(2);
504 $tabpay[$obj->rowid][
"paymentdonationid"] = $paymentdonstatic->id;
505 $tabtp[$obj->rowid][$account_pay_donation] = isset($tabtp[$obj->rowid][$account_pay_donation]) ? $tabtp[$obj->rowid][$account_pay_donation] + $amounttouse : $amounttouse;
506 } elseif ($links[$key][
'type'] ==
'member') {
507 $paymentsubscriptionstatic->id = $links[$key][
'url_id'];
508 $paymentsubscriptionstatic->ref = (string) $links[$key][
'url_id'];
509 $paymentsubscriptionstatic->label = $links[$key][
'label'];
510 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentsubscriptionstatic->getNomUrl(2);
511 $tabpay[$obj->rowid][
"paymentsubscriptionid"] = $paymentsubscriptionstatic->id;
512 $paymentsubscriptionstatic->fetch($paymentsubscriptionstatic->id);
513 $tabtp[$obj->rowid][$account_pay_subscription] = isset($tabtp[$obj->rowid][$account_pay_subscription]) ? $tabtp[$obj->rowid][$account_pay_subscription] + $amounttouse : $amounttouse;
514 } elseif ($links[$key][
'type'] ==
'payment_vat') {
515 $paymentvatstatic->id = $links[$key][
'url_id'];
516 $paymentvatstatic->ref = (string) $links[$key][
'url_id'];
517 $paymentvatstatic->label = $links[$key][
'label'];
518 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentvatstatic->getNomUrl(2);
519 $tabpay[$obj->rowid][
"paymentvatid"] = $paymentvatstatic->id;
520 $tabtp[$obj->rowid][$account_pay_vat] = isset($tabtp[$obj->rowid][$account_pay_vat]) ? $tabtp[$obj->rowid][$account_pay_vat] + $amounttouse : $amounttouse;
521 } elseif ($links[$key][
'type'] ==
'payment_salary') {
522 $paymentsalstatic->id = $links[$key][
'url_id'];
523 $paymentsalstatic->ref = (string) $links[$key][
'url_id'];
524 $paymentsalstatic->label = $links[$key][
'label'];
525 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentsalstatic->getNomUrl(2);
526 $tabpay[$obj->rowid][
"paymentsalid"] = $paymentsalstatic->id;
530 if (
getDolGlobalString(
'ACCOUNTANCY_AUTOFIX_MISSING_LINK_TO_USER_ON_SALARY_BANK_PAYMENT')) {
531 $tmpsalary =
new Salary($db);
532 $tmpsalary->fetch($paymentsalstatic->id);
533 $tmpsalary->fetch_user($tmpsalary->fk_user);
535 $userstatic->id = $tmpsalary->user->id;
536 $userstatic->name = $tmpsalary->user->name;
537 $userstatic->email = $tmpsalary->user->email;
538 $userstatic->firstname = $tmpsalary->user->firstname;
539 $userstatic->lastname = $tmpsalary->user->lastname;
540 $userstatic->status = $tmpsalary->user->status;
541 $userstatic->accountancy_code = $tmpsalary->user->accountancy_code;
543 if ($userstatic->id > 0) {
544 $tabpay[$obj->rowid][
"soclib"] = $userstatic->getNomUrl(1,
'accountancy', 0);
546 $tabpay[$obj->rowid][
"soclib"] =
'???';
549 if (empty($obj->typeop_user)) {
550 $accountancy_code_user_general = (!empty($obj->accountancy_code_user_general)) ? $obj->accountancy_code_user_general : $account_employee;
551 $compta_user = $userstatic->accountancy_code;
553 $tabtp[$obj->rowid][$compta_user] += $amounttouse;
554 $tabuser[$obj->rowid] = array(
555 'id' => $userstatic->id,
557 'lastname' => $userstatic->lastname,
558 'firstname' => $userstatic->firstname,
559 'email' => $userstatic->email,
560 'accountancy_code_general' => $accountancy_code_user_general,
561 'accountancy_code' => $compta_user,
562 'status' => $userstatic->status
567 } elseif ($links[$key][
'type'] ==
'payment_expensereport') {
568 $paymentexpensereportstatic->id = $links[$key][
'url_id'];
569 $tabpay[$obj->rowid][
"lib"] .= $paymentexpensereportstatic->getNomUrl(2);
570 $tabpay[$obj->rowid][
"paymentexpensereport"] = $paymentexpensereportstatic->id;
571 } elseif ($links[$key][
'type'] ==
'payment_various') {
572 $paymentvariousstatic->id = $links[$key][
'url_id'];
573 $paymentvariousstatic->ref = (string) $links[$key][
'url_id'];
574 $paymentvariousstatic->label = $links[$key][
'label'];
575 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentvariousstatic->getNomUrl(2);
576 $tabpay[$obj->rowid][
"paymentvariousid"] = $paymentvariousstatic->id;
577 $paymentvariousstatic->fetch($paymentvariousstatic->id);
578 $account_various = (!empty($paymentvariousstatic->accountancy_code) ? $paymentvariousstatic->accountancy_code :
'NotDefined');
579 $account_subledger = (!empty($paymentvariousstatic->subledger_account) ? $paymentvariousstatic->subledger_account :
'');
580 $tabpay[$obj->rowid][
"account_various"] = $account_various;
581 $tabtp[$obj->rowid][$account_subledger] = isset($tabtp[$obj->rowid][$account_subledger]) ? $tabtp[$obj->rowid][$account_subledger] + $amounttouse : $amounttouse;
582 } elseif ($links[$key][
'type'] ==
'payment_loan') {
583 $paymentloanstatic->id = $links[$key][
'url_id'];
584 $paymentloanstatic->ref = (string) $links[$key][
'url_id'];
585 $paymentloanstatic->fk_loan = $links[$key][
'url_id'];
586 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentloanstatic->getNomUrl(2);
587 $tabpay[$obj->rowid][
"paymentloanid"] = $paymentloanstatic->id;
589 $sqlmid =
'SELECT pl.amount_capital, pl.amount_insurance, pl.amount_interest, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest';
590 $sqlmid .=
' FROM '.MAIN_DB_PREFIX.
'payment_loan as pl, '.MAIN_DB_PREFIX.
'loan as l';
591 $sqlmid .=
' WHERE l.rowid = pl.fk_loan AND pl.fk_bank = '.((int) $obj->rowid);
593 dol_syslog(
"accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);
594 $resultmid = $db->query($sqlmid);
596 $objmid = $db->fetch_object($resultmid);
597 $tabtp[$obj->rowid][$objmid->accountancy_account_capital] = isset($objmid->amount_capital) ? $tabtp[$obj->rowid][$objmid->accountancy_account_capital] - $objmid->amount_capital : 0;
598 $tabtp[$obj->rowid][$objmid->accountancy_account_insurance] = isset($objmid->amount_insurance) ? $tabtp[$obj->rowid][$objmid->accountancy_account_insurance] - $objmid->amount_insurance : 0;
599 $tabtp[$obj->rowid][$objmid->accountancy_account_interest] = isset($objmid->amount_interest) ? $tabtp[$obj->rowid][$objmid->accountancy_account_interest] - $objmid->amount_interest : 0;
601 } elseif ($links[$key][
'type'] ==
'banktransfert') {
602 $accountLinestatic->fetch($links[$key][
'url_id']);
603 $tabpay[$obj->rowid][
"lib"] .=
' '.$langs->trans(
"BankTransfer").
'- '.$accountLinestatic ->getNomUrl(1);
604 $tabtp[$obj->rowid][$account_transfer] = isset($tabtp[$obj->rowid][$account_transfer]) ? $tabtp[$obj->rowid][$account_transfer] + $amounttouse : $amounttouse;
605 $bankaccountstatic->fetch($tabpay[$obj->rowid][
'fk_bank_account']);
606 $tabpay[$obj->rowid][
"soclib"] = $bankaccountstatic->getNomUrl(2);
611 if (empty($tabbq[$obj->rowid][$compta_bank])) {
612 $tabbq[$obj->rowid][$compta_bank] = $amounttouse;
614 $tabbq[$obj->rowid][$compta_bank] += $amounttouse;
619 if (empty($tabtp[$obj->rowid]) && !empty($tabmoreinfo[$obj->rowid][
'withdraw'])) {
620 foreach ($links as $key => $val) {
621 if ($links[$key][
'type'] ==
'payment') {
623 $tmppayment->fetch($links[$key][
'url_id']);
624 $arrayofamounts = $tmppayment->getAmountsArray();
625 if (is_array($arrayofamounts)) {
626 foreach ($arrayofamounts as $invoiceid => $amount) {
627 $tmpinvoice->fetch($invoiceid);
628 $tmpinvoice->fetch_thirdparty();
629 if ($tmpinvoice->thirdparty->code_compta_client) {
630 $tabtp[$obj->rowid][$tmpinvoice->thirdparty->code_compta_client] += $amount;
639 if (empty($tabtp[$obj->rowid])) {
640 $tabtp[$obj->rowid][
'NotDefined'] = $tabbq[$obj->rowid][$compta_bank];
652if (!$error && $action ==
'writebookkeeping' && $user->hasRight(
'accounting',
'bind',
'write')) {
656 $accountingaccountcustomer->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'),
true);
659 $accountingaccountsupplier->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUPPLIER'),
true);
662 $accountingaccountpayment->fetch(0,
getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT'),
true);
665 $accountingaccountexpensereport->fetch(0,
$conf->global->ACCOUNTING_ACCOUNT_EXPENSEREPORT,
true);
668 $accountingaccountsuspense->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUSPENSE'),
true);
671 foreach ($tabpay as $key => $val) {
686 if (!$errorforline && is_array($tabbq[$key])) {
688 foreach ($tabbq[$key] as $k => $mt) {
690 if (empty(
$conf->cache[
'accountingaccountincurrententity'][$k])) {
692 $accountingaccount->fetch(0, $k,
true);
693 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
695 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity'][$k];
698 $account_label = $accountingaccount->label;
701 if (!empty($val[
'lib'])) {
705 if (!empty($val[
'soclib'])) {
706 $reflabel .=
" - ".dol_string_nohtmltag($val[
'soclib']);
710 $bookkeeping->doc_date = $val[
"date"];
711 $bookkeeping->doc_ref = $ref;
712 $bookkeeping->doc_type =
'bank';
713 $bookkeeping->fk_doc = $key;
714 $bookkeeping->fk_docdet = $val[
"fk_bank"];
716 $bookkeeping->numero_compte = $k;
717 $bookkeeping->label_compte = $account_label;
719 $bookkeeping->label_operation = $reflabel;
720 $bookkeeping->montant = $mt;
721 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
722 $bookkeeping->debit = ($mt >= 0 ? $mt : 0);
723 $bookkeeping->credit = ($mt < 0 ? -$mt : 0);
724 $bookkeeping->code_journal = $journal;
725 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
726 $bookkeeping->fk_user_author = $user->id;
727 $bookkeeping->date_creation = $now;
730 $bookkeeping->subledger_account =
'';
731 $bookkeeping->label_operation = $reflabel;
732 $bookkeeping->entity =
$conf->entity;
734 $totaldebit += $bookkeeping->debit;
735 $totalcredit += $bookkeeping->credit;
737 $result = $bookkeeping->create($user);
739 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
742 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded',
null,
'warnings');
754 if (!$errorforline) {
755 if (is_array($tabtp[$key])) {
757 foreach ($tabtp[$key] as $k => $mt) {
762 if (!empty($val[
'lib'])) {
765 if ($tabtype[$key] ==
'banktransfert') {
766 $reflabel .=
dol_string_nohtmltag($langs->transnoentitiesnoconv(
'TransitionalAccount').
' '.$account_transfer);
772 $bookkeeping->doc_date = $val[
"date"];
773 $bookkeeping->doc_ref = $ref;
774 $bookkeeping->doc_type =
'bank';
775 $bookkeeping->fk_doc = $key;
776 $bookkeeping->fk_docdet = $val[
"fk_bank"];
778 $bookkeeping->label_operation = $reflabel;
779 $bookkeeping->montant = $mt;
780 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
781 $bookkeeping->debit = ($mt < 0 ? -$mt : 0);
782 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
783 $bookkeeping->code_journal = $journal;
784 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
785 $bookkeeping->fk_user_author = $user->id;
786 $bookkeeping->date_creation = $now;
788 if ($tabtype[$key] ==
'payment') {
790 $bookkeeping->subledger_account = $k;
791 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
792 $bookkeeping->numero_compte = $tabcompany[$key][
'accountancy_code_general'];
793 $bookkeeping->label_compte = $accountingaccountcustomer->label;
794 } elseif ($tabtype[$key] ==
'payment_supplier') {
796 $bookkeeping->subledger_account = $k;
797 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
798 $bookkeeping->numero_compte = $tabcompany[$key][
'accountancy_code_general'];
799 $bookkeeping->label_compte = $accountingaccountsupplier->label;
800 } elseif ($tabtype[$key] ==
'payment_expensereport') {
801 $bookkeeping->subledger_account = $tabuser[$key][
'accountancy_code'];
802 $bookkeeping->subledger_label = $tabuser[$key][
'name'];
804 $bookkeeping->label_compte = $accountingaccountexpensereport->label;
805 } elseif ($tabtype[$key] ==
'payment_salary') {
806 $bookkeeping->subledger_account = $tabuser[$key][
'accountancy_code'];
807 $bookkeeping->subledger_label = $tabuser[$key][
'name'];
808 $bookkeeping->numero_compte = $tabuser[$key][
'accountancy_code_general'];
809 $bookkeeping->label_compte = $accountingaccountpayment->label;
810 } elseif (in_array($tabtype[$key], array(
'sc',
'payment_sc'))) {
811 $bookkeeping->subledger_account =
'';
812 $bookkeeping->subledger_label =
'';
813 $accountingaccount->fetch(0, $k,
true);
814 $bookkeeping->numero_compte = $k;
815 $bookkeeping->label_compte = $accountingaccount->label;
816 } elseif ($tabtype[$key] ==
'payment_vat') {
817 $bookkeeping->subledger_account =
'';
818 $bookkeeping->subledger_label =
'';
819 $accountingaccount->fetch(0, $k,
true);
820 $bookkeeping->numero_compte = $k;
821 $bookkeeping->label_compte = $accountingaccount->label;
822 } elseif ($tabtype[$key] ==
'payment_donation') {
823 $bookkeeping->subledger_account =
'';
824 $bookkeeping->subledger_label =
'';
825 $accountingaccount->fetch(0, $k,
true);
826 $bookkeeping->numero_compte = $k;
827 $bookkeeping->label_compte = $accountingaccount->label;
828 } elseif ($tabtype[$key] ==
'member') {
829 $bookkeeping->subledger_account =
'';
830 $bookkeeping->subledger_label =
'';
831 $accountingaccount->fetch(0, $k,
true);
832 $bookkeeping->numero_compte = $k;
833 $bookkeeping->label_compte = $accountingaccount->label;
834 } elseif ($tabtype[$key] ==
'payment_loan') {
835 $bookkeeping->subledger_account =
'';
836 $bookkeeping->subledger_label =
'';
837 $accountingaccount->fetch(0, $k,
true);
838 $bookkeeping->numero_compte = $k;
839 $bookkeeping->label_compte = $accountingaccount->label;
840 } elseif ($tabtype[$key] ==
'payment_various') {
841 $bookkeeping->subledger_account = $k;
842 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
843 $accountingaccount->fetch(0, $tabpay[$key][
"account_various"],
true);
844 $bookkeeping->numero_compte = $tabpay[$key][
"account_various"];
845 $bookkeeping->label_compte = $accountingaccount->label;
846 } elseif ($tabtype[$key] ==
'banktransfert') {
847 $bookkeeping->subledger_account =
'';
848 $bookkeeping->subledger_label =
'';
849 $accountingaccount->fetch(0, $k,
true);
850 $bookkeeping->numero_compte = $k;
851 $bookkeeping->label_compte = $accountingaccount->label;
853 if ($tabtype[$key] ==
'unknown') {
855 $bookkeeping->subledger_account =
'';
856 $bookkeeping->subledger_label =
'';
858 $bookkeeping->label_compte = $accountingaccountsuspense->label;
861 $bookkeeping->label_operation = $reflabel;
862 $bookkeeping->entity =
$conf->entity;
864 $totaldebit += $bookkeeping->debit;
865 $totalcredit += $bookkeeping->credit;
867 $result = $bookkeeping->create($user);
869 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
872 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded',
null,
'warnings');
880 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/lettering.class.php';
882 $nb_lettering = $lettering_static->bookkeepingLetteringAll(array($bookkeeping->id));
888 foreach ($tabbq[$key] as $k => $mt) {
891 if (!empty($val[
'lib'])) {
897 $bookkeeping->doc_date = $val[
"date"];
898 $bookkeeping->doc_ref = $ref;
899 $bookkeeping->doc_type =
'bank';
900 $bookkeeping->fk_doc = $key;
901 $bookkeeping->fk_docdet = $val[
"fk_bank"];
902 $bookkeeping->montant = $mt;
903 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
904 $bookkeeping->debit = ($mt < 0 ? -$mt : 0);
905 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
906 $bookkeeping->code_journal = $journal;
907 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
908 $bookkeeping->fk_user_author = $user->id;
909 $bookkeeping->date_creation = $now;
910 $bookkeeping->label_compte =
'';
911 $bookkeeping->label_operation = $reflabel;
912 $bookkeeping->entity =
$conf->entity;
914 $totaldebit += $bookkeeping->debit;
915 $totalcredit += $bookkeeping->credit;
917 $result = $bookkeeping->create($user);
920 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
923 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded',
null,
'warnings');
938 setEventMessages(
'We tried to insert a non balanced transaction in book for '.$ref.
'. Canceled. Surely a bug.',
null,
'errors');
941 if (!$errorforline) {
948 if ($error >= $MAXNBERRORS) {
949 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped").
' (>'.$MAXNBERRORS.
')',
null,
'errors');
955 if (empty($error) && count($tabpay) > 0) {
957 } elseif (count($tabpay) == $error) {
960 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
966 if (count($tabpay) != $error) {
967 $param =
'id_journal='.$id_journal;
968 $param .=
'&date_startday='.$date_startday;
969 $param .=
'&date_startmonth='.$date_startmonth;
970 $param .=
'&date_startyear='.$date_startyear;
971 $param .=
'&date_endday='.$date_endday;
972 $param .=
'&date_endmonth='.$date_endmonth;
973 $param .=
'&date_endyear='.$date_endyear;
974 $param .=
'&in_bookkeeping='.$in_bookkeeping;
975 header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
983if ($action ==
'exportcsv' && $user->hasRight(
'accounting',
'bind',
'write')) {
986 $filename =
'journal';
987 $type_export =
'journal';
988 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
991 print
'"'.$langs->transnoentitiesnoconv(
"BankId").
'"'.$sep;
992 print
'"'.$langs->transnoentitiesnoconv(
"Date").
'"'.$sep;
993 print
'"'.$langs->transnoentitiesnoconv(
"PaymentMode").
'"'.$sep;
994 print
'"'.$langs->transnoentitiesnoconv(
"AccountAccounting").
'"'.$sep;
995 print
'"'.$langs->transnoentitiesnoconv(
"SubledgerAccount").
'"'.$sep;
996 print
'"'.$langs->transnoentitiesnoconv(
"Label").
'"'.$sep;
997 print
'"'.$langs->transnoentitiesnoconv(
"AccountingDebit").
'"'.$sep;
998 print
'"'.$langs->transnoentitiesnoconv(
"AccountingCredit").
'"'.$sep;
999 print
'"'.$langs->transnoentitiesnoconv(
"Journal").
'"'.$sep;
1000 print
'"'.$langs->transnoentitiesnoconv(
"Note").
'"'.$sep;
1003 foreach ($tabpay as $key => $val) {
1009 foreach ($tabbq[$key] as $k => $mt) {
1012 if (!empty($val[
'lib'])) {
1016 if (!empty($val[
'soclib'])) {
1017 $reflabel .=
" - ".dol_string_nohtmltag($val[
'soclib']);
1020 print
'"'.$key.
'"'.$sep;
1021 print
'"'.$date.
'"'.$sep;
1022 print
'"'.$val[
"type_payment"].
'"'.$sep;
1023 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1025 print
'"'.$reflabel.
'"'.$sep;
1026 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1027 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1028 print
'"'.$journal.
'"'.$sep;
1029 print
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
1035 if (is_array($tabtp[$key])) {
1036 foreach ($tabtp[$key] as $k => $mt) {
1039 if (!empty($val[
'lib'])) {
1042 if ($tabtype[$key] ==
'banktransfert') {
1043 $reflabel .=
dol_string_nohtmltag($langs->transnoentitiesnoconv(
'TransitionalAccount').
' '.$account_transfer);
1048 print
'"'.$key.
'"'.$sep;
1049 print
'"'.$date.
'"'.$sep;
1050 print
'"'.$val[
"type_payment"].
'"'.$sep;
1051 if ($tabtype[$key] ==
'payment_supplier') {
1052 $account_ledger = (!empty($obj->accountancy_code_supplier_general)) ? $obj->accountancy_code_supplier_general : $account_supplier;
1053 print
'"'.length_accountg($account_ledger).
'"'.$sep;
1054 } elseif ($tabtype[$key] ==
'payment') {
1055 $account_ledger = (!empty($obj->accountancy_code_customer_general)) ? $obj->accountancy_code_customer_general : $account_customer;
1056 print
'"'.length_accountg($account_ledger).
'"'.$sep;
1057 } elseif ($tabtype[$key] ==
'payment_expensereport') {
1058 print
'"'.length_accountg(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_EXPENSEREPORT')).
'"'.$sep;
1059 } elseif ($tabtype[$key] ==
'payment_salary') {
1060 $account_ledger = (!empty($obj->accountancy_code_user_general)) ? $obj->accountancy_code_user_general : $account_employee;
1061 print
'"'.length_accountg($account_ledger).
'"'.$sep;
1063 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1065 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
1066 print
'"'.$reflabel.
'"'.$sep;
1067 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1068 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1069 print
'"'.$journal.
'"'.$sep;
1070 print
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
1075 foreach ($tabbq[$key] as $k => $mt) {
1078 if (!empty($val[
'lib'])) {
1083 print
'"'.$key.
'"'.$sep;
1084 print
'"'.$date.
'"'.$sep;
1085 print
'"'.$val[
"type_payment"].
'"'.$sep;
1086 print
'"'.length_accountg(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUSPENSE')).
'"'.$sep;
1088 print
'"'.$reflabel.
'"'.$sep;
1089 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1090 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1091 print
'"'.$journal.
'"'.$sep;
1092 print
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
1105$form =
new Form($db);
1107if (empty($action) || $action ==
'view') {
1108 $invoicestatic =
new Facture($db);
1111 $vatstatic =
new Tva($db);
1112 $donationstatic =
new Don($db);
1113 $loanstatic =
new Loan($db);
1114 $salarystatic =
new Salary($db);
1117 $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1,
'', 1);
1118 $help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
1124 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
1126 $listofchoices = array(
1127 'notyet' => $langs->trans(
"NotYetInGeneralLedger"),
1128 'already' => $langs->trans(
"AlreadyInGeneralLedger")
1130 $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);
1131 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
1133 $varlink =
'id_journal='.$id_journal;
1137 $listofchoices = array(
1138 1 => $langs->trans(
"TransfertAllBankLines"),
1139 2 => $langs->trans(
"TransfertOnlyConciliatedBankLine")
1141 $moreoptions = [
"BankLineConciliated" => $form->selectarray(
'only_rappro', $listofchoices, $only_rappro)];
1143 journalHead($nom,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink, $moreoptions);
1150 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_fiscalyear WHERE entity = ".((int)
$conf->entity);
1151 $resql = $db->query($sql);
1153 $obj = $db->fetch_object($resql);
1154 if ($obj->nb == 0) {
1155 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheFiscalPeriodIsNotDefined");
1156 $desc =
' : '.$langs->trans(
"AccountancyAreaDescFiscalPeriod", 4,
'{link}');
1157 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"FiscalPeriod").
'</strong>', $desc);
1167 $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";
1168 $resql = $db->query($sql);
1170 $obj = $db->fetch_object($resql);
1172 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheJournalCodeIsNotDefinedOnSomeBankAccount");
1173 $desc =
' : '.$langs->trans(
"AccountancyAreaDescBank", 6,
'{link}');
1174 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"BankAccounts").
'</strong>', $desc);
1190 print($desc ?
'' :
'<br>').
'<div class="warning">'.
img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
1191 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
1192 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
1198 print
'<br><div class="tabsAction tabsActionNoBottom centerimp">';
1200 if (
getDolGlobalString(
'ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping ==
'notyet') {
1201 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
1206 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
1208 if ($in_bookkeeping ==
'notyet') {
1209 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
1211 print
'<a class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
1219 <script type="text/javascript">
1220 function launch_export() {
1221 console.log("Set value into form and submit");
1222 $("div.fiche form input[name=\"action\"]").val("exportcsv");
1223 $("div.fiche form input[type=\"submit\"]").click();
1224 $("div.fiche form input[name=\"action\"]").val("");
1226 function writebookkeeping() {
1227 console.log("Set value into form and submit");
1228 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
1229 $("div.fiche form input[type=\"submit\"]").click();
1230 $("div.fiche form input[name=\"action\"]").val("");
1240 print
'<div class="div-table-responsive">';
1241 print
'<table class="noborder centpercent">';
1242 print
'<tr class="liste_titre">';
1243 print
"<td>".$langs->trans(
"Date").
"</td>";
1244 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"ObjectsRef").
")</td>";
1245 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
1246 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
1247 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
1248 print
'<td class="center">'.$langs->trans(
"PaymentMode").
"</td>";
1249 print
'<td class="right">'.$langs->trans(
"AccountingDebit").
"</td>";
1250 print
'<td class="right">'.$langs->trans(
"AccountingCredit").
"</td>";
1255 foreach ($tabpay as $key => $val) {
1261 foreach ($tabbq[$key] as $k => $mt) {
1264 if (!empty($val[
'lib'])) {
1265 $reflabel .= $val[
'lib'].
" - ";
1267 $reflabel .= $langs->trans(
"Bank").
' '.$val[
'bank_account_ref'];
1268 if (!empty($val[
'soclib'])) {
1269 $reflabel .=
" - ".$val[
'soclib'];
1273 print
'<!-- Bank bank.rowid='.$key.
' type='.$tabpay[$key][
'type'].
' ref='.$tabpay[$key][
'ref'].
'-->';
1274 print
'<tr class="oddeven">';
1277 print
"<td>".$date.
"</td>";
1280 print
"<td>".dol_escape_htmltag($ref).
"</td>";
1284 if (empty($accounttoshow) || $accounttoshow ==
'NotDefined') {
1285 $accounttoshow =
'<span class="error">'.$langs->trans(
"BankAccountNotDefined").
'</span>';
1287 print
'<td class="maxwidth300" title="'.dol_escape_htmltag(
dol_string_nohtmltag($accounttoshow)).
'">';
1288 print $accounttoshow;
1292 print
'<td class="maxwidth300">';
1306 print
'<td class="center">'.$val[
"type_payment"].
"</td>";
1307 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1308 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1316 if (is_array($tabtp[$key])) {
1317 foreach ($tabtp[$key] as $k => $mt) {
1320 if (!empty($val[
'lib'])) {
1321 $reflabel .= $val[
'lib'].(isset($val[
'soclib']) ?
" - " :
"");
1323 if ($tabtype[$key] ==
'banktransfert') {
1324 $reflabel .= $langs->trans(
'TransitionalAccount').
' '.$account_transfer;
1326 $reflabel .= isset($val[
'soclib']) ? $val[
'soclib'] :
"";
1329 print
'<!-- Thirdparty bank.rowid='.$key.
' -->';
1330 print
'<tr class="oddeven">';
1333 print
"<td>".$date.
"</td>";
1336 print
"<td>".dol_escape_htmltag($ref).
"</td>";
1340 $account_ledger = $k;
1342 if ($tabtype[$key] ==
'payment') {
1343 $account_ledger = (!empty($obj->accountancy_code_customer_general)) ? $obj->accountancy_code_customer_general : $account_customer;
1345 if ($tabtype[$key] ==
'payment_supplier') {
1346 $account_ledger = (!empty($obj->accountancy_code_supplier_general)) ? $obj->accountancy_code_supplier_general : $account_supplier;
1348 if ($tabtype[$key] ==
'payment_expensereport') {
1351 if ($tabtype[$key] ==
'payment_salary') {
1352 $account_ledger = (!empty($obj->accountancy_code_user_general)) ? $obj->accountancy_code_user_general : $account_employee;
1354 if ($tabtype[$key] ==
'payment_vat') {
1357 if ($tabtype[$key] ==
'member') {
1360 if ($tabtype[$key] ==
'payment_various') {
1361 $account_ledger = $tabpay[$key][
"account_various"];
1364 if (empty($accounttoshow) || $accounttoshow ==
'NotDefined') {
1365 if ($tabtype[$key] ==
'unknown') {
1368 $accounttoshow =
'<span class="error small">'.$langs->trans(
'UnknownAccountForThirdpartyAndWaitingAccountNotDefinedBlocking').
'</span>';
1370 $accounttoshow =
'<span class="warning small">'.$langs->trans(
'UnknownAccountForThirdparty',
length_accountg(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUSPENSE'))).
'</span>';
1374 $errorstring =
'UnknownAccountForThirdpartyBlocking';
1375 if ($tabtype[$key] ==
'payment') {
1376 $errorstring =
'MainAccountForCustomersNotDefined';
1378 if ($tabtype[$key] ==
'payment_supplier') {
1379 $errorstring =
'MainAccountForSuppliersNotDefined';
1381 if ($tabtype[$key] ==
'payment_expensereport') {
1382 $errorstring =
'MainAccountForUsersNotDefined';
1384 if ($tabtype[$key] ==
'payment_salary') {
1385 $errorstring =
'MainAccountForUsersNotDefined';
1387 if ($tabtype[$key] ==
'payment_vat') {
1388 $errorstring =
'MainAccountForVatPaymentNotDefined';
1390 if ($tabtype[$key] ==
'member') {
1391 $errorstring =
'MainAccountForSubscriptionPaymentNotDefined';
1393 $accounttoshow =
'<span class="error small">'.$langs->trans($errorstring).
'</span>';
1396 print
'<td class="maxwidth300" title="'.dol_escape_htmltag(
dol_string_nohtmltag($accounttoshow)).
'">';
1397 print $accounttoshow;
1401 $accounttoshowsubledger =
'';
1402 if (in_array($tabtype[$key], array(
'payment',
'payment_supplier',
'payment_expensereport',
'payment_salary',
'payment_various'))) {
1404 if ($accounttoshow != $accounttoshowsubledger) {
1405 if (empty($accounttoshowsubledger) || $accounttoshowsubledger ==
'NotDefined') {
1407 if (!empty($tabcompany[$key][
'code_compta'])) {
1408 if (in_array($tabtype[$key], array(
'payment_various',
'payment_salary'))) {
1410 $accounttoshowsubledger =
'<span class="warning small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknownSubledgerIgnored").
'</span>';
1412 $accounttoshowsubledger =
'<span class="warning small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknown", $tabcompany[$key][
'code_compta']).
'</span>';
1415 $accounttoshowsubledger =
'<span class="error small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknownBlocking").
'</span>';
1419 $accounttoshowsubledger =
'';
1422 print
'<td class="maxwidth300">';
1423 print $accounttoshowsubledger;
1426 print
"<td>".$reflabel.
"</td>";
1428 print
'<td class="center">'.$val[
"type_payment"].
"</td>";
1430 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1432 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1440 foreach ($tabbq[$key] as $k => $mt) {
1443 if (!empty($val[
'lib'])) {
1444 $reflabel .= $val[
'lib'].
" - ";
1446 $reflabel .=
'WaitingAccount';
1448 print
'<!-- Wait bank.rowid='.$key.
' -->';
1449 print
'<tr class="oddeven">';
1450 print
"<td>".$date.
"</td>";
1451 print
"<td>".$ref.
"</td>";
1464 print
"<td>".dol_escape_htmltag($reflabel).
"</td>";
1465 print
'<td class="center">'.$val[
"type_payment"].
"</td>";
1466 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1467 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1478 print
'<tr class="oddeven"><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
1505 if ($ref ==
'(SupplierInvoicePayment)' || $ref ==
'(SupplierInvoicePaymentBack)') {
1506 $ref = $langs->transnoentitiesnoconv(
'Supplier');
1508 if ($ref ==
'(CustomerInvoicePayment)' || $ref ==
'(CustomerInvoicePaymentBack)') {
1509 $ref = $langs->transnoentitiesnoconv(
'Customer');
1511 if ($ref ==
'(SocialContributionPayment)') {
1512 $ref = $langs->transnoentitiesnoconv(
'SocialContribution');
1514 if ($ref ==
'(DonationPayment)') {
1515 $ref = $langs->transnoentitiesnoconv(
'Donation');
1517 if ($ref ==
'(SubscriptionPayment)') {
1518 $ref = $langs->transnoentitiesnoconv(
'Subscription');
1520 if ($ref ==
'(ExpenseReportPayment)') {
1521 $ref = $langs->transnoentitiesnoconv(
'Employee');
1523 if ($ref ==
'(LoanPayment)') {
1524 $ref = $langs->transnoentitiesnoconv(
'Loan');
1526 if ($ref ==
'(payment_salary)') {
1527 $ref = $langs->transnoentitiesnoconv(
'Employee');
1531 if ($typerecord ==
'payment') {
1533 $sqlmid =
"SELECT payfac.fk_facture as id, ".$db->ifsql(
'f1.rowid IS NULL',
'f.ref',
'f1.ref').
" as ref";
1534 $sqlmid .=
" FROM ".$db->prefix().
"paiement_facture as payfac";
1535 $sqlmid .=
" LEFT JOIN ".$db->prefix().
"facture as f ON f.rowid = payfac.fk_facture";
1536 $sqlmid .=
" LEFT JOIN ".$db->prefix().
"societe_remise_except as sre ON sre.fk_facture_source = payfac.fk_facture";
1537 $sqlmid .=
" LEFT JOIN ".$db->prefix().
"facture as f1 ON f1.rowid = sre.fk_facture";
1538 $sqlmid .=
" WHERE payfac.fk_paiement=".((int) $val[
'paymentid']);
1540 $sqlmid =
"SELECT payfac.fk_facture as id, f.ref as ref";
1541 $sqlmid .=
" FROM ".$db->prefix().
"paiement_facture as payfac";
1542 $sqlmid .=
" INNER JOIN ".$db->prefix().
"facture as f ON f.rowid = payfac.fk_facture";
1543 $sqlmid .=
" WHERE payfac.fk_paiement=".((int) $val[
'paymentid']);
1545 $ref = $langs->transnoentitiesnoconv(
"Invoice");
1546 } elseif ($typerecord ==
'payment_supplier') {
1547 $sqlmid =
'SELECT payfac.fk_facturefourn as id, f.ref';
1548 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as payfac, ".MAIN_DB_PREFIX.
"facture_fourn as f";
1549 $sqlmid .=
" WHERE payfac.fk_facturefourn = f.rowid AND payfac.fk_paiementfourn=".((int) $val[
"paymentsupplierid"]);
1550 $ref = $langs->transnoentitiesnoconv(
"SupplierInvoice");
1551 } elseif ($typerecord ==
'payment_expensereport') {
1552 $sqlmid =
'SELECT e.rowid as id, e.ref';
1553 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_expensereport as pe, ".MAIN_DB_PREFIX.
"expensereport as e";
1554 $sqlmid .=
" WHERE pe.rowid=".((int) $val[
"paymentexpensereport"]).
" AND pe.fk_expensereport = e.rowid";
1555 $ref = $langs->transnoentitiesnoconv(
"ExpenseReport");
1556 } elseif ($typerecord ==
'payment_salary') {
1557 $sqlmid =
'SELECT s.rowid as ref';
1558 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as s";
1559 $sqlmid .=
" WHERE s.rowid=".((int) $val[
"paymentsalid"]);
1560 $ref = $langs->transnoentitiesnoconv(
"SalaryPayment");
1561 } elseif ($typerecord ==
'sc') {
1562 $sqlmid =
'SELECT sc.rowid as ref';
1563 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"paiementcharge as sc";
1564 $sqlmid .=
" WHERE sc.rowid=".((int) $val[
"paymentscid"]);
1565 $ref = $langs->transnoentitiesnoconv(
"SocialContribution");
1566 } elseif ($typerecord ==
'payment_vat') {
1567 $sqlmid =
'SELECT v.rowid as ref';
1568 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"tva as v";
1569 $sqlmid .=
" WHERE v.rowid=".((int) $val[
"paymentvatid"]);
1570 $ref = $langs->transnoentitiesnoconv(
"PaymentVat");
1571 } elseif ($typerecord ==
'payment_donation') {
1572 $sqlmid =
'SELECT payd.fk_donation as ref';
1573 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_donation as payd";
1574 $sqlmid .=
" WHERE payd.fk_donation=".((int) $val[
"paymentdonationid"]);
1575 $ref = $langs->transnoentitiesnoconv(
"Donation");
1576 } elseif ($typerecord ==
'payment_loan') {
1577 $sqlmid =
'SELECT l.rowid as ref';
1578 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_loan as l";
1579 $sqlmid .=
" WHERE l.rowid=".((int) $val[
"paymentloanid"]);
1580 $ref = $langs->transnoentitiesnoconv(
"LoanPayment");
1581 } elseif ($typerecord ==
'payment_various') {
1582 $sqlmid =
'SELECT v.rowid as ref';
1583 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_various as v";
1584 $sqlmid .=
" WHERE v.rowid=".((int) $val[
"paymentvariousid"]);
1585 $ref = $langs->transnoentitiesnoconv(
"VariousPayment");
1588 if (empty($sqlmid)) {
1589 dol_syslog(
"Found a typerecord=".$typerecord.
" not supported", LOG_WARNING);
1593 dol_syslog(
"accountancy/journal/bankjournal.php::sqlmid=".$sqlmid, LOG_DEBUG);
1594 $resultmid = $db->query($sqlmid);
1596 while ($objmid = $db->fetch_object($resultmid)) {
1597 $ref .=
' '.$objmid->ref;
1604 $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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.