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);
116if (empty($date_startmonth)) {
119 $date_start = $dates[
'date_start'];
120 $pastmonthyear = $dates[
'pastmonthyear'];
121 $pastmonth = $dates[
'pastmonth'];
123if (empty($date_endmonth)) {
126 $date_end = $dates[
'date_end'];
127 $pastmonthyear = $dates[
'pastmonthyear'];
128 $pastmonth = $dates[
'pastmonth'];
131if (!GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end))) {
136$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,";
137$sql .=
" ba.courant, ba.ref as baref, ba.account_number, ba.fk_accountancy_journal,";
138$sql .=
" soc.rowid as socid, soc.nom as name, soc.email as email, bu1.type as typeop_company,";
140 $sql .=
" spe.accountancy_code_customer as code_compta,";
141 $sql .=
" spe.accountancy_code_supplier as code_compta_fournisseur,";
143 $sql .=
" soc.code_compta,";
144 $sql .=
" soc.code_compta_fournisseur,";
146$sql .=
" u.accountancy_code, u.rowid as userid, u.lastname as lastname, u.firstname as firstname, u.email as useremail, u.statut as userstatus,";
147$sql .=
" bu2.type as typeop_user,";
148$sql .=
" bu3.type as typeop_payment, bu4.type as typeop_payment_supplier";
149$sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
150$sql .=
" JOIN ".MAIN_DB_PREFIX.
"bank_account as ba on b.fk_account=ba.rowid";
151$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'";
152$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON bu2.fk_bank = b.rowid AND bu2.type='user'";
153$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu3 ON bu3.fk_bank = b.rowid AND bu3.type='payment'";
154$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu4 ON bu4.fk_bank = b.rowid AND bu4.type='payment_supplier'";
155$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as soc on bu1.url_id=soc.rowid";
157 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = soc.rowid AND spe.entity = " . ((int) $conf->entity);
159$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on bu2.url_id=u.rowid";
160$sql .=
" WHERE ba.fk_accountancy_journal=".((int) $id_journal);
161$sql .=
' AND b.amount <> 0 AND ba.entity IN ('.getEntity(
'bank_account', 0).
')';
162if ($date_start && $date_end) {
163 $sql .=
" AND b.dateo >= '".$db->idate($date_start).
"' AND b.dateo <= '".$db->idate($date_end).
"'";
167 $sql .=
" AND b.dateo >= '".$db->idate(
getDolGlobalInt(
'ACCOUNTING_DATE_START_BINDING')).
"'";
170if ($in_bookkeeping ==
'already') {
171 $sql .=
" AND (b.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
173if ($in_bookkeeping ==
'notyet') {
174 $sql .=
" AND (b.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
176if ($only_rappro == 2) {
177 $sql .=
" AND (b.rappro = '1')";
179$sql .=
" ORDER BY b.datev";
185$societestatic =
new Societe($db);
186$userstatic =
new User($db);
187$bankaccountstatic =
new Account($db);
190$paymentvatstatic =
new Tva($db);
205$accountingjournalstatic->fetch($id_journal);
206$journal = $accountingjournalstatic->code;
207$journal_label = $accountingjournalstatic->label;
209$tabcompany = array();
215$tabmoreinfo = array();
218@phan-var-force array<array{id:mixed,name:mixed,code_compta:string,email:string}> $tabcompany
219@phan-var-force array<array{id:int,name:string,lastname:string,firstname:string,email:string,accountancy_code:string,status:int> $tabuser
220@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
221@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
225dol_syslog(
"accountancy/journal/bankjournal.php", LOG_DEBUG);
226$result = $db->query($sql);
228 $num = $db->num_rows($result);
234 $account_employee =
getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT',
'NotDefined');
235 $account_expensereport =
getDolGlobalString(
'ACCOUNTING_ACCOUNT_EXPENSEREPORT',
'NotDefined');
237 $account_pay_donation =
getDolGlobalString(
'DONATION_ACCOUNTINGACCOUNT',
'NotDefined');
238 $account_pay_subscription =
getDolGlobalString(
'ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT',
'NotDefined');
239 $account_transfer =
getDolGlobalString(
'ACCOUNTING_ACCOUNT_TRANSFER_CASH',
'NotDefined');
248 $obj = $db->fetch_object($result);
250 $lineisapurchase = -1;
253 if ($obj->label ==
'(SupplierInvoicePayment)' || $obj->label ==
'(SupplierInvoicePaymentBack)') {
254 $lineisapurchase = 1;
256 if ($obj->label ==
'(CustomerInvoicePayment)' || $obj->label ==
'(CustomerInvoicePaymentBack)') {
260 if ($lineisapurchase < 0) {
261 if ($obj->typeop_payment_supplier ==
'payment_supplier') {
262 $lineisapurchase = 1;
265 if ($lineisasale < 0) {
266 if ($obj->typeop_payment ==
'payment') {
274 $compta_bank = $obj->account_number;
277 $compta_soc =
'NotDefined';
278 if ($lineisapurchase > 0) {
279 $compta_soc = (($obj->code_compta_fournisseur !=
"") ? $obj->code_compta_fournisseur : $account_supplier);
281 if ($lineisasale > 0) {
282 $compta_soc = (!empty($obj->code_compta) ? $obj->code_compta : $account_customer);
285 $tabcompany[$obj->rowid] = array(
287 'name' => $obj->name,
288 'code_compta' => $compta_soc,
289 'email' => $obj->email
295 $compta_user = (!empty($obj->accountancy_code) ? $obj->accountancy_code :
'');
297 $tabuser[$obj->rowid] = array(
298 'id' => $obj->userid,
300 'lastname' => $obj->lastname,
301 'firstname' => $obj->firstname,
302 'email' => $obj->useremail,
303 'accountancy_code' => $compta_user,
304 'status' => $obj->userstatus
308 $tabpay[$obj->rowid][
"date"] = $db->jdate($obj->do);
309 $tabpay[$obj->rowid][
"type_payment"] = $obj->fk_type;
310 $tabpay[$obj->rowid][
"ref"] = $obj->label;
311 $tabpay[$obj->rowid][
"fk_bank"] = $obj->rowid;
312 $tabpay[$obj->rowid][
"bank_account_ref"] = $obj->baref;
313 $tabpay[$obj->rowid][
"fk_bank_account"] = $obj->fk_account;
315 if (preg_match(
'/^\((.*)\)$/i', $obj->label, $reg)) {
316 $tabpay[$obj->rowid][
"lib"] = $langs->trans($reg[1]);
318 $tabpay[$obj->rowid][
"lib"] =
dol_trunc($obj->label, 60);
322 $links =
$object->get_url($obj->rowid);
327 $tabpay[$obj->rowid][
'type'] =
'unknown';
328 $tabtype[$obj->rowid] =
'unknown';
329 $tabmoreinfo[$obj->rowid] = array();
331 $amounttouse = $obj->amount;
332 if (!empty($obj->amount_main_currency)) {
334 $amounttouse = $obj->amount_main_currency;
338 if (is_array($links) && count($links) > 0) {
343 $is_expensereport =
false;
344 foreach ($links as $v) {
345 if ($v[
'type'] ==
'sc') {
349 if ($v[
'type'] ==
'payment_salary') {
353 if ($v[
'type'] ==
'payment_expensereport') {
354 $is_expensereport =
true;
360 foreach ($links as $key => $val) {
361 if ($links[$key][
'type'] ==
'user' && !$is_sc && !$is_salary && !$is_expensereport) {
366 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'))) {
370 $tabpay[$obj->rowid][
'type'] = $links[$key][
'type'];
371 $tabtype[$obj->rowid] = $links[$key][
'type'];
382 if ($links[$key][
'type'] ==
'withdraw') {
383 $tabmoreinfo[$obj->rowid][
'withdraw'] = 1;
386 if ($links[$key][
'type'] ==
'payment') {
387 $paymentstatic->id = $links[$key][
'url_id'];
388 $paymentstatic->ref = $links[$key][
'url_id'];
389 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentstatic->getNomUrl(2,
'',
'');
390 $tabpay[$obj->rowid][
"paymentid"] = $paymentstatic->id;
391 } elseif ($links[$key][
'type'] ==
'payment_supplier') {
392 $paymentsupplierstatic->id = $links[$key][
'url_id'];
393 $paymentsupplierstatic->ref = $links[$key][
'url_id'];
394 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentsupplierstatic->getNomUrl(2);
395 $tabpay[$obj->rowid][
"paymentsupplierid"] = $paymentsupplierstatic->id;
396 } elseif ($links[$key][
'type'] ==
'company') {
397 $societestatic->id = $links[$key][
'url_id'];
398 $societestatic->name = $links[$key][
'label'];
399 $societestatic->email = $tabcompany[$obj->rowid][
'email'];
400 $tabpay[$obj->rowid][
"soclib"] = $societestatic->getNomUrl(1,
'', 30);
402 if (empty($tabtp[$obj->rowid][$compta_soc])) {
403 $tabtp[$obj->rowid][$compta_soc] = $amounttouse;
405 $tabtp[$obj->rowid][$compta_soc] += $amounttouse;
408 } elseif ($links[$key][
'type'] ==
'user') {
409 $userstatic->id = $links[$key][
'url_id'];
410 $userstatic->name = $links[$key][
'label'];
411 $userstatic->email = $tabuser[$obj->rowid][
'email'];
412 $userstatic->firstname = $tabuser[$obj->rowid][
'firstname'];
413 $userstatic->lastname = $tabuser[$obj->rowid][
'lastname'];
414 $userstatic->status = $tabuser[$obj->rowid][
'status'];
415 $userstatic->accountancy_code = $tabuser[$obj->rowid][
'accountancy_code'];
419 if ($userstatic->id > 0) {
421 $tabpay[$obj->rowid][
"soclib"] .=
' '.$userstatic->getNomUrl(1,
'accountancy', 0);
423 $tabpay[$obj->rowid][
"soclib"] = $userstatic->getNomUrl(1,
'accountancy', 0);
426 $tabpay[$obj->rowid][
"soclib"] =
'???';
433 $tabtp[$obj->rowid][$compta_user] += $amounttouse;
436 } elseif ($links[$key][
'type'] ==
'sc') {
437 $chargestatic->id = $links[$key][
'url_id'];
438 $chargestatic->ref = $links[$key][
'url_id'];
440 $tabpay[$obj->rowid][
"lib"] .=
' '.$chargestatic->getNomUrl(2);
442 if (preg_match(
'/^\((.*)\)$/i', $links[$key][
'label'], $reg)) {
443 if ($reg[1] ==
'socialcontribution') {
444 $reg[1] =
'SocialContribution';
446 $chargestatic->label = $langs->trans($reg[1]);
448 $chargestatic->label = $links[$key][
'label'];
450 $chargestatic->ref = $chargestatic->label;
451 $tabpay[$obj->rowid][
"soclib"] = $chargestatic->getNomUrl(1, 30);
452 $tabpay[$obj->rowid][
"paymentscid"] = $chargestatic->id;
456 $sqlmid =
"SELECT cchgsoc.accountancy_code";
457 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales cchgsoc";
458 $sqlmid .=
" INNER JOIN ".MAIN_DB_PREFIX.
"chargesociales as chgsoc ON chgsoc.fk_type = cchgsoc.id";
459 $sqlmid .=
" INNER JOIN ".MAIN_DB_PREFIX.
"paiementcharge as paycharg ON paycharg.fk_charge = chgsoc.rowid";
460 $sqlmid .=
" INNER JOIN ".MAIN_DB_PREFIX.
"bank_url as bkurl ON bkurl.url_id=paycharg.rowid AND bkurl.type = 'payment_sc'";
461 $sqlmid .=
" WHERE bkurl.fk_bank = ".((int) $obj->rowid);
463 dol_syslog(
"accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);
464 $resultmid = $db->query($sqlmid);
466 $objmid = $db->fetch_object($resultmid);
467 $tabtp[$obj->rowid][$objmid->accountancy_code] = isset($tabtp[$obj->rowid][$objmid->accountancy_code]) ? $tabtp[$obj->rowid][$objmid->accountancy_code] + $amounttouse : $amounttouse;
469 } elseif ($links[$key][
'type'] ==
'payment_donation') {
470 $paymentdonstatic->id = $links[$key][
'url_id'];
471 $paymentdonstatic->ref = $links[$key][
'url_id'];
472 $paymentdonstatic->fk_donation = $links[$key][
'url_id'];
473 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentdonstatic->getNomUrl(2);
474 $tabpay[$obj->rowid][
"paymentdonationid"] = $paymentdonstatic->id;
475 $tabtp[$obj->rowid][$account_pay_donation] = isset($tabtp[$obj->rowid][$account_pay_donation]) ? $tabtp[$obj->rowid][$account_pay_donation] + $amounttouse : $amounttouse;
476 } elseif ($links[$key][
'type'] ==
'member') {
477 $paymentsubscriptionstatic->id = $links[$key][
'url_id'];
478 $paymentsubscriptionstatic->ref = $links[$key][
'url_id'];
479 $paymentsubscriptionstatic->label = $links[$key][
'label'];
480 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentsubscriptionstatic->getNomUrl(2);
481 $tabpay[$obj->rowid][
"paymentsubscriptionid"] = $paymentsubscriptionstatic->id;
482 $paymentsubscriptionstatic->fetch($paymentsubscriptionstatic->id);
483 $tabtp[$obj->rowid][$account_pay_subscription] = isset($tabtp[$obj->rowid][$account_pay_subscription]) ? $tabtp[$obj->rowid][$account_pay_subscription] + $amounttouse : $amounttouse;
484 } elseif ($links[$key][
'type'] ==
'payment_vat') {
485 $paymentvatstatic->id = $links[$key][
'url_id'];
486 $paymentvatstatic->ref = $links[$key][
'url_id'];
487 $paymentvatstatic->label = $links[$key][
'label'];
488 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentvatstatic->getNomUrl(2);
489 $tabpay[$obj->rowid][
"paymentvatid"] = $paymentvatstatic->id;
490 $tabtp[$obj->rowid][$account_pay_vat] = isset($tabtp[$obj->rowid][$account_pay_vat]) ? $tabtp[$obj->rowid][$account_pay_vat] + $amounttouse : $amounttouse;
491 } elseif ($links[$key][
'type'] ==
'payment_salary') {
492 $paymentsalstatic->id = $links[$key][
'url_id'];
493 $paymentsalstatic->ref = $links[$key][
'url_id'];
494 $paymentsalstatic->label = $links[$key][
'label'];
495 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentsalstatic->getNomUrl(2);
496 $tabpay[$obj->rowid][
"paymentsalid"] = $paymentsalstatic->id;
500 if (
getDolGlobalString(
'ACCOUNTANCY_AUTOFIX_MISSING_LINK_TO_USER_ON_SALARY_BANK_PAYMENT')) {
501 $tmpsalary =
new Salary($db);
502 $tmpsalary->fetch($paymentsalstatic->id);
503 $tmpsalary->fetch_user($tmpsalary->fk_user);
505 $userstatic->id = $tmpsalary->user->id;
506 $userstatic->name = $tmpsalary->user->name;
507 $userstatic->email = $tmpsalary->user->email;
508 $userstatic->firstname = $tmpsalary->user->firstname;
509 $userstatic->lastname = $tmpsalary->user->lastname;
510 $userstatic->status = $tmpsalary->user->status;
511 $userstatic->accountancy_code = $tmpsalary->user->accountancy_code;
513 if ($userstatic->id > 0) {
514 $tabpay[$obj->rowid][
"soclib"] = $userstatic->getNomUrl(1,
'accountancy', 0);
516 $tabpay[$obj->rowid][
"soclib"] =
'???';
519 if (empty($obj->typeop_user)) {
520 $compta_user = $userstatic->accountancy_code;
522 $tabtp[$obj->rowid][$compta_user] += $amounttouse;
523 $tabuser[$obj->rowid] = array(
524 'id' => $userstatic->id,
526 'lastname' => $userstatic->lastname,
527 'firstname' => $userstatic->firstname,
528 'email' => $userstatic->email,
529 'accountancy_code' => $compta_user,
530 'status' => $userstatic->status
535 } elseif ($links[$key][
'type'] ==
'payment_expensereport') {
536 $paymentexpensereportstatic->id = $links[$key][
'url_id'];
537 $tabpay[$obj->rowid][
"lib"] .= $paymentexpensereportstatic->getNomUrl(2);
538 $tabpay[$obj->rowid][
"paymentexpensereport"] = $paymentexpensereportstatic->id;
539 } elseif ($links[$key][
'type'] ==
'payment_various') {
540 $paymentvariousstatic->id = $links[$key][
'url_id'];
541 $paymentvariousstatic->ref = $links[$key][
'url_id'];
542 $paymentvariousstatic->label = $links[$key][
'label'];
543 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentvariousstatic->getNomUrl(2);
544 $tabpay[$obj->rowid][
"paymentvariousid"] = $paymentvariousstatic->id;
545 $paymentvariousstatic->fetch($paymentvariousstatic->id);
546 $account_various = (!empty($paymentvariousstatic->accountancy_code) ? $paymentvariousstatic->accountancy_code :
'NotDefined');
547 $account_subledger = (!empty($paymentvariousstatic->subledger_account) ? $paymentvariousstatic->subledger_account :
'');
548 $tabpay[$obj->rowid][
"account_various"] = $account_various;
549 $tabtp[$obj->rowid][$account_subledger] = isset($tabtp[$obj->rowid][$account_subledger]) ? $tabtp[$obj->rowid][$account_subledger] + $amounttouse : $amounttouse;
550 } elseif ($links[$key][
'type'] ==
'payment_loan') {
551 $paymentloanstatic->id = $links[$key][
'url_id'];
552 $paymentloanstatic->ref = $links[$key][
'url_id'];
553 $paymentloanstatic->fk_loan = $links[$key][
'url_id'];
554 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentloanstatic->getNomUrl(2);
555 $tabpay[$obj->rowid][
"paymentloanid"] = $paymentloanstatic->id;
557 $sqlmid =
'SELECT pl.amount_capital, pl.amount_insurance, pl.amount_interest, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest';
558 $sqlmid .=
' FROM '.MAIN_DB_PREFIX.
'payment_loan as pl, '.MAIN_DB_PREFIX.
'loan as l';
559 $sqlmid .=
' WHERE l.rowid = pl.fk_loan AND pl.fk_bank = '.((int) $obj->rowid);
561 dol_syslog(
"accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);
562 $resultmid = $db->query($sqlmid);
564 $objmid = $db->fetch_object($resultmid);
565 $tabtp[$obj->rowid][$objmid->accountancy_account_capital] = isset($objmid->amount_capital) ? $tabtp[$obj->rowid][$objmid->accountancy_account_capital] - $objmid->amount_capital : 0;
566 $tabtp[$obj->rowid][$objmid->accountancy_account_insurance] = isset($objmid->amount_insurance) ? $tabtp[$obj->rowid][$objmid->accountancy_account_insurance] - $objmid->amount_insurance : 0;
567 $tabtp[$obj->rowid][$objmid->accountancy_account_interest] = isset($objmid->amount_interest) ? $tabtp[$obj->rowid][$objmid->accountancy_account_interest] - $objmid->amount_interest : 0;
569 } elseif ($links[$key][
'type'] ==
'banktransfert') {
570 $accountLinestatic->fetch($links[$key][
'url_id']);
571 $tabpay[$obj->rowid][
"lib"] .=
' '.$langs->trans(
"BankTransfer").
'- '.$accountLinestatic ->getNomUrl(1);
572 $tabtp[$obj->rowid][$account_transfer] = isset($tabtp[$obj->rowid][$account_transfer]) ? $tabtp[$obj->rowid][$account_transfer] + $amounttouse : $amounttouse;
573 $bankaccountstatic->fetch($tabpay[$obj->rowid][
'fk_bank_account']);
574 $tabpay[$obj->rowid][
"soclib"] = $bankaccountstatic->getNomUrl(2);
579 if (empty($tabbq[$obj->rowid][$compta_bank])) {
580 $tabbq[$obj->rowid][$compta_bank] = $amounttouse;
582 $tabbq[$obj->rowid][$compta_bank] += $amounttouse;
587 if (empty($tabtp[$obj->rowid]) && !empty($tabmoreinfo[$obj->rowid][
'withdraw'])) {
588 foreach ($links as $key => $val) {
589 if ($links[$key][
'type'] ==
'payment') {
591 $tmppayment->fetch($links[$key][
'url_id']);
592 $arrayofamounts = $tmppayment->getAmountsArray();
593 if (is_array($arrayofamounts)) {
594 foreach ($arrayofamounts as $invoiceid => $amount) {
595 $tmpinvoice->fetch($invoiceid);
596 $tmpinvoice->fetch_thirdparty();
597 if ($tmpinvoice->thirdparty->code_compta_client) {
598 $tabtp[$obj->rowid][$tmpinvoice->thirdparty->code_compta_client] += $amount;
607 if (empty($tabtp[$obj->rowid])) {
608 $tabtp[$obj->rowid][
'NotDefined'] = $tabbq[$obj->rowid][$compta_bank];
627if (!$error && $action ==
'writebookkeeping' && $user->hasRight(
'accounting',
'bind',
'write')) {
631 $accountingaccountcustomer->fetch(
null,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'),
true);
634 $accountingaccountsupplier->fetch(
null,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUPPLIER'),
true);
637 $accountingaccountpayment->fetch(
null,
getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT'),
true);
640 $accountingaccountexpensereport->fetch(
null, $conf->global->ACCOUNTING_ACCOUNT_EXPENSEREPORT,
true);
643 $accountingaccountsuspense->fetch(
null,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUSPENSE'),
true);
646 foreach ($tabpay as $key => $val) {
664 if (!$errorforline && is_array($tabbq[$key])) {
666 foreach ($tabbq[$key] as $k => $mt) {
668 if (empty($conf->cache[
'accountingaccountincurrententity'][$k])) {
670 $accountingaccount->fetch(0, $k,
true);
671 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
673 $accountingaccount = $conf->cache[
'accountingaccountincurrententity'][$k];
676 $account_label = $accountingaccount->label;
679 if (!empty($val[
'lib'])) {
683 if (!empty($val[
'soclib'])) {
684 $reflabel .=
" - ".dol_string_nohtmltag($val[
'soclib']);
688 $bookkeeping->doc_date = $val[
"date"];
689 $bookkeeping->doc_ref = $ref;
690 $bookkeeping->doc_type =
'bank';
691 $bookkeeping->fk_doc = $key;
692 $bookkeeping->fk_docdet = $val[
"fk_bank"];
694 $bookkeeping->numero_compte = $k;
695 $bookkeeping->label_compte = $account_label;
697 $bookkeeping->label_operation = $reflabel;
698 $bookkeeping->montant = $mt;
699 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
700 $bookkeeping->debit = ($mt >= 0 ? $mt : 0);
701 $bookkeeping->credit = ($mt < 0 ? -$mt : 0);
702 $bookkeeping->code_journal = $journal;
703 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
704 $bookkeeping->fk_user_author = $user->id;
705 $bookkeeping->date_creation = $now;
708 $bookkeeping->subledger_account =
'';
709 $bookkeeping->label_operation = $reflabel;
710 $bookkeeping->entity = $conf->entity;
712 $totaldebit += $bookkeeping->debit;
713 $totalcredit += $bookkeeping->credit;
715 $result = $bookkeeping->create($user);
717 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
720 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded',
null,
'warnings');
732 if (!$errorforline) {
733 if (is_array($tabtp[$key])) {
735 foreach ($tabtp[$key] as $k => $mt) {
740 if (!empty($val[
'lib'])) {
743 if ($tabtype[$key] ==
'banktransfert') {
744 $reflabel .=
dol_string_nohtmltag($langs->transnoentitiesnoconv(
'TransitionalAccount').
' '.$account_transfer);
750 $bookkeeping->doc_date = $val[
"date"];
751 $bookkeeping->doc_ref = $ref;
752 $bookkeeping->doc_type =
'bank';
753 $bookkeeping->fk_doc = $key;
754 $bookkeeping->fk_docdet = $val[
"fk_bank"];
756 $bookkeeping->label_operation = $reflabel;
757 $bookkeeping->montant = $mt;
758 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
759 $bookkeeping->debit = ($mt < 0 ? -$mt : 0);
760 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
761 $bookkeeping->code_journal = $journal;
762 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
763 $bookkeeping->fk_user_author = $user->id;
764 $bookkeeping->date_creation = $now;
766 if ($tabtype[$key] ==
'payment') {
768 $bookkeeping->subledger_account = $k;
769 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
771 $bookkeeping->label_compte = $accountingaccountcustomer->label;
772 } elseif ($tabtype[$key] ==
'payment_supplier') {
774 $bookkeeping->subledger_account = $k;
775 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
777 $bookkeeping->label_compte = $accountingaccountsupplier->label;
778 } elseif ($tabtype[$key] ==
'payment_expensereport') {
779 $bookkeeping->subledger_account = $tabuser[$key][
'accountancy_code'];
780 $bookkeeping->subledger_label = $tabuser[$key][
'name'];
782 $bookkeeping->label_compte = $accountingaccountexpensereport->label;
783 } elseif ($tabtype[$key] ==
'payment_salary') {
784 $bookkeeping->subledger_account = $tabuser[$key][
'accountancy_code'];
785 $bookkeeping->subledger_label = $tabuser[$key][
'name'];
786 $bookkeeping->numero_compte =
getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT');
787 $bookkeeping->label_compte = $accountingaccountpayment->label;
788 } elseif (in_array($tabtype[$key], array(
'sc',
'payment_sc'))) {
789 $bookkeeping->subledger_account =
'';
790 $bookkeeping->subledger_label =
'';
791 if (empty($conf->cache[
'accountingaccountincurrententity'][$k])) {
793 $accountingaccount->fetch(0, $k,
true);
794 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
796 $accountingaccount = $conf->cache[
'accountingaccountincurrententity'][$k];
798 $bookkeeping->numero_compte = $k;
799 $bookkeeping->label_compte = $accountingaccount->label;
800 } elseif ($tabtype[$key] ==
'payment_vat') {
801 $bookkeeping->subledger_account =
'';
802 $bookkeeping->subledger_label =
'';
803 if (empty($conf->cache[
'accountingaccountincurrententity'][$k])) {
805 $accountingaccount->fetch(0, $k,
true);
806 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
808 $accountingaccount = $conf->cache[
'accountingaccountincurrententity'][$k];
810 $bookkeeping->numero_compte = $k;
811 $bookkeeping->label_compte = $accountingaccount->label;
812 } elseif ($tabtype[$key] ==
'payment_donation') {
813 $bookkeeping->subledger_account =
'';
814 $bookkeeping->subledger_label =
'';
815 if (empty($conf->cache[
'accountingaccountincurrententity'][$k])) {
817 $accountingaccount->fetch(0, $k,
true);
818 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
820 $accountingaccount = $conf->cache[
'accountingaccountincurrententity'][$k];
822 $bookkeeping->numero_compte = $k;
823 $bookkeeping->label_compte = $accountingaccount->label;
824 } elseif ($tabtype[$key] ==
'member') {
825 $bookkeeping->subledger_account =
'';
826 $bookkeeping->subledger_label =
'';
827 if (empty($conf->cache[
'accountingaccountincurrententity'][$k])) {
829 $accountingaccount->fetch(0, $k,
true);
830 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
832 $accountingaccount = $conf->cache[
'accountingaccountincurrententity'][$k];
834 $bookkeeping->numero_compte = $k;
835 $bookkeeping->label_compte = $accountingaccount->label;
836 } elseif ($tabtype[$key] ==
'payment_loan') {
837 $bookkeeping->subledger_account =
'';
838 $bookkeeping->subledger_label =
'';
839 if (empty($conf->cache[
'accountingaccountincurrententity'][$k])) {
841 $accountingaccount->fetch(0, $k,
true);
842 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
844 $accountingaccount = $conf->cache[
'accountingaccountincurrententity'][$k];
846 $bookkeeping->numero_compte = $k;
847 $bookkeeping->label_compte = $accountingaccount->label;
848 } elseif ($tabtype[$key] ==
'payment_various') {
849 $bookkeeping->subledger_account = $k;
850 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
851 if (empty($conf->cache[
'accountingaccountincurrententity'][$tabpay[$key][
"account_various"]])) {
853 $accountingaccount->fetch(0, $tabpay[$key][
"account_various"],
true);
854 $conf->cache[
'accountingaccountincurrententity'][$tabpay[$key][
"account_various"]] = $accountingaccount;
856 $accountingaccount = $conf->cache[
'accountingaccountincurrententity'][$tabpay[$key][
"account_various"]];
858 $bookkeeping->numero_compte = $tabpay[$key][
"account_various"];
859 $bookkeeping->label_compte = $accountingaccount->label;
860 } elseif ($tabtype[$key] ==
'banktransfert') {
861 $bookkeeping->subledger_account =
'';
862 $bookkeeping->subledger_label =
'';
863 if (empty($conf->cache[
'accountingaccountincurrententity'][$k])) {
865 $accountingaccount->fetch(0, $k,
true);
866 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
868 $accountingaccount = $conf->cache[
'accountingaccountincurrententity'][$k];
870 $bookkeeping->numero_compte = $k;
871 $bookkeeping->label_compte = $accountingaccount->label;
873 if ($tabtype[$key] ==
'unknown') {
875 $bookkeeping->subledger_account =
'';
876 $bookkeeping->subledger_label =
'';
878 $bookkeeping->label_compte = $accountingaccountsuspense->label;
881 $bookkeeping->label_operation = $reflabel;
882 $bookkeeping->entity = $conf->entity;
884 $totaldebit += $bookkeeping->debit;
885 $totalcredit += $bookkeeping->credit;
887 $result = $bookkeeping->create($user);
889 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
892 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded',
null,
'warnings');
900 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/lettering.class.php';
902 $nb_lettering = $lettering_static->bookkeepingLetteringAll(array($bookkeeping->id));
908 foreach ($tabbq[$key] as $k => $mt) {
911 if (!empty($val[
'lib'])) {
917 $bookkeeping->doc_date = $val[
"date"];
918 $bookkeeping->doc_ref = $ref;
919 $bookkeeping->doc_type =
'bank';
920 $bookkeeping->fk_doc = $key;
921 $bookkeeping->fk_docdet = $val[
"fk_bank"];
922 $bookkeeping->montant = $mt;
923 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
924 $bookkeeping->debit = ($mt < 0 ? -$mt : 0);
925 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
926 $bookkeeping->code_journal = $journal;
927 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
928 $bookkeeping->fk_user_author = $user->id;
929 $bookkeeping->date_creation = $now;
930 $bookkeeping->label_compte =
'';
931 $bookkeeping->label_operation = $reflabel;
932 $bookkeeping->entity = $conf->entity;
934 $totaldebit += $bookkeeping->debit;
935 $totalcredit += $bookkeeping->credit;
937 $result = $bookkeeping->create($user);
940 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
943 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded',
null,
'warnings');
958 setEventMessages(
'We tried to insert a non balanced transaction in book for '.$ref.
'. Canceled. Surely a bug.',
null,
'errors');
961 if (!$errorforline) {
968 if ($error >= $MAXNBERRORS) {
969 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped").
' (>'.$MAXNBERRORS.
')',
null,
'errors');
975 if (empty($error) && count($tabpay) > 0) {
977 } elseif (count($tabpay) == $error) {
980 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
986 if (count($tabpay) != $error) {
987 $param =
'id_journal='.$id_journal;
988 $param .=
'&date_startday='.$date_startday;
989 $param .=
'&date_startmonth='.$date_startmonth;
990 $param .=
'&date_startyear='.$date_startyear;
991 $param .=
'&date_endday='.$date_endday;
992 $param .=
'&date_endmonth='.$date_endmonth;
993 $param .=
'&date_endyear='.$date_endyear;
994 $param .=
'&in_bookkeeping='.$in_bookkeeping;
995 header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
1003if ($action ==
'exportcsv' && $user->hasRight(
'accounting',
'bind',
'write')) {
1006 $filename =
'journal';
1007 $type_export =
'journal';
1008 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
1011 print
'"'.$langs->transnoentitiesnoconv(
"BankId").
'"'.$sep;
1012 print
'"'.$langs->transnoentitiesnoconv(
"Date").
'"'.$sep;
1013 print
'"'.$langs->transnoentitiesnoconv(
"PaymentMode").
'"'.$sep;
1014 print
'"'.$langs->transnoentitiesnoconv(
"AccountAccounting").
'"'.$sep;
1015 print
'"'.$langs->transnoentitiesnoconv(
"LedgerAccount").
'"'.$sep;
1016 print
'"'.$langs->transnoentitiesnoconv(
"SubledgerAccount").
'"'.$sep;
1017 print
'"'.$langs->transnoentitiesnoconv(
"Label").
'"'.$sep;
1018 print
'"'.$langs->transnoentitiesnoconv(
"AccountingDebit").
'"'.$sep;
1019 print
'"'.$langs->transnoentitiesnoconv(
"AccountingCredit").
'"'.$sep;
1020 print
'"'.$langs->transnoentitiesnoconv(
"Journal").
'"'.$sep;
1021 print
'"'.$langs->transnoentitiesnoconv(
"Note").
'"'.$sep;
1024 foreach ($tabpay as $key => $val) {
1030 foreach ($tabbq[$key] as $k => $mt) {
1033 if (!empty($val[
'lib'])) {
1037 if (!empty($val[
'soclib'])) {
1038 $reflabel .=
" - ".dol_string_nohtmltag($val[
'soclib']);
1041 print
'"'.$key.
'"'.$sep;
1042 print
'"'.$date.
'"'.$sep;
1043 print
'"'.$val[
"type_payment"].
'"'.$sep;
1044 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1045 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
1047 print
'"'.$reflabel.
'"'.$sep;
1048 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1049 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1050 print
'"'.$journal.
'"'.$sep;
1051 print
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
1057 if (is_array($tabtp[$key])) {
1058 foreach ($tabtp[$key] as $k => $mt) {
1061 if (!empty($val[
'lib'])) {
1064 if ($tabtype[$key] ==
'banktransfert') {
1065 $reflabel .=
dol_string_nohtmltag($langs->transnoentitiesnoconv(
'TransitionalAccount').
' '.$account_transfer);
1070 print
'"'.$key.
'"'.$sep;
1071 print
'"'.$date.
'"'.$sep;
1072 print
'"'.$val[
"type_payment"].
'"'.$sep;
1073 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1074 if ($tabtype[$key] ==
'payment_supplier') {
1075 print
'"'.getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUPPLIER').
'"'.$sep;
1076 } elseif ($tabtype[$key] ==
'payment') {
1077 print
'"'.getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER').
'"'.$sep;
1078 } elseif ($tabtype[$key] ==
'payment_expensereport') {
1079 print
'"'.getDolGlobalString(
'ACCOUNTING_ACCOUNT_EXPENSEREPORT').
'"'.$sep;
1080 } elseif ($tabtype[$key] ==
'payment_salary') {
1081 print
'"'.getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT').
'"'.$sep;
1083 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1085 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
1086 print
'"'.$reflabel.
'"'.$sep;
1087 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1088 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1089 print
'"'.$journal.
'"'.$sep;
1090 print
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
1095 foreach ($tabbq[$key] as $k => $mt) {
1098 if (!empty($val[
'lib'])) {
1103 print
'"'.$key.
'"'.$sep;
1104 print
'"'.$date.
'"'.$sep;
1105 print
'"'.$val[
"type_payment"].
'"'.$sep;
1106 print
'"'.length_accountg(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUSPENSE')).
'"'.$sep;
1107 print
'"'.length_accounta(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUSPENSE')).
'"'.$sep;
1109 print
'"'.$reflabel.
'"'.$sep;
1110 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1111 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1112 print
'"'.$journal.
'"'.$sep;
1113 print
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
1126$form =
new Form($db);
1128if (empty($action) || $action ==
'view') {
1129 $invoicestatic =
new Facture($db);
1132 $vatstatic =
new Tva($db);
1133 $donationstatic =
new Don($db);
1134 $loanstatic =
new Loan($db);
1135 $salarystatic =
new Salary($db);
1138 $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1,
'', 1);
1139 $help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
1145 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
1147 $listofchoices = array(
1148 'notyet' => $langs->trans(
"NotYetInGeneralLedger"),
1149 'already' => $langs->trans(
"AlreadyInGeneralLedger")
1151 $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);
1152 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
1154 $varlink =
'id_journal='.$id_journal;
1158 $listofchoices = array(
1159 1 => $langs->trans(
"TransfertAllBankLines"),
1160 2 => $langs->trans(
"TransfertOnlyConciliatedBankLine")
1162 $moreoptions = [
"BankLineConciliated" => $form->selectarray(
'only_rappro', $listofchoices, $only_rappro)];
1164 journalHead($nom,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink, $moreoptions);
1171 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_fiscalyear WHERE entity = ".((int) $conf->entity);
1172 $resql = $db->query($sql);
1174 $obj = $db->fetch_object($resql);
1175 if ($obj->nb == 0) {
1176 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheFiscalPeriodIsNotDefined");
1177 $desc =
' : '.$langs->trans(
"AccountancyAreaDescFiscalPeriod", 4,
'{link}');
1178 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"FiscalPeriod").
'</strong>', $desc);
1188 $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";
1189 $resql = $db->query($sql);
1191 $obj = $db->fetch_object($resql);
1193 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheJournalCodeIsNotDefinedOnSomeBankAccount");
1194 $desc =
' : '.$langs->trans(
"AccountancyAreaDescBank", 6,
'{link}');
1195 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"BankAccounts").
'</strong>', $desc);
1211 print($desc ?
'' :
'<br>').
'<div class="warning">'.
img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
1212 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
1213 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
1219 print
'<br><div class="tabsAction tabsActionNoBottom centerimp">';
1221 if (
getDolGlobalString(
'ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping ==
'notyet') {
1222 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
1227 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
1229 if ($in_bookkeeping ==
'notyet') {
1230 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
1232 print
'<a class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
1240 <script type="text/javascript">
1241 function launch_export() {
1242 console.log("Set value into form and submit");
1243 $("div.fiche form input[name=\"action\"]").val("exportcsv");
1244 $("div.fiche form input[type=\"submit\"]").click();
1245 $("div.fiche form input[name=\"action\"]").val("");
1247 function writebookkeeping() {
1248 console.log("Set value into form and submit");
1249 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
1250 $("div.fiche form input[type=\"submit\"]").click();
1251 $("div.fiche form input[name=\"action\"]").val("");
1261 print
'<div class="div-table-responsive">';
1262 print
'<table class="noborder centpercent">';
1263 print
'<tr class="liste_titre">';
1264 print
"<td>".$langs->trans(
"Date").
"</td>";
1265 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"ObjectsRef").
")</td>";
1266 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
1267 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
1268 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
1269 print
'<td class="center">'.$langs->trans(
"PaymentMode").
"</td>";
1270 print
'<td class="right">'.$langs->trans(
"AccountingDebit").
"</td>";
1271 print
'<td class="right">'.$langs->trans(
"AccountingCredit").
"</td>";
1276 foreach ($tabpay as $key => $val) {
1282 foreach ($tabbq[$key] as $k => $mt) {
1285 if (!empty($val[
'lib'])) {
1286 $reflabel .= $val[
'lib'].
" - ";
1288 $reflabel .= $langs->trans(
"Bank").
' '.$val[
'bank_account_ref'];
1289 if (!empty($val[
'soclib'])) {
1290 $reflabel .=
" - ".$val[
'soclib'];
1294 print
'<!-- Bank bank.rowid='.$key.
' type='.$tabpay[$key][
'type'].
' ref='.$tabpay[$key][
'ref'].
'-->';
1295 print
'<tr class="oddeven">';
1298 print
"<td>".$date.
"</td>";
1301 print
"<td>".dol_escape_htmltag($ref).
"</td>";
1305 if (empty($accounttoshow) || $accounttoshow ==
'NotDefined') {
1306 $accounttoshow =
'<span class="error">'.$langs->trans(
"BankAccountNotDefined").
'</span>';
1308 print
'<td class="maxwidth300" title="'.dol_escape_htmltag(
dol_string_nohtmltag($accounttoshow)).
'">';
1309 print $accounttoshow;
1313 print
'<td class="maxwidth300">';
1327 print
'<td class="center">'.$val[
"type_payment"].
"</td>";
1328 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1329 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1337 if (is_array($tabtp[$key])) {
1338 foreach ($tabtp[$key] as $k => $mt) {
1341 if (!empty($val[
'lib'])) {
1342 $reflabel .= $val[
'lib'].(isset($val[
'soclib']) ?
" - " :
"");
1344 if ($tabtype[$key] ==
'banktransfert') {
1345 $reflabel .= $langs->trans(
'TransitionalAccount').
' '.$account_transfer;
1347 $reflabel .= isset($val[
'soclib']) ? $val[
'soclib'] :
"";
1350 print
'<!-- Thirdparty bank.rowid='.$key.
' -->';
1351 print
'<tr class="oddeven">';
1354 print
"<td>".$date.
"</td>";
1357 print
"<td>".dol_escape_htmltag($ref).
"</td>";
1360 $account_ledger = $k;
1362 if ($tabtype[$key] ==
'payment') {
1365 if ($tabtype[$key] ==
'payment_supplier') {
1368 if ($tabtype[$key] ==
'payment_expensereport') {
1371 if ($tabtype[$key] ==
'payment_salary') {
1374 if ($tabtype[$key] ==
'payment_vat') {
1377 if ($tabtype[$key] ==
'member') {
1380 if ($tabtype[$key] ==
'payment_various') {
1381 $account_ledger = $tabpay[$key][
"account_various"];
1384 if (empty($accounttoshow) || $accounttoshow ==
'NotDefined') {
1385 if ($tabtype[$key] ==
'unknown') {
1388 $accounttoshow =
'<span class="error small">'.$langs->trans(
'UnknownAccountForThirdpartyAndWaitingAccountNotDefinedBlocking').
'</span>';
1390 $accounttoshow =
'<span class="warning small">'.$langs->trans(
'UnknownAccountForThirdparty',
length_accountg(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUSPENSE'))).
'</span>';
1394 $errorstring =
'UnknownAccountForThirdpartyBlocking';
1395 if ($tabtype[$key] ==
'payment') {
1396 $errorstring =
'MainAccountForCustomersNotDefined';
1398 if ($tabtype[$key] ==
'payment_supplier') {
1399 $errorstring =
'MainAccountForSuppliersNotDefined';
1401 if ($tabtype[$key] ==
'payment_expensereport') {
1402 $errorstring =
'MainAccountForUsersNotDefined';
1404 if ($tabtype[$key] ==
'payment_salary') {
1405 $errorstring =
'MainAccountForUsersNotDefined';
1407 if ($tabtype[$key] ==
'payment_vat') {
1408 $errorstring =
'MainAccountForVatPaymentNotDefined';
1410 if ($tabtype[$key] ==
'member') {
1411 $errorstring =
'MainAccountForSubscriptionPaymentNotDefined';
1413 $accounttoshow =
'<span class="error small">'.$langs->trans($errorstring).
'</span>';
1416 print
'<td class="maxwidth300" title="'.dol_escape_htmltag(
dol_string_nohtmltag($accounttoshow)).
'">';
1417 print $accounttoshow;
1421 $accounttoshowsubledger =
'';
1422 if (in_array($tabtype[$key], array(
'payment',
'payment_supplier',
'payment_expensereport',
'payment_salary',
'payment_various'))) {
1424 if ($accounttoshow != $accounttoshowsubledger) {
1425 if (empty($accounttoshowsubledger) || $accounttoshowsubledger ==
'NotDefined') {
1430 if (!empty($tabcompany[$key][
'code_compta'])) {
1431 if (in_array($tabtype[$key], array(
'payment_various',
'payment_salary'))) {
1433 $accounttoshowsubledger =
'<span class="warning small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknownSubledgerIgnored").
'</span>';
1435 $accounttoshowsubledger =
'<span class="warning small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknown", $tabcompany[$key][
'code_compta']).
'</span>';
1438 $accounttoshowsubledger =
'<span class="error small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknownBlocking").
'</span>';
1442 $accounttoshowsubledger =
'';
1445 print
'<td class="maxwidth300">';
1446 print $accounttoshowsubledger;
1449 print
"<td>".$reflabel.
"</td>";
1451 print
'<td class="center">'.$val[
"type_payment"].
"</td>";
1453 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1455 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1463 foreach ($tabbq[$key] as $k => $mt) {
1466 if (!empty($val[
'lib'])) {
1467 $reflabel .= $val[
'lib'].
" - ";
1469 $reflabel .=
'WaitingAccount';
1471 print
'<!-- Wait bank.rowid='.$key.
' -->';
1472 print
'<tr class="oddeven">';
1473 print
"<td>".$date.
"</td>";
1474 print
"<td>".$ref.
"</td>";
1487 print
"<td>".dol_escape_htmltag($reflabel).
"</td>";
1488 print
'<td class="center">'.$val[
"type_payment"].
"</td>";
1489 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1490 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1501 print
'<tr class="oddeven"><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
1528 if ($ref ==
'(SupplierInvoicePayment)' || $ref ==
'(SupplierInvoicePaymentBack)') {
1529 $ref = $langs->transnoentitiesnoconv(
'Supplier');
1531 if ($ref ==
'(CustomerInvoicePayment)' || $ref ==
'(CustomerInvoicePaymentBack)') {
1532 $ref = $langs->transnoentitiesnoconv(
'Customer');
1534 if ($ref ==
'(SocialContributionPayment)') {
1535 $ref = $langs->transnoentitiesnoconv(
'SocialContribution');
1537 if ($ref ==
'(DonationPayment)') {
1538 $ref = $langs->transnoentitiesnoconv(
'Donation');
1540 if ($ref ==
'(SubscriptionPayment)') {
1541 $ref = $langs->transnoentitiesnoconv(
'Subscription');
1543 if ($ref ==
'(ExpenseReportPayment)') {
1544 $ref = $langs->transnoentitiesnoconv(
'Employee');
1546 if ($ref ==
'(LoanPayment)') {
1547 $ref = $langs->transnoentitiesnoconv(
'Loan');
1549 if ($ref ==
'(payment_salary)') {
1550 $ref = $langs->transnoentitiesnoconv(
'Employee');
1554 if ($typerecord ==
'payment') {
1556 $sqlmid =
"SELECT payfac.fk_facture as id, ".$db->ifsql(
'f1.rowid IS NULL',
'f.ref',
'f1.ref').
" as ref";
1557 $sqlmid .=
" FROM ".$db->prefix().
"paiement_facture as payfac";
1558 $sqlmid .=
" LEFT JOIN ".$db->prefix().
"facture as f ON f.rowid = payfac.fk_facture";
1559 $sqlmid .=
" LEFT JOIN ".$db->prefix().
"societe_remise_except as sre ON sre.fk_facture_source = payfac.fk_facture";
1560 $sqlmid .=
" LEFT JOIN ".$db->prefix().
"facture as f1 ON f1.rowid = sre.fk_facture";
1561 $sqlmid .=
" WHERE payfac.fk_paiement=".((int) $val[
'paymentid']);
1563 $sqlmid =
"SELECT payfac.fk_facture as id, f.ref as ref";
1564 $sqlmid .=
" FROM ".$db->prefix().
"paiement_facture as payfac";
1565 $sqlmid .=
" INNER JOIN ".$db->prefix().
"facture as f ON f.rowid = payfac.fk_facture";
1566 $sqlmid .=
" WHERE payfac.fk_paiement=".((int) $val[
'paymentid']);
1568 $ref = $langs->transnoentitiesnoconv(
"Invoice");
1569 } elseif ($typerecord ==
'payment_supplier') {
1570 $sqlmid =
'SELECT payfac.fk_facturefourn as id, f.ref';
1571 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as payfac, ".MAIN_DB_PREFIX.
"facture_fourn as f";
1572 $sqlmid .=
" WHERE payfac.fk_facturefourn = f.rowid AND payfac.fk_paiementfourn=".((int) $val[
"paymentsupplierid"]);
1573 $ref = $langs->transnoentitiesnoconv(
"SupplierInvoice");
1574 } elseif ($typerecord ==
'payment_expensereport') {
1575 $sqlmid =
'SELECT e.rowid as id, e.ref';
1576 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_expensereport as pe, ".MAIN_DB_PREFIX.
"expensereport as e";
1577 $sqlmid .=
" WHERE pe.rowid=".((int) $val[
"paymentexpensereport"]).
" AND pe.fk_expensereport = e.rowid";
1578 $ref = $langs->transnoentitiesnoconv(
"ExpenseReport");
1579 } elseif ($typerecord ==
'payment_salary') {
1580 $sqlmid =
'SELECT s.rowid as ref';
1581 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as s";
1582 $sqlmid .=
" WHERE s.rowid=".((int) $val[
"paymentsalid"]);
1583 $ref = $langs->transnoentitiesnoconv(
"SalaryPayment");
1584 } elseif ($typerecord ==
'sc') {
1585 $sqlmid =
'SELECT sc.rowid as ref';
1586 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"paiementcharge as sc";
1587 $sqlmid .=
" WHERE sc.rowid=".((int) $val[
"paymentscid"]);
1588 $ref = $langs->transnoentitiesnoconv(
"SocialContribution");
1589 } elseif ($typerecord ==
'payment_vat') {
1590 $sqlmid =
'SELECT v.rowid as ref';
1591 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"tva as v";
1592 $sqlmid .=
" WHERE v.rowid=".((int) $val[
"paymentvatid"]);
1593 $ref = $langs->transnoentitiesnoconv(
"PaymentVat");
1594 } elseif ($typerecord ==
'payment_donation') {
1595 $sqlmid =
'SELECT payd.fk_donation as ref';
1596 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_donation as payd";
1597 $sqlmid .=
" WHERE payd.fk_donation=".((int) $val[
"paymentdonationid"]);
1598 $ref = $langs->transnoentitiesnoconv(
"Donation");
1599 } elseif ($typerecord ==
'payment_loan') {
1600 $sqlmid =
'SELECT l.rowid as ref';
1601 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_loan as l";
1602 $sqlmid .=
" WHERE l.rowid=".((int) $val[
"paymentloanid"]);
1603 $ref = $langs->transnoentitiesnoconv(
"LoanPayment");
1604 } elseif ($typerecord ==
'payment_various') {
1605 $sqlmid =
'SELECT v.rowid as ref';
1606 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_various as v";
1607 $sqlmid .=
" WHERE v.rowid=".((int) $val[
"paymentvariousid"]);
1608 $ref = $langs->transnoentitiesnoconv(
"VariousPayment");
1611 if (empty($sqlmid)) {
1612 dol_syslog(
"Found a typerecord=".$typerecord.
" not supported", LOG_WARNING);
1616 dol_syslog(
"accountancy/journal/bankjournal.php::sqlmid=".$sqlmid, LOG_DEBUG);
1617 $resultmid = $db->query($sqlmid);
1619 while ($objmid = $db->fetch_object($resultmid)) {
1620 $ref .=
' '.$objmid->ref;
1627 $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()
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.
Put here description of your class.
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...
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 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.