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'];
104 if (!
GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end))) {
109 $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,";
110 $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,";
111 $sql .=
" s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur,";
113 $sql .=
" spe.accountancy_code_customer as code_compta,";
114 $sql .=
" spe.accountancy_code_supplier as code_compta_fournisseur,";
116 $sql .=
" s.code_compta as code_compta,";
117 $sql .=
" s.code_compta_fournisseur,";
119 $sql .=
" p.rowid as pid, p.ref as pref, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte,";
121 $sql .=
" ppe.accountancy_code_sell";
123 $sql .=
" p.accountancy_code_sell";
125 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
126 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = fd.fk_product";
128 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
130 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
131 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
132 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
134 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
136 $sql .=
" WHERE fd.fk_code_ventilation > 0";
137 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
')';
138 $sql .=
" AND f.fk_statut > 0";
144 $sql .=
" AND fd.product_type IN (0,1)";
145 if ($date_start && $date_end) {
146 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
153 if ($in_bookkeeping ==
'already') {
154 $sql .=
" AND f.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')";
157 if ($in_bookkeeping ==
'notyet') {
158 $sql .=
" AND f.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')";
161 $sql .=
" ORDER BY f.datef, f.ref";
164 dol_syslog(
'accountancy/journal/sellsjournal.php', LOG_DEBUG);
165 $result = $db->query(
$sql);
171 $tabwarranty = array();
173 $tablocaltax1 = array();
174 $tablocaltax2 = array();
175 $tabcompany = array();
177 $num = $db->num_rows($result);
185 $obj = $db->fetch_object($result);
188 $compta_soc = (!empty($obj->code_compta)) ? $obj->code_compta : $cptcli;
190 $compta_prod = $obj->compte;
191 if (empty($compta_prod)) {
192 if ($obj->product_type == 0) {
199 $vatdata =
getTaxesFromId($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''), $mysoc, $mysoc, 0);
200 $compta_tva = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cpttva);
201 $compta_localtax1 = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cpttva);
202 $compta_localtax2 = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cpttva);
205 if (
price2num($obj->tva_tx) || !empty($obj->vat_src_code)) {
206 $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.
')' :
''));
210 $situation_ratio = 1;
212 if ($obj->situation_cycle_ref) {
214 if ($obj->situation_percent == 0) {
215 $situation_ratio = 0;
218 $line->fetch($obj->fdid);
221 $prev_progress = $line->get_prev_progress($obj->rowid);
223 $situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent;
229 $tabfac[$obj->rowid][
"date"] = $db->jdate($obj->df);
230 $tabfac[$obj->rowid][
"datereg"] = $db->jdate($obj->dlr);
231 $tabfac[$obj->rowid][
"ref"] = $obj->ref;
232 $tabfac[$obj->rowid][
"type"] = $obj->type;
233 $tabfac[$obj->rowid][
"description"] = $obj->label_compte;
234 $tabfac[$obj->rowid][
"close_code"] = $obj->close_code;
238 if (!isset($tabttc[$obj->rowid][$compta_soc])) {
239 $tabttc[$obj->rowid][$compta_soc] = 0;
241 if (!isset($tabht[$obj->rowid][$compta_prod])) {
242 $tabht[$obj->rowid][$compta_prod] = 0;
244 if (!isset($tabtva[$obj->rowid][$compta_tva])) {
245 $tabtva[$obj->rowid][$compta_tva] = 0;
247 if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
248 $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
250 if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
251 $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
259 $total_ttc = $obj->total_ttc * $situation_ratio;
260 if (
getDolGlobalString(
'INVOICE_USE_RETAINED_WARRANTY') && $obj->retained_warranty > 0) {
261 $retained_warranty = (double)
price2num($total_ttc * $obj->retained_warranty / 100,
'MT');
262 $tabwarranty[$obj->rowid][$compta_soc] += $retained_warranty;
263 $total_ttc -= $retained_warranty;
265 $tabttc[$obj->rowid][$compta_soc] += $total_ttc;
266 $tabht[$obj->rowid][$compta_prod] += $obj->total_ht * $situation_ratio;
267 $tva_npr = (($obj->info_bits & 1 == 1) ? 1 : 0);
269 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio;
271 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1 * $situation_ratio;
272 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2 * $situation_ratio;
275 $tabcompany[$obj->rowid] = array(
277 'name' => $obj->name,
278 'code_client' => $obj->code_client,
279 'code_compta' => $compta_soc
288 $errorforinvoice = array();
291 foreach ($tabfac as $key => $val) {
292 $sql =
"SELECT COUNT(fd.rowid) as nb";
293 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
294 $sql .=
" WHERE fd.product_type <= 2 AND fd.fk_code_ventilation <= 0";
295 $sql .=
" AND fd.total_ttc <> 0 AND fk_facture = ".((int) $key);
296 $resql = $db->query(
$sql);
298 $obj = $db->fetch_object($resql);
300 $errorforinvoice[$key] =
'somelinesarenotbound';
310 if ($action ==
'writebookkeeping') {
314 $companystatic =
new Societe($db);
315 $invoicestatic =
new Facture($db);
318 $accountingaccountcustomer->fetch(
null,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'),
true);
322 $accountingaccountcustomerwarranty->fetch(
null,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY'),
true);
324 foreach ($tabfac as $key => $val) {
332 $companystatic->id = $tabcompany[$key][
'id'];
333 $companystatic->name = $tabcompany[$key][
'name'];
334 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
335 $companystatic->code_client = $tabcompany[$key][
'code_client'];
336 $companystatic->client = 3;
338 $invoicestatic->id = $key;
339 $invoicestatic->ref = (string) $val[
"ref"];
340 $invoicestatic->type = $val[
"type"];
341 $invoicestatic->close_code = $val[
"close_code"];
346 $replacedinvoice = 0;
347 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
348 $replacedinvoice = 1;
349 $alreadydispatched = $invoicestatic->getVentilExportCompta();
350 if ($alreadydispatched) {
351 $replacedinvoice = 2;
356 if ($replacedinvoice == 1) {
362 if ($errorforinvoice[$key] ==
'somelinesarenotbound') {
365 setEventMessages($langs->trans(
'ErrorInvoiceContainsLinesNotYetBounded', $val[
'ref']),
null,
'errors');
369 if (!$errorforline) {
370 foreach ($tabwarranty[$key] as $k => $mt) {
372 $bookkeeping->doc_date = $val[
"date"];
373 $bookkeeping->date_lim_reglement = $val[
"datereg"];
374 $bookkeeping->doc_ref = $val[
"ref"];
375 $bookkeeping->date_creation = $now;
376 $bookkeeping->doc_type =
'customer_invoice';
377 $bookkeeping->fk_doc = $key;
378 $bookkeeping->fk_docdet = 0;
379 $bookkeeping->thirdparty_code = $companystatic->code_client;
381 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
382 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
384 $bookkeeping->numero_compte =
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY');
385 $bookkeeping->label_compte = $accountingaccountcustomerwarranty->label;
387 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"Retainedwarranty");
388 $bookkeeping->montant = $mt;
389 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
390 $bookkeeping->debit = ($mt >= 0) ? $mt : 0;
391 $bookkeeping->credit = ($mt < 0) ? -$mt : 0;
392 $bookkeeping->code_journal = $journal;
393 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
394 $bookkeeping->fk_user_author = $user->id;
395 $bookkeeping->entity = $conf->entity;
397 $totaldebit += $bookkeeping->debit;
398 $totalcredit += $bookkeeping->credit;
400 $result = $bookkeeping->create($user);
402 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
405 $errorforinvoice[$key] =
'alreadyjournalized';
410 $errorforinvoice[$key] =
'other';
418 if (!$errorforline) {
419 foreach ($tabttc[$key] as $k => $mt) {
421 $bookkeeping->doc_date = $val[
"date"];
422 $bookkeeping->date_lim_reglement = $val[
"datereg"];
423 $bookkeeping->doc_ref = $val[
"ref"];
424 $bookkeeping->date_creation = $now;
425 $bookkeeping->doc_type =
'customer_invoice';
426 $bookkeeping->fk_doc = $key;
427 $bookkeeping->fk_docdet = 0;
428 $bookkeeping->thirdparty_code = $companystatic->code_client;
430 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
431 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
434 $bookkeeping->label_compte = $accountingaccountcustomer->label;
436 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"SubledgerAccount");
437 $bookkeeping->montant = $mt;
438 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
439 $bookkeeping->debit = ($mt >= 0) ? $mt : 0;
440 $bookkeeping->credit = ($mt < 0) ? -$mt : 0;
441 $bookkeeping->code_journal = $journal;
442 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
443 $bookkeeping->fk_user_author = $user->id;
444 $bookkeeping->entity = $conf->entity;
446 $totaldebit += $bookkeeping->debit;
447 $totalcredit += $bookkeeping->credit;
449 $result = $bookkeeping->create($user);
451 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
454 $errorforinvoice[$key] =
'alreadyjournalized';
459 $errorforinvoice[$key] =
'other';
464 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/lettering.class.php';
467 $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id));
474 if (!$errorforline) {
475 foreach ($tabht[$key] as $k => $mt) {
476 $resultfetch = $accountingaccount->fetch(
null, $k,
true);
477 $label_account = $accountingaccount->label;
480 if ($resultfetch > 0) {
482 $bookkeeping->doc_date = $val[
"date"];
483 $bookkeeping->date_lim_reglement = $val[
"datereg"];
484 $bookkeeping->doc_ref = $val[
"ref"];
485 $bookkeeping->date_creation = $now;
486 $bookkeeping->doc_type =
'customer_invoice';
487 $bookkeeping->fk_doc = $key;
488 $bookkeeping->fk_docdet = 0;
489 $bookkeeping->thirdparty_code = $companystatic->code_client;
493 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
494 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
496 $bookkeeping->subledger_account =
'';
497 $bookkeeping->subledger_label =
'';
500 $bookkeeping->subledger_account =
'';
501 $bookkeeping->subledger_label =
'';
504 $bookkeeping->numero_compte = $k;
505 $bookkeeping->label_compte = $label_account;
507 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref.
' - '.$label_account;
508 $bookkeeping->montant = $mt;
509 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
510 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
511 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
512 $bookkeeping->code_journal = $journal;
513 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
514 $bookkeeping->fk_user_author = $user->id;
515 $bookkeeping->entity = $conf->entity;
517 $totaldebit += $bookkeeping->debit;
518 $totalcredit += $bookkeeping->credit;
520 $result = $bookkeeping->create($user);
522 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
525 $errorforinvoice[$key] =
'alreadyjournalized';
530 $errorforinvoice[$key] =
'other';
539 if (!$errorforline) {
540 $listoftax = array(0, 1, 2);
541 foreach ($listoftax as $numtax) {
542 $arrayofvat = $tabtva;
544 $arrayofvat = $tablocaltax1;
547 $arrayofvat = $tablocaltax2;
550 foreach ($arrayofvat[$key] as $k => $mt) {
552 $accountingaccount->fetch(
null, $k,
true);
553 $label_account = $accountingaccount->label;
556 $bookkeeping->doc_date = $val[
"date"];
557 $bookkeeping->date_lim_reglement = $val[
"datereg"];
558 $bookkeeping->doc_ref = $val[
"ref"];
559 $bookkeeping->date_creation = $now;
560 $bookkeeping->doc_type =
'customer_invoice';
561 $bookkeeping->fk_doc = $key;
562 $bookkeeping->fk_docdet = 0;
563 $bookkeeping->thirdparty_code = $companystatic->code_client;
565 $bookkeeping->subledger_account =
'';
566 $bookkeeping->subledger_label =
'';
568 $bookkeeping->numero_compte = $k;
569 $bookkeeping->label_compte = $label_account;
571 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"VAT").
' '.join(
', ', $def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
'');
572 $bookkeeping->montant = $mt;
573 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
574 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
575 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
576 $bookkeeping->code_journal = $journal;
577 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
578 $bookkeeping->fk_user_author = $user->id;
579 $bookkeeping->entity = $conf->entity;
581 $totaldebit += $bookkeeping->debit;
582 $totalcredit += $bookkeeping->credit;
584 $result = $bookkeeping->create($user);
586 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
589 $errorforinvoice[$key] =
'alreadyjournalized';
594 $errorforinvoice[$key] =
'other';
604 if (!$errorforline && (
price2num($totaldebit,
'MT') !=
price2num($totalcredit,
'MT'))) {
607 $errorforinvoice[$key] =
'amountsnotbalanced';
608 setEventMessages(
'Try to insert a non balanced transaction in book for '.$invoicestatic->ref.
'. Canceled. Surely a bug.',
null,
'errors');
611 if (!$errorforline) {
617 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped"),
null,
'errors');
625 if (empty($error) && count($tabpay) > 0) {
627 } elseif (count($tabpay) == $error) {
630 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
636 if (count($tabpay) != $error) {
637 $param =
'id_journal='.$id_journal;
638 $param .=
'&date_startday='.$date_startday;
639 $param .=
'&date_startmonth='.$date_startmonth;
640 $param .=
'&date_startyear='.$date_startyear;
641 $param .=
'&date_endday='.$date_endday;
642 $param .=
'&date_endmonth='.$date_endmonth;
643 $param .=
'&date_endyear='.$date_endyear;
644 $param .=
'&in_bookkeeping='.$in_bookkeeping;
645 header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
659 if ($action ==
'exportcsv') {
662 $filename =
'journal';
663 $type_export =
'journal';
664 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
666 $companystatic =
new Client($db);
667 $invoicestatic =
new Facture($db);
669 foreach ($tabfac as $key => $val) {
670 $companystatic->id = $tabcompany[$key][
'id'];
671 $companystatic->name = $tabcompany[$key][
'name'];
672 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
673 $companystatic->code_compta_client = $tabcompany[$key][
'code_compta'];
674 $companystatic->code_client = $tabcompany[$key][
'code_client'];
675 $companystatic->client = 3;
677 $invoicestatic->id = $key;
678 $invoicestatic->ref = (string) $val[
"ref"];
679 $invoicestatic->type = $val[
"type"];
680 $invoicestatic->close_code = $val[
"close_code"];
685 $replacedinvoice = 0;
686 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
687 $replacedinvoice = 1;
688 $alreadydispatched = $invoicestatic->getVentilExportCompta();
689 if ($alreadydispatched) {
690 $replacedinvoice = 2;
695 if ($replacedinvoice == 1) {
700 foreach ($tabwarranty[$key] as $k => $mt) {
702 print
'"'.$key.
'"'.$sep;
703 print
'"'.$date.
'"'.$sep;
704 print
'"'.$val[
"ref"].
'"'.$sep;
705 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
706 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
707 print
'"'.length_accountg(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY')).
'"'.$sep;
708 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
709 print
'"'.$langs->trans(
"Thirdparty").
'"'.$sep;
710 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"Retainedwarranty").
'"'.$sep;
711 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
712 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
713 print
'"'.$journal.
'"';
719 foreach ($tabttc[$key] as $k => $mt) {
721 print
'"'.$key.
'"'.$sep;
722 print
'"'.$date.
'"'.$sep;
723 print
'"'.$val[
"ref"].
'"'.$sep;
724 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
725 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
726 print
'"'.length_accountg(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER')).
'"'.$sep;
727 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
728 print
'"'.$langs->trans(
"Thirdparty").
'"'.$sep;
729 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"Thirdparty").
'"'.$sep;
730 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
731 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
732 print
'"'.$journal.
'"';
738 foreach ($tabht[$key] as $k => $mt) {
740 $accountingaccount->fetch(
null, $k,
true);
742 print
'"'.$key.
'"'.$sep;
743 print
'"'.$date.
'"'.$sep;
744 print
'"'.$val[
"ref"].
'"'.$sep;
745 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
746 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
747 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
749 print
'"'.utf8_decode(
dol_trunc($accountingaccount->label, 32)).
'"'.$sep;
750 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.
dol_trunc($accountingaccount->label, 32).
'"'.$sep;
751 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
752 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
753 print
'"'.$journal.
'"';
759 $listoftax = array(0, 1, 2);
760 foreach ($listoftax as $numtax) {
761 $arrayofvat = $tabtva;
763 $arrayofvat = $tablocaltax1;
766 $arrayofvat = $tablocaltax2;
769 foreach ($arrayofvat[$key] as $k => $mt) {
771 print
'"'.$key.
'"'.$sep;
772 print
'"'.$date.
'"'.$sep;
773 print
'"'.$val[
"ref"].
'"'.$sep;
774 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
775 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
776 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
778 print
'"'.$langs->trans(
"VAT").
' - '.join(
', ', $def_tva[$key][$k]).
' %"'.$sep;
779 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"VAT").join(
', ', $def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
'').
'"'.$sep;
780 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
781 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
782 print
'"'.$journal.
'"';
792 if (empty($action) || $action ==
'view') {
793 $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1,
'', 1);
802 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
804 $description .= $langs->trans(
"DepositsAreNotIncluded");
806 $description .= $langs->trans(
"DepositsAreIncluded");
809 $listofchoices = array(
'notyet'=>$langs->trans(
"NotYetInGeneralLedger"),
'already'=>$langs->trans(
"AlreadyInGeneralLedger"));
810 $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);
811 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.
$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
813 $varlink =
'id_journal='.$id_journal;
815 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
818 $acctCustomerNotConfigured = in_array(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'), [
'',
'-1']);
819 if ($acctCustomerNotConfigured) {
820 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
821 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
822 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
826 print
'<div class="tabsAction tabsActionNoBottom centerimp">';
827 if (
getDolGlobalString(
'ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping ==
'notyet') {
828 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
830 if ($acctCustomerNotConfigured) {
831 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
833 if ($in_bookkeeping ==
'notyet') {
834 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
836 print
'<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
843 <script type="text/javascript">
844 function launch_export() {
845 $("div.fiche form input[name=\"action\"]").val("exportcsv");
846 $("div.fiche form input[type=\"submit\"]").click();
847 $("div.fiche form input[name=\"action\"]").val("");
849 function writebookkeeping() {
850 console.log("click on writebookkeeping");
851 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
852 $("div.fiche form input[type=\"submit\"]").click();
853 $("div.fiche form input[name=\"action\"]").val("");
862 print
'<div class="div-table-responsive">';
863 print
"<table class=\"noborder\" width=\"100%\">";
864 print
"<tr class=\"liste_titre\">";
865 print
"<td>".$langs->trans(
"Date").
"</td>";
866 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"InvoiceRef").
")</td>";
867 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
868 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
869 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
870 print
'<td class="center">'.$langs->trans(
"AccountingDebit").
"</td>";
871 print
'<td class="center">'.$langs->trans(
"AccountingCredit").
"</td>";
876 $companystatic =
new Client($db);
877 $invoicestatic =
new Facture($db);
879 foreach ($tabfac as $key => $val) {
880 $companystatic->id = $tabcompany[$key][
'id'];
881 $companystatic->name = $tabcompany[$key][
'name'];
882 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
883 $companystatic->code_client = $tabcompany[$key][
'code_client'];
884 $companystatic->client = 3;
886 $invoicestatic->id = $key;
887 $invoicestatic->ref = (string) $val[
"ref"];
888 $invoicestatic->type = $val[
"type"];
889 $invoicestatic->close_code = $val[
"close_code"];
894 $replacedinvoice = 0;
895 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
896 $replacedinvoice = 1;
897 $alreadydispatched = $invoicestatic->getVentilExportCompta();
898 if ($alreadydispatched) {
899 $replacedinvoice = 2;
904 if ($replacedinvoice == 1) {
905 print
'<tr class="oddeven">';
906 print
"<!-- Replaced invoice -->";
907 print
"<td>".$date.
"</td>";
908 print
"<td><strike>".$invoicestatic->getNomUrl(1).
"</strike></td>";
911 print $langs->trans(
"Replaced");
918 print
'<td class="right"></td>';
919 print
'<td class="right"></td>';
925 if ($errorforinvoice[$key] ==
'somelinesarenotbound') {
926 print
'<tr class="oddeven">';
927 print
"<!-- Some lines are not bound -->";
928 print
"<td>".$date.
"</td>";
929 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
932 print
'<span class="error">'.$langs->trans(
'ErrorInvoiceContainsLinesNotYetBoundedShort', $val[
'ref']).
'</span>';
939 print
'<td class="right"></td>';
940 print
'<td class="right"></td>';
947 foreach ($tabwarranty[$key] as $k => $mt) {
948 print
'<tr class="oddeven">';
949 print
"<!-- Thirdparty warranty -->";
950 print
"<td>".$date.
"</td>";
951 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
955 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
956 print
'<span class="error">'.$langs->trans(
"MainAccountForCustomersNotDefined").
'</span>';
964 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
965 print
'<span class="error">'.$langs->trans(
"ThirdpartyAccountNotDefined").
'</span>';
970 print
"<td>".$companystatic->getNomUrl(0,
'customer', 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"Retainedwarranty").
"</td>";
971 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
972 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
977 foreach ($tabttc[$key] as $k => $mt) {
978 print
'<tr class="oddeven">';
979 print
"<!-- Thirdparty -->";
980 print
"<td>".$date.
"</td>";
981 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
985 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
986 print
'<span class="error">'.$langs->trans(
"MainAccountForCustomersNotDefined").
'</span>';
994 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
995 print
'<span class="error">'.$langs->trans(
"ThirdpartyAccountNotDefined").
'</span>';
1000 print
"<td>".$companystatic->getNomUrl(0,
'customer', 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"SubledgerAccount").
"</td>";
1001 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1002 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1009 foreach ($tabht[$key] as $k => $mt) {
1011 $accountingaccount->fetch(
null, $k,
true);
1013 print
'<tr class="oddeven">';
1014 print
"<!-- Product -->";
1015 print
"<td>".$date.
"</td>";
1016 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1020 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1021 print
'<span class="error">'.$langs->trans(
"ProductNotDefined").
'</span>';
1023 print $accountoshow;
1032 } elseif (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1033 print
'<span class="error">' . $langs->trans(
"ThirdpartyAccountNotDefined") .
'</span>';
1036 $companystatic->id = $tabcompany[$key][
'id'];
1037 $companystatic->name = $tabcompany[$key][
'name'];
1038 print
"<td>".$companystatic->getNomUrl(0,
'customer', 16).
' - '.$invoicestatic->ref.
' - '.$accountingaccount->label.
"</td>";
1039 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1040 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1047 $listoftax = array(0, 1, 2);
1048 foreach ($listoftax as $numtax) {
1049 $arrayofvat = $tabtva;
1051 $arrayofvat = $tablocaltax1;
1054 $arrayofvat = $tablocaltax2;
1057 foreach ($arrayofvat[$key] as $k => $mt) {
1059 print
'<tr class="oddeven">';
1060 print
"<!-- VAT -->";
1061 print
"<td>".$date.
"</td>";
1062 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1066 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1067 print
'<span class="error">'.$langs->trans(
"VATAccountNotDefined").
' ('.$langs->trans(
"Sale").
')</span>';
1069 print $accountoshow;
1075 print
"<td>".$companystatic->getNomUrl(0,
'customer', 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"VAT").
' '.join(
', ', $def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
'');
1077 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1078 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1088 print
'<tr class="oddeven"><td colspan="6"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';