36require
'../../main.inc.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
48require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/societe/class/client.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
55$langs->loadLangs(array(
"commercial",
"compta",
"bills",
"other",
"accountancy"));
58$action =
GETPOST(
'action',
'aZ09');
60$date_startmonth =
GETPOSTINT(
'date_startmonth');
66$in_bookkeeping =
GETPOST(
'in_bookkeeping');
67if ($in_bookkeeping ==
'') {
68 $in_bookkeeping =
'notyet';
73$hookmanager->initHooks(array(
'sellsjournal'));
80if ($user->socid > 0) {
83if (!$user->hasRight(
'accounting',
'bind',
'write')) {
92$tabwarranty = array();
94$tablocaltax1 = array();
95$tablocaltax2 = array();
97$cptcli =
'NotDefined';
103$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $user, $action);
109$accountingjournalstatic->fetch($id_journal);
110$journal = $accountingjournalstatic->code;
111$journal_label = $accountingjournalstatic->label;
114$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
117$pastmonthyear =
null;
119if (empty($date_startmonth)) {
123 $pastmonthyear = $dates[
'pastmonthyear'];
124 $pastmonth = $dates[
'pastmonth'];
126if (empty($date_endmonth)) {
129 $date_end = $dates[
'date_end'];
130 $pastmonthyear = $dates[
'pastmonthyear'];
131 $pastmonth = $dates[
'pastmonth'];
137if (!
GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end))) {
139 $date_end =
dol_get_last_day((
int) $pastmonthyear, (
int) $pastmonth,
false);
142$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,";
143$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,";
144$sql .=
" s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur,";
146 $sql .=
" spe.accountancy_code_customer_general,";
147 $sql .=
" spe.accountancy_code_customer as code_compta_client,";
148 $sql .=
" spe.accountancy_code_supplier_general,";
149 $sql .=
" spe.accountancy_code_supplier as code_compta_fournisseur,";
151 $sql .=
" s.accountancy_code_customer_general,";
152 $sql .=
" s.code_compta as code_compta_client,";
153 $sql .=
" s.accountancy_code_supplier_general,";
154 $sql .=
" s.code_compta_fournisseur,";
156$sql .=
" p.rowid as pid, p.ref as pref, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte,";
158 $sql .=
" ppe.accountancy_code_sell";
160 $sql .=
" p.accountancy_code_sell";
162$parameters = array();
163$reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
164$sql .= $hookmanager->resPrint;
165$sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
166$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = fd.fk_product";
168 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int)
$conf->entity);
170$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
171$sql .=
" JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
172$sql .=
" JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
174 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int)
$conf->entity);
176$parameters = array();
177$reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters);
178$sql .= $hookmanager->resPrint;
179$sql .=
" WHERE fd.fk_code_ventilation > 0";
180$sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
')';
181$sql .=
" AND f.fk_statut > 0";
187$sql .=
" AND fd.product_type IN (0,1)";
188if ($date_start && $date_end) {
189 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
192 $sql .=
" AND f.module_source = 'takepos'";
196 $sql .=
" AND f.datef >= '".$db->idate(
getDolGlobalInt(
'ACCOUNTING_DATE_START_BINDING')).
"'";
199if ($in_bookkeeping ==
'already') {
200 $sql .=
" AND f.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')";
203if ($in_bookkeeping ==
'notyet') {
204 $sql .=
" AND f.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')";
207$parameters = array();
208$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
209$sql .= $hookmanager->resPrint;
210$sql .=
" ORDER BY f.datef, f.ref";
213dol_syslog(
'accountancy/journal/sellsjournal.php', LOG_DEBUG);
218$tabwarranty = array();
219$tabrevenuestamp = array();
221$tablocaltax1 = array();
222$tablocaltax2 = array();
223$tabcompany = array();
224$vatdata_cache = array();
232$result = $db->query($sql);
234 $num = $db->num_rows($result);
238 $obj = $db->fetch_object($result);
241 $accountancy_code_customer_general = (!empty($obj->accountancy_code_customer_general) && $obj->accountancy_code_customer_general !=
'-1') ? $obj->accountancy_code_customer_general : $cptcli;
242 $compta_soc = (!empty($obj->code_compta_client)) ? $obj->code_compta_client : $cptcli;
244 $compta_prod = $obj->compte;
245 if (empty($compta_prod)) {
246 if ($obj->product_type == 0) {
255 $tax_id = $obj->tva_tx . ($obj->vat_src_code ?
' (' . $obj->vat_src_code .
')' :
'');
256 if (array_key_exists($tax_id, $vatdata_cache)) {
257 $vatdata = $vatdata_cache[$tax_id];
261 $buyer->fetch($obj->socid);
267 $vatdata_cache[$tax_id] = $vatdata;
269 $compta_tva = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cpttva);
270 $compta_localtax1 = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cptlocaltax1);
271 $compta_localtax2 = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cptlocaltax2);
274 if (
price2num($obj->tva_tx) || !empty($obj->vat_src_code)) {
275 $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.
')' :
''));
276 if ($obj->localtax1_tx > 0.0) {
277 $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.
')' :
''));
279 if ($obj->localtax2_tx > 0.0) {
280 $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.
')' :
''));
285 $situation_ratio = 1;
287 if ($obj->situation_cycle_ref) {
289 if ($obj->situation_percent == 0) {
290 $situation_ratio = 0;
293 $line->fetch($obj->fdid);
296 $prev_progress = $line->get_prev_progress($obj->rowid);
298 $situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent;
303 $revenuestamp = (float)
price2num($obj->revenuestamp,
'MT');
306 $tabfac[$obj->rowid][
"date"] = $db->jdate($obj->df);
307 $tabfac[$obj->rowid][
"datereg"] = $db->jdate($obj->dlr);
308 $tabfac[$obj->rowid][
"ref"] = $obj->ref;
309 $tabfac[$obj->rowid][
"type"] = $obj->type;
310 $tabfac[$obj->rowid][
"description"] = $obj->label_compte;
311 $tabfac[$obj->rowid][
"close_code"] = $obj->close_code;
312 $tabfac[$obj->rowid][
"revenuestamp"] = $revenuestamp;
316 if (!isset($tabttc[$obj->rowid][$compta_soc])) {
317 $tabttc[$obj->rowid][$compta_soc] = 0;
319 if (!isset($tabht[$obj->rowid][$compta_prod])) {
320 $tabht[$obj->rowid][$compta_prod] = 0;
322 if (!isset($tabtva[$obj->rowid][$compta_tva])) {
323 $tabtva[$obj->rowid][$compta_tva] = 0;
325 if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
326 $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
328 if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
329 $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
338 $total_ttc = $obj->total_ttc * $situation_ratio;
339 $total_tva = $obj->total_tva * $situation_ratio;
340 $total_ht = $obj->total_ht * $situation_ratio;
342 $total_ttc = $obj->total_ttc;
343 $total_tva = $obj->total_tva;
344 $total_ht = $obj->total_ht;
348 if (
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY') && $obj->retained_warranty > 0 && (!
getDolGlobalString(
'INVOICE_RETAINED_WARRANTY_LIMITED_TO_FINAL_SITUATION') || !empty($obj->situation_final))) {
349 $retained_warranty = (float)
price2num($total_ttc * $obj->retained_warranty / 100,
'MT');
350 $tabwarranty[$obj->rowid][$compta_soc] += $retained_warranty;
351 $total_ttc -= $retained_warranty;
354 $tabttc[$obj->rowid][$compta_soc] += $total_ttc;
355 $tabht[$obj->rowid][$compta_prod] += $total_ht;
356 $tva_npr = ((($obj->info_bits & 1) == 1) ? 1 : 0);
359 $tabtva[$obj->rowid][$compta_tva] += $total_tva;
360 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1 * $situation_ratio;
361 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2 * $situation_ratio;
363 $tabtva[$obj->rowid][$compta_tva] += $total_tva;
364 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
365 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
369 $compta_revenuestamp =
'NotDefined';
370 if (!empty($revenuestamp)) {
371 $sqlrevenuestamp =
"SELECT accountancy_code_sell FROM ".MAIN_DB_PREFIX.
"c_revenuestamp";
372 $sqlrevenuestamp .=
" WHERE fk_pays = ".((int)
$mysoc->country_id);
373 $sqlrevenuestamp .=
" AND taux = ".((float) $revenuestamp);
374 $sqlrevenuestamp .=
" AND active = 1";
375 $resqlrevenuestamp = $db->query($sqlrevenuestamp);
377 if ($resqlrevenuestamp) {
378 $num_rows_revenuestamp = $db->num_rows($resqlrevenuestamp);
379 if ($num_rows_revenuestamp > 1) {
380 dol_print_error($db,
'Failed 2 or more lines for the revenue stamp of your country. Check the dictionary of revenue stamp.');
382 $objrevenuestamp = $db->fetch_object($resqlrevenuestamp);
383 if ($objrevenuestamp) {
384 $compta_revenuestamp = $objrevenuestamp->accountancy_code_sell;
390 if (empty($tabrevenuestamp[$obj->rowid][$compta_revenuestamp]) && !empty($revenuestamp)) {
392 $tabttc[$obj->rowid][$compta_soc] += $obj->revenuestamp;
393 $tabrevenuestamp[$obj->rowid][$compta_revenuestamp] = $obj->revenuestamp;
396 $tabcompany[$obj->rowid] = array(
398 'name' => $obj->name,
399 'code_client' => $obj->code_client,
400 'accountancy_code_customer_general' => $accountancy_code_customer_general,
401 'code_compta' => $compta_soc
407 'tabfac' => &$tabfac,
409 'tabtva' => &$tabtva,
410 'def_tva' => &$def_tva,
411 'tabwarranty' => &$tabwarranty,
412 'tabrevenuestamp' => &$tabrevenuestamp,
413 'tabttc' => &$tabttc,
414 'tablocaltax1' => &$tablocaltax1,
415 'tablocaltax2' => &$tablocaltax2,
416 'tabcompany' => &$tabcompany,
417 'vatdata_cache' => &$vatdata_cache,
419 $reshook = $hookmanager->executeHooks(
'processingJournalData', $parameters);
424 if ($i >
getDolGlobalInt(
'ACCOUNTANCY_MAX_TOO_MANY_LINES_TO_PROCESS', 10000)) {
426 setEventMessages(
"ErrorTooManyLinesToProcessPleaseUseAMoreSelectiveFilter",
null,
'errors');
433 'tabfac' => &$tabfac,
435 'tabtva' => &$tabtva,
436 'def_tva' => &$def_tva,
437 'tabwarranty' => &$tabwarranty,
438 'tabrevenuestamp' => &$tabrevenuestamp,
439 'tabttc' => &$tabttc,
440 'tablocaltax1' => &$tablocaltax1,
441 'tablocaltax2' => &$tablocaltax2,
442 'tabcompany' => &$tabcompany,
443 'vatdata_cache' => &$vatdata_cache,
445 $reshook = $hookmanager->executeHooks(
'processedJournalData', $parameters);
447 dol_print_error($db);
451$errorforinvoice = array();
473if (!empty($tabfac)) {
477 COUNT(fd.rowid) as nb
479 ".MAIN_DB_PREFIX.
"facturedet as fd
482 AND fd.fk_code_ventilation <= 0
483 AND fd.total_ttc <> 0
484 AND fk_facture IN (".$db->sanitize(implode(
",", array_keys($tabfac))).
")
487 $resql = $db->query($sql);
489 $num = $db->num_rows($resql);
492 $obj = $db->fetch_object($resql);
494 $errorforinvoice[$obj->fk_facture] =
'somelinesarenotbound';
503if ($action ==
'writebookkeeping' && !$error && $user->hasRight(
'accounting',
'bind',
'write')) {
507 $companystatic =
new Societe($db);
508 $invoicestatic =
new Facture($db);
512 $accountingaccountcustomer->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'),
true);
515 $accountingaccountcustomerwarranty->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY'),
true);
517 foreach ($tabfac as $key => $val) {
525 $companystatic->id = $tabcompany[$key][
'id'];
526 $companystatic->name = $tabcompany[$key][
'name'];
527 $companystatic->accountancy_code_customer_general = $tabcompany[$key][
'accountancy_code_customer_general'];
528 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
529 $companystatic->code_compta_client = $tabcompany[$key][
'code_compta'];
530 $companystatic->code_client = $tabcompany[$key][
'code_client'];
531 $companystatic->client = 3;
533 $invoicestatic->id = (int) $key;
534 $invoicestatic->ref = (string) $val[
"ref"];
535 $invoicestatic->type = $val[
"type"];
536 $invoicestatic->close_code = $val[
"close_code"];
541 $replacedinvoice = 0;
542 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
543 $replacedinvoice = 1;
544 $alreadydispatched = $invoicestatic->getVentilExportCompta();
545 if ($alreadydispatched) {
546 $replacedinvoice = 2;
551 if ($replacedinvoice == 1) {
557 if (isset($errorforinvoice[$key]) && $errorforinvoice[$key] ==
'somelinesarenotbound') {
560 setEventMessages($langs->trans(
'ErrorInvoiceContainsLinesNotYetBounded', $val[
'ref']),
null,
'errors');
565 if (isset($tabwarranty[$key]) && is_array($tabwarranty[$key])) {
566 foreach ($tabwarranty[$key] as $k => $mt) {
568 $bookkeeping->doc_date = $val[
"date"];
569 $bookkeeping->date_lim_reglement = $val[
"datereg"];
570 $bookkeeping->doc_ref = $val[
"ref"];
571 $bookkeeping->date_creation = $now;
572 $bookkeeping->doc_type =
'customer_invoice';
573 $bookkeeping->fk_doc = (int) $key;
574 $bookkeeping->fk_docdet = 0;
575 $bookkeeping->thirdparty_code = $companystatic->code_client;
577 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
578 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
580 $bookkeeping->numero_compte =
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY');
581 $bookkeeping->label_compte = $accountingaccountcustomerwarranty->label;
583 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"RetainedWarranty"));
584 $bookkeeping->montant = $mt;
585 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
586 $bookkeeping->debit = ($mt >= 0) ? $mt : 0;
587 $bookkeeping->credit = ($mt < 0) ? -$mt : 0;
588 $bookkeeping->code_journal = $journal;
589 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
590 $bookkeeping->fk_user_author = $user->id;
591 $bookkeeping->entity =
$conf->entity;
593 $totaldebit += $bookkeeping->debit;
594 $totalcredit += $bookkeeping->credit;
596 $result = $bookkeeping->create($user);
598 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
601 $errorforinvoice[$key] =
'alreadyjournalized';
606 $errorforinvoice[$key] =
'other';
607 setEventMessages($bookkeeping->error, $bookkeeping->errors,
'errors');
615 if (!$errorforline) {
616 foreach ($tabttc[$key] as $k => $mt) {
618 $bookkeeping->doc_date = $val[
"date"];
619 $bookkeeping->date_lim_reglement = $val[
"datereg"];
620 $bookkeeping->doc_ref = $val[
"ref"];
621 $bookkeeping->date_creation = $now;
622 $bookkeeping->doc_type =
'customer_invoice';
623 $bookkeeping->fk_doc = (int) $key;
624 $bookkeeping->fk_docdet = 0;
625 $bookkeeping->thirdparty_code = $companystatic->code_client;
627 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
628 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
630 $bookkeeping->numero_compte = (!empty($tabcompany[$key][
'accountancy_code_customer_general']) && $tabcompany[$key][
'accountancy_code_customer_general'] !=
'-1') ? $tabcompany[$key][
'accountancy_code_customer_general'] : $cptcli;
631 $bookkeeping->label_compte = $accountingaccountcustomer->label;
633 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"SubledgerAccount"));
634 $bookkeeping->montant = $mt;
635 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
636 $bookkeeping->debit = ($mt >= 0) ? $mt : 0;
637 $bookkeeping->credit = ($mt < 0) ? -$mt : 0;
638 $bookkeeping->code_journal = $journal;
639 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
640 $bookkeeping->fk_user_author = $user->id;
641 $bookkeeping->entity =
$conf->entity;
643 $totaldebit += $bookkeeping->debit;
644 $totalcredit += $bookkeeping->credit;
646 $result = $bookkeeping->create($user);
648 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
651 $errorforinvoice[$key] =
'alreadyjournalized';
656 $errorforinvoice[$key] =
'other';
657 setEventMessages($bookkeeping->error, $bookkeeping->errors,
'errors');
661 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/lettering.class.php';
664 $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id));
671 if (!$errorforline) {
672 foreach ($tabht[$key] as $k => $mt) {
673 if (empty(
$conf->cache[
'accountingaccountincurrententity'][$k])) {
675 $accountingaccount->fetch(0, $k,
true);
676 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
678 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity'][$k];
681 $label_account = $accountingaccount->label;
684 if ($accountingaccount->id > 0) {
686 $bookkeeping->doc_date = $val[
"date"];
687 $bookkeeping->date_lim_reglement = $val[
"datereg"];
688 $bookkeeping->doc_ref = $val[
"ref"];
689 $bookkeeping->date_creation = $now;
690 $bookkeeping->doc_type =
'customer_invoice';
691 $bookkeeping->fk_doc = (int) $key;
692 $bookkeeping->fk_docdet = 0;
693 $bookkeeping->thirdparty_code = $companystatic->code_client;
697 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
698 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
700 $bookkeeping->subledger_account =
'';
701 $bookkeeping->subledger_label =
'';
704 $bookkeeping->subledger_account =
'';
705 $bookkeeping->subledger_label =
'';
708 $bookkeeping->numero_compte = $k;
709 $bookkeeping->label_compte = $label_account;
711 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $label_account);
712 $bookkeeping->montant = $mt;
713 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
714 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
715 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
716 $bookkeeping->code_journal = $journal;
717 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
718 $bookkeeping->fk_user_author = $user->id;
719 $bookkeeping->entity =
$conf->entity;
721 $totaldebit += $bookkeeping->debit;
722 $totalcredit += $bookkeeping->credit;
724 $result = $bookkeeping->create($user);
726 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
729 $errorforinvoice[$key] =
'alreadyjournalized';
734 $errorforinvoice[$key] =
'other';
735 setEventMessages($bookkeeping->error, $bookkeeping->errors,
'errors');
743 if (!$errorforline) {
744 $listoftax = array(0, 1, 2);
745 foreach ($listoftax as $numtax) {
746 $arrayofvat = $tabtva;
748 $arrayofvat = $tablocaltax1;
751 $arrayofvat = $tablocaltax2;
754 foreach ($arrayofvat[$key] as $k => $mt) {
756 if (empty(
$conf->cache[
'accountingaccountincurrententity_vat'][$k])) {
758 $accountingaccount->fetch(0, $k,
true);
759 $conf->cache[
'accountingaccountincurrententity_vat'][$k] = $accountingaccount;
761 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity_vat'][$k];
764 $label_account = $accountingaccount->label;
767 $bookkeeping->doc_date = $val[
"date"];
768 $bookkeeping->date_lim_reglement = $val[
"datereg"];
769 $bookkeeping->doc_ref = $val[
"ref"];
770 $bookkeeping->date_creation = $now;
771 $bookkeeping->doc_type =
'customer_invoice';
772 $bookkeeping->fk_doc = (int) $key;
773 $bookkeeping->fk_docdet = 0;
774 $bookkeeping->thirdparty_code = $companystatic->code_client;
776 $bookkeeping->subledger_account =
'';
777 $bookkeeping->subledger_label =
'';
779 $bookkeeping->numero_compte = $k;
780 $bookkeeping->label_compte = $label_account;
783 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
784 $labelvataccount = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
785 $labelvataccount .= ($numtax ?
' - Localtax '.$numtax :
'');
786 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $labelvataccount);
788 $bookkeeping->montant = $mt;
789 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
790 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
791 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
792 $bookkeeping->code_journal = $journal;
793 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
794 $bookkeeping->fk_user_author = $user->id;
795 $bookkeeping->entity =
$conf->entity;
797 $totaldebit += $bookkeeping->debit;
798 $totalcredit += $bookkeeping->credit;
800 $result = $bookkeeping->create($user);
802 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
805 $errorforinvoice[$key] =
'alreadyjournalized';
810 $errorforinvoice[$key] =
'other';
811 setEventMessages($bookkeeping->error, $bookkeeping->errors,
'errors');
820 if (!$errorforline) {
821 if (isset($tabrevenuestamp[$key]) && is_array($tabrevenuestamp[$key])) {
822 foreach ($tabrevenuestamp[$key] as $k => $mt) {
824 if (empty(
$conf->cache[
'accountingaccountincurrententity_rs'][$k])) {
826 $accountingaccount->fetch(0, $k,
true);
827 $conf->cache[
'accountingaccountincurrententity_rs'][$k] = $accountingaccount;
829 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity_rs'][$k];
832 $label_account = $accountingaccount->label;
835 $bookkeeping->doc_date = $val[
"date"];
836 $bookkeeping->date_lim_reglement = $val[
"datereg"];
837 $bookkeeping->doc_ref = $val[
"ref"];
838 $bookkeeping->date_creation = $now;
839 $bookkeeping->doc_type =
'customer_invoice';
840 $bookkeeping->fk_doc = (int) $key;
841 $bookkeeping->fk_docdet = 0;
842 $bookkeeping->thirdparty_code = $companystatic->code_client;
844 $bookkeeping->subledger_account =
'';
845 $bookkeeping->subledger_label =
'';
847 $bookkeeping->numero_compte = $k;
848 $bookkeeping->label_compte = $label_account;
850 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"RevenueStamp"));
851 $bookkeeping->montant = $mt;
852 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
853 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
854 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
855 $bookkeeping->code_journal = $journal;
856 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
857 $bookkeeping->fk_user_author = $user->id;
858 $bookkeeping->entity =
$conf->entity;
860 $totaldebit += $bookkeeping->debit;
861 $totalcredit += $bookkeeping->credit;
863 $result = $bookkeeping->create($user);
865 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
868 $errorforinvoice[$key] =
'alreadyjournalized';
873 $errorforinvoice[$key] =
'other';
874 setEventMessages($bookkeeping->error, $bookkeeping->errors,
'errors');
883 if (!$errorforline && (
price2num($totaldebit,
'MT') !=
price2num($totalcredit,
'MT'))) {
886 $errorforinvoice[$key] =
'amountsnotbalanced';
887 setEventMessages(
'We Tried to insert a non balanced transaction in book for '.$invoicestatic->ref.
'. Canceled. Surely a bug.',
null,
'errors');
890 if (!$errorforline) {
896 $langs->load(
'errors');
897 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped"),
null,
'errors');
905 if (empty($error) && count($tabpay) > 0) {
906 setEventMessages($langs->trans(
"GeneralLedgerIsWritten"),
null,
'mesgs');
907 } elseif (count($tabpay) == $error) {
908 setEventMessages($langs->trans(
"NoNewRecordSaved"),
null,
'warnings');
910 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
916 if (count($tabpay) != $error) {
917 $param =
'id_journal='.$id_journal;
918 $param .=
'&date_startday='.$date_startday;
919 $param .=
'&date_startmonth='.$date_startmonth;
920 $param .=
'&date_startyear='.$date_startyear;
921 $param .=
'&date_endday='.$date_endday;
922 $param .=
'&date_endmonth='.$date_endmonth;
923 $param .=
'&date_endyear='.$date_endyear;
924 $param .=
'&in_bookkeeping='.$in_bookkeeping;
925 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?'.$param);
936$form =
new Form($db);
939if ($action ==
'exportcsv' && !$error) {
943 $filename =
'journal';
944 $type_export =
'journal';
945 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
947 $companystatic =
new Client($db);
948 $invoicestatic =
new Facture($db);
951 foreach ($tabfac as $key => $val) {
952 $companystatic->id = $tabcompany[$key][
'id'];
953 $companystatic->name = $tabcompany[$key][
'name'];
954 $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;
955 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
956 $companystatic->code_compta_client = $tabcompany[$key][
'code_compta'];
957 $companystatic->code_client = $tabcompany[$key][
'code_client'];
958 $companystatic->client = 3;
960 $invoicestatic->id = (int) $key;
961 $invoicestatic->ref = (string) $val[
"ref"];
962 $invoicestatic->type = $val[
"type"];
963 $invoicestatic->close_code = $val[
"close_code"];
968 $replacedinvoice = 0;
969 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
970 $replacedinvoice = 1;
971 $alreadydispatched = $invoicestatic->getVentilExportCompta();
972 if ($alreadydispatched) {
973 $replacedinvoice = 2;
978 if ($replacedinvoice == 1) {
983 if (
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY') && isset($tabwarranty[$key])) {
984 foreach ($tabwarranty[$key] as $k => $mt) {
986 print
'"'.$key.
'"'.$sep;
987 print
'"'.$date.
'"'.$sep;
988 print
'"'.$val[
"ref"].
'"'.$sep;
989 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
990 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
991 print
'"'.length_accountg(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY')).
'"'.$sep;
992 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
993 print
'"'.$langs->trans(
"ThirdParty").
'"'.$sep;
994 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"RetainedWarranty"))).
'"'.$sep;
995 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
996 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
997 print
'"'.$journal.
'"';
1004 foreach ($tabttc[$key] as $k => $mt) {
1006 print
'"'.$key.
'"'.$sep;
1007 print
'"'.$date.
'"'.$sep;
1008 print
'"'.$val[
"ref"].
'"'.$sep;
1009 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
1010 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
1011 print
'"'.length_accountg($companystatic->accountancy_code_customer_general).
'"'.$sep;
1012 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
1013 print
'"'.$langs->trans(
"ThirdParty").
'"'.$sep;
1014 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"ThirdParty"))).
'"'.$sep;
1015 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1016 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1017 print
'"'.$journal.
'"';
1023 foreach ($tabht[$key] as $k => $mt) {
1025 $accountingaccount->fetch(0, $k,
true);
1027 print
'"'.$key.
'"'.$sep;
1028 print
'"'.$date.
'"'.$sep;
1029 print
'"'.$val[
"ref"].
'"'.$sep;
1030 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
1031 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1032 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1034 print
'"'.csvClean(
dol_trunc($accountingaccount->label, 32)).
'"'.$sep;
1035 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $accountingaccount->label)).
'"'.$sep;
1036 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1037 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1038 print
'"'.$journal.
'"';
1044 $listoftax = array(0, 1, 2);
1045 foreach ($listoftax as $numtax) {
1046 $arrayofvat = $tabtva;
1048 $arrayofvat = $tablocaltax1;
1051 $arrayofvat = $tablocaltax2;
1054 foreach ($arrayofvat[$key] as $k => $mt) {
1056 print
'"'.$key.
'"'.$sep;
1057 print
'"'.$date.
'"'.$sep;
1058 print
'"'.$val[
"ref"].
'"'.$sep;
1059 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
1060 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1061 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1063 print
'"'.$langs->trans(
"VAT").
' - '.implode(
', ', $def_tva[$key][$k]).
' %"'.$sep;
1064 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"VAT").implode($def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
''))).
'"'.$sep;
1065 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1066 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1067 print
'"'.$journal.
'"';
1074 if (isset($tabrevenuestamp[$key])) {
1075 foreach ($tabrevenuestamp[$key] as $k => $mt) {
1077 print
'"'.$key.
'"'.$sep;
1078 print
'"'.$date.
'"'.$sep;
1079 print
'"'.$val[
"ref"].
'"'.$sep;
1080 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
1081 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1082 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1084 print
'"'.$langs->trans(
"RevenueStamp").
'"'.$sep;
1085 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"RevenueStamp"))).
'"'.$sep;
1086 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1087 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1088 print
'"'.$journal.
'"';
1098if (empty($action) || $action ==
'view') {
1099 $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1,
'', 1);
1100 $help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
1108 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
1110 $description .= $langs->trans(
"DepositsAreNotIncluded");
1112 $description .= $langs->trans(
"DepositsAreIncluded");
1115 $listofchoices = array(
'notyet' => $langs->trans(
"NotYetInGeneralLedger"),
'already' => $langs->trans(
"AlreadyInGeneralLedger"));
1116 $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);
1117 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
1119 $varlink =
'id_journal='.$id_journal;
1121 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
1126 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_fiscalyear WHERE entity = ".((int)
$conf->entity);
1127 $resql = $db->query($sql);
1129 $obj = $db->fetch_object($resql);
1130 if ($obj->nb == 0) {
1131 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheFiscalPeriodIsNotDefined");
1132 $desc =
' : '.$langs->trans(
"AccountancyAreaDescFiscalPeriod", 4,
'{link}');
1133 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"FiscalPeriod").
'</strong>', $desc);
1138 dol_print_error($db);
1143 $acctCustomerNotConfigured = in_array(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'), [
'',
'-1']);
1144 if ($acctCustomerNotConfigured) {
1145 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
1146 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
1147 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
1151 print
'<br><div class="tabsAction tabsActionNoBottom centerimp">';
1152 if (
getDolGlobalString(
'ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping ==
'notyet') {
1153 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
1155 if ($acctCustomerNotConfigured) {
1156 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
1158 if ($in_bookkeeping ==
'notyet') {
1159 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
1161 print
'<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
1168 <script type="text/javascript">
1169 function launch_export() {
1170 $("div.fiche form input[name=\"action\"]").val("exportcsv");
1171 $("div.fiche form input[type=\"submit\"]").click();
1172 $("div.fiche form input[name=\"action\"]").val("");
1174 function writebookkeeping() {
1175 console.log("click on writebookkeeping");
1176 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
1177 $("div.fiche form input[type=\"submit\"]").click();
1178 $("div.fiche form input[name=\"action\"]").val("");
1187 print
'<div class="div-table-responsive">';
1188 print
"<table class=\"noborder\" width=\"100%\">";
1189 print
"<tr class=\"liste_titre\">";
1190 print
"<td>".$langs->trans(
"Date").
"</td>";
1191 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"InvoiceRef").
")</td>";
1192 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
1193 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
1194 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
1195 print
'<td class="center">'.$langs->trans(
"AccountingDebit").
"</td>";
1196 print
'<td class="center">'.$langs->trans(
"AccountingCredit").
"</td>";
1201 $companystatic =
new Client($db);
1202 $invoicestatic =
new Facture($db);
1205 foreach ($tabfac as $key => $val) {
1206 $companystatic->id = $tabcompany[$key][
'id'];
1207 $companystatic->name = $tabcompany[$key][
'name'];
1208 $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;
1209 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
1210 $companystatic->code_compta_client = $tabcompany[$key][
'code_compta'];
1211 $companystatic->code_client = $tabcompany[$key][
'code_client'];
1212 $companystatic->client = 3;
1214 $invoicestatic->id = (int) $key;
1215 $invoicestatic->ref = (string) $val[
"ref"];
1216 $invoicestatic->type = $val[
"type"];
1217 $invoicestatic->close_code = $val[
"close_code"];
1222 $replacedinvoice = 0;
1223 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
1224 $replacedinvoice = 1;
1225 $alreadydispatched = $invoicestatic->getVentilExportCompta();
1226 if ($alreadydispatched) {
1227 $replacedinvoice = 2;
1232 if ($replacedinvoice == 1) {
1233 print
'<tr class="oddeven">';
1234 print
"<!-- Replaced invoice -->";
1235 print
"<td>".$date.
"</td>";
1236 print
"<td><strike>".$invoicestatic->getNomUrl(1).
"</strike></td>";
1239 print $langs->trans(
"Replaced");
1246 print
'<td class="right"></td>';
1247 print
'<td class="right"></td>';
1253 if (isset($errorforinvoice[$key]) && $errorforinvoice[$key] ==
'somelinesarenotbound') {
1254 print
'<tr class="oddeven">';
1255 print
"<!-- Some lines are not bound -->";
1256 print
"<td>".$date.
"</td>";
1257 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1260 print
'<span class="error">'.$langs->trans(
'ErrorInvoiceContainsLinesNotYetBoundedShort', $val[
'ref']).
'</span>';
1267 print
'<td class="right"></td>';
1268 print
'<td class="right"></td>';
1275 if (
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY') && isset($tabwarranty[$key]) && is_array($tabwarranty[$key])) {
1276 foreach ($tabwarranty[$key] as $k => $mt) {
1277 print
'<tr class="oddeven">';
1278 print
"<!-- Thirdparty warranty -->";
1279 print
"<td>" . $date .
"</td>";
1280 print
"<td>" . $invoicestatic->getNomUrl(1) .
"</td>";
1284 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1285 print
'<span class="error">' . $langs->trans(
"MainAccountForRetainedWarrantyNotDefined") .
'</span>';
1287 print $accountoshow;
1293 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1294 print
'<span class="error">' . $langs->trans(
"ThirdpartyAccountNotDefined") .
'</span>';
1296 print $accountoshow;
1299 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0), $invoicestatic->ref, $langs->trans(
"RetainedWarranty"), 1) .
"</td>";
1300 print
'<td class="right nowraponall amount">' . ($mt >= 0 ?
price($mt) :
'') .
"</td>";
1301 print
'<td class="right nowraponall amount">' . ($mt < 0 ?
price(-$mt) :
'') .
"</td>";
1307 foreach ($tabttc[$key] as $k => $mt) {
1308 print
'<tr class="oddeven">';
1309 print
"<!-- Thirdparty -->";
1310 print
"<td>".$date.
"</td>";
1311 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1314 $accountoshow =
length_accountg($companystatic->accountancy_code_customer_general);
1315 if (($accountoshow ==
"") || $accountoshow ==
"-1" || $accountoshow ==
'NotDefined') {
1316 print
'<span class="error">'.$langs->trans(
"MainAccountForCustomersNotDefined").
'</span>';
1318 print $accountoshow;
1324 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1325 print
'<span class="error">'.$langs->trans(
"ThirdpartyAccountNotDefined").
'</span>';
1327 print $accountoshow;
1330 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'customer'), $invoicestatic->ref, $langs->trans(
"SubledgerAccount"), 1) .
"</td>";
1331 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1332 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1339 foreach ($tabht[$key] as $k => $mt) {
1340 if (empty(
$conf->cache[
'accountingaccountincurrententity'][$k])) {
1342 $accountingaccount->fetch(0, $k,
true);
1343 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
1345 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity'][$k];
1348 print
'<tr class="oddeven">';
1349 print
"<!-- Product -->";
1350 print
"<td>".$date.
"</td>";
1351 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1355 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1356 print
'<span class="error">'.$langs->trans(
"ProductNotDefined").
'</span>';
1358 print $accountoshow;
1367 } elseif (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1368 print
'<span class="error">' . $langs->trans(
"ThirdpartyAccountNotDefined") .
'</span>';
1371 $companystatic->id = $tabcompany[$key][
'id'];
1372 $companystatic->name = $tabcompany[$key][
'name'];
1373 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'customer'), $invoicestatic->ref, $accountingaccount->label, 1) .
"</td>";
1374 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1375 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1382 $listoftax = array(0, 1, 2);
1383 foreach ($listoftax as $numtax) {
1384 $arrayofvat = $tabtva;
1386 $arrayofvat = $tablocaltax1;
1389 $arrayofvat = $tablocaltax2;
1393 foreach ($arrayofvat[$key] as $k => $mt) {
1395 print
'<tr class="oddeven">';
1396 print
"<!-- VAT -->";
1397 print
"<td>".$date.
"</td>";
1398 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1402 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1403 print
'<span class="error">'.$langs->trans(
"VATAccountNotDefined").
' ('.$langs->trans(
"AccountingJournalType6").
')</span>';
1405 print $accountoshow;
1413 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
1414 $labelvatrate = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
1415 $labelvatrate .= ($numtax ?
' - Localtax '.$numtax :
'');
1416 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'customer'), $invoicestatic->ref, $labelvatrate, 1) .
"</td>";
1417 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1418 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1427 if (isset($tabrevenuestamp[$key]) && is_array($tabrevenuestamp[$key])) {
1428 foreach ($tabrevenuestamp[$key] as $k => $mt) {
1429 print
'<tr class="oddeven">';
1430 print
"<!-- Thirdparty revenuestamp -->";
1431 print
"<td>" . $date .
"</td>";
1432 print
"<td>" . $invoicestatic->getNomUrl(1) .
"</td>";
1436 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1437 print
'<span class="error">' . $langs->trans(
"MainAccountForRevenueStampSaleNotDefined") .
'</span>';
1439 print $accountoshow;
1445 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'customer'), $invoicestatic->ref, $langs->trans(
"RevenueStamp"), 1) .
"</td>";
1446 print
'<td class="right nowraponall amount">' . ($mt < 0 ?
price(-$mt) :
'') .
"</td>";
1447 print
'<td class="right nowraponall amount">' . ($mt >= 0 ?
price($mt) :
'') .
"</td>";
1454 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)
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 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 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:
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.