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));
409 if ($nb_lettering < 0) {
412 $errorforinvoice[$key] =
'other';
413 setEventMessages($lettering_static->error, $lettering_static->errors,
'errors');
421 if (!$errorforline) {
422 foreach ($tabht[$key] as $k => $mt) {
423 $resultfetch = $accountingaccount->fetch(
null, $k,
true);
424 $label_account = $accountingaccount->label;
427 if ($resultfetch > 0) {
429 $bookkeeping->doc_date = $val[
"date"];
430 $bookkeeping->date_lim_reglement = $val[
"datereg"];
431 $bookkeeping->doc_ref = $val[
"ref"];
432 $bookkeeping->date_creation = $now;
433 $bookkeeping->doc_type =
'customer_invoice';
434 $bookkeeping->fk_doc = $key;
435 $bookkeeping->fk_docdet = 0;
436 $bookkeeping->thirdparty_code = $companystatic->code_client;
438 if (!empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT)) {
440 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta'];
441 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
443 $bookkeeping->subledger_account =
'';
444 $bookkeeping->subledger_label =
'';
447 $bookkeeping->subledger_account =
'';
448 $bookkeeping->subledger_label =
'';
451 $bookkeeping->numero_compte = $k;
452 $bookkeeping->label_compte = $label_account;
454 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref.
' - '.$label_account;
455 $bookkeeping->montant = $mt;
456 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
457 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
458 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
459 $bookkeeping->code_journal = $journal;
460 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
461 $bookkeeping->fk_user_author = $user->id;
462 $bookkeeping->entity = $conf->entity;
464 $totaldebit += $bookkeeping->debit;
465 $totalcredit += $bookkeeping->credit;
467 $result = $bookkeeping->create($user);
469 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
472 $errorforinvoice[$key] =
'alreadyjournalized';
477 $errorforinvoice[$key] =
'other';
486 if (!$errorforline) {
487 $listoftax = array(0, 1, 2);
488 foreach ($listoftax as $numtax) {
489 $arrayofvat = $tabtva;
491 $arrayofvat = $tablocaltax1;
494 $arrayofvat = $tablocaltax2;
497 foreach ($arrayofvat[$key] as $k => $mt) {
499 $accountingaccount->fetch(
null, $k,
true);
500 $label_account = $accountingaccount->label;
503 $bookkeeping->doc_date = $val[
"date"];
504 $bookkeeping->date_lim_reglement = $val[
"datereg"];
505 $bookkeeping->doc_ref = $val[
"ref"];
506 $bookkeeping->date_creation = $now;
507 $bookkeeping->doc_type =
'customer_invoice';
508 $bookkeeping->fk_doc = $key;
509 $bookkeeping->fk_docdet = 0;
510 $bookkeeping->thirdparty_code = $companystatic->code_client;
512 $bookkeeping->subledger_account =
'';
513 $bookkeeping->subledger_label =
'';
515 $bookkeeping->numero_compte = $k;
516 $bookkeeping->label_compte = $label_account;
518 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"VAT").
' '.join(
', ', $def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
'');
519 $bookkeeping->montant = $mt;
520 $bookkeeping->sens = ($mt < 0) ?
'D' :
'C';
521 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
522 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
523 $bookkeeping->code_journal = $journal;
524 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
525 $bookkeeping->fk_user_author = $user->id;
526 $bookkeeping->entity = $conf->entity;
528 $totaldebit += $bookkeeping->debit;
529 $totalcredit += $bookkeeping->credit;
531 $result = $bookkeeping->create($user);
533 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
536 $errorforinvoice[$key] =
'alreadyjournalized';
541 $errorforinvoice[$key] =
'other';
551 if (!$errorforline && (
price2num($totaldebit,
'MT') !=
price2num($totalcredit,
'MT'))) {
554 $errorforinvoice[$key] =
'amountsnotbalanced';
555 setEventMessages(
'Try to insert a non balanced transaction in book for '.$invoicestatic->ref.
'. Canceled. Surely a bug.',
null,
'errors');
558 if (!$errorforline) {
564 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped"),
null,
'errors');
572 if (empty($error) && count($tabpay) > 0) {
574 } elseif (count($tabpay) == $error) {
577 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
583 if (count($tabpay) != $error) {
584 $param =
'id_journal='.$id_journal;
585 $param .=
'&date_startday='.$date_startday;
586 $param .=
'&date_startmonth='.$date_startmonth;
587 $param .=
'&date_startyear='.$date_startyear;
588 $param .=
'&date_endday='.$date_endday;
589 $param .=
'&date_endmonth='.$date_endmonth;
590 $param .=
'&date_endyear='.$date_endyear;
591 $param .=
'&in_bookkeeping='.$in_bookkeeping;
592 header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
606 if ($action ==
'exportcsv') {
607 $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
609 $filename =
'journal';
610 $type_export =
'journal';
611 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
613 $companystatic =
new Client($db);
614 $invoicestatic =
new Facture($db);
616 foreach ($tabfac as $key => $val) {
617 $companystatic->id = $tabcompany[$key][
'id'];
618 $companystatic->name = $tabcompany[$key][
'name'];
619 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
620 $companystatic->code_compta_client = $tabcompany[$key][
'code_compta'];
621 $companystatic->code_client = $tabcompany[$key][
'code_client'];
622 $companystatic->client = 3;
624 $invoicestatic->id = $key;
625 $invoicestatic->ref = (string) $val[
"ref"];
626 $invoicestatic->type = $val[
"type"];
627 $invoicestatic->close_code = $val[
"close_code"];
632 $replacedinvoice = 0;
633 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
634 $replacedinvoice = 1;
635 $alreadydispatched = $invoicestatic->getVentilExportCompta();
636 if ($alreadydispatched) {
637 $replacedinvoice = 2;
642 if ($replacedinvoice == 1) {
647 foreach ($tabttc[$key] as $k => $mt) {
649 print
'"'.$key.
'"'.$sep;
650 print
'"'.$date.
'"'.$sep;
651 print
'"'.$val[
"ref"].
'"'.$sep;
652 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
653 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
654 print
'"'.length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER).
'"'.$sep;
655 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
656 print
'"'.$langs->trans(
"Thirdparty").
'"'.$sep;
657 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"Thirdparty").
'"'.$sep;
658 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
659 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
660 print
'"'.$journal.
'"';
666 foreach ($tabht[$key] as $k => $mt) {
668 $accountingaccount->fetch(
null, $k,
true);
670 print
'"'.$key.
'"'.$sep;
671 print
'"'.$date.
'"'.$sep;
672 print
'"'.$val[
"ref"].
'"'.$sep;
673 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
674 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
675 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
677 print
'"'.utf8_decode(
dol_trunc($accountingaccount->label, 32)).
'"'.$sep;
678 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.
dol_trunc($accountingaccount->label, 32).
'"'.$sep;
679 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
680 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
681 print
'"'.$journal.
'"';
687 $listoftax = array(0, 1, 2);
688 foreach ($listoftax as $numtax) {
689 $arrayofvat = $tabtva;
691 $arrayofvat = $tablocaltax1;
694 $arrayofvat = $tablocaltax2;
697 foreach ($arrayofvat[$key] as $k => $mt) {
699 print
'"'.$key.
'"'.$sep;
700 print
'"'.$date.
'"'.$sep;
701 print
'"'.$val[
"ref"].
'"'.$sep;
702 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
703 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
704 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
706 print
'"'.$langs->trans(
"VAT").
' - '.join(
', ', $def_tva[$key][$k]).
' %"'.$sep;
707 print
'"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"VAT").join(
', ', $def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
'').
'"'.$sep;
708 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
709 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
710 print
'"'.$journal.
'"';
720 if (empty($action) || $action ==
'view') {
721 $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1,
'', 1);
730 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
731 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
732 $description .= $langs->trans(
"DepositsAreNotIncluded");
734 $description .= $langs->trans(
"DepositsAreIncluded");
737 $listofchoices = array(
'notyet'=>$langs->trans(
"NotYetInGeneralLedger"),
'already'=>$langs->trans(
"AlreadyInGeneralLedger"));
738 $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);
739 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.
$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
741 $varlink =
'id_journal='.$id_journal;
743 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
746 if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
"") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
'-1') {
747 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
748 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
749 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
753 print
'<div class="tabsAction tabsActionNoBottom centerimp">';
754 if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping ==
'notyet') {
755 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
757 if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
"") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER ==
'-1') {
758 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
760 if ($in_bookkeeping ==
'notyet') {
761 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
763 print
'<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
770 <script type="text/javascript">
771 function launch_export() {
772 $("div.fiche form input[name=\"action\"]").val("exportcsv");
773 $("div.fiche form input[type=\"submit\"]").click();
774 $("div.fiche form input[name=\"action\"]").val("");
776 function writebookkeeping() {
777 console.log("click on writebookkeeping");
778 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
779 $("div.fiche form input[type=\"submit\"]").click();
780 $("div.fiche form input[name=\"action\"]").val("");
789 print
'<div class="div-table-responsive">';
790 print
"<table class=\"noborder\" width=\"100%\">";
791 print
"<tr class=\"liste_titre\">";
792 print
"<td>".$langs->trans(
"Date").
"</td>";
793 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"InvoiceRef").
")</td>";
794 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
795 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
796 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
797 print
'<td class="center">'.$langs->trans(
"AccountingDebit").
"</td>";
798 print
'<td class="center">'.$langs->trans(
"AccountingCredit").
"</td>";
803 $companystatic =
new Client($db);
804 $invoicestatic =
new Facture($db);
806 foreach ($tabfac as $key => $val) {
807 $companystatic->id = $tabcompany[$key][
'id'];
808 $companystatic->name = $tabcompany[$key][
'name'];
809 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
810 $companystatic->code_client = $tabcompany[$key][
'code_client'];
811 $companystatic->client = 3;
813 $invoicestatic->id = $key;
814 $invoicestatic->ref = (string) $val[
"ref"];
815 $invoicestatic->type = $val[
"type"];
816 $invoicestatic->close_code = $val[
"close_code"];
821 $replacedinvoice = 0;
822 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
823 $replacedinvoice = 1;
824 $alreadydispatched = $invoicestatic->getVentilExportCompta();
825 if ($alreadydispatched) {
826 $replacedinvoice = 2;
831 if ($replacedinvoice == 1) {
832 print
'<tr class="oddeven">';
833 print
"<!-- Replaced invoice -->";
834 print
"<td>".$date.
"</td>";
835 print
"<td><strike>".$invoicestatic->getNomUrl(1).
"</strike></td>";
838 print $langs->trans(
"Replaced");
845 print
'<td class="right"></td>';
846 print
'<td class="right"></td>';
852 if ($errorforinvoice[$key] ==
'somelinesarenotbound') {
853 print
'<tr class="oddeven">';
854 print
"<!-- Some lines are not bound -->";
855 print
"<td>".$date.
"</td>";
856 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
859 print
'<span class="error">'.$langs->trans(
'ErrorInvoiceContainsLinesNotYetBoundedShort', $val[
'ref']).
'</span>';
866 print
'<td class="right"></td>';
867 print
'<td class="right"></td>';
874 foreach ($tabttc[$key] as $k => $mt) {
875 print
'<tr class="oddeven">';
876 print
"<!-- Thirdparty -->";
877 print
"<td>".$date.
"</td>";
878 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
881 $accountoshow =
length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER);
882 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
883 print
'<span class="error">'.$langs->trans(
"MainAccountForCustomersNotDefined").
'</span>';
891 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
892 print
'<span class="error">'.$langs->trans(
"ThirdpartyAccountNotDefined").
'</span>';
897 print
"<td>".$companystatic->getNomUrl(0,
'customer', 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"SubledgerAccount").
"</td>";
898 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
899 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
906 foreach ($tabht[$key] as $k => $mt) {
908 $accountingaccount->fetch(
null, $k,
true);
910 print
'<tr class="oddeven">';
911 print
"<!-- Product -->";
912 print
"<td>".$date.
"</td>";
913 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
917 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
918 print
'<span class="error">'.$langs->trans(
"ProductNotDefined").
'</span>';
925 if (!empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT)) {
929 } elseif (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
930 print
'<span class="error">' . $langs->trans(
"ThirdpartyAccountNotDefined") .
'</span>';
933 $companystatic->id = $tabcompany[$key][
'id'];
934 $companystatic->name = $tabcompany[$key][
'name'];
935 print
"<td>".$companystatic->getNomUrl(0,
'customer', 16).
' - '.$invoicestatic->ref.
' - '.$accountingaccount->label.
"</td>";
936 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
937 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
944 $listoftax = array(0, 1, 2);
945 foreach ($listoftax as $numtax) {
946 $arrayofvat = $tabtva;
948 $arrayofvat = $tablocaltax1;
951 $arrayofvat = $tablocaltax2;
954 foreach ($arrayofvat[$key] as $k => $mt) {
956 print
'<tr class="oddeven">';
957 print
"<!-- VAT -->";
958 print
"<td>".$date.
"</td>";
959 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
963 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
964 print
'<span class="error">'.$langs->trans(
"VATAccountNotDefined").
' ('.$langs->trans(
"Sale").
')</span>';
972 print
"<td>".$companystatic->getNomUrl(0,
'customer', 16).
' - '.$invoicestatic->ref.
' - '.$langs->trans(
"VAT").
' '.join(
', ', $def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
'');
974 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
975 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
985 print
'<tr class="oddeven"><td colspan="6"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';