34require
'../../main.inc.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
45require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
52$langs->loadLangs(array(
"companies",
"other",
"compta",
"banks",
"bills",
"donations",
"loan",
"accountancy",
"trips",
"salaries",
"hrm",
"members"));
57$date_startmonth =
GETPOSTINT(
'date_startmonth');
63$in_bookkeeping =
GETPOST(
'in_bookkeeping',
'aZ09');
66if ($only_rappro == 0) {
73$action =
GETPOST(
'action',
'aZ09');
75if ($in_bookkeeping ==
'') {
76 $in_bookkeeping =
'notyet';
83if ($user->socid > 0) {
86if (!$user->hasRight(
'accounting',
'bind',
'write')) {
98$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
101$pastmonthyear =
null;
103if (empty($date_startmonth)) {
107 $pastmonthyear = $dates[
'pastmonthyear'];
108 $pastmonth = $dates[
'pastmonth'];
110if (empty($date_endmonth)) {
113 $date_end = $dates[
'date_end'];
114 $pastmonthyear = $dates[
'pastmonthyear'];
115 $pastmonth = $dates[
'pastmonth'];
118if (!
GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end))) {
120 $date_end =
dol_get_last_day((
int) $pastmonthyear, (
int) $pastmonth,
false);
125$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,";
126$sql .=
" ba.courant, ba.ref as baref, ba.account_number, ba.fk_accountancy_journal,";
127$sql .=
" bu.type as bu_type";
128$sql .=
" FROM ".$db->prefix().
"bank as b";
129$sql .=
" JOIN ".$db->prefix().
"bank_account as ba on b.fk_account = ba.rowid";
130$sql .=
" LEFT JOIN ".$db->prefix().
"bank_url as bu ON bu.fk_bank = b.rowid";
131$sql .=
" WHERE ba.fk_accountancy_journal = ".((int) $id_journal);
132$sql .=
" AND b.amount <> 0 AND ba.entity IN (".getEntity(
'bank_account').
")";
133if ($date_start && $date_end) {
134 $sql .=
" AND b.dateo >= '".$db->idate($date_start).
"' AND b.dateo <= '".
$db->idate($date_end).
"'";
138 $sql .=
" AND b.dateo >= '".$db->idate(
getDolGlobalInt(
'ACCOUNTING_DATE_START_BINDING')).
"'";
141if ($in_bookkeeping ==
'already') {
142 $sql .=
" AND (b.rowid IN (SELECT fk_doc FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
144if ($in_bookkeeping ==
'notyet') {
145 $sql .=
" AND (b.rowid NOT IN (SELECT fk_doc FROM ".$db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
147if ($only_rappro == 2) {
148 $sql .=
" AND (b.rappro = '1')";
150$sql .=
" ORDER BY b.dateo";
153$result_lines = array();
156$payment_ids = array();
158$tabaccount = array();
160$tabaccountingaccount = array();
161$tabvatdata = array();
163dol_syslog(
"accountancy/journal/treasuryjournal.php", LOG_DEBUG);
164$resql =
$db->query($sql);
166 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
169 while ($obj =
$db->fetch_object($resql)) {
171 if (!isset($tabpay[$obj->rowid])) {
172 $tabpay[$obj->rowid] = array(
174 'date' =>
$db->jdate($obj->do),
175 'type_payment' => $obj->fk_type,
176 'ref' => $obj->label,
177 'fk_bank_account' => $obj->fk_account,
178 'objects' => array(),
181 if (preg_match(
'/^\((.*)\)$/i', $obj->label, $reg)) {
182 $tabpay[$obj->rowid][
"lib"] = $langs->trans($reg[1]);
184 $tabpay[$obj->rowid][
"lib"] =
dol_trunc($obj->label, 60);
187 $payment_ids[$obj->bu_type][$obj->rowid] = $obj->rowid;
190 if (!isset($tabaccount[$obj->fk_account])) {
191 $static_account->id = $obj->fk_account;
192 $static_account->ref = $obj->baref;
193 $tabaccount[$obj->fk_account] = [
194 'id' => $obj->fk_account,
195 'account_ref' => $obj->baref,
196 'account_number' => $obj->account_number,
197 'url' => $static_account->getNomUrl(1),
203 foreach ($payment_ids as $type => $ids) {
206 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
210 $sql =
"SELECT f.rowid, f.ref AS ref, f.total_ht AS invoice_total_ht, f.total_ttc AS invoice_total_ttc,";
211 $sql .=
" pf.amount AS amount_payment,";
212 $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,";
213 $sql .=
" aa.account_number as accountancy_code, aa.label as accountancy_code_label,";
214 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
215 $sql .=
" FROM ".$db->prefix().
"facturedet as fd";
216 $sql .=
" INNER JOIN ".$db->prefix().
"facture as f ON f.rowid = fd.fk_facture";
217 $sql .=
" INNER JOIN ".$db->prefix().
"paiement_facture as pf ON pf.fk_facture = f.rowid";
218 $sql .=
" INNER JOIN ".$db->prefix().
"bank_url as bu ON bu.url_id = pf.fk_paiement AND bu.type = '".
$db->escape($type).
"'";
219 $sql .=
" LEFT JOIN ".$db->prefix().
"product as p ON p.rowid = fd.fk_product";
220 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
222 if ($in_bookkeeping ==
'already') {
223 $sql .=
" INNER JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=f.rowid";
225 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=f.rowid";
227 $sql .=
" WHERE f.entity IN (".getEntity(
'facture', 0).
')';
229 if ($in_bookkeeping ==
'notyet') {
230 $sql .=
" AND ab.rowid IS NULL";
232 $sql .=
" AND fd.fk_code_ventilation > 0";
233 $sql .=
" AND f.fk_statut > 0";
234 $sql .=
" AND fd.product_type IN (0,1)";
236 $sql .=
" AND bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
238 $sql .=
" ORDER BY aa.account_number";
240 $resql =
$db->query($sql);
242 $langs->load(
"bills");
244 $already_sum = array();
247 while ($obj =
$db->fetch_object($resql)) {
248 $object_key = $obj->bu_type.
'_'.$obj->rowid;
254 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
255 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
256 'amount' => $obj->amount_payment,
257 'bu_url_id' => $obj->bu_url_id,
261 if (isset($already_sum[$obj->row_id])) {
264 $already_sum[$obj->row_id] = $obj->row_id;
267 if (!isset($tabobject[$object_key])) {
268 $static_invoice->id = $obj->rowid;
269 $static_invoice->ref = $obj->ref;
270 $tabobject[$object_key] = array(
273 'total_ht' => $obj->invoice_total_ht,
274 'total_ttc' => $obj->invoice_total_ttc,
275 'url' => $static_invoice->getNomUrl(1),
276 'operations' => array(),
282 if (!isset($tabaccountingaccount[$obj->accountancy_code])) {
283 $tabaccountingaccount[$obj->accountancy_code] = array(
284 'label' => !empty($obj->accountancy_code_label) ? $obj->accountancy_code_label : $langs->trans(
'NotDefined'),
289 if (!isset($tabobject[$object_key][
'operations'][$obj->accountancy_code])) {
290 $tabobject[$object_key][
'operations'][$obj->accountancy_code] = array(
294 $tabobject[$object_key][
'operations'][$obj->accountancy_code][
'total_ht'] += $obj->total_ht;
296 if ($obj->total_tva + $obj->total_localtax1 + $obj->total_localtax2 != 0) {
298 if (!isset($tabvatdata[$obj->tva_tx][$obj->vat_src_code])) {
299 $tabvatdata[$obj->tva_tx][$obj->vat_src_code] =
getTaxesFromId($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''),
$mysoc,
$mysoc, 0);
301 $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);
304 if (!isset($tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx])) {
305 $tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx] = array(
306 'tva_tx' => $obj->tva_tx,
308 'total_localtax1' => 0,
309 'total_localtax2' => 0,
312 $tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx][
'total_tva'] += $obj->total_tva;
313 $tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx][
'total_localtax1'] += $obj->total_localtax1;
314 $tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx][
'total_localtax2'] += $obj->total_localtax2;
321 case 'payment_supplier':
322 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
326 $sql =
"SELECT ff.rowid, ff.ref, ff.total_ht AS supplier_invoice_total_ht, ff.total_ttc AS supplier_invoice_total_ttc,";
327 $sql .=
" pff.amount AS amount_payment,";
328 $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,";
329 $sql .=
" aa.account_number as accountancy_code, aa.label as accountancy_code_label,";
330 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
331 $sql .=
" FROM ".$db->prefix().
"facture_fourn_det as ffd";
332 $sql .=
" INNER JOIN ".$db->prefix().
"facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
333 $sql .=
" INNER JOIN ".$db->prefix().
"paiementfourn_facturefourn as pff ON pff.fk_facturefourn = ff.rowid";
334 $sql .=
" INNER JOIN ".$db->prefix().
"bank_url as bu ON bu.url_id = pff.fk_paiementfourn AND bu.type = '".
$db->escape($type).
"'";
335 $sql .=
" LEFT JOIN ".$db->prefix().
"product as p ON p.rowid = ffd.fk_product";
336 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_account as aa ON aa.rowid = ffd.fk_code_ventilation";
338 if ($in_bookkeeping ==
'already') {
339 $sql .=
" INNER JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=ff.rowid";
341 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=ff.rowid";
343 $sql .=
" WHERE ff.entity IN (".getEntity(
'facture_fourn', 0).
')';
345 if ($in_bookkeeping ==
'notyet') {
346 $sql .=
" AND ab.rowid IS NULL";
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;
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,";
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";
452 if ($in_bookkeeping ==
'already') {
453 $sql .=
" INNER JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=er.rowid";
455 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=er.rowid";
457 $sql .=
" WHERE er.entity IN (".getEntity(
'expensereport', 0).
')';
459 if ($in_bookkeeping ==
'notyet') {
460 $sql .=
" AND ab.rowid IS NULL";
462 $sql .=
" AND er.fk_statut >= ".ExpenseReport::STATUS_APPROVED;
463 $sql .=
" AND bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
465 $sql .=
" ORDER BY aa.account_number";
467 $resql =
$db->query($sql);
469 $langs->load(
"trips");
471 $already_sum = array();
474 while ($obj =
$db->fetch_object($resql)) {
475 $object_key = $obj->bu_type.
'_'.$obj->rowid;
478 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
479 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
480 'amount' => -$obj->amount_payment,
481 'bu_url_id' => $obj->bu_url_id,
485 if (isset($already_sum[$obj->row_id])) {
488 $already_sum[$obj->row_id] = $obj->row_id;
491 if (!isset($tabobject[$object_key])) {
492 $static_expense_report->id = $obj->rowid;
493 $static_expense_report->ref = $obj->ref;
494 $tabobject[$object_key] = array(
497 'total_ht' => -$obj->expense_report_total_ht,
498 'total_ttc' => -$obj->expense_report_total_ttc,
499 'url' => $static_expense_report->getNomUrl(1),
500 'operations' => array(),
506 $accountancy_code = !empty($obj->accountancy_code) ? $obj->accountancy_code :
'NotDefined';
507 if (!isset($tabaccountingaccount[$accountancy_code])) {
508 $tabaccountingaccount[$accountancy_code] = array(
509 'label' => !empty($obj->accountancy_code_label) ? $obj->accountancy_code_label : $langs->trans(
'NotDefined'),
514 if (!isset($tabobject[$object_key][
'operations'][$accountancy_code])) {
515 $tabobject[$object_key][
'operations'][$accountancy_code] = array(
519 $tabobject[$object_key][
'operations'][$accountancy_code][
'total_ht'] -= $obj->total_ht;
521 if ($obj->total_tva + $obj->total_localtax1 + $obj->total_localtax2 != 0) {
523 if (!isset($tabvatdata[$obj->tva_tx][$obj->vat_src_code])) {
524 $tabvatdata[$obj->tva_tx][$obj->vat_src_code] =
getTaxesFromId($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''),
$mysoc,
$mysoc, 0);
526 $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);
529 if (!isset($tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx])) {
530 $tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx] = array(
531 'tva_tx' => $obj->tva_tx,
533 'total_localtax1' => 0,
534 'total_localtax2' => 0,
537 $tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx][
'total_tva'] -= $obj->total_tva;
538 $tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx][
'total_localtax1'] -= $obj->total_localtax1;
539 $tabobject[$object_key][
'vats'][$compta_tva][$obj->tva_tx][
'total_localtax2'] -= $obj->total_localtax2;
546 case 'payment_salary':
549 $sql =
"SELECT ps.rowid,";
550 $sql .=
" ps.amount AS amount_payment, ps.label AS label,";
551 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
552 $sql .=
" FROM ".$db->prefix().
"payment_salary as ps";
553 $sql .=
" INNER JOIN ".$db->prefix().
"bank_url as bu ON bu.url_id = ps.rowid AND bu.type = '".
$db->escape($type).
"'";
555 if ($in_bookkeeping ==
'already') {
556 $sql .=
" INNER JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=ps.rowid";
558 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=ps.rowid";
560 $sql .=
" WHERE ps.entity IN (".getEntity(
'user', 0).
')';
562 if ($in_bookkeeping ==
'notyet') {
563 $sql .=
" AND ab.rowid IS NULL";
565 $sql .=
" AND bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
567 $resql =
$db->query($sql);
569 require_once DOL_DOCUMENT_ROOT.
'/salaries/class/paymentsalary.class.php';
570 $langs->load(
"salaries");
572 $account_employee =
getDolGlobalString(
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT',
'NotDefined');
575 while ($obj =
$db->fetch_object($resql)) {
576 $object_key = $obj->bu_type.
'_'.$obj->rowid;
579 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
580 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
581 'amount' => -$obj->amount_payment,
582 'bu_url_id' => $obj->bu_url_id,
587 if (!isset($tabobject[$object_key])) {
588 $static_payment_salary->id = $obj->rowid;
589 $static_payment_salary->ref = $prefix_ref.$obj->rowid;
590 $tabobject[$object_key] = array(
592 'ref' => $prefix_ref.$obj->rowid,
593 'total_ht' => -$obj->amount_payment,
594 'total_ttc' => -$obj->amount_payment,
595 'url' => $static_payment_salary->getNomUrl(1),
596 'operations' => array(),
602 $tabobject[$object_key][
'operations'][$account_employee] = array(
603 'total_ht' => -$obj->amount_payment,
604 'label' => $obj->label,
614 $sql =
"SELECT cs.rowid, cs.ref, cs.libelle AS label, cs.amount AS sociales_contributions_amount,";
615 $sql .=
" pc.amount AS amount_payment,";
616 $sql .=
" ccs.accountancy_code,";
617 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
618 $sql .=
" FROM ".$db->prefix().
"paiementcharge as pc";
619 $sql .=
" INNER JOIN ".$db->prefix().
"bank_url as bu ON bu.url_id = pc.rowid AND bu.type = '".
$db->escape($type).
"'";
620 $sql .=
" INNER JOIN ".$db->prefix().
"chargesociales AS cs ON cs.rowid = pc.fk_charge";
621 $sql .=
" LEFT JOIN ".$db->prefix().
"c_chargesociales as ccs ON ccs.id = cs.fk_type";
623 if ($in_bookkeeping ==
'already') {
624 $sql .=
" INNER JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=cs.rowid";
626 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=cs.rowid";
628 $sql .=
" WHERE cs.entity = ".((int)
$conf->entity);
630 if ($in_bookkeeping ==
'notyet') {
631 $sql .=
" AND ab.rowid IS NULL";
633 $sql .=
" AND bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
635 $resql =
$db->query($sql);
637 require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
639 $langs->load(
"bills");
641 $prefix_ref =
getDolGlobalString(
'MAIN_PAYMENT_SOCIALES_CONTRIBUTIONS_REF_PREFIX',
'SC');
643 while ($obj =
$db->fetch_object($resql)) {
644 $object_key = $obj->bu_type.
'_'.$obj->rowid;
647 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
648 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
649 'amount' => -$obj->amount_payment,
650 'bu_url_id' => $obj->bu_url_id,
655 if (!isset($tabobject[$object_key])) {
656 $static_sociales_contributions->id = $obj->rowid;
657 $static_sociales_contributions->ref = $prefix_ref.$obj->rowid;
658 $tabobject[$object_key] = array(
660 'ref' => $prefix_ref.$obj->rowid,
661 'total_ht' => -$obj->sociales_contributions_amount,
662 'total_ttc' => -$obj->sociales_contributions_amount,
663 'url' => $static_sociales_contributions->getNomUrl(1),
664 'operations' => array(),
669 $accountancy_code = !empty($obj->accountancy_code) ? $obj->accountancy_code :
'NotDefined';
672 $tabobject[$object_key][
'operations'][$accountancy_code] = array(
673 'total_ht' => -$obj->sociales_contributions_amount,
674 'label' => $obj->label,
685 $sql =
"SELECT pv.rowid, t.rowid AS tva_id,";
686 $sql .=
" pv.amount AS amount_payment, t.label AS label,";
687 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
688 $sql .=
" FROM ".$db->prefix().
"payment_vat as pv";
689 $sql .=
" INNER JOIN ".$db->prefix().
"tva as t ON t.rowid = pv.fk_tva";
690 $sql .=
" INNER JOIN ".$db->prefix().
"bank_url as bu ON bu.url_id = pv.rowid AND bu.type = '".
$db->escape($type).
"'";
692 if ($in_bookkeeping ==
'already') {
693 $sql .=
" INNER JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=t.rowid";
695 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=t.rowid";
697 $sql .=
" WHERE bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
700 if ($in_bookkeeping ==
'notyet') {
701 $sql .=
" AND ab.rowid IS NULL";
704 $resql =
$db->query($sql);
706 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
708 $langs->load(
"salaries");
709 $static_tva =
new Tva(
$db);
713 while ($obj =
$db->fetch_object($resql)) {
714 $object_key = $obj->bu_type.
'_'.$obj->rowid;
717 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
718 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
719 'amount' => -$obj->amount_payment,
720 'bu_url_id' => $obj->bu_url_id,
725 if (!isset($tabobject[$object_key])) {
726 $static_tva->id = $obj->tva_id;
727 $static_tva->ref = $prefix_ref.$obj->tva_id;
728 $tabobject[$object_key] = array(
729 'id' => $obj->tva_id,
730 'ref' => $prefix_ref.$obj->tva_id,
731 'total_ht' => -$obj->amount_payment,
732 'total_ttc' => -$obj->amount_payment,
733 'url' => $static_tva->getNomUrl(1),
734 'operations' => array(),
740 $tabobject[$object_key][
'operations'][$account_pay_vat] = array(
741 'total_ht' => -$obj->amount_payment,
742 'label' => $obj->label,
749 case 'payment_donation':
752 $sql =
"SELECT d.rowid, d.amount AS don_amount,";
753 $sql .=
" pd.amount AS amount_payment,";
754 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
755 $sql .=
" FROM ".$db->prefix().
"payment_donation as pd";
756 $sql .=
" INNER JOIN ".$db->prefix().
"don as d ON pd.fk_donation = d.rowid";
757 $sql .=
" INNER JOIN ".$db->prefix().
"bank_url as bu ON bu.url_id = pd.rowid AND bu.type = '".
$db->escape($type).
"'";
759 if ($in_bookkeeping ==
'already') {
760 $sql .=
" INNER JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=d.rowid";
762 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=d.rowid";
764 $sql .=
" WHERE d.entity IN (".getEntity(
'donation', 0).
')';
766 if ($in_bookkeeping ==
'notyet') {
767 $sql .=
" AND ab.rowid IS NULL";
769 $sql .=
" AND bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
771 $resql =
$db->query($sql);
773 require_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
775 $langs->load(
"donations");
776 $static_don =
new Don(
$db);
777 $account_pay_donation =
getDolGlobalString(
'DONATION_ACCOUNTINGACCOUNT',
'NotDefined');
780 while ($obj =
$db->fetch_object($resql)) {
781 $object_key = $obj->bu_type.
'_'.$obj->rowid;
784 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
785 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
786 'amount' => $obj->amount_payment,
787 'bu_url_id' => $obj->bu_url_id,
792 if (!isset($tabobject[$object_key])) {
793 $static_don->id = $obj->rowid;
794 $static_don->ref = $prefix_ref.$obj->rowid;
795 $tabobject[$object_key] = array(
797 'ref' => $prefix_ref.$obj->rowid,
798 'total_ht' => $obj->don_amount,
799 'total_ttc' => $obj->don_amount,
800 'url' => $static_don->getNomUrl(1),
801 'operations' => array(),
807 $tabobject[$object_key][
'operations'][$account_pay_donation] = array(
808 'total_ht' => $obj->don_amount,
809 'label' => $langs->trans(
'Donation').
' '.$prefix_ref.$obj->rowid,
819 $sql =
"SELECT l.rowid, l.capital AS loan_capital, l.accountancy_account_capital, l.accountancy_account_interest, l.accountancy_account_insurance, l.label,";
820 $sql .=
" pl.amount_capital, pl.rowid as payment_id, pl.amount_interest, pl.amount_insurance,";
821 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
822 $sql .=
" FROM ".$db->prefix().
"payment_loan as pl";
823 $sql .=
" INNER JOIN ".$db->prefix().
"loan as l ON pl.fk_loan = l.rowid";
824 $sql .=
" INNER JOIN ".$db->prefix().
"bank_url as bu ON bu.url_id = pl.rowid AND bu.type = '".
$db->escape($type).
"'";
826 if ($in_bookkeeping ==
'already') {
827 $sql .=
" INNER JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=l.rowid";
829 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=l.rowid";
831 $sql .=
" WHERE l.entity = ".((int)
$conf->entity);
833 if ($in_bookkeeping ==
'notyet') {
834 $sql .=
" AND ab.rowid IS NULL";
836 $sql .=
" AND bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
838 $resql =
$db->query($sql);
840 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
842 $langs->load(
"loan");
844 $account_pay_loan_capital =
getDolGlobalString(
'LOAN_ACCOUNTING_ACCOUNT_CAPITAL',
'NotDefined');
845 $account_pay_loan_interest =
getDolGlobalString(
'LOAN_ACCOUNTING_ACCOUNT_INTEREST',
'NotDefined');
846 $account_pay_loan_insurance =
getDolGlobalString(
'LOAN_ACCOUNTING_ACCOUNT_INSURANCE',
'NotDefined');
849 while ($obj =
$db->fetch_object($resql)) {
850 $object_key = $obj->bu_type.
'_'.$obj->payment_id;
853 $payment_amount = $obj->amount_capital + $obj->amount_interest + $obj->amount_insurance;
854 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
855 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
856 'amount' => -$payment_amount,
857 'bu_url_id' => $obj->bu_url_id,
862 if (!isset($tabobject[$object_key])) {
863 $static_loan->id = $obj->rowid;
864 $static_loan->ref = $prefix_ref.$obj->rowid;
865 $tabobject[$object_key] = array(
867 'ref' => $prefix_ref.$obj->rowid,
868 'total_ht' => -$obj->loan_capital,
869 'total_ttc' => -$obj->loan_capital,
870 'url' => $static_loan->getNomUrl(1),
871 'operations' => array(),
877 $accountancy_account_capital = !empty($obj->accountancy_account_capital) ? $obj->accountancy_account_capital : $account_pay_loan_capital;
878 $tabobject[$object_key][
'operations'][$accountancy_account_capital] = array(
880 'total_ht' => -($obj->loan_capital * $obj->amount_capital / $payment_amount),
881 'label' => $obj->label.
' '.$langs->trans(
'LoanCapital'),
885 $accountancy_account_interest = !empty($obj->accountancy_account_interest) ? $obj->accountancy_account_interest : $account_pay_loan_interest;
886 $tabobject[$object_key][
'operations'][$accountancy_account_interest] = array(
888 'total_ht' => -($obj->loan_capital * $obj->amount_interest / $payment_amount),
889 'label' => $obj->label.
' '.$langs->trans(
'Interest'),
895 $accountancy_account_insurance = !empty($obj->accountancy_account_insurance) ? $obj->accountancy_account_insurance : $account_pay_loan_insurance;
896 $tabobject[$object_key][
'operations'][$accountancy_account_insurance] = array(
898 'total_ht' => -($obj->loan_capital * $obj->amount_insurance / $payment_amount),
899 'label' => $obj->label.
' '.$langs->trans(
'Insurance'),
906 case 'payment_various':
909 $sql =
"SELECT pv.rowid,";
910 $sql .=
" pv.sens AS sens_payment, pv.amount AS amount_payment, pv.label, pv.accountancy_code,";
911 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
912 $sql .=
" FROM ".$db->prefix().
"payment_various as pv";
913 $sql .=
" INNER JOIN ".$db->prefix().
"bank_url as bu ON bu.url_id = pv.rowid AND bu.type = '".
$db->escape($type).
"'";
915 if ($in_bookkeeping ==
'already') {
916 $sql .=
" INNER JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=pv.rowid";
918 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=pv.rowid";
920 $sql .=
" WHERE pv.entity IN (".getEntity(
'payment_various', 0).
')';
921 $sql .=
" AND bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
923 if ($in_bookkeeping ==
'notyet') {
924 $sql .=
" AND ab.rowid IS NULL";
927 $resql =
$db->query($sql);
929 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
934 while ($obj =
$db->fetch_object($resql)) {
935 $object_key = $obj->bu_type.
'_'.$obj->rowid;
937 $payment_amount = (empty($obj->sens_payment) ? -1 : 1) * $obj->amount_payment;
939 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
940 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
941 'amount' => $payment_amount,
942 'bu_url_id' => $obj->bu_url_id,
947 if (!isset($tabobject[$object_key])) {
948 $static_payment_various->id = $obj->rowid;
949 $static_payment_various->ref = $prefix_ref.$obj->rowid;
950 $tabobject[$object_key] = array(
952 'ref' => $prefix_ref.$obj->rowid,
953 'total_ht' => $payment_amount,
954 'total_ttc' => $payment_amount,
955 'url' => $static_payment_various->getNomUrl(1),
956 'operations' => array(),
962 $accountancy_code = !empty($obj->accountancy_code) ? $obj->accountancy_code :
'NotDefined';
963 $tabobject[$object_key][
'operations'][$obj->accountancy_code] = array(
964 'total_ht' => $payment_amount,
965 'label' => $obj->label,
975 $sql =
"SELECT su.rowid,";
976 $sql .=
" su.subscription AS amount_payment, su.note AS label,";
977 $sql .=
" adh.lastname, adh.firstname,";
978 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
979 $sql .=
" FROM ".$db->prefix().
"subscription as su";
980 $sql .=
" INNER JOIN ".$db->prefix().
"adherent as adh ON adh.rowid = su.fk_adherent";
981 $sql .=
" INNER JOIN ".$db->prefix().
"bank_url as bu ON bu.fk_bank = su.fk_bank AND bu.type = '".
$db->escape($type).
"'";
983 if ($in_bookkeeping ==
'already') {
984 $sql .=
" INNER JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=su.rowid";
986 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=su.rowid";
988 $sql .=
" WHERE bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
990 if ($in_bookkeeping ==
'notyet') {
991 $sql .=
" AND ab.rowid IS NULL";
994 $resql =
$db->query($sql);
996 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
998 $langs->load(
"members");
1000 $account_subscription =
getDolGlobalString(
'ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT',
'NotDefined');
1003 while ($obj =
$db->fetch_object($resql)) {
1004 $object_key = $obj->bu_type.
'_'.$obj->rowid;
1007 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
1008 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
1009 'amount' => $obj->amount_payment,
1010 'bu_url_id' => $obj->bu_url_id,
1015 if (!isset($tabobject[$object_key])) {
1016 $static_subscription->id = $obj->rowid;
1017 $static_subscription->ref = $prefix_ref.$obj->rowid;
1018 $tabobject[$object_key] = array(
1019 'id' => $obj->rowid,
1020 'ref' => $prefix_ref.$obj->rowid,
1021 'total_ht' => -$obj->amount_payment,
1022 'total_ttc' => -$obj->amount_payment,
1023 'url' => $static_subscription->getNomUrl(1),
1024 'operations' => array(),
1030 $tabobject[$object_key][
'operations'][$account_subscription] = array(
1031 'total_ht' => -$obj->amount_payment,
1032 'label' => $obj->label.
' - '.$obj->lastname.
' '.$obj->firstname,
1039 case 'banktransfert':
1042 $sql =
"SELECT b.rowid, b.amount, b.label,";
1043 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
1044 $sql .=
" FROM ".$db->prefix().
"bank_url as bu";
1045 $sql .=
" INNER JOIN ".$db->prefix().
"bank as b ON bu.url_id = b.rowid";
1046 $sql .=
" LEFT JOIN ".$db->prefix().
"bank_account as ba ON ba.rowid = b.fk_account";
1048 if ($in_bookkeeping ==
'already') {
1049 $sql .=
" INNER JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=b.rowid";
1051 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=b.rowid";
1053 $sql .=
" WHERE ba.entity IN (".getEntity(
'bank_account', 0).
')';
1054 $sql .=
" AND bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
1055 $sql .=
" AND bu.type = '".$db->escape($type).
"'";
1057 if ($in_bookkeeping ==
'notyet') {
1058 $sql .=
" AND ab.rowid IS NULL";
1061 $resql =
$db->query($sql);
1063 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
1066 $account_transfer =
getDolGlobalString(
'ACCOUNTING_ACCOUNT_TRANSFER_CASH',
'NotDefined');
1069 while ($obj =
$db->fetch_object($resql)) {
1070 $object_key = $obj->bu_type.
'_'.$obj->rowid;
1073 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
1074 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
1075 'amount' => -$obj->amount,
1076 'bu_url_id' => $obj->bu_url_id,
1081 if (!isset($tabobject[$object_key])) {
1082 $static_account_line->id = $obj->rowid;
1083 $static_account_line->rowid = $obj->rowid;
1084 $static_account_line->ref = $prefix_ref.$obj->rowid;
1085 $tabobject[$object_key] = array(
1086 'id' => $obj->rowid,
1087 'ref' => $prefix_ref.$obj->rowid,
1088 'total_ht' => -$obj->amount,
1089 'total_ttc' => -$obj->amount,
1090 'url' => $static_account_line->getNomUrl(1),
1091 'operations' => array(),
1097 $tabobject[$object_key][
'operations'][$account_transfer] = array(
1098 'total_ht' => -$obj->amount,
1099 'label' => $obj->label,
1120 return isset($v[
'objects']) && count($v[
'objects']) > 0;
1123$tabpay = array_filter($tabpay,
'payment_filter');
1129$accountingjournalstatic->fetch($id_journal);
1130$journal = $accountingjournalstatic->code;
1131$journal_label = $langs->transnoentitiesnoconv($accountingjournalstatic->label);
1135if ($action ==
'writebookkeeping' ) {
1136 foreach ($tabpay as $payment_id => $payment) {
1137 $accountInfos = $tabaccount[$payment[
"fk_bank_account"]];
1140 if (!isset($tabaccountingaccount[$accountInfos[
'account_number']])) {
1141 $result = $accountingaccount->fetch(0, $accountInfos[
'account_number'],
true);
1143 setEventMessages($accountingaccount->error, $accountingaccount->errors,
'errors');
1147 $tabaccountingaccount[$accountInfos[
'account_number']] = array(
1148 'label' => $result > 0 ? $accountingaccount->label : $langs->trans(
'NotDefined'),
1156 foreach ($payment[
'objects'] as $object_key => $object_data) {
1157 $objectInfos = $tabobject[$object_key];
1159 $label_suffix = (count($payment[
'objects']) > 1 ?
' - '.$objectInfos[
'ref'] :
'');
1164 if ($object_data[
'amount'] >= 0) {
1165 $amount = (float)
price2num($object_data[
'amount'],
'MT');
1166 $total_check += $amount;
1173 $result = $bookkeepingToCreate->createFromValues($payment[
"date"], $objectInfos[
'ref'],
'bank', $payment_id, 0, $accountInfos[
'account_number'], $tabaccountingaccount[$accountInfos[
'account_number']][
'label'], $accountInfos[
'account_ref'].$label_suffix, $amount, $journal, $journal_label,
'');
1178 if (!empty($bookkeepingToCreate->warnings)) {
1181 if (!empty($bookkeepingToCreate->errors)) {
1188 $payment_total_vat = (float)
price2num($object_data[
'amount'] * ($objectInfos[
'total_ttc'] - $objectInfos[
'total_ht']) / $objectInfos[
'total_ttc'],
'MT');
1189 $payment_total_ht = $object_data[
'amount'] - $payment_total_vat;
1190 $total_operation = 0;
1192 $nb_operation = count($objectInfos[
'operations']);
1193 foreach ($objectInfos[
'operations'] as $accountancy_code => $operation) {
1194 if (!empty($operation[
'total_ht'])) {
1196 if (!isset($tabaccountingaccount[$accountancy_code])) {
1197 $result = $accountingaccount->fetch(0, $accountancy_code,
true);
1199 setEventMessages($accountingaccount->error, $accountingaccount->errors,
'errors');
1200 $accountancy_code_label = $accountingaccount->errorsToString();
1202 } elseif ($result > 0) {
1203 $accountancy_code_label = $accountingaccount->label;
1205 $accountancy_code_label = $langs->trans(
'NotDefined');
1207 $tabaccountingaccount[$accountancy_code] = array(
'label' => $accountancy_code_label);
1209 $accountingAccountInfos = $tabaccountingaccount[$accountancy_code];
1210 if ($idx < $nb_operation) {
1211 $amount =
price2num($payment_total_ht * $operation[
'total_ht'] / $objectInfos[
'total_ht'],
'MT');
1212 $total_operation += (float) $amount;
1214 $amount = $payment_total_ht - $total_operation;
1216 $total_check -= (float) $amount;
1220 $result = $bookkeepingToCreate->createFromValues($payment[
"date"], $objectInfos[
'ref'],
'bank', $payment_id, 0, $accountancy_code, $accountingAccountInfos[
'label'], (!empty($operation[
'label']) ? $operation[
'label'] : $accountingAccountInfos[
'label']).$label_suffix, - (float) $amount, $journal, $journal_label,
'');
1224 if (!empty($bookkeepingToCreate->warnings)) {
1227 if (!empty($bookkeepingToCreate->errors)) {
1239 foreach ($objectInfos[
'vats'] as $accountancy_code => $vats) {
1240 foreach ($vats as $vat_tx => $vat_infos) {
1244 foreach ($objectInfos[
'vats'] as $accountancy_code => $vats) {
1245 foreach ($vats as $vat_tx => $vat_infos) {
1246 $amount = $vat_infos[
'total_tva'] + $vat_infos[
'total_localtax1'] + $vat_infos[
'total_localtax2'];
1247 if (!empty($amount)) {
1249 if (!isset($tabaccountingaccount[$accountancy_code])) {
1250 $result = $accountingaccount->fetch(0, $accountancy_code,
true);
1252 setEventMessages($accountingaccount->error, $accountingaccount->errors,
'errors');
1253 $accountancy_code_label = $accountingaccount->errorsToString();
1255 } elseif ($result > 0) {
1256 $accountancy_code_label = $accountingaccount->label;
1258 $accountancy_code_label = $langs->trans(
'NotDefined');
1260 $tabaccountingaccount[$accountancy_code] = array(
'label' => $accountancy_code_label);
1262 $accountingAccountInfos = $tabaccountingaccount[$accountancy_code];
1263 $amount = (float)
price2num($payment_total_vat * $amount / ($objectInfos[
'total_ttc'] - $objectInfos[
'total_ht']),
'MT');
1264 $total_vat += $amount;
1265 $total_check -= $amount;
1269 $result = $bookkeepingToCreate->createFromValues($payment[
"date"], $objectInfos[
'ref'],
'bank', $payment_id, 0, $accountancy_code, $accountingAccountInfos[
'label'], $langs->trans(
'VAT').
' '.
price($vat_infos[
'tva_tx']).
'%'.$label_suffix, -$amount, $journal, $journal_label,
'');
1273 if (!empty($bookkeepingToCreate->warnings)) {
1276 if (!empty($bookkeepingToCreate->errors)) {
1286 if ($object_data[
'amount'] < 0) {
1287 $amount = (float)
price2num($object_data[
'amount'],
'MT');
1288 $total_check += $amount;
1292 $result = $bookkeepingToCreate->createFromValues($payment[
"date"], $objectInfos[
'ref'],
'bank', $payment_id, 0, $accountInfos[
'account_number'], $tabaccountingaccount[$accountInfos[
'account_number']][
'label'], $accountInfos[
'account_ref'].$label_suffix, $amount, $journal, $journal_label,
'');
1296 if (!empty($bookkeepingToCreate->warnings)) {
1299 if (!empty($bookkeepingToCreate->errors)) {
1305 $total_check =
price2num($total_check,
'MT');
1306 if (!empty($total_check)) {
1308 setEventMessages($langs->trans(
'ErrorBookkeepingTryInsertNotBalancedTransactionAndCanceled', $objectInfos[
'ref'], $object_data[
'bu_url_id']),
null,
'errors');
1311 if ($errorforline) {
1314 if ($error >= $MAXNBERRORS) {
1320 if (!$errorforline) {
1327 if ($error >= $MAXNBERRORS) {
1328 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped").
' (>'.$MAXNBERRORS.
')',
null,
'errors');
1334 if (empty($error) && count($tabpay) > 0) {
1336 } elseif (count($tabpay) == $error) {
1339 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
1345 if (count($tabpay) != $error) {
1346 $param =
'id_journal='.$id_journal;
1347 $param .=
'&date_startday='.$date_startday;
1348 $param .=
'&date_startmonth='.$date_startmonth;
1349 $param .=
'&date_startyear='.$date_startyear;
1350 $param .=
'&date_endday='.$date_endday;
1351 $param .=
'&date_endmonth='.$date_endmonth;
1352 $param .=
'&date_endyear='.$date_endyear;
1353 $param .=
'&in_bookkeeping='.$in_bookkeeping;
1354 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?' . $param);
1367if (empty($action) || $action ==
'view') {
1368 llxHeader(
'', $langs->trans(
"FinanceJournal"));
1370 $nom = $langs->trans(
"FinanceJournal").
' | '.$accountingjournalstatic->getNomUrl(0, 1, 1,
'', 1);
1373 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
1375 $listofchoices = array(
1376 'notyet' => $langs->trans(
"NotYetInGeneralLedger"),
1377 'already' => $langs->trans(
"AlreadyInGeneralLedger")
1379 $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);
1380 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
1382 $varlink =
'id_journal='.$id_journal;
1386 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
1389 $sql =
"SELECT COUNT(rowid) as nb FROM ".$db->prefix().
"bank_account WHERE fk_accountancy_journal IS NULL AND clos = 0";
1390 $resql =
$db->query($sql);
1392 $obj =
$db->fetch_object($resql);
1394 print
'<br>'.img_warning().
' '.$langs->trans(
"TheJournalCodeIsNotDefinedOnSomeBankAccount");
1395 print
' : '.$langs->trans(
"AccountancyAreaDescBank", 9,
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"BankAccounts").
'</strong>');
1405 print
'<br>'.img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
1406 print
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>');
1409 print
'<br><div class="tabsAction tabsActionNoBottom centerimp">';
1412 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
1418 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
1420 if ($in_bookkeeping ==
'notyet') {
1421 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
1423 print
'<a class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
1430 <script type="text/javascript">
1431 function writebookkeeping() {
1432 console.log("Set value into form and submit");
1433 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
1434 $("div.fiche form input[type=\"submit\"]").click();
1435 $("div.fiche form input[name=\"action\"]").val("");
1445 print
'<div class="div-table-responsive">';
1446 print
'<table class="noborder centpercent">';
1447 print
'<tr class="liste_titre">';
1448 print
"<td>".$langs->trans(
"Date").
"</td>";
1449 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"ObjectsRef").
')</td>';
1450 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
1451 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
1452 print
'<td class="center">'.$langs->trans(
"PaymentMode").
"</td>";
1453 print
'<td class="right">'.$langs->trans(
"AccountingDebit").
"</td>";
1454 print
'<td class="right">'.$langs->trans(
"AccountingCredit").
"</td>";
1457 foreach ($tabpay as $payment_id => $payment) {
1458 $accountInfos = $tabaccount[$payment[
"fk_bank_account"]];
1462 foreach ($payment[
'objects'] as $object_key => $object_data) {
1463 $objectInfos = $tabobject[$object_key];
1465 $label_suffix = (count($payment[
'objects']) > 1 ?
' - '.$objectInfos[
'ref'] :
'');
1468 if ($object_data[
'amount'] >= 0) {
1469 FormAccounting::printJournalLine($langs, $date, $objectInfos[
'url'], $accountInfos[
'account_number'], $accountInfos[
'account_ref'].$label_suffix, $payment[
'type_payment'], $object_data[
'amount']);
1473 $payment_total_vat = (float)
price2num($object_data[
'amount'] * ($objectInfos[
'total_ttc'] - $objectInfos[
'total_ht']) / $objectInfos[
'total_ttc'],
'MT');
1474 $payment_total_ht = $object_data[
'amount'] - $payment_total_vat;
1475 $total_operation = 0;
1477 $nb_operation = count($objectInfos[
'operations']);
1478 foreach ($objectInfos[
'operations'] as $accountancy_code => $operation) {
1480 if (!isset($tabaccountingaccount[$accountancy_code])) {
1481 $result = $accountingaccount->fetch(0, $accountancy_code,
true);
1482 $tabaccountingaccount[$accountancy_code] = array(
1483 'label' => $result < 0 ? $accountingaccount->errorsToString() : ($result > 0 ? $accountingaccount->label : $langs->trans(
'NotDefined')),
1486 $accountingAccountInfos = $tabaccountingaccount[$accountancy_code];
1487 if (!empty($operation[
'total_ht'])) {
1488 if ($idx < $nb_operation) {
1489 $value =
price2num($payment_total_ht * $operation[
'total_ht'] / $objectInfos[
'total_ht'],
'MT');
1490 $total_operation += (float) $value;
1492 $value = $payment_total_ht - $total_operation;
1494 FormAccounting::printJournalLine($langs, $date, $objectInfos[
'url'], (
string) $accountancy_code, (!empty($operation[
'label']) ? $operation[
'label'] : $accountingAccountInfos[
'label']).$label_suffix, $payment[
'type_payment'], - (float) $value);
1503 foreach ($objectInfos[
'vats'] as $accountancy_code => $vats) {
1504 foreach ($vats as $vat_tx => $vat_infos) {
1508 foreach ($objectInfos[
'vats'] as $accountancy_code => $vats) {
1509 foreach ($vats as $vat_tx => $vat_infos) {
1510 $amount_vat = $vat_infos[
'total_tva'] + $vat_infos[
'total_localtax1'] + $vat_infos[
'total_localtax2'];
1511 if (!empty($amount_vat)) {
1512 $amount_vat = (float)
price2num($payment_total_vat * $amount_vat / ($objectInfos[
'total_ttc'] - $objectInfos[
'total_ht']),
'MT');
1513 $total_vat += $amount_vat;
1514 FormAccounting::printJournalLine($langs, $date, $objectInfos[
'url'], $accountancy_code, $langs->trans(
'VAT').
' '.
price($vat_infos[
'tva_tx']).
'%'.$label_suffix, $payment[
'type_payment'], -$amount_vat);
1521 if ($object_data[
'amount'] < 0) {
1522 FormAccounting::printJournalLine($langs, $date, $objectInfos[
'url'], $accountInfos[
'account_number'], $accountInfos[
'account_ref'].$label_suffix, $payment[
'type_payment'], $object_data[
'amount']);
1529 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.
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
price2num($amount, $rounding='', $option=0)
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_print_error($db=null, $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.
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.
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.