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;
114$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
115$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
118$pastmonthyear =
null;
120if (empty($date_startmonth)) {
123 $date_start = $dates[
'date_start'];
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.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, s.fk_pays,";
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).
"'";
194 $sql .=
" AND f.datef >= '".$db->idate(
getDolGlobalInt(
'ACCOUNTING_DATE_START_BINDING')).
"'";
197if ($in_bookkeeping ==
'already') {
198 $sql .=
" AND f.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')";
201if ($in_bookkeeping ==
'notyet') {
202 $sql .=
" AND f.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')";
205$parameters = array();
206$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
207$sql .= $hookmanager->resPrint;
208$sql .=
" ORDER BY f.datef, f.ref";
211dol_syslog(
'accountancy/journal/sellsjournal.php', LOG_DEBUG);
216$tabwarranty = array();
217$tabrevenuestamp = array();
219$tablocaltax1 = array();
220$tablocaltax2 = array();
221$tabcompany = array();
222$vatdata_cache = array();
230$result = $db->query($sql);
232 $num = $db->num_rows($result);
236 $obj = $db->fetch_object($result);
239 $accountancy_code_customer_general = (!empty($obj->accountancy_code_customer_general) && $obj->accountancy_code_customer_general !=
'-1') ? $obj->accountancy_code_customer_general : $cptcli;
240 $compta_soc = (!empty($obj->code_compta_client)) ? $obj->code_compta_client : $cptcli;
242 $compta_prod = $obj->compte;
243 if (empty($compta_prod)) {
244 if ($obj->product_type == 0) {
253 $tax_id = $obj->tva_tx . ($obj->vat_src_code ?
' (' . $obj->vat_src_code .
')' :
'');
257 $vatdata_cache_key = $tax_id.
'_'.(int) $obj->fk_pays;
259 $vatdata_cache_key = $tax_id;
261 if (array_key_exists($vatdata_cache_key, $vatdata_cache)) {
262 $vatdata = $vatdata_cache[$vatdata_cache_key];
266 $buyer->fetch($obj->socid);
272 $vatdata_cache[$vatdata_cache_key] = $vatdata;
274 $compta_tva = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cpttva);
275 $compta_localtax1 = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cptlocaltax1);
276 $compta_localtax2 = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cptlocaltax2);
279 if (
price2num($obj->tva_tx) || !empty($obj->vat_src_code)) {
280 $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.
')' :
''));
281 if ($obj->localtax1_tx > 0.0) {
282 $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.
')' :
''));
284 if ($obj->localtax2_tx > 0.0) {
285 $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.
')' :
''));
290 $situation_ratio = 1;
292 if ($obj->situation_cycle_ref) {
294 if ($obj->situation_percent == 0) {
295 $situation_ratio = 0;
298 $line->fetch($obj->fdid);
301 $prev_progress = $line->get_prev_progress($obj->rowid);
303 $situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent;
308 $revenuestamp = (float)
price2num($obj->revenuestamp,
'MT');
311 $tabfac[$obj->rowid][
"date"] = $db->jdate($obj->df);
312 $tabfac[$obj->rowid][
"datereg"] = $db->jdate($obj->dlr);
313 $tabfac[$obj->rowid][
"ref"] = $obj->ref;
314 $tabfac[$obj->rowid][
"type"] = $obj->type;
315 $tabfac[$obj->rowid][
"description"] = $obj->label_compte;
316 $tabfac[$obj->rowid][
"close_code"] = $obj->close_code;
317 $tabfac[$obj->rowid][
"revenuestamp"] = $revenuestamp;
321 if (!isset($tabttc[$obj->rowid][$compta_soc])) {
322 $tabttc[$obj->rowid][$compta_soc] = 0;
324 if (!isset($tabht[$obj->rowid][$compta_prod])) {
325 $tabht[$obj->rowid][$compta_prod] = 0;
327 if (!isset($tabtva[$obj->rowid][$compta_tva])) {
328 $tabtva[$obj->rowid][$compta_tva] = 0;
330 if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
331 $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
333 if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
334 $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
343 $total_ttc = $obj->total_ttc * $situation_ratio;
345 $total_ttc = $obj->total_ttc;
349 if (
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY') && $obj->retained_warranty > 0 && (!
getDolGlobalString(
'INVOICE_RETAINED_WARRANTY_LIMITED_TO_FINAL_SITUATION') || !empty($obj->situation_final))) {
350 $retained_warranty = (float)
price2num($total_ttc * $obj->retained_warranty / 100,
'MT');
351 $tabwarranty[$obj->rowid][$compta_soc] += $retained_warranty;
352 $total_ttc -= $retained_warranty;
355 $tabttc[$obj->rowid][$compta_soc] += $total_ttc;
356 $tabht[$obj->rowid][$compta_prod] += $obj->total_ht * $situation_ratio;
357 $tva_npr = ((($obj->info_bits & 1) == 1) ? 1 : 0);
360 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
361 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
362 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
364 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio;
365 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1 * $situation_ratio;
366 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2 * $situation_ratio;
370 $compta_revenuestamp =
'NotDefined';
371 if (!empty($revenuestamp)) {
372 $sqlrevenuestamp =
"SELECT accountancy_code_sell FROM ".MAIN_DB_PREFIX.
"c_revenuestamp";
373 $sqlrevenuestamp .=
" WHERE fk_pays = ".((int)
$mysoc->country_id);
374 $sqlrevenuestamp .=
" AND taux = ".((float) $revenuestamp);
375 $sqlrevenuestamp .=
" AND active = 1";
376 $resqlrevenuestamp = $db->query($sqlrevenuestamp);
378 if ($resqlrevenuestamp) {
379 $num_rows_revenuestamp = $db->num_rows($resqlrevenuestamp);
380 if ($num_rows_revenuestamp > 1) {
381 dol_print_error($db,
'Failed 2 or more lines for the revenue stamp of your country. Check the dictionary of revenue stamp.');
383 $objrevenuestamp = $db->fetch_object($resqlrevenuestamp);
384 if ($objrevenuestamp) {
385 $compta_revenuestamp = $objrevenuestamp->accountancy_code_sell;
391 if (empty($tabrevenuestamp[$obj->rowid][$compta_revenuestamp]) && !empty($revenuestamp)) {
393 $tabttc[$obj->rowid][$compta_soc] += $obj->revenuestamp;
394 $tabrevenuestamp[$obj->rowid][$compta_revenuestamp] = $obj->revenuestamp;
397 $tabcompany[$obj->rowid] = array(
399 'name' => $obj->name,
400 'code_client' => $obj->code_client,
401 'accountancy_code_customer_general' => $accountancy_code_customer_general,
402 'code_compta' => $compta_soc
408 'tabfac' => &$tabfac,
410 'tabtva' => &$tabtva,
411 'def_tva' => &$def_tva,
412 'tabwarranty' => &$tabwarranty,
413 'tabrevenuestamp' => &$tabrevenuestamp,
414 'tabttc' => &$tabttc,
415 'tablocaltax1' => &$tablocaltax1,
416 'tablocaltax2' => &$tablocaltax2,
417 'tabcompany' => &$tabcompany,
418 'vatdata_cache' => &$vatdata_cache,
420 $reshook = $hookmanager->executeHooks(
'processingJournalData', $parameters);
425 if ($i >
getDolGlobalInt(
'ACCOUNTANCY_MAX_TOO_MANY_LINES_TO_PROCESS', 10000)) {
427 setEventMessages(
"ErrorTooManyLinesToProcessPleaseUseAMoreSelectiveFilter",
null,
'errors');
434 'tabfac' => &$tabfac,
436 'tabtva' => &$tabtva,
437 'def_tva' => &$def_tva,
438 'tabwarranty' => &$tabwarranty,
439 'tabrevenuestamp' => &$tabrevenuestamp,
440 'tabttc' => &$tabttc,
441 'tablocaltax1' => &$tablocaltax1,
442 'tablocaltax2' => &$tablocaltax2,
443 'tabcompany' => &$tabcompany,
444 'vatdata_cache' => &$vatdata_cache,
446 $reshook = $hookmanager->executeHooks(
'processedJournalData', $parameters);
452$errorforinvoice = array();
474if (!empty($tabfac)) {
478 COUNT(fd.rowid) as nb
480 ".MAIN_DB_PREFIX.
"facturedet as fd
483 AND fd.fk_code_ventilation <= 0
484 AND fd.total_ttc <> 0
485 AND fk_facture IN (".$db->sanitize(implode(
",", array_keys($tabfac))).
")
488 $resql = $db->query($sql);
490 $num = $db->num_rows($resql);
493 $obj = $db->fetch_object($resql);
495 $errorforinvoice[$obj->fk_facture] =
'somelinesarenotbound';
504if ($action ==
'writebookkeeping' && !$error && $user->hasRight(
'accounting',
'bind',
'write')) {
508 $companystatic =
new Societe($db);
509 $invoicestatic =
new Facture($db);
513 $accountingaccountcustomer->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'),
true);
516 $accountingaccountcustomerwarranty->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY'),
true);
518 foreach ($tabfac as $key => $val) {
526 $companystatic->id = $tabcompany[$key][
'id'];
527 $companystatic->name = $tabcompany[$key][
'name'];
528 $companystatic->accountancy_code_customer_general = $tabcompany[$key][
'accountancy_code_customer_general'];
529 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
530 $companystatic->code_compta_client = $tabcompany[$key][
'code_compta'];
531 $companystatic->code_client = $tabcompany[$key][
'code_client'];
532 $companystatic->client = 3;
534 $invoicestatic->id = $key;
535 $invoicestatic->ref = (string) $val[
"ref"];
536 $invoicestatic->type = $val[
"type"];
537 $invoicestatic->close_code = $val[
"close_code"];
542 $replacedinvoice = 0;
543 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
544 $replacedinvoice = 1;
545 $alreadydispatched = $invoicestatic->getVentilExportCompta();
546 if ($alreadydispatched) {
547 $replacedinvoice = 2;
552 if ($replacedinvoice == 1) {
558 if (isset($errorforinvoice[$key]) && $errorforinvoice[$key] ==
'somelinesarenotbound') {
561 setEventMessages($langs->trans(
'ErrorInvoiceContainsLinesNotYetBounded', $val[
'ref']),
null,
'errors');
566 if (isset($tabwarranty[$key]) && is_array($tabwarranty[$key])) {
567 foreach ($tabwarranty[$key] as $k => $mt) {
569 $bookkeeping->doc_date = $val[
"date"];
570 $bookkeeping->date_lim_reglement = $val[
"datereg"];
571 $bookkeeping->doc_ref = $val[
"ref"];
572 $bookkeeping->date_creation = $now;
573 $bookkeeping->doc_type =
'customer_invoice';
574 $bookkeeping->fk_doc = $key;
575 $bookkeeping->fk_docdet = 0;
576 $bookkeeping->thirdparty_code = $companystatic->code_client;
578 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
579 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
581 $bookkeeping->numero_compte =
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY');
582 $bookkeeping->label_compte = $accountingaccountcustomerwarranty->label;
584 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"RetainedWarranty"));
585 $bookkeeping->montant = $mt;
586 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
587 $bookkeeping->debit = ($mt >= 0) ? $mt : 0;
588 $bookkeeping->credit = ($mt < 0) ? -$mt : 0;
589 $bookkeeping->code_journal = $journal;
590 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
591 $bookkeeping->fk_user_author = $user->id;
592 $bookkeeping->entity = $conf->entity;
594 $totaldebit += $bookkeeping->debit;
595 $totalcredit += $bookkeeping->credit;
597 $result = $bookkeeping->create($user);
599 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
602 $errorforinvoice[$key] =
'alreadyjournalized';
607 $errorforinvoice[$key] =
'other';
616 if (!$errorforline) {
617 foreach ($tabttc[$key] as $k => $mt) {
619 $bookkeeping->doc_date = $val[
"date"];
620 $bookkeeping->date_lim_reglement = $val[
"datereg"];
621 $bookkeeping->doc_ref = $val[
"ref"];
622 $bookkeeping->date_creation = $now;
623 $bookkeeping->doc_type =
'customer_invoice';
624 $bookkeeping->fk_doc = $key;
625 $bookkeeping->fk_docdet = 0;
626 $bookkeeping->thirdparty_code = $companystatic->code_client;
628 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
629 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
631 $bookkeeping->numero_compte = (!empty($tabcompany[$key][
'accountancy_code_customer_general']) && $tabcompany[$key][
'accountancy_code_customer_general'] !=
'-1') ? $tabcompany[$key][
'accountancy_code_customer_general'] : $cptcli;
632 $bookkeeping->label_compte = $accountingaccountcustomer->label;
634 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"SubledgerAccount"));
635 $bookkeeping->montant = $mt;
636 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
637 $bookkeeping->debit = ($mt >= 0) ? $mt : 0;
638 $bookkeeping->credit = ($mt < 0) ? -$mt : 0;
639 $bookkeeping->code_journal = $journal;
640 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
641 $bookkeeping->fk_user_author = $user->id;
642 $bookkeeping->entity = $conf->entity;
644 $totaldebit += $bookkeeping->debit;
645 $totalcredit += $bookkeeping->credit;
647 $result = $bookkeeping->create($user);
649 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
652 $errorforinvoice[$key] =
'alreadyjournalized';
657 $errorforinvoice[$key] =
'other';
662 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/lettering.class.php';
665 $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id));
672 if (!$errorforline) {
673 foreach ($tabht[$key] as $k => $mt) {
674 if (empty($conf->cache[
'accountingaccountincurrententity'][$k])) {
676 $accountingaccount->fetch(0, $k,
true);
677 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
679 $accountingaccount = $conf->cache[
'accountingaccountincurrententity'][$k];
682 $label_account = $accountingaccount->label;
685 if ($accountingaccount->id > 0) {
687 $bookkeeping->doc_date = $val[
"date"];
688 $bookkeeping->date_lim_reglement = $val[
"datereg"];
689 $bookkeeping->doc_ref = $val[
"ref"];
690 $bookkeeping->date_creation = $now;
691 $bookkeeping->doc_type =
'customer_invoice';
692 $bookkeeping->fk_doc = $key;
693 $bookkeeping->fk_docdet = 0;
694 $bookkeeping->thirdparty_code = $companystatic->code_client;
698 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
699 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
701 $bookkeeping->subledger_account =
'';
702 $bookkeeping->subledger_label =
'';
705 $bookkeeping->subledger_account =
'';
706 $bookkeeping->subledger_label =
'';
709 $bookkeeping->numero_compte = $k;
710 $bookkeeping->label_compte = $label_account;
712 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $label_account);
713 $bookkeeping->montant = $mt;
714 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
715 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
716 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
717 $bookkeeping->code_journal = $journal;
718 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
719 $bookkeeping->fk_user_author = $user->id;
720 $bookkeeping->entity = $conf->entity;
722 $totaldebit += $bookkeeping->debit;
723 $totalcredit += $bookkeeping->credit;
725 $result = $bookkeeping->create($user);
727 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
730 $errorforinvoice[$key] =
'alreadyjournalized';
735 $errorforinvoice[$key] =
'other';
744 if (!$errorforline) {
745 $listoftax = array(0, 1, 2);
746 foreach ($listoftax as $numtax) {
747 $arrayofvat = $tabtva;
749 $arrayofvat = $tablocaltax1;
752 $arrayofvat = $tablocaltax2;
755 foreach ($arrayofvat[$key] as $k => $mt) {
757 if (empty($conf->cache[
'accountingaccountincurrententity_vat'][$k])) {
759 $accountingaccount->fetch(0, $k,
true);
760 $conf->cache[
'accountingaccountincurrententity_vat'][$k] = $accountingaccount;
762 $accountingaccount = $conf->cache[
'accountingaccountincurrententity_vat'][$k];
765 $label_account = $accountingaccount->label;
768 $bookkeeping->doc_date = $val[
"date"];
769 $bookkeeping->date_lim_reglement = $val[
"datereg"];
770 $bookkeeping->doc_ref = $val[
"ref"];
771 $bookkeeping->date_creation = $now;
772 $bookkeeping->doc_type =
'customer_invoice';
773 $bookkeeping->fk_doc = $key;
774 $bookkeeping->fk_docdet = 0;
775 $bookkeeping->thirdparty_code = $companystatic->code_client;
777 $bookkeeping->subledger_account =
'';
778 $bookkeeping->subledger_label =
'';
780 $bookkeeping->numero_compte = $k;
781 $bookkeeping->label_compte = $label_account;
784 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
785 $labelvataccount = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
786 $labelvataccount .= ($numtax ?
' - Localtax '.$numtax :
'');
787 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $labelvataccount);
789 $bookkeeping->montant = $mt;
790 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
791 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
792 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
793 $bookkeeping->code_journal = $journal;
794 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
795 $bookkeeping->fk_user_author = $user->id;
796 $bookkeeping->entity = $conf->entity;
798 $totaldebit += $bookkeeping->debit;
799 $totalcredit += $bookkeeping->credit;
801 $result = $bookkeeping->create($user);
803 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
806 $errorforinvoice[$key] =
'alreadyjournalized';
811 $errorforinvoice[$key] =
'other';
821 if (!$errorforline) {
822 if (isset($tabrevenuestamp[$key]) && is_array($tabrevenuestamp[$key])) {
823 foreach ($tabrevenuestamp[$key] as $k => $mt) {
825 if (empty($conf->cache[
'accountingaccountincurrententity_rs'][$k])) {
827 $accountingaccount->fetch(0, $k,
true);
828 $conf->cache[
'accountingaccountincurrententity_rs'][$k] = $accountingaccount;
830 $accountingaccount = $conf->cache[
'accountingaccountincurrententity_rs'][$k];
833 $label_account = $accountingaccount->label;
836 $bookkeeping->doc_date = $val[
"date"];
837 $bookkeeping->date_lim_reglement = $val[
"datereg"];
838 $bookkeeping->doc_ref = $val[
"ref"];
839 $bookkeeping->date_creation = $now;
840 $bookkeeping->doc_type =
'customer_invoice';
841 $bookkeeping->fk_doc = $key;
842 $bookkeeping->fk_docdet = 0;
843 $bookkeeping->thirdparty_code = $companystatic->code_client;
845 $bookkeeping->subledger_account =
'';
846 $bookkeeping->subledger_label =
'';
848 $bookkeeping->numero_compte = $k;
849 $bookkeeping->label_compte = $label_account;
851 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans(
"RevenueStamp"));
852 $bookkeeping->montant = $mt;
853 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
854 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
855 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
856 $bookkeeping->code_journal = $journal;
857 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
858 $bookkeeping->fk_user_author = $user->id;
859 $bookkeeping->entity = $conf->entity;
861 $totaldebit += $bookkeeping->debit;
862 $totalcredit += $bookkeeping->credit;
864 $result = $bookkeeping->create($user);
866 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
869 $errorforinvoice[$key] =
'alreadyjournalized';
874 $errorforinvoice[$key] =
'other';
884 if (!$errorforline && (
price2num($totaldebit,
'MT') !=
price2num($totalcredit,
'MT'))) {
887 $errorforinvoice[$key] =
'amountsnotbalanced';
888 setEventMessages(
'We Tried to insert a non balanced transaction in book for '.$invoicestatic->ref.
'. Canceled. Surely a bug.',
null,
'errors');
891 if (!$errorforline) {
897 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped"),
null,
'errors');
905 if (empty($error) && count($tabpay) > 0) {
907 } elseif (count($tabpay) == $error) {
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 ?
'?'.$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 = $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);
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 = $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(
"AccountingJournalType2").
')</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.
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_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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.