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 $tabtp[$obj->rowid][$compta_soc] += $amounttouse;
354 } elseif ($links[$key][
'type'] ==
'user') {
355 $userstatic->id = $links[$key][
'url_id'];
356 $userstatic->name = $links[$key][
'label'];
357 $userstatic->email = $tabuser[$obj->rowid][
'email'];
358 $userstatic->firstname = $tabuser[$obj->rowid][
'firstname'];
359 $userstatic->lastname = $tabuser[$obj->rowid][
'lastname'];
360 $userstatic->statut = $tabuser[$obj->rowid][
'status'];
361 $userstatic->accountancy_code = $tabuser[$obj->rowid][
'accountancy_code'];
362 if ($userstatic->id > 0) {
363 $tabpay[$obj->rowid][
"soclib"] = $userstatic->getNomUrl(1,
'accountancy', 0);
365 $tabpay[$obj->rowid][
"soclib"] =
'???';
368 $tabtp[$obj->rowid][$compta_user] += $amounttouse;
370 } elseif ($links[$key][
'type'] ==
'sc') {
371 $chargestatic->id = $links[$key][
'url_id'];
372 $chargestatic->ref = $links[$key][
'url_id'];
374 $tabpay[$obj->rowid][
"lib"] .=
' '.$chargestatic->getNomUrl(2);
376 if (preg_match(
'/^\((.*)\)$/i', $links[$key][
'label'], $reg)) {
377 if ($reg[1] ==
'socialcontribution') {
378 $reg[1] =
'SocialContribution';
380 $chargestatic->label = $langs->trans($reg[1]);
382 $chargestatic->label = $links[$key][
'label'];
384 $chargestatic->ref = $chargestatic->label;
385 $tabpay[$obj->rowid][
"soclib"] = $chargestatic->getNomUrl(1, 30);
386 $tabpay[$obj->rowid][
"paymentscid"] = $chargestatic->id;
390 $sqlmid =
"SELECT cchgsoc.accountancy_code";
391 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales cchgsoc";
392 $sqlmid .=
" INNER JOIN ".MAIN_DB_PREFIX.
"chargesociales as chgsoc ON chgsoc.fk_type = cchgsoc.id";
393 $sqlmid .=
" INNER JOIN ".MAIN_DB_PREFIX.
"paiementcharge as paycharg ON paycharg.fk_charge = chgsoc.rowid";
394 $sqlmid .=
" INNER JOIN ".MAIN_DB_PREFIX.
"bank_url as bkurl ON bkurl.url_id=paycharg.rowid AND bkurl.type = 'payment_sc'";
395 $sqlmid .=
" WHERE bkurl.fk_bank = ".((int) $obj->rowid);
397 dol_syslog(
"accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);
398 $resultmid = $db->query($sqlmid);
400 $objmid = $db->fetch_object($resultmid);
401 $tabtp[$obj->rowid][$objmid->accountancy_code] += $amounttouse;
403 } elseif ($links[$key][
'type'] ==
'payment_donation') {
404 $paymentdonstatic->id = $links[$key][
'url_id'];
405 $paymentdonstatic->ref = $links[$key][
'url_id'];
406 $paymentdonstatic->fk_donation = $links[$key][
'url_id'];
407 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentdonstatic->getNomUrl(2);
408 $tabpay[$obj->rowid][
"paymentdonationid"] = $paymentdonstatic->id;
409 $tabtp[$obj->rowid][$account_pay_donation] += $amounttouse;
410 } elseif ($links[$key][
'type'] ==
'member') {
411 $paymentsubscriptionstatic->id = $links[$key][
'url_id'];
412 $paymentsubscriptionstatic->ref = $links[$key][
'url_id'];
413 $paymentsubscriptionstatic->label = $links[$key][
'label'];
414 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentsubscriptionstatic->getNomUrl(2);
415 $tabpay[$obj->rowid][
"paymentsubscriptionid"] = $paymentsubscriptionstatic->id;
416 $paymentsubscriptionstatic->fetch($paymentsubscriptionstatic->id);
417 $tabtp[$obj->rowid][$account_pay_subscription] += $amounttouse;
418 } elseif ($links[$key][
'type'] ==
'payment_vat') {
419 $paymentvatstatic->id = $links[$key][
'url_id'];
420 $paymentvatstatic->ref = $links[$key][
'url_id'];
421 $paymentvatstatic->label = $links[$key][
'label'];
422 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentvatstatic->getNomUrl(2);
423 $tabpay[$obj->rowid][
"paymentvatid"] = $paymentvatstatic->id;
424 $tabtp[$obj->rowid][$account_pay_vat] += $amounttouse;
425 } elseif ($links[$key][
'type'] ==
'payment_salary') {
426 $paymentsalstatic->id = $links[$key][
'url_id'];
427 $paymentsalstatic->ref = $links[$key][
'url_id'];
428 $paymentsalstatic->label = $links[$key][
'label'];
429 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentsalstatic->getNomUrl(2);
430 $tabpay[$obj->rowid][
"paymentsalid"] = $paymentsalstatic->id;
434 if (!empty($conf->global->ACCOUNTANCY_AUTOFIX_MISSING_LINK_TO_USEr_ON_SALARY_BANK_PAYMENT)) {
435 $tmpsalary =
new Salary($db);
436 $tmpsalary->fetch($paymentsalstatic->id);
437 $tmpsalary->fetch_user($tmpsalary->fk_user);
439 $userstatic->id = $tmpsalary->user->id;
440 $userstatic->name = $tmpsalary->user->name;
441 $userstatic->email = $tmpsalary->user->email;
442 $userstatic->firstname = $tmpsalary->user->firstname;
443 $userstatic->lastname = $tmpsalary->user->lastname;
444 $userstatic->statut = $tmpsalary->user->statut;
445 $userstatic->accountancy_code = $tmpsalary->user->accountancy_code;
447 if ($userstatic->id > 0) {
448 $tabpay[$obj->rowid][
"soclib"] = $userstatic->getNomUrl(1,
'accountancy', 0);
450 $tabpay[$obj->rowid][
"soclib"] =
'???';
453 if (empty($obj->typeop_user)) {
454 $compta_user = $userstatic->accountancy_code;
456 $tabtp[$obj->rowid][$compta_user] += $amounttouse;
457 $tabuser[$obj->rowid] = array(
458 'id' => $userstatic->id,
460 'lastname' => $userstatic->lastname,
461 'firstname' => $userstatic->firstname,
462 'email' => $userstatic->email,
463 'accountancy_code' => $compta_user,
464 'status' => $userstatic->statut
469 } elseif ($links[$key][
'type'] ==
'payment_expensereport') {
470 $paymentexpensereportstatic->id = $links[$key][
'url_id'];
471 $tabpay[$obj->rowid][
"lib"] .= $paymentexpensereportstatic->getNomUrl(2);
472 $tabpay[$obj->rowid][
"paymentexpensereport"] = $paymentexpensereportstatic->id;
473 } elseif ($links[$key][
'type'] ==
'payment_various') {
474 $paymentvariousstatic->id = $links[$key][
'url_id'];
475 $paymentvariousstatic->ref = $links[$key][
'url_id'];
476 $paymentvariousstatic->label = $links[$key][
'label'];
477 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentvariousstatic->getNomUrl(2);
478 $tabpay[$obj->rowid][
"paymentvariousid"] = $paymentvariousstatic->id;
479 $paymentvariousstatic->fetch($paymentvariousstatic->id);
480 $account_various = (!empty($paymentvariousstatic->accountancy_code) ? $paymentvariousstatic->accountancy_code :
'NotDefined');
481 $account_subledger = (!empty($paymentvariousstatic->subledger_account) ? $paymentvariousstatic->subledger_account :
'');
482 $tabpay[$obj->rowid][
"account_various"] = $account_various;
483 $tabtp[$obj->rowid][$account_subledger] += $amounttouse;
484 } elseif ($links[$key][
'type'] ==
'payment_loan') {
485 $paymentloanstatic->id = $links[$key][
'url_id'];
486 $paymentloanstatic->ref = $links[$key][
'url_id'];
487 $paymentloanstatic->fk_loan = $links[$key][
'url_id'];
488 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentloanstatic->getNomUrl(2);
489 $tabpay[$obj->rowid][
"paymentloanid"] = $paymentloanstatic->id;
491 $sqlmid =
'SELECT pl.amount_capital, pl.amount_insurance, pl.amount_interest, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest';
492 $sqlmid .=
' FROM '.MAIN_DB_PREFIX.
'payment_loan as pl, '.MAIN_DB_PREFIX.
'loan as l';
493 $sqlmid .=
' WHERE l.rowid = pl.fk_loan AND pl.fk_bank = '.((int) $obj->rowid);
495 dol_syslog(
"accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);
496 $resultmid = $db->query($sqlmid);
498 $objmid = $db->fetch_object($resultmid);
499 $tabtp[$obj->rowid][$objmid->accountancy_account_capital] -= $objmid->amount_capital;
500 $tabtp[$obj->rowid][$objmid->accountancy_account_insurance] -= $objmid->amount_insurance;
501 $tabtp[$obj->rowid][$objmid->accountancy_account_interest] -= $objmid->amount_interest;
503 } elseif ($links[$key][
'type'] ==
'banktransfert') {
504 $accountLinestatic->fetch($links[$key][
'url_id']);
505 $tabpay[$obj->rowid][
"lib"] .=
' '.$langs->trans(
"BankTransfer").
'- '.$accountLinestatic ->getNomUrl(1);
506 $tabtp[$obj->rowid][$account_transfer] += $amounttouse;
507 $bankaccountstatic->fetch($tabpay[$obj->rowid][
'fk_bank_account']);
508 $tabpay[$obj->rowid][
"soclib"] = $bankaccountstatic->getNomUrl(2);
513 $tabbq[$obj->rowid][$compta_bank] += $amounttouse;
517 if (empty($tabtp[$obj->rowid]) && !empty($tabmoreinfo[$obj->rowid][
'withdraw'])) {
518 foreach ($links as $key => $val) {
519 if ($links[$key][
'type'] ==
'payment') {
521 $tmppayment->fetch($links[$key][
'url_id']);
522 $arrayofamounts = $tmppayment->getAmountsArray();
523 if (is_array($arrayofamounts)) {
524 foreach ($arrayofamounts as $invoiceid => $amount) {
525 $tmpinvoice->fetch($invoiceid);
526 $tmpinvoice->fetch_thirdparty();
527 if ($tmpinvoice->thirdparty->code_compta) {
528 $tabtp[$obj->rowid][$tmpinvoice->thirdparty->code_compta] += $amount;
537 if (empty($tabtp[$obj->rowid])) {
538 $tabtp[$obj->rowid][
'NotDefined'] = $tabbq[$obj->rowid][$compta_bank];
576 if (!$error && $action ==
'writebookkeeping') {
580 $accountingaccountcustomer->fetch(
null, $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER,
true);
583 $accountingaccountsupplier->fetch(
null, $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER,
true);
586 $accountingaccountpayment->fetch(
null, $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT,
true);
589 $accountingaccountsuspense->fetch(
null, $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE,
true);
592 foreach ($tabpay as $key => $val) {
610 if (!$errorforline && is_array($tabbq[$key])) {
612 foreach ($tabbq[$key] as $k => $mt) {
614 $accountingaccount->fetch(
null, $k,
true);
615 $account_label = $accountingaccount->label;
618 if (!empty($val[
'lib'])) {
622 if (!empty($val[
'soclib'])) {
623 $reflabel .=
" - ".dol_string_nohtmltag($val[
'soclib']);
627 $bookkeeping->doc_date = $val[
"date"];
628 $bookkeeping->doc_ref = $ref;
629 $bookkeeping->doc_type =
'bank';
630 $bookkeeping->fk_doc = $key;
631 $bookkeeping->fk_docdet = $val[
"fk_bank"];
633 $bookkeeping->numero_compte = $k;
634 $bookkeeping->label_compte = $account_label;
636 $bookkeeping->label_operation = $reflabel;
637 $bookkeeping->montant = $mt;
638 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
639 $bookkeeping->debit = ($mt >= 0 ? $mt : 0);
640 $bookkeeping->credit = ($mt < 0 ? -$mt : 0);
641 $bookkeeping->code_journal = $journal;
642 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
643 $bookkeeping->fk_user_author = $user->id;
644 $bookkeeping->date_creation = $now;
647 $bookkeeping->subledger_account =
'';
648 $bookkeeping->label_operation = $reflabel;
649 $bookkeeping->entity = $conf->entity;
651 $totaldebit += $bookkeeping->debit;
652 $totalcredit += $bookkeeping->credit;
654 $result = $bookkeeping->create($user);
656 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
659 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded',
null,
'warnings');
671 if (!$errorforline) {
672 if (is_array($tabtp[$key])) {
674 foreach ($tabtp[$key] as $k => $mt) {
679 if (!empty($val[
'lib'])) {
682 if ($tabtype[$key] ==
'banktransfert') {
683 $reflabel .=
dol_string_nohtmltag($langs->transnoentitiesnoconv(
'TransitionalAccount').
' '.$account_transfer);
689 $bookkeeping->doc_date = $val[
"date"];
690 $bookkeeping->doc_ref = $ref;
691 $bookkeeping->doc_type =
'bank';
692 $bookkeeping->fk_doc = $key;
693 $bookkeeping->fk_docdet = $val[
"fk_bank"];
695 $bookkeeping->label_operation = $reflabel;
696 $bookkeeping->montant = $mt;
697 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
698 $bookkeeping->debit = ($mt < 0 ? -$mt : 0);
699 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
700 $bookkeeping->code_journal = $journal;
701 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
702 $bookkeeping->fk_user_author = $user->id;
703 $bookkeeping->date_creation = $now;
705 if ($tabtype[$key] ==
'payment') {
707 $bookkeeping->subledger_account = $k;
708 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
709 $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
710 $bookkeeping->label_compte = $accountingaccountcustomer->label;
711 } elseif ($tabtype[$key] ==
'payment_supplier') {
713 $bookkeeping->subledger_account = $k;
714 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
715 $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER;
716 $bookkeeping->label_compte = $accountingaccountsupplier->label;
717 } elseif ($tabtype[$key] ==
'payment_expensereport') {
718 $bookkeeping->subledger_account = $tabuser[$key][
'accountancy_code'];
719 $bookkeeping->subledger_label = $tabuser[$key][
'name'];
720 $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT;
721 $bookkeeping->label_compte = $accountingaccountpayment->label;
722 } elseif ($tabtype[$key] ==
'payment_salary') {
723 $bookkeeping->subledger_account = $tabuser[$key][
'accountancy_code'];
724 $bookkeeping->subledger_label = $tabuser[$key][
'name'];
725 $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT;
726 $bookkeeping->label_compte = $accountingaccountpayment->label;
727 } elseif (in_array($tabtype[$key], array(
'sc',
'payment_sc'))) {
728 $bookkeeping->subledger_account =
'';
729 $bookkeeping->subledger_label =
'';
730 $accountingaccount->fetch(
null, $k,
true);
731 $bookkeeping->numero_compte = $k;
732 $bookkeeping->label_compte = $accountingaccount->label;
733 } elseif ($tabtype[$key] ==
'payment_vat') {
734 $bookkeeping->subledger_account =
'';
735 $bookkeeping->subledger_label =
'';
736 $accountingaccount->fetch(
null, $k,
true);
737 $bookkeeping->numero_compte = $k;
738 $bookkeeping->label_compte = $accountingaccount->label;
739 } elseif ($tabtype[$key] ==
'payment_donation') {
740 $bookkeeping->subledger_account =
'';
741 $bookkeeping->subledger_label =
'';
742 $accountingaccount->fetch(
null, $k,
true);
743 $bookkeeping->numero_compte = $k;
744 $bookkeeping->label_compte = $accountingaccount->label;
745 } elseif ($tabtype[$key] ==
'member') {
746 $bookkeeping->subledger_account =
'';
747 $bookkeeping->subledger_label =
'';
748 $accountingaccount->fetch(
null, $k,
true);
749 $bookkeeping->numero_compte = $k;
750 $bookkeeping->label_compte = $accountingaccount->label;
751 } elseif ($tabtype[$key] ==
'payment_loan') {
752 $bookkeeping->subledger_account =
'';
753 $bookkeeping->subledger_label =
'';
754 $accountingaccount->fetch(
null, $k,
true);
755 $bookkeeping->numero_compte = $k;
756 $bookkeeping->label_compte = $accountingaccount->label;
757 } elseif ($tabtype[$key] ==
'payment_various') {
758 $bookkeeping->subledger_account = $k;
759 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
760 $accountingaccount->fetch(
null, $tabpay[$key][
"account_various"],
true);
761 $bookkeeping->numero_compte = $tabpay[$key][
"account_various"];
762 $bookkeeping->label_compte = $accountingaccount->label;
763 } elseif ($tabtype[$key] ==
'banktransfert') {
764 $bookkeeping->subledger_account =
'';
765 $bookkeeping->subledger_label =
'';
766 $accountingaccount->fetch(
null, $k,
true);
767 $bookkeeping->numero_compte = $k;
768 $bookkeeping->label_compte = $accountingaccount->label;
770 if ($tabtype[$key] ==
'unknown') {
772 $bookkeeping->subledger_account =
'';
773 $bookkeeping->subledger_label =
'';
774 $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE;
775 $bookkeeping->label_compte = $accountingaccountsuspense->label;
778 $bookkeeping->label_operation = $reflabel;
779 $bookkeeping->entity = $conf->entity;
781 $totaldebit += $bookkeeping->debit;
782 $totalcredit += $bookkeeping->credit;
784 $result = $bookkeeping->create($user);
786 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
789 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded',
null,
'warnings');
797 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/lettering.class.php';
799 $nb_lettering = $lettering_static->bookkeepingLetteringAll(array($bookkeeping->id));
805 foreach ($tabbq[$key] as $k => $mt) {
808 if (!empty($val[
'lib'])) {
814 $bookkeeping->doc_date = $val[
"date"];
815 $bookkeeping->doc_ref = $ref;
816 $bookkeeping->doc_type =
'bank';
817 $bookkeeping->fk_doc = $key;
818 $bookkeeping->fk_docdet = $val[
"fk_bank"];
819 $bookkeeping->montant = $mt;
820 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
821 $bookkeeping->debit = ($mt < 0 ? -$mt : 0);
822 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
823 $bookkeeping->code_journal = $journal;
824 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
825 $bookkeeping->fk_user_author = $user->id;
826 $bookkeeping->date_creation = $now;
827 $bookkeeping->label_compte =
'';
828 $bookkeeping->label_operation = $reflabel;
829 $bookkeeping->entity = $conf->entity;
831 $totaldebit += $bookkeeping->debit;
832 $totalcredit += $bookkeeping->credit;
834 $result = $bookkeeping->create($user);
837 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
840 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded',
null,
'warnings');
855 setEventMessages(
'Try to insert a non balanced transaction in book for '.$ref.
'. Canceled. Surely a bug.',
null,
'errors');
858 if (!$errorforline) {
865 if ($error >= $MAXNBERRORS) {
866 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped").
' (>'.$MAXNBERRORS.
')',
null,
'errors');
872 if (empty($error) && count($tabpay) > 0) {
874 } elseif (count($tabpay) == $error) {
877 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
883 if (count($tabpay) != $error) {
884 $param =
'id_journal='.$id_journal;
885 $param .=
'&date_startday='.$date_startday;
886 $param .=
'&date_startmonth='.$date_startmonth;
887 $param .=
'&date_startyear='.$date_startyear;
888 $param .=
'&date_endday='.$date_endday;
889 $param .=
'&date_endmonth='.$date_endmonth;
890 $param .=
'&date_endyear='.$date_endyear;
891 $param .=
'&in_bookkeeping='.$in_bookkeeping;
892 header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
900 if ($action ==
'exportcsv') {
901 $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
903 $filename =
'journal';
904 $type_export =
'journal';
905 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
908 print
'"'.$langs->transnoentitiesnoconv(
"BankId").
'"'.$sep;
909 print
'"'.$langs->transnoentitiesnoconv(
"Date").
'"'.$sep;
910 print
'"'.$langs->transnoentitiesnoconv(
"PaymentMode").
'"'.$sep;
911 print
'"'.$langs->transnoentitiesnoconv(
"AccountAccounting").
'"'.$sep;
912 print
'"'.$langs->transnoentitiesnoconv(
"LedgerAccount").
'"'.$sep;
913 print
'"'.$langs->transnoentitiesnoconv(
"SubledgerAccount").
'"'.$sep;
914 print
'"'.$langs->transnoentitiesnoconv(
"Label").
'"'.$sep;
915 print
'"'.$langs->transnoentitiesnoconv(
"Debit").
'"'.$sep;
916 print
'"'.$langs->transnoentitiesnoconv(
"Credit").
'"'.$sep;
917 print
'"'.$langs->transnoentitiesnoconv(
"Journal").
'"'.$sep;
918 print
'"'.$langs->transnoentitiesnoconv(
"Note").
'"'.$sep;
921 foreach ($tabpay as $key => $val) {
927 foreach ($tabbq[$key] as $k => $mt) {
930 if (!empty($val[
'lib'])) {
934 if (!empty($val[
'soclib'])) {
935 $reflabel .=
" - ".dol_string_nohtmltag($val[
'soclib']);
938 print
'"'.$key.
'"'.$sep;
939 print
'"'.$date.
'"'.$sep;
940 print
'"'.$val[
"type_payment"].
'"'.$sep;
941 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
942 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
944 print
'"'.$reflabel.
'"'.$sep;
945 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
946 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
947 print
'"'.$journal.
'"'.$sep;
948 print
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
954 if (is_array($tabtp[$key])) {
955 foreach ($tabtp[$key] as $k => $mt) {
958 if (!empty($val[
'lib'])) {
961 if ($tabtype[$key] ==
'banktransfert') {
962 $reflabel .=
dol_string_nohtmltag($langs->transnoentitiesnoconv(
'TransitionalAccount').
' '.$account_transfer);
967 print
'"'.$key.
'"'.$sep;
968 print
'"'.$date.
'"'.$sep;
969 print
'"'.$val[
"type_payment"].
'"'.$sep;
970 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
971 if ($tabtype[$key] ==
'payment_supplier') {
972 print
'"'.$conf->global->ACCOUNTING_ACCOUNT_SUPPLIER.
'"'.$sep;
973 } elseif ($tabtype[$key] ==
'payment') {
974 print
'"'.$conf->global->ACCOUNTING_ACCOUNT_CUSTOMER.
'"'.$sep;
975 } elseif ($tabtype[$key] ==
'payment_expensereport') {
976 print
'"'.$conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT.
'"'.$sep;
977 } elseif ($tabtype[$key] ==
'payment_salary') {
978 print
'"'.$conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT.
'"'.$sep;
980 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
982 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
983 print
'"'.$reflabel.
'"'.$sep;
984 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
985 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
986 print
'"'.$journal.
'"'.$sep;
987 print
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
992 foreach ($tabbq[$key] as $k => $mt) {
995 if (!empty($val[
'lib'])) {
1000 print
'"'.$key.
'"'.$sep;
1001 print
'"'.$date.
'"'.$sep;
1002 print
'"'.$val[
"type_payment"].
'"'.$sep;
1003 print
'"'.length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE).
'"'.$sep;
1004 print
'"'.length_accounta($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE).
'"'.$sep;
1006 print
'"'.$reflabel.
'"'.$sep;
1007 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1008 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1009 print
'"'.$journal.
'"'.$sep;
1010 print
'"'.dol_string_nohtmltag($ref).
'"'.$sep;
1025 if (empty($action) || $action ==
'view') {
1026 $invoicestatic =
new Facture($db);
1029 $vatstatic =
new Tva($db);
1030 $donationstatic =
new Don($db);
1031 $loanstatic =
new Loan($db);
1032 $salarystatic =
new Salary($db);
1035 llxHeader(
'', $langs->trans(
"FinanceJournal"));
1037 $nom = $langs->trans(
"FinanceJournal").
' | '.$accountingjournalstatic->getNomUrl(0, 1, 1,
'', 1);
1040 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
1042 $listofchoices = array(
1043 'notyet'=>$langs->trans(
"NotYetInGeneralLedger"),
1044 'already'=>$langs->trans(
"AlreadyInGeneralLedger")
1046 $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);
1047 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.
$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
1049 $varlink =
'id_journal='.$id_journal;
1053 journalHead($nom,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
1057 $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";
1058 $resql = $db->query($sql);
1060 $obj = $db->fetch_object(
$resql);
1062 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheJournalCodeIsNotDefinedOnSomeBankAccount");
1063 $desc =
' : '.$langs->trans(
"AccountancyAreaDescBank", 9,
'{link}');
1064 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"BankAccounts").
'</strong>', $desc);
1074 if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
"") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
'-1'
1075 || ($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
"") || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
'-1'
1076 || empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) || $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT ==
'-1') {
1077 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
1078 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
1079 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
1085 print
'<div class="tabsAction tabsActionNoBottom centerimp">';
1087 if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping ==
'notyet') {
1088 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
1091 if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
"") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
'-1'
1092 || ($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
"") || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
'-1') {
1093 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
1095 if ($in_bookkeeping ==
'notyet') {
1096 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
1098 print
'<a class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
1106 <script type="text/javascript">
1107 function launch_export() {
1108 console.log("Set value into form and submit");
1109 $("div.fiche form input[name=\"action\"]").val("exportcsv");
1110 $("div.fiche form input[type=\"submit\"]").click();
1111 $("div.fiche form input[name=\"action\"]").val("");
1113 function writebookkeeping() {
1114 console.log("Set value into form and submit");
1115 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
1116 $("div.fiche form input[type=\"submit\"]").click();
1117 $("div.fiche form input[name=\"action\"]").val("");
1127 print
'<div class="div-table-responsive">';
1128 print
"<table class=\"noborder\" width=\"100%\">";
1129 print
"<tr class=\"liste_titre\">";
1130 print
"<td>".$langs->trans(
"Date").
"</td>";
1131 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"ObjectsRef").
")</td>";
1132 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
1133 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
1134 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
1135 print
'<td class="center">'.$langs->trans(
"PaymentMode").
"</td>";
1136 print
'<td class="right">'.$langs->trans(
"Debit").
"</td>";
1137 print
'<td class="right">'.$langs->trans(
"Credit").
"</td>";
1142 foreach ($tabpay as $key => $val) {
1148 foreach ($tabbq[$key] as $k => $mt) {
1151 if (!empty($val[
'lib'])) {
1152 $reflabel .= $val[
'lib'].
" - ";
1154 $reflabel .= $langs->trans(
"Bank").
' '.$val[
'bank_account_ref'];
1155 if (!empty($val[
'soclib'])) {
1156 $reflabel .=
" - ".$val[
'soclib'];
1160 print
'<!-- Bank bank.rowid='.$key.
' type='.$tabpay[$key][
'type'].
' ref='.$tabpay[$key][
'ref'].
'-->';
1161 print
'<tr class="oddeven">';
1164 print
"<td>".$date.
"</td>";
1167 print
"<td>".dol_escape_htmltag($ref).
"</td>";
1171 if (empty($accounttoshow) || $accounttoshow ==
'NotDefined') {
1172 $accounttoshow =
'<span class="error">'.$langs->trans(
"BankAccountNotDefined").
'</span>';
1174 print
'<td class="maxwidth300" title="'.dol_escape_htmltag(
dol_string_nohtmltag($accounttoshow)).
'">';
1175 print $accounttoshow;
1179 print
'<td class="maxwidth300">';
1193 print
'<td class="center">'.$val[
"type_payment"].
"</td>";
1194 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1195 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1201 if (is_array($tabtp[$key])) {
1202 foreach ($tabtp[$key] as $k => $mt) {
1205 if (!empty($val[
'lib'])) {
1206 $reflabel .= $val[
'lib'].($val[
'soclib'] ?
" - " :
"");
1208 if ($tabtype[$key] ==
'banktransfert') {
1209 $reflabel .= $langs->trans(
'TransitionalAccount').
' '.$account_transfer;
1211 $reflabel .= $val[
'soclib'];
1214 print
'<!-- Thirdparty bank.rowid='.$key.
' -->';
1215 print
'<tr class="oddeven">';
1218 print
"<td>".$date.
"</td>";
1221 print
"<td>".dol_escape_htmltag($ref).
"</td>";
1224 $account_ledger = $k;
1226 if ($tabtype[$key] ==
'payment') {
1227 $account_ledger = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
1229 if ($tabtype[$key] ==
'payment_supplier') {
1230 $account_ledger = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER;
1232 if ($tabtype[$key] ==
'payment_expensereport') {
1233 $account_ledger = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT;
1235 if ($tabtype[$key] ==
'payment_salary') {
1236 $account_ledger = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT;
1238 if ($tabtype[$key] ==
'payment_vat') {
1239 $account_ledger = $conf->global->ACCOUNTING_VAT_PAY_ACCOUNT;
1241 if ($tabtype[$key] ==
'member') {
1242 $account_ledger = $conf->global->ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT;
1244 if ($tabtype[$key] ==
'payment_various') {
1245 $account_ledger = $tabpay[$key][
"account_various"];
1248 if (empty($accounttoshow) || $accounttoshow ==
'NotDefined') {
1249 if ($tabtype[$key] ==
'unknown') {
1251 if (empty($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) || $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE ==
'-1') {
1252 $accounttoshow =
'<span class="error small">'.$langs->trans(
'UnknownAccountForThirdpartyAndWaitingAccountNotDefinedBlocking').
'</span>';
1254 $accounttoshow =
'<span class="warning small">'.$langs->trans(
'UnknownAccountForThirdparty',
length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE)).
'</span>';
1258 $errorstring =
'UnknownAccountForThirdpartyBlocking';
1259 if ($tabtype[$key] ==
'payment') {
1260 $errorstring =
'MainAccountForCustomersNotDefined';
1262 if ($tabtype[$key] ==
'payment_supplier') {
1263 $errorstring =
'MainAccountForSuppliersNotDefined';
1265 if ($tabtype[$key] ==
'payment_expensereport') {
1266 $errorstring =
'MainAccountForUsersNotDefined';
1268 if ($tabtype[$key] ==
'payment_salary') {
1269 $errorstring =
'MainAccountForUsersNotDefined';
1271 if ($tabtype[$key] ==
'payment_vat') {
1272 $errorstring =
'MainAccountForVatPaymentNotDefined';
1274 if ($tabtype[$key] ==
'member') {
1275 $errorstring =
'MainAccountForSubscriptionPaymentNotDefined';
1277 $accounttoshow =
'<span class="error small">'.$langs->trans($errorstring).
'</span>';
1280 print
'<td class="maxwidth300" title="'.dol_escape_htmltag(
dol_string_nohtmltag($accounttoshow)).
'">';
1281 print $accounttoshow;
1285 $accounttoshowsubledger =
'';
1286 if (in_array($tabtype[$key], array(
'payment',
'payment_supplier',
'payment_expensereport',
'payment_salary',
'payment_various'))) {
1288 if ($accounttoshow != $accounttoshowsubledger) {
1289 if (empty($accounttoshowsubledger) || $accounttoshowsubledger ==
'NotDefined') {
1294 if (!empty($tabcompany[$key][
'code_compta'])) {
1295 if (in_array($tabtype[$key], array(
'payment_various',
'payment_salary'))) {
1297 $accounttoshowsubledger =
'<span class="warning small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknownSubledgerIgnored").
'</span>';
1299 $accounttoshowsubledger =
'<span class="warning small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknown", $tabcompany[$key][
'code_compta']).
'</span>';
1302 $accounttoshowsubledger =
'<span class="error small">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknownBlocking").
'</span>';
1306 $accounttoshowsubledger =
'';
1309 print
'<td class="maxwidth300">';
1310 print $accounttoshowsubledger;
1313 print
"<td>".$reflabel.
"</td>";
1315 print
'<td class="center">'.$val[
"type_payment"].
"</td>";
1317 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1319 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1325 foreach ($tabbq[$key] as $k => $mt) {
1328 if (!empty($val[
'lib'])) {
1329 $reflabel .= $val[
'lib'].
" - ";
1331 $reflabel .=
'WaitingAccount';
1333 print
'<!-- Wait bank.rowid='.$key.
' -->';
1334 print
'<tr class="oddeven">';
1335 print
"<td>".$date.
"</td>";
1336 print
"<td>".$ref.
"</td>";
1354 print
"<td>".$reflabel.
"</td>";
1355 print
'<td class="center">'.$val[
"type_payment"].
"</td>";
1356 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1357 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1388 if ($ref ==
'(SupplierInvoicePayment)' || $ref ==
'(SupplierInvoicePaymentBack)') {
1389 $ref = $langs->transnoentitiesnoconv(
'Supplier');
1391 if ($ref ==
'(CustomerInvoicePayment)' || $ref ==
'(CustomerInvoicePaymentBack)') {
1392 $ref = $langs->transnoentitiesnoconv(
'Customer');
1394 if ($ref ==
'(SocialContributionPayment)') {
1395 $ref = $langs->transnoentitiesnoconv(
'SocialContribution');
1397 if ($ref ==
'(DonationPayment)') {
1398 $ref = $langs->transnoentitiesnoconv(
'Donation');
1400 if ($ref ==
'(SubscriptionPayment)') {
1401 $ref = $langs->transnoentitiesnoconv(
'Subscription');
1403 if ($ref ==
'(ExpenseReportPayment)') {
1404 $ref = $langs->transnoentitiesnoconv(
'Employee');
1406 if ($ref ==
'(LoanPayment)') {
1407 $ref = $langs->transnoentitiesnoconv(
'Loan');
1409 if ($ref ==
'(payment_salary)') {
1410 $ref = $langs->transnoentitiesnoconv(
'Employee');
1414 if ($typerecord ==
'payment') {
1415 $sqlmid =
'SELECT payfac.fk_facture as id, f.ref as ref';
1416 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"paiement_facture as payfac, ".MAIN_DB_PREFIX.
"facture as f";
1417 $sqlmid .=
" WHERE payfac.fk_facture = f.rowid AND payfac.fk_paiement=".((int) $val[
"paymentid"]);
1418 $ref = $langs->transnoentitiesnoconv(
"Invoice");
1419 } elseif ($typerecord ==
'payment_supplier') {
1420 $sqlmid =
'SELECT payfac.fk_facturefourn as id, f.ref';
1421 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as payfac, ".MAIN_DB_PREFIX.
"facture_fourn as f";
1422 $sqlmid .=
" WHERE payfac.fk_facturefourn = f.rowid AND payfac.fk_paiementfourn=".((int) $val[
"paymentsupplierid"]);
1423 $ref = $langs->transnoentitiesnoconv(
"SupplierInvoice");
1424 } elseif ($typerecord ==
'payment_expensereport') {
1425 $sqlmid =
'SELECT e.rowid as id, e.ref';
1426 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_expensereport as pe, ".MAIN_DB_PREFIX.
"expensereport as e";
1427 $sqlmid .=
" WHERE pe.rowid=".((int) $val[
"paymentexpensereport"]).
" AND pe.fk_expensereport = e.rowid";
1428 $ref = $langs->transnoentitiesnoconv(
"ExpenseReport");
1429 } elseif ($typerecord ==
'payment_salary') {
1430 $sqlmid =
'SELECT s.rowid as ref';
1431 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as s";
1432 $sqlmid .=
" WHERE s.rowid=".((int) $val[
"paymentsalid"]);
1433 $ref = $langs->transnoentitiesnoconv(
"SalaryPayment");
1434 } elseif ($typerecord ==
'sc') {
1435 $sqlmid =
'SELECT sc.rowid as ref';
1436 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"paiementcharge as sc";
1437 $sqlmid .=
" WHERE sc.rowid=".((int) $val[
"paymentscid"]);
1438 $ref = $langs->transnoentitiesnoconv(
"SocialContribution");
1439 } elseif ($typerecord ==
'payment_vat') {
1440 $sqlmid =
'SELECT v.rowid as ref';
1441 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"tva as v";
1442 $sqlmid .=
" WHERE v.rowid=".((int) $val[
"paymentvatid"]);
1443 $ref = $langs->transnoentitiesnoconv(
"PaymentVat");
1444 } elseif ($typerecord ==
'payment_donation') {
1445 $sqlmid =
'SELECT payd.fk_donation as ref';
1446 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_donation as payd";
1447 $sqlmid .=
" WHERE payd.fk_donation=".((int) $val[
"paymentdonationid"]);
1448 $ref = $langs->transnoentitiesnoconv(
"Donation");
1449 } elseif ($typerecord ==
'payment_loan') {
1450 $sqlmid =
'SELECT l.rowid as ref';
1451 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_loan as l";
1452 $sqlmid .=
" WHERE l.rowid=".((int) $val[
"paymentloanid"]);
1453 $ref = $langs->transnoentitiesnoconv(
"LoanPayment");
1454 } elseif ($typerecord ==
'payment_various') {
1455 $sqlmid =
'SELECT v.rowid as ref';
1456 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_various as v";
1457 $sqlmid .=
" WHERE v.rowid=".((int) $val[
"paymentvariousid"]);
1458 $ref = $langs->transnoentitiesnoconv(
"VariousPayment");
1461 if (empty($sqlmid)) {
1462 dol_syslog(
"Found a typerecord=".$typerecord.
" not supported", LOG_WARNING);
1466 dol_syslog(
"accountancy/journal/bankjournal.php::sqlmid=".$sqlmid, LOG_DEBUG);
1467 $resultmid = $db->query($sqlmid);
1469 while ($objmid = $db->fetch_object($resultmid)) {
1470 $ref .=
' '.$objmid->ref;
1477 $ref =
dol_trunc($langs->transnoentitiesnoconv(
"BankId").
' '.$val[
'fk_bank'].
' - '.$ref, 295);