36require
'../../main.inc.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
47require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/core/lib/loan.lib.php';
55$langs->loadLangs(array(
"companies",
"other",
"compta",
"banks",
"bills",
"donations",
"loan",
"accountancy",
"trips",
"salaries",
"hrm",
"members"));
60$date_startmonth =
GETPOSTINT(
'date_startmonth');
66$in_bookkeeping =
GETPOST(
'in_bookkeeping',
'aZ09');
69if ($only_rappro == 0) {
76$action =
GETPOST(
'action',
'aZ09');
78if ($in_bookkeeping ==
'' || $action ==
'writebookkeeping') {
79 $in_bookkeeping =
'notyet';
86if ($user->socid > 0) {
89if (!$user->hasRight(
'accounting',
'bind',
'write')) {
101$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
104$pastmonthyear =
null;
106if (empty($date_startmonth)) {
110 $pastmonthyear = $dates[
'pastmonthyear'];
111 $pastmonth = $dates[
'pastmonth'];
113if (empty($date_endmonth)) {
116 $date_end = $dates[
'date_end'];
117 $pastmonthyear = $dates[
'pastmonthyear'];
118 $pastmonth = $dates[
'pastmonth'];
121if (!
GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end))) {
123 $date_end =
dol_get_last_day((
int) $pastmonthyear, (
int) $pastmonth,
false);
128$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,";
129$sql .=
" ba.courant, ba.ref as baref, ba.account_number, ba.fk_accountancy_journal,";
130$sql .=
" bu.type as bu_type";
131$sql .=
" FROM ".$db->prefix().
"bank as b";
132$sql .=
" JOIN ".$db->prefix().
"bank_account as ba on b.fk_account = ba.rowid";
133$sql .=
" LEFT JOIN ".$db->prefix().
"bank_url as bu ON bu.fk_bank = b.rowid";
134$sql .=
" WHERE ba.fk_accountancy_journal = ".((int) $id_journal);
135$sql .=
" AND b.amount <> 0 AND ba.entity IN (".getEntity(
'bank_account').
")";
136if ($date_start && $date_end) {
137 $sql .=
" AND b.dateo >= '".$db->idate($date_start).
"' AND b.dateo <= '".$db->idate($date_end).
"'";
141 $sql .=
" AND b.dateo >= '".$db->idate(
getDolGlobalInt(
'ACCOUNTING_DATE_START_BINDING')).
"'";
144if ($in_bookkeeping ==
'already') {
145 $sql .=
" AND (b.rowid IN (SELECT fk_doc FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
147if ($in_bookkeeping ==
'notyet') {
148 $sql .=
" AND (b.rowid NOT IN (SELECT fk_doc FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
150if ($only_rappro == 2) {
151 $sql .=
" AND (b.rappro = '1')";
153$sql .=
" ORDER BY b.dateo";
156$result_lines = array();
159$payment_ids = array();
161$tabaccount = array();
163$tabaccountingaccount = array();
164$tabvatdata = array();
166dol_syslog(
"accountancy/journal/treasuryjournal.php", LOG_DEBUG);
167$resql = $db->query($sql);
169 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
170 $static_account =
new Account($db);
172 while ($obj = $db->fetch_object($resql)) {
174 if (!isset($tabpay[$obj->rowid])) {
175 $tabpay[$obj->rowid] = array(
177 'date' => $db->jdate($obj->do),
178 'type_payment' => $obj->fk_type,
179 'ref' => $obj->label,
180 'fk_bank_account' => $obj->fk_account,
181 'objects' => array(),
184 if (preg_match(
'/^\((.*)\)$/i', $obj->label, $reg)) {
185 $tabpay[$obj->rowid][
"lib"] = $langs->trans($reg[1]);
187 $tabpay[$obj->rowid][
"lib"] =
dol_trunc($obj->label, 60);
190 $payment_ids[$obj->bu_type][$obj->rowid] = $obj->rowid;
193 if (!isset($tabaccount[$obj->fk_account])) {
194 $static_account->id = $obj->fk_account;
195 $static_account->ref = $obj->baref;
196 $tabaccount[$obj->fk_account] = [
197 'id' => $obj->fk_account,
198 'account_ref' => $obj->baref,
199 'account_number' => $obj->account_number,
200 'url' => $static_account->getNomUrl(1),
207 foreach ($payment_ids as $type => $ids) {
210 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
214 $sql =
"SELECT f.rowid, f.ref AS ref, f.total_ht AS invoice_total_ht, f.total_ttc AS invoice_total_ttc,";
215 $sql .=
" pf.amount AS amount_payment, pf.fk_paiement AS payment_id,";
216 $sql .=
" fd.rowid AS row_id, fd.total_ht, fd.total_tva, fd.total_localtax1, fd.total_localtax2, fd.tva_tx, fd.total_ttc, fd.vat_src_code,";
217 $sql .=
" aa.account_number as accountancy_code, aa.label as accountancy_code_label,";
218 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
219 $sql .=
" FROM ".$db->prefix().
"facturedet as fd";
220 $sql .=
" INNER JOIN ".$db->prefix().
"facture as f ON f.rowid = fd.fk_facture";
221 $sql .=
" INNER JOIN ".$db->prefix().
"paiement_facture as pf ON pf.fk_facture = f.rowid";
222 $sql .=
" INNER JOIN ".$db->prefix().
"bank_url as bu ON bu.url_id = pf.fk_paiement AND bu.type = '".$db->escape($type).
"'";
223 $sql .=
" LEFT JOIN ".$db->prefix().
"product as p ON p.rowid = fd.fk_product";
224 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
226 $sql .=
" WHERE f.entity IN (".getEntity(
'facture', 0).
')';
228 if ($in_bookkeeping ==
'already') {
229 $sql .=
" AND EXISTS (SELECT ab.rowid FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type = 'bank' AND ab.fk_doc = bu.fk_bank)";
231 if ($in_bookkeeping ==
'notyet') {
232 $sql .=
" AND NOT EXISTS (SELECT ab.rowid FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type = 'bank' AND ab.fk_doc = bu.fk_bank)";
234 $sql .=
" AND fd.fk_code_ventilation > 0";
235 $sql .=
" AND f.fk_statut > 0";
236 $sql .=
" AND fd.product_type IN (0,1)";
238 $sql .=
" AND bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
240 $sql .=
" ORDER BY aa.account_number";
242 $resql = $db->query($sql);
244 $langs->load(
"bills");
245 $static_invoice =
new Facture($db);
246 $already_sum = array();
249 while ($obj = $db->fetch_object($resql)) {
250 $object_key = $obj->bu_type.
'_'.$obj->rowid;
257 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
258 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
259 'amount' => $obj->amount_payment,
260 'bu_url_id' => $obj->bu_url_id,
264 if (isset($already_sum[$obj->row_id])) {
267 $already_sum[$obj->row_id] = $obj->row_id;
270 if (!isset($tabobject[$object_key])) {
271 $static_invoice->id = $obj->rowid;
272 $static_invoice->ref = $obj->ref;
273 $tabobject[$object_key] = array(
276 'total_ht' => $obj->invoice_total_ht,
277 'total_ttc' => $obj->invoice_total_ttc,
278 'url' => $static_invoice->getNomUrl(1),
279 'operations' => array(),
285 if (!isset($tabaccountingaccount[$obj->accountancy_code])) {
286 $tabaccountingaccount[$obj->accountancy_code] = array(
287 'label' => !empty($obj->accountancy_code_label) ? $obj->accountancy_code_label : $langs->trans(
'NotDefined'),
292 if (!isset($tabobject[$object_key][
'operations'][$obj->accountancy_code])) {
293 $tabobject[$object_key][
'operations'][$obj->accountancy_code] = array(
297 $tabobject[$object_key][
'operations'][$obj->accountancy_code][
'total_ht'] += $obj->total_ht;
299 if ($obj->total_tva + $obj->total_localtax1 + $obj->total_localtax2 != 0) {
301 if (!isset($tabvatdata[$obj->tva_tx][$obj->vat_src_code])) {
302 $tabvatdata[$obj->tva_tx][$obj->vat_src_code] =
getTaxesFromId($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''),
$mysoc,
$mysoc, 0);
304 $compta_tva = (!empty($tabvatdata[$obj->tva_tx][$obj->vat_src_code][
'accountancy_code_sell']) ? $tabvatdata[$obj->tva_tx][$obj->vat_src_code][
'accountancy_code_sell'] : $account_vat_sold);
307 if (!isset($tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx])) {
308 $tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx] = array(
309 'tva_tx' => $obj->tva_tx,
311 'total_localtax1' => 0,
312 'total_localtax2' => 0,
315 $tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx][
'total_tva'] += $obj->total_tva;
316 $tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx][
'total_localtax1'] += $obj->total_localtax1;
317 $tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx][
'total_localtax2'] += $obj->total_localtax2;
321 dol_print_error($db);
324 case 'payment_supplier':
325 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
329 $sql =
"SELECT ff.rowid, ff.ref, ff.total_ht AS supplier_invoice_total_ht, ff.total_ttc AS supplier_invoice_total_ttc,";
330 $sql .=
" pff.amount AS amount_payment, pff.fk_paiementfourn AS payment_id,";
331 $sql .=
" ffd.rowid AS row_id, ffd.total_ht, ffd.tva AS total_tva, ffd.total_localtax1, ffd.total_localtax2, ffd.tva_tx, ffd.total_ttc, ffd.vat_src_code,";
332 $sql .=
" aa.account_number as accountancy_code, aa.label as accountancy_code_label,";
333 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
334 $sql .=
" FROM ".$db->prefix().
"facture_fourn_det as ffd";
335 $sql .=
" INNER JOIN ".$db->prefix().
"facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
336 $sql .=
" INNER JOIN ".$db->prefix().
"paiementfourn_facturefourn as pff ON pff.fk_facturefourn = ff.rowid";
337 $sql .=
" INNER JOIN ".$db->prefix().
"bank_url as bu ON bu.url_id = pff.fk_paiementfourn AND bu.type = '".$db->escape($type).
"'";
338 $sql .=
" LEFT JOIN ".$db->prefix().
"product as p ON p.rowid = ffd.fk_product";
339 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_account as aa ON aa.rowid = ffd.fk_code_ventilation";
340 $sql .=
" WHERE ff.entity IN (".getEntity(
'facture_fourn', 0).
')';
342 if ($in_bookkeeping ==
'already') {
343 $sql .=
" AND EXISTS (SELECT ab.rowid FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type = 'bank' AND ab.fk_doc = bu.fk_bank)";
345 if ($in_bookkeeping ==
'notyet') {
346 $sql .=
" AND NOT EXISTS (SELECT ab.rowid FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type = 'bank' AND ab.fk_doc = bu.fk_bank)";
348 $sql .=
" AND ffd.fk_code_ventilation > 0";
349 $sql .=
" AND ff.fk_statut > 0";
350 $sql .=
" AND ffd.product_type IN (0,1)";
352 $sql .=
" AND bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
354 $sql .=
" ORDER BY aa.account_number";
356 $resql = $db->query($sql);
358 $langs->load(
"suppliers");
360 $already_sum = array();
363 while ($obj = $db->fetch_object($resql)) {
364 $object_key = $obj->bu_type.
'_'.$obj->rowid;
367 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
368 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
369 'amount' => -$obj->amount_payment,
370 'bu_url_id' => $obj->bu_url_id,
374 if (isset($already_sum[$obj->row_id])) {
377 $already_sum[$obj->row_id] = $obj->row_id;
380 if (!isset($tabobject[$object_key])) {
381 $static_supplier_invoice->id = $obj->rowid;
382 $static_supplier_invoice->ref = $obj->ref;
383 $tabobject[$object_key] = array(
386 'total_ht' => -$obj->supplier_invoice_total_ht,
387 'total_ttc' => -$obj->supplier_invoice_total_ttc,
388 'url' => $static_supplier_invoice->getNomUrl(1),
389 'operations' => array(),
395 if (!isset($tabaccountingaccount[$obj->accountancy_code])) {
396 $tabaccountingaccount[$obj->accountancy_code] = array(
397 'label' => !empty($obj->accountancy_code_label) ? $obj->accountancy_code_label : $langs->trans(
'NotDefined'),
402 if (!isset($tabobject[$object_key][
'operations'][$obj->accountancy_code])) {
403 $tabobject[$object_key][
'operations'][$obj->accountancy_code] = array(
407 $tabobject[$object_key][
'operations'][$obj->accountancy_code][
'total_ht'] -= $obj->total_ht;
409 if ($obj->total_tva + $obj->total_localtax1 + $obj->total_localtax2 != 0) {
411 if (!isset($tabvatdata[$obj->tva_tx][$obj->vat_src_code])) {
412 $tabvatdata[$obj->tva_tx][$obj->vat_src_code] =
getTaxesFromId($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''),
$mysoc,
$mysoc, 0);
414 $compta_tva = (!empty($tabvatdata[$obj->tva_tx][$obj->vat_src_code][
'accountancy_code_buy']) ? $tabvatdata[$obj->tva_tx][$obj->vat_src_code][
'accountancy_code_buy'] : $account_vat_buy);
417 if (!isset($tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx])) {
418 $tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx] = array(
419 'tva_tx' => $obj->tva_tx,
421 'total_localtax1' => 0,
422 'total_localtax2' => 0,
425 $tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx][
'total_tva'] -= $obj->total_tva;
426 $tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx][
'total_localtax1'] -= $obj->total_localtax1;
427 $tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx][
'total_localtax2'] -= $obj->total_localtax2;
431 dol_print_error($db);
434 case 'payment_expensereport':
435 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
439 $sql =
"SELECT er.rowid, er.ref, er.total_ht AS expense_report_total_ht, er.total_ttc AS expense_report_total_ttc,";
440 $sql .=
" per.amount AS amount_payment, per.rowid AS payment_id,";
441 $sql .=
" erf.rowid AS row_id, erf.total_ht, erf.total_tva, erf.total_localtax1, erf.total_localtax2, erf.tva_tx, erf.total_ttc, erf.vat_src_code,";
442 $sql .=
" ctf.accountancy_code,";
443 $sql .=
" aa.label as accountancy_code_label,";
444 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
445 $sql .=
" FROM ".$db->prefix().
"expensereport_det as erf";
446 $sql .=
" INNER JOIN ".$db->prefix().
"expensereport as er ON er.rowid = erf.fk_expensereport";
447 $sql .=
" INNER JOIN ".$db->prefix().
"payment_expensereport as per ON per.fk_expensereport = er.rowid";
448 $sql .=
" INNER JOIN ".$db->prefix().
"bank_url as bu ON bu.url_id = per.rowid AND bu.type = '".$db->escape($type).
"'";
449 $sql .=
" LEFT JOIN ".$db->prefix().
"c_type_fees as ctf ON ctf.id = erf.fk_c_type_fees";
450 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_account as aa ON aa.account_number = ctf.accountancy_code";
451 $sql .=
" WHERE er.entity IN (".getEntity(
'expensereport', 0).
')';
453 if ($in_bookkeeping ==
'already') {
454 $sql .=
" AND EXISTS (SELECT ab.rowid FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type = 'bank' AND ab.fk_doc = bu.fk_bank)";
456 if ($in_bookkeeping ==
'notyet') {
457 $sql .=
" AND NOT EXISTS (SELECT ab.rowid FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type = 'bank' AND ab.fk_doc = bu.fk_bank)";
459 $sql .=
" AND er.fk_statut >= ".ExpenseReport::STATUS_APPROVED;
460 $sql .=
" AND bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
462 $sql .=
" ORDER BY aa.account_number";
464 $resql = $db->query($sql);
466 $langs->load(
"trips");
468 $already_sum = array();
471 while ($obj = $db->fetch_object($resql)) {
472 $object_key = $obj->bu_type.
'_'.$obj->rowid;
475 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
476 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
477 'amount' => -$obj->amount_payment,
478 'bu_url_id' => $obj->bu_url_id,
482 if (isset($already_sum[$obj->row_id])) {
485 $already_sum[$obj->row_id] = $obj->row_id;
488 if (!isset($tabobject[$object_key])) {
489 $static_expense_report->id = $obj->rowid;
490 $static_expense_report->ref = $obj->ref;
491 $tabobject[$object_key] = array(
494 'total_ht' => -$obj->expense_report_total_ht,
495 'total_ttc' => -$obj->expense_report_total_ttc,
496 'url' => $static_expense_report->getNomUrl(1),
497 'operations' => array(),
503 $accountancy_code = !empty($obj->accountancy_code) ? $obj->accountancy_code :
'NotDefined';
504 if (!isset($tabaccountingaccount[$accountancy_code])) {
505 $tabaccountingaccount[$accountancy_code] = array(
506 'label' => !empty($obj->accountancy_code_label) ? $obj->accountancy_code_label : $langs->trans(
'NotDefined'),
511 if (!isset($tabobject[$object_key][
'operations'][$accountancy_code])) {
512 $tabobject[$object_key][
'operations'][$accountancy_code] = array(
516 $tabobject[$object_key][
'operations'][$accountancy_code][
'total_ht'] -= $obj->total_ht;
518 if ($obj->total_tva + $obj->total_localtax1 + $obj->total_localtax2 != 0) {
520 if (!isset($tabvatdata[$obj->tva_tx][$obj->vat_src_code])) {
521 $tabvatdata[$obj->tva_tx][$obj->vat_src_code] =
getTaxesFromId($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''),
$mysoc,
$mysoc, 0);
523 $compta_tva = (!empty($tabvatdata[$obj->tva_tx][$obj->vat_src_code][
'accountancy_code_buy']) ? $tabvatdata[$obj->tva_tx][$obj->vat_src_code][
'accountancy_code_buy'] : $account_vat_buy);
526 if (!isset($tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx])) {
527 $tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx] = array(
528 'tva_tx' => $obj->tva_tx,
530 'total_localtax1' => 0,
531 'total_localtax2' => 0,
534 $tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx][
'total_tva'] -= $obj->total_tva;
535 $tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx][
'total_localtax1'] -= $obj->total_localtax1;
536 $tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx][
'total_localtax2'] -= $obj->total_localtax2;
540 dol_print_error($db);
543 case 'payment_salary':
546 $sql =
"SELECT ps.rowid,";
547 $sql .=
" ps.amount AS amount_payment, ps.rowid as payment_id, ps.label AS label,";
548 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
549 $sql .=
" FROM ".$db->prefix().
"payment_salary as ps";
550 $sql .=
" INNER JOIN ".$db->prefix().
"bank_url as bu ON bu.url_id = ps.rowid AND bu.type = '".$db->escape($type).
"'";
551 $sql .=
" WHERE ps.entity IN (".getEntity(
'user', 0).
')';
553 if ($in_bookkeeping ==
'already') {
554 $sql .=
" AND EXISTS (SELECT ab.rowid FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type = 'bank' AND ab.fk_doc = bu.fk_bank)";
556 if ($in_bookkeeping ==
'notyet') {
557 $sql .=
" AND NOT EXISTS (SELECT ab.rowid FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type = 'bank' AND ab.fk_doc = bu.fk_bank)";
559 $sql .=
" AND bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
561 $resql = $db->query($sql);
563 require_once DOL_DOCUMENT_ROOT.
'/salaries/class/paymentsalary.class.php';
564 $langs->load(
"salaries");
566 $account_employee =
getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT',
'NotDefined');
569 while ($obj = $db->fetch_object($resql)) {
570 $object_key = $obj->bu_type.
'_'.$obj->rowid;
573 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
574 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
575 'amount' => -$obj->amount_payment,
576 'bu_url_id' => $obj->bu_url_id,
581 if (!isset($tabobject[$object_key])) {
582 $static_payment_salary->id = $obj->rowid;
583 $static_payment_salary->ref = $prefix_ref.$obj->rowid;
584 $tabobject[$object_key] = array(
586 'ref' => $prefix_ref.$obj->rowid,
587 'total_ht' => -$obj->amount_payment,
588 'total_ttc' => -$obj->amount_payment,
589 'url' => $static_payment_salary->getNomUrl(1),
590 'operations' => array(),
596 $tabobject[$object_key][
'operations'][$account_employee] = array(
597 'total_ht' => -$obj->amount_payment,
598 'label' => $obj->label,
602 dol_print_error($db);
608 $sql =
"SELECT cs.rowid, cs.ref, cs.libelle AS label, cs.amount AS sociales_contributions_amount,";
609 $sql .=
" pc.amount AS amount_payment, pc.rowid as payement_id,";
610 $sql .=
" ccs.accountancy_code,";
611 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
612 $sql .=
" FROM ".$db->prefix().
"paiementcharge as pc";
613 $sql .=
" INNER JOIN ".$db->prefix().
"bank_url as bu ON bu.url_id = pc.rowid AND bu.type = '".$db->escape($type).
"'";
614 $sql .=
" INNER JOIN ".$db->prefix().
"chargesociales AS cs ON cs.rowid = pc.fk_charge";
615 $sql .=
" LEFT JOIN ".$db->prefix().
"c_chargesociales as ccs ON ccs.id = cs.fk_type";
616 $sql .=
" WHERE cs.entity = ".((int)
$conf->entity);
618 if ($in_bookkeeping ==
'already') {
619 $sql .=
" AND EXISTS (SELECT ab.rowid FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type = 'bank' AND ab.fk_doc = bu.fk_bank)";
621 if ($in_bookkeeping ==
'notyet') {
622 $sql .=
" AND NOT EXISTS (SELECT ab.rowid FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type = 'bank' AND ab.fk_doc = bu.fk_bank)";
624 $sql .=
" AND bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
626 $resql = $db->query($sql);
628 require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
630 $langs->load(
"bills");
632 $prefix_ref =
getDolGlobalString(
'MAIN_PAYMENT_SOCIALES_CONTRIBUTIONS_REF_PREFIX',
'SC');
634 while ($obj = $db->fetch_object($resql)) {
635 $object_key = $obj->bu_type.
'_'.$obj->rowid;
638 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
639 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
640 'amount' => -$obj->amount_payment,
641 'bu_url_id' => $obj->bu_url_id,
646 if (!isset($tabobject[$object_key])) {
647 $static_sociales_contributions->id = $obj->rowid;
648 $static_sociales_contributions->ref = $prefix_ref.$obj->rowid;
649 $tabobject[$object_key] = array(
651 'ref' => $prefix_ref.$obj->rowid,
652 'total_ht' => -$obj->sociales_contributions_amount,
653 'total_ttc' => -$obj->sociales_contributions_amount,
654 'url' => $static_sociales_contributions->getNomUrl(1),
655 'operations' => array(),
660 $accountancy_code = !empty($obj->accountancy_code) ? $obj->accountancy_code :
'NotDefined';
663 $tabobject[$object_key][
'operations'][$accountancy_code] = array(
664 'total_ht' => -$obj->sociales_contributions_amount,
665 'label' => $obj->label,
669 dol_print_error($db);
676 $sql =
"SELECT pv.rowid, t.rowid AS tva_id,";
677 $sql .=
" pv.amount AS amount_payment, t.label AS label,";
678 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
679 $sql .=
" FROM ".$db->prefix().
"payment_vat as pv";
680 $sql .=
" INNER JOIN ".$db->prefix().
"tva as t ON t.rowid = pv.fk_tva";
681 $sql .=
" INNER JOIN ".$db->prefix().
"bank_url as bu ON bu.url_id = pv.rowid AND bu.type = '".$db->escape($type).
"'";
682 $sql .=
" WHERE bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
685 if ($in_bookkeeping ==
'already') {
686 $sql .=
" AND EXISTS (SELECT ab.rowid FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type = 'bank' AND ab.fk_doc = bu.fk_bank)";
688 if ($in_bookkeeping ==
'notyet') {
689 $sql .=
" AND NOT EXISTS (SELECT ab.rowid FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type = 'bank' AND ab.fk_doc = bu.fk_bank)";
692 $resql = $db->query($sql);
694 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
696 $langs->load(
"salaries");
697 $static_tva =
new Tva($db);
701 while ($obj = $db->fetch_object($resql)) {
702 $object_key = $obj->bu_type.
'_'.$obj->rowid;
705 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
706 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
707 'amount' => -$obj->amount_payment,
708 'bu_url_id' => $obj->bu_url_id,
713 if (!isset($tabobject[$object_key])) {
714 $static_tva->id = $obj->tva_id;
715 $static_tva->ref = $prefix_ref.$obj->tva_id;
716 $tabobject[$object_key] = array(
717 'id' => $obj->tva_id,
718 'ref' => $prefix_ref.$obj->tva_id,
719 'total_ht' => -$obj->amount_payment,
720 'total_ttc' => -$obj->amount_payment,
721 'url' => $static_tva->getNomUrl(1),
722 'operations' => array(),
728 $tabobject[$object_key][
'operations'][$account_pay_vat] = array(
729 'total_ht' => -$obj->amount_payment,
730 'label' => $obj->label,
734 dol_print_error($db);
737 case 'payment_donation':
740 $sql =
"SELECT d.rowid, d.amount AS don_amount,";
741 $sql .=
" pd.amount AS amount_payment, pd.rowid as payment_id,";
742 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
743 $sql .=
" FROM ".$db->prefix().
"payment_donation as pd";
744 $sql .=
" INNER JOIN ".$db->prefix().
"don as d ON pd.fk_donation = d.rowid";
745 $sql .=
" INNER JOIN ".$db->prefix().
"bank_url as bu ON bu.url_id = pd.rowid AND bu.type = '".$db->escape($type).
"'";
746 $sql .=
" WHERE d.entity IN (".getEntity(
'donation', 0).
')';
748 if ($in_bookkeeping ==
'already') {
749 $sql .=
" AND EXISTS (SELECT ab.rowid FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type = 'bank' AND ab.fk_doc = bu.fk_bank)";
751 if ($in_bookkeeping ==
'notyet') {
752 $sql .=
" AND NOT EXISTS (SELECT ab.rowid FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type = 'bank' AND ab.fk_doc = bu.fk_bank)";
754 $sql .=
" AND bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
756 $resql = $db->query($sql);
758 require_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
760 $langs->load(
"donations");
761 $static_don =
new Don($db);
762 $account_pay_donation =
getDolGlobalString(
'DONATION_ACCOUNTINGACCOUNT',
'NotDefined');
765 while ($obj = $db->fetch_object($resql)) {
766 $object_key = $obj->bu_type.
'_'.$obj->rowid;
769 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
770 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
771 'amount' => $obj->amount_payment,
772 'bu_url_id' => $obj->bu_url_id,
777 if (!isset($tabobject[$object_key])) {
778 $static_don->id = $obj->rowid;
779 $static_don->ref = $prefix_ref.$obj->rowid;
780 $tabobject[$object_key] = array(
782 'ref' => $prefix_ref.$obj->rowid,
783 'total_ht' => $obj->don_amount,
784 'total_ttc' => $obj->don_amount,
785 'url' => $static_don->getNomUrl(1),
786 'operations' => array(),
792 $tabobject[$object_key][
'operations'][$account_pay_donation] = array(
793 'total_ht' => $obj->don_amount,
794 'label' => $langs->trans(
'Donation').
' '.$prefix_ref.$obj->rowid,
798 dol_print_error($db);
804 $sql =
"SELECT l.rowid, l.capital AS loan_capital, l.accountancy_account_capital, l.accountancy_account_interest, l.accountancy_account_insurance, l.label, l.charge_type,";
805 $sql .=
" pl.amount_capital, pl.rowid as payment_id, pl.amount_interest, pl.amount_insurance,";
806 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
807 $sql .=
" FROM ".$db->prefix().
"payment_loan as pl";
808 $sql .=
" INNER JOIN ".$db->prefix().
"loan as l ON pl.fk_loan = l.rowid";
809 $sql .=
" INNER JOIN ".$db->prefix().
"bank_url as bu ON bu.url_id = pl.rowid AND bu.type = '".$db->escape($type).
"'";
810 $sql .=
" WHERE l.entity = ".((int)
$conf->entity);
812 if ($in_bookkeeping ==
'already') {
813 $sql .=
" AND EXISTS (SELECT ab.rowid FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type = 'bank' AND ab.fk_doc = bu.fk_bank)";
815 if ($in_bookkeeping ==
'notyet') {
816 $sql .=
" AND NOT EXISTS (SELECT ab.rowid FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type = 'bank' AND ab.fk_doc = bu.fk_bank)";
818 $sql .=
" AND bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
820 $resql = $db->query($sql);
822 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
824 $langs->load(
"loan");
825 $static_loan =
new Loan($db);
826 $account_pay_loan_capital =
getDolGlobalString(
'LOAN_ACCOUNTING_ACCOUNT_CAPITAL',
'NotDefined');
827 $account_pay_loan_interest =
getDolGlobalString(
'LOAN_ACCOUNTING_ACCOUNT_INTEREST',
'NotDefined');
828 $account_pay_loan_insurance =
getDolGlobalString(
'LOAN_ACCOUNTING_ACCOUNT_INSURANCE',
'NotDefined');
831 while ($obj = $db->fetch_object($resql)) {
832 $object_key = $obj->bu_type.
'_'.$obj->rowid;
835 $payment_amount = $obj->amount_capital + $obj->amount_interest + $obj->amount_insurance;
836 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
837 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
838 'amount' => -$payment_amount,
839 'bu_url_id' => $obj->bu_url_id,
844 if (!isset($tabobject[$object_key])) {
845 $static_loan->id = $obj->rowid;
846 $static_loan->ref = $prefix_ref.$obj->rowid;
847 $tabobject[$object_key] = array(
849 'ref' => $prefix_ref.$obj->rowid,
850 'total_ht' => -$obj->loan_capital,
851 'total_ttc' => -$obj->loan_capital,
852 'url' => $static_loan->getNomUrl(1),
853 'operations' => array(),
859 $accountancy_account_capital = !empty($obj->accountancy_account_capital) ? $obj->accountancy_account_capital : $account_pay_loan_capital;
860 $tabobject[$object_key][
'operations'][$accountancy_account_capital] = array(
862 'total_ht' => -($obj->loan_capital * $obj->amount_capital / $payment_amount),
863 'label' => $obj->label.
' '.$langs->trans(
'LoanCapital'),
867 $accountancy_account_interest = !empty($obj->accountancy_account_interest) ? $obj->accountancy_account_interest : $account_pay_loan_interest;
868 $tabobject[$object_key][
'operations'][$accountancy_account_interest] = array(
870 'total_ht' => -($obj->loan_capital * $obj->amount_interest / $payment_amount),
871 'label' => $obj->label.
' '.$langs->trans(
'Interest'),
877 $accountancy_account_insurance = !empty($obj->accountancy_account_insurance) ? $obj->accountancy_account_insurance : $account_pay_loan_insurance;
878 $tabobject[$object_key][
'operations'][$accountancy_account_insurance] = array(
880 'total_ht' => -($obj->loan_capital * $obj->amount_insurance / $payment_amount),
885 dol_print_error($db);
888 case 'payment_various':
891 $sql =
"SELECT pv.rowid,";
892 $sql .=
" pv.sens AS sens_payment, pv.amount AS amount_payment, pv.rowid as payment_id, pv.label, pv.accountancy_code,";
893 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
894 $sql .=
" FROM ".$db->prefix().
"payment_various as pv";
895 $sql .=
" INNER JOIN ".$db->prefix().
"bank_url as bu ON bu.url_id = pv.rowid AND bu.type = '".$db->escape($type).
"'";
896 $sql .=
" WHERE pv.entity IN (".getEntity(
'payment_various', 0).
')';
897 $sql .=
" AND bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
899 if ($in_bookkeeping ==
'already') {
900 $sql .=
" AND EXISTS (SELECT ab.rowid FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type = 'bank' AND ab.fk_doc = bu.fk_bank)";
902 if ($in_bookkeeping ==
'notyet') {
903 $sql .=
" AND NOT EXISTS (SELECT ab.rowid FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type = 'bank' AND ab.fk_doc = bu.fk_bank)";
906 $resql = $db->query($sql);
908 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
913 while ($obj = $db->fetch_object($resql)) {
914 $object_key = $obj->bu_type.
'_'.$obj->rowid;
916 $payment_amount = (empty($obj->sens_payment) ? -1 : 1) * $obj->amount_payment;
918 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
919 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
920 'amount' => $payment_amount,
921 'bu_url_id' => $obj->bu_url_id,
926 if (!isset($tabobject[$object_key])) {
927 $static_payment_various->id = $obj->rowid;
928 $static_payment_various->ref = $prefix_ref.$obj->rowid;
929 $tabobject[$object_key] = array(
931 'ref' => $prefix_ref.$obj->rowid,
932 'total_ht' => $payment_amount,
933 'total_ttc' => $payment_amount,
934 'url' => $static_payment_various->getNomUrl(1),
935 'operations' => array(),
941 $accountancy_code = !empty($obj->accountancy_code) ? $obj->accountancy_code :
'NotDefined';
942 $tabobject[$object_key][
'operations'][$obj->accountancy_code] = array(
943 'total_ht' => $payment_amount,
944 'label' => $obj->label,
948 dol_print_error($db);
954 $sql =
"SELECT su.rowid,";
955 $sql .=
" su.subscription AS amount_payment, su.rowid as payment_id, su.note AS label,";
956 $sql .=
" adh.lastname, adh.firstname,";
957 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
958 $sql .=
" FROM ".$db->prefix().
"subscription as su";
959 $sql .=
" INNER JOIN ".$db->prefix().
"adherent as adh ON adh.rowid = su.fk_adherent";
960 $sql .=
" INNER JOIN ".$db->prefix().
"bank_url as bu ON bu.fk_bank = su.fk_bank AND bu.type = '".$db->escape($type).
"'";
961 $sql .=
" WHERE bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
963 if ($in_bookkeeping ==
'already') {
964 $sql .=
" AND EXISTS (SELECT ab.rowid FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type = 'bank' AND ab.fk_doc = bu.fk_bank)";
966 if ($in_bookkeeping ==
'notyet') {
967 $sql .=
" AND NOT EXISTS (SELECT ab.rowid FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type = 'bank' AND ab.fk_doc = bu.fk_bank)";
970 $resql = $db->query($sql);
972 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
974 $langs->load(
"members");
976 $account_subscription =
getDolGlobalString(
'ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT',
'NotDefined');
979 while ($obj = $db->fetch_object($resql)) {
980 $object_key = $obj->bu_type.
'_'.$obj->rowid;
983 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
984 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
985 'amount' => $obj->amount_payment,
986 'bu_url_id' => $obj->bu_url_id,
991 if (!isset($tabobject[$object_key])) {
992 $static_subscription->id = $obj->rowid;
993 $static_subscription->ref = $prefix_ref.$obj->rowid;
994 $tabobject[$object_key] = array(
996 'ref' => $prefix_ref.$obj->rowid,
997 'total_ht' => -$obj->amount_payment,
998 'total_ttc' => -$obj->amount_payment,
999 'url' => $static_subscription->getNomUrl(1),
1000 'operations' => array(),
1006 $tabobject[$object_key][
'operations'][$account_subscription] = array(
1007 'total_ht' => -$obj->amount_payment,
1008 'label' => $obj->label.
' - '.$obj->lastname.
' '.$obj->firstname,
1012 dol_print_error($db);
1015 case 'banktransfert':
1018 $sql =
"SELECT b.rowid, b.amount, b.label,";
1019 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
1020 $sql .=
" FROM ".$db->prefix().
"bank_url as bu";
1021 $sql .=
" INNER JOIN ".$db->prefix().
"bank as b ON bu.url_id = b.rowid";
1022 $sql .=
" LEFT JOIN ".$db->prefix().
"bank_account as ba ON ba.rowid = b.fk_account";
1023 $sql .=
" WHERE ba.entity IN (".getEntity(
'bank_account', 0).
')';
1024 $sql .=
" AND bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
1025 $sql .=
" AND bu.type = '".$db->escape($type).
"'";
1027 if ($in_bookkeeping ==
'already') {
1028 $sql .=
" AND EXISTS (SELECT ab.rowid FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type = 'bank' AND ab.fk_doc = bu.fk_bank)";
1030 if ($in_bookkeeping ==
'notyet') {
1031 $sql .=
" AND NOT EXISTS (SELECT ab.rowid FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type = 'bank' AND ab.fk_doc = bu.fk_bank)";
1034 $resql = $db->query($sql);
1036 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
1039 $account_transfer =
getDolGlobalString(
'ACCOUNTING_ACCOUNT_TRANSFER_CASH',
'NotDefined');
1042 while ($obj = $db->fetch_object($resql)) {
1043 $object_key = $obj->bu_type.
'_'.$obj->rowid;
1046 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
1047 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
1048 'amount' => -$obj->amount,
1049 'bu_url_id' => $obj->bu_url_id,
1054 if (!isset($tabobject[$object_key])) {
1055 $static_account_line->id = $obj->rowid;
1056 $static_account_line->rowid = $obj->rowid;
1057 $static_account_line->ref = $prefix_ref.$obj->rowid;
1058 $tabobject[$object_key] = array(
1059 'id' => $obj->rowid,
1060 'ref' => $prefix_ref.$obj->rowid,
1061 'total_ht' => -$obj->amount,
1062 'total_ttc' => -$obj->amount,
1063 'url' => $static_account_line->getNomUrl(1),
1064 'operations' => array(),
1070 $tabobject[$object_key][
'operations'][$account_transfer] = array(
1071 'total_ht' => -$obj->amount,
1072 'label' => $obj->label,
1076 dol_print_error($db);
1082 dol_print_error($db);
1093 return isset($v[
'objects']) && count($v[
'objects']) > 0;
1096$tabpay = array_filter($tabpay,
'payment_filter');
1102$accountingjournalstatic->fetch($id_journal);
1103$journal = $accountingjournalstatic->code;
1104$journal_label = $langs->transnoentitiesnoconv($accountingjournalstatic->label);
1108if ($action ==
'writebookkeeping' ) {
1109 foreach ($tabpay as $bid => $payment) {
1110 $accountInfos = $tabaccount[$payment[
"fk_bank_account"]];
1113 if (!isset($tabaccountingaccount[$accountInfos[
'account_number']])) {
1114 $result = $accountingaccount->fetch(0, $accountInfos[
'account_number'],
true);
1116 setEventMessages($accountingaccount->error, $accountingaccount->errors,
'errors');
1120 $tabaccountingaccount[$accountInfos[
'account_number']] = array(
1121 'label' => $result > 0 ? $accountingaccount->label : $langs->trans(
'NotDefined'),
1130 foreach ($payment[
'objects'] as $object_key => $object_data) {
1131 $objectInfos = $tabobject[$object_key];
1133 $label_suffix = (count($payment[
'objects']) > 1 ?
' - '.$objectInfos[
'ref'] :
'');
1138 if ($object_data[
'amount'] >= 0) {
1139 $amount = (float)
price2num($object_data[
'amount'],
'MT');
1140 $total_check += $amount;
1147 $result = $bookkeepingToCreate->createFromValues($payment[
"date"], $objectInfos[
'ref'],
'bank', $bid, 0, $accountInfos[
'account_number'], $tabaccountingaccount[$accountInfos[
'account_number']][
'label'], $accountInfos[
'account_ref'].$label_suffix, $amount, $journal, $journal_label,
'');
1152 if (!empty($bookkeepingToCreate->warnings)) {
1153 setEventMessages(
null, $bookkeepingToCreate->warnings,
'warnings');
1155 if (!empty($bookkeepingToCreate->errors)) {
1156 setEventMessages(
null, $bookkeepingToCreate->errors,
'errors');
1162 $payment_total_vat = (float)
price2num($object_data[
'amount'] * ($objectInfos[
'total_ttc'] - $objectInfos[
'total_ht']) / $objectInfos[
'total_ttc'],
'MT');
1163 $payment_total_ht = $object_data[
'amount'] - $payment_total_vat;
1164 $total_operation = 0;
1166 $nb_operation = count($objectInfos[
'operations']);
1167 foreach ($objectInfos[
'operations'] as $accountancy_code => $operation) {
1168 if (!empty($operation[
'total_ht'])) {
1170 if (!isset($tabaccountingaccount[$accountancy_code])) {
1171 $result = $accountingaccount->fetch(0, $accountancy_code,
true);
1173 setEventMessages($accountingaccount->error, $accountingaccount->errors,
'errors');
1174 $accountancy_code_label = $accountingaccount->errorsToString();
1176 } elseif ($result > 0) {
1177 $accountancy_code_label = $accountingaccount->label;
1179 $accountancy_code_label = $langs->trans(
'NotDefined');
1181 $tabaccountingaccount[$accountancy_code] = array(
'label' => $accountancy_code_label);
1183 $accountingAccountInfos = $tabaccountingaccount[$accountancy_code];
1184 if ($idx < $nb_operation) {
1185 $amount =
price2num($payment_total_ht * $operation[
'total_ht'] / $objectInfos[
'total_ht'],
'MT');
1186 $total_operation += (float) $amount;
1188 $amount = $payment_total_ht - $total_operation;
1190 $total_check -= (float) $amount;
1194 $result = $bookkeepingToCreate->createFromValues($payment[
"date"], $objectInfos[
'ref'],
'bank', $bid, 0, $accountancy_code, $accountingAccountInfos[
'label'], (!empty($operation[
'label']) ? $operation[
'label'] : $accountingAccountInfos[
'label']).$label_suffix, - (float) $amount, $journal, $journal_label,
'');
1198 if (!empty($bookkeepingToCreate->warnings)) {
1199 setEventMessages(
null, $bookkeepingToCreate->warnings,
'warnings');
1201 if (!empty($bookkeepingToCreate->errors)) {
1202 setEventMessages(
null, $bookkeepingToCreate->errors,
'errors');
1213 foreach ($objectInfos[
'vats'] as $accountancy_code => $vats) {
1214 foreach ($vats as $vat_tx => $vat_infos) {
1218 foreach ($objectInfos[
'vats'] as $accountancy_code => $vats) {
1219 foreach ($vats as $vat_tx => $vat_infos) {
1220 $amount = $vat_infos[
'total_tva'] + $vat_infos[
'total_localtax1'] + $vat_infos[
'total_localtax2'];
1221 if (!empty($amount)) {
1223 if (!isset($tabaccountingaccount[$accountancy_code])) {
1224 $result = $accountingaccount->fetch(0, $accountancy_code,
true);
1226 setEventMessages($accountingaccount->error, $accountingaccount->errors,
'errors');
1227 $accountancy_code_label = $accountingaccount->errorsToString();
1229 } elseif ($result > 0) {
1230 $accountancy_code_label = $accountingaccount->label;
1232 $accountancy_code_label = $langs->trans(
'NotDefined');
1234 $tabaccountingaccount[$accountancy_code] = array(
'label' => $accountancy_code_label);
1236 $accountingAccountInfos = $tabaccountingaccount[$accountancy_code];
1237 $amount = (float)
price2num($payment_total_vat * $amount / ($objectInfos[
'total_ttc'] - $objectInfos[
'total_ht']),
'MT');
1238 $total_vat += $amount;
1239 $total_check -= $amount;
1243 $result = $bookkeepingToCreate->createFromValues($payment[
"date"], $objectInfos[
'ref'],
'bank', $bid, 0, $accountancy_code, $accountingAccountInfos[
'label'], $langs->trans(
'VAT').
' '.
price($vat_infos[
'tva_tx']).
'%'.$label_suffix, -$amount, $journal, $journal_label,
'');
1247 if (!empty($bookkeepingToCreate->warnings)) {
1248 setEventMessages(
null, $bookkeepingToCreate->warnings,
'warnings');
1250 if (!empty($bookkeepingToCreate->errors)) {
1251 setEventMessages(
null, $bookkeepingToCreate->errors,
'errors');
1260 if ($object_data[
'amount'] < 0) {
1261 $amount = (float)
price2num($object_data[
'amount'],
'MT');
1262 $total_check += $amount;
1266 $result = $bookkeepingToCreate->createFromValues($payment[
"date"], $objectInfos[
'ref'],
'bank', $bid, 0, $accountInfos[
'account_number'], $tabaccountingaccount[$accountInfos[
'account_number']][
'label'], $accountInfos[
'account_ref'].$label_suffix, $amount, $journal, $journal_label,
'');
1270 if (!empty($bookkeepingToCreate->warnings)) {
1271 setEventMessages(
null, $bookkeepingToCreate->warnings,
'warnings');
1273 if (!empty($bookkeepingToCreate->errors)) {
1274 setEventMessages(
null, $bookkeepingToCreate->errors,
'errors');
1279 $total_check =
price2num($total_check,
'MT');
1280 if (!empty($total_check)) {
1282 setEventMessages($langs->trans(
'ErrorBookkeepingTryInsertNotBalancedTransactionAndCanceled', $objectInfos[
'ref'], $object_data[
'bu_url_id']),
null,
'errors');
1285 if ($errorforline) {
1288 if ($error >= $MAXNBERRORS) {
1294 if (!$errorforline) {
1301 if ($error >= $MAXNBERRORS) {
1302 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped").
' (>'.$MAXNBERRORS.
')',
null,
'errors');
1308 if (empty($error) && count($tabpay) > 0) {
1309 setEventMessages($langs->trans(
"GeneralLedgerIsWritten"),
null,
'mesgs');
1310 } elseif (count($tabpay) == $error) {
1311 setEventMessages($langs->trans(
"NoNewRecordSaved"),
null,
'warnings');
1313 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
1319 if (count($tabpay) != $error) {
1320 $param =
'id_journal='.$id_journal;
1321 $param .=
'&date_startday='.$date_startday;
1322 $param .=
'&date_startmonth='.$date_startmonth;
1323 $param .=
'&date_startyear='.$date_startyear;
1324 $param .=
'&date_endday='.$date_endday;
1325 $param .=
'&date_endmonth='.$date_endmonth;
1326 $param .=
'&date_endyear='.$date_endyear;
1327 $param .=
'&in_bookkeeping='.$in_bookkeeping;
1328 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?' . $param);
1338$form =
new Form($db);
1341if (empty($action) || $action ==
'view') {
1342 llxHeader(
'', $langs->trans(
"FinanceJournal"));
1344 $nom = $langs->trans(
"FinanceJournal").
' | '.$accountingjournalstatic->getNomUrl(0, 1, 1,
'', 1);
1347 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
1349 $listofchoices = array(
1350 'notyet' => $langs->trans(
"NotYetInGeneralLedger"),
1351 'already' => $langs->trans(
"AlreadyInGeneralLedger")
1353 $period = $form->selectDate($date_start ?: -1,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end ?: -1,
'date_end', 0, 0, 0,
'', 1, 0);
1354 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
1356 $varlink =
'id_journal='.$id_journal;
1360 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
1363 $sql =
"SELECT COUNT(rowid) as nb FROM ".$db->prefix().
"bank_account WHERE fk_accountancy_journal IS NULL AND clos = 0";
1364 $resql = $db->query($sql);
1366 $obj = $db->fetch_object($resql);
1368 print
'<br>'.img_warning().
' '.$langs->trans(
"TheJournalCodeIsNotDefinedOnSomeBankAccount");
1369 print
' : '.$langs->trans(
"AccountancyAreaDescBank", 9,
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"BankAccounts").
'</strong>');
1372 dol_print_error($db);
1379 print
'<br>'.img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
1380 print
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>');
1383 print
'<br><div class="tabsAction tabsActionNoBottom centerimp">';
1386 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
1392 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
1394 if ($in_bookkeeping ==
'notyet') {
1395 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
1397 print
'<a class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
1404 <script type="text/javascript">
1405 function writebookkeeping() {
1406 console.log("Set value into form and submit");
1407 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
1408 $("div.fiche form input[type=\"submit\"]").click();
1409 $("div.fiche form input[name=\"action\"]").val("");
1419 print
'<div class="div-table-responsive">';
1420 print
'<table class="noborder centpercent">';
1421 print
'<tr class="liste_titre">';
1422 print
"<td>".$langs->trans(
"Date").
"</td>";
1423 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"ObjectsRef").
')</td>';
1424 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
1425 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
1426 print
'<td class="center">'.$langs->trans(
"PaymentMode").
"</td>";
1427 print
'<td class="right">'.$langs->trans(
"AccountingDebit").
"</td>";
1428 print
'<td class="right">'.$langs->trans(
"AccountingCredit").
"</td>";
1431 foreach ($tabpay as $bid => $payment) {
1432 $accountInfos = $tabaccount[$payment[
"fk_bank_account"]];
1436 foreach ($payment[
'objects'] as $object_key => $object_data) {
1437 $objectInfos = $tabobject[$object_key];
1439 $label_suffix = (count($payment[
'objects']) > 1 ?
' - '.$objectInfos[
'ref'] :
'');
1442 if ($object_data[
'amount'] >= 0) {
1443 FormAccounting::printJournalLine($langs, $date, $objectInfos[
'url'], $accountInfos[
'account_number'], $accountInfos[
'account_ref'].$label_suffix, $payment[
'type_payment'], $object_data[
'amount']);
1447 $payment_total_vat = (float)
price2num($object_data[
'amount'] * ($objectInfos[
'total_ttc'] - $objectInfos[
'total_ht']) / $objectInfos[
'total_ttc'],
'MT');
1448 $payment_total_ht = $object_data[
'amount'] - $payment_total_vat;
1449 $total_operation = 0;
1451 $nb_operation = count($objectInfos[
'operations']);
1452 foreach ($objectInfos[
'operations'] as $accountancy_code => $operation) {
1454 if (!isset($tabaccountingaccount[$accountancy_code])) {
1455 $result = $accountingaccount->fetch(0, $accountancy_code,
true);
1456 $tabaccountingaccount[$accountancy_code] = array(
1457 'label' => $result < 0 ? $accountingaccount->errorsToString() : ($result > 0 ? $accountingaccount->label : $langs->trans(
'NotDefined')),
1460 $accountingAccountInfos = $tabaccountingaccount[$accountancy_code];
1461 if (!empty($operation[
'total_ht'])) {
1462 if ($idx < $nb_operation) {
1463 $value =
price2num($payment_total_ht * $operation[
'total_ht'] / $objectInfos[
'total_ht'],
'MT');
1464 $total_operation += (float) $value;
1466 $value = $payment_total_ht - $total_operation;
1468 FormAccounting::printJournalLine($langs, $date, $objectInfos[
'url'], (
string) $accountancy_code, (!empty($operation[
'label']) ? $operation[
'label'] : $accountingAccountInfos[
'label']).$label_suffix, $payment[
'type_payment'], - (float) $value);
1477 foreach ($objectInfos[
'vats'] as $accountancy_code => $vats) {
1478 foreach ($vats as $vat_tx => $vat_infos) {
1482 foreach ($objectInfos[
'vats'] as $accountancy_code => $vats) {
1483 foreach ($vats as $vat_tx => $vat_infos) {
1484 $amount_vat = $vat_infos[
'total_tva'] + $vat_infos[
'total_localtax1'] + $vat_infos[
'total_localtax2'];
1485 if (!empty($amount_vat)) {
1486 $amount_vat = (float)
price2num($payment_total_vat * $amount_vat / ($objectInfos[
'total_ttc'] - $objectInfos[
'total_ht']),
'MT');
1487 $total_vat += $amount_vat;
1488 FormAccounting::printJournalLine($langs, $date, $objectInfos[
'url'], $accountancy_code, $langs->trans(
'VAT').
' '.
price($vat_infos[
'tva_tx']).
'%'.$label_suffix, $payment[
'type_payment'], -$amount_vat);
1495 if ($object_data[
'amount'] < 0) {
1496 FormAccounting::printJournalLine($langs, $date, $objectInfos[
'url'], $accountInfos[
'account_number'], $accountInfos[
'account_ref'].$label_suffix, $payment[
'type_payment'], $object_data[
'amount']);
1503 print
'<tr class="oddeven"><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
journalHead($nom, $variant, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='', $moreoptions=array())
Show header of a page used to transfer/dispatch data in accounting.
getDefaultDatesForTransfer()
Return Default dates for transfer based on periodicity option in accountancy setup.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage bank accounts.
Class to manage bank transaction lines.
Class to manage accounting accounts.
Class to manage accounting journals.
Class to manage Ledger (General Ledger and Subledger)
Class for managing the social charges.
const TYPE_SITUATION
Situation invoice.
Class to manage donations.
Class to manage Trips and Expenses.
Class to manage suppliers invoices.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
const TYPE_REPLACEMENT
Replacement invoice.
Class to manage invoices.
const TYPE_REPLACEMENT
Replacement invoice.
const TYPE_SITUATION
Situation invoice.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage payments of salaries.
Class to manage various payments.
Class to manage subscriptions of foundation members.
Class to manage VAT - Value-added tax (also known in French as TVA)
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
getTaxesFromId($vatrate, $buyer=null, $seller=null, $firstparamisid=1)
Get tax (VAT) main information from Id.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
loanChargeLabel($charge_type, $outputlangs)
Label of the charge of a loan (Insurance, Account-keeping fee, Other fee).
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
payment_filter($v)
Filter for payment.