33require
'../../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
36require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
40require_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';
80if (!isModEnabled(
'accounting')) {
83if ($user->socid > 0) {
86if (!$user->hasRight(
'accounting',
'bind',
'write')) {
97$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
98$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
101$pastmonthyear =
null;
103if (empty($date_startmonth)) {
106 $date_start = $dates[
'date_start'];
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';
167 $static_account =
new Account($db);
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");
243 $static_invoice =
new Facture($db);
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 = ".$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,
684 $sql =
"SELECT t.rowid,";
685 $sql .=
" t.amount AS amount_payment, t.label AS label,";
686 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
687 $sql .=
" FROM ".$db->prefix().
"tva as t";
688 $sql .=
" INNER JOIN ".$db->prefix().
"bank_url as bu ON bu.url_id = t.rowid AND bu.type = '".$db->escape($type).
"'";
690 if ($in_bookkeeping ==
'already') {
691 $sql .=
" INNER JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=t.rowid";
693 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=t.rowid";
695 $sql .=
" WHERE bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
698 if ($in_bookkeeping ==
'notyet') {
699 $sql .=
" AND ab.rowid IS NULL";
702 $resql = $db->query($sql);
704 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
706 $langs->load(
"salaries");
707 $static_tva =
new Tva($db);
711 while ($obj = $db->fetch_object($resql)) {
712 $object_key = $obj->bu_type.
'_'.$obj->rowid;
715 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
716 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
717 'amount' => -$obj->amount_payment,
718 'bu_url_id' => $obj->bu_url_id,
723 if (!isset($tabobject[$object_key])) {
724 $static_tva->id = $obj->rowid;
725 $static_tva->ref = $prefix_ref.$obj->rowid;
726 $tabobject[$object_key] = array(
728 'ref' => $prefix_ref.$obj->rowid,
729 'total_ht' => -$obj->amount_payment,
730 'total_ttc' => -$obj->amount_payment,
731 'url' => $static_tva->getNomUrl(1),
732 'operations' => array(),
738 $tabobject[$object_key][
'operations'][$account_pay_vat] = array(
739 'total_ht' => -$obj->amount_payment,
740 'label' => $obj->label,
747 case 'payment_donation':
750 $sql =
"SELECT d.rowid, d.amount AS don_amount,";
751 $sql .=
" pd.amount AS amount_payment,";
752 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
753 $sql .=
" FROM ".$db->prefix().
"payment_donation as pd";
754 $sql .=
" INNER JOIN ".$db->prefix().
"don as d ON pd.fk_donation = d.rowid";
755 $sql .=
" INNER JOIN ".$db->prefix().
"bank_url as bu ON bu.url_id = pd.rowid AND bu.type = '".$db->escape($type).
"'";
757 if ($in_bookkeeping ==
'already') {
758 $sql .=
" INNER JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=d.rowid";
760 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=d.rowid";
762 $sql .=
" WHERE d.entity IN (".getEntity(
'donation', 0).
')';
764 if ($in_bookkeeping ==
'notyet') {
765 $sql .=
" AND ab.rowid IS NULL";
767 $sql .=
" AND bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
769 $resql = $db->query($sql);
771 require_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
773 $langs->load(
"donations");
774 $static_don =
new Don($db);
775 $account_pay_donation =
getDolGlobalString(
'DONATION_ACCOUNTINGACCOUNT',
'NotDefined');
778 while ($obj = $db->fetch_object($resql)) {
779 $object_key = $obj->bu_type.
'_'.$obj->rowid;
782 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
783 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
784 'amount' => $obj->amount_payment,
785 'bu_url_id' => $obj->bu_url_id,
790 if (!isset($tabobject[$object_key])) {
791 $static_don->id = $obj->rowid;
792 $static_don->ref = $prefix_ref.$obj->rowid;
793 $tabobject[$object_key] = array(
795 'ref' => $prefix_ref.$obj->rowid,
796 'total_ht' => $obj->don_amount,
797 'total_ttc' => $obj->don_amount,
798 'url' => $static_don->getNomUrl(1),
799 'operations' => array(),
805 $tabobject[$object_key][
'operations'][$account_pay_donation] = array(
806 'total_ht' => $obj->don_amount,
807 'label' => $langs->trans(
'Donation').
' '.$prefix_ref.$obj->rowid,
817 $sql =
"SELECT l.rowid, l.capital AS loan_capital, l.accountancy_account_capital, l.accountancy_account_interest, l.accountancy_account_insurance, l.label,";
818 $sql .=
" pl.amount_capital, pl.amount_interest, pl.amount_insurance,";
819 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
820 $sql .=
" FROM ".$db->prefix().
"payment_loan as pl";
821 $sql .=
" INNER JOIN ".$db->prefix().
"loan as l ON pl.fk_loan = l.rowid";
822 $sql .=
" INNER JOIN ".$db->prefix().
"bank_url as bu ON bu.url_id = pl.rowid AND bu.type = '".$db->escape($type).
"'";
824 if ($in_bookkeeping ==
'already') {
825 $sql .=
" INNER JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=l.rowid";
827 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=l.rowid";
829 $sql .=
" WHERE l.entity = ".$conf->entity;
831 if ($in_bookkeeping ==
'notyet') {
832 $sql .=
" AND ab.rowid IS NULL";
834 $sql .=
" AND bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
836 $resql = $db->query($sql);
838 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
840 $langs->load(
"loan");
841 $static_loan =
new Loan($db);
842 $account_pay_loan_capital =
getDolGlobalString(
'LOAN_ACCOUNTING_ACCOUNT_CAPITAL',
'NotDefined');
843 $account_pay_loan_interest =
getDolGlobalString(
'LOAN_ACCOUNTING_ACCOUNT_INTEREST',
'NotDefined');
844 $account_pay_loan_insurance =
getDolGlobalString(
'LOAN_ACCOUNTING_ACCOUNT_INSURANCE',
'NotDefined');
847 while ($obj = $db->fetch_object($resql)) {
848 $object_key = $obj->bu_type.
'_'.$obj->rowid;
851 $payment_amount = $obj->amount_capital + $obj->amount_interest + $obj->amount_insurance;
852 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
853 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
854 'amount' => -$payment_amount,
855 'bu_url_id' => $obj->bu_url_id,
860 if (!isset($tabobject[$object_key])) {
861 $static_loan->id = $obj->rowid;
862 $static_loan->ref = $prefix_ref.$obj->rowid;
863 $tabobject[$object_key] = array(
865 'ref' => $prefix_ref.$obj->rowid,
866 'total_ht' => -$obj->loan_capital,
867 'total_ttc' => -$obj->loan_capital,
868 'url' => $static_loan->getNomUrl(1),
869 'operations' => array(),
875 $accountancy_account_capital = !empty($obj->accountancy_account_capital) ? $obj->accountancy_account_capital : $account_pay_loan_capital;
876 $tabobject[$object_key][
'operations'][$accountancy_account_capital] = array(
878 'total_ht' => -($obj->loan_capital * $obj->amount_capital / $payment_amount),
879 'label' => $obj->label.
' '.$langs->trans(
'LoanCapital'),
883 $accountancy_account_interest = !empty($obj->accountancy_account_interest) ? $obj->accountancy_account_interest : $account_pay_loan_interest;
884 $tabobject[$object_key][
'operations'][$accountancy_account_interest] = array(
886 'total_ht' => -($obj->loan_capital * $obj->amount_interest / $payment_amount),
887 'label' => $obj->label.
' '.$langs->trans(
'Interest'),
893 $accountancy_account_insurance = !empty($obj->accountancy_account_insurance) ? $obj->accountancy_account_insurance : $account_pay_loan_insurance;
894 $tabobject[$object_key][
'operations'][$accountancy_account_insurance] = array(
896 'total_ht' => -($obj->loan_capital * $obj->amount_insurance / $payment_amount),
897 'label' => $obj->label.
' '.$langs->trans(
'Insurance'),
904 case 'payment_various':
907 $sql =
"SELECT pv.rowid,";
908 $sql .=
" pv.sens AS sens_payment, pv.amount AS amount_payment, pv.label, pv.accountancy_code,";
909 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
910 $sql .=
" FROM ".$db->prefix().
"payment_various as pv";
911 $sql .=
" INNER JOIN ".$db->prefix().
"bank_url as bu ON bu.url_id = pv.rowid AND bu.type = '".$db->escape($type).
"'";
913 if ($in_bookkeeping ==
'already') {
914 $sql .=
" INNER JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=pv.rowid";
916 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=pv.rowid";
918 $sql .=
" WHERE pv.entity IN (".getEntity(
'payment_various', 0).
')';
919 $sql .=
" AND bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
921 if ($in_bookkeeping ==
'notyet') {
922 $sql .=
" AND ab.rowid IS NULL";
925 $resql = $db->query($sql);
927 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
932 while ($obj = $db->fetch_object($resql)) {
933 $object_key = $obj->bu_type.
'_'.$obj->rowid;
935 $payment_amount = (empty($obj->sens_payment) ? -1 : 1) * $obj->amount_payment;
937 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
938 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
939 'amount' => $payment_amount,
940 'bu_url_id' => $obj->bu_url_id,
945 if (!isset($tabobject[$object_key])) {
946 $static_payment_various->id = $obj->rowid;
947 $static_payment_various->ref = $prefix_ref.$obj->rowid;
948 $tabobject[$object_key] = array(
950 'ref' => $prefix_ref.$obj->rowid,
951 'total_ht' => $payment_amount,
952 'total_ttc' => $payment_amount,
953 'url' => $static_payment_various->getNomUrl(1),
954 'operations' => array(),
960 $accountancy_code = !empty($obj->accountancy_code) ? $obj->accountancy_code :
'NotDefined';
961 $tabobject[$object_key][
'operations'][$obj->accountancy_code] = array(
962 'total_ht' => $payment_amount,
963 'label' => $obj->label,
973 $sql =
"SELECT su.rowid,";
974 $sql .=
" su.subscription AS amount_payment, su.note AS label,";
975 $sql .=
" adh.lastname, adh.firstname,";
976 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
977 $sql .=
" FROM ".$db->prefix().
"subscription as su";
978 $sql .=
" INNER JOIN ".$db->prefix().
"adherent as adh ON adh.rowid = su.fk_adherent";
979 $sql .=
" INNER JOIN ".$db->prefix().
"bank_url as bu ON bu.fk_bank = su.fk_bank AND bu.type = '".$db->escape($type).
"'";
981 if ($in_bookkeeping ==
'already') {
982 $sql .=
" INNER JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=su.rowid";
984 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=su.rowid";
986 $sql .=
" WHERE bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
988 if ($in_bookkeeping ==
'notyet') {
989 $sql .=
" AND ab.rowid IS NULL";
992 $resql = $db->query($sql);
994 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
996 $langs->load(
"members");
998 $account_subscription =
getDolGlobalString(
'ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT',
'NotDefined');
1001 while ($obj = $db->fetch_object($resql)) {
1002 $object_key = $obj->bu_type.
'_'.$obj->rowid;
1005 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
1006 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
1007 'amount' => $obj->amount_payment,
1008 'bu_url_id' => $obj->bu_url_id,
1013 if (!isset($tabobject[$object_key])) {
1014 $static_subscription->id = $obj->rowid;
1015 $static_subscription->ref = $prefix_ref.$obj->rowid;
1016 $tabobject[$object_key] = array(
1017 'id' => $obj->rowid,
1018 'ref' => $prefix_ref.$obj->rowid,
1019 'total_ht' => -$obj->amount_payment,
1020 'total_ttc' => -$obj->amount_payment,
1021 'url' => $static_subscription->getNomUrl(1),
1022 'operations' => array(),
1028 $tabobject[$object_key][
'operations'][$account_subscription] = array(
1029 'total_ht' => -$obj->amount_payment,
1030 'label' => $obj->label.
' - '.$obj->lastname.
' '.$obj->firstname,
1037 case 'banktransfert':
1040 $sql =
"SELECT b.rowid, b.amount, b.label,";
1041 $sql .=
" bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
1042 $sql .=
" FROM ".$db->prefix().
"bank_url as bu";
1043 $sql .=
" INNER JOIN ".$db->prefix().
"bank as b ON bu.url_id = b.rowid";
1044 $sql .=
" LEFT JOIN ".$db->prefix().
"bank_account as ba ON ba.rowid = b.fk_account";
1046 if ($in_bookkeeping ==
'already') {
1047 $sql .=
" INNER JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=b.rowid";
1049 $sql .=
" LEFT JOIN ".$db->prefix().
"accounting_bookkeeping as ab ON ab.fk_doc=bu.fk_bank AND ab.fk_docdet=b.rowid";
1051 $sql .=
" WHERE ba.entity IN (".getEntity(
'bank_account', 0).
')';
1052 $sql .=
" AND bu.fk_bank IN (".$db->sanitize(implode(
',', $ids)).
")";
1053 $sql .=
" AND bu.type = '".$db->escape($type).
"'";
1055 if ($in_bookkeeping ==
'notyet') {
1056 $sql .=
" AND ab.rowid IS NULL";
1059 $resql = $db->query($sql);
1061 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
1064 $account_transfer =
getDolGlobalString(
'ACCOUNTING_ACCOUNT_TRANSFER_CASH',
'NotDefined');
1067 while ($obj = $db->fetch_object($resql)) {
1068 $object_key = $obj->bu_type.
'_'.$obj->rowid;
1071 if (!isset($tabpay[$obj->fk_bank][
'objects'][$object_key])) {
1072 $tabpay[$obj->fk_bank][
'objects'][$object_key] = array(
1073 'amount' => -$obj->amount,
1074 'bu_url_id' => $obj->bu_url_id,
1079 if (!isset($tabobject[$object_key])) {
1080 $static_account_line->id = $obj->rowid;
1081 $static_account_line->rowid = $obj->rowid;
1082 $static_account_line->ref = $prefix_ref.$obj->rowid;
1083 $tabobject[$object_key] = array(
1084 'id' => $obj->rowid,
1085 'ref' => $prefix_ref.$obj->rowid,
1086 'total_ht' => -$obj->amount,
1087 'total_ttc' => -$obj->amount,
1088 'url' => $static_account_line->getNomUrl(1),
1089 'operations' => array(),
1095 $tabobject[$object_key][
'operations'][$account_transfer] = array(
1096 'total_ht' => -$obj->amount,
1097 'label' => $obj->label,
1118 return isset($v[
'objects']) && count($v[
'objects']) > 0;
1121$tabpay = array_filter($tabpay,
'payment_filter');
1127$accountingjournalstatic->fetch($id_journal);
1128$journal = $accountingjournalstatic->code;
1129$journal_label = $langs->transnoentitiesnoconv($accountingjournalstatic->label);
1133if ($action ==
'writebookkeeping' ) {
1134 foreach ($tabpay as $payment_id => $payment) {
1135 $accountInfos = $tabaccount[$payment[
"fk_bank_account"]];
1138 if (!isset($tabaccountingaccount[$accountInfos[
'account_number']])) {
1139 $result = $accountingaccount->fetch(0, $accountInfos[
'account_number'],
true);
1141 setEventMessages($accountingaccount->error, $accountingaccount->errors,
'errors');
1145 $tabaccountingaccount[$accountInfos[
'account_number']] = array(
1146 'label' => $result > 0 ? $accountingaccount->label : $langs->trans(
'NotDefined'),
1154 foreach ($payment[
'objects'] as $object_key => $object_data) {
1155 $objectInfos = $tabobject[$object_key];
1157 $label_suffix = (count($payment[
'objects']) > 1 ?
' - '.$objectInfos[
'ref'] :
'');
1162 if ($object_data[
'amount'] >= 0) {
1163 $amount = (float)
price2num($object_data[
'amount'],
'MT');
1164 $total_check += $amount;
1171 $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,
'');
1176 if (!empty($bookkeepingToCreate->warnings)) {
1179 if (!empty($bookkeepingToCreate->errors)) {
1186 $payment_total_vat = (float)
price2num($object_data[
'amount'] * ($objectInfos[
'total_ttc'] - $objectInfos[
'total_ht']) / $objectInfos[
'total_ttc'],
'MT');
1187 $payment_total_ht = $object_data[
'amount'] - $payment_total_vat;
1188 $total_operation = 0;
1190 $nb_operation = count($objectInfos[
'operations']);
1191 foreach ($objectInfos[
'operations'] as $accountancy_code => $operation) {
1192 if (!empty($operation[
'total_ht'])) {
1194 if (!isset($tabaccountingaccount[$accountancy_code])) {
1195 $result = $accountingaccount->fetch(0, $accountancy_code,
true);
1197 setEventMessages($accountingaccount->error, $accountingaccount->errors,
'errors');
1198 $accountancy_code_label = $accountingaccount->errorsToString();
1200 } elseif ($result > 0) {
1201 $accountancy_code_label = $accountingaccount->label;
1203 $accountancy_code_label = $langs->trans(
'NotDefined');
1205 $tabaccountingaccount[$accountancy_code] = array(
'label' => $accountancy_code_label);
1207 $accountingAccountInfos = $tabaccountingaccount[$accountancy_code];
1208 if ($idx < $nb_operation) {
1209 $amount =
price2num($payment_total_ht * $operation[
'total_ht'] / $objectInfos[
'total_ht'],
'MT');
1210 $total_operation += $amount;
1212 $amount = $payment_total_ht - $total_operation;
1214 $total_check -= $amount;
1218 $result = $bookkeepingToCreate->createFromValues($payment[
"date"], $objectInfos[
'ref'],
'bank', $payment_id, 0, $accountancy_code, $accountingAccountInfos[
'label'], (!empty($operation[
'label']) ? $operation[
'label'] : $accountingAccountInfos[
'label']).$label_suffix, -$amount, $journal, $journal_label,
'');
1222 if (!empty($bookkeepingToCreate->warnings)) {
1225 if (!empty($bookkeepingToCreate->errors)) {
1237 foreach ($objectInfos[
'vats'] as $accountancy_code => $vats) {
1238 foreach ($vats as $vat_tx => $vat_infos) {
1242 foreach ($objectInfos[
'vats'] as $accountancy_code => $vats) {
1243 foreach ($vats as $vat_tx => $vat_infos) {
1244 $amount = $vat_infos[
'total_tva'] + $vat_infos[
'total_localtax1'] + $vat_infos[
'total_localtax2'];
1245 if (!empty($amount)) {
1247 if (!isset($tabaccountingaccount[$accountancy_code])) {
1248 $result = $accountingaccount->fetch(0, $accountancy_code,
true);
1250 setEventMessages($accountingaccount->error, $accountingaccount->errors,
'errors');
1251 $accountancy_code_label = $accountingaccount->errorsToString();
1253 } elseif ($result > 0) {
1254 $accountancy_code_label = $accountingaccount->label;
1256 $accountancy_code_label = $langs->trans(
'NotDefined');
1258 $tabaccountingaccount[$accountancy_code] = array(
'label' => $accountancy_code_label);
1260 $accountingAccountInfos = $tabaccountingaccount[$accountancy_code];
1261 $amount = (float)
price2num($payment_total_vat * $amount / ($objectInfos[
'total_ttc'] - $objectInfos[
'total_ht']),
'MT');
1262 $total_vat += $amount;
1263 $total_check -= $amount;
1267 $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,
'');
1271 if (!empty($bookkeepingToCreate->warnings)) {
1274 if (!empty($bookkeepingToCreate->errors)) {
1284 if ($object_data[
'amount'] < 0) {
1285 $amount = (float)
price2num($object_data[
'amount'],
'MT');
1286 $total_check += $amount;
1290 $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,
'');
1294 if (!empty($bookkeepingToCreate->warnings)) {
1297 if (!empty($bookkeepingToCreate->errors)) {
1303 $total_check =
price2num($total_check,
'MT');
1304 if (!empty($total_check)) {
1306 setEventMessages($langs->trans(
'ErrorBookkeepingTryInsertNotBalancedTransactionAndCanceled', $objectInfos[
'ref'], $object_data[
'bu_url_id']),
null,
'errors');
1309 if ($errorforline) {
1312 if ($error >= $MAXNBERRORS) {
1318 if (!$errorforline) {
1325 if ($error >= $MAXNBERRORS) {
1326 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped").
' (>'.$MAXNBERRORS.
')',
null,
'errors');
1332 if (empty($error) && count($tabpay) > 0) {
1334 } elseif (count($tabpay) == $error) {
1337 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
1343 if (count($tabpay) != $error) {
1344 $param =
'id_journal='.$id_journal;
1345 $param .=
'&date_startday='.$date_startday;
1346 $param .=
'&date_startmonth='.$date_startmonth;
1347 $param .=
'&date_startyear='.$date_startyear;
1348 $param .=
'&date_endday='.$date_endday;
1349 $param .=
'&date_endmonth='.$date_endmonth;
1350 $param .=
'&date_endyear='.$date_endyear;
1351 $param .=
'&in_bookkeeping='.$in_bookkeeping;
1352 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?' . $param);
1362$form =
new Form($db);
1365if (empty($action) || $action ==
'view') {
1366 llxHeader(
'', $langs->trans(
"FinanceJournal"));
1368 $nom = $langs->trans(
"FinanceJournal").
' | '.$accountingjournalstatic->getNomUrl(0, 1, 1,
'', 1);
1371 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
1373 $listofchoices = array(
1374 'notyet' => $langs->trans(
"NotYetInGeneralLedger"),
1375 'already' => $langs->trans(
"AlreadyInGeneralLedger")
1377 $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);
1378 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
1380 $varlink =
'id_journal='.$id_journal;
1384 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
1387 $sql =
"SELECT COUNT(rowid) as nb FROM ".$db->prefix().
"bank_account WHERE fk_accountancy_journal IS NULL AND clos = 0";
1388 $resql = $db->query($sql);
1390 $obj = $db->fetch_object($resql);
1392 print
'<br>'.img_warning().
' '.$langs->trans(
"TheJournalCodeIsNotDefinedOnSomeBankAccount");
1393 print
' : '.$langs->trans(
"AccountancyAreaDescBank", 9,
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"BankAccounts").
'</strong>');
1403 print
'<br>'.img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
1404 print
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>');
1407 print
'<br><div class="tabsAction tabsActionNoBottom centerimp">';
1410 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
1416 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
1418 if ($in_bookkeeping ==
'notyet') {
1419 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
1421 print
'<a class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
1428 <script type="text/javascript">
1429 function writebookkeeping() {
1430 console.log("Set value into form and submit");
1431 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
1432 $("div.fiche form input[type=\"submit\"]").click();
1433 $("div.fiche form input[name=\"action\"]").val("");
1443 print
'<div class="div-table-responsive">';
1444 print
'<table class="noborder centpercent">';
1445 print
'<tr class="liste_titre">';
1446 print
"<td>".$langs->trans(
"Date").
"</td>";
1447 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"ObjectsRef").
')</td>';
1448 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
1449 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
1450 print
'<td class="center">'.$langs->trans(
"PaymentMode").
"</td>";
1451 print
'<td class="right">'.$langs->trans(
"AccountingDebit").
"</td>";
1452 print
'<td class="right">'.$langs->trans(
"AccountingCredit").
"</td>";
1455 foreach ($tabpay as $payment_id => $payment) {
1456 $accountInfos = $tabaccount[$payment[
"fk_bank_account"]];
1460 foreach ($payment[
'objects'] as $object_key => $object_data) {
1461 $objectInfos = $tabobject[$object_key];
1463 $label_suffix = (count($payment[
'objects']) > 1 ?
' - '.$objectInfos[
'ref'] :
'');
1466 if ($object_data[
'amount'] >= 0) {
1467 FormAccounting::printJournalLine($langs, $date, $objectInfos[
'url'], $accountInfos[
'account_number'], $accountInfos[
'account_ref'].$label_suffix, $payment[
'type_payment'], $object_data[
'amount']);
1471 $payment_total_vat = (float)
price2num($object_data[
'amount'] * ($objectInfos[
'total_ttc'] - $objectInfos[
'total_ht']) / $objectInfos[
'total_ttc'],
'MT');
1472 $payment_total_ht = $object_data[
'amount'] - $payment_total_vat;
1473 $total_operation = 0;
1475 $nb_operation = count($objectInfos[
'operations']);
1476 foreach ($objectInfos[
'operations'] as $accountancy_code => $operation) {
1478 if (!isset($tabaccountingaccount[$accountancy_code])) {
1479 $result = $accountingaccount->fetch(0, $accountancy_code,
true);
1480 $tabaccountingaccount[$accountancy_code] = array(
1481 'label' => $result < 0 ? $accountingaccount->errorsToString() : ($result > 0 ? $accountingaccount->label : $langs->trans(
'NotDefined')),
1484 $accountingAccountInfos = $tabaccountingaccount[$accountancy_code];
1485 if (!empty($operation[
'total_ht'])) {
1486 if ($idx < $nb_operation) {
1487 $value =
price2num($payment_total_ht * $operation[
'total_ht'] / $objectInfos[
'total_ht'],
'MT');
1488 $total_operation += $value;
1490 $value = $payment_total_ht - $total_operation;
1492 FormAccounting::printJournalLine($langs, $date, $objectInfos[
'url'], $accountancy_code, (!empty($operation[
'label']) ? $operation[
'label'] : $accountingAccountInfos[
'label']).$label_suffix, $payment[
'type_payment'], -$value);
1501 foreach ($objectInfos[
'vats'] as $accountancy_code => $vats) {
1502 foreach ($vats as $vat_tx => $vat_infos) {
1506 foreach ($objectInfos[
'vats'] as $accountancy_code => $vats) {
1507 foreach ($vats as $vat_tx => $vat_infos) {
1508 $amount_vat = $vat_infos[
'total_tva'] + $vat_infos[
'total_localtax1'] + $vat_infos[
'total_localtax2'];
1509 if (!empty($amount_vat)) {
1510 $amount_vat = (float)
price2num($payment_total_vat * $amount_vat / ($objectInfos[
'total_ttc'] - $objectInfos[
'total_ht']),
'MT');
1511 $total_vat += $amount_vat;
1512 FormAccounting::printJournalLine($langs, $date, $objectInfos[
'url'], $accountancy_code, $langs->trans(
'VAT').
' '.
price($vat_infos[
'tva_tx']).
'%'.$label_suffix, $payment[
'type_payment'], -$amount_vat);
1519 if ($object_data[
'amount'] < 0) {
1520 FormAccounting::printJournalLine($langs, $date, $objectInfos[
'url'], $accountInfos[
'account_number'], $accountInfos[
'account_ref'].$label_suffix, $payment[
'type_payment'], $object_data[
'amount']);
1527 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 - Taxe sur la valeur ajoutée)
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.
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.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.