33 require
'../../main.inc.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
40 require_once DOL_DOCUMENT_ROOT.
'/societe/class/client.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
44 $langs->loadLangs(array(
"commercial",
"compta",
"bills",
"other",
"accountancy",
"errors"));
46 $id_journal =
GETPOST(
'id_journal',
'int');
47 $action =
GETPOST(
'action',
'aZ09');
49 $date_startmonth =
GETPOST(
'date_startmonth');
50 $date_startday =
GETPOST(
'date_startday');
51 $date_startyear =
GETPOST(
'date_startyear');
52 $date_endmonth =
GETPOST(
'date_endmonth');
53 $date_endday =
GETPOST(
'date_endday');
54 $date_endyear =
GETPOST(
'date_endyear');
55 $in_bookkeeping =
GETPOST(
'in_bookkeeping');
56 if ($in_bookkeeping ==
'') {
57 $in_bookkeeping =
'notyet';
62 $hookmanager->initHooks(array(
'sellsjournal'));
63 $parameters = array();
69 if ($user->socid > 0) {
72 if (empty($user->rights->accounting->mouvements->lire)) {
81 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $user, $action);
87 $accountingjournalstatic->fetch($id_journal);
88 $journal = $accountingjournalstatic->code;
89 $journal_label = $accountingjournalstatic->label;
91 $date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
92 $date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
94 if (empty($date_startmonth) || empty($date_endmonth)) {
97 $date_start = $dates[
'date_start'];
98 $date_end = $dates[
'date_end'];
99 $pastmonthyear = $dates[
'pastmonthyear'];
100 $pastmonth = $dates[
'pastmonth'];
103 if (!
GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end))) {
108 $sql =
"SELECT f.rowid, f.ref, f.type, f.datef as df, f.ref_client, f.date_lim_reglement as dlr, f.close_code,";
109 $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,";
110 $sql .=
" s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur,";
111 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
112 $sql .=
" spe.accountancy_code_customer as code_compta,";
113 $sql .=
" spe.accountancy_code_supplier as code_compta_fournisseur,";
115 $sql .=
" s.code_compta as code_compta,";
116 $sql .=
" s.code_compta_fournisseur,";
118 $sql .=
" p.rowid as pid, p.ref as pref, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte,";
119 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
120 $sql .=
" ppe.accountancy_code_sell";
122 $sql .=
" p.accountancy_code_sell";
124 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
125 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = fd.fk_product";
126 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
127 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
129 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
130 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
131 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
132 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
133 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
135 $sql .=
" WHERE fd.fk_code_ventilation > 0";
136 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
')';
137 $sql .=
" AND f.fk_statut > 0";
138 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
143 $sql .=
" AND fd.product_type IN (0,1)";
144 if ($date_start && $date_end) {
145 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
148 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
149 $sql .=
" AND f.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
152 if ($in_bookkeeping ==
'already') {
153 $sql .=
" AND f.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')";
156 if ($in_bookkeeping ==
'notyet') {
157 $sql .=
" AND f.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')";
160 $sql .=
" ORDER BY f.datef, f.ref";
163 dol_syslog(
'accountancy/journal/sellsjournal.php', LOG_DEBUG);
164 $result = $db->query($sql);
171 $tablocaltax1 = array();
172 $tablocaltax2 = array();
173 $tabcompany = array();
175 $num = $db->num_rows($result);
178 $cptcli = (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER !=
"")) ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER :
'NotDefined';
179 $cpttva = (!empty($conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT :
'NotDefined';
183 $obj = $db->fetch_object($result);
186 $compta_soc = (!empty($obj->code_compta)) ? $obj->code_compta : $cptcli;
188 $compta_prod = $obj->compte;
189 if (empty($compta_prod)) {
190 if ($obj->product_type == 0) {
191 $compta_prod = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT :
'NotDefined';
193 $compta_prod = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT :
'NotDefined';
197 $vatdata =
getTaxesFromId($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''), $mysoc, $mysoc, 0);
198 $compta_tva = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cpttva);
199 $compta_localtax1 = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cpttva);
200 $compta_localtax2 = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cpttva);
203 if (
price2num($obj->tva_tx) || !empty($obj->vat_src_code)) {
204 $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.
')' :
''));
208 $line->fetch($obj->fdid);
211 $prev_progress = $line->get_prev_progress($obj->rowid);
215 if ($obj->situation_percent == 0) {
216 $situation_ratio = 0;
218 $situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent;
221 $situation_ratio = 1;
225 $tabfac[$obj->rowid][
"date"] = $db->jdate($obj->df);
226 $tabfac[$obj->rowid][
"datereg"] = $db->jdate($obj->dlr);
227 $tabfac[$obj->rowid][
"ref"] = $obj->ref;
228 $tabfac[$obj->rowid][
"type"] = $obj->type;
229 $tabfac[$obj->rowid][
"description"] = $obj->label_compte;
230 $tabfac[$obj->rowid][
"close_code"] = $obj->close_code;
234 if (!isset($tabttc[$obj->rowid][$compta_soc])) {
235 $tabttc[$obj->rowid][$compta_soc] = 0;
237 if (!isset($tabht[$obj->rowid][$compta_prod])) {
238 $tabht[$obj->rowid][$compta_prod] = 0;
240 if (!isset($tabtva[$obj->rowid][$compta_tva])) {
241 $tabtva[$obj->rowid][$compta_tva] = 0;
243 if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
244 $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
246 if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
247 $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
250 $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc * $situation_ratio;
251 $tabht[$obj->rowid][$compta_prod] += $obj->total_ht * $situation_ratio;
252 if (empty($line->tva_npr)) {
253 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio;
255 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1 * $situation_ratio;
256 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2 * $situation_ratio;
257 $tabcompany[$obj->rowid] = array(
259 'name' => $obj->name,
260 'code_client' => $obj->code_client,
261 'code_compta' => $compta_soc
270 $errorforinvoice = array();
273 foreach ($tabfac as $key => $val) {
274 $sql =
"SELECT COUNT(fd.rowid) as nb";
275 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
276 $sql .=
" WHERE fd.product_type <= 2 AND fd.fk_code_ventilation <= 0";
277 $sql .=
" AND fd.total_ttc <> 0 AND fk_facture = ".((int) $key);
278 $resql = $db->query($sql);
280 $obj = $db->fetch_object(
$resql);
282 $errorforinvoice[$key] =
'somelinesarenotbound';
292 if ($action ==
'writebookkeeping') {
296 $companystatic =
new Societe($db);
297 $invoicestatic =
new Facture($db);
300 $accountingaccountcustomer->fetch(
null, $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER,
true);
302 foreach ($tabfac as $key => $val) {
310 $companystatic->id = $tabcompany[$key][
'id'];
311 $companystatic->name = $tabcompany[$key][
'name'];
312 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
313 $companystatic->code_client = $tabcompany[$key][
'code_client'];
314 $companystatic->client = 3;
316 $invoicestatic->id = $key;
317 $invoicestatic->ref = (string) $val[
"ref"];
318 $invoicestatic->type = $val[
"type"];
319 $invoicestatic->close_code = $val[
"close_code"];
324 $replacedinvoice = 0;
325 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
326 $replacedinvoice = 1;
327 $alreadydispatched = $invoicestatic->getVentilExportCompta();
328 if ($alreadydispatched) {
329 $replacedinvoice = 2;
334 if ($replacedinvoice == 1) {
340 if ($errorforinvoice[$key] ==
'somelinesarenotbound') {
343 setEventMessages($langs->trans(
'ErrorInvoiceContainsLinesNotYetBounded', $val[
'ref']),
null,
'errors');
347 if (!$errorforline) {
348 foreach ($tabttc[$key] as $k => $mt) {
350 $bookkeeping->doc_date = $val[
"date"];
351 $bookkeeping->date_lim_reglement = $val[
"datereg"];
352 $bookkeeping->doc_ref = $val[
"ref"];
353 $bookkeeping->date_creation = $now;
354 $bookkeeping->doc_type =
'customer_invoice';
355 $bookkeeping->fk_doc = $key;
356 $bookkeeping->fk_docdet = 0;
357 $bookkeeping->thirdparty_code = $companystatic->code_client;
359 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
360 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
362 $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
363 $bookkeeping->label_compte = $accountingaccountcustomer->label;
365 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"SubledgerAccount");
366 $bookkeeping->montant = $mt;
367 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
368 $bookkeeping->debit = ($mt >= 0) ? $mt : 0;
369 $bookkeeping->credit = ($mt < 0) ? -$mt : 0;
370 $bookkeeping->code_journal = $journal;
371 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
372 $bookkeeping->fk_user_author = $user->id;
373 $bookkeeping->entity = $conf->entity;
375 $totaldebit += $bookkeeping->debit;
376 $totalcredit += $bookkeeping->credit;
378 $result = $bookkeeping->create($user);
380 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
383 $errorforinvoice[$key] =
'alreadyjournalized';
388 $errorforinvoice[$key] =
'other';
393 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/lettering.class.php';
395 $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id),
'customer_invoice');
402 if (!$errorforline) {
403 foreach ($tabht[$key] as $k => $mt) {
404 $resultfetch = $accountingaccount->fetch(
null, $k,
true);
405 $label_account = $accountingaccount->label;
408 if ($resultfetch > 0) {
410 $bookkeeping->doc_date = $val[
"date"];
411 $bookkeeping->date_lim_reglement = $val[
"datereg"];
412 $bookkeeping->doc_ref = $val[
"ref"];
413 $bookkeeping->date_creation = $now;
414 $bookkeeping->doc_type =
'customer_invoice';
415 $bookkeeping->fk_doc = $key;
416 $bookkeeping->fk_docdet = 0;
417 $bookkeeping->thirdparty_code = $companystatic->code_client;
419 if (!empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT)) {
421 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
422 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
424 $bookkeeping->subledger_account =
'';
425 $bookkeeping->subledger_label =
'';
428 $bookkeeping->subledger_account =
'';
429 $bookkeeping->subledger_label =
'';
432 $bookkeeping->numero_compte = $k;
433 $bookkeeping->label_compte = $label_account;
435 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref.
' - '.$label_account;
436 $bookkeeping->montant = $mt;
437 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
438 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
439 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
440 $bookkeeping->code_journal = $journal;
441 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
442 $bookkeeping->fk_user_author = $user->id;
443 $bookkeeping->entity = $conf->entity;
445 $totaldebit += $bookkeeping->debit;
446 $totalcredit += $bookkeeping->credit;
448 $result = $bookkeeping->create($user);
450 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
453 $errorforinvoice[$key] =
'alreadyjournalized';
458 $errorforinvoice[$key] =
'other';
467 if (!$errorforline) {
468 $listoftax = array(0, 1, 2);
469 foreach ($listoftax as $numtax) {
470 $arrayofvat = $tabtva;
472 $arrayofvat = $tablocaltax1;
475 $arrayofvat = $tablocaltax2;
478 foreach ($arrayofvat[$key] as $k => $mt) {
480 $accountingaccount->fetch(
null, $k,
true);
481 $label_account = $accountingaccount->label;
484 $bookkeeping->doc_date = $val[
"date"];
485 $bookkeeping->date_lim_reglement = $val[
"datereg"];
486 $bookkeeping->doc_ref = $val[
"ref"];
487 $bookkeeping->date_creation = $now;
488 $bookkeeping->doc_type =
'customer_invoice';
489 $bookkeeping->fk_doc = $key;
490 $bookkeeping->fk_docdet = 0;
491 $bookkeeping->thirdparty_code = $companystatic->code_client;
493 $bookkeeping->subledger_account =
'';
494 $bookkeeping->subledger_label =
'';
496 $bookkeeping->numero_compte = $k;
497 $bookkeeping->label_compte = $label_account;
499 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"VAT").
' '.join(
', ', $def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
'');
500 $bookkeeping->montant = $mt;
501 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
502 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
503 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
504 $bookkeeping->code_journal = $journal;
505 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
506 $bookkeeping->fk_user_author = $user->id;
507 $bookkeeping->entity = $conf->entity;
509 $totaldebit += $bookkeeping->debit;
510 $totalcredit += $bookkeeping->credit;
512 $result = $bookkeeping->create($user);
514 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
517 $errorforinvoice[$key] =
'alreadyjournalized';
522 $errorforinvoice[$key] =
'other';
532 if (!$errorforline && (
price2num($totaldebit,
'MT') !=
price2num($totalcredit,
'MT'))) {
535 $errorforinvoice[$key] =
'amountsnotbalanced';
536 setEventMessages(
'Try to insert a non balanced transaction in book for '.$invoicestatic->ref.
'. Canceled. Surely a bug.',
null,
'errors');
539 if (!$errorforline) {
545 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped"),
null,
'errors');
553 if (empty($error) && count($tabpay) > 0) {
555 } elseif (count($tabpay) == $error) {
558 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
564 if (count($tabpay) != $error) {
565 $param =
'id_journal='.$id_journal;
566 $param .=
'&date_startday='.$date_startday;
567 $param .=
'&date_startmonth='.$date_startmonth;
568 $param .=
'&date_startyear='.$date_startyear;
569 $param .=
'&date_endday='.$date_endday;
570 $param .=
'&date_endmonth='.$date_endmonth;
571 $param .=
'&date_endyear='.$date_endyear;
572 $param .=
'&in_bookkeeping='.$in_bookkeeping;
573 header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
587 if ($action ==
'exportcsv') {
588 $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
590 $filename =
'journal';
591 $type_export =
'journal';
592 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
594 $companystatic =
new Client($db);
595 $invoicestatic =
new Facture($db);
597 foreach ($tabfac as $key => $val) {
598 $companystatic->id = $tabcompany[$key][
'id'];
599 $companystatic->name = $tabcompany[$key][
'name'];
600 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
601 $companystatic->code_client = $tabcompany[$key][
'code_client'];
602 $companystatic->client = 3;
604 $invoicestatic->id = $key;
605 $invoicestatic->ref = (string) $val[
"ref"];
606 $invoicestatic->type = $val[
"type"];
607 $invoicestatic->close_code = $val[
"close_code"];
612 $replacedinvoice = 0;
613 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
614 $replacedinvoice = 1;
615 $alreadydispatched = $invoicestatic->getVentilExportCompta();
616 if ($alreadydispatched) {
617 $replacedinvoice = 2;
622 if ($replacedinvoice == 1) {
627 foreach ($tabttc[$key] as $k => $mt) {
629 print
'"'.$key.
'"'.$sep;
630 print
'"'.$date.
'"'.$sep;
631 print
'"'.$val[
"ref"].
'"'.$sep;
632 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
633 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
634 print
'"'.length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER).
'"'.$sep;
635 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
636 print
'"'.$langs->trans(
"Thirdparty").
'"'.$sep;
637 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"Thirdparty").
'"'.$sep;
638 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
639 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
640 print
'"'.$journal.
'"';
646 foreach ($tabht[$key] as $k => $mt) {
648 $accountingaccount->fetch(
null, $k,
true);
650 print
'"'.$key.
'"'.$sep;
651 print
'"'.$date.
'"'.$sep;
652 print
'"'.$val[
"ref"].
'"'.$sep;
653 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
654 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
655 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
657 print
'"'.utf8_decode(
dol_trunc($accountingaccount->label, 32)).
'"'.$sep;
658 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.
dol_trunc($accountingaccount->label, 32).
'"'.$sep;
659 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
660 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
661 print
'"'.$journal.
'"';
667 $listoftax = array(0, 1, 2);
668 foreach ($listoftax as $numtax) {
669 $arrayofvat = $tabtva;
671 $arrayofvat = $tablocaltax1;
674 $arrayofvat = $tablocaltax2;
677 foreach ($arrayofvat[$key] as $k => $mt) {
679 print
'"'.$key.
'"'.$sep;
680 print
'"'.$date.
'"'.$sep;
681 print
'"'.$val[
"ref"].
'"'.$sep;
682 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
683 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
684 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
686 print
'"'.$langs->trans(
"VAT").
' - '.join(
', ', $def_tva[$key][$k]).
' %"'.$sep;
687 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"VAT").join(
', ', $def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
'').
'"'.$sep;
688 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
689 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
690 print
'"'.$journal.
'"';
700 if (empty($action) || $action ==
'view') {
701 llxHeader(
'', $langs->trans(
"SellsJournal"));
703 $nom = $langs->trans(
"SellsJournal").
' | '.$accountingjournalstatic->getNomUrl(0, 1, 1,
'', 1);
708 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
709 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
710 $description .= $langs->trans(
"DepositsAreNotIncluded");
712 $description .= $langs->trans(
"DepositsAreIncluded");
715 $listofchoices = array(
'notyet'=>$langs->trans(
"NotYetInGeneralLedger"),
'already'=>$langs->trans(
"AlreadyInGeneralLedger"));
716 $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);
717 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.
$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
719 $varlink =
'id_journal='.$id_journal;
721 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
724 if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
"") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
'-1') {
725 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
726 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
727 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
731 print
'<div class="tabsAction tabsActionNoBottom centerimp">';
732 if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping ==
'notyet') {
733 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
735 if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
"") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
'-1') {
736 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
738 if ($in_bookkeeping ==
'notyet') {
739 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
741 print
'<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
748 <script type="text/javascript">
749 function launch_export() {
750 $("div.fiche form input[name=\"action\"]").val("exportcsv");
751 $("div.fiche form input[type=\"submit\"]").click();
752 $("div.fiche form input[name=\"action\"]").val("");
754 function writebookkeeping() {
755 console.log("click on writebookkeeping");
756 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
757 $("div.fiche form input[type=\"submit\"]").click();
758 $("div.fiche form input[name=\"action\"]").val("");
768 print
'<div class="div-table-responsive">';
769 print
"<table class=\"noborder\" width=\"100%\">";
770 print
"<tr class=\"liste_titre\">";
771 print
"<td>".$langs->trans(
"Date").
"</td>";
772 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"InvoiceRef").
")</td>";
773 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
774 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
775 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
776 print
'<td class="center">'.$langs->trans(
"Debit").
"</td>";
777 print
'<td class="center">'.$langs->trans(
"Credit").
"</td>";
782 $companystatic =
new Client($db);
783 $invoicestatic =
new Facture($db);
785 foreach ($tabfac as $key => $val) {
786 $companystatic->id = $tabcompany[$key][
'id'];
787 $companystatic->name = $tabcompany[$key][
'name'];
788 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
789 $companystatic->code_client = $tabcompany[$key][
'code_client'];
790 $companystatic->client = 3;
792 $invoicestatic->id = $key;
793 $invoicestatic->ref = (string) $val[
"ref"];
794 $invoicestatic->type = $val[
"type"];
795 $invoicestatic->close_code = $val[
"close_code"];
800 $replacedinvoice = 0;
801 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
802 $replacedinvoice = 1;
803 $alreadydispatched = $invoicestatic->getVentilExportCompta();
804 if ($alreadydispatched) {
805 $replacedinvoice = 2;
810 if ($replacedinvoice == 1) {
811 print
'<tr class="oddeven">';
812 print
"<!-- Replaced invoice -->";
813 print
"<td>".$date.
"</td>";
814 print
"<td><strike>".$invoicestatic->getNomUrl(1).
"</strike></td>";
817 print $langs->trans(
"Replaced");
824 print
'<td class="right"></td>';
825 print
'<td class="right"></td>';
830 if ($errorforinvoice[$key] ==
'somelinesarenotbound') {
831 print
'<tr class="oddeven">';
832 print
"<!-- Some lines are not bound -->";
833 print
"<td>".$date.
"</td>";
834 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
837 print
'<span class="error">'.$langs->trans(
'ErrorInvoiceContainsLinesNotYetBoundedShort', $val[
'ref']).
'</span>';
844 print
'<td class="right"></td>';
845 print
'<td class="right"></td>';
850 foreach ($tabttc[$key] as $k => $mt) {
851 print
'<tr class="oddeven">';
852 print
"<!-- Thirdparty -->";
853 print
"<td>".$date.
"</td>";
854 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
857 $accountoshow =
length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER);
858 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
859 print
'<span class="error">'.$langs->trans(
"MainAccountForCustomersNotDefined").
'</span>';
867 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
868 print
'<span class="error">'.$langs->trans(
"ThirdpartyAccountNotDefined").
'</span>';
873 print
"<td>".$companystatic->getNomUrl(0,
'customer', 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"SubledgerAccount").
"</td>";
874 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
875 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
880 foreach ($tabht[$key] as $k => $mt) {
882 $accountingaccount->fetch(
null, $k,
true);
884 print
'<tr class="oddeven">';
885 print
"<!-- Product -->";
886 print
"<td>".$date.
"</td>";
887 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
891 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
892 print
'<span class="error">'.$langs->trans(
"ProductNotDefined").
'</span>';
899 if (!empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT)) {
903 } elseif (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
904 print
'<span class="error">' . $langs->trans(
"ThirdpartyAccountNotDefined") .
'</span>';
907 $companystatic->id = $tabcompany[$key][
'id'];
908 $companystatic->name = $tabcompany[$key][
'name'];
909 print
"<td>".$companystatic->getNomUrl(0,
'customer', 16).
' - '.$invoicestatic->ref.
' - '.$accountingaccount->label.
"</td>";
910 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
911 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
916 $listoftax = array(0, 1, 2);
917 foreach ($listoftax as $numtax) {
918 $arrayofvat = $tabtva;
920 $arrayofvat = $tablocaltax1;
923 $arrayofvat = $tablocaltax2;
926 foreach ($arrayofvat[$key] as $k => $mt) {
928 print
'<tr class="oddeven">';
929 print
"<!-- VAT -->";
930 print
"<td>".$date.
"</td>";
931 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
935 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
936 print
'<span class="error">'.$langs->trans(
"VATAccountNotDefined").
' ('.$langs->trans(
"Sale").
')</span>';
944 print
"<td>".$companystatic->getNomUrl(0,
'customer', 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"VAT").
' '.join(
', ', $def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
'');
946 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
947 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";