31 require
'../../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
35 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
42 $langs->loadLangs(array(
"commercial",
"compta",
"bills",
"other",
"accountancy",
"errors"));
44 $id_journal =
GETPOST(
'id_journal',
'int');
45 $action =
GETPOST(
'action',
'aZ09');
47 $date_startmonth =
GETPOST(
'date_startmonth');
48 $date_startday =
GETPOST(
'date_startday');
49 $date_startyear =
GETPOST(
'date_startyear');
50 $date_endmonth =
GETPOST(
'date_endmonth');
51 $date_endday =
GETPOST(
'date_endday');
52 $date_endyear =
GETPOST(
'date_endyear');
53 $in_bookkeeping =
GETPOST(
'in_bookkeeping');
54 if ($in_bookkeeping ==
'') $in_bookkeeping =
'notyet';
62 $hookmanager->initHooks(array(
'purchasesjournal'));
63 $parameters = array();
68 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $user, $action);
74 $accountingjournalstatic->fetch($id_journal);
75 $journal = $accountingjournalstatic->code;
76 $journal_label = $accountingjournalstatic->label;
78 $date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
79 $date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
81 if (empty($date_startmonth) || empty($date_endmonth))
85 $date_start = $dates[
'date_start'];
86 $date_end = $dates[
'date_end'];
87 $pastmonthyear = $dates[
'pastmonthyear'];
88 $pastmonth = $dates[
'pastmonth'];
91 if (!
GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end)))
97 $sql =
"SELECT f.rowid, f.ref as ref, f.type, f.datef as df, f.libelle,f.ref_supplier, f.date_lim_reglement as dlf, f.close_code,";
98 $sql .=
" fd.rowid as fdid, fd.description, fd.product_type, fd.total_ht, fd.tva as total_tva, fd.total_localtax1, fd.total_localtax2, fd.tva_tx, fd.total_ttc, fd.vat_src_code,";
99 $sql .=
" s.rowid as socid, s.nom as name, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,";
100 $sql .=
" p.accountancy_code_buy , aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte";
101 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn_det as fd";
102 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = fd.fk_product";
103 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
104 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f ON f.rowid = fd.fk_facture_fourn";
105 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
106 $sql .=
" WHERE f.fk_statut > 0";
107 $sql .=
" AND fd.fk_code_ventilation > 0";
108 $sql .=
" AND f.entity IN (".getEntity(
'facture_fourn', 0).
")";
109 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
114 if ($date_start && $date_end)
115 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
117 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
118 $sql .=
" AND f.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
121 if ($in_bookkeeping ==
'already')
123 $sql .=
" AND f.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='supplier_invoice')";
125 if ($in_bookkeeping ==
'notyet')
127 $sql .=
" AND f.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='supplier_invoice')";
129 $sql .=
" ORDER BY f.datef";
131 dol_syslog(
'accountancy/journal/purchasesjournal.php', LOG_DEBUG);
132 $result = $db->query($sql);
139 $tablocaltax1 = array();
140 $tablocaltax2 = array();
141 $tabcompany = array();
144 $num = $db->num_rows($result);
147 $cptfour = ($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER !=
"") ? $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER :
'NotDefined';
148 $cpttva = (!empty($conf->global->ACCOUNTING_VAT_BUY_ACCOUNT)) ? $conf->global->ACCOUNTING_VAT_BUY_ACCOUNT :
'NotDefined';
152 $obj = $db->fetch_object($result);
155 $compta_soc = ($obj->code_compta_fournisseur !=
"") ? $obj->code_compta_fournisseur : $cptfour;
157 $compta_prod = $obj->compte;
158 if (empty($compta_prod)) {
159 if ($obj->product_type == 0)
160 $compta_prod = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT)) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT :
'NotDefined';
162 $compta_prod = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT)) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT :
'NotDefined';
166 $vatdata =
getTaxesFromId($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''), $mysoc, $mysoc, 0);
167 $compta_tva = (!empty($vatdata[
'accountancy_code_buy']) ? $vatdata[
'accountancy_code_buy'] : $cpttva);
168 $compta_localtax1 = (!empty($vatdata[
'accountancy_code_buy']) ? $vatdata[
'accountancy_code_buy'] : $cpttva);
169 $compta_localtax2 = (!empty($vatdata[
'accountancy_code_buy']) ? $vatdata[
'accountancy_code_buy'] : $cpttva);
170 $compta_counterpart_tva_npr = (!empty($conf->global->ACCOUNTING_COUNTERPART_VAT_NPR)) ? $conf->global->ACCOUNTING_COUNTERPART_VAT_NPR :
'NotDefined';
173 if (
price2num($obj->tva_tx) || !empty($obj->vat_src_code))
175 $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.
')' :
''));
179 $line->fetch($obj->fdid);
181 $tabfac[$obj->rowid][
"date"] = $db->jdate($obj->df);
182 $tabfac[$obj->rowid][
"datereg"] = $db->jdate($obj->dlr);
183 $tabfac[$obj->rowid][
"ref"] = $obj->ref_supplier.
' ('.$obj->ref.
')';
184 $tabfac[$obj->rowid][
"refsologest"] = $obj->ref;
185 $tabfac[$obj->rowid][
"refsuppliersologest"] = $obj->ref_supplier;
186 $tabfac[$obj->rowid][
"type"] = $obj->type;
187 $tabfac[$obj->rowid][
"description"] = $obj->description;
188 $tabfac[$obj->rowid][
"close_code"] = $obj->close_code;
192 if (!isset($tabttc[$obj->rowid][$compta_soc])) $tabttc[$obj->rowid][$compta_soc] = 0;
193 if (!isset($tabht[$obj->rowid][$compta_prod])) $tabht[$obj->rowid][$compta_prod] = 0;
194 if (!isset($tabtva[$obj->rowid][$compta_tva])) $tabtva[$obj->rowid][$compta_tva] = 0;
195 if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
196 if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
198 $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc;
199 $tabht[$obj->rowid][$compta_prod] += $obj->total_ht;
200 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
201 if (!empty($line->tva_npr))
203 $tabother[$obj->rowid][$compta_counterpart_tva_npr] += $obj->total_tva;
205 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
206 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
207 $tabcompany[$obj->rowid] = array(
209 'name' => $obj->name,
210 'code_fournisseur' => $obj->code_fournisseur,
211 'code_compta_fournisseur' => $compta_soc
220 $errorforinvoice = array();
223 foreach ($tabfac as $key => $val) {
224 $sql =
"SELECT COUNT(fd.rowid) as nb";
225 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn_det as fd";
226 $sql .=
" WHERE fd.product_type <= 2 AND fd.fk_code_ventilation <= 0";
227 $sql .=
" AND fd.total_ttc <> 0 AND fk_facture_fourn = ".$key;
228 $resql = $db->query($sql);
231 $obj = $db->fetch_object(
$resql);
234 $errorforinvoice[$key] =
'somelinesarenotbound';
243 if ($action ==
'writebookkeeping') {
247 $companystatic =
new Societe($db);
250 foreach ($tabfac as $key => $val) {
258 $companystatic->id = $tabcompany[$key][
'id'];
259 $companystatic->name = $tabcompany[$key][
'name'];
260 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
261 $companystatic->code_compta_fournisseur = $tabcompany[$key][
'code_compta_fournisseur'];
262 $companystatic->code_client = $tabcompany[$key][
'code_client'];
263 $companystatic->code_fournisseur = $tabcompany[$key][
'code_fournisseur'];
264 $companystatic->fournisseur = 1;
266 $invoicestatic->id = $key;
267 $invoicestatic->ref = (string) $val[
"refsologest"];
268 $invoicestatic->ref_supplier = $val[
"refsuppliersologest"];
269 $invoicestatic->type = $val[
"type"];
270 $invoicestatic->description = html_entity_decode(
dol_trunc($val[
"description"], 32));
271 $invoicestatic->close_code = $val[
"close_code"];
276 $replacedinvoice = 0;
277 if ($invoicestatic->close_code == FactureFournisseur::CLOSECODE_REPLACED)
279 $replacedinvoice = 1;
280 $alreadydispatched = $invoicestatic->getVentilExportCompta();
281 if ($alreadydispatched) $replacedinvoice = 2;
285 if ($replacedinvoice == 1)
292 if ($errorforinvoice[$key] ==
'somelinesarenotbound')
296 setEventMessages($langs->trans(
'ErrorInvoiceContainsLinesNotYetBounded', $val[
'ref']), null,
'errors');
302 foreach ($tabttc[$key] as $k => $mt) {
304 $bookkeeping->doc_date = $val[
"date"];
305 $bookkeeping->date_lim_reglement = $val[
"datereg"];
306 $bookkeeping->doc_ref = $val[
"refsologest"];
307 $bookkeeping->date_creation = $now;
308 $bookkeeping->doc_type =
'supplier_invoice';
309 $bookkeeping->fk_doc = $key;
310 $bookkeeping->fk_docdet = 0;
311 $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
312 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta_fournisseur'];
313 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
314 $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER;
316 $accountingaccount->fetch(null, $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER,
true);
317 $bookkeeping->label_compte = $accountingaccount->label;
319 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref_supplier.
' - '.$langs->trans(
"SubledgerAccount");
320 $bookkeeping->montant = $mt;
321 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
322 $bookkeeping->debit = ($mt <= 0) ? -$mt : 0;
323 $bookkeeping->credit = ($mt > 0) ? $mt : 0;
324 $bookkeeping->code_journal = $journal;
325 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
326 $bookkeeping->fk_user_author = $user->id;
327 $bookkeeping->entity = $conf->entity;
329 $totaldebit += $bookkeeping->debit;
330 $totalcredit += $bookkeeping->credit;
332 $result = $bookkeeping->create($user);
334 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists')
338 $errorforinvoice[$key] =
'alreadyjournalized';
343 $errorforinvoice[$key] =
'other';
353 foreach ($tabht[$key] as $k => $mt) {
355 if ($accountingaccount->fetch(null, $k,
true)) {
357 $bookkeeping->doc_date = $val[
"date"];
358 $bookkeeping->date_lim_reglement = $val[
"datereg"];
359 $bookkeeping->doc_ref = $val[
"refsologest"];
360 $bookkeeping->date_creation = $now;
361 $bookkeeping->doc_type =
'supplier_invoice';
362 $bookkeeping->fk_doc = $key;
363 $bookkeeping->fk_docdet = 0;
364 $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
365 $bookkeeping->subledger_account =
'';
366 $bookkeeping->subledger_label =
'';
367 $bookkeeping->numero_compte = $k;
368 $bookkeeping->label_compte = $accountingaccount->label;
369 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref_supplier.
' - '.$accountingaccount->label;
370 $bookkeeping->montant = $mt;
371 $bookkeeping->sens = ($mt < 0) ?
'C' :
'D';
372 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
373 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
374 $bookkeeping->code_journal = $journal;
375 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
376 $bookkeeping->fk_user_author = $user->id;
377 $bookkeeping->entity = $conf->entity;
379 $totaldebit += $bookkeeping->debit;
380 $totalcredit += $bookkeeping->credit;
382 $result = $bookkeeping->create($user);
384 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists')
388 $errorforinvoice[$key] =
'alreadyjournalized';
393 $errorforinvoice[$key] =
'other';
405 $listoftax = array(0, 1, 2);
406 foreach ($listoftax as $numtax)
408 $arrayofvat = $tabtva;
409 if ($numtax == 1) $arrayofvat = $tablocaltax1;
410 if ($numtax == 2) $arrayofvat = $tablocaltax2;
412 foreach ($arrayofvat[$key] as $k => $mt) {
415 $bookkeeping->doc_date = $val[
"date"];
416 $bookkeeping->date_lim_reglement = $val[
"datereg"];
417 $bookkeeping->doc_ref = $val[
"refsologest"];
418 $bookkeeping->date_creation = $now;
419 $bookkeeping->doc_type =
'supplier_invoice';
420 $bookkeeping->fk_doc = $key;
421 $bookkeeping->fk_docdet = 0;
422 $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
423 $bookkeeping->subledger_account =
'';
424 $bookkeeping->subledger_label =
'';
425 $bookkeeping->numero_compte = $k;
427 $accountingaccount->fetch($k, null,
true);
428 $bookkeeping->label_compte = $accountingaccount->label;
430 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref_supplier.
' - '.$langs->trans(
"VAT").
' '.join(
', ', $def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
'');
431 $bookkeeping->montant = $mt;
432 $bookkeeping->sens = ($mt < 0) ?
'C' :
'D';
433 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
434 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
435 $bookkeeping->code_journal = $journal;
436 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
437 $bookkeeping->fk_user_author = $user->id;
438 $bookkeeping->entity = $conf->entity;
440 $totaldebit += $bookkeeping->debit;
441 $totalcredit += $bookkeeping->credit;
443 $result = $bookkeeping->create($user);
445 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists')
449 $errorforinvoice[$key] =
'alreadyjournalized';
454 $errorforinvoice[$key] =
'other';
465 if (!$errorforline && is_array($tabother[$key]))
467 foreach ($tabother[$key] as $k => $mt) {
470 $bookkeeping->doc_date = $val[
"date"];
471 $bookkeeping->date_lim_reglement = $val[
"datereg"];
472 $bookkeeping->doc_ref = $val[
"refsologest"];
473 $bookkeeping->date_creation = $now;
474 $bookkeeping->doc_type =
'supplier_invoice';
475 $bookkeeping->fk_doc = $key;
476 $bookkeeping->fk_docdet = 0;
477 $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
478 $bookkeeping->subledger_account =
'';
479 $bookkeeping->subledger_label =
'';
480 $bookkeeping->numero_compte = $k;
481 $bookkeeping->label_operation =
dol_trunc($companystatic->name, 16).
' - '.$invoicestatic->ref_supplier.
' - '.$langs->trans(
"VAT").
' NPR';
482 $bookkeeping->montant = $mt;
483 $bookkeeping->sens = ($mt < 0) ?
'C' :
'D';
484 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
485 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
486 $bookkeeping->code_journal = $journal;
487 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
488 $bookkeeping->fk_user_author = $user->id;
489 $bookkeeping->entity = $conf->entity;
491 $totaldebit += $bookkeeping->debit;
492 $totalcredit += $bookkeeping->credit;
494 $result = $bookkeeping->create($user);
496 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists')
500 $errorforinvoice[$key] =
'alreadyjournalized';
505 $errorforinvoice[$key] =
'other';
514 if (!$errorforline && (
price2num($totaldebit,
'MT') !=
price2num($totalcredit,
'MT')))
518 $errorforinvoice[$key] =
'amountsnotbalanced';
519 setEventMessages(
'Try to insert a non balanced transaction in book for '.$invoicestatic->ref.
'. Canceled. Surely a bug.', null,
'errors');
530 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped"), null,
'errors');
538 if (empty($error) && count($tabpay) > 0) {
540 } elseif (count($tabpay) == $error)
544 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"), null,
'warnings');
550 if (count($tabpay) != $error)
552 $param =
'id_journal='.$id_journal;
553 $param .=
'&date_startday='.$date_startday;
554 $param .=
'&date_startmonth='.$date_startmonth;
555 $param .=
'&date_startyear='.$date_startyear;
556 $param .=
'&date_endday='.$date_endday;
557 $param .=
'&date_endmonth='.$date_endmonth;
558 $param .=
'&date_endyear='.$date_endyear;
559 $param .=
'&in_bookkeeping='.$in_bookkeeping;
560 header(
"Location: ".
$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
569 $form =
new Form($db);
572 if ($action ==
'exportcsv') {
573 $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
575 $filename =
'journal';
576 $type_export =
'journal';
577 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
582 foreach ($tabfac as $key => $val)
584 $companystatic->id = $tabcompany[$key][
'id'];
585 $companystatic->name = $tabcompany[$key][
'name'];
586 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
587 $companystatic->code_compta_fournisseur = $tabcompany[$key][
'code_compta_fournisseur'];
588 $companystatic->code_client = $tabcompany[$key][
'code_client'];
589 $companystatic->code_fournisseur = $tabcompany[$key][
'code_fournisseur'];
590 $companystatic->fournisseur = 1;
592 $invoicestatic->id = $key;
593 $invoicestatic->ref = $val[
"refsologest"];
594 $invoicestatic->ref_supplier = $val[
"refsuppliersologest"];
595 $invoicestatic->type = $val[
"type"];
596 $invoicestatic->description =
dol_trunc(html_entity_decode($val[
"description"]), 32);
597 $invoicestatic->close_code = $val[
"close_code"];
602 $replacedinvoice = 0;
603 if ($invoicestatic->close_code == FactureFournisseur::CLOSECODE_REPLACED)
605 $replacedinvoice = 1;
606 $alreadydispatched = $invoicestatic->getVentilExportCompta();
607 if ($alreadydispatched) $replacedinvoice = 2;
611 if ($replacedinvoice == 1)
617 foreach ($tabttc[$key] as $k => $mt) {
619 print '"'.$key.
'"'.$sep;
620 print '"'.$date.
'"'.$sep;
621 print '"'.$val[
"refsologest"].
'"'.$sep;
622 print '"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
623 print '"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
624 print '"'.$conf->global->ACCOUNTING_ACCOUNT_SUPPLIER.
'"'.$sep;
625 print '"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
626 print '"'.$langs->trans(
"Thirdparty").
'"'.$sep;
627 print '"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.$val[
"refsuppliersologest"].
' - '.$langs->trans(
"Thirdparty").
'"'.$sep;
628 print '"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
629 print '"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
630 print '"'.$journal.
'"';
636 foreach ($tabht[$key] as $k => $mt) {
638 $accountingaccount->fetch(null, $k,
true);
640 print '"'.$key.
'"'.$sep;
641 print '"'.$date.
'"'.$sep;
642 print '"'.$val[
"refsologest"].
'"'.$sep;
643 print '"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
644 print '"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
645 print '"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
647 print '"'.utf8_decode(
dol_trunc($accountingaccount->label, 32)).
'"'.$sep;
648 print '"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.$val[
"refsuppliersologest"].
' - '.
dol_trunc($accountingaccount->label, 32).
'"'.$sep;
649 print '"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
650 print '"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
651 print '"'.$journal.
'"';
657 $listoftax = array(0, 1, 2);
658 foreach ($listoftax as $numtax) {
659 $arrayofvat = $tabtva;
660 if ($numtax == 1) $arrayofvat = $tablocaltax1;
661 if ($numtax == 2) $arrayofvat = $tablocaltax2;
663 foreach ($arrayofvat[$key] as $k => $mt) {
665 print '"'.$key.
'"'.$sep;
666 print '"'.$date.
'"'.$sep;
667 print '"'.$val[
"refsologest"].
'"'.$sep;
668 print '"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
669 print '"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
670 print '"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
672 print '"'.$langs->trans(
"VAT").
' - '.join(
', ', $def_tva[$key][$k]).
' %"'.$sep;
673 print '"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.$val[
"refsuppliersologest"].
' - '.$langs->trans(
"VAT").join(
', ', $def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
'').
'"'.$sep;
674 print '"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
675 print '"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
676 print '"'.$journal.
'"';
682 if (is_array($tabother[$key]))
684 foreach ($tabother[$key] as $k => $mt) {
686 print '"'.$key.
'"'.$sep;
687 print '"'.$date.
'"'.$sep;
688 print '"'.$val[
"refsologest"].
'"'.$sep;
689 print '"'.utf8_decode(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
690 print '"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
691 print '"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
692 print '"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
693 print '"'.$langs->trans(
"Thirdparty").
'"'.$sep;
694 print '"'.utf8_decode(
dol_trunc($companystatic->name, 16)).
' - '.$val[
"refsuppliersologest"].
' - '.$langs->trans(
"VAT").
' NPR"'.$sep;
695 print '"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
696 print '"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
697 print '"'.$journal.
'"';
706 if (empty($action) || $action ==
'view') {
707 llxHeader(
'', $langs->trans(
"PurchasesJournal"));
709 $nom = $langs->trans(
"PurchasesJournal").
' | '.$accountingjournalstatic->getNomUrl(0, 1, 1,
'', 1);
714 $description .= $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
715 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
716 $description .= $langs->trans(
"DepositsAreNotIncluded");
718 $description .= $langs->trans(
"DepositsAreIncluded");
721 $listofchoices = array(
'notyet'=>$langs->trans(
"NotYetInGeneralLedger"),
'already'=>$langs->trans(
"AlreadyInGeneralLedger"));
722 $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);
723 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
725 $varlink =
'id_journal='.$id_journal;
727 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
730 if (($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
"") || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
'-1') {
732 print img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
733 print ' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>');
735 print '<div class="tabsAction tabsActionNoBottom">';
736 if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping ==
'notyet')
print '<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
737 if (($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
"") || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER ==
'-1') {
738 print '<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
740 if ($in_bookkeeping ==
'notyet')
print '<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
741 else print '<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
747 <script type="text/javascript">
748 function launch_export() {
749 $("div.fiche form input[name=\"action\"]").val("exportcsv");
750 $("div.fiche form input[type=\"submit\"]").click();
751 $("div.fiche form input[name=\"action\"]").val("");
753 function writebookkeeping() {
754 console.log("click on writebookkeeping");
755 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
756 $("div.fiche form input[type=\"submit\"]").click();
757 $("div.fiche form input[name=\"action\"]").val("");
767 print '<div class="div-table-responsive">';
768 print "<table class=\"noborder\" width=\"100%\">";
769 print "<tr class=\"liste_titre\">";
770 print "<td>".$langs->trans(
"Date").
"</td>";
771 print "<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"InvoiceRef").
")</td>";
772 print "<td>".$langs->trans(
"AccountAccounting").
"</td>";
773 print "<td>".$langs->trans(
"SubledgerAccount").
"</td>";
774 print "<td>".$langs->trans(
"LabelOperation").
"</td>";
775 print '<td class="center">'.$langs->trans(
"Debit").
"</td>";
776 print '<td class="center">'.$langs->trans(
"Credit").
"</td>";
784 foreach ($tabfac as $key => $val)
786 $companystatic->id = $tabcompany[$key][
'id'];
787 $companystatic->name = $tabcompany[$key][
'name'];
788 $companystatic->code_compta = $tabcompany[$key][
'code_compta'];
789 $companystatic->code_compta_fournisseur = $tabcompany[$key][
'code_compta_fournisseur'];
790 $companystatic->code_client = $tabcompany[$key][
'code_client'];
791 $companystatic->code_fournisseur = $tabcompany[$key][
'code_fournisseur'];
792 $companystatic->fournisseur = 1;
794 $invoicestatic->id = $key;
795 $invoicestatic->ref = $val[
"refsologest"];
796 $invoicestatic->ref_supplier = $val[
"refsuppliersologest"];
797 $invoicestatic->type = $val[
"type"];
798 $invoicestatic->description =
dol_trunc(html_entity_decode($val[
"description"]), 32);
799 $invoicestatic->close_code = $val[
"close_code"];
804 $replacedinvoice = 0;
805 if ($invoicestatic->close_code == FactureFournisseur::CLOSECODE_REPLACED)
807 $replacedinvoice = 1;
808 $alreadydispatched = $invoicestatic->getVentilExportCompta();
809 if ($alreadydispatched) $replacedinvoice = 2;
813 if ($replacedinvoice == 1)
815 print '<tr class="oddeven">';
816 print "<!-- Replaced invoice -->";
817 print "<td>".$date.
"</td>";
818 print "<td><strike>".$invoicestatic->getNomUrl(1).
"</strike></td>";
821 print $langs->trans(
"Replaced");
828 print '<td class="right"></td>';
829 print '<td class="right"></td>';
834 if ($errorforinvoice[$key] ==
'somelinesarenotbound')
836 print '<tr class="oddeven">';
837 print "<!-- Some lines are not bound -->";
838 print "<td>".$date.
"</td>";
839 print "<td>".$invoicestatic->getNomUrl(1).
"</td>";
842 print '<span class="error">'.$langs->trans(
'ErrorInvoiceContainsLinesNotYetBoundedShort', $val[
'ref']).
'</span>';
849 print '<td class="right"></td>';
850 print '<td class="right"></td>';
855 foreach ($tabttc[$key] as $k => $mt) {
856 print '<tr class="oddeven">';
857 print "<!-- Thirdparty -->";
858 print "<td>".$date.
"</td>";
859 print "<td>".$invoicestatic->getNomUrl(1).
"</td>";
862 $accountoshow =
length_accounta($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER);
863 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined')
865 print '<span class="error">'.$langs->trans(
"MainAccountForSuppliersNotDefined").
'</span>';
866 }
else print $accountoshow;
871 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined')
873 print '<span class="error">'.$langs->trans(
"ThirdpartyAccountNotDefined").
'</span>';
874 }
else print $accountoshow;
876 print "<td>".$companystatic->getNomUrl(0,
'supplier', 16).
' - '.$invoicestatic->ref_supplier.
' - '.$langs->trans(
"SubledgerAccount").
"</td>";
877 print '<td class="right nowraponall">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
878 print '<td class="right nowraponall">'.($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')
896 print '<span class="error">'.$langs->trans(
"ProductAccountNotDefined").
'</span>';
897 }
else print $accountoshow;
902 $companystatic->id = $tabcompany[$key][
'id'];
903 $companystatic->name = $tabcompany[$key][
'name'];
904 print "<td>".$companystatic->getNomUrl(0,
'supplier', 16).
' - '.$invoicestatic->ref_supplier.
' - '.$accountingaccount->label.
"</td>";
905 print '<td class="right nowraponall">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
906 print '<td class="right nowraponall">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
911 $listoftax = array(0, 1, 2);
912 foreach ($listoftax as $numtax) {
913 $arrayofvat = $tabtva;
914 if ($numtax == 1) $arrayofvat = $tablocaltax1;
915 if ($numtax == 2) $arrayofvat = $tablocaltax2;
917 foreach ($arrayofvat[$key] as $k => $mt) {
919 print '<tr class="oddeven">';
920 print "<!-- VAT -->";
921 print "<td>".$date.
"</td>";
922 print "<td>".$invoicestatic->getNomUrl(1).
"</td>";
926 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined')
928 print '<span class="error">'.$langs->trans(
"VATAccountNotDefined").
' ('.$langs->trans(
"Purchase").
')</span>';
929 }
else print $accountoshow;
935 print $companystatic->getNomUrl(0,
'supplier', 16).
' - '.$invoicestatic->ref_supplier.
' - '.$langs->trans(
"VAT").
' '.join(
', ', $def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
'');
937 print '<td class="right nowraponall">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
938 print '<td class="right nowraponall">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
945 if (is_array($tabother[$key]))
947 foreach ($tabother[$key] as $k => $mt) {
949 print '<tr class="oddeven">';
950 print '<!-- VAT counterpart NPR -->';
951 print "<td>".$date.
"</td>";
952 print "<td>".$invoicestatic->getNomUrl(1).
"</td>";
956 if ($accountoshow ==
'' || $accountoshow ==
'NotDefined')
958 print '<span class="error">'.$langs->trans(
"VATAccountNotDefined").
' ('.$langs->trans(
"NPR counterpart").
'). Set ACCOUNTING_COUNTERPART_VAT_NPR to the subvention account</span>';
959 }
else print $accountoshow;
964 print "<td>".$companystatic->getNomUrl(0,
'supplier', 16).
' - '.$invoicestatic->ref_supplier.
' - '.$langs->trans(
"VAT").
" NPR (counterpart)</td>";
965 print '<td class="right nowraponall">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
966 print '<td class="right nowraponall">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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...
const TYPE_DEPOSIT
Deposit invoice.
Class to manage line invoices.
dol_now($mode= 'auto')
Return date for now.
getDefaultDatesForTransfer()
Return Default dates for transfer based on periodicity option in accountancy setup.
getTaxesFromId($vatrate, $buyer=null, $seller=null, $firstparamisid=1)
Get tax (VAT) main information from Id.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
const TYPE_REPLACEMENT
Replacement invoice.
Class to manage suppliers invoices.
journalHead($nom, $variante, $period, $periodlink, $description, $builddate, $exportlink= '', $moreparam=array(), $calcmode= '', $varlink= '')
Show header of a page used to transfer/dispatch data in accounting.
Class to manage suppliers.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
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...
Class to manage Ledger (General Ledger and Subledger)
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages...
print $_SERVER["PHP_SELF"]
Edit parameters.
const TYPE_CREDIT_NOTE
Credit note invoice.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
const TYPE_SITUATION
Situation invoice.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
Class to manage accounting accounts.
Class to manage accounting accounts.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.