34 require
'../../main.inc.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
39 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
40 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
44 require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
45 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
46 require_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
47 require_once DOL_DOCUMENT_ROOT.
'/don/class/paymentdonation.class.php';
48 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
49 require_once DOL_DOCUMENT_ROOT.
'/salaries/class/paymentsalary.class.php';
50 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
51 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
52 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
53 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
54 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
55 require_once DOL_DOCUMENT_ROOT.
'/societe/class/client.class.php';
56 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
57 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/paymentexpensereport.class.php';
58 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
59 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
60 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
61 require_once DOL_DOCUMENT_ROOT.
'/loan/class/paymentloan.class.php';
62 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
65 $langs->loadLangs(array(
"companies",
"other",
"compta",
"banks",
"bills",
"donations",
"loan",
"accountancy",
"trips",
"salaries",
"hrm",
"members"));
68 $id_journal =
GETPOST(
'id_journal',
'int');
70 $date_startmonth =
GETPOST(
'date_startmonth',
'int');
71 $date_startday =
GETPOST(
'date_startday',
'int');
72 $date_startyear =
GETPOST(
'date_startyear',
'int');
73 $date_endmonth =
GETPOST(
'date_endmonth',
'int');
74 $date_endday =
GETPOST(
'date_endday',
'int');
75 $date_endyear =
GETPOST(
'date_endyear',
'int');
76 $in_bookkeeping =
GETPOST(
'in_bookkeeping',
'aZ09');
77 if ($in_bookkeeping ==
'') {
78 $in_bookkeeping =
'notyet';
83 $action =
GETPOST(
'action',
'aZ09');
89 if ($user->socid > 0) {
92 if (empty($user->rights->accounting->mouvements->lire)) {
103 $date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
104 $date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
106 if (empty($date_startmonth) || empty($date_endmonth)) {
109 $date_start = $dates[
'date_start'];
110 $date_end = $dates[
'date_end'];
111 $pastmonthyear = $dates[
'pastmonthyear'];
112 $pastmonth = $dates[
'pastmonth'];
115 if (!
GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end))) {
120 $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,";
121 $sql .=
" ba.courant, ba.ref as baref, ba.account_number, ba.fk_accountancy_journal,";
122 $sql .=
" soc.rowid as socid, soc.nom as name, soc.email as email, bu1.type as typeop_company,";
123 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
124 $sql .=
" spe.accountancy_code_customer as code_compta,";
125 $sql .=
" spe.accountancy_code_supplier as code_compta_fournisseur,";
127 $sql .=
" soc.code_compta,";
128 $sql .=
" soc.code_compta_fournisseur,";
130 $sql .=
" u.accountancy_code, u.rowid as userid, u.lastname as lastname, u.firstname as firstname, u.email as useremail, u.statut as userstatus,";
131 $sql .=
" bu2.type as typeop_user,";
132 $sql .=
" bu3.type as typeop_payment, bu4.type as typeop_payment_supplier";
133 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
134 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"bank_account as ba on b.fk_account=ba.rowid";
135 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'";
136 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON bu2.fk_bank = b.rowid AND bu2.type='user'";
137 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu3 ON bu3.fk_bank = b.rowid AND bu3.type='payment'";
138 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu4 ON bu4.fk_bank = b.rowid AND bu4.type='payment_supplier'";
139 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as soc on bu1.url_id=soc.rowid";
140 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
141 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = soc.rowid AND spe.entity = " . ((int) $conf->entity);
143 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on bu2.url_id=u.rowid";
144 $sql .=
" WHERE ba.fk_accountancy_journal=".((int) $id_journal);
145 $sql .=
' AND b.amount <> 0 AND ba.entity IN ('.getEntity(
'bank_account', 0).
')';
146 if ($date_start && $date_end) {
147 $sql .=
" AND b.dateo >= '".$db->idate($date_start).
"' AND b.dateo <= '".$db->idate($date_end).
"'";
150 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
151 $sql .=
" AND b.dateo >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
154 if ($in_bookkeeping ==
'already') {
155 $sql .=
" AND (b.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
157 if ($in_bookkeeping ==
'notyet') {
158 $sql .=
" AND (b.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
160 $sql .=
" ORDER BY b.datev";
166 $societestatic =
new Societe($db);
167 $userstatic =
new User($db);
168 $bankaccountstatic =
new Account($db);
171 $paymentvatstatic =
new Tva($db);
180 $tmpinvoice =
new Facture($db);
186 $accountingjournalstatic->fetch($id_journal);
187 $journal = $accountingjournalstatic->code;
188 $journal_label = $accountingjournalstatic->label;
191 dol_syslog(
"accountancy/journal/bankjournal.php", LOG_DEBUG);
192 $result = $db->query(
$sql);
194 $num = $db->num_rows($result);
198 $account_supplier = (($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER !=
"") ? $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER :
'NotDefined');
199 $account_customer = (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER !=
"") ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER :
'NotDefined');
200 $account_employee = (!empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) ? $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT :
'NotDefined');
201 $account_pay_vat = (!empty($conf->global->ACCOUNTING_VAT_PAY_ACCOUNT) ? $conf->global->ACCOUNTING_VAT_PAY_ACCOUNT :
'NotDefined');
202 $account_pay_donation = (!empty($conf->global->DONATION_ACCOUNTINGACCOUNT) ? $conf->global->DONATION_ACCOUNTINGACCOUNT :
'NotDefined');
203 $account_pay_subscription = (!empty($conf->global->ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT) ? $conf->global->ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT :
'NotDefined');
204 $account_transfer = (!empty($conf->global->ACCOUNTING_ACCOUNT_TRANSFER_CASH) ? $conf->global->ACCOUNTING_ACCOUNT_TRANSFER_CASH :
'NotDefined');
206 $tabcompany = array();
212 $tabmoreinfo = array();
220 $obj = $db->fetch_object($result);
222 $lineisapurchase = -1;
225 if ($obj->label ==
'(SupplierInvoicePayment)' || $obj->label ==
'(SupplierInvoicePaymentBack)') {
226 $lineisapurchase = 1;
228 if ($obj->label ==
'(CustomerInvoicePayment)' || $obj->label ==
'(CustomerInvoicePaymentBack)') {
232 if ($lineisapurchase < 0) {
233 if ($obj->typeop_payment_supplier ==
'payment_supplier') {
234 $lineisapurchase = 1;
237 if ($lineisasale < 0) {
238 if ($obj->typeop_payment ==
'payment') {
246 $compta_bank = $obj->account_number;
249 $compta_soc =
'NotDefined';
250 if ($lineisapurchase > 0) {
251 $compta_soc = (($obj->code_compta_fournisseur !=
"") ? $obj->code_compta_fournisseur : $account_supplier);
253 if ($lineisasale > 0) {
254 $compta_soc = (!empty($obj->code_compta) ? $obj->code_compta : $account_customer);
257 $tabcompany[$obj->rowid] = array(
259 'name' => $obj->name,
260 'code_compta' => $compta_soc,
261 'email' => $obj->email
266 $compta_user = (!empty($obj->accountancy_code) ? $obj->accountancy_code :
'');
268 $tabuser[$obj->rowid] = array(
269 'id' => $obj->userid,
271 'lastname' => $obj->lastname,
272 'firstname' => $obj->firstname,
273 'email' => $obj->useremail,
274 'accountancy_code' => $compta_user,
275 'status' => $obj->userstatus
279 $tabpay[$obj->rowid][
"date"] = $obj->do;
280 $tabpay[$obj->rowid][
"type_payment"] = $obj->fk_type;
281 $tabpay[$obj->rowid][
"ref"] = $obj->label;
282 $tabpay[$obj->rowid][
"fk_bank"] = $obj->rowid;
283 $tabpay[$obj->rowid][
"bank_account_ref"] = $obj->baref;
284 $tabpay[$obj->rowid][
"fk_bank_account"] = $obj->fk_account;
286 if (preg_match(
'/^\((.*)\)$/i', $obj->label, $reg)) {
287 $tabpay[$obj->rowid][
"lib"] = $langs->trans($reg[1]);
289 $tabpay[$obj->rowid][
"lib"] =
dol_trunc($obj->label, 60);
293 $links = $object->get_url($obj->rowid);
296 $tabpay[$obj->rowid][
'type'] =
'unknown';
297 $tabtype[$obj->rowid] =
'unknown';
298 $tabmoreinfo[$obj->rowid] = array();
300 $amounttouse = $obj->amount;
301 if (!empty($obj->amount_main_currency)) {
303 $amounttouse = $obj->amount_main_currency;
307 if (is_array($links) && count($links) > 0) {
309 foreach ($links as $v) {
310 if ($v[
'type'] ==
'sc') {
316 foreach ($links as $key => $val) {
317 if ($links[$key][
'type'] ==
'user' && !$is_sc)
continue;
318 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'))) {
322 $tabpay[$obj->rowid][
'type'] = $links[$key][
'type'];
323 $tabtype[$obj->rowid] = $links[$key][
'type'];
324 } elseif (in_array($links[$key][
'type'], array(
'company',
'user'))) {
325 if ($tabpay[$obj->rowid][
'type'] ==
'unknown') {
332 if ($links[$key][
'type'] ==
'withdraw') {
333 $tabmoreinfo[$obj->rowid][
'withdraw'] = 1;
336 if ($links[$key][
'type'] ==
'payment') {
337 $paymentstatic->id = $links[$key][
'url_id'];
338 $paymentstatic->ref = $links[$key][
'url_id'];
339 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentstatic->getNomUrl(2,
'',
'');
340 $tabpay[$obj->rowid][
"paymentid"] = $paymentstatic->id;
341 } elseif ($links[$key][
'type'] ==
'payment_supplier') {
342 $paymentsupplierstatic->id = $links[$key][
'url_id'];
343 $paymentsupplierstatic->ref = $links[$key][
'url_id'];
344 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentsupplierstatic->getNomUrl(2);
345 $tabpay[$obj->rowid][
"paymentsupplierid"] = $paymentsupplierstatic->id;
346 } elseif ($links[$key][
'type'] ==
'company') {
347 $societestatic->id = $links[$key][
'url_id'];
348 $societestatic->name = $links[$key][
'label'];
349 $societestatic->email = $tabcompany[$obj->rowid][
'email'];
350 $tabpay[$obj->rowid][
"soclib"] = $societestatic->getNomUrl(1,
'', 30);
352 if (empty($tabtp[$obj->rowid][$compta_soc])) {
353 $tabtp[$obj->rowid][$compta_soc] = $amounttouse;
355 $tabtp[$obj->rowid][$compta_soc] += $amounttouse;
358 } elseif ($links[$key][
'type'] ==
'user') {
359 $userstatic->id = $links[$key][
'url_id'];
360 $userstatic->name = $links[$key][
'label'];
361 $userstatic->email = $tabuser[$obj->rowid][
'email'];
362 $userstatic->firstname = $tabuser[$obj->rowid][
'firstname'];
363 $userstatic->lastname = $tabuser[$obj->rowid][
'lastname'];
364 $userstatic->statut = $tabuser[$obj->rowid][
'status'];
365 $userstatic->accountancy_code = $tabuser[$obj->rowid][
'accountancy_code'];
366 if ($userstatic->id > 0) {
367 $tabpay[$obj->rowid][
"soclib"] = $userstatic->getNomUrl(1,
'accountancy', 0);
369 $tabpay[$obj->rowid][
"soclib"] =
'???';
372 $tabtp[$obj->rowid][$compta_user] += $amounttouse;
374 } elseif ($links[$key][
'type'] ==
'sc') {
375 $chargestatic->id = $links[$key][
'url_id'];
376 $chargestatic->ref = $links[$key][
'url_id'];
378 $tabpay[$obj->rowid][
"lib"] .=
' '.$chargestatic->getNomUrl(2);
380 if (preg_match(
'/^\((.*)\)$/i', $links[$key][
'label'], $reg)) {
381 if ($reg[1] ==
'socialcontribution') {
382 $reg[1] =
'SocialContribution';
384 $chargestatic->label = $langs->trans($reg[1]);
386 $chargestatic->label = $links[$key][
'label'];
388 $chargestatic->ref = $chargestatic->label;
389 $tabpay[$obj->rowid][
"soclib"] = $chargestatic->getNomUrl(1, 30);
390 $tabpay[$obj->rowid][
"paymentscid"] = $chargestatic->id;
394 $sqlmid =
"SELECT cchgsoc.accountancy_code";
395 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales cchgsoc";
396 $sqlmid .=
" INNER JOIN ".MAIN_DB_PREFIX.
"chargesociales as chgsoc ON chgsoc.fk_type = cchgsoc.id";
397 $sqlmid .=
" INNER JOIN ".MAIN_DB_PREFIX.
"paiementcharge as paycharg ON paycharg.fk_charge = chgsoc.rowid";
398 $sqlmid .=
" INNER JOIN ".MAIN_DB_PREFIX.
"bank_url as bkurl ON bkurl.url_id=paycharg.rowid AND bkurl.type = 'payment_sc'";
399 $sqlmid .=
" WHERE bkurl.fk_bank = ".((int) $obj->rowid);
401 dol_syslog(
"accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);
402 $resultmid = $db->query($sqlmid);
404 $objmid = $db->fetch_object($resultmid);
405 $tabtp[$obj->rowid][$objmid->accountancy_code] += $amounttouse;
407 } elseif ($links[$key][
'type'] ==
'payment_donation') {
408 $paymentdonstatic->id = $links[$key][
'url_id'];
409 $paymentdonstatic->ref = $links[$key][
'url_id'];
410 $paymentdonstatic->fk_donation = $links[$key][
'url_id'];
411 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentdonstatic->getNomUrl(2);
412 $tabpay[$obj->rowid][
"paymentdonationid"] = $paymentdonstatic->id;
413 $tabtp[$obj->rowid][$account_pay_donation] += $amounttouse;
414 } elseif ($links[$key][
'type'] ==
'member') {
415 $paymentsubscriptionstatic->id = $links[$key][
'url_id'];
416 $paymentsubscriptionstatic->ref = $links[$key][
'url_id'];
417 $paymentsubscriptionstatic->label = $links[$key][
'label'];
418 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentsubscriptionstatic->getNomUrl(2);
419 $tabpay[$obj->rowid][
"paymentsubscriptionid"] = $paymentsubscriptionstatic->id;
420 $paymentsubscriptionstatic->fetch($paymentsubscriptionstatic->id);
421 $tabtp[$obj->rowid][$account_pay_subscription] += $amounttouse;
422 } elseif ($links[$key][
'type'] ==
'payment_vat') {
423 $paymentvatstatic->id = $links[$key][
'url_id'];
424 $paymentvatstatic->ref = $links[$key][
'url_id'];
425 $paymentvatstatic->label = $links[$key][
'label'];
426 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentvatstatic->getNomUrl(2);
427 $tabpay[$obj->rowid][
"paymentvatid"] = $paymentvatstatic->id;
428 $tabtp[$obj->rowid][$account_pay_vat] += $amounttouse;
429 } elseif ($links[$key][
'type'] ==
'payment_salary') {
430 $paymentsalstatic->id = $links[$key][
'url_id'];
431 $paymentsalstatic->ref = $links[$key][
'url_id'];
432 $paymentsalstatic->label = $links[$key][
'label'];
433 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentsalstatic->getNomUrl(2);
434 $tabpay[$obj->rowid][
"paymentsalid"] = $paymentsalstatic->id;
438 if (!empty($conf->global->ACCOUNTANCY_AUTOFIX_MISSING_LINK_TO_USEr_ON_SALARY_BANK_PAYMENT)) {
439 $tmpsalary =
new Salary($db);
440 $tmpsalary->fetch($paymentsalstatic->id);
441 $tmpsalary->fetch_user($tmpsalary->fk_user);
443 $userstatic->id = $tmpsalary->user->id;
444 $userstatic->name = $tmpsalary->user->name;
445 $userstatic->email = $tmpsalary->user->email;
446 $userstatic->firstname = $tmpsalary->user->firstname;
447 $userstatic->lastname = $tmpsalary->user->lastname;
448 $userstatic->statut = $tmpsalary->user->statut;
449 $userstatic->accountancy_code = $tmpsalary->user->accountancy_code;
451 if ($userstatic->id > 0) {
452 $tabpay[$obj->rowid][
"soclib"] = $userstatic->getNomUrl(1,
'accountancy', 0);
454 $tabpay[$obj->rowid][
"soclib"] =
'???';
457 if (empty($obj->typeop_user)) {
458 $compta_user = $userstatic->accountancy_code;
460 $tabtp[$obj->rowid][$compta_user] += $amounttouse;
461 $tabuser[$obj->rowid] = array(
462 'id' => $userstatic->id,
464 'lastname' => $userstatic->lastname,
465 'firstname' => $userstatic->firstname,
466 'email' => $userstatic->email,
467 'accountancy_code' => $compta_user,
468 'status' => $userstatic->statut
473 } elseif ($links[$key][
'type'] ==
'payment_expensereport') {
474 $paymentexpensereportstatic->id = $links[$key][
'url_id'];
475 $tabpay[$obj->rowid][
"lib"] .= $paymentexpensereportstatic->getNomUrl(2);
476 $tabpay[$obj->rowid][
"paymentexpensereport"] = $paymentexpensereportstatic->id;
477 } elseif ($links[$key][
'type'] ==
'payment_various') {
478 $paymentvariousstatic->id = $links[$key][
'url_id'];
479 $paymentvariousstatic->ref = $links[$key][
'url_id'];
480 $paymentvariousstatic->label = $links[$key][
'label'];
481 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentvariousstatic->getNomUrl(2);
482 $tabpay[$obj->rowid][
"paymentvariousid"] = $paymentvariousstatic->id;
483 $paymentvariousstatic->fetch($paymentvariousstatic->id);
484 $account_various = (!empty($paymentvariousstatic->accountancy_code) ? $paymentvariousstatic->accountancy_code :
'NotDefined');
485 $account_subledger = (!empty($paymentvariousstatic->subledger_account) ? $paymentvariousstatic->subledger_account :
'');
486 $tabpay[$obj->rowid][
"account_various"] = $account_various;
487 $tabtp[$obj->rowid][$account_subledger] += $amounttouse;
488 } elseif ($links[$key][
'type'] ==
'payment_loan') {
489 $paymentloanstatic->id = $links[$key][
'url_id'];
490 $paymentloanstatic->ref = $links[$key][
'url_id'];
491 $paymentloanstatic->fk_loan = $links[$key][
'url_id'];
492 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentloanstatic->getNomUrl(2);
493 $tabpay[$obj->rowid][
"paymentloanid"] = $paymentloanstatic->id;
495 $sqlmid =
'SELECT pl.amount_capital, pl.amount_insurance, pl.amount_interest, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest';
496 $sqlmid .=
' FROM '.MAIN_DB_PREFIX.
'payment_loan as pl, '.MAIN_DB_PREFIX.
'loan as l';
497 $sqlmid .=
' WHERE l.rowid = pl.fk_loan AND pl.fk_bank = '.((int) $obj->rowid);
499 dol_syslog(
"accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);
500 $resultmid = $db->query($sqlmid);
502 $objmid = $db->fetch_object($resultmid);
503 $tabtp[$obj->rowid][$objmid->accountancy_account_capital] -= $objmid->amount_capital;
504 $tabtp[$obj->rowid][$objmid->accountancy_account_insurance] -= $objmid->amount_insurance;
505 $tabtp[$obj->rowid][$objmid->accountancy_account_interest] -= $objmid->amount_interest;
507 } elseif ($links[$key][
'type'] ==
'banktransfert') {
508 $accountLinestatic->fetch($links[$key][
'url_id']);
509 $tabpay[$obj->rowid][
"lib"] .=
' '.$langs->trans(
"BankTransfer").
'- '.$accountLinestatic ->getNomUrl(1);
510 $tabtp[$obj->rowid][$account_transfer] += $amounttouse;
511 $bankaccountstatic->fetch($tabpay[$obj->rowid][
'fk_bank_account']);
512 $tabpay[$obj->rowid][
"soclib"] = $bankaccountstatic->getNomUrl(2);
517 if (empty($tabbq[$obj->rowid][$compta_bank])) {
518 $tabbq[$obj->rowid][$compta_bank] = $amounttouse;
520 $tabbq[$obj->rowid][$compta_bank] += $amounttouse;
525 if (empty($tabtp[$obj->rowid]) && !empty($tabmoreinfo[$obj->rowid][
'withdraw'])) {
526 foreach ($links as $key => $val) {
527 if ($links[$key][
'type'] ==
'payment') {
529 $tmppayment->fetch($links[$key][
'url_id']);
530 $arrayofamounts = $tmppayment->getAmountsArray();
531 if (is_array($arrayofamounts)) {
532 foreach ($arrayofamounts as $invoiceid => $amount) {
533 $tmpinvoice->fetch($invoiceid);
534 $tmpinvoice->fetch_thirdparty();
535 if ($tmpinvoice->thirdparty->code_compta) {
536 $tabtp[$obj->rowid][$tmpinvoice->thirdparty->code_compta] += $amount;
545 if (empty($tabtp[$obj->rowid])) {
546 $tabtp[$obj->rowid][
'NotDefined'] = $tabbq[$obj->rowid][$compta_bank];
584 if (!$error && $action ==
'writebookkeeping') {
588 $accountingaccountcustomer->fetch(
null, $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER,
true);
591 $accountingaccountsupplier->fetch(
null, $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER,
true);
594 $accountingaccountpayment->fetch(
null, $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT,
true);
597 $accountingaccountsuspense->fetch(
null, $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE,
true);
600 foreach ($tabpay as $key => $val) {
618 if (!$errorforline && is_array($tabbq[$key])) {
620 foreach ($tabbq[$key] as $k => $mt) {
622 $accountingaccount->fetch(
null, $k,
true);
623 $account_label = $accountingaccount->label;
626 if (!empty($val[
'lib'])) {
630 if (!empty($val[
'soclib'])) {
631 $reflabel .=
" - ".dol_string_nohtmltag($val[
'soclib']);
635 $bookkeeping->doc_date = $val[
"date"];
636 $bookkeeping->doc_ref = $ref;
637 $bookkeeping->doc_type =
'bank';
638 $bookkeeping->fk_doc = $key;
639 $bookkeeping->fk_docdet = $val[
"fk_bank"];
641 $bookkeeping->numero_compte = $k;
642 $bookkeeping->label_compte = $account_label;
644 $bookkeeping->label_operation = $reflabel;
645 $bookkeeping->montant = $mt;
646 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
647 $bookkeeping->debit = ($mt >= 0 ? $mt : 0);
648 $bookkeeping->credit = ($mt < 0 ? -$mt : 0);
649 $bookkeeping->code_journal = $journal;
650 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
651 $bookkeeping->fk_user_author = $user->id;
652 $bookkeeping->date_creation = $now;
655 $bookkeeping->subledger_account =
'';
656 $bookkeeping->label_operation = $reflabel;
657 $bookkeeping->entity = $conf->entity;
659 $totaldebit += $bookkeeping->debit;
660 $totalcredit += $bookkeeping->credit;
662 $result = $bookkeeping->create($user);
664 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
667 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded',
null,
'warnings');
679 if (!$errorforline) {
680 if (is_array($tabtp[$key])) {
682 foreach ($tabtp[$key] as $k => $mt) {
687 if (!empty($val[
'lib'])) {
690 if ($tabtype[$key] ==
'banktransfert') {
691 $reflabel .=
dol_string_nohtmltag($langs->transnoentitiesnoconv(
'TransitionalAccount').
' '.$account_transfer);
697 $bookkeeping->doc_date = $val[
"date"];
698 $bookkeeping->doc_ref = $ref;
699 $bookkeeping->doc_type =
'bank';
700 $bookkeeping->fk_doc = $key;
701 $bookkeeping->fk_docdet = $val[
"fk_bank"];
703 $bookkeeping->label_operation = $reflabel;
704 $bookkeeping->montant = $mt;
705 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
706 $bookkeeping->debit = ($mt < 0 ? -$mt : 0);
707 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
708 $bookkeeping->code_journal = $journal;
709 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
710 $bookkeeping->fk_user_author = $user->id;
711 $bookkeeping->date_creation = $now;
713 if ($tabtype[$key] ==
'payment') {
715 $bookkeeping->subledger_account = $k;
716 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
717 $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
718 $bookkeeping->label_compte = $accountingaccountcustomer->label;
719 } elseif ($tabtype[$key] ==
'payment_supplier') {
721 $bookkeeping->subledger_account = $k;
722 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
723 $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER;
724 $bookkeeping->label_compte = $accountingaccountsupplier->label;
725 } elseif ($tabtype[$key] ==
'payment_expensereport') {
726 $bookkeeping->subledger_account = $tabuser[$key][
'accountancy_code'];
727 $bookkeeping->subledger_label = $tabuser[$key][
'name'];
728 $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT;
729 $bookkeeping->label_compte = $accountingaccountpayment->label;
730 } elseif ($tabtype[$key] ==
'payment_salary') {
731 $bookkeeping->subledger_account = $tabuser[$key][
'accountancy_code'];
732 $bookkeeping->subledger_label = $tabuser[$key][
'name'];
733 $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT;
734 $bookkeeping->label_compte = $accountingaccountpayment->label;
735 } elseif (in_array($tabtype[$key], array(
'sc',
'payment_sc'))) {
736 $bookkeeping->subledger_account =
'';
737 $bookkeeping->subledger_label =
'';
738 $accountingaccount->fetch(
null, $k,
true);
739 $bookkeeping->numero_compte = $k;
740 $bookkeeping->label_compte = $accountingaccount->label;
741 } elseif ($tabtype[$key] ==
'payment_vat') {
742 $bookkeeping->subledger_account =
'';
743 $bookkeeping->subledger_label =
'';
744 $accountingaccount->fetch(
null, $k,
true);
745 $bookkeeping->numero_compte = $k;
746 $bookkeeping->label_compte = $accountingaccount->label;
747 } elseif ($tabtype[$key] ==
'payment_donation') {
748 $bookkeeping->subledger_account =
'';
749 $bookkeeping->subledger_label =
'';
750 $accountingaccount->fetch(
null, $k,
true);
751 $bookkeeping->numero_compte = $k;
752 $bookkeeping->label_compte = $accountingaccount->label;
753 } elseif ($tabtype[$key] ==
'member') {
754 $bookkeeping->subledger_account =
'';
755 $bookkeeping->subledger_label =
'';
756 $accountingaccount->fetch(
null, $k,
true);
757 $bookkeeping->numero_compte = $k;
758 $bookkeeping->label_compte = $accountingaccount->label;
759 } elseif ($tabtype[$key] ==
'payment_loan') {
760 $bookkeeping->subledger_account =
'';
761 $bookkeeping->subledger_label =
'';
762 $accountingaccount->fetch(
null, $k,
true);
763 $bookkeeping->numero_compte = $k;
764 $bookkeeping->label_compte = $accountingaccount->label;
765 } elseif ($tabtype[$key] ==
'payment_various') {
766 $bookkeeping->subledger_account = $k;
767 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
768 $accountingaccount->fetch(
null, $tabpay[$key][
"account_various"],
true);
769 $bookkeeping->numero_compte = $tabpay[$key][
"account_various"];
770 $bookkeeping->label_compte = $accountingaccount->label;
771 } elseif ($tabtype[$key] ==
'banktransfert') {
772 $bookkeeping->subledger_account =
'';
773 $bookkeeping->subledger_label =
'';
774 $accountingaccount->fetch(
null, $k,
true);
775 $bookkeeping->numero_compte = $k;
776 $bookkeeping->label_compte = $accountingaccount->label;
778 if ($tabtype[$key] ==
'unknown') {
780 $bookkeeping->subledger_account =
'';
781 $bookkeeping->subledger_label =
'';
782 $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE;
783 $bookkeeping->label_compte = $accountingaccountsuspense->label;
786 $bookkeeping->label_operation = $reflabel;
787 $bookkeeping->entity = $conf->entity;
789 $totaldebit += $bookkeeping->debit;
790 $totalcredit += $bookkeeping->credit;
792 $result = $bookkeeping->create($user);
794 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
797 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded',
null,
'warnings');
805 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/lettering.class.php';
807 $nb_lettering = $lettering_static->bookkeepingLetteringAll(array($bookkeeping->id));
813 foreach ($tabbq[$key] as $k => $mt) {
816 if (!empty($val[
'lib'])) {
822 $bookkeeping->doc_date = $val[
"date"];
823 $bookkeeping->doc_ref = $ref;
824 $bookkeeping->doc_type =
'bank';
825 $bookkeeping->fk_doc = $key;
826 $bookkeeping->fk_docdet = $val[
"fk_bank"];
827 $bookkeeping->montant = $mt;
828 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
829 $bookkeeping->debit = ($mt < 0 ? -$mt : 0);
830 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
831 $bookkeeping->code_journal = $journal;
832 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
833 $bookkeeping->fk_user_author = $user->id;
834 $bookkeeping->date_creation = $now;
835 $bookkeeping->label_compte =
'';
836 $bookkeeping->label_operation = $reflabel;
837 $bookkeeping->entity = $conf->entity;
839 $totaldebit += $bookkeeping->debit;
840 $totalcredit += $bookkeeping->credit;
842 $result = $bookkeeping->create($user);
845 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
848 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded',
null,
'warnings');
863 setEventMessages(
'Try to insert a non balanced transaction in book for '.$ref.
'. Canceled. Surely a bug.',
null,
'errors');
866 if (!$errorforline) {
873 if ($error >= $MAXNBERRORS) {
874 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped").
' (>'.$MAXNBERRORS.
')',
null,
'errors');
880 if (empty($error) && count($tabpay) > 0) {
882 } elseif (count($tabpay) == $error) {
885 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
891 if (count($tabpay) != $error) {
892 $param =
'id_journal='.$id_journal;
893 $param .=
'&date_startday='.$date_startday;
894 $param .=
'&date_startmonth='.$date_startmonth;
895 $param .=
'&date_startyear='.$date_startyear;
896 $param .=
'&date_endday='.$date_endday;
897 $param .=
'&date_endmonth='.$date_endmonth;
898 $param .=
'&date_endyear='.$date_endyear;
899 $param .=
'&in_bookkeeping='.$in_bookkeeping;
900 header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
908 if ($action ==
'exportcsv') {
909 $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
911 $filename =
'journal';
912 $type_export =
'journal';
913 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
916 print
'"'.$langs->transnoentitiesnoconv(
"BankId").
'"'.$sep;
917 print
'"'.$langs->transnoentitiesnoconv(
"Date").
'"'.$sep;
918 print
'"'.$langs->transnoentitiesnoconv(
"PaymentMode").
'"'.$sep;
919 print
'"'.$langs->transnoentitiesnoconv(
"AccountAccounting").
'"'.$sep;
920 print
'"'.$langs->transnoentitiesnoconv(
"LedgerAccount").
'"'.$sep;
921 print
'"'.$langs->transnoentitiesnoconv(
"SubledgerAccount").
'"'.$sep;
922 print
'"'.$langs->transnoentitiesnoconv(
"Label").
'"'.$sep;
923 print
'"'.$langs->transnoentitiesnoconv(
"AccountingDebit").
'"'.$sep;
924 print
'"'.$langs->transnoentitiesnoconv(
"AccountingCredit").
'"'.$sep;
925 print
'"'.$langs->transnoentitiesnoconv(
"Journal").
'"'.$sep;
926 print
'"'.$langs->transnoentitiesnoconv(
"Note").
'"'.$sep;
929 foreach ($tabpay as $key => $val) {
935 foreach ($tabbq[$key] as $k => $mt) {
938 if (!empty($val[
'lib'])) {
942 if (!empty($val[
'soclib'])) {
943 $reflabel .=
" - ".dol_string_nohtmltag($val[
'soclib']);
946 print
'"'.$key.
'"'.$sep;
947 print
'"'.$date.
'"'.$sep;
948 print
'"'.$val[
"type_payment"].
'"'.$sep;
949 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
950 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
952 print
'"'.$reflabel.
'"'.$sep;
953 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
954 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
955 print
'"'.$journal.
'"'.$sep;
956 print
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
962 if (is_array($tabtp[$key])) {
963 foreach ($tabtp[$key] as $k => $mt) {
966 if (!empty($val[
'lib'])) {
969 if ($tabtype[$key] ==
'banktransfert') {
970 $reflabel .=
dol_string_nohtmltag($langs->transnoentitiesnoconv(
'TransitionalAccount').
' '.$account_transfer);
975 print
'"'.$key.
'"'.$sep;
976 print
'"'.$date.
'"'.$sep;
977 print
'"'.$val[
"type_payment"].
'"'.$sep;
978 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
979 if ($tabtype[$key] ==
'payment_supplier') {
980 print
'"'.$conf->global->ACCOUNTING_ACCOUNT_SUPPLIER.
'"'.$sep;
981 } elseif ($tabtype[$key] ==
'payment') {
982 print
'"'.$conf->global->ACCOUNTING_ACCOUNT_CUSTOMER.
'"'.$sep;
983 } elseif ($tabtype[$key] ==
'payment_expensereport') {
984 print
'"'.$conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT.
'"'.$sep;
985 } elseif ($tabtype[$key] ==
'payment_salary') {
986 print
'"'.$conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT.
'"'.$sep;
988 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
990 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
991 print
'"'.$reflabel.
'"'.$sep;
992 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
993 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
994 print
'"'.$journal.
'"'.$sep;
995 print
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
1000 foreach ($tabbq[$key] as $k => $mt) {
1003 if (!empty($val[
'lib'])) {
1008 print
'"'.$key.
'"'.$sep;
1009 print
'"'.$date.
'"'.$sep;
1010 print
'"'.$val[
"type_payment"].
'"'.$sep;
1011 print
'"'.length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE).
'"'.$sep;
1012 print
'"'.length_accounta($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE).
'"'.$sep;
1014 print
'"'.$reflabel.
'"'.$sep;
1015 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1016 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1017 print
'"'.$journal.
'"'.$sep;
1018 print
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
1033 if (empty($action) || $action ==
'view') {
1034 $invoicestatic =
new Facture($db);
1037 $vatstatic =
new Tva($db);
1038 $donationstatic =
new Don($db);
1039 $loanstatic =
new Loan($db);
1040 $salarystatic =
new Salary($db);
1043 $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1,
'', 1);
1050 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
1052 $listofchoices = array(
1053 'notyet'=>$langs->trans(
"NotYetInGeneralLedger"),
1054 'already'=>$langs->trans(
"AlreadyInGeneralLedger")
1056 $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);
1057 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.
$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
1059 $varlink =
'id_journal='.$id_journal;
1063 journalHead($nom,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
1068 $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";
1069 $resql = $db->query(
$sql);
1071 $obj = $db->fetch_object($resql);
1073 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheJournalCodeIsNotDefinedOnSomeBankAccount");
1074 $desc =
' : '.$langs->trans(
"AccountancyAreaDescBank", 9,
'{link}');
1075 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"BankAccounts").
'</strong>', $desc);
1085 if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
"") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
'-1'
1086 || ($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
"") || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
'-1'
1087 || empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) || $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT ==
'-1') {
1088 print ($desc ?
'' :
'<br>').
'<div class="warning">'.
img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
1089 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
1090 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
1096 print
'<div class="tabsAction tabsActionNoBottom centerimp">';
1098 if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping ==
'notyet') {
1099 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
1102 if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
"") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
'-1'
1103 || ($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
"") || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
'-1') {
1104 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
1106 if ($in_bookkeeping ==
'notyet') {
1107 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
1109 print
'<a class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
1117 <script type="text/javascript">
1118 function launch_export() {
1119 console.log("Set value into form and submit");
1120 $("div.fiche form input[name=\"action\"]").val("exportcsv");
1121 $("div.fiche form input[type=\"submit\"]").click();
1122 $("div.fiche form input[name=\"action\"]").val("");
1124 function writebookkeeping() {
1125 console.log("Set value into form and submit");
1126 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
1127 $("div.fiche form input[type=\"submit\"]").click();
1128 $("div.fiche form input[name=\"action\"]").val("");
1138 print
'<div class="div-table-responsive">';
1139 print
'<table class="noborder centpercent">';
1140 print
'<tr class="liste_titre">';
1141 print
"<td>".$langs->trans(
"Date").
"</td>";
1142 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"ObjectsRef").
")</td>";
1143 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
1144 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
1145 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
1146 print
'<td class="center">'.$langs->trans(
"PaymentMode").
"</td>";
1147 print
'<td class="right">'.$langs->trans(
"AccountingDebit").
"</td>";
1148 print
'<td class="right">'.$langs->trans(
"AccountingCredit").
"</td>";
1153 foreach ($tabpay as $key => $val) {
1159 foreach ($tabbq[$key] as $k => $mt) {
1162 if (!empty($val[
'lib'])) {
1163 $reflabel .= $val[
'lib'].
" - ";
1165 $reflabel .= $langs->trans(
"Bank").
' '.$val[
'bank_account_ref'];
1166 if (!empty($val[
'soclib'])) {
1167 $reflabel .=
" - ".$val[
'soclib'];
1171 print
'<!-- Bank bank.rowid='.$key.
' type='.$tabpay[$key][
'type'].
' ref='.$tabpay[$key][
'ref'].
'-->';
1172 print
'<tr class="oddeven">';
1175 print
"<td>".$date.
"</td>";
1178 print
"<td>".dol_escape_htmltag($ref).
"</td>";
1182 if (empty($accounttoshow) || $accounttoshow ==
'NotDefined') {
1183 $accounttoshow =
'<span class="error">'.$langs->trans(
"BankAccountNotDefined").
'</span>';
1185 print
'<td class="maxwidth300" title="'.dol_escape_htmltag(
dol_string_nohtmltag($accounttoshow)).
'">';
1186 print $accounttoshow;
1190 print
'<td class="maxwidth300">';
1204 print
'<td class="center">'.$val[
"type_payment"].
"</td>";
1205 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1206 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1212 if (is_array($tabtp[$key])) {
1213 foreach ($tabtp[$key] as $k => $mt) {
1216 if (!empty($val[
'lib'])) {
1217 $reflabel .= $val[
'lib'].($val[
'soclib'] ?
" - " :
"");
1219 if ($tabtype[$key] ==
'banktransfert') {
1220 $reflabel .= $langs->trans(
'TransitionalAccount').
' '.$account_transfer;
1222 $reflabel .= $val[
'soclib'];
1225 print
'<!-- Thirdparty bank.rowid='.$key.
' -->';
1226 print
'<tr class="oddeven">';
1229 print
"<td>".$date.
"</td>";
1232 print
"<td>".dol_escape_htmltag($ref).
"</td>";
1235 $account_ledger = $k;
1237 if ($tabtype[$key] ==
'payment') {
1240 if ($tabtype[$key] ==
'payment_supplier') {
1243 if ($tabtype[$key] ==
'payment_expensereport') {
1246 if ($tabtype[$key] ==
'payment_salary') {
1249 if ($tabtype[$key] ==
'payment_vat') {
1252 if ($tabtype[$key] ==
'member') {
1255 if ($tabtype[$key] ==
'payment_various') {
1256 $account_ledger = $tabpay[$key][
"account_various"];
1259 if (empty($accounttoshow) || $accounttoshow ==
'NotDefined') {
1260 if ($tabtype[$key] ==
'unknown') {
1262 if (empty($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) || $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE ==
'-1') {
1263 $accounttoshow =
'<span class="error small">'.$langs->trans(
'UnknownAccountForThirdpartyAndWaitingAccountNotDefinedBlocking').
'</span>';
1265 $accounttoshow =
'<span class="warning small">'.$langs->trans(
'UnknownAccountForThirdparty',
length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE)).
'</span>';
1269 $errorstring =
'UnknownAccountForThirdpartyBlocking';
1270 if ($tabtype[$key] ==
'payment') {
1271 $errorstring =
'MainAccountForCustomersNotDefined';
1273 if ($tabtype[$key] ==
'payment_supplier') {
1274 $errorstring =
'MainAccountForSuppliersNotDefined';
1276 if ($tabtype[$key] ==
'payment_expensereport') {
1277 $errorstring =
'MainAccountForUsersNotDefined';
1279 if ($tabtype[$key] ==
'payment_salary') {
1280 $errorstring =
'MainAccountForUsersNotDefined';
1282 if ($tabtype[$key] ==
'payment_vat') {
1283 $errorstring =
'MainAccountForVatPaymentNotDefined';
1285 if ($tabtype[$key] ==
'member') {
1286 $errorstring =
'MainAccountForSubscriptionPaymentNotDefined';
1288 $accounttoshow =
'<span class="error small">'.$langs->trans($errorstring).
'</span>';
1291 print
'<td class="maxwidth300" title="'.dol_escape_htmltag(
dol_string_nohtmltag($accounttoshow)).
'">';
1292 print $accounttoshow;
1296 $accounttoshowsubledger =
'';
1297 if (in_array($tabtype[$key], array(
'payment',
'payment_supplier',
'payment_expensereport',
'payment_salary',
'payment_various'))) {
1299 if ($accounttoshow != $accounttoshowsubledger) {
1300 if (empty($accounttoshowsubledger) || $accounttoshowsubledger ==
'NotDefined') {
1305 if (!empty($tabcompany[$key][
'code_compta'])) {
1306 if (in_array($tabtype[$key], array(
'payment_various',
'payment_salary'))) {
1308 $accounttoshowsubledger =
'<span class="warning small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknownSubledgerIgnored").
'</span>';
1310 $accounttoshowsubledger =
'<span class="warning small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknown", $tabcompany[$key][
'code_compta']).
'</span>';
1313 $accounttoshowsubledger =
'<span class="error small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknownBlocking").
'</span>';
1317 $accounttoshowsubledger =
'';
1320 print
'<td class="maxwidth300">';
1321 print $accounttoshowsubledger;
1324 print
"<td>".$reflabel.
"</td>";
1326 print
'<td class="center">'.$val[
"type_payment"].
"</td>";
1328 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1330 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1336 foreach ($tabbq[$key] as $k => $mt) {
1339 if (!empty($val[
'lib'])) {
1340 $reflabel .= $val[
'lib'].
" - ";
1342 $reflabel .=
'WaitingAccount';
1344 print
'<!-- Wait bank.rowid='.$key.
' -->';
1345 print
'<tr class="oddeven">';
1346 print
"<td>".$date.
"</td>";
1347 print
"<td>".$ref.
"</td>";
1365 print
"<td>".$reflabel.
"</td>";
1366 print
'<td class="center">'.$val[
"type_payment"].
"</td>";
1367 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1368 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1399 if ($ref ==
'(SupplierInvoicePayment)' || $ref ==
'(SupplierInvoicePaymentBack)') {
1400 $ref = $langs->transnoentitiesnoconv(
'Supplier');
1402 if ($ref ==
'(CustomerInvoicePayment)' || $ref ==
'(CustomerInvoicePaymentBack)') {
1403 $ref = $langs->transnoentitiesnoconv(
'Customer');
1405 if ($ref ==
'(SocialContributionPayment)') {
1406 $ref = $langs->transnoentitiesnoconv(
'SocialContribution');
1408 if ($ref ==
'(DonationPayment)') {
1409 $ref = $langs->transnoentitiesnoconv(
'Donation');
1411 if ($ref ==
'(SubscriptionPayment)') {
1412 $ref = $langs->transnoentitiesnoconv(
'Subscription');
1414 if ($ref ==
'(ExpenseReportPayment)') {
1415 $ref = $langs->transnoentitiesnoconv(
'Employee');
1417 if ($ref ==
'(LoanPayment)') {
1418 $ref = $langs->transnoentitiesnoconv(
'Loan');
1420 if ($ref ==
'(payment_salary)') {
1421 $ref = $langs->transnoentitiesnoconv(
'Employee');
1425 if ($typerecord ==
'payment') {
1427 $sqlmid =
"SELECT payfac.fk_facture as id, ".$db->ifsql(
'f1.rowid IS NULL',
'f.ref',
'f1.ref').
" as ref";
1428 $sqlmid .=
" FROM ".$db->prefix().
"paiement_facture as payfac";
1429 $sqlmid .=
" LEFT JOIN ".$db->prefix().
"facture as f ON f.rowid = payfac.fk_facture";
1430 $sqlmid .=
" LEFT JOIN ".$db->prefix().
"societe_remise_except as sre ON sre.fk_facture_source = payfac.fk_facture";
1431 $sqlmid .=
" LEFT JOIN ".$db->prefix().
"facture as f1 ON f1.rowid = sre.fk_facture";
1432 $sqlmid .=
" WHERE payfac.fk_paiement=".((int) $val[
'paymentid']);
1434 $sqlmid =
"SELECT payfac.fk_facture as id, f.ref as ref";
1435 $sqlmid .=
" FROM ".$db->prefix().
"paiement_facture as payfac";
1436 $sqlmid .=
" INNER JOIN ".$db->prefix().
"facture as f ON f.rowid = payfac.fk_facture";
1437 $sqlmid .=
" WHERE payfac.fk_paiement=".((int) $val[
'paymentid']);
1439 $ref = $langs->transnoentitiesnoconv(
"Invoice");
1440 } elseif ($typerecord ==
'payment_supplier') {
1441 $sqlmid =
'SELECT payfac.fk_facturefourn as id, f.ref';
1442 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as payfac, ".MAIN_DB_PREFIX.
"facture_fourn as f";
1443 $sqlmid .=
" WHERE payfac.fk_facturefourn = f.rowid AND payfac.fk_paiementfourn=".((int) $val[
"paymentsupplierid"]);
1444 $ref = $langs->transnoentitiesnoconv(
"SupplierInvoice");
1445 } elseif ($typerecord ==
'payment_expensereport') {
1446 $sqlmid =
'SELECT e.rowid as id, e.ref';
1447 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_expensereport as pe, ".MAIN_DB_PREFIX.
"expensereport as e";
1448 $sqlmid .=
" WHERE pe.rowid=".((int) $val[
"paymentexpensereport"]).
" AND pe.fk_expensereport = e.rowid";
1449 $ref = $langs->transnoentitiesnoconv(
"ExpenseReport");
1450 } elseif ($typerecord ==
'payment_salary') {
1451 $sqlmid =
'SELECT s.rowid as ref';
1452 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as s";
1453 $sqlmid .=
" WHERE s.rowid=".((int) $val[
"paymentsalid"]);
1454 $ref = $langs->transnoentitiesnoconv(
"SalaryPayment");
1455 } elseif ($typerecord ==
'sc') {
1456 $sqlmid =
'SELECT sc.rowid as ref';
1457 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"paiementcharge as sc";
1458 $sqlmid .=
" WHERE sc.rowid=".((int) $val[
"paymentscid"]);
1459 $ref = $langs->transnoentitiesnoconv(
"SocialContribution");
1460 } elseif ($typerecord ==
'payment_vat') {
1461 $sqlmid =
'SELECT v.rowid as ref';
1462 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"tva as v";
1463 $sqlmid .=
" WHERE v.rowid=".((int) $val[
"paymentvatid"]);
1464 $ref = $langs->transnoentitiesnoconv(
"PaymentVat");
1465 } elseif ($typerecord ==
'payment_donation') {
1466 $sqlmid =
'SELECT payd.fk_donation as ref';
1467 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_donation as payd";
1468 $sqlmid .=
" WHERE payd.fk_donation=".((int) $val[
"paymentdonationid"]);
1469 $ref = $langs->transnoentitiesnoconv(
"Donation");
1470 } elseif ($typerecord ==
'payment_loan') {
1471 $sqlmid =
'SELECT l.rowid as ref';
1472 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_loan as l";
1473 $sqlmid .=
" WHERE l.rowid=".((int) $val[
"paymentloanid"]);
1474 $ref = $langs->transnoentitiesnoconv(
"LoanPayment");
1475 } elseif ($typerecord ==
'payment_various') {
1476 $sqlmid =
'SELECT v.rowid as ref';
1477 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_various as v";
1478 $sqlmid .=
" WHERE v.rowid=".((int) $val[
"paymentvariousid"]);
1479 $ref = $langs->transnoentitiesnoconv(
"VariousPayment");
1482 if (empty($sqlmid)) {
1483 dol_syslog(
"Found a typerecord=".$typerecord.
" not supported", LOG_WARNING);
1487 dol_syslog(
"accountancy/journal/bankjournal.php::sqlmid=".$sqlmid, LOG_DEBUG);
1488 $resultmid = $db->query($sqlmid);
1490 while ($objmid = $db->fetch_object($resultmid)) {
1491 $ref .=
' '.$objmid->ref;
1498 $ref =
dol_trunc($langs->transnoentitiesnoconv(
"BankId").
' '.$val[
'fk_bank'].
' - '.$ref, 295);