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.situation_cycle_ref, 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, fd.info_bits,";
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, f.ref";
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 $situation_ratio = 1;
211 if ($obj->situation_cycle_ref) {
213 if ($obj->situation_percent == 0) {
214 $situation_ratio = 0;
217 $line->fetch($obj->fdid);
220 $prev_progress = $line->get_prev_progress($obj->rowid);
222 $situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent;
228 $tabfac[$obj->rowid][
"date"] = $db->jdate($obj->df);
229 $tabfac[$obj->rowid][
"datereg"] = $db->jdate($obj->dlr);
230 $tabfac[$obj->rowid][
"ref"] = $obj->ref;
231 $tabfac[$obj->rowid][
"type"] = $obj->type;
232 $tabfac[$obj->rowid][
"description"] = $obj->label_compte;
233 $tabfac[$obj->rowid][
"close_code"] = $obj->close_code;
237 if (!isset($tabttc[$obj->rowid][$compta_soc])) {
238 $tabttc[$obj->rowid][$compta_soc] = 0;
240 if (!isset($tabht[$obj->rowid][$compta_prod])) {
241 $tabht[$obj->rowid][$compta_prod] = 0;
243 if (!isset($tabtva[$obj->rowid][$compta_tva])) {
244 $tabtva[$obj->rowid][$compta_tva] = 0;
246 if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
247 $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
249 if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
250 $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
258 $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc * $situation_ratio;
259 $tabht[$obj->rowid][$compta_prod] += $obj->total_ht * $situation_ratio;
260 $tva_npr = (($obj->info_bits & 1 == 1) ? 1 : 0);
262 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio;
264 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1 * $situation_ratio;
265 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2 * $situation_ratio;
268 $tabcompany[$obj->rowid] = array(
270 'name' => $obj->name,
271 'code_client' => $obj->code_client,
272 'code_compta' => $compta_soc
281 $errorforinvoice = array();
284 foreach ($tabfac as $key => $val) {
285 $sql =
"SELECT COUNT(fd.rowid) as nb";
286 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
287 $sql .=
" WHERE fd.product_type <= 2 AND fd.fk_code_ventilation <= 0";
288 $sql .=
" AND fd.total_ttc <> 0 AND fk_facture = ".((int) $key);
289 $resql = $db->query($sql);
291 $obj = $db->fetch_object(
$resql);
293 $errorforinvoice[$key] =
'somelinesarenotbound';
303 if ($action ==
'writebookkeeping') {
307 $companystatic =
new Societe($db);
308 $invoicestatic =
new Facture($db);
311 $accountingaccountcustomer->fetch(
null, $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER,
true);
313 foreach ($tabfac as $key => $val) {
321 $companystatic->id = $tabcompany[$key][
'id'];
322 $companystatic->name = $tabcompany[$key][
'name'];
323 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
324 $companystatic->code_client = $tabcompany[$key][
'code_client'];
325 $companystatic->client = 3;
327 $invoicestatic->id = $key;
328 $invoicestatic->ref = (string) $val[
"ref"];
329 $invoicestatic->type = $val[
"type"];
330 $invoicestatic->close_code = $val[
"close_code"];
335 $replacedinvoice = 0;
336 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
337 $replacedinvoice = 1;
338 $alreadydispatched = $invoicestatic->getVentilExportCompta();
339 if ($alreadydispatched) {
340 $replacedinvoice = 2;
345 if ($replacedinvoice == 1) {
351 if ($errorforinvoice[$key] ==
'somelinesarenotbound') {
354 setEventMessages($langs->trans(
'ErrorInvoiceContainsLinesNotYetBounded', $val[
'ref']),
null,
'errors');
358 if (!$errorforline) {
359 foreach ($tabttc[$key] as $k => $mt) {
361 $bookkeeping->doc_date = $val[
"date"];
362 $bookkeeping->date_lim_reglement = $val[
"datereg"];
363 $bookkeeping->doc_ref = $val[
"ref"];
364 $bookkeeping->date_creation = $now;
365 $bookkeeping->doc_type =
'customer_invoice';
366 $bookkeeping->fk_doc = $key;
367 $bookkeeping->fk_docdet = 0;
368 $bookkeeping->thirdparty_code = $companystatic->code_client;
370 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
371 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
373 $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
374 $bookkeeping->label_compte = $accountingaccountcustomer->label;
376 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"SubledgerAccount");
377 $bookkeeping->montant = $mt;
378 $bookkeeping->sens = ($mt >= 0) ?
'D' :
'C';
379 $bookkeeping->debit = ($mt >= 0) ? $mt : 0;
380 $bookkeeping->credit = ($mt < 0) ? -$mt : 0;
381 $bookkeeping->code_journal = $journal;
382 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
383 $bookkeeping->fk_user_author = $user->id;
384 $bookkeeping->entity = $conf->entity;
386 $totaldebit += $bookkeeping->debit;
387 $totalcredit += $bookkeeping->credit;
389 $result = $bookkeeping->create($user);
391 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
394 $errorforinvoice[$key] =
'alreadyjournalized';
399 $errorforinvoice[$key] =
'other';
404 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/lettering.class.php';
407 $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id));
414 if (!$errorforline) {
415 foreach ($tabht[$key] as $k => $mt) {
416 $resultfetch = $accountingaccount->fetch(
null, $k,
true);
417 $label_account = $accountingaccount->label;
420 if ($resultfetch > 0) {
422 $bookkeeping->doc_date = $val[
"date"];
423 $bookkeeping->date_lim_reglement = $val[
"datereg"];
424 $bookkeeping->doc_ref = $val[
"ref"];
425 $bookkeeping->date_creation = $now;
426 $bookkeeping->doc_type =
'customer_invoice';
427 $bookkeeping->fk_doc = $key;
428 $bookkeeping->fk_docdet = 0;
429 $bookkeeping->thirdparty_code = $companystatic->code_client;
431 if (!empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT)) {
433 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
434 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
436 $bookkeeping->subledger_account =
'';
437 $bookkeeping->subledger_label =
'';
440 $bookkeeping->subledger_account =
'';
441 $bookkeeping->subledger_label =
'';
444 $bookkeeping->numero_compte = $k;
445 $bookkeeping->label_compte = $label_account;
447 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref.
' - '.$label_account;
448 $bookkeeping->montant = $mt;
449 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
450 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
451 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
452 $bookkeeping->code_journal = $journal;
453 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
454 $bookkeeping->fk_user_author = $user->id;
455 $bookkeeping->entity = $conf->entity;
457 $totaldebit += $bookkeeping->debit;
458 $totalcredit += $bookkeeping->credit;
460 $result = $bookkeeping->create($user);
462 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
465 $errorforinvoice[$key] =
'alreadyjournalized';
470 $errorforinvoice[$key] =
'other';
479 if (!$errorforline) {
480 $listoftax = array(0, 1, 2);
481 foreach ($listoftax as $numtax) {
482 $arrayofvat = $tabtva;
484 $arrayofvat = $tablocaltax1;
487 $arrayofvat = $tablocaltax2;
490 foreach ($arrayofvat[$key] as $k => $mt) {
492 $accountingaccount->fetch(
null, $k,
true);
493 $label_account = $accountingaccount->label;
496 $bookkeeping->doc_date = $val[
"date"];
497 $bookkeeping->date_lim_reglement = $val[
"datereg"];
498 $bookkeeping->doc_ref = $val[
"ref"];
499 $bookkeeping->date_creation = $now;
500 $bookkeeping->doc_type =
'customer_invoice';
501 $bookkeeping->fk_doc = $key;
502 $bookkeeping->fk_docdet = 0;
503 $bookkeeping->thirdparty_code = $companystatic->code_client;
505 $bookkeeping->subledger_account =
'';
506 $bookkeeping->subledger_label =
'';
508 $bookkeeping->numero_compte = $k;
509 $bookkeeping->label_compte = $label_account;
511 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"VAT").
' '.join(
', ', $def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
'');
512 $bookkeeping->montant = $mt;
513 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
514 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
515 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
516 $bookkeeping->code_journal = $journal;
517 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
518 $bookkeeping->fk_user_author = $user->id;
519 $bookkeeping->entity = $conf->entity;
521 $totaldebit += $bookkeeping->debit;
522 $totalcredit += $bookkeeping->credit;
524 $result = $bookkeeping->create($user);
526 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
529 $errorforinvoice[$key] =
'alreadyjournalized';
534 $errorforinvoice[$key] =
'other';
544 if (!$errorforline && (
price2num($totaldebit,
'MT') !=
price2num($totalcredit,
'MT'))) {
547 $errorforinvoice[$key] =
'amountsnotbalanced';
548 setEventMessages(
'Try to insert a non balanced transaction in book for '.$invoicestatic->ref.
'. Canceled. Surely a bug.',
null,
'errors');
551 if (!$errorforline) {
557 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped"),
null,
'errors');
565 if (empty($error) && count($tabpay) > 0) {
567 } elseif (count($tabpay) == $error) {
570 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
576 if (count($tabpay) != $error) {
577 $param =
'id_journal='.$id_journal;
578 $param .=
'&date_startday='.$date_startday;
579 $param .=
'&date_startmonth='.$date_startmonth;
580 $param .=
'&date_startyear='.$date_startyear;
581 $param .=
'&date_endday='.$date_endday;
582 $param .=
'&date_endmonth='.$date_endmonth;
583 $param .=
'&date_endyear='.$date_endyear;
584 $param .=
'&in_bookkeeping='.$in_bookkeeping;
585 header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
599 if ($action ==
'exportcsv') {
600 $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
602 $filename =
'journal';
603 $type_export =
'journal';
604 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
606 $companystatic =
new Client($db);
607 $invoicestatic =
new Facture($db);
609 foreach ($tabfac as $key => $val) {
610 $companystatic->id = $tabcompany[$key][
'id'];
611 $companystatic->name = $tabcompany[$key][
'name'];
612 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
613 $companystatic->code_compta_client = $tabcompany[$key][
'code_compta'];
614 $companystatic->code_client = $tabcompany[$key][
'code_client'];
615 $companystatic->client = 3;
617 $invoicestatic->id = $key;
618 $invoicestatic->ref = (string) $val[
"ref"];
619 $invoicestatic->type = $val[
"type"];
620 $invoicestatic->close_code = $val[
"close_code"];
625 $replacedinvoice = 0;
626 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
627 $replacedinvoice = 1;
628 $alreadydispatched = $invoicestatic->getVentilExportCompta();
629 if ($alreadydispatched) {
630 $replacedinvoice = 2;
635 if ($replacedinvoice == 1) {
640 foreach ($tabttc[$key] as $k => $mt) {
642 print
'"'.$key.
'"'.$sep;
643 print
'"'.$date.
'"'.$sep;
644 print
'"'.$val[
"ref"].
'"'.$sep;
645 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
646 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
647 print
'"'.length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER).
'"'.$sep;
648 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
649 print
'"'.$langs->trans(
"Thirdparty").
'"'.$sep;
650 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"Thirdparty").
'"'.$sep;
651 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
652 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
653 print
'"'.$journal.
'"';
659 foreach ($tabht[$key] as $k => $mt) {
661 $accountingaccount->fetch(
null, $k,
true);
663 print
'"'.$key.
'"'.$sep;
664 print
'"'.$date.
'"'.$sep;
665 print
'"'.$val[
"ref"].
'"'.$sep;
666 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
667 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
668 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
670 print
'"'.utf8_decode(
dol_trunc($accountingaccount->label, 32)).
'"'.$sep;
671 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.
dol_trunc($accountingaccount->label, 32).
'"'.$sep;
672 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
673 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
674 print
'"'.$journal.
'"';
680 $listoftax = array(0, 1, 2);
681 foreach ($listoftax as $numtax) {
682 $arrayofvat = $tabtva;
684 $arrayofvat = $tablocaltax1;
687 $arrayofvat = $tablocaltax2;
690 foreach ($arrayofvat[$key] as $k => $mt) {
692 print
'"'.$key.
'"'.$sep;
693 print
'"'.$date.
'"'.$sep;
694 print
'"'.$val[
"ref"].
'"'.$sep;
695 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
696 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
697 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
699 print
'"'.$langs->trans(
"VAT").
' - '.join(
', ', $def_tva[$key][$k]).
' %"'.$sep;
700 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"VAT").join(
', ', $def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
'').
'"'.$sep;
701 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
702 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
703 print
'"'.$journal.
'"';
713 if (empty($action) || $action ==
'view') {
714 $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1,
'', 1);
723 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
724 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
725 $description .= $langs->trans(
"DepositsAreNotIncluded");
727 $description .= $langs->trans(
"DepositsAreIncluded");
730 $listofchoices = array(
'notyet'=>$langs->trans(
"NotYetInGeneralLedger"),
'already'=>$langs->trans(
"AlreadyInGeneralLedger"));
731 $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);
732 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.
$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
734 $varlink =
'id_journal='.$id_journal;
736 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
739 if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
"") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
'-1') {
740 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
741 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
742 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
746 print
'<div class="tabsAction tabsActionNoBottom centerimp">';
747 if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping ==
'notyet') {
748 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
750 if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
"") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
'-1') {
751 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
753 if ($in_bookkeeping ==
'notyet') {
754 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
756 print
'<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
763 <script type="text/javascript">
764 function launch_export() {
765 $("div.fiche form input[name=\"action\"]").val("exportcsv");
766 $("div.fiche form input[type=\"submit\"]").click();
767 $("div.fiche form input[name=\"action\"]").val("");
769 function writebookkeeping() {
770 console.log("click on writebookkeeping");
771 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
772 $("div.fiche form input[type=\"submit\"]").click();
773 $("div.fiche form input[name=\"action\"]").val("");
782 print
'<div class="div-table-responsive">';
783 print
"<table class=\"noborder\" width=\"100%\">";
784 print
"<tr class=\"liste_titre\">";
785 print
"<td>".$langs->trans(
"Date").
"</td>";
786 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"InvoiceRef").
")</td>";
787 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
788 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
789 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
790 print
'<td class="center">'.$langs->trans(
"AccountingDebit").
"</td>";
791 print
'<td class="center">'.$langs->trans(
"AccountingCredit").
"</td>";
796 $companystatic =
new Client($db);
797 $invoicestatic =
new Facture($db);
799 foreach ($tabfac as $key => $val) {
800 $companystatic->id = $tabcompany[$key][
'id'];
801 $companystatic->name = $tabcompany[$key][
'name'];
802 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
803 $companystatic->code_client = $tabcompany[$key][
'code_client'];
804 $companystatic->client = 3;
806 $invoicestatic->id = $key;
807 $invoicestatic->ref = (string) $val[
"ref"];
808 $invoicestatic->type = $val[
"type"];
809 $invoicestatic->close_code = $val[
"close_code"];
814 $replacedinvoice = 0;
815 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
816 $replacedinvoice = 1;
817 $alreadydispatched = $invoicestatic->getVentilExportCompta();
818 if ($alreadydispatched) {
819 $replacedinvoice = 2;
824 if ($replacedinvoice == 1) {
825 print
'<tr class="oddeven">';
826 print
"<!-- Replaced invoice -->";
827 print
"<td>".$date.
"</td>";
828 print
"<td><strike>".$invoicestatic->getNomUrl(1).
"</strike></td>";
831 print $langs->trans(
"Replaced");
838 print
'<td class="right"></td>';
839 print
'<td class="right"></td>';
845 if ($errorforinvoice[$key] ==
'somelinesarenotbound') {
846 print
'<tr class="oddeven">';
847 print
"<!-- Some lines are not bound -->";
848 print
"<td>".$date.
"</td>";
849 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
852 print
'<span class="error">'.$langs->trans(
'ErrorInvoiceContainsLinesNotYetBoundedShort', $val[
'ref']).
'</span>';
859 print
'<td class="right"></td>';
860 print
'<td class="right"></td>';
867 foreach ($tabttc[$key] as $k => $mt) {
868 print
'<tr class="oddeven">';
869 print
"<!-- Thirdparty -->";
870 print
"<td>".$date.
"</td>";
871 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
874 $accountoshow =
length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER);
875 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
876 print
'<span class="error">'.$langs->trans(
"MainAccountForCustomersNotDefined").
'</span>';
884 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
885 print
'<span class="error">'.$langs->trans(
"ThirdpartyAccountNotDefined").
'</span>';
890 print
"<td>".$companystatic->getNomUrl(0,
'customer', 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"SubledgerAccount").
"</td>";
891 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
892 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
899 foreach ($tabht[$key] as $k => $mt) {
901 $accountingaccount->fetch(
null, $k,
true);
903 print
'<tr class="oddeven">';
904 print
"<!-- Product -->";
905 print
"<td>".$date.
"</td>";
906 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
910 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
911 print
'<span class="error">'.$langs->trans(
"ProductNotDefined").
'</span>';
918 if (!empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT)) {
922 } elseif (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
923 print
'<span class="error">' . $langs->trans(
"ThirdpartyAccountNotDefined") .
'</span>';
926 $companystatic->id = $tabcompany[$key][
'id'];
927 $companystatic->name = $tabcompany[$key][
'name'];
928 print
"<td>".$companystatic->getNomUrl(0,
'customer', 16).
' - '.$invoicestatic->ref.
' - '.$accountingaccount->label.
"</td>";
929 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
930 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
937 $listoftax = array(0, 1, 2);
938 foreach ($listoftax as $numtax) {
939 $arrayofvat = $tabtva;
941 $arrayofvat = $tablocaltax1;
944 $arrayofvat = $tablocaltax2;
947 foreach ($arrayofvat[$key] as $k => $mt) {
949 print
'<tr class="oddeven">';
950 print
"<!-- VAT -->";
951 print
"<td>".$date.
"</td>";
952 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
956 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
957 print
'<span class="error">'.$langs->trans(
"VATAccountNotDefined").
' ('.$langs->trans(
"Sale").
')</span>';
965 print
"<td>".$companystatic->getNomUrl(0,
'customer', 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"VAT").
' '.join(
', ', $def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
'');
967 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
968 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
978 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 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.