34 require
'../../main.inc.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
38 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
40 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/societe/class/client.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
45 $langs->loadLangs(array(
"commercial",
"compta",
"bills",
"other",
"accountancy",
"errors"));
47 $id_journal =
GETPOST(
'id_journal',
'int');
48 $action =
GETPOST(
'action',
'aZ09');
50 $date_startmonth =
GETPOST(
'date_startmonth');
51 $date_startday =
GETPOST(
'date_startday');
52 $date_startyear =
GETPOST(
'date_startyear');
53 $date_endmonth =
GETPOST(
'date_endmonth');
54 $date_endday =
GETPOST(
'date_endday');
55 $date_endyear =
GETPOST(
'date_endyear');
56 $in_bookkeeping =
GETPOST(
'in_bookkeeping');
57 if ($in_bookkeeping ==
'') {
58 $in_bookkeeping =
'notyet';
63 $hookmanager->initHooks(array(
'sellsjournal'));
64 $parameters = array();
70 if ($user->socid > 0) {
73 if (!$user->hasRight(
'accounting',
'mouvements',
'lire')) {
82 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $user, $action);
88 $accountingjournalstatic->fetch($id_journal);
89 $journal = $accountingjournalstatic->code;
90 $journal_label = $accountingjournalstatic->label;
92 $date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
93 $date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
95 if (empty($date_startmonth) || empty($date_endmonth)) {
98 $date_start = $dates[
'date_start'];
99 $date_end = $dates[
'date_end'];
100 $pastmonthyear = $dates[
'pastmonthyear'];
101 $pastmonth = $dates[
'pastmonth'];
107 if (!
GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end))) {
112 $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,";
113 $sql .=
" fd.rowid as fdid, fd.description, fd.product_type, fd.total_ht, fd.total_tva, fd.total_localtax1, fd.total_localtax2, fd.tva_tx, fd.total_ttc, fd.situation_percent, fd.vat_src_code, fd.info_bits,";
114 $sql .=
" s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur,";
116 $sql .=
" spe.accountancy_code_customer as code_compta,";
117 $sql .=
" spe.accountancy_code_supplier as code_compta_fournisseur,";
119 $sql .=
" s.code_compta as code_compta,";
120 $sql .=
" s.code_compta_fournisseur,";
122 $sql .=
" p.rowid as pid, p.ref as pref, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte,";
124 $sql .=
" ppe.accountancy_code_sell";
126 $sql .=
" p.accountancy_code_sell";
128 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
129 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = fd.fk_product";
131 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
133 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
134 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
135 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
137 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
139 $sql .=
" WHERE fd.fk_code_ventilation > 0";
140 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
')';
141 $sql .=
" AND f.fk_statut > 0";
147 $sql .=
" AND fd.product_type IN (0,1)";
148 if ($date_start && $date_end) {
149 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
156 if ($in_bookkeeping ==
'already') {
157 $sql .=
" AND f.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')";
160 if ($in_bookkeeping ==
'notyet') {
161 $sql .=
" AND f.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')";
164 $sql .=
" ORDER BY f.datef, f.ref";
167 dol_syslog(
'accountancy/journal/sellsjournal.php', LOG_DEBUG);
168 $result = $db->query(
$sql);
174 $tabwarranty = array();
176 $tablocaltax1 = array();
177 $tablocaltax2 = array();
178 $tabcompany = array();
180 $num = $db->num_rows($result);
188 $obj = $db->fetch_object($result);
191 $compta_soc = (!empty($obj->code_compta)) ? $obj->code_compta : $cptcli;
193 $compta_prod = $obj->compte;
194 if (empty($compta_prod)) {
195 if ($obj->product_type == 0) {
202 $vatdata =
getTaxesFromId($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''), $mysoc, $mysoc, 0);
203 $compta_tva = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cpttva);
204 $compta_localtax1 = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cpttva);
205 $compta_localtax2 = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cpttva);
208 if (
price2num($obj->tva_tx) || !empty($obj->vat_src_code)) {
209 $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.
')' :
''));
213 $situation_ratio = 1;
215 if ($obj->situation_cycle_ref) {
217 if ($obj->situation_percent == 0) {
218 $situation_ratio = 0;
221 $line->fetch($obj->fdid);
224 $prev_progress = $line->get_prev_progress($obj->rowid);
226 $situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent;
232 $tabfac[$obj->rowid][
"date"] = $db->jdate($obj->df);
233 $tabfac[$obj->rowid][
"datereg"] = $db->jdate($obj->dlr);
234 $tabfac[$obj->rowid][
"ref"] = $obj->ref;
235 $tabfac[$obj->rowid][
"type"] = $obj->type;
236 $tabfac[$obj->rowid][
"description"] = $obj->label_compte;
237 $tabfac[$obj->rowid][
"close_code"] = $obj->close_code;
241 if (!isset($tabttc[$obj->rowid][$compta_soc])) {
242 $tabttc[$obj->rowid][$compta_soc] = 0;
244 if (!isset($tabht[$obj->rowid][$compta_prod])) {
245 $tabht[$obj->rowid][$compta_prod] = 0;
247 if (!isset($tabtva[$obj->rowid][$compta_tva])) {
248 $tabtva[$obj->rowid][$compta_tva] = 0;
250 if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
251 $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
253 if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
254 $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
262 $total_ttc = $obj->total_ttc * $situation_ratio;
263 if (
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY') && $obj->retained_warranty > 0) {
264 $retained_warranty = (double)
price2num($total_ttc * $obj->retained_warranty / 100,
'MT');
265 $tabwarranty[$obj->rowid][$compta_soc] += $retained_warranty;
266 $total_ttc -= $retained_warranty;
268 $tabttc[$obj->rowid][$compta_soc] += $total_ttc;
269 $tabht[$obj->rowid][$compta_prod] += $obj->total_ht * $situation_ratio;
270 $tva_npr = (($obj->info_bits & 1 == 1) ? 1 : 0);
272 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio;
274 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1 * $situation_ratio;
275 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2 * $situation_ratio;
278 $tabcompany[$obj->rowid] = array(
280 'name' => $obj->name,
281 'code_client' => $obj->code_client,
282 'code_compta' => $compta_soc
291 $errorforinvoice = array();
294 foreach ($tabfac as $key => $val) {
295 $sql =
"SELECT COUNT(fd.rowid) as nb";
296 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
297 $sql .=
" WHERE fd.product_type <= 2 AND fd.fk_code_ventilation <= 0";
298 $sql .=
" AND fd.total_ttc <> 0 AND fk_facture = ".((int) $key);
299 $resql = $db->query(
$sql);
301 $obj = $db->fetch_object($resql);
303 $errorforinvoice[$key] =
'somelinesarenotbound';
313 if ($action ==
'writebookkeeping') {
317 $companystatic =
new Societe($db);
318 $invoicestatic =
new Facture($db);
321 $accountingaccountcustomer->fetch(
null,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'),
true);
325 $accountingaccountcustomerwarranty->fetch(
null,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY'),
true);
327 foreach ($tabfac as $key => $val) {
335 $companystatic->id = $tabcompany[$key][
'id'];
336 $companystatic->name = $tabcompany[$key][
'name'];
337 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
338 $companystatic->code_client = $tabcompany[$key][
'code_client'];
339 $companystatic->client = 3;
341 $invoicestatic->id = $key;
342 $invoicestatic->ref = (string) $val[
"ref"];
343 $invoicestatic->type = $val[
"type"];
344 $invoicestatic->close_code = $val[
"close_code"];
349 $replacedinvoice = 0;
350 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
351 $replacedinvoice = 1;
352 $alreadydispatched = $invoicestatic->getVentilExportCompta();
353 if ($alreadydispatched) {
354 $replacedinvoice = 2;
359 if ($replacedinvoice == 1) {
365 if ($errorforinvoice[$key] ==
'somelinesarenotbound') {
368 setEventMessages($langs->trans(
'ErrorInvoiceContainsLinesNotYetBounded', $val[
'ref']),
null,
'errors');
372 if (!$errorforline) {
373 foreach ($tabwarranty[$key] as $k => $mt) {
375 $bookkeeping->doc_date = $val[
"date"];
376 $bookkeeping->date_lim_reglement = $val[
"datereg"];
377 $bookkeeping->doc_ref = $val[
"ref"];
378 $bookkeeping->date_creation = $now;
379 $bookkeeping->doc_type =
'customer_invoice';
380 $bookkeeping->fk_doc = $key;
381 $bookkeeping->fk_docdet = 0;
382 $bookkeeping->thirdparty_code = $companystatic->code_client;
384 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
385 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
387 $bookkeeping->numero_compte =
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY');
388 $bookkeeping->label_compte = $accountingaccountcustomerwarranty->label;
390 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"Retainedwarranty");
391 $bookkeeping->montant = $mt;
392 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
393 $bookkeeping->debit = ($mt >= 0) ? $mt : 0;
394 $bookkeeping->credit = ($mt < 0) ? -$mt : 0;
395 $bookkeeping->code_journal = $journal;
396 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
397 $bookkeeping->fk_user_author = $user->id;
398 $bookkeeping->entity = $conf->entity;
400 $totaldebit += $bookkeeping->debit;
401 $totalcredit += $bookkeeping->credit;
403 $result = $bookkeeping->create($user);
405 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
408 $errorforinvoice[$key] =
'alreadyjournalized';
413 $errorforinvoice[$key] =
'other';
421 if (!$errorforline) {
422 foreach ($tabttc[$key] as $k => $mt) {
424 $bookkeeping->doc_date = $val[
"date"];
425 $bookkeeping->date_lim_reglement = $val[
"datereg"];
426 $bookkeeping->doc_ref = $val[
"ref"];
427 $bookkeeping->date_creation = $now;
428 $bookkeeping->doc_type =
'customer_invoice';
429 $bookkeeping->fk_doc = $key;
430 $bookkeeping->fk_docdet = 0;
431 $bookkeeping->thirdparty_code = $companystatic->code_client;
433 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
434 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
437 $bookkeeping->label_compte = $accountingaccountcustomer->label;
439 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"SubledgerAccount");
440 $bookkeeping->montant = $mt;
441 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
442 $bookkeeping->debit = ($mt >= 0) ? $mt : 0;
443 $bookkeeping->credit = ($mt < 0) ? -$mt : 0;
444 $bookkeeping->code_journal = $journal;
445 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
446 $bookkeeping->fk_user_author = $user->id;
447 $bookkeeping->entity = $conf->entity;
449 $totaldebit += $bookkeeping->debit;
450 $totalcredit += $bookkeeping->credit;
452 $result = $bookkeeping->create($user);
454 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
457 $errorforinvoice[$key] =
'alreadyjournalized';
462 $errorforinvoice[$key] =
'other';
467 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/lettering.class.php';
470 $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id));
477 if (!$errorforline) {
478 foreach ($tabht[$key] as $k => $mt) {
479 $resultfetch = $accountingaccount->fetch(
null, $k,
true);
480 $label_account = $accountingaccount->label;
483 if ($resultfetch > 0) {
485 $bookkeeping->doc_date = $val[
"date"];
486 $bookkeeping->date_lim_reglement = $val[
"datereg"];
487 $bookkeeping->doc_ref = $val[
"ref"];
488 $bookkeeping->date_creation = $now;
489 $bookkeeping->doc_type =
'customer_invoice';
490 $bookkeeping->fk_doc = $key;
491 $bookkeeping->fk_docdet = 0;
492 $bookkeeping->thirdparty_code = $companystatic->code_client;
496 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
497 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
499 $bookkeeping->subledger_account =
'';
500 $bookkeeping->subledger_label =
'';
503 $bookkeeping->subledger_account =
'';
504 $bookkeeping->subledger_label =
'';
507 $bookkeeping->numero_compte = $k;
508 $bookkeeping->label_compte = $label_account;
510 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref.
' - '.$label_account;
511 $bookkeeping->montant = $mt;
512 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
513 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
514 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
515 $bookkeeping->code_journal = $journal;
516 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
517 $bookkeeping->fk_user_author = $user->id;
518 $bookkeeping->entity = $conf->entity;
520 $totaldebit += $bookkeeping->debit;
521 $totalcredit += $bookkeeping->credit;
523 $result = $bookkeeping->create($user);
525 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
528 $errorforinvoice[$key] =
'alreadyjournalized';
533 $errorforinvoice[$key] =
'other';
542 if (!$errorforline) {
543 $listoftax = array(0, 1, 2);
544 foreach ($listoftax as $numtax) {
545 $arrayofvat = $tabtva;
547 $arrayofvat = $tablocaltax1;
550 $arrayofvat = $tablocaltax2;
553 foreach ($arrayofvat[$key] as $k => $mt) {
555 $accountingaccount->fetch(
null, $k,
true);
556 $label_account = $accountingaccount->label;
559 $bookkeeping->doc_date = $val[
"date"];
560 $bookkeeping->date_lim_reglement = $val[
"datereg"];
561 $bookkeeping->doc_ref = $val[
"ref"];
562 $bookkeeping->date_creation = $now;
563 $bookkeeping->doc_type =
'customer_invoice';
564 $bookkeeping->fk_doc = $key;
565 $bookkeeping->fk_docdet = 0;
566 $bookkeeping->thirdparty_code = $companystatic->code_client;
568 $bookkeeping->subledger_account =
'';
569 $bookkeeping->subledger_label =
'';
571 $bookkeeping->numero_compte = $k;
572 $bookkeeping->label_compte = $label_account;
574 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"VAT").
' '.join(
', ', $def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
'');
575 $bookkeeping->montant = $mt;
576 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
577 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
578 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
579 $bookkeeping->code_journal = $journal;
580 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
581 $bookkeeping->fk_user_author = $user->id;
582 $bookkeeping->entity = $conf->entity;
584 $totaldebit += $bookkeeping->debit;
585 $totalcredit += $bookkeeping->credit;
587 $result = $bookkeeping->create($user);
589 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
592 $errorforinvoice[$key] =
'alreadyjournalized';
597 $errorforinvoice[$key] =
'other';
607 if (!$errorforline && (
price2num($totaldebit,
'MT') !=
price2num($totalcredit,
'MT'))) {
610 $errorforinvoice[$key] =
'amountsnotbalanced';
611 setEventMessages(
'Try to insert a non balanced transaction in book for '.$invoicestatic->ref.
'. Canceled. Surely a bug.',
null,
'errors');
614 if (!$errorforline) {
620 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped"),
null,
'errors');
628 if (empty($error) && count($tabpay) > 0) {
630 } elseif (count($tabpay) == $error) {
633 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
639 if (count($tabpay) != $error) {
640 $param =
'id_journal='.$id_journal;
641 $param .=
'&date_startday='.$date_startday;
642 $param .=
'&date_startmonth='.$date_startmonth;
643 $param .=
'&date_startyear='.$date_startyear;
644 $param .=
'&date_endday='.$date_endday;
645 $param .=
'&date_endmonth='.$date_endmonth;
646 $param .=
'&date_endyear='.$date_endyear;
647 $param .=
'&in_bookkeeping='.$in_bookkeeping;
648 header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
662 if ($action ==
'exportcsv') {
665 $filename =
'journal';
666 $type_export =
'journal';
667 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
669 $companystatic =
new Client($db);
670 $invoicestatic =
new Facture($db);
672 foreach ($tabfac as $key => $val) {
673 $companystatic->id = $tabcompany[$key][
'id'];
674 $companystatic->name = $tabcompany[$key][
'name'];
675 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
676 $companystatic->code_compta_client = $tabcompany[$key][
'code_compta'];
677 $companystatic->code_client = $tabcompany[$key][
'code_client'];
678 $companystatic->client = 3;
680 $invoicestatic->id = $key;
681 $invoicestatic->ref = (string) $val[
"ref"];
682 $invoicestatic->type = $val[
"type"];
683 $invoicestatic->close_code = $val[
"close_code"];
688 $replacedinvoice = 0;
689 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
690 $replacedinvoice = 1;
691 $alreadydispatched = $invoicestatic->getVentilExportCompta();
692 if ($alreadydispatched) {
693 $replacedinvoice = 2;
698 if ($replacedinvoice == 1) {
703 foreach ($tabwarranty[$key] as $k => $mt) {
705 print
'"'.$key.
'"'.$sep;
706 print
'"'.$date.
'"'.$sep;
707 print
'"'.$val[
"ref"].
'"'.$sep;
708 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
709 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
710 print
'"'.length_accountg(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY')).
'"'.$sep;
711 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
712 print
'"'.$langs->trans(
"Thirdparty").
'"'.$sep;
713 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"Retainedwarranty").
'"'.$sep;
714 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
715 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
716 print
'"'.$journal.
'"';
722 foreach ($tabttc[$key] as $k => $mt) {
724 print
'"'.$key.
'"'.$sep;
725 print
'"'.$date.
'"'.$sep;
726 print
'"'.$val[
"ref"].
'"'.$sep;
727 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
728 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
729 print
'"'.length_accountg(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER')).
'"'.$sep;
730 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
731 print
'"'.$langs->trans(
"Thirdparty").
'"'.$sep;
732 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"Thirdparty").
'"'.$sep;
733 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
734 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
735 print
'"'.$journal.
'"';
741 foreach ($tabht[$key] as $k => $mt) {
743 $accountingaccount->fetch(
null, $k,
true);
745 print
'"'.$key.
'"'.$sep;
746 print
'"'.$date.
'"'.$sep;
747 print
'"'.$val[
"ref"].
'"'.$sep;
748 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
749 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
750 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
752 print
'"'.utf8_decode(
dol_trunc($accountingaccount->label, 32)).
'"'.$sep;
753 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.
dol_trunc($accountingaccount->label, 32).
'"'.$sep;
754 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
755 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
756 print
'"'.$journal.
'"';
762 $listoftax = array(0, 1, 2);
763 foreach ($listoftax as $numtax) {
764 $arrayofvat = $tabtva;
766 $arrayofvat = $tablocaltax1;
769 $arrayofvat = $tablocaltax2;
772 foreach ($arrayofvat[$key] as $k => $mt) {
774 print
'"'.$key.
'"'.$sep;
775 print
'"'.$date.
'"'.$sep;
776 print
'"'.$val[
"ref"].
'"'.$sep;
777 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
778 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
779 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
781 print
'"'.$langs->trans(
"VAT").
' - '.join(
', ', $def_tva[$key][$k]).
' %"'.$sep;
782 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"VAT").join(
', ', $def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
'').
'"'.$sep;
783 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
784 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
785 print
'"'.$journal.
'"';
795 if (empty($action) || $action ==
'view') {
796 $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1,
'', 1);
805 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
807 $description .= $langs->trans(
"DepositsAreNotIncluded");
809 $description .= $langs->trans(
"DepositsAreIncluded");
812 $listofchoices = array(
'notyet'=>$langs->trans(
"NotYetInGeneralLedger"),
'already'=>$langs->trans(
"AlreadyInGeneralLedger"));
813 $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);
814 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.
$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
816 $varlink =
'id_journal='.$id_journal;
818 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
821 $acctCustomerNotConfigured = in_array(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'), [
'',
'-1']);
822 if ($acctCustomerNotConfigured) {
823 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
824 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
825 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
829 print
'<div class="tabsAction tabsActionNoBottom centerimp">';
830 if (
getDolGlobalString(
'ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping ==
'notyet') {
831 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
833 if ($acctCustomerNotConfigured) {
834 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
836 if ($in_bookkeeping ==
'notyet') {
837 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
839 print
'<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
846 <script type="text/javascript">
847 function launch_export() {
848 $("div.fiche form input[name=\"action\"]").val("exportcsv");
849 $("div.fiche form input[type=\"submit\"]").click();
850 $("div.fiche form input[name=\"action\"]").val("");
852 function writebookkeeping() {
853 console.log("click on writebookkeeping");
854 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
855 $("div.fiche form input[type=\"submit\"]").click();
856 $("div.fiche form input[name=\"action\"]").val("");
865 print
'<div class="div-table-responsive">';
866 print
"<table class=\"noborder\" width=\"100%\">";
867 print
"<tr class=\"liste_titre\">";
868 print
"<td>".$langs->trans(
"Date").
"</td>";
869 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"InvoiceRef").
")</td>";
870 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
871 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
872 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
873 print
'<td class="center">'.$langs->trans(
"AccountingDebit").
"</td>";
874 print
'<td class="center">'.$langs->trans(
"AccountingCredit").
"</td>";
879 $companystatic =
new Client($db);
880 $invoicestatic =
new Facture($db);
882 foreach ($tabfac as $key => $val) {
883 $companystatic->id = $tabcompany[$key][
'id'];
884 $companystatic->name = $tabcompany[$key][
'name'];
885 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
886 $companystatic->code_client = $tabcompany[$key][
'code_client'];
887 $companystatic->client = 3;
889 $invoicestatic->id = $key;
890 $invoicestatic->ref = (string) $val[
"ref"];
891 $invoicestatic->type = $val[
"type"];
892 $invoicestatic->close_code = $val[
"close_code"];
897 $replacedinvoice = 0;
898 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
899 $replacedinvoice = 1;
900 $alreadydispatched = $invoicestatic->getVentilExportCompta();
901 if ($alreadydispatched) {
902 $replacedinvoice = 2;
907 if ($replacedinvoice == 1) {
908 print
'<tr class="oddeven">';
909 print
"<!-- Replaced invoice -->";
910 print
"<td>".$date.
"</td>";
911 print
"<td><strike>".$invoicestatic->getNomUrl(1).
"</strike></td>";
914 print $langs->trans(
"Replaced");
921 print
'<td class="right"></td>';
922 print
'<td class="right"></td>';
928 if ($errorforinvoice[$key] ==
'somelinesarenotbound') {
929 print
'<tr class="oddeven">';
930 print
"<!-- Some lines are not bound -->";
931 print
"<td>".$date.
"</td>";
932 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
935 print
'<span class="error">'.$langs->trans(
'ErrorInvoiceContainsLinesNotYetBoundedShort', $val[
'ref']).
'</span>';
942 print
'<td class="right"></td>';
943 print
'<td class="right"></td>';
950 foreach ($tabwarranty[$key] as $k => $mt) {
951 print
'<tr class="oddeven">';
952 print
"<!-- Thirdparty warranty -->";
953 print
"<td>".$date.
"</td>";
954 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
958 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
959 print
'<span class="error">'.$langs->trans(
"MainAccountForCustomersNotDefined").
'</span>';
967 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
968 print
'<span class="error">'.$langs->trans(
"ThirdpartyAccountNotDefined").
'</span>';
973 print
"<td>".$companystatic->getNomUrl(0,
'customer', 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"Retainedwarranty").
"</td>";
974 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
975 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
980 foreach ($tabttc[$key] as $k => $mt) {
981 print
'<tr class="oddeven">';
982 print
"<!-- Thirdparty -->";
983 print
"<td>".$date.
"</td>";
984 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
988 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
989 print
'<span class="error">'.$langs->trans(
"MainAccountForCustomersNotDefined").
'</span>';
997 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
998 print
'<span class="error">'.$langs->trans(
"ThirdpartyAccountNotDefined").
'</span>';
1000 print $accountoshow;
1003 print
"<td>".$companystatic->getNomUrl(0,
'customer', 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"SubledgerAccount").
"</td>";
1004 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1005 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1012 foreach ($tabht[$key] as $k => $mt) {
1014 $accountingaccount->fetch(
null, $k,
true);
1016 print
'<tr class="oddeven">';
1017 print
"<!-- Product -->";
1018 print
"<td>".$date.
"</td>";
1019 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1023 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1024 print
'<span class="error">'.$langs->trans(
"ProductNotDefined").
'</span>';
1026 print $accountoshow;
1035 } elseif (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1036 print
'<span class="error">' . $langs->trans(
"ThirdpartyAccountNotDefined") .
'</span>';
1039 $companystatic->id = $tabcompany[$key][
'id'];
1040 $companystatic->name = $tabcompany[$key][
'name'];
1041 print
"<td>".$companystatic->getNomUrl(0,
'customer', 16).
' - '.$invoicestatic->ref.
' - '.$accountingaccount->label.
"</td>";
1042 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1043 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1050 $listoftax = array(0, 1, 2);
1051 foreach ($listoftax as $numtax) {
1052 $arrayofvat = $tabtva;
1054 $arrayofvat = $tablocaltax1;
1057 $arrayofvat = $tablocaltax2;
1060 foreach ($arrayofvat[$key] as $k => $mt) {
1062 print
'<tr class="oddeven">';
1063 print
"<!-- VAT -->";
1064 print
"<td>".$date.
"</td>";
1065 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1069 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1070 print
'<span class="error">'.$langs->trans(
"VATAccountNotDefined").
' ('.$langs->trans(
"Sale").
')</span>';
1072 print $accountoshow;
1078 print
"<td>".$companystatic->getNomUrl(0,
'customer', 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"VAT").
' '.join(
', ', $def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
'');
1080 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1081 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1091 print
'<tr class="oddeven"><td colspan="6"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
getDefaultDatesForTransfer()
Return Default dates for transfer based on periodicity option in accountancy setup.
journalHead($nom, $variante, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a page used to transfer/dispatch data in accounting.
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
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...)
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
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 '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getTaxesFromId($vatrate, $buyer=null, $seller=null, $firstparamisid=1)
Get tax (VAT) main information from Id.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return 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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return 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.
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.