35 require
'../../main.inc.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
40 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
44 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
45 require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
46 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
47 require_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
48 require_once DOL_DOCUMENT_ROOT.
'/don/class/paymentdonation.class.php';
49 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
50 require_once DOL_DOCUMENT_ROOT.
'/salaries/class/paymentsalary.class.php';
51 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
52 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
53 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
54 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
55 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
56 require_once DOL_DOCUMENT_ROOT.
'/societe/class/client.class.php';
57 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
58 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/paymentexpensereport.class.php';
59 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
60 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
61 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
62 require_once DOL_DOCUMENT_ROOT.
'/loan/class/paymentloan.class.php';
63 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
66 $langs->loadLangs(array(
"companies",
"other",
"compta",
"banks",
"bills",
"donations",
"loan",
"accountancy",
"trips",
"salaries",
"hrm",
"members"));
69 $id_journal =
GETPOST(
'id_journal',
'int');
71 $date_startmonth =
GETPOST(
'date_startmonth',
'int');
72 $date_startday =
GETPOST(
'date_startday',
'int');
73 $date_startyear =
GETPOST(
'date_startyear',
'int');
74 $date_endmonth =
GETPOST(
'date_endmonth',
'int');
75 $date_endday =
GETPOST(
'date_endday',
'int');
76 $date_endyear =
GETPOST(
'date_endyear',
'int');
77 $in_bookkeeping =
GETPOST(
'in_bookkeeping',
'aZ09');
78 if ($in_bookkeeping ==
'') {
79 $in_bookkeeping =
'notyet';
84 $action =
GETPOST(
'action',
'aZ09');
90 if ($user->socid > 0) {
93 if (!$user->hasRight(
'accounting',
'mouvements',
'lire')) {
104 $date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
105 $date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
107 if (empty($date_startmonth) || empty($date_endmonth)) {
110 $date_start = $dates[
'date_start'];
111 $date_end = $dates[
'date_end'];
112 $pastmonthyear = $dates[
'pastmonthyear'];
113 $pastmonth = $dates[
'pastmonth'];
116 if (!
GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end))) {
121 $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,";
122 $sql .=
" ba.courant, ba.ref as baref, ba.account_number, ba.fk_accountancy_journal,";
123 $sql .=
" soc.rowid as socid, soc.nom as name, soc.email as email, bu1.type as typeop_company,";
124 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
125 $sql .=
" spe.accountancy_code_customer as code_compta,";
126 $sql .=
" spe.accountancy_code_supplier as code_compta_fournisseur,";
128 $sql .=
" soc.code_compta,";
129 $sql .=
" soc.code_compta_fournisseur,";
131 $sql .=
" u.accountancy_code, u.rowid as userid, u.lastname as lastname, u.firstname as firstname, u.email as useremail, u.statut as userstatus,";
132 $sql .=
" bu2.type as typeop_user,";
133 $sql .=
" bu3.type as typeop_payment, bu4.type as typeop_payment_supplier";
134 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
135 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"bank_account as ba on b.fk_account=ba.rowid";
136 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'";
137 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON bu2.fk_bank = b.rowid AND bu2.type='user'";
138 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu3 ON bu3.fk_bank = b.rowid AND bu3.type='payment'";
139 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu4 ON bu4.fk_bank = b.rowid AND bu4.type='payment_supplier'";
140 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as soc on bu1.url_id=soc.rowid";
141 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
142 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = soc.rowid AND spe.entity = " . ((int) $conf->entity);
144 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on bu2.url_id=u.rowid";
145 $sql .=
" WHERE ba.fk_accountancy_journal=".((int) $id_journal);
146 $sql .=
' AND b.amount <> 0 AND ba.entity IN ('.getEntity(
'bank_account', 0).
')';
147 if ($date_start && $date_end) {
148 $sql .=
" AND b.dateo >= '".$db->idate($date_start).
"' AND b.dateo <= '".$db->idate($date_end).
"'";
152 $sql .=
" AND b.dateo >= '".$db->idate(
getDolGlobalInt(
'ACCOUNTING_DATE_START_BINDING')).
"'";
155 if ($in_bookkeeping ==
'already') {
156 $sql .=
" AND (b.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
158 if ($in_bookkeeping ==
'notyet') {
159 $sql .=
" AND (b.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
161 $sql .=
" ORDER BY b.datev";
167 $societestatic =
new Societe($db);
168 $userstatic =
new User($db);
169 $bankaccountstatic =
new Account($db);
172 $paymentvatstatic =
new Tva($db);
181 $tmpinvoice =
new Facture($db);
187 $accountingjournalstatic->fetch($id_journal);
188 $journal = $accountingjournalstatic->code;
189 $journal_label = $accountingjournalstatic->label;
192 dol_syslog(
"accountancy/journal/bankjournal.php", LOG_DEBUG);
193 $result = $db->query(
$sql);
195 $num = $db->num_rows($result);
201 $account_employee =
getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT',
'NotDefined');
203 $account_pay_donation =
getDolGlobalString(
'DONATION_ACCOUNTINGACCOUNT',
'NotDefined');
204 $account_pay_subscription =
getDolGlobalString(
'ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT',
'NotDefined');
205 $account_transfer =
getDolGlobalString(
'ACCOUNTING_ACCOUNT_TRANSFER_CASH',
'NotDefined');
207 $tabcompany = array();
213 $tabmoreinfo = array();
221 $obj = $db->fetch_object($result);
223 $lineisapurchase = -1;
226 if ($obj->label ==
'(SupplierInvoicePayment)' || $obj->label ==
'(SupplierInvoicePaymentBack)') {
227 $lineisapurchase = 1;
229 if ($obj->label ==
'(CustomerInvoicePayment)' || $obj->label ==
'(CustomerInvoicePaymentBack)') {
233 if ($lineisapurchase < 0) {
234 if ($obj->typeop_payment_supplier ==
'payment_supplier') {
235 $lineisapurchase = 1;
238 if ($lineisasale < 0) {
239 if ($obj->typeop_payment ==
'payment') {
247 $compta_bank = $obj->account_number;
250 $compta_soc =
'NotDefined';
251 if ($lineisapurchase > 0) {
252 $compta_soc = (($obj->code_compta_fournisseur !=
"") ? $obj->code_compta_fournisseur : $account_supplier);
254 if ($lineisasale > 0) {
255 $compta_soc = (!empty($obj->code_compta) ? $obj->code_compta : $account_customer);
258 $tabcompany[$obj->rowid] = array(
260 'name' => $obj->name,
261 'code_compta' => $compta_soc,
262 'email' => $obj->email
267 $compta_user = (!empty($obj->accountancy_code) ? $obj->accountancy_code :
'');
269 $tabuser[$obj->rowid] = array(
270 'id' => $obj->userid,
272 'lastname' => $obj->lastname,
273 'firstname' => $obj->firstname,
274 'email' => $obj->useremail,
275 'accountancy_code' => $compta_user,
276 'status' => $obj->userstatus
280 $tabpay[$obj->rowid][
"date"] = $obj->do;
281 $tabpay[$obj->rowid][
"type_payment"] = $obj->fk_type;
282 $tabpay[$obj->rowid][
"ref"] = $obj->label;
283 $tabpay[$obj->rowid][
"fk_bank"] = $obj->rowid;
284 $tabpay[$obj->rowid][
"bank_account_ref"] = $obj->baref;
285 $tabpay[$obj->rowid][
"fk_bank_account"] = $obj->fk_account;
287 if (preg_match(
'/^\((.*)\)$/i', $obj->label, $reg)) {
288 $tabpay[$obj->rowid][
"lib"] = $langs->trans($reg[1]);
290 $tabpay[$obj->rowid][
"lib"] =
dol_trunc($obj->label, 60);
294 $links = $object->get_url($obj->rowid);
297 $tabpay[$obj->rowid][
'type'] =
'unknown';
298 $tabtype[$obj->rowid] =
'unknown';
299 $tabmoreinfo[$obj->rowid] = array();
301 $amounttouse = $obj->amount;
302 if (!empty($obj->amount_main_currency)) {
304 $amounttouse = $obj->amount_main_currency;
308 if (is_array($links) && count($links) > 0) {
310 foreach ($links as $v) {
311 if ($v[
'type'] ==
'sc') {
317 foreach ($links as $key => $val) {
318 if ($links[$key][
'type'] ==
'user' && !$is_sc)
continue;
319 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'))) {
323 $tabpay[$obj->rowid][
'type'] = $links[$key][
'type'];
324 $tabtype[$obj->rowid] = $links[$key][
'type'];
325 } elseif (in_array($links[$key][
'type'], array(
'company',
'user'))) {
326 if ($tabpay[$obj->rowid][
'type'] ==
'unknown') {
333 if ($links[$key][
'type'] ==
'withdraw') {
334 $tabmoreinfo[$obj->rowid][
'withdraw'] = 1;
337 if ($links[$key][
'type'] ==
'payment') {
338 $paymentstatic->id = $links[$key][
'url_id'];
339 $paymentstatic->ref = $links[$key][
'url_id'];
340 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentstatic->getNomUrl(2,
'',
'');
341 $tabpay[$obj->rowid][
"paymentid"] = $paymentstatic->id;
342 } elseif ($links[$key][
'type'] ==
'payment_supplier') {
343 $paymentsupplierstatic->id = $links[$key][
'url_id'];
344 $paymentsupplierstatic->ref = $links[$key][
'url_id'];
345 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentsupplierstatic->getNomUrl(2);
346 $tabpay[$obj->rowid][
"paymentsupplierid"] = $paymentsupplierstatic->id;
347 } elseif ($links[$key][
'type'] ==
'company') {
348 $societestatic->id = $links[$key][
'url_id'];
349 $societestatic->name = $links[$key][
'label'];
350 $societestatic->email = $tabcompany[$obj->rowid][
'email'];
351 $tabpay[$obj->rowid][
"soclib"] = $societestatic->getNomUrl(1,
'', 30);
353 if (empty($tabtp[$obj->rowid][$compta_soc])) {
354 $tabtp[$obj->rowid][$compta_soc] = $amounttouse;
356 $tabtp[$obj->rowid][$compta_soc] += $amounttouse;
359 } elseif ($links[$key][
'type'] ==
'user') {
360 $userstatic->id = $links[$key][
'url_id'];
361 $userstatic->name = $links[$key][
'label'];
362 $userstatic->email = $tabuser[$obj->rowid][
'email'];
363 $userstatic->firstname = $tabuser[$obj->rowid][
'firstname'];
364 $userstatic->lastname = $tabuser[$obj->rowid][
'lastname'];
365 $userstatic->statut = $tabuser[$obj->rowid][
'status'];
366 $userstatic->accountancy_code = $tabuser[$obj->rowid][
'accountancy_code'];
367 if ($userstatic->id > 0) {
368 $tabpay[$obj->rowid][
"soclib"] = $userstatic->getNomUrl(1,
'accountancy', 0);
370 $tabpay[$obj->rowid][
"soclib"] =
'???';
373 $tabtp[$obj->rowid][$compta_user] += $amounttouse;
375 } elseif ($links[$key][
'type'] ==
'sc') {
376 $chargestatic->id = $links[$key][
'url_id'];
377 $chargestatic->ref = $links[$key][
'url_id'];
379 $tabpay[$obj->rowid][
"lib"] .=
' '.$chargestatic->getNomUrl(2);
381 if (preg_match(
'/^\((.*)\)$/i', $links[$key][
'label'], $reg)) {
382 if ($reg[1] ==
'socialcontribution') {
383 $reg[1] =
'SocialContribution';
385 $chargestatic->label = $langs->trans($reg[1]);
387 $chargestatic->label = $links[$key][
'label'];
389 $chargestatic->ref = $chargestatic->label;
390 $tabpay[$obj->rowid][
"soclib"] = $chargestatic->getNomUrl(1, 30);
391 $tabpay[$obj->rowid][
"paymentscid"] = $chargestatic->id;
395 $sqlmid =
"SELECT cchgsoc.accountancy_code";
396 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales cchgsoc";
397 $sqlmid .=
" INNER JOIN ".MAIN_DB_PREFIX.
"chargesociales as chgsoc ON chgsoc.fk_type = cchgsoc.id";
398 $sqlmid .=
" INNER JOIN ".MAIN_DB_PREFIX.
"paiementcharge as paycharg ON paycharg.fk_charge = chgsoc.rowid";
399 $sqlmid .=
" INNER JOIN ".MAIN_DB_PREFIX.
"bank_url as bkurl ON bkurl.url_id=paycharg.rowid AND bkurl.type = 'payment_sc'";
400 $sqlmid .=
" WHERE bkurl.fk_bank = ".((int) $obj->rowid);
402 dol_syslog(
"accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);
403 $resultmid = $db->query($sqlmid);
405 $objmid = $db->fetch_object($resultmid);
406 $tabtp[$obj->rowid][$objmid->accountancy_code] += $amounttouse;
408 } elseif ($links[$key][
'type'] ==
'payment_donation') {
409 $paymentdonstatic->id = $links[$key][
'url_id'];
410 $paymentdonstatic->ref = $links[$key][
'url_id'];
411 $paymentdonstatic->fk_donation = $links[$key][
'url_id'];
412 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentdonstatic->getNomUrl(2);
413 $tabpay[$obj->rowid][
"paymentdonationid"] = $paymentdonstatic->id;
414 $tabtp[$obj->rowid][$account_pay_donation] += $amounttouse;
415 } elseif ($links[$key][
'type'] ==
'member') {
416 $paymentsubscriptionstatic->id = $links[$key][
'url_id'];
417 $paymentsubscriptionstatic->ref = $links[$key][
'url_id'];
418 $paymentsubscriptionstatic->label = $links[$key][
'label'];
419 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentsubscriptionstatic->getNomUrl(2);
420 $tabpay[$obj->rowid][
"paymentsubscriptionid"] = $paymentsubscriptionstatic->id;
421 $paymentsubscriptionstatic->fetch($paymentsubscriptionstatic->id);
422 $tabtp[$obj->rowid][$account_pay_subscription] += $amounttouse;
423 } elseif ($links[$key][
'type'] ==
'payment_vat') {
424 $paymentvatstatic->id = $links[$key][
'url_id'];
425 $paymentvatstatic->ref = $links[$key][
'url_id'];
426 $paymentvatstatic->label = $links[$key][
'label'];
427 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentvatstatic->getNomUrl(2);
428 $tabpay[$obj->rowid][
"paymentvatid"] = $paymentvatstatic->id;
429 $tabtp[$obj->rowid][$account_pay_vat] += $amounttouse;
430 } elseif ($links[$key][
'type'] ==
'payment_salary') {
431 $paymentsalstatic->id = $links[$key][
'url_id'];
432 $paymentsalstatic->ref = $links[$key][
'url_id'];
433 $paymentsalstatic->label = $links[$key][
'label'];
434 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentsalstatic->getNomUrl(2);
435 $tabpay[$obj->rowid][
"paymentsalid"] = $paymentsalstatic->id;
439 if (!empty($conf->global->ACCOUNTANCY_AUTOFIX_MISSING_LINK_TO_USEr_ON_SALARY_BANK_PAYMENT)) {
440 $tmpsalary =
new Salary($db);
441 $tmpsalary->fetch($paymentsalstatic->id);
442 $tmpsalary->fetch_user($tmpsalary->fk_user);
444 $userstatic->id = $tmpsalary->user->id;
445 $userstatic->name = $tmpsalary->user->name;
446 $userstatic->email = $tmpsalary->user->email;
447 $userstatic->firstname = $tmpsalary->user->firstname;
448 $userstatic->lastname = $tmpsalary->user->lastname;
449 $userstatic->statut = $tmpsalary->user->statut;
450 $userstatic->accountancy_code = $tmpsalary->user->accountancy_code;
452 if ($userstatic->id > 0) {
453 $tabpay[$obj->rowid][
"soclib"] = $userstatic->getNomUrl(1,
'accountancy', 0);
455 $tabpay[$obj->rowid][
"soclib"] =
'???';
458 if (empty($obj->typeop_user)) {
459 $compta_user = $userstatic->accountancy_code;
461 $tabtp[$obj->rowid][$compta_user] += $amounttouse;
462 $tabuser[$obj->rowid] = array(
463 'id' => $userstatic->id,
465 'lastname' => $userstatic->lastname,
466 'firstname' => $userstatic->firstname,
467 'email' => $userstatic->email,
468 'accountancy_code' => $compta_user,
469 'status' => $userstatic->statut
474 } elseif ($links[$key][
'type'] ==
'payment_expensereport') {
475 $paymentexpensereportstatic->id = $links[$key][
'url_id'];
476 $tabpay[$obj->rowid][
"lib"] .= $paymentexpensereportstatic->getNomUrl(2);
477 $tabpay[$obj->rowid][
"paymentexpensereport"] = $paymentexpensereportstatic->id;
478 } elseif ($links[$key][
'type'] ==
'payment_various') {
479 $paymentvariousstatic->id = $links[$key][
'url_id'];
480 $paymentvariousstatic->ref = $links[$key][
'url_id'];
481 $paymentvariousstatic->label = $links[$key][
'label'];
482 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentvariousstatic->getNomUrl(2);
483 $tabpay[$obj->rowid][
"paymentvariousid"] = $paymentvariousstatic->id;
484 $paymentvariousstatic->fetch($paymentvariousstatic->id);
485 $account_various = (!empty($paymentvariousstatic->accountancy_code) ? $paymentvariousstatic->accountancy_code :
'NotDefined');
486 $account_subledger = (!empty($paymentvariousstatic->subledger_account) ? $paymentvariousstatic->subledger_account :
'');
487 $tabpay[$obj->rowid][
"account_various"] = $account_various;
488 $tabtp[$obj->rowid][$account_subledger] += $amounttouse;
489 } elseif ($links[$key][
'type'] ==
'payment_loan') {
490 $paymentloanstatic->id = $links[$key][
'url_id'];
491 $paymentloanstatic->ref = $links[$key][
'url_id'];
492 $paymentloanstatic->fk_loan = $links[$key][
'url_id'];
493 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentloanstatic->getNomUrl(2);
494 $tabpay[$obj->rowid][
"paymentloanid"] = $paymentloanstatic->id;
496 $sqlmid =
'SELECT pl.amount_capital, pl.amount_insurance, pl.amount_interest, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest';
497 $sqlmid .=
' FROM '.MAIN_DB_PREFIX.
'payment_loan as pl, '.MAIN_DB_PREFIX.
'loan as l';
498 $sqlmid .=
' WHERE l.rowid = pl.fk_loan AND pl.fk_bank = '.((int) $obj->rowid);
500 dol_syslog(
"accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);
501 $resultmid = $db->query($sqlmid);
503 $objmid = $db->fetch_object($resultmid);
504 $tabtp[$obj->rowid][$objmid->accountancy_account_capital] -= $objmid->amount_capital;
505 $tabtp[$obj->rowid][$objmid->accountancy_account_insurance] -= $objmid->amount_insurance;
506 $tabtp[$obj->rowid][$objmid->accountancy_account_interest] -= $objmid->amount_interest;
508 } elseif ($links[$key][
'type'] ==
'banktransfert') {
509 $accountLinestatic->fetch($links[$key][
'url_id']);
510 $tabpay[$obj->rowid][
"lib"] .=
' '.$langs->trans(
"BankTransfer").
'- '.$accountLinestatic ->getNomUrl(1);
511 $tabtp[$obj->rowid][$account_transfer] += $amounttouse;
512 $bankaccountstatic->fetch($tabpay[$obj->rowid][
'fk_bank_account']);
513 $tabpay[$obj->rowid][
"soclib"] = $bankaccountstatic->getNomUrl(2);
518 if (empty($tabbq[$obj->rowid][$compta_bank])) {
519 $tabbq[$obj->rowid][$compta_bank] = $amounttouse;
521 $tabbq[$obj->rowid][$compta_bank] += $amounttouse;
526 if (empty($tabtp[$obj->rowid]) && !empty($tabmoreinfo[$obj->rowid][
'withdraw'])) {
527 foreach ($links as $key => $val) {
528 if ($links[$key][
'type'] ==
'payment') {
530 $tmppayment->fetch($links[$key][
'url_id']);
531 $arrayofamounts = $tmppayment->getAmountsArray();
532 if (is_array($arrayofamounts)) {
533 foreach ($arrayofamounts as $invoiceid => $amount) {
534 $tmpinvoice->fetch($invoiceid);
535 $tmpinvoice->fetch_thirdparty();
536 if ($tmpinvoice->thirdparty->code_compta) {
537 $tabtp[$obj->rowid][$tmpinvoice->thirdparty->code_compta] += $amount;
546 if (empty($tabtp[$obj->rowid])) {
547 $tabtp[$obj->rowid][
'NotDefined'] = $tabbq[$obj->rowid][$compta_bank];
585 if (!$error && $action ==
'writebookkeeping') {
589 $accountingaccountcustomer->fetch(
null, $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER,
true);
592 $accountingaccountsupplier->fetch(
null, $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER,
true);
595 $accountingaccountpayment->fetch(
null, $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT,
true);
598 $accountingaccountsuspense->fetch(
null, $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE,
true);
601 foreach ($tabpay as $key => $val) {
619 if (!$errorforline && is_array($tabbq[$key])) {
621 foreach ($tabbq[$key] as $k => $mt) {
623 $accountingaccount->fetch(
null, $k,
true);
624 $account_label = $accountingaccount->label;
627 if (!empty($val[
'lib'])) {
631 if (!empty($val[
'soclib'])) {
632 $reflabel .=
" - ".dol_string_nohtmltag($val[
'soclib']);
636 $bookkeeping->doc_date = $val[
"date"];
637 $bookkeeping->doc_ref = $ref;
638 $bookkeeping->doc_type =
'bank';
639 $bookkeeping->fk_doc = $key;
640 $bookkeeping->fk_docdet = $val[
"fk_bank"];
642 $bookkeeping->numero_compte = $k;
643 $bookkeeping->label_compte = $account_label;
645 $bookkeeping->label_operation = $reflabel;
646 $bookkeeping->montant = $mt;
647 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
648 $bookkeeping->debit = ($mt >= 0 ? $mt : 0);
649 $bookkeeping->credit = ($mt < 0 ? -$mt : 0);
650 $bookkeeping->code_journal = $journal;
651 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
652 $bookkeeping->fk_user_author = $user->id;
653 $bookkeeping->date_creation = $now;
656 $bookkeeping->subledger_account =
'';
657 $bookkeeping->label_operation = $reflabel;
658 $bookkeeping->entity = $conf->entity;
660 $totaldebit += $bookkeeping->debit;
661 $totalcredit += $bookkeeping->credit;
663 $result = $bookkeeping->create($user);
665 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
668 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded',
null,
'warnings');
680 if (!$errorforline) {
681 if (is_array($tabtp[$key])) {
683 foreach ($tabtp[$key] as $k => $mt) {
688 if (!empty($val[
'lib'])) {
691 if ($tabtype[$key] ==
'banktransfert') {
692 $reflabel .=
dol_string_nohtmltag($langs->transnoentitiesnoconv(
'TransitionalAccount').
' '.$account_transfer);
698 $bookkeeping->doc_date = $val[
"date"];
699 $bookkeeping->doc_ref = $ref;
700 $bookkeeping->doc_type =
'bank';
701 $bookkeeping->fk_doc = $key;
702 $bookkeeping->fk_docdet = $val[
"fk_bank"];
704 $bookkeeping->label_operation = $reflabel;
705 $bookkeeping->montant = $mt;
706 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
707 $bookkeeping->debit = ($mt < 0 ? -$mt : 0);
708 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
709 $bookkeeping->code_journal = $journal;
710 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
711 $bookkeeping->fk_user_author = $user->id;
712 $bookkeeping->date_creation = $now;
714 if ($tabtype[$key] ==
'payment') {
716 $bookkeeping->subledger_account = $k;
717 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
718 $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
719 $bookkeeping->label_compte = $accountingaccountcustomer->label;
720 } elseif ($tabtype[$key] ==
'payment_supplier') {
722 $bookkeeping->subledger_account = $k;
723 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
724 $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER;
725 $bookkeeping->label_compte = $accountingaccountsupplier->label;
726 } elseif ($tabtype[$key] ==
'payment_expensereport') {
727 $bookkeeping->subledger_account = $tabuser[$key][
'accountancy_code'];
728 $bookkeeping->subledger_label = $tabuser[$key][
'name'];
729 $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT;
730 $bookkeeping->label_compte = $accountingaccountpayment->label;
731 } elseif ($tabtype[$key] ==
'payment_salary') {
732 $bookkeeping->subledger_account = $tabuser[$key][
'accountancy_code'];
733 $bookkeeping->subledger_label = $tabuser[$key][
'name'];
734 $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT;
735 $bookkeeping->label_compte = $accountingaccountpayment->label;
736 } elseif (in_array($tabtype[$key], array(
'sc',
'payment_sc'))) {
737 $bookkeeping->subledger_account =
'';
738 $bookkeeping->subledger_label =
'';
739 $accountingaccount->fetch(
null, $k,
true);
740 $bookkeeping->numero_compte = $k;
741 $bookkeeping->label_compte = $accountingaccount->label;
742 } elseif ($tabtype[$key] ==
'payment_vat') {
743 $bookkeeping->subledger_account =
'';
744 $bookkeeping->subledger_label =
'';
745 $accountingaccount->fetch(
null, $k,
true);
746 $bookkeeping->numero_compte = $k;
747 $bookkeeping->label_compte = $accountingaccount->label;
748 } elseif ($tabtype[$key] ==
'payment_donation') {
749 $bookkeeping->subledger_account =
'';
750 $bookkeeping->subledger_label =
'';
751 $accountingaccount->fetch(
null, $k,
true);
752 $bookkeeping->numero_compte = $k;
753 $bookkeeping->label_compte = $accountingaccount->label;
754 } elseif ($tabtype[$key] ==
'member') {
755 $bookkeeping->subledger_account =
'';
756 $bookkeeping->subledger_label =
'';
757 $accountingaccount->fetch(
null, $k,
true);
758 $bookkeeping->numero_compte = $k;
759 $bookkeeping->label_compte = $accountingaccount->label;
760 } elseif ($tabtype[$key] ==
'payment_loan') {
761 $bookkeeping->subledger_account =
'';
762 $bookkeeping->subledger_label =
'';
763 $accountingaccount->fetch(
null, $k,
true);
764 $bookkeeping->numero_compte = $k;
765 $bookkeeping->label_compte = $accountingaccount->label;
766 } elseif ($tabtype[$key] ==
'payment_various') {
767 $bookkeeping->subledger_account = $k;
768 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
769 $accountingaccount->fetch(
null, $tabpay[$key][
"account_various"],
true);
770 $bookkeeping->numero_compte = $tabpay[$key][
"account_various"];
771 $bookkeeping->label_compte = $accountingaccount->label;
772 } elseif ($tabtype[$key] ==
'banktransfert') {
773 $bookkeeping->subledger_account =
'';
774 $bookkeeping->subledger_label =
'';
775 $accountingaccount->fetch(
null, $k,
true);
776 $bookkeeping->numero_compte = $k;
777 $bookkeeping->label_compte = $accountingaccount->label;
779 if ($tabtype[$key] ==
'unknown') {
781 $bookkeeping->subledger_account =
'';
782 $bookkeeping->subledger_label =
'';
783 $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE;
784 $bookkeeping->label_compte = $accountingaccountsuspense->label;
787 $bookkeeping->label_operation = $reflabel;
788 $bookkeeping->entity = $conf->entity;
790 $totaldebit += $bookkeeping->debit;
791 $totalcredit += $bookkeeping->credit;
793 $result = $bookkeeping->create($user);
795 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
798 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded',
null,
'warnings');
806 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/lettering.class.php';
808 $nb_lettering = $lettering_static->bookkeepingLetteringAll(array($bookkeeping->id));
814 foreach ($tabbq[$key] as $k => $mt) {
817 if (!empty($val[
'lib'])) {
823 $bookkeeping->doc_date = $val[
"date"];
824 $bookkeeping->doc_ref = $ref;
825 $bookkeeping->doc_type =
'bank';
826 $bookkeeping->fk_doc = $key;
827 $bookkeeping->fk_docdet = $val[
"fk_bank"];
828 $bookkeeping->montant = $mt;
829 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
830 $bookkeeping->debit = ($mt < 0 ? -$mt : 0);
831 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
832 $bookkeeping->code_journal = $journal;
833 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
834 $bookkeeping->fk_user_author = $user->id;
835 $bookkeeping->date_creation = $now;
836 $bookkeeping->label_compte =
'';
837 $bookkeeping->label_operation = $reflabel;
838 $bookkeeping->entity = $conf->entity;
840 $totaldebit += $bookkeeping->debit;
841 $totalcredit += $bookkeeping->credit;
843 $result = $bookkeeping->create($user);
846 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
849 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded',
null,
'warnings');
864 setEventMessages(
'Try to insert a non balanced transaction in book for '.$ref.
'. Canceled. Surely a bug.',
null,
'errors');
867 if (!$errorforline) {
874 if ($error >= $MAXNBERRORS) {
875 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped").
' (>'.$MAXNBERRORS.
')',
null,
'errors');
881 if (empty($error) && count($tabpay) > 0) {
883 } elseif (count($tabpay) == $error) {
886 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
892 if (count($tabpay) != $error) {
893 $param =
'id_journal='.$id_journal;
894 $param .=
'&date_startday='.$date_startday;
895 $param .=
'&date_startmonth='.$date_startmonth;
896 $param .=
'&date_startyear='.$date_startyear;
897 $param .=
'&date_endday='.$date_endday;
898 $param .=
'&date_endmonth='.$date_endmonth;
899 $param .=
'&date_endyear='.$date_endyear;
900 $param .=
'&in_bookkeeping='.$in_bookkeeping;
901 header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
909 if ($action ==
'exportcsv') {
912 $filename =
'journal';
913 $type_export =
'journal';
914 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
917 print
'"'.$langs->transnoentitiesnoconv(
"BankId").
'"'.$sep;
918 print
'"'.$langs->transnoentitiesnoconv(
"Date").
'"'.$sep;
919 print
'"'.$langs->transnoentitiesnoconv(
"PaymentMode").
'"'.$sep;
920 print
'"'.$langs->transnoentitiesnoconv(
"AccountAccounting").
'"'.$sep;
921 print
'"'.$langs->transnoentitiesnoconv(
"LedgerAccount").
'"'.$sep;
922 print
'"'.$langs->transnoentitiesnoconv(
"SubledgerAccount").
'"'.$sep;
923 print
'"'.$langs->transnoentitiesnoconv(
"Label").
'"'.$sep;
924 print
'"'.$langs->transnoentitiesnoconv(
"AccountingDebit").
'"'.$sep;
925 print
'"'.$langs->transnoentitiesnoconv(
"AccountingCredit").
'"'.$sep;
926 print
'"'.$langs->transnoentitiesnoconv(
"Journal").
'"'.$sep;
927 print
'"'.$langs->transnoentitiesnoconv(
"Note").
'"'.$sep;
930 foreach ($tabpay as $key => $val) {
936 foreach ($tabbq[$key] as $k => $mt) {
939 if (!empty($val[
'lib'])) {
943 if (!empty($val[
'soclib'])) {
944 $reflabel .=
" - ".dol_string_nohtmltag($val[
'soclib']);
947 print
'"'.$key.
'"'.$sep;
948 print
'"'.$date.
'"'.$sep;
949 print
'"'.$val[
"type_payment"].
'"'.$sep;
950 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
951 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
953 print
'"'.$reflabel.
'"'.$sep;
954 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
955 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
956 print
'"'.$journal.
'"'.$sep;
957 print
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
963 if (is_array($tabtp[$key])) {
964 foreach ($tabtp[$key] as $k => $mt) {
967 if (!empty($val[
'lib'])) {
970 if ($tabtype[$key] ==
'banktransfert') {
971 $reflabel .=
dol_string_nohtmltag($langs->transnoentitiesnoconv(
'TransitionalAccount').
' '.$account_transfer);
976 print
'"'.$key.
'"'.$sep;
977 print
'"'.$date.
'"'.$sep;
978 print
'"'.$val[
"type_payment"].
'"'.$sep;
979 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
980 if ($tabtype[$key] ==
'payment_supplier') {
981 print
'"'.getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUPPLIER').
'"'.$sep;
982 } elseif ($tabtype[$key] ==
'payment') {
983 print
'"'.getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER').
'"'.$sep;
984 } elseif ($tabtype[$key] ==
'payment_expensereport') {
985 print
'"'.getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT').
'"'.$sep;
986 } elseif ($tabtype[$key] ==
'payment_salary') {
987 print
'"'.getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT').
'"'.$sep;
989 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
991 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
992 print
'"'.$reflabel.
'"'.$sep;
993 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
994 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
995 print
'"'.$journal.
'"'.$sep;
996 print
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
1001 foreach ($tabbq[$key] as $k => $mt) {
1004 if (!empty($val[
'lib'])) {
1009 print
'"'.$key.
'"'.$sep;
1010 print
'"'.$date.
'"'.$sep;
1011 print
'"'.$val[
"type_payment"].
'"'.$sep;
1012 print
'"'.length_accountg(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUSPENSE')).
'"'.$sep;
1013 print
'"'.length_accounta(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUSPENSE')).
'"'.$sep;
1015 print
'"'.$reflabel.
'"'.$sep;
1016 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1017 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1018 print
'"'.$journal.
'"'.$sep;
1019 print
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
1034 if (empty($action) || $action ==
'view') {
1035 $invoicestatic =
new Facture($db);
1038 $vatstatic =
new Tva($db);
1039 $donationstatic =
new Don($db);
1040 $loanstatic =
new Loan($db);
1041 $salarystatic =
new Salary($db);
1044 $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1,
'', 1);
1051 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
1053 $listofchoices = array(
1054 'notyet'=>$langs->trans(
"NotYetInGeneralLedger"),
1055 'already'=>$langs->trans(
"AlreadyInGeneralLedger")
1057 $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);
1058 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.
$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
1060 $varlink =
'id_journal='.$id_journal;
1064 journalHead($nom,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
1069 $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";
1070 $resql = $db->query(
$sql);
1072 $obj = $db->fetch_object($resql);
1074 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheJournalCodeIsNotDefinedOnSomeBankAccount");
1075 $desc =
' : '.$langs->trans(
"AccountancyAreaDescBank", 9,
'{link}');
1076 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"BankAccounts").
'</strong>', $desc);
1089 print ($desc ?
'' :
'<br>').
'<div class="warning">'.
img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
1090 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
1091 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
1097 print
'<div class="tabsAction tabsActionNoBottom centerimp">';
1099 if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping ==
'notyet') {
1100 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
1105 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
1107 if ($in_bookkeeping ==
'notyet') {
1108 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
1110 print
'<a class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
1118 <script type="text/javascript">
1119 function launch_export() {
1120 console.log("Set value into form and submit");
1121 $("div.fiche form input[name=\"action\"]").val("exportcsv");
1122 $("div.fiche form input[type=\"submit\"]").click();
1123 $("div.fiche form input[name=\"action\"]").val("");
1125 function writebookkeeping() {
1126 console.log("Set value into form and submit");
1127 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
1128 $("div.fiche form input[type=\"submit\"]").click();
1129 $("div.fiche form input[name=\"action\"]").val("");
1139 print
'<div class="div-table-responsive">';
1140 print
'<table class="noborder centpercent">';
1141 print
'<tr class="liste_titre">';
1142 print
"<td>".$langs->trans(
"Date").
"</td>";
1143 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"ObjectsRef").
")</td>";
1144 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
1145 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
1146 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
1147 print
'<td class="center">'.$langs->trans(
"PaymentMode").
"</td>";
1148 print
'<td class="right">'.$langs->trans(
"AccountingDebit").
"</td>";
1149 print
'<td class="right">'.$langs->trans(
"AccountingCredit").
"</td>";
1154 foreach ($tabpay as $key => $val) {
1160 foreach ($tabbq[$key] as $k => $mt) {
1163 if (!empty($val[
'lib'])) {
1164 $reflabel .= $val[
'lib'].
" - ";
1166 $reflabel .= $langs->trans(
"Bank").
' '.$val[
'bank_account_ref'];
1167 if (!empty($val[
'soclib'])) {
1168 $reflabel .=
" - ".$val[
'soclib'];
1172 print
'<!-- Bank bank.rowid='.$key.
' type='.$tabpay[$key][
'type'].
' ref='.$tabpay[$key][
'ref'].
'-->';
1173 print
'<tr class="oddeven">';
1176 print
"<td>".$date.
"</td>";
1179 print
"<td>".dol_escape_htmltag($ref).
"</td>";
1183 if (empty($accounttoshow) || $accounttoshow ==
'NotDefined') {
1184 $accounttoshow =
'<span class="error">'.$langs->trans(
"BankAccountNotDefined").
'</span>';
1186 print
'<td class="maxwidth300" title="'.dol_escape_htmltag(
dol_string_nohtmltag($accounttoshow)).
'">';
1187 print $accounttoshow;
1191 print
'<td class="maxwidth300">';
1205 print
'<td class="center">'.$val[
"type_payment"].
"</td>";
1206 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1207 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1215 if (is_array($tabtp[$key])) {
1216 foreach ($tabtp[$key] as $k => $mt) {
1219 if (!empty($val[
'lib'])) {
1220 $reflabel .= $val[
'lib'].($val[
'soclib'] ?
" - " :
"");
1222 if ($tabtype[$key] ==
'banktransfert') {
1223 $reflabel .= $langs->trans(
'TransitionalAccount').
' '.$account_transfer;
1225 $reflabel .= $val[
'soclib'];
1228 print
'<!-- Thirdparty bank.rowid='.$key.
' -->';
1229 print
'<tr class="oddeven">';
1232 print
"<td>".$date.
"</td>";
1235 print
"<td>".dol_escape_htmltag($ref).
"</td>";
1238 $account_ledger = $k;
1240 if ($tabtype[$key] ==
'payment') {
1243 if ($tabtype[$key] ==
'payment_supplier') {
1246 if ($tabtype[$key] ==
'payment_expensereport') {
1249 if ($tabtype[$key] ==
'payment_salary') {
1252 if ($tabtype[$key] ==
'payment_vat') {
1255 if ($tabtype[$key] ==
'member') {
1258 if ($tabtype[$key] ==
'payment_various') {
1259 $account_ledger = $tabpay[$key][
"account_various"];
1262 if (empty($accounttoshow) || $accounttoshow ==
'NotDefined') {
1263 if ($tabtype[$key] ==
'unknown') {
1265 if (empty($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) || $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE ==
'-1') {
1266 $accounttoshow =
'<span class="error small">'.$langs->trans(
'UnknownAccountForThirdpartyAndWaitingAccountNotDefinedBlocking').
'</span>';
1268 $accounttoshow =
'<span class="warning small">'.$langs->trans(
'UnknownAccountForThirdparty',
length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE)).
'</span>';
1272 $errorstring =
'UnknownAccountForThirdpartyBlocking';
1273 if ($tabtype[$key] ==
'payment') {
1274 $errorstring =
'MainAccountForCustomersNotDefined';
1276 if ($tabtype[$key] ==
'payment_supplier') {
1277 $errorstring =
'MainAccountForSuppliersNotDefined';
1279 if ($tabtype[$key] ==
'payment_expensereport') {
1280 $errorstring =
'MainAccountForUsersNotDefined';
1282 if ($tabtype[$key] ==
'payment_salary') {
1283 $errorstring =
'MainAccountForUsersNotDefined';
1285 if ($tabtype[$key] ==
'payment_vat') {
1286 $errorstring =
'MainAccountForVatPaymentNotDefined';
1288 if ($tabtype[$key] ==
'member') {
1289 $errorstring =
'MainAccountForSubscriptionPaymentNotDefined';
1291 $accounttoshow =
'<span class="error small">'.$langs->trans($errorstring).
'</span>';
1294 print
'<td class="maxwidth300" title="'.dol_escape_htmltag(
dol_string_nohtmltag($accounttoshow)).
'">';
1295 print $accounttoshow;
1299 $accounttoshowsubledger =
'';
1300 if (in_array($tabtype[$key], array(
'payment',
'payment_supplier',
'payment_expensereport',
'payment_salary',
'payment_various'))) {
1302 if ($accounttoshow != $accounttoshowsubledger) {
1303 if (empty($accounttoshowsubledger) || $accounttoshowsubledger ==
'NotDefined') {
1308 if (!empty($tabcompany[$key][
'code_compta'])) {
1309 if (in_array($tabtype[$key], array(
'payment_various',
'payment_salary'))) {
1311 $accounttoshowsubledger =
'<span class="warning small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknownSubledgerIgnored").
'</span>';
1313 $accounttoshowsubledger =
'<span class="warning small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknown", $tabcompany[$key][
'code_compta']).
'</span>';
1316 $accounttoshowsubledger =
'<span class="error small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknownBlocking").
'</span>';
1320 $accounttoshowsubledger =
'';
1323 print
'<td class="maxwidth300">';
1324 print $accounttoshowsubledger;
1327 print
"<td>".$reflabel.
"</td>";
1329 print
'<td class="center">'.$val[
"type_payment"].
"</td>";
1331 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1333 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1341 foreach ($tabbq[$key] as $k => $mt) {
1344 if (!empty($val[
'lib'])) {
1345 $reflabel .= $val[
'lib'].
" - ";
1347 $reflabel .=
'WaitingAccount';
1349 print
'<!-- Wait bank.rowid='.$key.
' -->';
1350 print
'<tr class="oddeven">';
1351 print
"<td>".$date.
"</td>";
1352 print
"<td>".$ref.
"</td>";
1370 print
"<td>".$reflabel.
"</td>";
1371 print
'<td class="center">'.$val[
"type_payment"].
"</td>";
1372 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1373 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1384 print
'<tr class="oddeven"><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
1411 if ($ref ==
'(SupplierInvoicePayment)' || $ref ==
'(SupplierInvoicePaymentBack)') {
1412 $ref = $langs->transnoentitiesnoconv(
'Supplier');
1414 if ($ref ==
'(CustomerInvoicePayment)' || $ref ==
'(CustomerInvoicePaymentBack)') {
1415 $ref = $langs->transnoentitiesnoconv(
'Customer');
1417 if ($ref ==
'(SocialContributionPayment)') {
1418 $ref = $langs->transnoentitiesnoconv(
'SocialContribution');
1420 if ($ref ==
'(DonationPayment)') {
1421 $ref = $langs->transnoentitiesnoconv(
'Donation');
1423 if ($ref ==
'(SubscriptionPayment)') {
1424 $ref = $langs->transnoentitiesnoconv(
'Subscription');
1426 if ($ref ==
'(ExpenseReportPayment)') {
1427 $ref = $langs->transnoentitiesnoconv(
'Employee');
1429 if ($ref ==
'(LoanPayment)') {
1430 $ref = $langs->transnoentitiesnoconv(
'Loan');
1432 if ($ref ==
'(payment_salary)') {
1433 $ref = $langs->transnoentitiesnoconv(
'Employee');
1437 if ($typerecord ==
'payment') {
1439 $sqlmid =
"SELECT payfac.fk_facture as id, ".$db->ifsql(
'f1.rowid IS NULL',
'f.ref',
'f1.ref').
" as ref";
1440 $sqlmid .=
" FROM ".$db->prefix().
"paiement_facture as payfac";
1441 $sqlmid .=
" LEFT JOIN ".$db->prefix().
"facture as f ON f.rowid = payfac.fk_facture";
1442 $sqlmid .=
" LEFT JOIN ".$db->prefix().
"societe_remise_except as sre ON sre.fk_facture_source = payfac.fk_facture";
1443 $sqlmid .=
" LEFT JOIN ".$db->prefix().
"facture as f1 ON f1.rowid = sre.fk_facture";
1444 $sqlmid .=
" WHERE payfac.fk_paiement=".((int) $val[
'paymentid']);
1446 $sqlmid =
"SELECT payfac.fk_facture as id, f.ref as ref";
1447 $sqlmid .=
" FROM ".$db->prefix().
"paiement_facture as payfac";
1448 $sqlmid .=
" INNER JOIN ".$db->prefix().
"facture as f ON f.rowid = payfac.fk_facture";
1449 $sqlmid .=
" WHERE payfac.fk_paiement=".((int) $val[
'paymentid']);
1451 $ref = $langs->transnoentitiesnoconv(
"Invoice");
1452 } elseif ($typerecord ==
'payment_supplier') {
1453 $sqlmid =
'SELECT payfac.fk_facturefourn as id, f.ref';
1454 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as payfac, ".MAIN_DB_PREFIX.
"facture_fourn as f";
1455 $sqlmid .=
" WHERE payfac.fk_facturefourn = f.rowid AND payfac.fk_paiementfourn=".((int) $val[
"paymentsupplierid"]);
1456 $ref = $langs->transnoentitiesnoconv(
"SupplierInvoice");
1457 } elseif ($typerecord ==
'payment_expensereport') {
1458 $sqlmid =
'SELECT e.rowid as id, e.ref';
1459 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_expensereport as pe, ".MAIN_DB_PREFIX.
"expensereport as e";
1460 $sqlmid .=
" WHERE pe.rowid=".((int) $val[
"paymentexpensereport"]).
" AND pe.fk_expensereport = e.rowid";
1461 $ref = $langs->transnoentitiesnoconv(
"ExpenseReport");
1462 } elseif ($typerecord ==
'payment_salary') {
1463 $sqlmid =
'SELECT s.rowid as ref';
1464 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as s";
1465 $sqlmid .=
" WHERE s.rowid=".((int) $val[
"paymentsalid"]);
1466 $ref = $langs->transnoentitiesnoconv(
"SalaryPayment");
1467 } elseif ($typerecord ==
'sc') {
1468 $sqlmid =
'SELECT sc.rowid as ref';
1469 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"paiementcharge as sc";
1470 $sqlmid .=
" WHERE sc.rowid=".((int) $val[
"paymentscid"]);
1471 $ref = $langs->transnoentitiesnoconv(
"SocialContribution");
1472 } elseif ($typerecord ==
'payment_vat') {
1473 $sqlmid =
'SELECT v.rowid as ref';
1474 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"tva as v";
1475 $sqlmid .=
" WHERE v.rowid=".((int) $val[
"paymentvatid"]);
1476 $ref = $langs->transnoentitiesnoconv(
"PaymentVat");
1477 } elseif ($typerecord ==
'payment_donation') {
1478 $sqlmid =
'SELECT payd.fk_donation as ref';
1479 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_donation as payd";
1480 $sqlmid .=
" WHERE payd.fk_donation=".((int) $val[
"paymentdonationid"]);
1481 $ref = $langs->transnoentitiesnoconv(
"Donation");
1482 } elseif ($typerecord ==
'payment_loan') {
1483 $sqlmid =
'SELECT l.rowid as ref';
1484 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_loan as l";
1485 $sqlmid .=
" WHERE l.rowid=".((int) $val[
"paymentloanid"]);
1486 $ref = $langs->transnoentitiesnoconv(
"LoanPayment");
1487 } elseif ($typerecord ==
'payment_various') {
1488 $sqlmid =
'SELECT v.rowid as ref';
1489 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_various as v";
1490 $sqlmid .=
" WHERE v.rowid=".((int) $val[
"paymentvariousid"]);
1491 $ref = $langs->transnoentitiesnoconv(
"VariousPayment");
1494 if (empty($sqlmid)) {
1495 dol_syslog(
"Found a typerecord=".$typerecord.
" not supported", LOG_WARNING);
1499 dol_syslog(
"accountancy/journal/bankjournal.php::sqlmid=".$sqlmid, LOG_DEBUG);
1500 $resultmid = $db->query($sqlmid);
1502 while ($objmid = $db->fetch_object($resultmid)) {
1503 $ref .=
' '.$objmid->ref;
1510 $ref =
dol_trunc($langs->transnoentitiesnoconv(
"BankId").
' '.$val[
'fk_bank'].
' - '.$ref, 295);