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 (empty($user->rights->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.datef as df, f.ref_client, f.date_lim_reglement as dlr, f.close_code,";
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,";
111 $sql .=
" s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur,";
112 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
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,";
120 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
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";
127 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
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";
133 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
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";
139 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
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).
"'";
149 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
150 $sql .=
" AND f.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
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";
164 dol_syslog(
'accountancy/journal/sellsjournal.php', LOG_DEBUG);
165 $result = $db->query($sql);
172 $tablocaltax1 = array();
173 $tablocaltax2 = array();
174 $tabcompany = array();
176 $num = $db->num_rows($result);
179 $cptcli = (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER !=
"")) ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER :
'NotDefined';
180 $cpttva = (!empty($conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT :
'NotDefined';
184 $obj = $db->fetch_object($result);
187 $compta_soc = (!empty($obj->code_compta)) ? $obj->code_compta : $cptcli;
189 $compta_prod = $obj->compte;
190 if (empty($compta_prod)) {
191 if ($obj->product_type == 0) {
192 $compta_prod = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT :
'NotDefined';
194 $compta_prod = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT :
'NotDefined';
198 $vatdata =
getTaxesFromId($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''), $mysoc, $mysoc, 0);
199 $compta_tva = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cpttva);
200 $compta_localtax1 = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cpttva);
201 $compta_localtax2 = (!empty($vatdata[
'accountancy_code_sell']) ? $vatdata[
'accountancy_code_sell'] : $cpttva);
204 if (
price2num($obj->tva_tx) || !empty($obj->vat_src_code)) {
205 $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.
')' :
''));
209 $line->fetch($obj->fdid);
212 $prev_progress = $line->get_prev_progress($obj->rowid);
216 if ($obj->situation_percent == 0) {
217 $situation_ratio = 0;
219 $situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent;
222 $situation_ratio = 1;
226 $tabfac[$obj->rowid][
"date"] = $db->jdate($obj->df);
227 $tabfac[$obj->rowid][
"datereg"] = $db->jdate($obj->dlr);
228 $tabfac[$obj->rowid][
"ref"] = $obj->ref;
229 $tabfac[$obj->rowid][
"type"] = $obj->type;
230 $tabfac[$obj->rowid][
"description"] = $obj->label_compte;
231 $tabfac[$obj->rowid][
"close_code"] = $obj->close_code;
235 if (!isset($tabttc[$obj->rowid][$compta_soc])) {
236 $tabttc[$obj->rowid][$compta_soc] = 0;
238 if (!isset($tabht[$obj->rowid][$compta_prod])) {
239 $tabht[$obj->rowid][$compta_prod] = 0;
241 if (!isset($tabtva[$obj->rowid][$compta_tva])) {
242 $tabtva[$obj->rowid][$compta_tva] = 0;
244 if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
245 $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
247 if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
248 $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
251 $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc * $situation_ratio;
252 $tabht[$obj->rowid][$compta_prod] += $obj->total_ht * $situation_ratio;
253 if (empty($line->tva_npr)) {
254 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio;
256 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1 * $situation_ratio;
257 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2 * $situation_ratio;
258 $tabcompany[$obj->rowid] = array(
260 'name' => $obj->name,
261 'code_client' => $obj->code_client,
262 'code_compta' => $compta_soc
271 $errorforinvoice = array();
274 foreach ($tabfac as $key => $val) {
275 $sql =
"SELECT COUNT(fd.rowid) as nb";
276 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
277 $sql .=
" WHERE fd.product_type <= 2 AND fd.fk_code_ventilation <= 0";
278 $sql .=
" AND fd.total_ttc <> 0 AND fk_facture = ".((int) $key);
279 $resql = $db->query($sql);
281 $obj = $db->fetch_object(
$resql);
283 $errorforinvoice[$key] =
'somelinesarenotbound';
293 if ($action ==
'writebookkeeping') {
297 $companystatic =
new Societe($db);
298 $invoicestatic =
new Facture($db);
301 $accountingaccountcustomer->fetch(
null, $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER,
true);
303 foreach ($tabfac as $key => $val) {
311 $companystatic->id = $tabcompany[$key][
'id'];
312 $companystatic->name = $tabcompany[$key][
'name'];
313 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
314 $companystatic->code_client = $tabcompany[$key][
'code_client'];
315 $companystatic->client = 3;
317 $invoicestatic->id = $key;
318 $invoicestatic->ref = (string) $val[
"ref"];
319 $invoicestatic->type = $val[
"type"];
320 $invoicestatic->close_code = $val[
"close_code"];
325 $replacedinvoice = 0;
326 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
327 $replacedinvoice = 1;
328 $alreadydispatched = $invoicestatic->getVentilExportCompta();
329 if ($alreadydispatched) {
330 $replacedinvoice = 2;
335 if ($replacedinvoice == 1) {
341 if ($errorforinvoice[$key] ==
'somelinesarenotbound') {
344 setEventMessages($langs->trans(
'ErrorInvoiceContainsLinesNotYetBounded', $val[
'ref']),
null,
'errors');
348 if (!$errorforline) {
349 foreach ($tabttc[$key] as $k => $mt) {
351 $bookkeeping->doc_date = $val[
"date"];
352 $bookkeeping->date_lim_reglement = $val[
"datereg"];
353 $bookkeeping->doc_ref = $val[
"ref"];
354 $bookkeeping->date_creation = $now;
355 $bookkeeping->doc_type =
'customer_invoice';
356 $bookkeeping->fk_doc = $key;
357 $bookkeeping->fk_docdet = 0;
358 $bookkeeping->thirdparty_code = $companystatic->code_client;
360 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
361 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
363 $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
364 $bookkeeping->label_compte = $accountingaccountcustomer->label;
366 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"SubledgerAccount");
367 $bookkeeping->montant = $mt;
368 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
369 $bookkeeping->debit = ($mt >= 0) ? $mt : 0;
370 $bookkeeping->credit = ($mt < 0) ? -$mt : 0;
371 $bookkeeping->code_journal = $journal;
372 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
373 $bookkeeping->fk_user_author = $user->id;
374 $bookkeeping->entity = $conf->entity;
376 $totaldebit += $bookkeeping->debit;
377 $totalcredit += $bookkeeping->credit;
379 $result = $bookkeeping->create($user);
381 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
384 $errorforinvoice[$key] =
'alreadyjournalized';
389 $errorforinvoice[$key] =
'other';
394 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/lettering.class.php';
396 $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id));
403 if (!$errorforline) {
404 foreach ($tabht[$key] as $k => $mt) {
405 $resultfetch = $accountingaccount->fetch(
null, $k,
true);
406 $label_account = $accountingaccount->label;
409 if ($resultfetch > 0) {
411 $bookkeeping->doc_date = $val[
"date"];
412 $bookkeeping->date_lim_reglement = $val[
"datereg"];
413 $bookkeeping->doc_ref = $val[
"ref"];
414 $bookkeeping->date_creation = $now;
415 $bookkeeping->doc_type =
'customer_invoice';
416 $bookkeeping->fk_doc = $key;
417 $bookkeeping->fk_docdet = 0;
418 $bookkeeping->thirdparty_code = $companystatic->code_client;
420 if (!empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT)) {
422 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
423 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
425 $bookkeeping->subledger_account =
'';
426 $bookkeeping->subledger_label =
'';
429 $bookkeeping->subledger_account =
'';
430 $bookkeeping->subledger_label =
'';
433 $bookkeeping->numero_compte = $k;
434 $bookkeeping->label_compte = $label_account;
436 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref.
' - '.$label_account;
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';
468 if (!$errorforline) {
469 $listoftax = array(0, 1, 2);
470 foreach ($listoftax as $numtax) {
471 $arrayofvat = $tabtva;
473 $arrayofvat = $tablocaltax1;
476 $arrayofvat = $tablocaltax2;
479 foreach ($arrayofvat[$key] as $k => $mt) {
481 $accountingaccount->fetch(
null, $k,
true);
482 $label_account = $accountingaccount->label;
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;
494 $bookkeeping->subledger_account =
'';
495 $bookkeeping->subledger_label =
'';
497 $bookkeeping->numero_compte = $k;
498 $bookkeeping->label_compte = $label_account;
500 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"VAT").
' '.join(
', ', $def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
'');
501 $bookkeeping->montant = $mt;
502 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
503 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
504 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
505 $bookkeeping->code_journal = $journal;
506 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
507 $bookkeeping->fk_user_author = $user->id;
508 $bookkeeping->entity = $conf->entity;
510 $totaldebit += $bookkeeping->debit;
511 $totalcredit += $bookkeeping->credit;
513 $result = $bookkeeping->create($user);
515 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
518 $errorforinvoice[$key] =
'alreadyjournalized';
523 $errorforinvoice[$key] =
'other';
533 if (!$errorforline && (
price2num($totaldebit,
'MT') !=
price2num($totalcredit,
'MT'))) {
536 $errorforinvoice[$key] =
'amountsnotbalanced';
537 setEventMessages(
'Try to insert a non balanced transaction in book for '.$invoicestatic->ref.
'. Canceled. Surely a bug.',
null,
'errors');
540 if (!$errorforline) {
546 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped"),
null,
'errors');
554 if (empty($error) && count($tabpay) > 0) {
556 } elseif (count($tabpay) == $error) {
559 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
565 if (count($tabpay) != $error) {
566 $param =
'id_journal='.$id_journal;
567 $param .=
'&date_startday='.$date_startday;
568 $param .=
'&date_startmonth='.$date_startmonth;
569 $param .=
'&date_startyear='.$date_startyear;
570 $param .=
'&date_endday='.$date_endday;
571 $param .=
'&date_endmonth='.$date_endmonth;
572 $param .=
'&date_endyear='.$date_endyear;
573 $param .=
'&in_bookkeeping='.$in_bookkeeping;
574 header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
588 if ($action ==
'exportcsv') {
589 $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
591 $filename =
'journal';
592 $type_export =
'journal';
593 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
595 $companystatic =
new Client($db);
596 $invoicestatic =
new Facture($db);
598 foreach ($tabfac as $key => $val) {
599 $companystatic->id = $tabcompany[$key][
'id'];
600 $companystatic->name = $tabcompany[$key][
'name'];
601 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
602 $companystatic->code_client = $tabcompany[$key][
'code_client'];
603 $companystatic->client = 3;
605 $invoicestatic->id = $key;
606 $invoicestatic->ref = (string) $val[
"ref"];
607 $invoicestatic->type = $val[
"type"];
608 $invoicestatic->close_code = $val[
"close_code"];
613 $replacedinvoice = 0;
614 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
615 $replacedinvoice = 1;
616 $alreadydispatched = $invoicestatic->getVentilExportCompta();
617 if ($alreadydispatched) {
618 $replacedinvoice = 2;
623 if ($replacedinvoice == 1) {
628 foreach ($tabttc[$key] as $k => $mt) {
630 print
'"'.$key.
'"'.$sep;
631 print
'"'.$date.
'"'.$sep;
632 print
'"'.$val[
"ref"].
'"'.$sep;
633 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
634 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
635 print
'"'.length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER).
'"'.$sep;
636 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
637 print
'"'.$langs->trans(
"Thirdparty").
'"'.$sep;
638 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"Thirdparty").
'"'.$sep;
639 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
640 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
641 print
'"'.$journal.
'"';
647 foreach ($tabht[$key] as $k => $mt) {
649 $accountingaccount->fetch(
null, $k,
true);
651 print
'"'.$key.
'"'.$sep;
652 print
'"'.$date.
'"'.$sep;
653 print
'"'.$val[
"ref"].
'"'.$sep;
654 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
655 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
656 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
658 print
'"'.utf8_decode(
dol_trunc($accountingaccount->label, 32)).
'"'.$sep;
659 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.
dol_trunc($accountingaccount->label, 32).
'"'.$sep;
660 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
661 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
662 print
'"'.$journal.
'"';
668 $listoftax = array(0, 1, 2);
669 foreach ($listoftax as $numtax) {
670 $arrayofvat = $tabtva;
672 $arrayofvat = $tablocaltax1;
675 $arrayofvat = $tablocaltax2;
678 foreach ($arrayofvat[$key] as $k => $mt) {
680 print
'"'.$key.
'"'.$sep;
681 print
'"'.$date.
'"'.$sep;
682 print
'"'.$val[
"ref"].
'"'.$sep;
683 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
684 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
685 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
687 print
'"'.$langs->trans(
"VAT").
' - '.join(
', ', $def_tva[$key][$k]).
' %"'.$sep;
688 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"VAT").join(
', ', $def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
'').
'"'.$sep;
689 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
690 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
691 print
'"'.$journal.
'"';
701 if (empty($action) || $action ==
'view') {
702 $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1,
'', 1);
711 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
712 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
713 $description .= $langs->trans(
"DepositsAreNotIncluded");
715 $description .= $langs->trans(
"DepositsAreIncluded");
718 $listofchoices = array(
'notyet'=>$langs->trans(
"NotYetInGeneralLedger"),
'already'=>$langs->trans(
"AlreadyInGeneralLedger"));
719 $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);
720 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.
$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
722 $varlink =
'id_journal='.$id_journal;
724 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
727 if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
"") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
'-1') {
728 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
729 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
730 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
734 print
'<div class="tabsAction tabsActionNoBottom centerimp">';
735 if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping ==
'notyet') {
736 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
738 if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
"") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
'-1') {
739 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
741 if ($in_bookkeeping ==
'notyet') {
742 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
744 print
'<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
751 <script type="text/javascript">
752 function launch_export() {
753 $("div.fiche form input[name=\"action\"]").val("exportcsv");
754 $("div.fiche form input[type=\"submit\"]").click();
755 $("div.fiche form input[name=\"action\"]").val("");
757 function writebookkeeping() {
758 console.log("click on writebookkeeping");
759 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
760 $("div.fiche form input[type=\"submit\"]").click();
761 $("div.fiche form input[name=\"action\"]").val("");
771 print
'<div class="div-table-responsive">';
772 print
"<table class=\"noborder\" width=\"100%\">";
773 print
"<tr class=\"liste_titre\">";
774 print
"<td>".$langs->trans(
"Date").
"</td>";
775 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"InvoiceRef").
")</td>";
776 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
777 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
778 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
779 print
'<td class="center">'.$langs->trans(
"AccountingDebit").
"</td>";
780 print
'<td class="center">'.$langs->trans(
"AccountingCredit").
"</td>";
785 $companystatic =
new Client($db);
786 $invoicestatic =
new Facture($db);
788 foreach ($tabfac as $key => $val) {
789 $companystatic->id = $tabcompany[$key][
'id'];
790 $companystatic->name = $tabcompany[$key][
'name'];
791 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
792 $companystatic->code_client = $tabcompany[$key][
'code_client'];
793 $companystatic->client = 3;
795 $invoicestatic->id = $key;
796 $invoicestatic->ref = (string) $val[
"ref"];
797 $invoicestatic->type = $val[
"type"];
798 $invoicestatic->close_code = $val[
"close_code"];
803 $replacedinvoice = 0;
804 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
805 $replacedinvoice = 1;
806 $alreadydispatched = $invoicestatic->getVentilExportCompta();
807 if ($alreadydispatched) {
808 $replacedinvoice = 2;
813 if ($replacedinvoice == 1) {
814 print
'<tr class="oddeven">';
815 print
"<!-- Replaced invoice -->";
816 print
"<td>".$date.
"</td>";
817 print
"<td><strike>".$invoicestatic->getNomUrl(1).
"</strike></td>";
820 print $langs->trans(
"Replaced");
827 print
'<td class="right"></td>';
828 print
'<td class="right"></td>';
833 if ($errorforinvoice[$key] ==
'somelinesarenotbound') {
834 print
'<tr class="oddeven">';
835 print
"<!-- Some lines are not bound -->";
836 print
"<td>".$date.
"</td>";
837 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
840 print
'<span class="error">'.$langs->trans(
'ErrorInvoiceContainsLinesNotYetBoundedShort', $val[
'ref']).
'</span>';
847 print
'<td class="right"></td>';
848 print
'<td class="right"></td>';
853 foreach ($tabttc[$key] as $k => $mt) {
854 print
'<tr class="oddeven">';
855 print
"<!-- Thirdparty -->";
856 print
"<td>".$date.
"</td>";
857 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
860 $accountoshow =
length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER);
861 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
862 print
'<span class="error">'.$langs->trans(
"MainAccountForCustomersNotDefined").
'</span>';
870 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
871 print
'<span class="error">'.$langs->trans(
"ThirdpartyAccountNotDefined").
'</span>';
876 print
"<td>".$companystatic->getNomUrl(0,
'customer', 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"SubledgerAccount").
"</td>";
877 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
878 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
883 foreach ($tabht[$key] as $k => $mt) {
885 $accountingaccount->fetch(
null, $k,
true);
887 print
'<tr class="oddeven">';
888 print
"<!-- Product -->";
889 print
"<td>".$date.
"</td>";
890 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
894 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
895 print
'<span class="error">'.$langs->trans(
"ProductNotDefined").
'</span>';
902 if (!empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT)) {
906 } elseif (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
907 print
'<span class="error">' . $langs->trans(
"ThirdpartyAccountNotDefined") .
'</span>';
910 $companystatic->id = $tabcompany[$key][
'id'];
911 $companystatic->name = $tabcompany[$key][
'name'];
912 print
"<td>".$companystatic->getNomUrl(0,
'customer', 16).
' - '.$invoicestatic->ref.
' - '.$accountingaccount->label.
"</td>";
913 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
914 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
919 $listoftax = array(0, 1, 2);
920 foreach ($listoftax as $numtax) {
921 $arrayofvat = $tabtva;
923 $arrayofvat = $tablocaltax1;
926 $arrayofvat = $tablocaltax2;
929 foreach ($arrayofvat[$key] as $k => $mt) {
931 print
'<tr class="oddeven">';
932 print
"<!-- VAT -->";
933 print
"<td>".$date.
"</td>";
934 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
938 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
939 print
'<span class="error">'.$langs->trans(
"VATAccountNotDefined").
' ('.$langs->trans(
"Sale").
')</span>';
947 print
"<td>".$companystatic->getNomUrl(0,
'customer', 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"VAT").
' '.join(
', ', $def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
'');
949 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
950 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
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 accounts.
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') &&!empty($user->rights->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') &&!empty($user->rights->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)) $resql
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.
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.