36require
'../../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
40require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/societe/class/client.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
56$langs->loadLangs(array(
"commercial",
"compta",
"bills",
"other",
"accountancy",
"errors"));
59$action =
GETPOST(
'action',
'aZ09');
61$date_startmonth =
GETPOSTINT(
'date_startmonth');
67$in_bookkeeping =
GETPOST(
'in_bookkeeping');
68if ($in_bookkeeping ==
'') {
69 $in_bookkeeping =
'notyet';
74$hookmanager->initHooks(array(
'sellsjournal'));
81if ($user->socid > 0) {
84if (!$user->hasRight(
'accounting',
'bind',
'write')) {
93$tabwarranty = array();
95$tablocaltax1 = array();
96$tablocaltax2 = array();
98$cptcli =
'NotDefined';
104$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $user, $action);
110$accountingjournalstatic->fetch($id_journal);
111$journal = $accountingjournalstatic->code;
112$journal_label = $accountingjournalstatic->label;
115$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
118$pastmonthyear =
null;
120if (empty($date_startmonth)) {
124 $pastmonthyear = $dates[
'pastmonthyear'];
125 $pastmonth = $dates[
'pastmonth'];
127if (empty($date_endmonth)) {
130 $date_end = $dates[
'date_end'];
131 $pastmonthyear = $dates[
'pastmonthyear'];
132 $pastmonth = $dates[
'pastmonth'];
138if (!GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end))) {
140 $date_end =
dol_get_last_day((
int) $pastmonthyear, (
int) $pastmonth,
false);
143$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,";
144$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,";
145$sql .=
" s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur,";
147 $sql .=
" spe.accountancy_code_customer_general,";
148 $sql .=
" spe.accountancy_code_customer as code_compta_client,";
149 $sql .=
" spe.accountancy_code_supplier_general,";
150 $sql .=
" spe.accountancy_code_supplier as code_compta_fournisseur,";
152 $sql .=
" s.accountancy_code_customer_general,";
153 $sql .=
" s.code_compta as code_compta_client,";
154 $sql .=
" s.accountancy_code_supplier_general,";
155 $sql .=
" s.code_compta_fournisseur,";
157$sql .=
" p.rowid as pid, p.ref as pref, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte,";
159 $sql .=
" ppe.accountancy_code_sell";
161 $sql .=
" p.accountancy_code_sell";
163$parameters = array();
164$reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
165$sql .= $hookmanager->resPrint;
166$sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
167$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = fd.fk_product";
169 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int)
$conf->entity);
171$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
172$sql .=
" JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
173$sql .=
" JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
175 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int)
$conf->entity);
177$parameters = array();
178$reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters);
179$sql .= $hookmanager->resPrint;
180$sql .=
" WHERE fd.fk_code_ventilation > 0";
181$sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
')';
182$sql .=
" AND f.fk_statut > 0";
188$sql .=
" AND fd.product_type IN (0,1)";
189if ($date_start && $date_end) {
190 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".
$db->idate($date_end).
"'";
193 $sql .=
" AND f.module_source = 'takepos'";
197 $sql .=
" AND f.datef >= '".$db->idate(
getDolGlobalInt(
'ACCOUNTING_DATE_START_BINDING')).
"'";
200if ($in_bookkeeping ==
'already') {
201 $sql .=
" AND f.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')";
204if ($in_bookkeeping ==
'notyet') {
205 $sql .=
" AND f.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')";
208$parameters = array();
209$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
210$sql .= $hookmanager->resPrint;
211$sql .=
" ORDER BY f.datef, f.ref";
214dol_syslog(
'accountancy/journal/sellsjournal.php', LOG_DEBUG);
219$tabwarranty = array();
220$tabrevenuestamp = array();
222$tablocaltax1 = array();
223$tablocaltax2 = array();
224$tabcompany = array();
225$vatdata_cache = array();
233$result =
$db->query($sql);
235 $num =
$db->num_rows($result);
239 $obj =
$db->fetch_object($result);
242 $accountancy_code_customer_general = (!empty($obj->accountancy_code_customer_general) && $obj->accountancy_code_customer_general !=
'-1') ? $obj->accountancy_code_customer_general : $cptcli;
243 $compta_soc = (!empty($obj->code_compta_client)) ? $obj->code_compta_client : $cptcli;
245 $compta_prod = $obj->compte;
246 if (empty($compta_prod)) {
247 if ($obj->product_type == 0) {
256 $tax_id = $obj->tva_tx . ($obj->vat_src_code ?
' (' . $obj->vat_src_code .
')' :
'');
257 if (array_key_exists($tax_id, $vatdata_cache)) {
258 $vatdata = $vatdata_cache[$tax_id];
262 $buyer->fetch($obj->socid);
268 $vatdata_cache[$tax_id] = $vatdata;
270 $compta_tva = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cpttva);
271 $compta_localtax1 = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cptlocaltax1);
272 $compta_localtax2 = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cptlocaltax2);
275 if (
price2num($obj->tva_tx) || !empty($obj->vat_src_code)) {
276 $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.
')' :
''));
277 if ($obj->localtax1_tx > 0.0) {
278 $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.
')' :
''));
280 if ($obj->localtax2_tx > 0.0) {
281 $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.
')' :
''));
286 $situation_ratio = 1;
288 if ($obj->situation_cycle_ref) {
290 if ($obj->situation_percent == 0) {
291 $situation_ratio = 0;
294 $line->fetch($obj->fdid);
297 $prev_progress = $line->get_prev_progress($obj->rowid);
299 $situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent;
304 $revenuestamp = (float)
price2num($obj->revenuestamp,
'MT');
307 $tabfac[$obj->rowid][
"date"] =
$db->jdate($obj->df);
308 $tabfac[$obj->rowid][
"datereg"] =
$db->jdate($obj->dlr);
309 $tabfac[$obj->rowid][
"ref"] = $obj->ref;
310 $tabfac[$obj->rowid][
"type"] = $obj->type;
311 $tabfac[$obj->rowid][
"description"] = $obj->label_compte;
312 $tabfac[$obj->rowid][
"close_code"] = $obj->close_code;
313 $tabfac[$obj->rowid][
"revenuestamp"] = $revenuestamp;
317 if (!isset($tabttc[$obj->rowid][$compta_soc])) {
318 $tabttc[$obj->rowid][$compta_soc] = 0;
320 if (!isset($tabht[$obj->rowid][$compta_prod])) {
321 $tabht[$obj->rowid][$compta_prod] = 0;
323 if (!isset($tabtva[$obj->rowid][$compta_tva])) {
324 $tabtva[$obj->rowid][$compta_tva] = 0;
326 if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
327 $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
329 if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
330 $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
339 $total_ttc = $obj->total_ttc * $situation_ratio;
341 $total_ttc = $obj->total_ttc;
345 if (
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY') && $obj->retained_warranty > 0 && (!
getDolGlobalString(
'INVOICE_RETAINED_WARRANTY_LIMITED_TO_FINAL_SITUATION') || !empty($obj->situation_final))) {
346 $retained_warranty = (float)
price2num($total_ttc * $obj->retained_warranty / 100,
'MT');
347 $tabwarranty[$obj->rowid][$compta_soc] += $retained_warranty;
348 $total_ttc -= $retained_warranty;
351 $tabttc[$obj->rowid][$compta_soc] += $total_ttc;
352 $tabht[$obj->rowid][$compta_prod] += $obj->total_ht * $situation_ratio;
353 $tva_npr = ((($obj->info_bits & 1) == 1) ? 1 : 0);
356 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
357 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
358 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
360 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio;
361 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1 * $situation_ratio;
362 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2 * $situation_ratio;
366 $compta_revenuestamp =
'NotDefined';
367 if (!empty($revenuestamp)) {
368 $sqlrevenuestamp =
"SELECT accountancy_code_sell FROM ".MAIN_DB_PREFIX.
"c_revenuestamp";
369 $sqlrevenuestamp .=
" WHERE fk_pays = ".((int)
$mysoc->country_id);
370 $sqlrevenuestamp .=
" AND taux = ".((float) $revenuestamp);
371 $sqlrevenuestamp .=
" AND active = 1";
372 $resqlrevenuestamp =
$db->query($sqlrevenuestamp);
374 if ($resqlrevenuestamp) {
375 $num_rows_revenuestamp =
$db->num_rows($resqlrevenuestamp);
376 if ($num_rows_revenuestamp > 1) {
377 dol_print_error(
$db,
'Failed 2 or more lines for the revenue stamp of your country. Check the dictionary of revenue stamp.');
379 $objrevenuestamp =
$db->fetch_object($resqlrevenuestamp);
380 if ($objrevenuestamp) {
381 $compta_revenuestamp = $objrevenuestamp->accountancy_code_sell;
387 if (empty($tabrevenuestamp[$obj->rowid][$compta_revenuestamp]) && !empty($revenuestamp)) {
389 $tabttc[$obj->rowid][$compta_soc] += $obj->revenuestamp;
390 $tabrevenuestamp[$obj->rowid][$compta_revenuestamp] = $obj->revenuestamp;
393 $tabcompany[$obj->rowid] = array(
395 'name' => $obj->name,
396 'code_client' => $obj->code_client,
397 'accountancy_code_customer_general' => $accountancy_code_customer_general,
398 'code_compta' => $compta_soc
404 'tabfac' => &$tabfac,
406 'tabtva' => &$tabtva,
407 'def_tva' => &$def_tva,
408 'tabwarranty' => &$tabwarranty,
409 'tabrevenuestamp' => &$tabrevenuestamp,
410 'tabttc' => &$tabttc,
411 'tablocaltax1' => &$tablocaltax1,
412 'tablocaltax2' => &$tablocaltax2,
413 'tabcompany' => &$tabcompany,
414 'vatdata_cache' => &$vatdata_cache,
416 $reshook = $hookmanager->executeHooks(
'processingJournalData', $parameters);
421 if ($i >
getDolGlobalInt(
'ACCOUNTANCY_MAX_TOO_MANY_LINES_TO_PROCESS', 10000)) {
423 setEventMessages(
"ErrorTooManyLinesToProcessPleaseUseAMoreSelectiveFilter",
null,
'errors');
430 'tabfac' => &$tabfac,
432 'tabtva' => &$tabtva,
433 'def_tva' => &$def_tva,
434 'tabwarranty' => &$tabwarranty,
435 'tabrevenuestamp' => &$tabrevenuestamp,
436 'tabttc' => &$tabttc,
437 'tablocaltax1' => &$tablocaltax1,
438 'tablocaltax2' => &$tablocaltax2,
439 'tabcompany' => &$tabcompany,
440 'vatdata_cache' => &$vatdata_cache,
442 $reshook = $hookmanager->executeHooks(
'processedJournalData', $parameters);
448$errorforinvoice = array();
470if (!empty($tabfac)) {
474 COUNT(fd.rowid) as nb
476 ".MAIN_DB_PREFIX.
"facturedet as fd
479 AND fd.fk_code_ventilation <= 0
480 AND fd.total_ttc <> 0
481 AND fk_facture IN (".
$db->sanitize(implode(
",", array_keys($tabfac))).
")
484 $resql =
$db->query($sql);
486 $num =
$db->num_rows($resql);
489 $obj =
$db->fetch_object($resql);
491 $errorforinvoice[$obj->fk_facture] =
'somelinesarenotbound';
500if ($action ==
'writebookkeeping' && !$error && $user->hasRight(
'accounting',
'bind',
'write')) {
509 $accountingaccountcustomer->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'),
true);
512 $accountingaccountcustomerwarranty->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY'),
true);
514 foreach ($tabfac as $key => $val) {
522 $companystatic->id = $tabcompany[$key][
'id'];
523 $companystatic->name = $tabcompany[$key][
'name'];
524 $companystatic->accountancy_code_customer_general = $tabcompany[$key][
'accountancy_code_customer_general'];
525 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
526 $companystatic->code_compta_client = $tabcompany[$key][
'code_compta'];
527 $companystatic->code_client = $tabcompany[$key][
'code_client'];
528 $companystatic->client = 3;
530 $invoicestatic->id = (int) $key;
531 $invoicestatic->ref = (
string) $val[
"ref"];
532 $invoicestatic->type = $val[
"type"];
533 $invoicestatic->close_code = $val[
"close_code"];
538 $replacedinvoice = 0;
539 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
540 $replacedinvoice = 1;
541 $alreadydispatched = $invoicestatic->getVentilExportCompta();
542 if ($alreadydispatched) {
543 $replacedinvoice = 2;
548 if ($replacedinvoice == 1) {
554 if (isset($errorforinvoice[$key]) && $errorforinvoice[$key] ==
'somelinesarenotbound') {
557 setEventMessages($langs->trans(
'ErrorInvoiceContainsLinesNotYetBounded', $val[
'ref']),
null,
'errors');
562 if (isset($tabwarranty[$key]) && is_array($tabwarranty[$key])) {
563 foreach ($tabwarranty[$key] as $k => $mt) {
565 $bookkeeping->doc_date = $val[
"date"];
566 $bookkeeping->date_lim_reglement = $val[
"datereg"];
567 $bookkeeping->doc_ref = $val[
"ref"];
568 $bookkeeping->date_creation = $now;
569 $bookkeeping->doc_type =
'customer_invoice';
570 $bookkeeping->fk_doc = (int) $key;
571 $bookkeeping->fk_docdet = 0;
572 $bookkeeping->thirdparty_code = $companystatic->code_client;
574 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
575 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
577 $bookkeeping->numero_compte =
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY');
578 $bookkeeping->label_compte = $accountingaccountcustomerwarranty->label;
580 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"RetainedWarranty"));
581 $bookkeeping->montant = $mt;
582 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
583 $bookkeeping->debit = ($mt >= 0) ? $mt : 0;
584 $bookkeeping->credit = ($mt < 0) ? -$mt : 0;
585 $bookkeeping->code_journal = $journal;
586 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
587 $bookkeeping->fk_user_author = $user->id;
588 $bookkeeping->entity =
$conf->entity;
590 $totaldebit += $bookkeeping->debit;
591 $totalcredit += $bookkeeping->credit;
593 $result = $bookkeeping->create($user);
595 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
598 $errorforinvoice[$key] =
'alreadyjournalized';
603 $errorforinvoice[$key] =
'other';
612 if (!$errorforline) {
613 foreach ($tabttc[$key] as $k => $mt) {
615 $bookkeeping->doc_date = $val[
"date"];
616 $bookkeeping->date_lim_reglement = $val[
"datereg"];
617 $bookkeeping->doc_ref = $val[
"ref"];
618 $bookkeeping->date_creation = $now;
619 $bookkeeping->doc_type =
'customer_invoice';
620 $bookkeeping->fk_doc = (int) $key;
621 $bookkeeping->fk_docdet = 0;
622 $bookkeeping->thirdparty_code = $companystatic->code_client;
624 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
625 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
627 $bookkeeping->numero_compte = (!empty($tabcompany[$key][
'accountancy_code_customer_general']) && $tabcompany[$key][
'accountancy_code_customer_general'] !=
'-1') ? $tabcompany[$key][
'accountancy_code_customer_general'] : $cptcli;
628 $bookkeeping->label_compte = $accountingaccountcustomer->label;
630 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"SubledgerAccount"));
631 $bookkeeping->montant = $mt;
632 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
633 $bookkeeping->debit = ($mt >= 0) ? $mt : 0;
634 $bookkeeping->credit = ($mt < 0) ? -$mt : 0;
635 $bookkeeping->code_journal = $journal;
636 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
637 $bookkeeping->fk_user_author = $user->id;
638 $bookkeeping->entity =
$conf->entity;
640 $totaldebit += $bookkeeping->debit;
641 $totalcredit += $bookkeeping->credit;
643 $result = $bookkeeping->create($user);
645 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
648 $errorforinvoice[$key] =
'alreadyjournalized';
653 $errorforinvoice[$key] =
'other';
658 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/lettering.class.php';
661 $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id));
668 if (!$errorforline) {
669 foreach ($tabht[$key] as $k => $mt) {
670 if (empty(
$conf->cache[
'accountingaccountincurrententity'][$k])) {
672 $accountingaccount->fetch(0, $k,
true);
673 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
675 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity'][$k];
678 $label_account = $accountingaccount->label;
681 if ($accountingaccount->id > 0) {
683 $bookkeeping->doc_date = $val[
"date"];
684 $bookkeeping->date_lim_reglement = $val[
"datereg"];
685 $bookkeeping->doc_ref = $val[
"ref"];
686 $bookkeeping->date_creation = $now;
687 $bookkeeping->doc_type =
'customer_invoice';
688 $bookkeeping->fk_doc = (int) $key;
689 $bookkeeping->fk_docdet = 0;
690 $bookkeeping->thirdparty_code = $companystatic->code_client;
694 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
695 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
697 $bookkeeping->subledger_account =
'';
698 $bookkeeping->subledger_label =
'';
701 $bookkeeping->subledger_account =
'';
702 $bookkeeping->subledger_label =
'';
705 $bookkeeping->numero_compte = $k;
706 $bookkeeping->label_compte = $label_account;
708 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $label_account);
709 $bookkeeping->montant = $mt;
710 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
711 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
712 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
713 $bookkeeping->code_journal = $journal;
714 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
715 $bookkeeping->fk_user_author = $user->id;
716 $bookkeeping->entity =
$conf->entity;
718 $totaldebit += $bookkeeping->debit;
719 $totalcredit += $bookkeeping->credit;
721 $result = $bookkeeping->create($user);
723 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
726 $errorforinvoice[$key] =
'alreadyjournalized';
731 $errorforinvoice[$key] =
'other';
740 if (!$errorforline) {
741 $listoftax = array(0, 1, 2);
742 foreach ($listoftax as $numtax) {
743 $arrayofvat = $tabtva;
745 $arrayofvat = $tablocaltax1;
748 $arrayofvat = $tablocaltax2;
751 foreach ($arrayofvat[$key] as $k => $mt) {
753 if (empty(
$conf->cache[
'accountingaccountincurrententity_vat'][$k])) {
755 $accountingaccount->fetch(0, $k,
true);
756 $conf->cache[
'accountingaccountincurrententity_vat'][$k] = $accountingaccount;
758 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity_vat'][$k];
761 $label_account = $accountingaccount->label;
764 $bookkeeping->doc_date = $val[
"date"];
765 $bookkeeping->date_lim_reglement = $val[
"datereg"];
766 $bookkeeping->doc_ref = $val[
"ref"];
767 $bookkeeping->date_creation = $now;
768 $bookkeeping->doc_type =
'customer_invoice';
769 $bookkeeping->fk_doc = (int) $key;
770 $bookkeeping->fk_docdet = 0;
771 $bookkeeping->thirdparty_code = $companystatic->code_client;
773 $bookkeeping->subledger_account =
'';
774 $bookkeeping->subledger_label =
'';
776 $bookkeeping->numero_compte = $k;
777 $bookkeeping->label_compte = $label_account;
780 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
781 $labelvataccount = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
782 $labelvataccount .= ($numtax ?
' - Localtax '.$numtax :
'');
783 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $labelvataccount);
785 $bookkeeping->montant = $mt;
786 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
787 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
788 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
789 $bookkeeping->code_journal = $journal;
790 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
791 $bookkeeping->fk_user_author = $user->id;
792 $bookkeeping->entity =
$conf->entity;
794 $totaldebit += $bookkeeping->debit;
795 $totalcredit += $bookkeeping->credit;
797 $result = $bookkeeping->create($user);
799 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
802 $errorforinvoice[$key] =
'alreadyjournalized';
807 $errorforinvoice[$key] =
'other';
817 if (!$errorforline) {
818 if (isset($tabrevenuestamp[$key]) && is_array($tabrevenuestamp[$key])) {
819 foreach ($tabrevenuestamp[$key] as $k => $mt) {
821 if (empty(
$conf->cache[
'accountingaccountincurrententity_rs'][$k])) {
823 $accountingaccount->fetch(0, $k,
true);
824 $conf->cache[
'accountingaccountincurrententity_rs'][$k] = $accountingaccount;
826 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity_rs'][$k];
829 $label_account = $accountingaccount->label;
832 $bookkeeping->doc_date = $val[
"date"];
833 $bookkeeping->date_lim_reglement = $val[
"datereg"];
834 $bookkeeping->doc_ref = $val[
"ref"];
835 $bookkeeping->date_creation = $now;
836 $bookkeeping->doc_type =
'customer_invoice';
837 $bookkeeping->fk_doc = (int) $key;
838 $bookkeeping->fk_docdet = 0;
839 $bookkeeping->thirdparty_code = $companystatic->code_client;
841 $bookkeeping->subledger_account =
'';
842 $bookkeeping->subledger_label =
'';
844 $bookkeeping->numero_compte = $k;
845 $bookkeeping->label_compte = $label_account;
847 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"RevenueStamp"));
848 $bookkeeping->montant = $mt;
849 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
850 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
851 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
852 $bookkeeping->code_journal = $journal;
853 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
854 $bookkeeping->fk_user_author = $user->id;
855 $bookkeeping->entity =
$conf->entity;
857 $totaldebit += $bookkeeping->debit;
858 $totalcredit += $bookkeeping->credit;
860 $result = $bookkeeping->create($user);
862 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
865 $errorforinvoice[$key] =
'alreadyjournalized';
870 $errorforinvoice[$key] =
'other';
880 if (!$errorforline && (
price2num($totaldebit,
'MT') !=
price2num($totalcredit,
'MT'))) {
883 $errorforinvoice[$key] =
'amountsnotbalanced';
884 setEventMessages(
'We Tried to insert a non balanced transaction in book for '.$invoicestatic->ref.
'. Canceled. Surely a bug.',
null,
'errors');
887 if (!$errorforline) {
893 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped"),
null,
'errors');
901 if (empty($error) && count($tabpay) > 0) {
903 } elseif (count($tabpay) == $error) {
906 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
912 if (count($tabpay) != $error) {
913 $param =
'id_journal='.$id_journal;
914 $param .=
'&date_startday='.$date_startday;
915 $param .=
'&date_startmonth='.$date_startmonth;
916 $param .=
'&date_startyear='.$date_startyear;
917 $param .=
'&date_endday='.$date_endday;
918 $param .=
'&date_endmonth='.$date_endmonth;
919 $param .=
'&date_endyear='.$date_endyear;
920 $param .=
'&in_bookkeeping='.$in_bookkeeping;
921 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?'.$param);
935if ($action ==
'exportcsv' && !$error) {
939 $filename =
'journal';
940 $type_export =
'journal';
941 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
947 foreach ($tabfac as $key => $val) {
948 $companystatic->id = $tabcompany[$key][
'id'];
949 $companystatic->name = $tabcompany[$key][
'name'];
950 $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;
951 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
952 $companystatic->code_compta_client = $tabcompany[$key][
'code_compta'];
953 $companystatic->code_client = $tabcompany[$key][
'code_client'];
954 $companystatic->client = 3;
956 $invoicestatic->id = (int) $key;
957 $invoicestatic->ref = (
string) $val[
"ref"];
958 $invoicestatic->type = $val[
"type"];
959 $invoicestatic->close_code = $val[
"close_code"];
964 $replacedinvoice = 0;
965 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
966 $replacedinvoice = 1;
967 $alreadydispatched = $invoicestatic->getVentilExportCompta();
968 if ($alreadydispatched) {
969 $replacedinvoice = 2;
974 if ($replacedinvoice == 1) {
979 if (
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY') && isset($tabwarranty[$key])) {
980 foreach ($tabwarranty[$key] as $k => $mt) {
982 print
'"'.$key.
'"'.$sep;
983 print
'"'.$date.
'"'.$sep;
984 print
'"'.$val[
"ref"].
'"'.$sep;
985 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
986 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
987 print
'"'.length_accountg(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY')).
'"'.$sep;
988 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
989 print
'"'.$langs->trans(
"ThirdParty").
'"'.$sep;
990 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"RetainedWarranty"))).
'"'.$sep;
991 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
992 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
993 print
'"'.$journal.
'"';
1000 foreach ($tabttc[$key] as $k => $mt) {
1002 print
'"'.$key.
'"'.$sep;
1003 print
'"'.$date.
'"'.$sep;
1004 print
'"'.$val[
"ref"].
'"'.$sep;
1005 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
1006 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
1007 print
'"'.length_accountg($companystatic->accountancy_code_customer_general).
'"'.$sep;
1008 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
1009 print
'"'.$langs->trans(
"ThirdParty").
'"'.$sep;
1010 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"ThirdParty"))).
'"'.$sep;
1011 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1012 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1013 print
'"'.$journal.
'"';
1019 foreach ($tabht[$key] as $k => $mt) {
1021 $accountingaccount->fetch(0, $k,
true);
1023 print
'"'.$key.
'"'.$sep;
1024 print
'"'.$date.
'"'.$sep;
1025 print
'"'.$val[
"ref"].
'"'.$sep;
1026 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
1027 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1028 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1030 print
'"'.csvClean(
dol_trunc($accountingaccount->label, 32)).
'"'.$sep;
1031 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $accountingaccount->label)).
'"'.$sep;
1032 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1033 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1034 print
'"'.$journal.
'"';
1040 $listoftax = array(0, 1, 2);
1041 foreach ($listoftax as $numtax) {
1042 $arrayofvat = $tabtva;
1044 $arrayofvat = $tablocaltax1;
1047 $arrayofvat = $tablocaltax2;
1050 foreach ($arrayofvat[$key] as $k => $mt) {
1052 print
'"'.$key.
'"'.$sep;
1053 print
'"'.$date.
'"'.$sep;
1054 print
'"'.$val[
"ref"].
'"'.$sep;
1055 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
1056 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1057 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1059 print
'"'.$langs->trans(
"VAT").
' - '.implode(
', ', $def_tva[$key][$k]).
' %"'.$sep;
1060 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"VAT").implode($def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
''))).
'"'.$sep;
1061 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1062 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1063 print
'"'.$journal.
'"';
1070 if (isset($tabrevenuestamp[$key])) {
1071 foreach ($tabrevenuestamp[$key] as $k => $mt) {
1073 print
'"'.$key.
'"'.$sep;
1074 print
'"'.$date.
'"'.$sep;
1075 print
'"'.$val[
"ref"].
'"'.$sep;
1076 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
1077 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1078 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1080 print
'"'.$langs->trans(
"RevenueStamp").
'"'.$sep;
1081 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"RevenueStamp"))).
'"'.$sep;
1082 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1083 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1084 print
'"'.$journal.
'"';
1094if (empty($action) || $action ==
'view') {
1095 $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1,
'', 1);
1096 $help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
1104 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
1106 $description .= $langs->trans(
"DepositsAreNotIncluded");
1108 $description .= $langs->trans(
"DepositsAreIncluded");
1111 $listofchoices = array(
'notyet' => $langs->trans(
"NotYetInGeneralLedger"),
'already' => $langs->trans(
"AlreadyInGeneralLedger"));
1112 $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);
1113 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
1115 $varlink =
'id_journal='.$id_journal;
1117 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
1122 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_fiscalyear WHERE entity = ".((int)
$conf->entity);
1123 $resql =
$db->query($sql);
1125 $obj =
$db->fetch_object($resql);
1126 if ($obj->nb == 0) {
1127 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheFiscalPeriodIsNotDefined");
1128 $desc =
' : '.$langs->trans(
"AccountancyAreaDescFiscalPeriod", 4,
'{link}');
1129 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"FiscalPeriod").
'</strong>', $desc);
1139 $acctCustomerNotConfigured = in_array(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'), [
'',
'-1']);
1140 if ($acctCustomerNotConfigured) {
1141 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
1142 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
1143 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
1147 print
'<br><div class="tabsAction tabsActionNoBottom centerimp">';
1148 if (
getDolGlobalString(
'ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping ==
'notyet') {
1149 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
1151 if ($acctCustomerNotConfigured) {
1152 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
1154 if ($in_bookkeeping ==
'notyet') {
1155 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
1157 print
'<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
1164 <script type="text/javascript">
1165 function launch_export() {
1166 $("div.fiche form input[name=\"action\"]").val("exportcsv");
1167 $("div.fiche form input[type=\"submit\"]").click();
1168 $("div.fiche form input[name=\"action\"]").val("");
1170 function writebookkeeping() {
1171 console.log("click on writebookkeeping");
1172 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
1173 $("div.fiche form input[type=\"submit\"]").click();
1174 $("div.fiche form input[name=\"action\"]").val("");
1183 print
'<div class="div-table-responsive">';
1184 print
"<table class=\"noborder\" width=\"100%\">";
1185 print
"<tr class=\"liste_titre\">";
1186 print
"<td>".$langs->trans(
"Date").
"</td>";
1187 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"InvoiceRef").
")</td>";
1188 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
1189 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
1190 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
1191 print
'<td class="center">'.$langs->trans(
"AccountingDebit").
"</td>";
1192 print
'<td class="center">'.$langs->trans(
"AccountingCredit").
"</td>";
1201 foreach ($tabfac as $key => $val) {
1202 $companystatic->id = $tabcompany[$key][
'id'];
1203 $companystatic->name = $tabcompany[$key][
'name'];
1204 $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;
1205 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
1206 $companystatic->code_compta_client = $tabcompany[$key][
'code_compta'];
1207 $companystatic->code_client = $tabcompany[$key][
'code_client'];
1208 $companystatic->client = 3;
1210 $invoicestatic->id = (int) $key;
1211 $invoicestatic->ref = (
string) $val[
"ref"];
1212 $invoicestatic->type = $val[
"type"];
1213 $invoicestatic->close_code = $val[
"close_code"];
1218 $replacedinvoice = 0;
1219 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
1220 $replacedinvoice = 1;
1221 $alreadydispatched = $invoicestatic->getVentilExportCompta();
1222 if ($alreadydispatched) {
1223 $replacedinvoice = 2;
1228 if ($replacedinvoice == 1) {
1229 print
'<tr class="oddeven">';
1230 print
"<!-- Replaced invoice -->";
1231 print
"<td>".$date.
"</td>";
1232 print
"<td><strike>".$invoicestatic->getNomUrl(1).
"</strike></td>";
1235 print $langs->trans(
"Replaced");
1242 print
'<td class="right"></td>';
1243 print
'<td class="right"></td>';
1249 if (isset($errorforinvoice[$key]) && $errorforinvoice[$key] ==
'somelinesarenotbound') {
1250 print
'<tr class="oddeven">';
1251 print
"<!-- Some lines are not bound -->";
1252 print
"<td>".$date.
"</td>";
1253 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1256 print
'<span class="error">'.$langs->trans(
'ErrorInvoiceContainsLinesNotYetBoundedShort', $val[
'ref']).
'</span>';
1263 print
'<td class="right"></td>';
1264 print
'<td class="right"></td>';
1271 if (
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY') && isset($tabwarranty[$key]) && is_array($tabwarranty[$key])) {
1272 foreach ($tabwarranty[$key] as $k => $mt) {
1273 print
'<tr class="oddeven">';
1274 print
"<!-- Thirdparty warranty -->";
1275 print
"<td>" . $date .
"</td>";
1276 print
"<td>" . $invoicestatic->getNomUrl(1) .
"</td>";
1280 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1281 print
'<span class="error">' . $langs->trans(
"MainAccountForRetainedWarrantyNotDefined") .
'</span>';
1283 print $accountoshow;
1289 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1290 print
'<span class="error">' . $langs->trans(
"ThirdpartyAccountNotDefined") .
'</span>';
1292 print $accountoshow;
1295 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0), $invoicestatic->ref, $langs->trans(
"RetainedWarranty"), 1) .
"</td>";
1296 print
'<td class="right nowraponall amount">' . ($mt >= 0 ?
price($mt) :
'') .
"</td>";
1297 print
'<td class="right nowraponall amount">' . ($mt < 0 ?
price(-$mt) :
'') .
"</td>";
1303 foreach ($tabttc[$key] as $k => $mt) {
1304 print
'<tr class="oddeven">';
1305 print
"<!-- Thirdparty -->";
1306 print
"<td>".$date.
"</td>";
1307 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1310 $accountoshow =
length_accountg($companystatic->accountancy_code_customer_general);
1311 if (($accountoshow ==
"") || $accountoshow ==
"-1" || $accountoshow ==
'NotDefined') {
1312 print
'<span class="error">'.$langs->trans(
"MainAccountForCustomersNotDefined").
'</span>';
1314 print $accountoshow;
1320 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1321 print
'<span class="error">'.$langs->trans(
"ThirdpartyAccountNotDefined").
'</span>';
1323 print $accountoshow;
1326 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'customer'), $invoicestatic->ref, $langs->trans(
"SubledgerAccount"), 1) .
"</td>";
1327 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1328 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1335 foreach ($tabht[$key] as $k => $mt) {
1336 if (empty(
$conf->cache[
'accountingaccountincurrententity'][$k])) {
1338 $accountingaccount->fetch(0, $k,
true);
1339 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
1341 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity'][$k];
1344 print
'<tr class="oddeven">';
1345 print
"<!-- Product -->";
1346 print
"<td>".$date.
"</td>";
1347 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1351 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1352 print
'<span class="error">'.$langs->trans(
"ProductNotDefined").
'</span>';
1354 print $accountoshow;
1363 } elseif (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1364 print
'<span class="error">' . $langs->trans(
"ThirdpartyAccountNotDefined") .
'</span>';
1367 $companystatic->id = $tabcompany[$key][
'id'];
1368 $companystatic->name = $tabcompany[$key][
'name'];
1369 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'customer'), $invoicestatic->ref, $accountingaccount->label, 1) .
"</td>";
1370 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1371 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1378 $listoftax = array(0, 1, 2);
1379 foreach ($listoftax as $numtax) {
1380 $arrayofvat = $tabtva;
1382 $arrayofvat = $tablocaltax1;
1385 $arrayofvat = $tablocaltax2;
1389 foreach ($arrayofvat[$key] as $k => $mt) {
1391 print
'<tr class="oddeven">';
1392 print
"<!-- VAT -->";
1393 print
"<td>".$date.
"</td>";
1394 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1398 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1399 print
'<span class="error">'.$langs->trans(
"VATAccountNotDefined").
' ('.$langs->trans(
"AccountingJournalType6").
')</span>';
1401 print $accountoshow;
1409 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
1410 $labelvatrate = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
1411 $labelvatrate .= ($numtax ?
' - Localtax '.$numtax :
'');
1412 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'customer'), $invoicestatic->ref, $labelvatrate, 1) .
"</td>";
1413 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1414 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1423 if (isset($tabrevenuestamp[$key]) && is_array($tabrevenuestamp[$key])) {
1424 foreach ($tabrevenuestamp[$key] as $k => $mt) {
1425 print
'<tr class="oddeven">';
1426 print
"<!-- Thirdparty revenuestamp -->";
1427 print
"<td>" . $date .
"</td>";
1428 print
"<td>" . $invoicestatic->getNomUrl(1) .
"</td>";
1432 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1433 print
'<span class="error">' . $langs->trans(
"MainAccountForRevenueStampSaleNotDefined") .
'</span>';
1435 print $accountoshow;
1441 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'customer'), $invoicestatic->ref, $langs->trans(
"RevenueStamp"), 1) .
"</td>";
1442 print
'<td class="right nowraponall amount">' . ($mt < 0 ?
price(-$mt) :
'') .
"</td>";
1443 print
'<td class="right nowraponall amount">' . ($mt >= 0 ?
price($mt) :
'') .
"</td>";
1450 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.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
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.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.