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($tabtp[$obj->rowid][$objmid->accountancy_account_capital]) ? $tabtp[$obj->rowid][$objmid->accountancy_account_capital] - $objmid->amount_capital : $amounttouse;
566 $tabtp[$obj->rowid][$objmid->accountancy_account_insurance] = isset($tabtp[$obj->rowid][$objmid->accountancy_account_insurance]) ? $tabtp[$obj->rowid][$objmid->accountancy_account_insurance] - $objmid->amount_insurance : $amounttouse;
567 $tabtp[$obj->rowid][$objmid->accountancy_account_interest] = isset($tabtp[$obj->rowid][$objmid->accountancy_account_interest]) ? $tabtp[$obj->rowid][$objmid->accountancy_account_interest] - $objmid->amount_interes : $amounttouse;
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 $accountingaccount->fetch(
null, $k,
true);
792 $bookkeeping->numero_compte = $k;
793 $bookkeeping->label_compte = $accountingaccount->label;
794 } elseif ($tabtype[$key] ==
'payment_vat') {
795 $bookkeeping->subledger_account =
'';
796 $bookkeeping->subledger_label =
'';
797 $accountingaccount->fetch(
null, $k,
true);
798 $bookkeeping->numero_compte = $k;
799 $bookkeeping->label_compte = $accountingaccount->label;
800 } elseif ($tabtype[$key] ==
'payment_donation') {
801 $bookkeeping->subledger_account =
'';
802 $bookkeeping->subledger_label =
'';
803 $accountingaccount->fetch(
null, $k,
true);
804 $bookkeeping->numero_compte = $k;
805 $bookkeeping->label_compte = $accountingaccount->label;
806 } elseif ($tabtype[$key] ==
'member') {
807 $bookkeeping->subledger_account =
'';
808 $bookkeeping->subledger_label =
'';
809 $accountingaccount->fetch(
null, $k,
true);
810 $bookkeeping->numero_compte = $k;
811 $bookkeeping->label_compte = $accountingaccount->label;
812 } elseif ($tabtype[$key] ==
'payment_loan') {
813 $bookkeeping->subledger_account =
'';
814 $bookkeeping->subledger_label =
'';
815 $accountingaccount->fetch(
null, $k,
true);
816 $bookkeeping->numero_compte = $k;
817 $bookkeeping->label_compte = $accountingaccount->label;
818 } elseif ($tabtype[$key] ==
'payment_various') {
819 $bookkeeping->subledger_account = $k;
820 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
821 $accountingaccount->fetch(
null, $tabpay[$key][
"account_various"],
true);
822 $bookkeeping->numero_compte = $tabpay[$key][
"account_various"];
823 $bookkeeping->label_compte = $accountingaccount->label;
824 } elseif ($tabtype[$key] ==
'banktransfert') {
825 $bookkeeping->subledger_account =
'';
826 $bookkeeping->subledger_label =
'';
827 $accountingaccount->fetch(
null, $k,
true);
828 $bookkeeping->numero_compte = $k;
829 $bookkeeping->label_compte = $accountingaccount->label;
831 if ($tabtype[$key] ==
'unknown') {
833 $bookkeeping->subledger_account =
'';
834 $bookkeeping->subledger_label =
'';
836 $bookkeeping->label_compte = $accountingaccountsuspense->label;
839 $bookkeeping->label_operation = $reflabel;
840 $bookkeeping->entity = $conf->entity;
842 $totaldebit += $bookkeeping->debit;
843 $totalcredit += $bookkeeping->credit;
845 $result = $bookkeeping->create($user);
847 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
850 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded',
null,
'warnings');
858 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/lettering.class.php';
860 $nb_lettering = $lettering_static->bookkeepingLetteringAll(array($bookkeeping->id));
866 foreach ($tabbq[$key] as $k => $mt) {
869 if (!empty($val[
'lib'])) {
875 $bookkeeping->doc_date = $val[
"date"];
876 $bookkeeping->doc_ref = $ref;
877 $bookkeeping->doc_type =
'bank';
878 $bookkeeping->fk_doc = $key;
879 $bookkeeping->fk_docdet = $val[
"fk_bank"];
880 $bookkeeping->montant = $mt;
881 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
882 $bookkeeping->debit = ($mt < 0 ? -$mt : 0);
883 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
884 $bookkeeping->code_journal = $journal;
885 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
886 $bookkeeping->fk_user_author = $user->id;
887 $bookkeeping->date_creation = $now;
888 $bookkeeping->label_compte =
'';
889 $bookkeeping->label_operation = $reflabel;
890 $bookkeeping->entity = $conf->entity;
892 $totaldebit += $bookkeeping->debit;
893 $totalcredit += $bookkeeping->credit;
895 $result = $bookkeeping->create($user);
898 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
901 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded',
null,
'warnings');
916 setEventMessages(
'We tried to insert a non balanced transaction in book for '.$ref.
'. Canceled. Surely a bug.',
null,
'errors');
919 if (!$errorforline) {
926 if ($error >= $MAXNBERRORS) {
927 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped").
' (>'.$MAXNBERRORS.
')',
null,
'errors');
933 if (empty($error) && count($tabpay) > 0) {
935 } elseif (count($tabpay) == $error) {
938 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
944 if (count($tabpay) != $error) {
945 $param =
'id_journal='.$id_journal;
946 $param .=
'&date_startday='.$date_startday;
947 $param .=
'&date_startmonth='.$date_startmonth;
948 $param .=
'&date_startyear='.$date_startyear;
949 $param .=
'&date_endday='.$date_endday;
950 $param .=
'&date_endmonth='.$date_endmonth;
951 $param .=
'&date_endyear='.$date_endyear;
952 $param .=
'&in_bookkeeping='.$in_bookkeeping;
953 header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
961if ($action ==
'exportcsv' && $user->hasRight(
'accounting',
'bind',
'write')) {
964 $filename =
'journal';
965 $type_export =
'journal';
966 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
969 print
'"'.$langs->transnoentitiesnoconv(
"BankId").
'"'.$sep;
970 print
'"'.$langs->transnoentitiesnoconv(
"Date").
'"'.$sep;
971 print
'"'.$langs->transnoentitiesnoconv(
"PaymentMode").
'"'.$sep;
972 print
'"'.$langs->transnoentitiesnoconv(
"AccountAccounting").
'"'.$sep;
973 print
'"'.$langs->transnoentitiesnoconv(
"LedgerAccount").
'"'.$sep;
974 print
'"'.$langs->transnoentitiesnoconv(
"SubledgerAccount").
'"'.$sep;
975 print
'"'.$langs->transnoentitiesnoconv(
"Label").
'"'.$sep;
976 print
'"'.$langs->transnoentitiesnoconv(
"AccountingDebit").
'"'.$sep;
977 print
'"'.$langs->transnoentitiesnoconv(
"AccountingCredit").
'"'.$sep;
978 print
'"'.$langs->transnoentitiesnoconv(
"Journal").
'"'.$sep;
979 print
'"'.$langs->transnoentitiesnoconv(
"Note").
'"'.$sep;
982 foreach ($tabpay as $key => $val) {
988 foreach ($tabbq[$key] as $k => $mt) {
991 if (!empty($val[
'lib'])) {
995 if (!empty($val[
'soclib'])) {
996 $reflabel .=
" - ".dol_string_nohtmltag($val[
'soclib']);
999 print
'"'.$key.
'"'.$sep;
1000 print
'"'.$date.
'"'.$sep;
1001 print
'"'.$val[
"type_payment"].
'"'.$sep;
1002 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1003 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
1005 print
'"'.$reflabel.
'"'.$sep;
1006 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1007 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1008 print
'"'.$journal.
'"'.$sep;
1009 print
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
1015 if (is_array($tabtp[$key])) {
1016 foreach ($tabtp[$key] as $k => $mt) {
1019 if (!empty($val[
'lib'])) {
1022 if ($tabtype[$key] ==
'banktransfert') {
1023 $reflabel .=
dol_string_nohtmltag($langs->transnoentitiesnoconv(
'TransitionalAccount').
' '.$account_transfer);
1028 print
'"'.$key.
'"'.$sep;
1029 print
'"'.$date.
'"'.$sep;
1030 print
'"'.$val[
"type_payment"].
'"'.$sep;
1031 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1032 if ($tabtype[$key] ==
'payment_supplier') {
1033 print
'"'.getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUPPLIER').
'"'.$sep;
1034 } elseif ($tabtype[$key] ==
'payment') {
1035 print
'"'.getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER').
'"'.$sep;
1036 } elseif ($tabtype[$key] ==
'payment_expensereport') {
1037 print
'"'.getDolGlobalString(
'ACCOUNTING_ACCOUNT_EXPENSEREPORT').
'"'.$sep;
1038 } elseif ($tabtype[$key] ==
'payment_salary') {
1039 print
'"'.getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT').
'"'.$sep;
1041 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1043 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
1044 print
'"'.$reflabel.
'"'.$sep;
1045 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1046 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1047 print
'"'.$journal.
'"'.$sep;
1048 print
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
1053 foreach ($tabbq[$key] as $k => $mt) {
1056 if (!empty($val[
'lib'])) {
1061 print
'"'.$key.
'"'.$sep;
1062 print
'"'.$date.
'"'.$sep;
1063 print
'"'.$val[
"type_payment"].
'"'.$sep;
1064 print
'"'.length_accountg(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUSPENSE')).
'"'.$sep;
1065 print
'"'.length_accounta(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUSPENSE')).
'"'.$sep;
1067 print
'"'.$reflabel.
'"'.$sep;
1068 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1069 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1070 print
'"'.$journal.
'"'.$sep;
1071 print
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
1084$form =
new Form($db);
1086if (empty($action) || $action ==
'view') {
1087 $invoicestatic =
new Facture($db);
1090 $vatstatic =
new Tva($db);
1091 $donationstatic =
new Don($db);
1092 $loanstatic =
new Loan($db);
1093 $salarystatic =
new Salary($db);
1096 $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1,
'', 1);
1097 $help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
1103 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
1105 $listofchoices = array(
1106 'notyet' => $langs->trans(
"NotYetInGeneralLedger"),
1107 'already' => $langs->trans(
"AlreadyInGeneralLedger")
1109 $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);
1110 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
1112 $varlink =
'id_journal='.$id_journal;
1116 $listofchoices = array(
1117 1 => $langs->trans(
"TransfertAllBankLines"),
1118 2 => $langs->trans(
"TransfertOnlyConciliatedBankLine")
1120 $moreoptions = [
"BankLineConciliated" => $form->selectarray(
'only_rappro', $listofchoices, $only_rappro)];
1122 journalHead($nom,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink, $moreoptions);
1129 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_fiscalyear WHERE entity = ".((int) $conf->entity);
1130 $resql = $db->query($sql);
1132 $obj = $db->fetch_object($resql);
1133 if ($obj->nb == 0) {
1134 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheFiscalPeriodIsNotDefined");
1135 $desc =
' : '.$langs->trans(
"AccountancyAreaDescFiscalPeriod", 4,
'{link}');
1136 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"FiscalPeriod").
'</strong>', $desc);
1146 $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";
1147 $resql = $db->query($sql);
1149 $obj = $db->fetch_object($resql);
1151 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheJournalCodeIsNotDefinedOnSomeBankAccount");
1152 $desc =
' : '.$langs->trans(
"AccountancyAreaDescBank", 6,
'{link}');
1153 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"BankAccounts").
'</strong>', $desc);
1169 print($desc ?
'' :
'<br>').
'<div class="warning">'.
img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
1170 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
1171 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
1177 print
'<br><div class="tabsAction tabsActionNoBottom centerimp">';
1179 if (
getDolGlobalString(
'ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping ==
'notyet') {
1180 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
1185 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
1187 if ($in_bookkeeping ==
'notyet') {
1188 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
1190 print
'<a class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
1198 <script type="text/javascript">
1199 function launch_export() {
1200 console.log("Set value into form and submit");
1201 $("div.fiche form input[name=\"action\"]").val("exportcsv");
1202 $("div.fiche form input[type=\"submit\"]").click();
1203 $("div.fiche form input[name=\"action\"]").val("");
1205 function writebookkeeping() {
1206 console.log("Set value into form and submit");
1207 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
1208 $("div.fiche form input[type=\"submit\"]").click();
1209 $("div.fiche form input[name=\"action\"]").val("");
1219 print
'<div class="div-table-responsive">';
1220 print
'<table class="noborder centpercent">';
1221 print
'<tr class="liste_titre">';
1222 print
"<td>".$langs->trans(
"Date").
"</td>";
1223 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"ObjectsRef").
")</td>";
1224 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
1225 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
1226 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
1227 print
'<td class="center">'.$langs->trans(
"PaymentMode").
"</td>";
1228 print
'<td class="right">'.$langs->trans(
"AccountingDebit").
"</td>";
1229 print
'<td class="right">'.$langs->trans(
"AccountingCredit").
"</td>";
1234 foreach ($tabpay as $key => $val) {
1240 foreach ($tabbq[$key] as $k => $mt) {
1243 if (!empty($val[
'lib'])) {
1244 $reflabel .= $val[
'lib'].
" - ";
1246 $reflabel .= $langs->trans(
"Bank").
' '.$val[
'bank_account_ref'];
1247 if (!empty($val[
'soclib'])) {
1248 $reflabel .=
" - ".$val[
'soclib'];
1252 print
'<!-- Bank bank.rowid='.$key.
' type='.$tabpay[$key][
'type'].
' ref='.$tabpay[$key][
'ref'].
'-->';
1253 print
'<tr class="oddeven">';
1256 print
"<td>".$date.
"</td>";
1259 print
"<td>".dol_escape_htmltag($ref).
"</td>";
1263 if (empty($accounttoshow) || $accounttoshow ==
'NotDefined') {
1264 $accounttoshow =
'<span class="error">'.$langs->trans(
"BankAccountNotDefined").
'</span>';
1266 print
'<td class="maxwidth300" title="'.dol_escape_htmltag(
dol_string_nohtmltag($accounttoshow)).
'">';
1267 print $accounttoshow;
1271 print
'<td class="maxwidth300">';
1285 print
'<td class="center">'.$val[
"type_payment"].
"</td>";
1286 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1287 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1295 if (is_array($tabtp[$key])) {
1296 foreach ($tabtp[$key] as $k => $mt) {
1299 if (!empty($val[
'lib'])) {
1300 $reflabel .= $val[
'lib'].(isset($val[
'soclib']) ?
" - " :
"");
1302 if ($tabtype[$key] ==
'banktransfert') {
1303 $reflabel .= $langs->trans(
'TransitionalAccount').
' '.$account_transfer;
1305 $reflabel .= isset($val[
'soclib']) ? $val[
'soclib'] :
"";
1308 print
'<!-- Thirdparty bank.rowid='.$key.
' -->';
1309 print
'<tr class="oddeven">';
1312 print
"<td>".$date.
"</td>";
1315 print
"<td>".dol_escape_htmltag($ref).
"</td>";
1318 $account_ledger = $k;
1320 if ($tabtype[$key] ==
'payment') {
1323 if ($tabtype[$key] ==
'payment_supplier') {
1326 if ($tabtype[$key] ==
'payment_expensereport') {
1329 if ($tabtype[$key] ==
'payment_salary') {
1332 if ($tabtype[$key] ==
'payment_vat') {
1335 if ($tabtype[$key] ==
'member') {
1338 if ($tabtype[$key] ==
'payment_various') {
1339 $account_ledger = $tabpay[$key][
"account_various"];
1342 if (empty($accounttoshow) || $accounttoshow ==
'NotDefined') {
1343 if ($tabtype[$key] ==
'unknown') {
1346 $accounttoshow =
'<span class="error small">'.$langs->trans(
'UnknownAccountForThirdpartyAndWaitingAccountNotDefinedBlocking').
'</span>';
1348 $accounttoshow =
'<span class="warning small">'.$langs->trans(
'UnknownAccountForThirdparty',
length_accountg(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUSPENSE'))).
'</span>';
1352 $errorstring =
'UnknownAccountForThirdpartyBlocking';
1353 if ($tabtype[$key] ==
'payment') {
1354 $errorstring =
'MainAccountForCustomersNotDefined';
1356 if ($tabtype[$key] ==
'payment_supplier') {
1357 $errorstring =
'MainAccountForSuppliersNotDefined';
1359 if ($tabtype[$key] ==
'payment_expensereport') {
1360 $errorstring =
'MainAccountForUsersNotDefined';
1362 if ($tabtype[$key] ==
'payment_salary') {
1363 $errorstring =
'MainAccountForUsersNotDefined';
1365 if ($tabtype[$key] ==
'payment_vat') {
1366 $errorstring =
'MainAccountForVatPaymentNotDefined';
1368 if ($tabtype[$key] ==
'member') {
1369 $errorstring =
'MainAccountForSubscriptionPaymentNotDefined';
1371 $accounttoshow =
'<span class="error small">'.$langs->trans($errorstring).
'</span>';
1374 print
'<td class="maxwidth300" title="'.dol_escape_htmltag(
dol_string_nohtmltag($accounttoshow)).
'">';
1375 print $accounttoshow;
1379 $accounttoshowsubledger =
'';
1380 if (in_array($tabtype[$key], array(
'payment',
'payment_supplier',
'payment_expensereport',
'payment_salary',
'payment_various'))) {
1382 if ($accounttoshow != $accounttoshowsubledger) {
1383 if (empty($accounttoshowsubledger) || $accounttoshowsubledger ==
'NotDefined') {
1388 if (!empty($tabcompany[$key][
'code_compta'])) {
1389 if (in_array($tabtype[$key], array(
'payment_various',
'payment_salary'))) {
1391 $accounttoshowsubledger =
'<span class="warning small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknownSubledgerIgnored").
'</span>';
1393 $accounttoshowsubledger =
'<span class="warning small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknown", $tabcompany[$key][
'code_compta']).
'</span>';
1396 $accounttoshowsubledger =
'<span class="error small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknownBlocking").
'</span>';
1400 $accounttoshowsubledger =
'';
1403 print
'<td class="maxwidth300">';
1404 print $accounttoshowsubledger;
1407 print
"<td>".$reflabel.
"</td>";
1409 print
'<td class="center">'.$val[
"type_payment"].
"</td>";
1411 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1413 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1421 foreach ($tabbq[$key] as $k => $mt) {
1424 if (!empty($val[
'lib'])) {
1425 $reflabel .= $val[
'lib'].
" - ";
1427 $reflabel .=
'WaitingAccount';
1429 print
'<!-- Wait bank.rowid='.$key.
' -->';
1430 print
'<tr class="oddeven">';
1431 print
"<td>".$date.
"</td>";
1432 print
"<td>".$ref.
"</td>";
1445 print
"<td>".dol_escape_htmltag($reflabel).
"</td>";
1446 print
'<td class="center">'.$val[
"type_payment"].
"</td>";
1447 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1448 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1459 print
'<tr class="oddeven"><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
1486 if ($ref ==
'(SupplierInvoicePayment)' || $ref ==
'(SupplierInvoicePaymentBack)') {
1487 $ref = $langs->transnoentitiesnoconv(
'Supplier');
1489 if ($ref ==
'(CustomerInvoicePayment)' || $ref ==
'(CustomerInvoicePaymentBack)') {
1490 $ref = $langs->transnoentitiesnoconv(
'Customer');
1492 if ($ref ==
'(SocialContributionPayment)') {
1493 $ref = $langs->transnoentitiesnoconv(
'SocialContribution');
1495 if ($ref ==
'(DonationPayment)') {
1496 $ref = $langs->transnoentitiesnoconv(
'Donation');
1498 if ($ref ==
'(SubscriptionPayment)') {
1499 $ref = $langs->transnoentitiesnoconv(
'Subscription');
1501 if ($ref ==
'(ExpenseReportPayment)') {
1502 $ref = $langs->transnoentitiesnoconv(
'Employee');
1504 if ($ref ==
'(LoanPayment)') {
1505 $ref = $langs->transnoentitiesnoconv(
'Loan');
1507 if ($ref ==
'(payment_salary)') {
1508 $ref = $langs->transnoentitiesnoconv(
'Employee');
1512 if ($typerecord ==
'payment') {
1514 $sqlmid =
"SELECT payfac.fk_facture as id, ".$db->ifsql(
'f1.rowid IS NULL',
'f.ref',
'f1.ref').
" as ref";
1515 $sqlmid .=
" FROM ".$db->prefix().
"paiement_facture as payfac";
1516 $sqlmid .=
" LEFT JOIN ".$db->prefix().
"facture as f ON f.rowid = payfac.fk_facture";
1517 $sqlmid .=
" LEFT JOIN ".$db->prefix().
"societe_remise_except as sre ON sre.fk_facture_source = payfac.fk_facture";
1518 $sqlmid .=
" LEFT JOIN ".$db->prefix().
"facture as f1 ON f1.rowid = sre.fk_facture";
1519 $sqlmid .=
" WHERE payfac.fk_paiement=".((int) $val[
'paymentid']);
1521 $sqlmid =
"SELECT payfac.fk_facture as id, f.ref as ref";
1522 $sqlmid .=
" FROM ".$db->prefix().
"paiement_facture as payfac";
1523 $sqlmid .=
" INNER JOIN ".$db->prefix().
"facture as f ON f.rowid = payfac.fk_facture";
1524 $sqlmid .=
" WHERE payfac.fk_paiement=".((int) $val[
'paymentid']);
1526 $ref = $langs->transnoentitiesnoconv(
"Invoice");
1527 } elseif ($typerecord ==
'payment_supplier') {
1528 $sqlmid =
'SELECT payfac.fk_facturefourn as id, f.ref';
1529 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as payfac, ".MAIN_DB_PREFIX.
"facture_fourn as f";
1530 $sqlmid .=
" WHERE payfac.fk_facturefourn = f.rowid AND payfac.fk_paiementfourn=".((int) $val[
"paymentsupplierid"]);
1531 $ref = $langs->transnoentitiesnoconv(
"SupplierInvoice");
1532 } elseif ($typerecord ==
'payment_expensereport') {
1533 $sqlmid =
'SELECT e.rowid as id, e.ref';
1534 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_expensereport as pe, ".MAIN_DB_PREFIX.
"expensereport as e";
1535 $sqlmid .=
" WHERE pe.rowid=".((int) $val[
"paymentexpensereport"]).
" AND pe.fk_expensereport = e.rowid";
1536 $ref = $langs->transnoentitiesnoconv(
"ExpenseReport");
1537 } elseif ($typerecord ==
'payment_salary') {
1538 $sqlmid =
'SELECT s.rowid as ref';
1539 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as s";
1540 $sqlmid .=
" WHERE s.rowid=".((int) $val[
"paymentsalid"]);
1541 $ref = $langs->transnoentitiesnoconv(
"SalaryPayment");
1542 } elseif ($typerecord ==
'sc') {
1543 $sqlmid =
'SELECT sc.rowid as ref';
1544 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"paiementcharge as sc";
1545 $sqlmid .=
" WHERE sc.rowid=".((int) $val[
"paymentscid"]);
1546 $ref = $langs->transnoentitiesnoconv(
"SocialContribution");
1547 } elseif ($typerecord ==
'payment_vat') {
1548 $sqlmid =
'SELECT v.rowid as ref';
1549 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"tva as v";
1550 $sqlmid .=
" WHERE v.rowid=".((int) $val[
"paymentvatid"]);
1551 $ref = $langs->transnoentitiesnoconv(
"PaymentVat");
1552 } elseif ($typerecord ==
'payment_donation') {
1553 $sqlmid =
'SELECT payd.fk_donation as ref';
1554 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_donation as payd";
1555 $sqlmid .=
" WHERE payd.fk_donation=".((int) $val[
"paymentdonationid"]);
1556 $ref = $langs->transnoentitiesnoconv(
"Donation");
1557 } elseif ($typerecord ==
'payment_loan') {
1558 $sqlmid =
'SELECT l.rowid as ref';
1559 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_loan as l";
1560 $sqlmid .=
" WHERE l.rowid=".((int) $val[
"paymentloanid"]);
1561 $ref = $langs->transnoentitiesnoconv(
"LoanPayment");
1562 } elseif ($typerecord ==
'payment_various') {
1563 $sqlmid =
'SELECT v.rowid as ref';
1564 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_various as v";
1565 $sqlmid .=
" WHERE v.rowid=".((int) $val[
"paymentvariousid"]);
1566 $ref = $langs->transnoentitiesnoconv(
"VariousPayment");
1569 if (empty($sqlmid)) {
1570 dol_syslog(
"Found a typerecord=".$typerecord.
" not supported", LOG_WARNING);
1574 dol_syslog(
"accountancy/journal/bankjournal.php::sqlmid=".$sqlmid, LOG_DEBUG);
1575 $resultmid = $db->query($sqlmid);
1577 while ($objmid = $db->fetch_object($resultmid)) {
1578 $ref .=
' '.$objmid->ref;
1585 $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.