33 require
'../../main.inc.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
38 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
40 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
44 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
45 require_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
46 require_once DOL_DOCUMENT_ROOT.
'/don/class/paymentdonation.class.php';
47 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
48 require_once DOL_DOCUMENT_ROOT.
'/salaries/class/paymentsalary.class.php';
49 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
50 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
51 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
52 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
53 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
54 require_once DOL_DOCUMENT_ROOT.
'/societe/class/client.class.php';
55 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
56 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/paymentexpensereport.class.php';
57 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
58 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
59 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
60 require_once DOL_DOCUMENT_ROOT.
'/loan/class/paymentloan.class.php';
61 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
64 $langs->loadLangs(array(
"companies",
"other",
"compta",
"banks",
"bills",
"donations",
"loan",
"accountancy",
"trips",
"salaries",
"hrm",
"members"));
67 $id_journal =
GETPOST(
'id_journal',
'int');
69 $date_startmonth =
GETPOST(
'date_startmonth',
'int');
70 $date_startday =
GETPOST(
'date_startday',
'int');
71 $date_startyear =
GETPOST(
'date_startyear',
'int');
72 $date_endmonth =
GETPOST(
'date_endmonth',
'int');
73 $date_endday =
GETPOST(
'date_endday',
'int');
74 $date_endyear =
GETPOST(
'date_endyear',
'int');
75 $in_bookkeeping =
GETPOST(
'in_bookkeeping',
'aZ09');
76 if ($in_bookkeeping ==
'') {
77 $in_bookkeeping =
'notyet';
82 $action =
GETPOST(
'action',
'aZ09');
85 if ($user->socid > 0 && empty($id_journal)) {
96 $date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
97 $date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
99 if (empty($date_startmonth) || empty($date_endmonth)) {
102 $date_start = $dates[
'date_start'];
103 $date_end = $dates[
'date_end'];
104 $pastmonthyear = $dates[
'pastmonthyear'];
105 $pastmonth = $dates[
'pastmonth'];
108 if (!
GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end))) {
113 $sql =
"SELECT b.rowid, b.dateo as do, b.datev as dv, b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type, b.fk_account,";
114 $sql .=
" ba.courant, ba.ref as baref, ba.account_number, ba.fk_accountancy_journal,";
115 $sql .=
" soc.code_compta, soc.code_compta_fournisseur, soc.rowid as socid, soc.nom as name, soc.email as email, bu1.type as typeop_company,";
116 $sql .=
" u.accountancy_code, u.rowid as userid, u.lastname as lastname, u.firstname as firstname, u.email as useremail, bu2.type as typeop_user,";
117 $sql .=
" bu3.type as typeop_payment, bu4.type as typeop_payment_supplier";
118 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
119 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"bank_account as ba on b.fk_account=ba.rowid";
120 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'";
121 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON bu2.fk_bank = b.rowid AND bu2.type='user'";
122 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu3 ON bu3.fk_bank = b.rowid AND bu3.type='payment'";
123 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu4 ON bu4.fk_bank = b.rowid AND bu4.type='payment_supplier'";
124 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as soc on bu1.url_id=soc.rowid";
125 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on bu2.url_id=u.rowid";
126 $sql .=
" WHERE ba.fk_accountancy_journal=".$id_journal;
127 $sql .=
' AND b.amount != 0 AND ba.entity IN ('.getEntity(
'bank_account', 0).
')';
128 if ($date_start && $date_end) {
129 $sql .=
" AND b.dateo >= '".$db->idate($date_start).
"' AND b.dateo <= '".$db->idate($date_end).
"'";
132 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
133 $sql .=
" AND b.dateo >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
136 if ($in_bookkeeping ==
'already') {
137 $sql .=
" AND (b.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
139 if ($in_bookkeeping ==
'notyet') {
140 $sql .=
" AND (b.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
142 $sql .=
" ORDER BY b.datev";
148 $societestatic =
new Societe($db);
149 $userstatic =
new User($db);
150 $bankaccountstatic =
new Account($db);
153 $paymentvatstatic =
new TVA($db);
162 $tmpinvoice =
new Facture($db);
168 $accountingjournalstatic->fetch($id_journal);
169 $journal = $accountingjournalstatic->code;
170 $journal_label = $accountingjournalstatic->label;
173 dol_syslog(
"accountancy/journal/bankjournal.php", LOG_DEBUG);
174 $result = $db->query($sql);
176 $num = $db->num_rows($result);
180 $account_supplier = (($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER !=
"") ? $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER :
'NotDefined');
181 $account_customer = (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER !=
"") ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER :
'NotDefined');
182 $account_employee = (!empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) ? $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT :
'NotDefined');
183 $account_pay_vat = (!empty($conf->global->ACCOUNTING_VAT_PAY_ACCOUNT) ? $conf->global->ACCOUNTING_VAT_PAY_ACCOUNT :
'NotDefined');
184 $account_pay_donation = (!empty($conf->global->DONATION_ACCOUNTINGACCOUNT) ? $conf->global->DONATION_ACCOUNTINGACCOUNT :
'NotDefined');
185 $account_pay_subscription = (!empty($conf->global->ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT) ? $conf->global->ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT :
'NotDefined');
186 $account_transfer = (!empty($conf->global->ACCOUNTING_ACCOUNT_TRANSFER_CASH) ? $conf->global->ACCOUNTING_ACCOUNT_TRANSFER_CASH :
'NotDefined');
188 $tabcompany = array();
194 $tabmoreinfo = array();
202 $obj = $db->fetch_object($result);
204 $lineisapurchase = -1;
207 if ($obj->label ==
'(SupplierInvoicePayment)' || $obj->label ==
'(SupplierInvoicePaymentBack)') {
208 $lineisapurchase = 1;
210 if ($obj->label ==
'(CustomerInvoicePayment)' || $obj->label ==
'(CustomerInvoicePaymentBack)') {
214 if ($lineisapurchase < 0) {
215 if ($obj->typeop_payment_supplier ==
'payment_supplier') {
216 $lineisapurchase = 1;
219 if ($lineisasale < 0) {
220 if ($obj->typeop_payment ==
'payment') {
228 $compta_bank = $obj->account_number;
231 $compta_soc =
'NotDefined';
232 if ($lineisapurchase > 0) {
233 $compta_soc = (($obj->code_compta_fournisseur !=
"") ? $obj->code_compta_fournisseur : $account_supplier);
235 if ($lineisasale > 0) {
236 $compta_soc = (!empty($obj->code_compta) ? $obj->code_compta : $account_customer);
239 $tabcompany[$obj->rowid] = array(
241 'name' => $obj->name,
242 'code_compta' => $compta_soc,
243 'email' => $obj->email
247 $compta_user = (!empty($obj->accountancy_code) ? $obj->accountancy_code :
'');
249 $tabuser[$obj->rowid] = array(
250 'id' => $obj->userid,
252 'lastname' => $obj->lastname,
253 'firstname' => $obj->firstname,
254 'email' => $obj->useremail,
255 'accountancy_code' => $compta_user
259 $tabpay[$obj->rowid][
"date"] = $obj->do;
260 $tabpay[$obj->rowid][
"type_payment"] = $obj->fk_type;
261 $tabpay[$obj->rowid][
"ref"] = $obj->label;
262 $tabpay[$obj->rowid][
"fk_bank"] = $obj->rowid;
263 $tabpay[$obj->rowid][
"bank_account_ref"] = $obj->baref;
264 $tabpay[$obj->rowid][
"fk_bank_account"] = $obj->fk_account;
265 if (preg_match(
'/^\((.*)\)$/i', $obj->label, $reg)) {
266 $tabpay[$obj->rowid][
"lib"] = $langs->trans($reg[1]);
268 $tabpay[$obj->rowid][
"lib"] =
dol_trunc($obj->label, 60);
272 $links = $object->get_url($obj->rowid);
275 $tabpay[$obj->rowid][
'type'] =
'unknown';
276 $tabtype[$obj->rowid] =
'unknown';
277 $tabmoreinfo[$obj->rowid] = array();
280 if (is_array($links) && count($links) > 0) {
282 foreach ($links as $key => $val) {
283 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'))) {
287 $tabpay[$obj->rowid][
'type'] = $links[$key][
'type'];
288 $tabtype[$obj->rowid] = $links[$key][
'type'];
289 } elseif (in_array($links[$key][
'type'], array(
'company',
'user'))) {
290 if ($tabpay[$obj->rowid][
'type'] ==
'unknown') {
296 if ($links[$key][
'type'] ==
'withdraw') {
297 $tabmoreinfo[$obj->rowid][
'withdraw'] = 1;
300 if ($links[$key][
'type'] ==
'payment') {
301 $paymentstatic->id = $links[$key][
'url_id'];
302 $paymentstatic->ref = $links[$key][
'url_id'];
303 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentstatic->getNomUrl(2,
'',
'');
304 $tabpay[$obj->rowid][
"paymentid"] = $paymentstatic->id;
305 } elseif ($links[$key][
'type'] ==
'payment_supplier') {
306 $paymentsupplierstatic->id = $links[$key][
'url_id'];
307 $paymentsupplierstatic->ref = $links[$key][
'url_id'];
308 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentsupplierstatic->getNomUrl(2);
309 $tabpay[$obj->rowid][
"paymentsupplierid"] = $paymentsupplierstatic->id;
310 } elseif ($links[$key][
'type'] ==
'company') {
311 $societestatic->id = $links[$key][
'url_id'];
312 $societestatic->name = $links[$key][
'label'];
313 $societestatic->email = $tabcompany[$obj->rowid][
'email'];
314 $tabpay[$obj->rowid][
"soclib"] = $societestatic->getNomUrl(1,
'', 30);
316 $tabtp[$obj->rowid][$compta_soc] += $obj->amount;
318 } elseif ($links[$key][
'type'] ==
'user') {
319 $userstatic->id = $links[$key][
'url_id'];
320 $userstatic->name = $links[$key][
'label'];
321 $userstatic->email = $tabuser[$obj->rowid][
'email'];
322 $userstatic->firstname = $tabuser[$obj->rowid][
'firstname'];
323 $userstatic->lastname = $tabuser[$obj->rowid][
'lastname'];
324 if ($userstatic->id > 0) {
325 $tabpay[$obj->rowid][
"soclib"] = $userstatic->getNomUrl(1,
'', 30);
327 $tabpay[$obj->rowid][
"soclib"] =
'???';
330 $tabtp[$obj->rowid][$compta_user] += $obj->amount;
332 } elseif ($links[$key][
'type'] ==
'sc') {
333 $chargestatic->id = $links[$key][
'url_id'];
334 $chargestatic->ref = $links[$key][
'url_id'];
336 $tabpay[$obj->rowid][
"lib"] .=
' '.$chargestatic->getNomUrl(2);
338 if (preg_match(
'/^\((.*)\)$/i', $links[$key][
'label'], $reg)) {
339 if ($reg[1] ==
'socialcontribution') {
340 $reg[1] =
'SocialContribution';
342 $chargestatic->label = $langs->trans($reg[1]);
344 $chargestatic->label = $links[$key][
'label'];
346 $chargestatic->ref = $chargestatic->label;
347 $tabpay[$obj->rowid][
"soclib"] = $chargestatic->getNomUrl(1, 30);
348 $tabpay[$obj->rowid][
"paymentscid"] = $chargestatic->id;
352 $sqlmid =
'SELECT cchgsoc.accountancy_code';
353 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales cchgsoc";
354 $sqlmid .=
" INNER JOIN ".MAIN_DB_PREFIX.
"chargesociales as chgsoc ON chgsoc.fk_type=cchgsoc.id";
355 $sqlmid .=
" INNER JOIN ".MAIN_DB_PREFIX.
"paiementcharge as paycharg ON paycharg.fk_charge=chgsoc.rowid";
356 $sqlmid .=
" INNER JOIN ".MAIN_DB_PREFIX.
"bank_url as bkurl ON bkurl.url_id=paycharg.rowid AND bkurl.type = 'payment_sc'";
357 $sqlmid .=
" WHERE bkurl.fk_bank=".$obj->rowid;
359 dol_syslog(
"accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);
360 $resultmid = $db->query($sqlmid);
362 $objmid = $db->fetch_object($resultmid);
363 $tabtp[$obj->rowid][$objmid->accountancy_code] += $obj->amount;
365 } elseif ($links[$key][
'type'] ==
'payment_donation') {
366 $paymentdonstatic->id = $links[$key][
'url_id'];
367 $paymentdonstatic->ref = $links[$key][
'url_id'];
368 $paymentdonstatic->fk_donation = $links[$key][
'url_id'];
369 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentdonstatic->getNomUrl(2);
370 $tabpay[$obj->rowid][
"paymentdonationid"] = $paymentdonstatic->id;
371 $tabtp[$obj->rowid][$account_pay_donation] += $obj->amount;
372 } elseif ($links[$key][
'type'] ==
'member') {
373 $paymentsubscriptionstatic->id = $links[$key][
'url_id'];
374 $paymentsubscriptionstatic->ref = $links[$key][
'url_id'];
375 $paymentsubscriptionstatic->label = $links[$key][
'label'];
376 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentsubscriptionstatic->getNomUrl(2);
377 $tabpay[$obj->rowid][
"paymentsubscriptionid"] = $paymentsubscriptionstatic->id;
378 $paymentsubscriptionstatic->fetch($paymentsubscriptionstatic->id);
379 $tabtp[$obj->rowid][$account_pay_subscription] += $obj->amount;
380 } elseif ($links[$key][
'type'] ==
'payment_vat') {
381 $paymentvatstatic->id = $links[$key][
'url_id'];
382 $paymentvatstatic->ref = $links[$key][
'url_id'];
383 $paymentvatstatic->label = $links[$key][
'label'];
384 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentvatstatic->getNomUrl(2);
385 $tabpay[$obj->rowid][
"paymentvatid"] = $paymentvatstatic->id;
386 $tabtp[$obj->rowid][$account_pay_vat] += $obj->amount;
387 } elseif ($links[$key][
'type'] ==
'payment_salary') {
388 $paymentsalstatic->id = $links[$key][
'url_id'];
389 $paymentsalstatic->ref = $links[$key][
'url_id'];
390 $paymentsalstatic->label = $links[$key][
'label'];
391 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentsalstatic->getNomUrl(2);
392 $tabpay[$obj->rowid][
"paymentsalid"] = $paymentsalstatic->id;
393 } elseif ($links[$key][
'type'] ==
'payment_expensereport') {
394 $paymentexpensereportstatic->id = $links[$key][
'url_id'];
395 $tabpay[$obj->rowid][
"lib"] .= $paymentexpensereportstatic->getNomUrl(2);
396 $tabpay[$obj->rowid][
"paymentexpensereport"] = $paymentexpensereportstatic->id;
397 } elseif ($links[$key][
'type'] ==
'payment_various') {
398 $paymentvariousstatic->id = $links[$key][
'url_id'];
399 $paymentvariousstatic->ref = $links[$key][
'url_id'];
400 $paymentvariousstatic->label = $links[$key][
'label'];
401 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentvariousstatic->getNomUrl(2);
402 $tabpay[$obj->rowid][
"paymentvariousid"] = $paymentvariousstatic->id;
403 $paymentvariousstatic->fetch($paymentvariousstatic->id);
404 $account_various = (!empty($paymentvariousstatic->accountancy_code) ? $paymentvariousstatic->accountancy_code :
'NotDefined');
405 $account_subledger = (!empty($paymentvariousstatic->subledger_account) ? $paymentvariousstatic->subledger_account :
'');
406 $tabpay[$obj->rowid][
"account_various"] = $account_various;
407 $tabtp[$obj->rowid][$account_subledger] += $obj->amount;
408 } elseif ($links[$key][
'type'] ==
'payment_loan') {
409 $paymentloanstatic->id = $links[$key][
'url_id'];
410 $paymentloanstatic->ref = $links[$key][
'url_id'];
411 $paymentloanstatic->fk_loan = $links[$key][
'url_id'];
412 $tabpay[$obj->rowid][
"lib"] .=
' '.$paymentloanstatic->getNomUrl(2);
413 $tabpay[$obj->rowid][
"paymentloanid"] = $paymentloanstatic->id;
415 $sqlmid =
'SELECT pl.amount_capital, pl.amount_insurance, pl.amount_interest, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest';
416 $sqlmid .=
' FROM '.MAIN_DB_PREFIX.
'payment_loan as pl, '.MAIN_DB_PREFIX.
'loan as l';
417 $sqlmid .=
' WHERE l.rowid = pl.fk_loan AND pl.fk_bank = '.$obj->rowid;
419 dol_syslog(
"accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);
420 $resultmid = $db->query($sqlmid);
422 $objmid = $db->fetch_object($resultmid);
423 $tabtp[$obj->rowid][$objmid->accountancy_account_capital] -= $objmid->amount_capital;
424 $tabtp[$obj->rowid][$objmid->accountancy_account_insurance] -= $objmid->amount_insurance;
425 $tabtp[$obj->rowid][$objmid->accountancy_account_interest] -= $objmid->amount_interest;
427 } elseif ($links[$key][
'type'] ==
'banktransfert') {
428 $accountLinestatic->fetch($links[$key][
'url_id']);
429 $tabpay[$obj->rowid][
"lib"] .=
' '.$langs->trans(
"BankTransfer").
'- '.$accountLinestatic ->getNomUrl(1);
430 $tabtp[$obj->rowid][$account_transfer] += $obj->amount;
431 $bankaccountstatic->fetch($tabpay[$obj->rowid][
'fk_bank_account']);
432 $tabpay[$obj->rowid][
"soclib"] = $bankaccountstatic->getNomUrl(2);
437 $tabbq[$obj->rowid][$compta_bank] += $obj->amount;
441 if (empty($tabtp[$obj->rowid]) && !empty($tabmoreinfo[$obj->rowid][
'withdraw'])) {
442 foreach ($links as $key => $val) {
443 if ($links[$key][
'type'] ==
'payment') {
445 $tmppayment->fetch($links[$key][
'url_id']);
446 $arrayofamounts = $tmppayment->getAmountsArray();
447 if (is_array($arrayofamounts)) {
448 foreach ($arrayofamounts as $invoiceid => $amount) {
449 $tmpinvoice->fetch($invoiceid);
450 $tmpinvoice->fetch_thirdparty();
451 if ($tmpinvoice->thirdparty->code_compta) {
452 $tabtp[$obj->rowid][$tmpinvoice->thirdparty->code_compta] += $amount;
461 if (empty($tabtp[$obj->rowid])) {
462 $tabtp[$obj->rowid][
'NotDefined'] = $tabbq[$obj->rowid][$compta_bank];
500 if (!$error && $action ==
'writebookkeeping') {
504 foreach ($tabpay as $key => $val) {
522 if (!$errorforline && is_array($tabbq[$key])) {
524 foreach ($tabbq[$key] as $k => $mt) {
527 if (!empty($val[
'lib'])) {
531 if (!empty($val[
'soclib'])) {
532 $reflabel .=
" - ".dol_string_nohtmltag($val[
'soclib']);
536 $bookkeeping->doc_date = $val[
"date"];
537 $bookkeeping->doc_ref = $ref;
538 $bookkeeping->doc_type =
'bank';
539 $bookkeeping->fk_doc = $key;
540 $bookkeeping->fk_docdet = $val[
"fk_bank"];
541 $bookkeeping->numero_compte = $k;
543 $accountingaccount->fetch(null, $k,
true);
544 $bookkeeping->label_compte = $accountingaccount->label;
546 $bookkeeping->label_operation = $reflabel;
547 $bookkeeping->montant = $mt;
548 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
549 $bookkeeping->debit = ($mt >= 0 ? $mt : 0);
550 $bookkeeping->credit = ($mt < 0 ? -$mt : 0);
551 $bookkeeping->code_journal = $journal;
552 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
553 $bookkeeping->fk_user_author = $user->id;
554 $bookkeeping->date_creation = $now;
557 $bookkeeping->subledger_account =
'';
558 $bookkeeping->label_operation = $reflabel;
559 $bookkeeping->entity = $conf->entity;
561 $totaldebit += $bookkeeping->debit;
562 $totalcredit += $bookkeeping->credit;
564 $result = $bookkeeping->create($user);
566 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
569 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded', null,
'warnings');
581 if (!$errorforline) {
582 if (is_array($tabtp[$key])) {
584 foreach ($tabtp[$key] as $k => $mt) {
587 if (!empty($val[
'lib'])) {
590 if ($tabtype[$key] ==
'banktransfert') {
591 $reflabel .=
dol_string_nohtmltag($langs->transnoentitiesnoconv(
'TransitionalAccount').
' '.$account_transfer);
597 $bookkeeping->doc_date = $val[
"date"];
598 $bookkeeping->doc_ref = $ref;
599 $bookkeeping->doc_type =
'bank';
600 $bookkeeping->fk_doc = $key;
601 $bookkeeping->fk_docdet = $val[
"fk_bank"];
602 $bookkeeping->label_operation = $reflabel;
603 $bookkeeping->montant = $mt;
604 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
605 $bookkeeping->debit = ($mt < 0 ? -$mt : 0);
606 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
607 $bookkeeping->code_journal = $journal;
608 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
609 $bookkeeping->fk_user_author = $user->id;
610 $bookkeeping->date_creation = $now;
612 if ($tabtype[$key] ==
'payment') {
613 $bookkeeping->subledger_account = $k;
614 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
615 $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
617 $accountingaccount->fetch(null, $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER,
true);
618 $bookkeeping->label_compte = $accountingaccount->label;
619 } elseif ($tabtype[$key] ==
'payment_supplier') {
620 $bookkeeping->subledger_account = $k;
621 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
622 $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER;
624 $accountingaccount->fetch(null, $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER,
true);
625 $bookkeeping->label_compte = $accountingaccount->label;
626 } elseif ($tabtype[$key] ==
'payment_expensereport') {
627 $bookkeeping->subledger_account = $tabuser[$key][
'accountancy_code'];
628 $bookkeeping->subledger_label = $tabuser[$key][
'name'];
629 $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT;
631 $accountingaccount->fetch(null, $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT,
true);
632 $bookkeeping->label_compte = $accountingaccount->label;
633 } elseif ($tabtype[$key] ==
'payment_salary') {
634 $bookkeeping->subledger_account = $tabuser[$key][
'accountancy_code'];
635 $bookkeeping->subledger_label = $tabuser[$key][
'name'];
636 $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT;
638 $accountingaccount->fetch(null, $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT,
true);
639 $bookkeeping->label_compte = $accountingaccount->label;
640 } elseif (in_array($tabtype[$key], array(
'sc',
'payment_sc'))) {
641 $bookkeeping->subledger_account =
'';
642 $bookkeeping->subledger_label =
'';
643 $bookkeeping->numero_compte = $k;
645 $accountingaccount->fetch(null, $k,
true);
646 $bookkeeping->label_compte = $accountingaccount->label;
647 } elseif ($tabtype[$key] ==
'payment_vat') {
648 $bookkeeping->subledger_account =
'';
649 $bookkeeping->subledger_label =
'';
650 $bookkeeping->numero_compte = $k;
652 $accountingaccount->fetch(null, $k,
true);
653 $bookkeeping->label_compte = $accountingaccount->label;
654 } elseif ($tabtype[$key] ==
'payment_donation') {
655 $bookkeeping->subledger_account =
'';
656 $bookkeeping->subledger_label =
'';
657 $bookkeeping->numero_compte = $k;
659 $accountingaccount->fetch(null, $k,
true);
660 $bookkeeping->label_compte = $accountingaccount->label;
661 } elseif ($tabtype[$key] ==
'member') {
662 $bookkeeping->subledger_account =
'';
663 $bookkeeping->subledger_label =
'';
664 $bookkeeping->numero_compte = $k;
666 $accountingaccount->fetch(null, $k,
true);
667 $bookkeeping->label_compte = $accountingaccount->label;
668 } elseif ($tabtype[$key] ==
'payment_loan') {
669 $bookkeeping->subledger_account =
'';
670 $bookkeeping->subledger_label =
'';
671 $bookkeeping->numero_compte = $k;
673 $accountingaccount->fetch(null, $k,
true);
674 $bookkeeping->label_compte = $accountingaccount->label;
675 } elseif ($tabtype[$key] ==
'payment_various') {
676 $bookkeeping->subledger_account = $k;
677 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
678 $bookkeeping->numero_compte = $tabpay[$key][
"account_various"];
680 $accountingaccount->fetch(null, $bookkeeping->numero_compte,
true);
681 $bookkeeping->label_compte = $accountingaccount->label;
682 } elseif ($tabtype[$key] ==
'banktransfert') {
683 $bookkeeping->subledger_account =
'';
684 $bookkeeping->subledger_label =
'';
685 $bookkeeping->numero_compte = $k;
687 $accountingaccount->fetch(null, $k,
true);
688 $bookkeeping->label_compte = $accountingaccount->label;
690 if ($tabtype[$key] ==
'unknown') {
692 $bookkeeping->subledger_account =
'';
693 $bookkeeping->subledger_label =
'';
694 $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE;
696 $accountingaccount->fetch(null, $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE,
true);
697 $bookkeeping->label_compte = $accountingaccount->label;
700 $bookkeeping->label_operation = $reflabel;
701 $bookkeeping->entity = $conf->entity;
703 $totaldebit += $bookkeeping->debit;
704 $totalcredit += $bookkeeping->credit;
706 $result = $bookkeeping->create($user);
708 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
711 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded', null,
'warnings');
721 foreach ($tabbq[$key] as $k => $mt) {
724 if (!empty($val[
'lib'])) {
730 $bookkeeping->doc_date = $val[
"date"];
731 $bookkeeping->doc_ref = $ref;
732 $bookkeeping->doc_type =
'bank';
733 $bookkeeping->fk_doc = $key;
734 $bookkeeping->fk_docdet = $val[
"fk_bank"];
735 $bookkeeping->montant = $mt;
736 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
737 $bookkeeping->debit = ($mt < 0 ? -$mt : 0);
738 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
739 $bookkeeping->code_journal = $journal;
740 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
741 $bookkeeping->fk_user_author = $user->id;
742 $bookkeeping->date_creation = $now;
743 $bookkeeping->label_compte =
'';
744 $bookkeeping->label_operation = $reflabel;
745 $bookkeeping->entity = $conf->entity;
747 $totaldebit += $bookkeeping->debit;
748 $totalcredit += $bookkeeping->credit;
750 $result = $bookkeeping->create($user);
753 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
756 setEventMessages(
'Transaction for ('.$bookkeeping->doc_type.
', '.$bookkeeping->fk_doc.
', '.$bookkeeping->fk_docdet.
') were already recorded', null,
'warnings');
771 setEventMessages(
'Try to insert a non balanced transaction in book for '.$ref.
'. Canceled. Surely a bug.', null,
'errors');
774 if (!$errorforline) {
781 if ($error >= $MAXNBERRORS) {
782 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped").
' (>'.$MAXNBERRORS.
')', null,
'errors');
788 if (empty($error) && count($tabpay) > 0) {
790 } elseif (count($tabpay) == $error) {
793 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"), null,
'warnings');
799 if (count($tabpay) != $error) {
800 $param =
'id_journal='.$id_journal;
801 $param .=
'&date_startday='.$date_startday;
802 $param .=
'&date_startmonth='.$date_startmonth;
803 $param .=
'&date_startyear='.$date_startyear;
804 $param .=
'&date_endday='.$date_endday;
805 $param .=
'&date_endmonth='.$date_endmonth;
806 $param .=
'&date_endyear='.$date_endyear;
807 $param .=
'&in_bookkeeping='.$in_bookkeeping;
808 header(
"Location: ".
$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
816 if ($action ==
'exportcsv') {
817 $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
819 $filename =
'journal';
820 $type_export =
'journal';
821 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
824 print '"'.$langs->transnoentitiesnoconv(
"BankId").
'"'.$sep;
825 print '"'.$langs->transnoentitiesnoconv(
"Date").
'"'.$sep;
826 print '"'.$langs->transnoentitiesnoconv(
"PaymentMode").
'"'.$sep;
827 print '"'.$langs->transnoentitiesnoconv(
"AccountAccounting").
'"'.$sep;
828 print '"'.$langs->transnoentitiesnoconv(
"LedgerAccount").
'"'.$sep;
829 print '"'.$langs->transnoentitiesnoconv(
"SubledgerAccount").
'"'.$sep;
830 print '"'.$langs->transnoentitiesnoconv(
"Label").
'"'.$sep;
831 print '"'.$langs->transnoentitiesnoconv(
"Debit").
'"'.$sep;
832 print '"'.$langs->transnoentitiesnoconv(
"Credit").
'"'.$sep;
833 print '"'.$langs->transnoentitiesnoconv(
"Journal").
'"'.$sep;
834 print '"'.$langs->transnoentitiesnoconv(
"Note").
'"'.$sep;
837 foreach ($tabpay as $key => $val) {
843 foreach ($tabbq[$key] as $k => $mt) {
846 if (!empty($val[
'lib'])) {
850 if (!empty($val[
'soclib'])) {
851 $reflabel .=
" - ".dol_string_nohtmltag($val[
'soclib']);
854 print '"'.$key.
'"'.$sep;
855 print '"'.$date.
'"'.$sep;
856 print '"'.$val[
"type_payment"].
'"'.$sep;
857 print '"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
858 print '"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
860 print '"'.$reflabel.
'"'.$sep;
861 print '"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
862 print '"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
863 print '"'.$journal.
'"'.$sep;
864 print '"'.dol_string_nohtmltag($ref).
'"'.$sep;
870 if (is_array($tabtp[$key])) {
871 foreach ($tabtp[$key] as $k => $mt) {
874 if (!empty($val[
'lib'])) {
877 if ($tabtype[$key] ==
'banktransfert') {
878 $reflabel .=
dol_string_nohtmltag($langs->transnoentitiesnoconv(
'TransitionalAccount').
' '.$account_transfer);
883 print '"'.$key.
'"'.$sep;
884 print '"'.$date.
'"'.$sep;
885 print '"'.$val[
"type_payment"].
'"'.$sep;
886 print '"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
887 if ($tabtype[$key] ==
'payment_supplier') {
888 print '"'.$conf->global->ACCOUNTING_ACCOUNT_SUPPLIER.
'"'.$sep;
889 } elseif ($tabtype[$key] ==
'payment') {
890 print '"'.$conf->global->ACCOUNTING_ACCOUNT_CUSTOMER.
'"'.$sep;
891 } elseif ($tabtype[$key] ==
'payment_expensereport') {
892 print '"'.$conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT.
'"'.$sep;
893 } elseif ($tabtype[$key] ==
'payment_salary') {
894 print '"'.$conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT.
'"'.$sep;
896 print '"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
898 print '"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
899 print '"'.$reflabel.
'"'.$sep;
900 print '"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
901 print '"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
902 print '"'.$journal.
'"'.$sep;
903 print '"'.dol_string_nohtmltag($ref).
'"'.$sep;
908 foreach ($tabbq[$key] as $k => $mt) {
911 if (!empty($val[
'lib'])) {
916 print '"'.$key.
'"'.$sep;
917 print '"'.$date.
'"'.$sep;
918 print '"'.$val[
"type_payment"].
'"'.$sep;
919 print '"'.length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE).
'"'.$sep;
920 print '"'.length_accounta($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE).
'"'.$sep;
922 print '"'.$reflabel.
'"'.$sep;
923 print '"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
924 print '"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
925 print '"'.$journal.
'"'.$sep;
926 print '"'.dol_string_nohtmltag($ref).
'"'.$sep;
939 $form =
new Form($db);
941 if (empty($action) || $action ==
'view') {
942 $invoicestatic =
new Facture($db);
945 $vatstatic =
new Tva($db);
946 $donationstatic =
new Don($db);
947 $loanstatic =
new Loan($db);
951 llxHeader(
'', $langs->trans(
"FinanceJournal"));
953 $nom = $langs->trans(
"FinanceJournal").
' | '.$accountingjournalstatic->getNomUrl(0, 1, 1,
'', 1);
956 $description .= $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
958 $listofchoices = array(
'notyet'=>$langs->trans(
"NotYetInGeneralLedger"),
'already'=>$langs->trans(
"AlreadyInGeneralLedger"));
959 $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);
960 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
962 $varlink =
'id_journal='.$id_journal;
964 journalHead($nom,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
968 $sql =
'SELECT COUNT(rowid) as nb FROM '.MAIN_DB_PREFIX.
'bank_account WHERE entity = '.$conf->entity.
' AND fk_accountancy_journal IS NULL AND clos=0';
969 $resql = $db->query($sql);
971 $obj = $db->fetch_object(
$resql);
973 print '<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheJournalCodeIsNotDefinedOnSomeBankAccount");
974 $desc =
' : '.$langs->trans(
"AccountancyAreaDescBank", 9,
'{link}');
975 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"BankAccounts").
'</strong>', $desc);
985 if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
"") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
'-1'
986 || ($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
"") || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
'-1'
987 || empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) || $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT ==
'-1') {
988 print '<br>'.img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
989 print ' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>');
993 print '<div class="tabsAction tabsActionNoBottom">';
995 if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping ==
'notyet') {
996 print '<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
999 if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
"") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
'-1'
1000 || ($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
"") || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
'-1') {
1001 print '<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
1003 if ($in_bookkeeping ==
'notyet') {
1004 print '<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
1006 print '<a class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
1014 <script type="text/javascript">
1015 function launch_export() {
1016 console.log("Set value into form and submit");
1017 $("div.fiche form input[name=\"action\"]").val("exportcsv");
1018 $("div.fiche form input[type=\"submit\"]").click();
1019 $("div.fiche form input[name=\"action\"]").val("");
1021 function writebookkeeping() {
1022 console.log("Set value into form and submit");
1023 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
1024 $("div.fiche form input[type=\"submit\"]").click();
1025 $("div.fiche form input[name=\"action\"]").val("");
1035 print '<div class="div-table-responsive">';
1036 print "<table class=\"noborder\" width=\"100%\">";
1037 print "<tr class=\"liste_titre\">";
1038 print "<td>".$langs->trans(
"Date").
"</td>";
1039 print "<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"ObjectsRef").
")</td>";
1040 print "<td>".$langs->trans(
"AccountAccounting").
"</td>";
1041 print "<td>".$langs->trans(
"SubledgerAccount").
"</td>";
1042 print "<td>".$langs->trans(
"LabelOperation").
"</td>";
1043 print '<td class="center">'.$langs->trans(
"PaymentMode").
"</td>";
1044 print '<td class="right">'.$langs->trans(
"Debit").
"</td>";
1045 print '<td class="right">'.$langs->trans(
"Credit").
"</td>";
1050 foreach ($tabpay as $key => $val) {
1056 foreach ($tabbq[$key] as $k => $mt) {
1059 if (!empty($val[
'lib'])) {
1060 $reflabel .= $val[
'lib'].
" - ";
1062 $reflabel .= $langs->trans(
"Bank").
' '.$val[
'bank_account_ref'];
1063 if (!empty($val[
'soclib'])) {
1064 $reflabel .=
" - ".$val[
'soclib'];
1068 print '<!-- Bank bank.rowid='.$key.
' type='.$tabpay[$key][
'type'].
' ref='.$tabpay[$key][
'ref'].
'-->';
1069 print '<tr class="oddeven">';
1070 print "<td>".$date.
"</td>";
1071 print "<td>".$ref.
"</td>";
1075 if (empty($accounttoshow) || $accounttoshow ==
'NotDefined') {
1076 print '<span class="error">'.$langs->trans(
"BankAccountNotDefined").
'</span>';
1078 print $accounttoshow;
1093 print '<td class="center">'.$val[
"type_payment"].
"</td>";
1094 print '<td class="right nowraponall">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1095 print '<td class="right nowraponall">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1101 if (is_array($tabtp[$key])) {
1102 foreach ($tabtp[$key] as $k => $mt) {
1105 if (!empty($val[
'lib'])) {
1106 $reflabel .= $val[
'lib'].($val[
'soclib'] ?
" - " :
"");
1108 if ($tabtype[$key] ==
'banktransfert') {
1109 $reflabel .= $langs->trans(
'TransitionalAccount').
' '.$account_transfer;
1111 $reflabel .= $val[
'soclib'];
1114 print '<!-- Thirdparty bank.rowid='.$key.
' -->';
1115 print '<tr class="oddeven">';
1116 print "<td>".$date.
"</td>";
1117 print "<td>".$ref.
"</td>";
1120 $account_ledger = $k;
1122 if ($tabtype[$key] ==
'payment') {
1123 $account_ledger = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
1125 if ($tabtype[$key] ==
'payment_supplier') {
1126 $account_ledger = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER;
1128 if ($tabtype[$key] ==
'payment_expensereport') {
1129 $account_ledger = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT;
1131 if ($tabtype[$key] ==
'payment_salary') {
1132 $account_ledger = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT;
1134 if ($tabtype[$key] ==
'payment_vat') {
1135 $account_ledger = $conf->global->ACCOUNTING_VAT_PAY_ACCOUNT;
1137 if ($tabtype[$key] ==
'member') {
1138 $account_ledger = $conf->global->ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT;
1140 if ($tabtype[$key] ==
'payment_various') {
1141 $account_ledger = $tabpay[$key][
"account_various"];
1144 if (empty($accounttoshow) || $accounttoshow ==
'NotDefined') {
1145 if ($tabtype[$key] ==
'unknown') {
1147 if (empty($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) || $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE ==
'-1') {
1148 print '<span class="error">'.$langs->trans(
'UnknownAccountForThirdpartyAndWaitingAccountNotDefinedBlocking').
'</span>';
1150 print '<span class="warning">'.$langs->trans(
'UnknownAccountForThirdparty',
length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE)).
'</span>';
1154 $errorstring =
'UnknownAccountForThirdpartyBlocking';
1155 if ($tabtype[$key] ==
'payment') {
1156 $errorstring =
'MainAccountForCustomersNotDefined';
1158 if ($tabtype[$key] ==
'payment_supplier') {
1159 $errorstring =
'MainAccountForSuppliersNotDefined';
1161 if ($tabtype[$key] ==
'payment_expensereport') {
1162 $errorstring =
'MainAccountForUsersNotDefined';
1164 if ($tabtype[$key] ==
'payment_salary') {
1165 $errorstring =
'MainAccountForUsersNotDefined';
1167 if ($tabtype[$key] ==
'payment_vat') {
1168 $errorstring =
'MainAccountForVatPaymentNotDefined';
1170 if ($tabtype[$key] ==
'member') {
1171 $errorstring =
'MainAccountForSubscriptionPaymentNotDefined';
1173 print '<span class="error">'.$langs->trans($errorstring).
'</span>';
1176 print $accounttoshow;
1182 if (in_array($tabtype[$key], array(
'payment',
'payment_supplier',
'payment_expensereport',
'payment_salary',
'payment_various'))) {
1184 if ($accounttoshow != $accounttoshowsubledger) {
1185 if (empty($accounttoshowsubledger) || $accounttoshowsubledger ==
'NotDefined') {
1190 if (!empty($tabcompany[$key][
'code_compta'])) {
1191 if (in_array($tabtype[$key], array(
'payment_various'))) {
1193 print '<span class="warning">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknownSubledgerIgnored").
'</span>';
1195 print '<span class="warning">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknown", $tabcompany[$key][
'code_compta']).
'</span>';
1198 print '<span class="error">'.$langs->trans(
"ThirdpartyAccountNotDefinedOrThirdPartyUnknownBlocking").
'</span>';
1201 print $accounttoshowsubledger;
1206 print "<td>".$reflabel.
"</td>";
1207 print '<td class="center">'.$val[
"type_payment"].
"</td>";
1208 print '<td class="right nowraponall">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1209 print '<td class="right nowraponall">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1214 foreach ($tabbq[$key] as $k => $mt) {
1217 if (!empty($val[
'lib'])) {
1218 $reflabel .= $val[
'lib'].
" - ";
1220 $reflabel .=
'WaitingAccount';
1222 print '<!-- Wait bank.rowid='.$key.
' -->';
1223 print '<tr class="oddeven">';
1224 print "<td>".$date.
"</td>";
1225 print "<td>".$ref.
"</td>";
1243 print "<td>".$reflabel.
"</td>";
1244 print '<td class="center">'.$val[
"type_payment"].
"</td>";
1245 print '<td class="right nowraponall">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1246 print '<td class="right nowraponall">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1277 if ($ref ==
'(SupplierInvoicePayment)' || $ref ==
'(SupplierInvoicePaymentBack)') {
1278 $ref = $langs->transnoentitiesnoconv(
'Supplier');
1280 if ($ref ==
'(CustomerInvoicePayment)' || $ref ==
'(CustomerInvoicePaymentBack)') {
1281 $ref = $langs->transnoentitiesnoconv(
'Customer');
1283 if ($ref ==
'(SocialContributionPayment)') {
1284 $ref = $langs->transnoentitiesnoconv(
'SocialContribution');
1286 if ($ref ==
'(DonationPayment)') {
1287 $ref = $langs->transnoentitiesnoconv(
'Donation');
1289 if ($ref ==
'(SubscriptionPayment)') {
1290 $ref = $langs->transnoentitiesnoconv(
'Subscription');
1292 if ($ref ==
'(ExpenseReportPayment)') {
1293 $ref = $langs->transnoentitiesnoconv(
'Employee');
1295 if ($ref ==
'(LoanPayment)') {
1296 $ref = $langs->transnoentitiesnoconv(
'Loan');
1298 if ($ref ==
'(payment_salary)') {
1299 $ref = $langs->transnoentitiesnoconv(
'Employee');
1303 if ($typerecord ==
'payment') {
1304 $sqlmid =
'SELECT payfac.fk_facture as id, f.ref as ref';
1305 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"paiement_facture as payfac, ".MAIN_DB_PREFIX.
"facture as f";
1306 $sqlmid .=
" WHERE payfac.fk_facture = f.rowid AND payfac.fk_paiement=".$val[
"paymentid"];
1307 $ref = $langs->transnoentitiesnoconv(
"Invoice");
1308 } elseif ($typerecord ==
'payment_supplier') {
1309 $sqlmid =
'SELECT payfac.fk_facturefourn as id, f.ref';
1310 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as payfac, ".MAIN_DB_PREFIX.
"facture_fourn as f";
1311 $sqlmid .=
" WHERE payfac.fk_facturefourn = f.rowid AND payfac.fk_paiementfourn=".$val[
"paymentsupplierid"];
1312 $ref = $langs->transnoentitiesnoconv(
"SupplierInvoice");
1313 } elseif ($typerecord ==
'payment_expensereport') {
1314 $sqlmid =
'SELECT e.rowid as id, e.ref';
1315 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_expensereport as pe, ".MAIN_DB_PREFIX.
"expensereport as e";
1316 $sqlmid .=
" WHERE pe.rowid=".$val[
"paymentexpensereport"].
" AND pe.fk_expensereport = e.rowid";
1317 $ref = $langs->transnoentitiesnoconv(
"ExpenseReport");
1318 } elseif ($typerecord ==
'payment_salary') {
1319 $sqlmid =
'SELECT s.rowid as ref';
1320 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as s";
1321 $sqlmid .=
" WHERE s.rowid=".$val[
"paymentsalid"];
1322 $ref = $langs->transnoentitiesnoconv(
"SalaryPayment");
1323 } elseif ($typerecord ==
'sc') {
1324 $sqlmid =
'SELECT sc.rowid as ref';
1325 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"paiementcharge as sc";
1326 $sqlmid .=
" WHERE sc.rowid=".$val[
"paymentscid"];
1327 $ref = $langs->transnoentitiesnoconv(
"SocialContribution");
1328 } elseif ($typerecord ==
'payment_vat') {
1329 $sqlmid =
'SELECT v.rowid as ref';
1330 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"tva as v";
1331 $sqlmid .=
" WHERE v.rowid=".$val[
"paymentvatid"];
1332 $ref = $langs->transnoentitiesnoconv(
"PaymentVat");
1333 } elseif ($typerecord ==
'payment_donation') {
1334 $sqlmid =
'SELECT payd.fk_donation as ref';
1335 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_donation as payd";
1336 $sqlmid .=
" WHERE payd.fk_donation=".$val[
"paymentdonationid"];
1337 $ref = $langs->transnoentitiesnoconv(
"Donation");
1338 } elseif ($typerecord ==
'payment_loan') {
1339 $sqlmid =
'SELECT l.rowid as ref';
1340 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_loan as l";
1341 $sqlmid .=
" WHERE l.rowid=".$val[
"paymentloanid"];
1342 $ref = $langs->transnoentitiesnoconv(
"LoanPayment");
1343 } elseif ($typerecord ==
'payment_various') {
1344 $sqlmid =
'SELECT v.rowid as ref';
1345 $sqlmid .=
" FROM ".MAIN_DB_PREFIX.
"payment_various as v";
1346 $sqlmid .=
" WHERE v.rowid=".$val[
"paymentvariousid"];
1347 $ref = $langs->transnoentitiesnoconv(
"VariousPayment");
1350 if (empty($sqlmid)) {
1351 dol_syslog(
"Found a typerecord=".$typerecord.
" not supported", LOG_WARNING);
1355 dol_syslog(
"accountancy/journal/bankjournal.php::sqlmid=".$sqlmid, LOG_DEBUG);
1356 $resultmid = $db->query($sqlmid);
1358 while ($objmid = $db->fetch_object($resultmid)) {
1359 $ref .=
' '.$objmid->ref;
1366 $ref =
dol_trunc($langs->transnoentitiesnoconv(
"BankId").
' '.$val[
'fk_bank'].
' - '.$ref, 295);
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto= 'UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Class to manage various payments.
Class to manage salary payments.
dol_now($mode= 'auto')
Return date for now.
getDefaultDatesForTransfer()
Return Default dates for transfer based on periodicity option in accountancy setup.
Class to manage Dolibarr users.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Class to manage bank transaction lines.
Class to manage suppliers invoices.
journalHead($nom, $variante, $period, $periodlink, $description, $builddate, $exportlink= '', $moreparam=array(), $calcmode= '', $varlink= '')
Show header of a page used to transfer/dispatch data in accounting.
Class to manage bank accounts.
Put here description of your class.
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
Class to manage Ledger (General Ledger and Subledger)
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
Class to manage payments of loans.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Class to manage payments of customer invoices.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
getSourceDocRef($val, $typerecord)
Return source for doc_ref of a bank transaction.
Class to manage Trips and Expenses.
Class to manage subscriptions of foundation members.
Class to manage payments of donations.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
print
Draft customers invoices.
Class to manage donations.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Class to manage payments of expense report.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc= 'right', $stringencoding= 'UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
Class to manage accounting accounts.
Class to manage accounting accounts.
Class to manage invoices.
Class to manage payments for supplier invoices.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...
Classe permettant la gestion des paiements des charges La tva collectee n'est calculee que sur les fa...
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.