37require
'../../main.inc.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
48require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
49require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/societe/class/client.class.php';
53require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
54require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
57$langs->loadLangs(array(
"commercial",
"compta",
"bills",
"other",
"accountancy"));
60$action =
GETPOST(
'action',
'aZ09');
62$date_startmonth =
GETPOSTINT(
'date_startmonth');
68$in_bookkeeping =
GETPOST(
'in_bookkeeping');
69if ($in_bookkeeping ==
'' || $action ==
'writebookkeeping') {
70 $in_bookkeeping =
'notyet';
75$hookmanager->initHooks(array(
'sellsjournal'));
82if ($user->socid > 0) {
85if (!$user->hasRight(
'accounting',
'bind',
'write')) {
94$tabwarranty = array();
96$tablocaltax1 = array();
97$tablocaltax2 = array();
98$tabCustomerDiscountHT = array();
99$tabCustomerDiscountVAT = array();
100$tabCustomerDiscountTTC = array();
103$manageCustomerDepositInInvoice = (
getDolGlobalInt(
'ACCOUNTING_MANAGE_CUSTOMER_DEPOSIT_IN_INVOICE') && !
getDolGlobalString(
'FACTURE_DEPOSITS_ARE_JUST_PAYMENTS'));
104$labelCustomerDiscountExtension =
' (AC)';
106$cptcli =
'NotDefined';
107$accountCustomerDeposit =
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT',
'NotDefined');
108$accountCustomerDepositVAT =
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT_FOR_VAT',
'NotDefined');
114$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $user, $action);
120$accountingjournalstatic->fetch($id_journal);
121$journal = $accountingjournalstatic->code;
122$journal_label = $accountingjournalstatic->label;
125$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
128$pastmonthyear =
null;
130if (empty($date_startmonth)) {
134 $pastmonthyear = $dates[
'pastmonthyear'];
135 $pastmonth = $dates[
'pastmonth'];
137if (empty($date_endmonth)) {
140 $date_end = $dates[
'date_end'];
141 $pastmonthyear = $dates[
'pastmonthyear'];
142 $pastmonth = $dates[
'pastmonth'];
148if (!
GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end))) {
150 $date_end =
dol_get_last_day((
int) $pastmonthyear, (
int) $pastmonth,
false);
153$sql =
"SELECT f.rowid, f.ref, f.type, f.module_source, f.situation_cycle_ref, f.datef as df, f.ref_client, f.date_lim_reglement as dlr, f.close_code, f.retained_warranty, f.revenuestamp, f.situation_final,";
154$sql .=
" fd.rowid as fdid, fd.description, fd.product_type, fd.total_ht, fd.total_tva, fd.total_localtax1, fd.total_localtax2, fd.tva_tx, fd.localtax1_tx, fd.localtax2_tx, fd.total_ttc, fd.situation_percent, fd.vat_src_code, fd.info_bits,";
155$sql .=
" s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur, s.fk_pays,";
157 $sql .=
" spe.accountancy_code_customer_general,";
158 $sql .=
" spe.accountancy_code_customer as code_compta_client,";
159 $sql .=
" spe.accountancy_code_supplier_general,";
160 $sql .=
" spe.accountancy_code_supplier as code_compta_fournisseur,";
162 $sql .=
" s.accountancy_code_customer_general,";
163 $sql .=
" s.code_compta as code_compta_client,";
164 $sql .=
" s.accountancy_code_supplier_general,";
165 $sql .=
" s.code_compta_fournisseur,";
167$sql .=
" p.rowid as pid, p.ref as pref, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte,";
169 $sql .=
" ppe.accountancy_code_sell";
171 $sql .=
" p.accountancy_code_sell";
173$parameters = array();
174$reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
175$sql .= $hookmanager->resPrint;
176$sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
177$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = fd.fk_product";
179 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int)
$conf->entity);
181$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
182$sql .=
" JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
183$sql .=
" JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
185 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int)
$conf->entity);
187$parameters = array();
188$reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters);
189$sql .= $hookmanager->resPrint;
190$sql .=
" WHERE fd.fk_code_ventilation > 0";
191$sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
')';
192$sql .=
" AND f.fk_statut > 0";
198$sql .=
" AND fd.product_type IN (0,1)";
199if ($date_start && $date_end) {
200 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
203 $sql .=
" AND (f.module_source IS NULL OR f.module_source <> 'takepos')";
207 $sql .=
" AND f.datef >= '".$db->idate(
getDolGlobalInt(
'ACCOUNTING_DATE_START_BINDING')).
"'";
210if ($in_bookkeeping ==
'already') {
211 $sql .=
" AND f.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')";
214if ($in_bookkeeping ==
'notyet') {
215 $sql .=
" AND f.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')";
218if ($manageCustomerDepositInInvoice) {
221 $sql .=
" AND COALESCE(fd.fk_remise_except, 0) NOT IN (SELECT re.rowid FROM ".$db->prefix().
"societe_remise_except as re";
222 $sql .=
" INNER JOIN ".$db->prefix().
"facture as fs ON fs.rowid = re.fk_facture_source";
223 $sql .=
" WHERE fs.type = ".Facture::TYPE_DEPOSIT.
" AND re.description LIKE '(DEPOSIT)%')";
225$parameters = array();
226$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
227$sql .= $hookmanager->resPrint;
228$sql .=
" ORDER BY f.datef, f.ref";
231dol_syslog(
'accountancy/journal/sellsjournal.php', LOG_DEBUG);
236$tabwarranty = array();
237$tabrevenuestamp = array();
239$tablocaltax1 = array();
240$tablocaltax2 = array();
241$tabcompany = array();
242$vatdata_cache = array();
243$tabCustomerDiscountHT = array();
244$tabCustomerDiscountVAT = array();
245$tabCustomerDiscountTTC = array();
253$result = $db->query($sql);
255 $num = $db->num_rows($result);
259 $obj = $db->fetch_object($result);
262 $accountancy_code_customer_general = (!empty($obj->accountancy_code_customer_general) && $obj->accountancy_code_customer_general !=
'-1') ? $obj->accountancy_code_customer_general : $cptcli;
265 $compta_prod = $obj->compte;
266 if (empty($compta_prod)) {
267 if ($obj->product_type == 0) {
276 $tax_id = $obj->tva_tx . ($obj->vat_src_code ?
' (' . $obj->vat_src_code .
')' :
'');
280 $vatdata_cache_key = $tax_id.
'_'.(int) $obj->fk_pays;
282 $vatdata_cache_key = $tax_id;
284 if (array_key_exists($vatdata_cache_key, $vatdata_cache)) {
285 $vatdata = $vatdata_cache[$vatdata_cache_key];
289 $buyer->fetch($obj->socid);
295 $vatdata_cache[$vatdata_cache_key] = $vatdata;
299 $compta_tva = $accountCustomerDepositVAT;
301 $compta_tva = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cpttva);
303 $compta_localtax1 = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cptlocaltax1);
304 $compta_localtax2 = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cptlocaltax2);
307 if (
price2num($obj->tva_tx) || !empty($obj->vat_src_code)) {
308 $def_tva[$obj->rowid][$compta_tva][
vatrate($obj->tva_tx).($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
'')] = (
vatrate($obj->tva_tx).($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''));
309 if ($obj->localtax1_tx > 0.0) {
310 $def_tva[$obj->rowid][$compta_localtax1][
vatrate($obj->localtax1_tx).($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
'').
' LT1'] = (
vatrate($obj->localtax1_tx).($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''));
312 if ($obj->localtax2_tx > 0.0) {
313 $def_tva[$obj->rowid][$compta_localtax2][
vatrate($obj->localtax2_tx).($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
'').
' LT2'] = (
vatrate($obj->localtax2_tx).($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''));
318 $situation_ratio = 1;
320 if ($obj->situation_cycle_ref) {
322 if ($obj->situation_percent == 0) {
323 $situation_ratio = 0;
326 $line->fetch($obj->fdid);
329 $prev_progress = $line->get_prev_progress($obj->rowid);
331 $situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent;
336 $revenuestamp = (float)
price2num($obj->revenuestamp,
'MT');
338 if ($manageCustomerDepositInInvoice && $obj->type ==
Facture::TYPE_STANDARD && !isset($tabfac[$obj->rowid])) {
341 $sql2 =
"SELECT re.rowid";
342 $sql2 .=
" FROM " . $db->prefix() .
"societe_remise_except as re";
343 $sql2 .=
" INNER JOIN " . $db->prefix() .
"facture as fs ON fs.rowid = re.fk_facture_source";
345 $sql2 .=
" AND (re.fk_facture = " . ((int) $obj->rowid);
346 $sql2 .=
" OR re.fk_facture_line IN (SELECT rowid FROM " . $db->prefix() .
"facturedet WHERE fk_facture = " . ((int) $obj->rowid) .
")";
349 $resql2 = $db->query($sql2);
351 if ($db->num_rows($resql2) > 0) {
352 if (!isset($tabCustomerDiscountHT[$obj->rowid][$accountCustomerDeposit])) {
353 $tabCustomerDiscountHT[$obj->rowid][$accountCustomerDeposit] = 0;
355 if (!isset($tabCustomerDiscountVAT[$obj->rowid][$accountCustomerDepositVAT])) {
356 $tabCustomerDiscountVAT[$obj->rowid][$accountCustomerDepositVAT] = 0;
358 if (!isset($tabCustomerDiscountTTC[$obj->rowid][$compta_soc])) {
359 $tabCustomerDiscountTTC[$obj->rowid][$compta_soc] = 0;
362 while ($obj2 = $db->fetch_object($resql2)) {
364 $customerDiscount->fetch($obj2->rowid);
367 $tabCustomerDiscountHT[$obj->rowid][$accountCustomerDeposit] -= $customerDiscount->total_ht;
368 $tabCustomerDiscountVAT[$obj->rowid][$accountCustomerDepositVAT] -= $customerDiscount->total_tva;
369 $tabCustomerDiscountTTC[$obj->rowid][$compta_soc] -= $customerDiscount->total_ttc;
374 dol_print_error($db);
379 $tabfac[$obj->rowid][
"date"] = $db->jdate($obj->df);
380 $tabfac[$obj->rowid][
"datereg"] = $db->jdate($obj->dlr);
381 $tabfac[$obj->rowid][
"ref"] = $obj->ref;
382 $tabfac[$obj->rowid][
"type"] = $obj->type;
383 $tabfac[$obj->rowid][
"description"] = $obj->label_compte;
384 $tabfac[$obj->rowid][
"close_code"] = $obj->close_code;
385 $tabfac[$obj->rowid][
"revenuestamp"] = $revenuestamp;
389 if (!isset($tabttc[$obj->rowid][$compta_soc])) {
390 $tabttc[$obj->rowid][$compta_soc] = 0;
392 if (!isset($tabht[$obj->rowid][$compta_prod])) {
393 $tabht[$obj->rowid][$compta_prod] = 0;
395 if (!isset($tabtva[$obj->rowid][$compta_tva])) {
396 $tabtva[$obj->rowid][$compta_tva] = 0;
398 if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
399 $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
401 if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
402 $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
411 $total_ttc = $obj->total_ttc * $situation_ratio;
412 $total_ht = $obj->total_ht * $situation_ratio;
414 $total_ttc = $obj->total_ttc;
415 $total_ht = $obj->total_ht;
419 if (
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY') && $obj->retained_warranty > 0 && (!
getDolGlobalString(
'INVOICE_RETAINED_WARRANTY_LIMITED_TO_FINAL_SITUATION') || !empty($obj->situation_final))) {
420 $retained_warranty = (float)
price2num($total_ttc * $obj->retained_warranty / 100,
'MT');
421 $tabwarranty[$obj->rowid][$compta_soc] += $retained_warranty;
422 $total_ttc -= $retained_warranty;
425 $tabttc[$obj->rowid][$compta_soc] += $total_ttc;
426 $tabht[$obj->rowid][$compta_prod] += $total_ht;
427 $tva_npr = ((($obj->info_bits & 1) == 1) ? 1 : 0);
430 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio;
431 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1 * $situation_ratio;
432 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2 * $situation_ratio;
434 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
435 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
436 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
440 $compta_revenuestamp =
'NotDefined';
441 if (!empty($revenuestamp)) {
442 $sqlrevenuestamp =
"SELECT accountancy_code_sell FROM ".MAIN_DB_PREFIX.
"c_revenuestamp";
443 $sqlrevenuestamp .=
" WHERE fk_pays = ".((int)
$mysoc->country_id);
444 $sqlrevenuestamp .=
" AND taux = ".((float) $revenuestamp);
445 $sqlrevenuestamp .=
" AND active = 1";
446 $resqlrevenuestamp = $db->query($sqlrevenuestamp);
448 if ($resqlrevenuestamp) {
449 $num_rows_revenuestamp = $db->num_rows($resqlrevenuestamp);
450 if ($num_rows_revenuestamp > 1) {
451 dol_print_error($db,
'Failed 2 or more lines for the revenue stamp of your country. Check the dictionary of revenue stamp.');
453 $objrevenuestamp = $db->fetch_object($resqlrevenuestamp);
454 if ($objrevenuestamp) {
455 $compta_revenuestamp = $objrevenuestamp->accountancy_code_sell;
461 if (empty($tabrevenuestamp[$obj->rowid][$compta_revenuestamp]) && !empty($revenuestamp)) {
463 $tabttc[$obj->rowid][$compta_soc] += $obj->revenuestamp;
464 $tabrevenuestamp[$obj->rowid][$compta_revenuestamp] = $obj->revenuestamp;
467 $tabcompany[$obj->rowid] = array(
469 'name' => $obj->name,
470 'code_client' => $obj->code_client,
471 'accountancy_code_customer_general' => $accountancy_code_customer_general,
472 'code_compta' => $compta_soc
478 'tabfac' => &$tabfac,
480 'tabtva' => &$tabtva,
481 'def_tva' => &$def_tva,
482 'tabwarranty' => &$tabwarranty,
483 'tabrevenuestamp' => &$tabrevenuestamp,
484 'tabttc' => &$tabttc,
485 'tablocaltax1' => &$tablocaltax1,
486 'tablocaltax2' => &$tablocaltax2,
487 'tabcompany' => &$tabcompany,
488 'vatdata_cache' => &$vatdata_cache,
490 $reshook = $hookmanager->executeHooks(
'processingJournalData', $parameters);
495 if ($i >
getDolGlobalInt(
'ACCOUNTANCY_MAX_TOO_MANY_LINES_TO_PROCESS', 10000)) {
497 setEventMessages(
"ErrorTooManyLinesToProcessPleaseUseAMoreSelectiveFilter",
null,
'errors');
504 'tabfac' => &$tabfac,
506 'tabtva' => &$tabtva,
507 'def_tva' => &$def_tva,
508 'tabwarranty' => &$tabwarranty,
509 'tabrevenuestamp' => &$tabrevenuestamp,
510 'tabttc' => &$tabttc,
511 'tablocaltax1' => &$tablocaltax1,
512 'tablocaltax2' => &$tablocaltax2,
513 'tabcompany' => &$tabcompany,
514 'vatdata_cache' => &$vatdata_cache,
516 $reshook = $hookmanager->executeHooks(
'processedJournalData', $parameters);
518 dol_print_error($db);
522$errorforinvoice = array();
544if (!empty($tabfac)) {
548 COUNT(fd.rowid) as nb
550 ".MAIN_DB_PREFIX.
"facturedet as fd
553 AND fd.fk_code_ventilation <= 0
554 AND fd.total_ttc <> 0
555 AND fk_facture IN (".$db->sanitize(implode(
",", array_keys($tabfac))).
")
558 $resql = $db->query($sql);
560 $num = $db->num_rows($resql);
563 $obj = $db->fetch_object($resql);
565 $errorforinvoice[$obj->fk_facture] =
'somelinesarenotbound';
574if ($action ==
'writebookkeeping' && !$error && $user->hasRight(
'accounting',
'bind',
'write')) {
578 $companystatic =
new Societe($db);
579 $invoicestatic =
new Facture($db);
583 $accountingaccountcustomer->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'),
true);
586 $accountingaccountcustomerwarranty->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY'),
true);
588 foreach ($tabfac as $key => $val) {
596 $companystatic->id = $tabcompany[$key][
'id'];
597 $companystatic->name = $tabcompany[$key][
'name'];
598 $companystatic->accountancy_code_customer_general = $tabcompany[$key][
'accountancy_code_customer_general'];
599 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
600 $companystatic->code_compta_client = $tabcompany[$key][
'code_compta'];
601 $companystatic->code_client = $tabcompany[$key][
'code_client'];
602 $companystatic->client = 3;
604 $invoicestatic->id = (int) $key;
605 $invoicestatic->ref = (string) $val[
"ref"];
606 $invoicestatic->type = (int) ($val[
"type"] ?? 0);
607 $invoicestatic->close_code = (string) ($val[
"close_code"] ??
'');
612 $replacedinvoice = 0;
613 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
614 $replacedinvoice = 1;
615 $alreadydispatched = $invoicestatic->getVentilExportCompta();
616 if ($alreadydispatched) {
617 $replacedinvoice = 2;
622 if ($replacedinvoice == 1) {
628 if (isset($errorforinvoice[$key]) && $errorforinvoice[$key] ==
'somelinesarenotbound') {
631 setEventMessages($langs->trans(
'ErrorInvoiceContainsLinesNotYetBounded', (
string) ($val[
'ref'] ??
'')),
null,
'errors');
636 if (isset($tabwarranty[$key]) && is_array($tabwarranty[$key])) {
637 foreach ($tabwarranty[$key] as $k => $mt) {
639 $bookkeeping->doc_date = $val[
"date"];
640 $bookkeeping->date_lim_reglement = $val[
"datereg"];
641 $bookkeeping->doc_ref = $val[
"ref"];
642 $bookkeeping->date_creation = $now;
643 $bookkeeping->doc_type =
'customer_invoice';
644 $bookkeeping->fk_doc = (int) $key;
645 $bookkeeping->fk_docdet = 0;
646 $bookkeeping->thirdparty_code = $companystatic->code_client;
648 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
649 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
651 $bookkeeping->numero_compte =
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY');
652 $bookkeeping->label_compte = $accountingaccountcustomerwarranty->label;
654 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"RetainedWarranty"));
655 $bookkeeping->montant = $mt;
656 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
657 $bookkeeping->debit = ($mt >= 0) ? $mt : 0;
658 $bookkeeping->credit = ($mt < 0) ? -$mt : 0;
659 $bookkeeping->code_journal = $journal;
660 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
661 $bookkeeping->fk_user_author = $user->id;
662 $bookkeeping->entity =
$conf->entity;
664 $totaldebit += $bookkeeping->debit;
665 $totalcredit += $bookkeeping->credit;
667 $result = $bookkeeping->create($user);
669 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
672 $errorforinvoice[$key] =
'alreadyjournalized';
677 $errorforinvoice[$key] =
'other';
678 setEventMessages($bookkeeping->error, $bookkeeping->errors,
'errors');
686 if (!$errorforline) {
687 foreach ($tabttc[$key] as $k => $mt) {
689 $bookkeeping->doc_date = $val[
"date"];
690 $bookkeeping->date_lim_reglement = $val[
"datereg"];
691 $bookkeeping->doc_ref = $val[
"ref"];
692 $bookkeeping->date_creation = $now;
693 $bookkeeping->doc_type =
'customer_invoice';
694 $bookkeeping->fk_doc = (int) $key;
695 $bookkeeping->fk_docdet = 0;
696 $bookkeeping->thirdparty_code = $companystatic->code_client;
698 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
699 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
701 $bookkeeping->numero_compte = (!empty($tabcompany[$key][
'accountancy_code_customer_general']) && $tabcompany[$key][
'accountancy_code_customer_general'] !=
'-1') ? $tabcompany[$key][
'accountancy_code_customer_general'] : $cptcli;
702 $bookkeeping->label_compte = $accountingaccountcustomer->label;
704 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"SubledgerAccount"));
705 $bookkeeping->montant = $mt;
706 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
707 $bookkeeping->debit = ($mt >= 0) ? $mt : 0;
708 $bookkeeping->credit = ($mt < 0) ? -$mt : 0;
709 $bookkeeping->code_journal = $journal;
710 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
711 $bookkeeping->fk_user_author = $user->id;
712 $bookkeeping->entity =
$conf->entity;
714 $totaldebit += $bookkeeping->debit;
715 $totalcredit += $bookkeeping->credit;
717 $result = $bookkeeping->create($user);
719 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
722 $errorforinvoice[$key] =
'alreadyjournalized';
727 $errorforinvoice[$key] =
'other';
728 setEventMessages($bookkeeping->error, $bookkeeping->errors,
'errors');
732 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/lettering.class.php';
735 $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id));
742 if (!$errorforline) {
743 foreach ($tabht[$key] as $k => $mt) {
744 if (empty(
$conf->cache[
'accountingaccountincurrententity'][$k])) {
746 $accountingaccount->fetch(0, $k,
true);
747 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
749 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity'][$k];
752 $label_account = $accountingaccount->label;
755 if ($accountingaccount->id > 0) {
757 $bookkeeping->doc_date = $val[
"date"];
758 $bookkeeping->date_lim_reglement = $val[
"datereg"];
759 $bookkeeping->doc_ref = $val[
"ref"];
760 $bookkeeping->date_creation = $now;
761 $bookkeeping->doc_type =
'customer_invoice';
762 $bookkeeping->fk_doc = (int) $key;
763 $bookkeeping->fk_docdet = 0;
764 $bookkeeping->thirdparty_code = $companystatic->code_client;
768 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
769 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
771 $bookkeeping->subledger_account =
'';
772 $bookkeeping->subledger_label =
'';
775 $bookkeeping->subledger_account =
'';
776 $bookkeeping->subledger_label =
'';
779 $bookkeeping->numero_compte = $k;
780 $bookkeeping->label_compte = $label_account;
782 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $label_account);
783 $bookkeeping->montant = $mt;
784 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
785 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
786 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
787 $bookkeeping->code_journal = $journal;
788 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
789 $bookkeeping->fk_user_author = $user->id;
790 $bookkeeping->entity =
$conf->entity;
792 $totaldebit += $bookkeeping->debit;
793 $totalcredit += $bookkeeping->credit;
795 $result = $bookkeeping->create($user);
797 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
800 $errorforinvoice[$key] =
'alreadyjournalized';
805 $errorforinvoice[$key] =
'other';
806 setEventMessages($bookkeeping->error, $bookkeeping->errors,
'errors');
814 if (!$errorforline) {
815 $listoftax = array(0, 1, 2);
816 foreach ($listoftax as $numtax) {
817 $arrayofvat = $tabtva;
819 $arrayofvat = $tablocaltax1;
822 $arrayofvat = $tablocaltax2;
825 foreach ($arrayofvat[$key] as $k => $mt) {
827 if (empty(
$conf->cache[
'accountingaccountincurrententity_vat'][$k])) {
829 $accountingaccount->fetch(0, $k,
true);
830 $conf->cache[
'accountingaccountincurrententity_vat'][$k] = $accountingaccount;
832 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity_vat'][$k];
835 $label_account = $accountingaccount->label;
838 $bookkeeping->doc_date = $val[
"date"];
839 $bookkeeping->date_lim_reglement = $val[
"datereg"];
840 $bookkeeping->doc_ref = $val[
"ref"];
841 $bookkeeping->date_creation = $now;
842 $bookkeeping->doc_type =
'customer_invoice';
843 $bookkeeping->fk_doc = (int) $key;
844 $bookkeeping->fk_docdet = 0;
845 $bookkeeping->thirdparty_code = $companystatic->code_client;
847 $bookkeeping->subledger_account =
'';
848 $bookkeeping->subledger_label =
'';
850 $bookkeeping->numero_compte = $k;
851 $bookkeeping->label_compte = $label_account;
854 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
855 $labelvataccount = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
856 $labelvataccount .= ($numtax ?
' - Localtax '.$numtax :
'');
857 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $labelvataccount);
859 $bookkeeping->montant = $mt;
860 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
861 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
862 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
863 $bookkeeping->code_journal = $journal;
864 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
865 $bookkeeping->fk_user_author = $user->id;
866 $bookkeeping->entity =
$conf->entity;
868 $totaldebit += $bookkeeping->debit;
869 $totalcredit += $bookkeeping->credit;
871 $result = $bookkeeping->create($user);
873 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
876 $errorforinvoice[$key] =
'alreadyjournalized';
881 $errorforinvoice[$key] =
'other';
882 setEventMessages($bookkeeping->error, $bookkeeping->errors,
'errors');
891 if (!$errorforline) {
892 if (isset($tabrevenuestamp[$key]) && is_array($tabrevenuestamp[$key])) {
893 foreach ($tabrevenuestamp[$key] as $k => $mt) {
895 if (empty(
$conf->cache[
'accountingaccountincurrententity_rs'][$k])) {
897 $accountingaccount->fetch(0, $k,
true);
898 $conf->cache[
'accountingaccountincurrententity_rs'][$k] = $accountingaccount;
900 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity_rs'][$k];
903 $label_account = $accountingaccount->label;
906 $bookkeeping->doc_date = $val[
"date"];
907 $bookkeeping->date_lim_reglement = $val[
"datereg"];
908 $bookkeeping->doc_ref = $val[
"ref"];
909 $bookkeeping->date_creation = $now;
910 $bookkeeping->doc_type =
'customer_invoice';
911 $bookkeeping->fk_doc = (int) $key;
912 $bookkeeping->fk_docdet = 0;
913 $bookkeeping->thirdparty_code = $companystatic->code_client;
915 $bookkeeping->subledger_account =
'';
916 $bookkeeping->subledger_label =
'';
918 $bookkeeping->numero_compte = $k;
919 $bookkeeping->label_compte = $label_account;
921 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"RevenueStamp"));
922 $bookkeeping->montant = $mt;
923 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
924 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
925 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
926 $bookkeeping->code_journal = $journal;
927 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
928 $bookkeeping->fk_user_author = $user->id;
929 $bookkeeping->entity =
$conf->entity;
931 $totaldebit += $bookkeeping->debit;
932 $totalcredit += $bookkeeping->credit;
934 $result = $bookkeeping->create($user);
936 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
939 $errorforinvoice[$key] =
'alreadyjournalized';
944 $errorforinvoice[$key] =
'other';
945 setEventMessages($bookkeeping->error, $bookkeeping->errors,
'errors');
953 if ($manageCustomerDepositInInvoice) {
955 if (!$errorforline && isset($tabCustomerDiscountTTC[$key])) {
956 foreach ($tabCustomerDiscountTTC[$key] as $k => $mt) {
958 $bookkeeping->doc_date = $val[
"date"];
959 $bookkeeping->date_lim_reglement = $val[
"datereg"];
960 $bookkeeping->doc_ref = $val[
"ref"];
961 $bookkeeping->date_creation = $now;
962 $bookkeeping->doc_type =
'customer_invoice';
963 $bookkeeping->fk_doc = $key;
964 $bookkeeping->fk_docdet = 0;
965 $bookkeeping->thirdparty_code = $companystatic->code_client;
967 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
968 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
972 $bookkeeping->label_compte = $accountingaccountcustomer->label;
974 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"SubledgerAccount") . $labelCustomerDiscountExtension);
975 $bookkeeping->montant = $mt;
976 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
977 $bookkeeping->debit = ($mt >= 0) ? $mt : 0;
978 $bookkeeping->credit = ($mt < 0) ? -$mt : 0;
979 $bookkeeping->code_journal = $journal;
980 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
981 $bookkeeping->fk_user_author = $user->id;
982 $bookkeeping->entity =
$conf->entity;
984 $totaldebit += $bookkeeping->debit;
985 $totalcredit += $bookkeeping->credit;
987 $result = $bookkeeping->create($user);
989 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
992 $errorforinvoice[$key] =
'alreadyjournalized';
996 $errorforinvoice[$key] =
'other';
997 setEventMessages($bookkeeping->error, $bookkeeping->errors,
'errors');
1001 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/lettering.class.php';
1004 $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id));
1011 if (!$errorforline && isset($tabCustomerDiscountHT[$key])) {
1012 foreach ($tabCustomerDiscountHT[$key] as $k => $mt) {
1013 if (empty(
$conf->cache[
'accountingaccountincurrententity'][$k])) {
1015 $accountingaccount->fetch(0, $k,
true);
1016 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
1018 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity'][$k];
1021 $label_account = $accountingaccount->label;
1024 if ($accountingaccount->id > 0) {
1026 $bookkeeping->doc_date = $val[
"date"];
1027 $bookkeeping->date_lim_reglement = $val[
"datereg"];
1028 $bookkeeping->doc_ref = $val[
"ref"];
1029 $bookkeeping->date_creation = $now;
1030 $bookkeeping->doc_type =
'customer_invoice';
1031 $bookkeeping->fk_doc = $key;
1032 $bookkeeping->fk_docdet = 0;
1033 $bookkeeping->thirdparty_code = $companystatic->code_client;
1037 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
1038 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
1040 $bookkeeping->subledger_account =
'';
1041 $bookkeeping->subledger_label =
'';
1044 $bookkeeping->subledger_account =
'';
1045 $bookkeeping->subledger_label =
'';
1048 $bookkeeping->numero_compte = $k;
1049 $bookkeeping->label_compte = $label_account;
1051 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $label_account) . $labelCustomerDiscountExtension;
1052 $bookkeeping->montant = $mt;
1053 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
1054 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
1055 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
1056 $bookkeeping->code_journal = $journal;
1057 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
1058 $bookkeeping->fk_user_author = $user->id;
1059 $bookkeeping->entity =
$conf->entity;
1061 $totaldebit += $bookkeeping->debit;
1062 $totalcredit += $bookkeeping->credit;
1064 $result = $bookkeeping->create($user);
1066 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
1069 $errorforinvoice[$key] =
'alreadyjournalized';
1073 $errorforinvoice[$key] =
'other';
1074 setEventMessages($bookkeeping->error, $bookkeeping->errors,
'errors');
1082 if (!$errorforline && isset($tabCustomerDiscountVAT[$key])) {
1083 foreach ($tabCustomerDiscountVAT[$key] as $k => $mt) {
1084 if (empty(
$conf->cache[
'accountingaccountincurrententity_vat'][$k])) {
1086 $accountingaccount->fetch(0, $k,
true);
1087 $conf->cache[
'accountingaccountincurrententity_vat'][$k] = $accountingaccount;
1089 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity_vat'][$k];
1092 $label_account = $accountingaccount->label;
1095 $bookkeeping->doc_date = $val[
"date"];
1096 $bookkeeping->date_lim_reglement = $val[
"datereg"];
1097 $bookkeeping->doc_ref = $val[
"ref"];
1098 $bookkeeping->date_creation = $now;
1099 $bookkeeping->doc_type =
'customer_invoice';
1100 $bookkeeping->fk_doc = $key;
1101 $bookkeeping->fk_docdet = 0;
1102 $bookkeeping->thirdparty_code = $companystatic->code_client;
1104 $bookkeeping->subledger_account =
'';
1105 $bookkeeping->subledger_label =
'';
1107 $bookkeeping->numero_compte = $k;
1108 $bookkeeping->label_compte = $label_account;
1110 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
1111 $labelvataccount = $langs->trans(
"Taxes") .
' ' . $tmpvatrate .
' %';
1112 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $labelvataccount) . $labelCustomerDiscountExtension;
1114 $bookkeeping->montant = $mt;
1115 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
1116 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
1117 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
1118 $bookkeeping->code_journal = $journal;
1119 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
1120 $bookkeeping->fk_user_author = $user->id;
1121 $bookkeeping->entity =
$conf->entity;
1123 $totaldebit += $bookkeeping->debit;
1124 $totalcredit += $bookkeeping->credit;
1126 $result = $bookkeeping->create($user);
1128 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
1131 $errorforinvoice[$key] =
'alreadyjournalized';
1135 $errorforinvoice[$key] =
'other';
1136 setEventMessages($bookkeeping->error, $bookkeeping->errors,
'errors');
1144 if (!$errorforline && (
price2num($totaldebit,
'MT') !=
price2num($totalcredit,
'MT'))) {
1147 $errorforinvoice[$key] =
'amountsnotbalanced';
1148 setEventMessages(
'We Tried to insert a non balanced transaction in book for '.$invoicestatic->ref.
'. Canceled. Surely a bug.',
null,
'errors');
1151 if (!$errorforline) {
1157 $langs->load(
'errors');
1158 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped"),
null,
'errors');
1166 if (empty($error) && count($tabpay) > 0) {
1167 setEventMessages($langs->trans(
"GeneralLedgerIsWritten"),
null,
'mesgs');
1168 } elseif (count($tabpay) == $error) {
1169 setEventMessages($langs->trans(
"NoNewRecordSaved"),
null,
'warnings');
1171 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
1177 if (count($tabpay) != $error) {
1178 $param =
'id_journal='.$id_journal;
1179 $param .=
'&date_startday='.$date_startday;
1180 $param .=
'&date_startmonth='.$date_startmonth;
1181 $param .=
'&date_startyear='.$date_startyear;
1182 $param .=
'&date_endday='.$date_endday;
1183 $param .=
'&date_endmonth='.$date_endmonth;
1184 $param .=
'&date_endyear='.$date_endyear;
1185 $param .=
'&in_bookkeeping='.$in_bookkeeping;
1186 header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
1197$form =
new Form($db);
1200if ($action ==
'exportcsv' && !$error) {
1204 $filename =
'journal';
1205 $type_export =
'journal';
1206 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
1208 $companystatic =
new Client($db);
1209 $invoicestatic =
new Facture($db);
1212 foreach ($tabfac as $key => $val) {
1213 $companystatic->id = $tabcompany[$key][
'id'];
1214 $companystatic->name = $tabcompany[$key][
'name'];
1215 $companystatic->accountancy_code_customer_general = (!empty($tabcompany[$key][
'accountancy_code_customer_general']) && $tabcompany[$key][
'accountancy_code_customer_general'] !=
'-1') ? $tabcompany[$key][
'accountancy_code_customer_general'] : $cptcli;
1216 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
1217 $companystatic->code_compta_client = $tabcompany[$key][
'code_compta'];
1218 $companystatic->code_client = $tabcompany[$key][
'code_client'];
1219 $companystatic->client = 3;
1221 $invoicestatic->id = (int) $key;
1222 $invoicestatic->ref = (string) $val[
"ref"];
1223 $invoicestatic->type = (int) ($val[
"type"] ?? 0);
1224 $invoicestatic->close_code = (string) ($val[
"close_code"] ??
'');
1229 $replacedinvoice = 0;
1230 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
1231 $replacedinvoice = 1;
1232 $alreadydispatched = $invoicestatic->getVentilExportCompta();
1233 if ($alreadydispatched) {
1234 $replacedinvoice = 2;
1239 if ($replacedinvoice == 1) {
1244 if (
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY') && isset($tabwarranty[$key])) {
1245 foreach ($tabwarranty[$key] as $k => $mt) {
1247 print
'"'.$key.
'"'.$sep;
1248 print
'"'.$date.
'"'.$sep;
1249 print
'"'.((string) ($val[
"ref"] ??
'')).
'"'.$sep;
1250 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
1251 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
1252 print
'"'.length_accountg(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY')).
'"'.$sep;
1253 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
1254 print
'"'.$langs->trans(
"ThirdParty").
'"'.$sep;
1255 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"RetainedWarranty"))).
'"'.$sep;
1256 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1257 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1258 print
'"'.$journal.
'"';
1265 foreach ($tabttc[$key] as $k => $mt) {
1267 print
'"'.$key.
'"'.$sep;
1268 print
'"'.$date.
'"'.$sep;
1269 print
'"'.((string) ($val[
"ref"] ??
'')).
'"'.$sep;
1270 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
1271 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
1272 print
'"'.length_accountg($companystatic->accountancy_code_customer_general).
'"'.$sep;
1273 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
1274 print
'"'.$langs->trans(
"ThirdParty").
'"'.$sep;
1275 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"ThirdParty"))).
'"'.$sep;
1276 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1277 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1278 print
'"'.$journal.
'"';
1284 foreach ($tabht[$key] as $k => $mt) {
1286 $accountingaccount->fetch(0, $k,
true);
1288 print
'"'.$key.
'"'.$sep;
1289 print
'"'.$date.
'"'.$sep;
1290 print
'"'.((string) ($val[
"ref"] ??
'')).
'"'.$sep;
1291 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
1292 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1293 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1295 print
'"'.csvClean(
dol_trunc($accountingaccount->label, 32)).
'"'.$sep;
1296 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $accountingaccount->label)).
'"'.$sep;
1297 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1298 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1299 print
'"'.$journal.
'"';
1305 $listoftax = array(0, 1, 2);
1306 foreach ($listoftax as $numtax) {
1307 $arrayofvat = $tabtva;
1309 $arrayofvat = $tablocaltax1;
1312 $arrayofvat = $tablocaltax2;
1315 foreach ($arrayofvat[$key] as $k => $mt) {
1317 print
'"'.$key.
'"'.$sep;
1318 print
'"'.$date.
'"'.$sep;
1319 print
'"'.((string) ($val[
"ref"] ??
'')).
'"'.$sep;
1320 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
1321 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1322 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1324 print
'"'.$langs->trans(
"VAT").
' - '.implode(
', ', $def_tva[$key][$k]).
' %"'.$sep;
1325 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"VAT").implode($def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
''))).
'"'.$sep;
1326 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1327 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1328 print
'"'.$journal.
'"';
1335 if (isset($tabrevenuestamp[$key])) {
1336 foreach ($tabrevenuestamp[$key] as $k => $mt) {
1338 print
'"'.$key.
'"'.$sep;
1339 print
'"'.$date.
'"'.$sep;
1340 print
'"'.((string) ($val[
"ref"] ??
'')).
'"'.$sep;
1341 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
1342 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1343 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1345 print
'"'.$langs->trans(
"RevenueStamp").
'"'.$sep;
1346 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"RevenueStamp"))).
'"'.$sep;
1347 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1348 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1349 print
'"'.$journal.
'"';
1355 if ($manageCustomerDepositInInvoice) {
1357 if (isset($tabCustomerDiscountTTC[$key])) {
1358 foreach ($tabCustomerDiscountTTC[$key] as $k => $mt) {
1360 print
'"' . $key .
'"' . $sep;
1361 print
'"' . $date .
'"' . $sep;
1362 print
'"' . ((string) ($val[
"ref"] ??
'')) .
'"' . $sep;
1365 print
'"' .
length_accountg($companystatic->accountancy_code_customer_general) .
'"' . $sep;
1367 print
'"' . $langs->trans(
"ThirdParty") .
'"' . $sep;
1368 print
'"' .
csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"ThirdParty")) . $labelCustomerDiscountExtension) .
'"' . $sep;
1369 print
'"' . ($mt >= 0 ?
price($mt) :
'') .
'"' . $sep;
1370 print
'"' . ($mt < 0 ?
price(-$mt) :
'') .
'"' . $sep;
1371 print
'"' . $journal .
'"';
1378 if (isset($tabCustomerDiscountHT[$key])) {
1379 foreach ($tabCustomerDiscountHT[$key] as $k => $mt) {
1381 $accountingaccount->fetch(0, $k,
true);
1383 print
'"' . $key .
'"' . $sep;
1384 print
'"' . $date .
'"' . $sep;
1385 print
'"' . ((string) ($val[
"ref"] ??
'')) .
'"' . $sep;
1391 print
'"' .
csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $accountingaccount->label) . $labelCustomerDiscountExtension) .
'"' . $sep;
1392 print
'"' . ($mt < 0 ?
price(-$mt) :
'') .
'"' . $sep;
1393 print
'"' . ($mt >= 0 ?
price($mt) :
'') .
'"' . $sep;
1394 print
'"' . $journal .
'"';
1401 if (isset($tabCustomerDiscountVAT[$key])) {
1402 foreach ($tabCustomerDiscountVAT[$key] as $k => $mt) {
1404 print
'"' . $key .
'"' . $sep;
1405 print
'"' . $date .
'"' . $sep;
1406 print
'"' . ((string) ($val[
"ref"] ??
'')) .
'"' . $sep;
1411 print
'"' . $langs->trans(
"VAT") .
' - ' . implode(
', ', $def_tva[$key][$k]) .
' %"' . $sep;
1412 print
'"' .
csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"VAT") . implode($def_tva[$key][$k]) .
' %') . $labelCustomerDiscountExtension) .
'"' . $sep;
1413 print
'"' . ($mt < 0 ?
price(-$mt) :
'') .
'"' . $sep;
1414 print
'"' . ($mt >= 0 ?
price($mt) :
'') .
'"' . $sep;
1415 print
'"' . $journal .
'"';
1426if (empty($action) || $action ==
'view') {
1427 $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1,
'', 1);
1428 $help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
1436 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
1438 $description .= $langs->trans(
"DepositsAreNotIncluded");
1440 $description .= $langs->trans(
"DepositsAreIncluded");
1443 $listofchoices = array(
'notyet' => $langs->trans(
"NotYetInGeneralLedger"),
'already' => $langs->trans(
"AlreadyInGeneralLedger"));
1444 $period = $form->selectDate($date_start ? $date_start : -1,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end ? $date_end : -1,
'date_end', 0, 0, 0,
'', 1, 0);
1445 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
1447 $varlink =
'id_journal='.$id_journal;
1449 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
1454 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_fiscalyear WHERE entity = ".((int)
$conf->entity);
1455 $resql = $db->query($sql);
1457 $obj = $db->fetch_object($resql);
1458 if ($obj->nb == 0) {
1459 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheFiscalPeriodIsNotDefined");
1460 $desc =
' : '.$langs->trans(
"AccountancyAreaDescFiscalPeriod", 4,
'{link}');
1461 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"FiscalPeriod").
'</strong>', $desc);
1466 dol_print_error($db);
1471 $acctCustomerNotConfigured = in_array(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'), [
'',
'-1']);
1472 if ($acctCustomerNotConfigured) {
1473 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
1474 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
1475 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
1479 print
'<br><div class="tabsAction tabsActionNoBottom centerimp">';
1480 if (
getDolGlobalString(
'ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping ==
'notyet') {
1481 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
1483 if ($acctCustomerNotConfigured) {
1484 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
1486 if ($in_bookkeeping ==
'notyet') {
1487 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
1489 print
'<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
1496 <script type="text/javascript">
1497 function launch_export() {
1498 $("div.fiche form input[name=\"action\"]").val("exportcsv");
1499 $("div.fiche form input[type=\"submit\"]").click();
1500 $("div.fiche form input[name=\"action\"]").val("");
1502 function writebookkeeping() {
1503 console.log("click on writebookkeeping");
1504 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
1505 $("div.fiche form input[type=\"submit\"]").click();
1506 $("div.fiche form input[name=\"action\"]").val("");
1515 print
'<div class="div-table-responsive">';
1516 print
"<table class=\"noborder\" width=\"100%\">";
1517 print
"<tr class=\"liste_titre\">";
1518 print
"<td>".$langs->trans(
"Date").
"</td>";
1519 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"InvoiceRef").
")</td>";
1520 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
1521 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
1522 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
1523 print
'<td class="center">'.$langs->trans(
"AccountingDebit").
"</td>";
1524 print
'<td class="center">'.$langs->trans(
"AccountingCredit").
"</td>";
1529 $companystatic =
new Client($db);
1530 $invoicestatic =
new Facture($db);
1533 foreach ($tabfac as $key => $val) {
1534 $companystatic->id = $tabcompany[$key][
'id'];
1535 $companystatic->name = $tabcompany[$key][
'name'];
1536 $companystatic->accountancy_code_customer_general = (!empty($tabcompany[$key][
'accountancy_code_customer_general']) && $tabcompany[$key][
'accountancy_code_customer_general'] !=
'-1') ? $tabcompany[$key][
'accountancy_code_customer_general'] : $cptcli;
1537 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
1538 $companystatic->code_compta_client = $tabcompany[$key][
'code_compta'];
1539 $companystatic->code_client = $tabcompany[$key][
'code_client'];
1540 $companystatic->client = 3;
1542 $invoicestatic->id = (int) $key;
1543 $invoicestatic->ref = (string) $val[
"ref"];
1544 $invoicestatic->type = (int) ($val[
"type"] ?? 0);
1545 $invoicestatic->close_code = (string) ($val[
"close_code"] ??
'');
1550 $replacedinvoice = 0;
1551 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
1552 $replacedinvoice = 1;
1553 $alreadydispatched = $invoicestatic->getVentilExportCompta();
1554 if ($alreadydispatched) {
1555 $replacedinvoice = 2;
1560 if ($replacedinvoice == 1) {
1561 print
'<tr class="oddeven">';
1562 print
"<!-- Replaced invoice -->";
1563 print
"<td>".$date.
"</td>";
1564 print
"<td><strike>".$invoicestatic->getNomUrl(1).
"</strike></td>";
1567 print $langs->trans(
"Replaced");
1574 print
'<td class="right"></td>';
1575 print
'<td class="right"></td>';
1581 if (isset($errorforinvoice[$key]) && $errorforinvoice[$key] ==
'somelinesarenotbound') {
1582 print
'<tr class="oddeven">';
1583 print
"<!-- Some lines are not bound -->";
1584 print
"<td>".$date.
"</td>";
1585 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1588 print
'<span class="error">'.$langs->trans(
'ErrorInvoiceContainsLinesNotYetBoundedShort', $invoicestatic->ref).
'</span>';
1595 print
'<td class="right"></td>';
1596 print
'<td class="right"></td>';
1603 if (
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY') && isset($tabwarranty[$key]) && is_array($tabwarranty[$key])) {
1604 foreach ($tabwarranty[$key] as $k => $mt) {
1605 print
'<tr class="oddeven">';
1606 print
"<!-- Thirdparty warranty -->";
1607 print
"<td>" . $date .
"</td>";
1608 print
"<td>" . $invoicestatic->getNomUrl(1) .
"</td>";
1612 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1613 print
'<span class="error">' . $langs->trans(
"MainAccountForRetainedWarrantyNotDefined") .
'</span>';
1615 print $accountoshow;
1621 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1622 print
'<span class="error">' . $langs->trans(
"ThirdpartyAccountNotDefined") .
'</span>';
1624 print $accountoshow;
1627 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0), $invoicestatic->ref, $langs->trans(
"RetainedWarranty"), 1) .
"</td>";
1628 print
'<td class="right nowraponall amount">' . ($mt >= 0 ?
price($mt) :
'') .
"</td>";
1629 print
'<td class="right nowraponall amount">' . ($mt < 0 ?
price(-$mt) :
'') .
"</td>";
1635 foreach ($tabttc[$key] as $k => $mt) {
1636 print
'<tr class="oddeven">';
1637 print
"<!-- Thirdparty -->";
1638 print
"<td>".$date.
"</td>";
1639 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1642 $accountoshow =
length_accountg($companystatic->accountancy_code_customer_general);
1643 if (($accountoshow ==
"") || $accountoshow ==
"-1" || $accountoshow ==
'NotDefined') {
1644 print
'<span class="error">'.$langs->trans(
"MainAccountForCustomersNotDefined").
'</span>';
1646 print $accountoshow;
1652 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1653 print
'<span class="error">'.$langs->trans(
"ThirdpartyAccountNotDefined").
'</span>';
1655 print $accountoshow;
1658 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'customer'), $invoicestatic->ref, $langs->trans(
"SubledgerAccount"), 1) .
"</td>";
1659 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1660 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1667 foreach ($tabht[$key] as $k => $mt) {
1668 if (empty(
$conf->cache[
'accountingaccountincurrententity'][$k])) {
1670 $accountingaccount->fetch(0, $k,
true);
1671 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
1673 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity'][$k];
1676 print
'<tr class="oddeven">';
1677 print
"<!-- Product -->";
1678 print
"<td>".$date.
"</td>";
1679 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1683 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1684 print
'<span class="error">'.$langs->trans(
"ProductNotDefined").
'</span>';
1686 print $accountoshow;
1695 } elseif (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1696 print
'<span class="error">' . $langs->trans(
"ThirdpartyAccountNotDefined") .
'</span>';
1699 $companystatic->id = $tabcompany[$key][
'id'];
1700 $companystatic->name = $tabcompany[$key][
'name'];
1701 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'customer'), $invoicestatic->ref, $accountingaccount->label, 1) .
"</td>";
1702 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1703 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1710 $listoftax = array(0, 1, 2);
1711 foreach ($listoftax as $numtax) {
1712 $arrayofvat = $tabtva;
1714 $arrayofvat = $tablocaltax1;
1717 $arrayofvat = $tablocaltax2;
1721 foreach ($arrayofvat[$key] as $k => $mt) {
1723 print
'<tr class="oddeven">';
1724 print
"<!-- VAT -->";
1725 print
"<td>".$date.
"</td>";
1726 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1730 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1731 print
'<span class="error">'.$langs->trans(
"VATAccountNotDefined").
' ('.$langs->trans(
"AccountingJournalType2").
')</span>';
1733 print $accountoshow;
1741 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
1742 $labelvatrate = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
1743 $labelvatrate .= ($numtax ?
' - Localtax '.$numtax :
'');
1744 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'customer'), $invoicestatic->ref, $labelvatrate, 1) .
"</td>";
1745 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1746 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1755 if (isset($tabrevenuestamp[$key]) && is_array($tabrevenuestamp[$key])) {
1756 foreach ($tabrevenuestamp[$key] as $k => $mt) {
1757 print
'<tr class="oddeven">';
1758 print
"<!-- Thirdparty revenuestamp -->";
1759 print
"<td>" . $date .
"</td>";
1760 print
"<td>" . $invoicestatic->getNomUrl(1) .
"</td>";
1764 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1765 print
'<span class="error">' . $langs->trans(
"MainAccountForRevenueStampSaleNotDefined") .
'</span>';
1767 print $accountoshow;
1773 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'customer'), $invoicestatic->ref, $langs->trans(
"RevenueStamp"), 1) .
"</td>";
1774 print
'<td class="right nowraponall amount">' . ($mt < 0 ?
price(-$mt) :
'') .
"</td>";
1775 print
'<td class="right nowraponall amount">' . ($mt >= 0 ?
price($mt) :
'') .
"</td>";
1780 if ($manageCustomerDepositInInvoice) {
1782 if (isset($tabCustomerDiscountTTC[$key])) {
1783 foreach ($tabCustomerDiscountTTC[$key] as $k => $mt) {
1784 print
'<tr class="oddeven">';
1785 print
"<!-- Discount TTC -->";
1786 print
"<td>" . $date .
"</td>";
1787 print
"<td>" . $invoicestatic->getNomUrl(1) .
"</td>";
1791 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1792 print
'<span class="error">' . $langs->trans(
"MainAccountForCustomersNotDefined") .
'</span>';
1794 print $accountoshow;
1800 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1801 print
'<span class="error">' . $langs->trans(
"ThirdpartyAccountNotDefined") .
'</span>';
1803 print $accountoshow;
1806 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'customer'), $invoicestatic->ref, $langs->trans(
"SubledgerAccount") . $labelCustomerDiscountExtension, 1) .
"</td>";
1807 print
'<td class="right nowraponall amount">' . ($mt >= 0 ?
price($mt) :
'') .
"</td>";
1808 print
'<td class="right nowraponall amount">' . ($mt < 0 ?
price(-$mt) :
'') .
"</td>";
1816 if (isset($tabCustomerDiscountHT[$key])) {
1817 foreach ($tabCustomerDiscountHT[$key] as $k => $mt) {
1818 if (empty(
$conf->cache[
'accountingaccountincurrententity'][$k])) {
1820 $accountingaccount->fetch(0, $k,
true);
1821 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
1823 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity'][$k];
1826 print
'<tr class="oddeven">';
1827 print
"<!-- Discount HT -->";
1828 print
"<td>" . $date .
"</td>";
1829 print
"<td>" . $invoicestatic->getNomUrl(1) .
"</td>";
1833 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1834 print
'<span class="error">' . $langs->trans(
"ProductNotDefined") .
'</span>';
1836 print $accountoshow;
1845 } elseif (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1846 print
'<span class="error">' . $langs->trans(
"ThirdpartyAccountNotDefined") .
'</span>';
1849 $companystatic->id = $tabcompany[$key][
'id'];
1850 $companystatic->name = $tabcompany[$key][
'name'];
1851 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'customer'), $invoicestatic->ref, $accountingaccount->label, 1) . $labelCustomerDiscountExtension .
"</td>";
1852 print
'<td class="right nowraponall amount">' . ($mt < 0 ?
price(-$mt) :
'') .
"</td>";
1853 print
'<td class="right nowraponall amount">' . ($mt >= 0 ?
price($mt) :
'') .
"</td>";
1861 if (isset($tabCustomerDiscountVAT[$key])) {
1862 foreach ($tabCustomerDiscountVAT[$key] as $k => $mt) {
1863 print
'<tr class="oddeven">';
1864 print
"<!-- Discount VAT -->";
1865 print
"<td>" . $date .
"</td>";
1866 print
"<td>" . $invoicestatic->getNomUrl(1) .
"</td>";
1870 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1871 print
'<span class="error">' . $langs->trans(
"VATAccountNotDefined") .
' (' . $langs->trans(
"AccountingJournalType2") .
')</span>';
1873 print $accountoshow;
1879 $tmpvatrate = (empty($def_tva[$key][$k]) ?
'' : implode(
', ', $def_tva[$key][$k]));
1880 $labelvatrate = $langs->trans(
"Taxes") .
' ' . $tmpvatrate .
' %';
1881 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'customer'), $invoicestatic->ref, $labelvatrate, 1) . $labelCustomerDiscountExtension .
"</td>";
1882 print
'<td class="right nowraponall amount">' . ($mt < 0 ?
price(-$mt) :
'') .
"</td>";
1883 print
'<td class="right nowraponall amount">' . ($mt >= 0 ?
price($mt) :
'') .
"</td>";
1893 print
'<tr class="oddeven"><td colspan="7"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
getSubledgerAccountWithDefault($thirdpartyCode, $type='customer')
Return the subledger account to use for a thirdparty.
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.
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage accounting accounts.
Class to manage accounting journals.
Class to manage Ledger (General Ledger and Subledger)
Class to manage customers or prospects.
Class to manage absolute discounts.
Class to manage invoices.
const TYPE_REPLACEMENT
Replacement invoice.
const TYPE_STANDARD
Standard invoice.
const TYPE_SITUATION
Situation invoice.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage invoice lines.
Class to manage third parties objects (customers, suppliers, prospects...)
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:
csvClean($newvalue, $charset='', $separator='')
Clean a cell to respect rules of CSV file cells.
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...
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
getTaxesFromId($vatrate, $buyer=null, $seller=null, $firstparamisid=1)
Get tax (VAT) main information from Id.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.