35require
'../../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
39require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/societe/class/client.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
55$langs->loadLangs(array(
"commercial",
"compta",
"bills",
"other",
"accountancy",
"errors"));
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'));
77if (!isModEnabled(
'accounting')) {
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;
113$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
114$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
117$pastmonthyear =
null;
119if (empty($date_startmonth)) {
122 $date_start = $dates[
'date_start'];
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))) {
142$sql =
"SELECT f.rowid, f.ref, f.type, 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,";
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.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).
"'";
193 $sql .=
" AND f.datef >= '".$db->idate(
getDolGlobalString(
'ACCOUNTING_DATE_START_BINDING')).
"'";
196if ($in_bookkeeping ==
'already') {
197 $sql .=
" AND f.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')";
200if ($in_bookkeeping ==
'notyet') {
201 $sql .=
" AND f.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')";
204$parameters = array();
205$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
206$sql .= $hookmanager->resPrint;
207$sql .=
" ORDER BY f.datef, f.ref";
210dol_syslog(
'accountancy/journal/sellsjournal.php', LOG_DEBUG);
215$tabwarranty = array();
216$tabrevenuestamp = array();
218$tablocaltax1 = array();
219$tablocaltax2 = array();
220$tabcompany = array();
221$vatdata_cache = array();
227$result = $db->query($sql);
229 $num = $db->num_rows($result);
233 $obj = $db->fetch_object($result);
236 $accountancy_code_customer_general = (!empty($obj->accountancy_code_customer_general) && $obj->accountancy_code_customer_general !=
'-1') ? $obj->accountancy_code_customer_general : $cptcli;
237 $compta_soc = (!empty($obj->code_compta_client)) ? $obj->code_compta_client : $cptcli;
239 $compta_prod = $obj->compte;
240 if (empty($compta_prod)) {
241 if ($obj->product_type == 0) {
250 $tax_id = $obj->tva_tx . ($obj->vat_src_code ?
' (' . $obj->vat_src_code .
')' :
'');
251 if (array_key_exists($tax_id, $vatdata_cache)) {
252 $vatdata = $vatdata_cache[$tax_id];
256 $buyer->fetch($obj->socid);
262 $vatdata_cache[$tax_id] = $vatdata;
264 $compta_tva = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cpttva);
265 $compta_localtax1 = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cpttva);
266 $compta_localtax2 = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cpttva);
269 if (
price2num($obj->tva_tx) || !empty($obj->vat_src_code)) {
270 $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.
')' :
''));
274 $situation_ratio = 1;
276 if ($obj->situation_cycle_ref) {
278 if ($obj->situation_percent == 0) {
279 $situation_ratio = 0;
282 $line->fetch($obj->fdid);
285 $prev_progress = $line->get_prev_progress($obj->rowid);
287 $situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent;
292 $revenuestamp = (float)
price2num($obj->revenuestamp,
'MT');
295 $tabfac[$obj->rowid][
"date"] = $db->jdate($obj->df);
296 $tabfac[$obj->rowid][
"datereg"] = $db->jdate($obj->dlr);
297 $tabfac[$obj->rowid][
"ref"] = $obj->ref;
298 $tabfac[$obj->rowid][
"type"] = $obj->type;
299 $tabfac[$obj->rowid][
"description"] = $obj->label_compte;
300 $tabfac[$obj->rowid][
"close_code"] = $obj->close_code;
301 $tabfac[$obj->rowid][
"revenuestamp"] = $revenuestamp;
305 if (!isset($tabttc[$obj->rowid][$compta_soc])) {
306 $tabttc[$obj->rowid][$compta_soc] = 0;
308 if (!isset($tabht[$obj->rowid][$compta_prod])) {
309 $tabht[$obj->rowid][$compta_prod] = 0;
311 if (!isset($tabtva[$obj->rowid][$compta_tva])) {
312 $tabtva[$obj->rowid][$compta_tva] = 0;
314 if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
315 $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
317 if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
318 $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
327 $total_ttc = $obj->total_ttc * $situation_ratio;
329 $total_ttc = $obj->total_ttc;
333 if (
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY') && $obj->retained_warranty > 0) {
334 $retained_warranty = (float)
price2num($total_ttc * $obj->retained_warranty / 100,
'MT');
335 $tabwarranty[$obj->rowid][$compta_soc] += $retained_warranty;
336 $total_ttc -= $retained_warranty;
339 $tabttc[$obj->rowid][$compta_soc] += $total_ttc;
340 $tabht[$obj->rowid][$compta_prod] += $obj->total_ht * $situation_ratio;
341 $tva_npr = ((($obj->info_bits & 1) == 1) ? 1 : 0);
344 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
345 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
346 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
348 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio;
349 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1 * $situation_ratio;
350 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2 * $situation_ratio;
354 $compta_revenuestamp =
'NotDefined';
355 if (!empty($revenuestamp)) {
356 $sqlrevenuestamp =
"SELECT accountancy_code_sell FROM ".MAIN_DB_PREFIX.
"c_revenuestamp";
357 $sqlrevenuestamp .=
" WHERE fk_pays = ".((int) $mysoc->country_id);
358 $sqlrevenuestamp .=
" AND taux = ".((float) $revenuestamp);
359 $sqlrevenuestamp .=
" AND active = 1";
360 $resqlrevenuestamp = $db->query($sqlrevenuestamp);
362 if ($resqlrevenuestamp) {
363 $num_rows_revenuestamp = $db->num_rows($resqlrevenuestamp);
364 if ($num_rows_revenuestamp > 1) {
365 dol_print_error($db,
'Failed 2 or more lines for the revenue stamp of your country. Check the dictionary of revenue stamp.');
367 $objrevenuestamp = $db->fetch_object($resqlrevenuestamp);
368 if ($objrevenuestamp) {
369 $compta_revenuestamp = $objrevenuestamp->accountancy_code_sell;
375 if (empty($tabrevenuestamp[$obj->rowid][$compta_revenuestamp]) && !empty($revenuestamp)) {
377 $tabttc[$obj->rowid][$compta_soc] += $obj->revenuestamp;
378 $tabrevenuestamp[$obj->rowid][$compta_revenuestamp] = $obj->revenuestamp;
381 $tabcompany[$obj->rowid] = array(
383 'name' => $obj->name,
384 'code_client' => $obj->code_client,
385 'accountancy_code_customer_general' => $accountancy_code_customer_general,
386 'code_compta' => $compta_soc
392 'tabfac' => &$tabfac,
394 'tabtva' => &$tabtva,
395 'def_tva' => &$def_tva,
396 'tabwarranty' => &$tabwarranty,
397 'tabrevenuestamp' => &$tabrevenuestamp,
398 'tabttc' => &$tabttc,
399 'tablocaltax1' => &$tablocaltax1,
400 'tablocaltax2' => &$tablocaltax2,
401 'tabcompany' => &$tabcompany,
402 'vatdata_cache' => &$vatdata_cache,
404 $reshook = $hookmanager->executeHooks(
'processingJournalData', $parameters);
409 if ($i >
getDolGlobalInt(
'ACCOUNTANCY_MAX_TOO_MANY_LINES_TO_PROCESS', 10000)) {
411 setEventMessages(
"ErrorTooManyLinesToProcessPleaseUseAMoreSelectiveFilter",
null,
'errors');
418 'tabfac' => &$tabfac,
420 'tabtva' => &$tabtva,
421 'def_tva' => &$def_tva,
422 'tabwarranty' => &$tabwarranty,
423 'tabrevenuestamp' => &$tabrevenuestamp,
424 'tabttc' => &$tabttc,
425 'tablocaltax1' => &$tablocaltax1,
426 'tablocaltax2' => &$tablocaltax2,
427 'tabcompany' => &$tabcompany,
428 'vatdata_cache' => &$vatdata_cache,
430 $reshook = $hookmanager->executeHooks(
'processedJournalData', $parameters);
436$errorforinvoice = array();
458if (!empty($tabfac)) {
462 COUNT(fd.rowid) as nb
464 ".MAIN_DB_PREFIX.
"facturedet as fd
467 AND fd.fk_code_ventilation <= 0
468 AND fd.total_ttc <> 0
469 AND fk_facture IN (".$db->sanitize(implode(
",", array_keys($tabfac))).
")
472 $resql = $db->query($sql);
474 $num = $db->num_rows($resql);
477 $obj = $db->fetch_object($resql);
479 $errorforinvoice[$obj->fk_facture] =
'somelinesarenotbound';
488if ($action ==
'writebookkeeping' && !$error && $user->hasRight(
'accounting',
'bind',
'write')) {
492 $companystatic =
new Societe($db);
493 $invoicestatic =
new Facture($db);
497 $accountingaccountcustomer->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'),
true);
500 $accountingaccountcustomerwarranty->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY'),
true);
502 foreach ($tabfac as $key => $val) {
510 $companystatic->id = $tabcompany[$key][
'id'];
511 $companystatic->name = $tabcompany[$key][
'name'];
512 $companystatic->accountancy_code_customer_general = $tabcompany[$key][
'accountancy_code_customer_general'];
513 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
514 $companystatic->code_compta_client = $tabcompany[$key][
'code_compta'];
515 $companystatic->code_client = $tabcompany[$key][
'code_client'];
516 $companystatic->client = 3;
518 $invoicestatic->id = $key;
519 $invoicestatic->ref = (string) $val[
"ref"];
520 $invoicestatic->type = $val[
"type"];
521 $invoicestatic->close_code = $val[
"close_code"];
526 $replacedinvoice = 0;
527 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
528 $replacedinvoice = 1;
529 $alreadydispatched = $invoicestatic->getVentilExportCompta();
530 if ($alreadydispatched) {
531 $replacedinvoice = 2;
536 if ($replacedinvoice == 1) {
542 if (isset($errorforinvoice[$key]) && $errorforinvoice[$key] ==
'somelinesarenotbound') {
545 setEventMessages($langs->trans(
'ErrorInvoiceContainsLinesNotYetBounded', $val[
'ref']),
null,
'errors');
550 if (isset($tabwarranty[$key]) && is_array($tabwarranty[$key])) {
551 foreach ($tabwarranty[$key] as $k => $mt) {
553 $bookkeeping->doc_date = $val[
"date"];
554 $bookkeeping->date_lim_reglement = $val[
"datereg"];
555 $bookkeeping->doc_ref = $val[
"ref"];
556 $bookkeeping->date_creation = $now;
557 $bookkeeping->doc_type =
'customer_invoice';
558 $bookkeeping->fk_doc = $key;
559 $bookkeeping->fk_docdet = 0;
560 $bookkeeping->thirdparty_code = $companystatic->code_client;
562 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
563 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
565 $bookkeeping->numero_compte =
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY');
566 $bookkeeping->label_compte = $accountingaccountcustomerwarranty->label;
568 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"RetainedWarranty"));
569 $bookkeeping->montant = $mt;
570 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
571 $bookkeeping->debit = ($mt >= 0) ? $mt : 0;
572 $bookkeeping->credit = ($mt < 0) ? -$mt : 0;
573 $bookkeeping->code_journal = $journal;
574 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
575 $bookkeeping->fk_user_author = $user->id;
576 $bookkeeping->entity =
$conf->entity;
578 $totaldebit += $bookkeeping->debit;
579 $totalcredit += $bookkeeping->credit;
581 $result = $bookkeeping->create($user);
583 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
586 $errorforinvoice[$key] =
'alreadyjournalized';
591 $errorforinvoice[$key] =
'other';
600 if (!$errorforline) {
601 foreach ($tabttc[$key] as $k => $mt) {
603 $bookkeeping->doc_date = $val[
"date"];
604 $bookkeeping->date_lim_reglement = $val[
"datereg"];
605 $bookkeeping->doc_ref = $val[
"ref"];
606 $bookkeeping->date_creation = $now;
607 $bookkeeping->doc_type =
'customer_invoice';
608 $bookkeeping->fk_doc = $key;
609 $bookkeeping->fk_docdet = 0;
610 $bookkeeping->thirdparty_code = $companystatic->code_client;
612 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
613 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
615 $bookkeeping->numero_compte = (!empty($tabcompany[$key][
'accountancy_code_customer_general']) && $tabcompany[$key][
'accountancy_code_customer_general'] !=
'-1') ? $tabcompany[$key][
'accountancy_code_customer_general'] : $cptcli;
616 $bookkeeping->label_compte = $accountingaccountcustomer->label;
618 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"SubledgerAccount"));
619 $bookkeeping->montant = $mt;
620 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
621 $bookkeeping->debit = ($mt >= 0) ? $mt : 0;
622 $bookkeeping->credit = ($mt < 0) ? -$mt : 0;
623 $bookkeeping->code_journal = $journal;
624 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
625 $bookkeeping->fk_user_author = $user->id;
626 $bookkeeping->entity =
$conf->entity;
628 $totaldebit += $bookkeeping->debit;
629 $totalcredit += $bookkeeping->credit;
631 $result = $bookkeeping->create($user);
633 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
636 $errorforinvoice[$key] =
'alreadyjournalized';
641 $errorforinvoice[$key] =
'other';
646 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/lettering.class.php';
649 $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id));
656 if (!$errorforline) {
657 foreach ($tabht[$key] as $k => $mt) {
658 if (empty(
$conf->cache[
'accountingaccountincurrententity'][$k])) {
660 $accountingaccount->fetch(0, $k,
true);
661 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
663 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity'][$k];
666 $label_account = $accountingaccount->label;
669 if ($accountingaccount->id > 0) {
671 $bookkeeping->doc_date = $val[
"date"];
672 $bookkeeping->date_lim_reglement = $val[
"datereg"];
673 $bookkeeping->doc_ref = $val[
"ref"];
674 $bookkeeping->date_creation = $now;
675 $bookkeeping->doc_type =
'customer_invoice';
676 $bookkeeping->fk_doc = $key;
677 $bookkeeping->fk_docdet = 0;
678 $bookkeeping->thirdparty_code = $companystatic->code_client;
682 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
683 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
685 $bookkeeping->subledger_account =
'';
686 $bookkeeping->subledger_label =
'';
689 $bookkeeping->subledger_account =
'';
690 $bookkeeping->subledger_label =
'';
693 $bookkeeping->numero_compte = $k;
694 $bookkeeping->label_compte = $label_account;
696 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $label_account);
697 $bookkeeping->montant = $mt;
698 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
699 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
700 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
701 $bookkeeping->code_journal = $journal;
702 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
703 $bookkeeping->fk_user_author = $user->id;
704 $bookkeeping->entity =
$conf->entity;
706 $totaldebit += $bookkeeping->debit;
707 $totalcredit += $bookkeeping->credit;
709 $result = $bookkeeping->create($user);
711 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
714 $errorforinvoice[$key] =
'alreadyjournalized';
719 $errorforinvoice[$key] =
'other';
728 if (!$errorforline) {
729 $listoftax = array(0, 1, 2);
730 foreach ($listoftax as $numtax) {
731 $arrayofvat = $tabtva;
733 $arrayofvat = $tablocaltax1;
736 $arrayofvat = $tablocaltax2;
739 foreach ($arrayofvat[$key] as $k => $mt) {
741 $accountingaccount->fetch(0, $k,
true);
742 $label_account = $accountingaccount->label;
745 $bookkeeping->doc_date = $val[
"date"];
746 $bookkeeping->date_lim_reglement = $val[
"datereg"];
747 $bookkeeping->doc_ref = $val[
"ref"];
748 $bookkeeping->date_creation = $now;
749 $bookkeeping->doc_type =
'customer_invoice';
750 $bookkeeping->fk_doc = $key;
751 $bookkeeping->fk_docdet = 0;
752 $bookkeeping->thirdparty_code = $companystatic->code_client;
754 $bookkeeping->subledger_account =
'';
755 $bookkeeping->subledger_label =
'';
757 $bookkeeping->numero_compte = $k;
758 $bookkeeping->label_compte = $label_account;
761 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
762 $labelvataccount = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
763 $labelvataccount .= ($numtax ?
' - Localtax '.$numtax :
'');
764 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $labelvataccount);
766 $bookkeeping->montant = $mt;
767 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
768 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
769 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
770 $bookkeeping->code_journal = $journal;
771 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
772 $bookkeeping->fk_user_author = $user->id;
773 $bookkeeping->entity =
$conf->entity;
775 $totaldebit += $bookkeeping->debit;
776 $totalcredit += $bookkeeping->credit;
778 $result = $bookkeeping->create($user);
780 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
783 $errorforinvoice[$key] =
'alreadyjournalized';
788 $errorforinvoice[$key] =
'other';
798 if (!$errorforline) {
799 if (isset($tabrevenuestamp[$key]) && is_array($tabrevenuestamp[$key])) {
800 foreach ($tabrevenuestamp[$key] as $k => $mt) {
802 $accountingaccount->fetch(0, $k,
true);
803 $label_account = $accountingaccount->label;
806 $bookkeeping->doc_date = $val[
"date"];
807 $bookkeeping->date_lim_reglement = $val[
"datereg"];
808 $bookkeeping->doc_ref = $val[
"ref"];
809 $bookkeeping->date_creation = $now;
810 $bookkeeping->doc_type =
'customer_invoice';
811 $bookkeeping->fk_doc = $key;
812 $bookkeeping->fk_docdet = 0;
813 $bookkeeping->thirdparty_code = $companystatic->code_client;
815 $bookkeeping->subledger_account =
'';
816 $bookkeeping->subledger_label =
'';
818 $bookkeeping->numero_compte = $k;
819 $bookkeeping->label_compte = $label_account;
821 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"RevenueStamp"));
822 $bookkeeping->montant = $mt;
823 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
824 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
825 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
826 $bookkeeping->code_journal = $journal;
827 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
828 $bookkeeping->fk_user_author = $user->id;
829 $bookkeeping->entity =
$conf->entity;
831 $totaldebit += $bookkeeping->debit;
832 $totalcredit += $bookkeeping->credit;
834 $result = $bookkeeping->create($user);
836 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
839 $errorforinvoice[$key] =
'alreadyjournalized';
844 $errorforinvoice[$key] =
'other';
854 if (!$errorforline && (
price2num($totaldebit,
'MT') !=
price2num($totalcredit,
'MT'))) {
857 $errorforinvoice[$key] =
'amountsnotbalanced';
858 setEventMessages(
'We Tried to insert a non balanced transaction in book for '.$invoicestatic->ref.
'. Canceled. Surely a bug.',
null,
'errors');
861 if (!$errorforline) {
867 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped"),
null,
'errors');
875 if (empty($error) && count($tabpay) > 0) {
877 } elseif (count($tabpay) == $error) {
880 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
886 if (count($tabpay) != $error) {
887 $param =
'id_journal='.$id_journal;
888 $param .=
'&date_startday='.$date_startday;
889 $param .=
'&date_startmonth='.$date_startmonth;
890 $param .=
'&date_startyear='.$date_startyear;
891 $param .=
'&date_endday='.$date_endday;
892 $param .=
'&date_endmonth='.$date_endmonth;
893 $param .=
'&date_endyear='.$date_endyear;
894 $param .=
'&in_bookkeeping='.$in_bookkeeping;
895 header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
906$form =
new Form($db);
909if ($action ==
'exportcsv' && !$error) {
913 $filename =
'journal';
914 $type_export =
'journal';
915 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
917 $companystatic =
new Client($db);
918 $invoicestatic =
new Facture($db);
921 foreach ($tabfac as $key => $val) {
922 $companystatic->id = $tabcompany[$key][
'id'];
923 $companystatic->name = $tabcompany[$key][
'name'];
924 $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;
925 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
926 $companystatic->code_compta_client = $tabcompany[$key][
'code_compta'];
927 $companystatic->code_client = $tabcompany[$key][
'code_client'];
928 $companystatic->client = 3;
930 $invoicestatic->id = $key;
931 $invoicestatic->ref = (string) $val[
"ref"];
932 $invoicestatic->type = $val[
"type"];
933 $invoicestatic->close_code = $val[
"close_code"];
938 $replacedinvoice = 0;
939 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
940 $replacedinvoice = 1;
941 $alreadydispatched = $invoicestatic->getVentilExportCompta();
942 if ($alreadydispatched) {
943 $replacedinvoice = 2;
948 if ($replacedinvoice == 1) {
953 if (
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY') && isset($tabwarranty[$key])) {
954 foreach ($tabwarranty[$key] as $k => $mt) {
956 print
'"'.$key.
'"'.$sep;
957 print
'"'.$date.
'"'.$sep;
958 print
'"'.$val[
"ref"].
'"'.$sep;
959 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
960 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
961 print
'"'.length_accountg(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY')).
'"'.$sep;
962 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
963 print
'"'.$langs->trans(
"Thirdparty").
'"'.$sep;
964 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"RetainedWarranty"))).
'"'.$sep;
965 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
966 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
967 print
'"'.$journal.
'"';
974 foreach ($tabttc[$key] as $k => $mt) {
976 print
'"'.$key.
'"'.$sep;
977 print
'"'.$date.
'"'.$sep;
978 print
'"'.$val[
"ref"].
'"'.$sep;
979 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
980 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
981 print
'"'.length_accountg($companystatic->accountancy_code_customer_general).
'"'.$sep;
982 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
983 print
'"'.$langs->trans(
"Thirdparty").
'"'.$sep;
984 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"Thirdparty"))).
'"'.$sep;
985 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
986 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
987 print
'"'.$journal.
'"';
993 foreach ($tabht[$key] as $k => $mt) {
995 $accountingaccount->fetch(0, $k,
true);
997 print
'"'.$key.
'"'.$sep;
998 print
'"'.$date.
'"'.$sep;
999 print
'"'.$val[
"ref"].
'"'.$sep;
1000 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
1001 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1002 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1004 print
'"'.csvClean(
dol_trunc($accountingaccount->label, 32)).
'"'.$sep;
1005 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $accountingaccount->label)).
'"'.$sep;
1006 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1007 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1008 print
'"'.$journal.
'"';
1014 $listoftax = array(0, 1, 2);
1015 foreach ($listoftax as $numtax) {
1016 $arrayofvat = $tabtva;
1018 $arrayofvat = $tablocaltax1;
1021 $arrayofvat = $tablocaltax2;
1024 foreach ($arrayofvat[$key] as $k => $mt) {
1026 print
'"'.$key.
'"'.$sep;
1027 print
'"'.$date.
'"'.$sep;
1028 print
'"'.$val[
"ref"].
'"'.$sep;
1029 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
1030 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1031 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1033 print
'"'.$langs->trans(
"VAT").
' - '.implode(
', ', $def_tva[$key][$k]).
' %"'.$sep;
1034 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"VAT").implode($def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
''))).
'"'.$sep;
1035 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1036 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1037 print
'"'.$journal.
'"';
1044 if (isset($tabrevenuestamp[$key])) {
1045 foreach ($tabrevenuestamp[$key] as $k => $mt) {
1047 print
'"'.$key.
'"'.$sep;
1048 print
'"'.$date.
'"'.$sep;
1049 print
'"'.$val[
"ref"].
'"'.$sep;
1050 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
1051 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1052 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1054 print
'"'.$langs->trans(
"RevenueStamp").
'"'.$sep;
1055 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"RevenueStamp"))).
'"'.$sep;
1056 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1057 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1058 print
'"'.$journal.
'"';
1068if (empty($action) || $action ==
'view') {
1069 $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1,
'', 1);
1070 $help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
1078 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
1080 $description .= $langs->trans(
"DepositsAreNotIncluded");
1082 $description .= $langs->trans(
"DepositsAreIncluded");
1085 $listofchoices = array(
'notyet' => $langs->trans(
"NotYetInGeneralLedger"),
'already' => $langs->trans(
"AlreadyInGeneralLedger"));
1086 $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);
1087 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
1089 $varlink =
'id_journal='.$id_journal;
1091 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
1096 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_fiscalyear WHERE entity = ".((int)
$conf->entity);
1097 $resql = $db->query($sql);
1099 $obj = $db->fetch_object($resql);
1100 if ($obj->nb == 0) {
1101 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheFiscalPeriodIsNotDefined");
1102 $desc =
' : '.$langs->trans(
"AccountancyAreaDescFiscalPeriod", 4,
'{link}');
1103 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"FiscalPeriod").
'</strong>', $desc);
1113 $acctCustomerNotConfigured = in_array(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'), [
'',
'-1']);
1114 if ($acctCustomerNotConfigured) {
1115 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
1116 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
1117 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
1121 print
'<br><div class="tabsAction tabsActionNoBottom centerimp">';
1122 if (
getDolGlobalString(
'ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping ==
'notyet') {
1123 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
1125 if ($acctCustomerNotConfigured) {
1126 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
1128 if ($in_bookkeeping ==
'notyet') {
1129 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
1131 print
'<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
1138 <script type="text/javascript">
1139 function launch_export() {
1140 $("div.fiche form input[name=\"action\"]").val("exportcsv");
1141 $("div.fiche form input[type=\"submit\"]").click();
1142 $("div.fiche form input[name=\"action\"]").val("");
1144 function writebookkeeping() {
1145 console.log("click on writebookkeeping");
1146 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
1147 $("div.fiche form input[type=\"submit\"]").click();
1148 $("div.fiche form input[name=\"action\"]").val("");
1157 print
'<div class="div-table-responsive">';
1158 print
"<table class=\"noborder\" width=\"100%\">";
1159 print
"<tr class=\"liste_titre\">";
1160 print
"<td>".$langs->trans(
"Date").
"</td>";
1161 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"InvoiceRef").
")</td>";
1162 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
1163 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
1164 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
1165 print
'<td class="center">'.$langs->trans(
"AccountingDebit").
"</td>";
1166 print
'<td class="center">'.$langs->trans(
"AccountingCredit").
"</td>";
1171 $companystatic =
new Client($db);
1172 $invoicestatic =
new Facture($db);
1175 foreach ($tabfac as $key => $val) {
1176 $companystatic->id = $tabcompany[$key][
'id'];
1177 $companystatic->name = $tabcompany[$key][
'name'];
1178 $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;
1179 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
1180 $companystatic->code_compta_client = $tabcompany[$key][
'code_compta'];
1181 $companystatic->code_client = $tabcompany[$key][
'code_client'];
1182 $companystatic->client = 3;
1184 $invoicestatic->id = $key;
1185 $invoicestatic->ref = (string) $val[
"ref"];
1186 $invoicestatic->type = $val[
"type"];
1187 $invoicestatic->close_code = $val[
"close_code"];
1192 $replacedinvoice = 0;
1193 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
1194 $replacedinvoice = 1;
1195 $alreadydispatched = $invoicestatic->getVentilExportCompta();
1196 if ($alreadydispatched) {
1197 $replacedinvoice = 2;
1202 if ($replacedinvoice == 1) {
1203 print
'<tr class="oddeven">';
1204 print
"<!-- Replaced invoice -->";
1205 print
"<td>".$date.
"</td>";
1206 print
"<td><strike>".$invoicestatic->getNomUrl(1).
"</strike></td>";
1209 print $langs->trans(
"Replaced");
1216 print
'<td class="right"></td>';
1217 print
'<td class="right"></td>';
1223 if (isset($errorforinvoice[$key]) && $errorforinvoice[$key] ==
'somelinesarenotbound') {
1224 print
'<tr class="oddeven">';
1225 print
"<!-- Some lines are not bound -->";
1226 print
"<td>".$date.
"</td>";
1227 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1230 print
'<span class="error">'.$langs->trans(
'ErrorInvoiceContainsLinesNotYetBoundedShort', $val[
'ref']).
'</span>';
1237 print
'<td class="right"></td>';
1238 print
'<td class="right"></td>';
1245 if (
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY') && isset($tabwarranty[$key]) && is_array($tabwarranty[$key])) {
1246 foreach ($tabwarranty[$key] as $k => $mt) {
1247 print
'<tr class="oddeven">';
1248 print
"<!-- Thirdparty warranty -->";
1249 print
"<td>" . $date .
"</td>";
1250 print
"<td>" . $invoicestatic->getNomUrl(1) .
"</td>";
1254 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1255 print
'<span class="error">' . $langs->trans(
"MainAccountForRetainedWarrantyNotDefined") .
'</span>';
1257 print $accountoshow;
1263 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1264 print
'<span class="error">' . $langs->trans(
"ThirdpartyAccountNotDefined") .
'</span>';
1266 print $accountoshow;
1269 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0), $invoicestatic->ref, $langs->trans(
"RetainedWarranty"), 1) .
"</td>";
1270 print
'<td class="right nowraponall amount">' . ($mt >= 0 ?
price($mt) :
'') .
"</td>";
1271 print
'<td class="right nowraponall amount">' . ($mt < 0 ?
price(-$mt) :
'') .
"</td>";
1277 foreach ($tabttc[$key] as $k => $mt) {
1278 print
'<tr class="oddeven">';
1279 print
"<!-- Thirdparty -->";
1280 print
"<td>".$date.
"</td>";
1281 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1284 $accountoshow =
length_accountg($companystatic->accountancy_code_customer_general);
1285 if (($accountoshow ==
"") || $accountoshow ==
"-1" || $accountoshow ==
'NotDefined') {
1286 print
'<span class="error">'.$langs->trans(
"MainAccountForCustomersNotDefined").
'</span>';
1288 print $accountoshow;
1294 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1295 print
'<span class="error">'.$langs->trans(
"ThirdpartyAccountNotDefined").
'</span>';
1297 print $accountoshow;
1300 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'customer'), $invoicestatic->ref, $langs->trans(
"SubledgerAccount"), 1) .
"</td>";
1301 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1302 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1309 foreach ($tabht[$key] as $k => $mt) {
1310 if (empty(
$conf->cache[
'accountingaccountincurrententity'][$k])) {
1312 $accountingaccount->fetch(0, $k,
true);
1313 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
1315 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity'][$k];
1318 print
'<tr class="oddeven">';
1319 print
"<!-- Product -->";
1320 print
"<td>".$date.
"</td>";
1321 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1325 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1326 print
'<span class="error">'.$langs->trans(
"ProductNotDefined").
'</span>';
1328 print $accountoshow;
1337 } elseif (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1338 print
'<span class="error">' . $langs->trans(
"ThirdpartyAccountNotDefined") .
'</span>';
1341 $companystatic->id = $tabcompany[$key][
'id'];
1342 $companystatic->name = $tabcompany[$key][
'name'];
1343 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'customer'), $invoicestatic->ref, $accountingaccount->label, 1) .
"</td>";
1344 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1345 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1352 $listoftax = array(0, 1, 2);
1353 foreach ($listoftax as $numtax) {
1354 $arrayofvat = $tabtva;
1356 $arrayofvat = $tablocaltax1;
1359 $arrayofvat = $tablocaltax2;
1363 foreach ($arrayofvat[$key] as $k => $mt) {
1365 print
'<tr class="oddeven">';
1366 print
"<!-- VAT -->";
1367 print
"<td>".$date.
"</td>";
1368 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1372 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1373 print
'<span class="error">'.$langs->trans(
"VATAccountNotDefined").
' ('.$langs->trans(
"AccountingJournalType2").
')</span>';
1375 print $accountoshow;
1383 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
1384 $labelvatrate = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
1385 $labelvatrate .= ($numtax ?
' - Localtax '.$numtax :
'');
1386 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'customer'), $invoicestatic->ref, $labelvatrate, 1) .
"</td>";
1387 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1388 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1397 if (isset($tabrevenuestamp[$key]) && is_array($tabrevenuestamp[$key])) {
1398 foreach ($tabrevenuestamp[$key] as $k => $mt) {
1399 print
'<tr class="oddeven">';
1400 print
"<!-- Thirdparty revenuestamp -->";
1401 print
"<td>" . $date .
"</td>";
1402 print
"<td>" . $invoicestatic->getNomUrl(1) .
"</td>";
1406 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1407 print
'<span class="error">' . $langs->trans(
"MainAccountForRevenueStampSaleNotDefined") .
'</span>';
1409 print $accountoshow;
1415 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'customer'), $invoicestatic->ref, $langs->trans(
"RevenueStamp"), 1) .
"</td>";
1416 print
'<td class="right nowraponall amount">' . ($mt < 0 ?
price(-$mt) :
'') .
"</td>";
1417 print
'<td class="right nowraponall amount">' . ($mt >= 0 ?
price($mt) :
'') .
"</td>";
1424 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.
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.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
getTaxesFromId($vatrate, $buyer=null, $seller=null, $firstparamisid=1)
Get tax (VAT) main information from Id.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.