33require
'../../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
38require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
54$langs->loadLangs(array(
"commercial",
"compta",
"bills",
"other",
"accountancy",
"errors"));
57$action =
GETPOST(
'action',
'aZ09');
59$date_startmonth =
GETPOSTINT(
'date_startmonth');
65$in_bookkeeping =
GETPOST(
'in_bookkeeping');
66if ($in_bookkeeping ==
'') {
67 $in_bookkeeping =
'notyet';
72$hookmanager->initHooks(array(
'purchasesjournal'));
79if ($user->socid > 0) {
82if (!$user->hasRight(
'accounting',
'bind',
'write')) {
92$tablocaltax1 = array();
93$tablocaltax2 = array();
95$tabrclocaltax1 = array();
96$tabrclocaltax2 = array();
99$cptcli =
'NotDefined';
100$cptfour =
'NotDefined';
106$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $user, $action);
112$accountingjournalstatic->fetch($id_journal);
113$journal = $accountingjournalstatic->code;
114$journal_label = $accountingjournalstatic->label;
116$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
117$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
120$pastmonthyear =
null;
122if (empty($date_startmonth)) {
125 $date_start = $dates[
'date_start'];
126 $pastmonthyear = $dates[
'pastmonthyear'];
127 $pastmonth = $dates[
'pastmonth'];
129if (empty($date_endmonth)) {
132 $date_end = $dates[
'date_end'];
133 $pastmonthyear = $dates[
'pastmonthyear'];
134 $pastmonth = $dates[
'pastmonth'];
137if (!GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end))) {
139 $date_end =
dol_get_last_day((
int) $pastmonthyear, (
int) $pastmonth,
false);
142$sql =
"SELECT f.rowid, f.ref as ref, f.type, f.datef as df, f.libelle as label, f.ref_supplier, f.date_lim_reglement as dlr, f.close_code, f.vat_reverse_charge,";
143$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.localtax1_tx, fd.localtax2_tx, fd.total_ttc, fd.vat_src_code, fd.info_bits,";
144$sql .=
" p.default_vat_code AS product_buy_default_vat_code, p.tva_tx as product_buy_vat, p.localtax1_tx as product_buy_localvat1, p.localtax2_tx as product_buy_localvat2,";
145$sql .=
" co.code as country_code, co.label as country_label,";
146$sql .=
" s.rowid as socid, s.nom as name, s.fournisseur, s.code_client, s.code_fournisseur, s.fk_pays,";
148 $sql .=
" spe.accountancy_code_customer_general,";
149 $sql .=
" spe.accountancy_code_customer as code_compta,";
150 $sql .=
" spe.accountancy_code_supplier_general,";
151 $sql .=
" spe.accountancy_code_supplier as code_compta_fournisseur,";
153 $sql .=
" s.accountancy_code_customer_general,";
154 $sql .=
" s.code_compta as code_compta,";
155 $sql .=
" s.accountancy_code_supplier_general,";
156 $sql .=
" s.code_compta_fournisseur,";
159 $sql .=
" ppe.accountancy_code_buy,";
161 $sql .=
" p.accountancy_code_buy,";
163$sql .=
" aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte";
164$parameters = array();
165$reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
166$sql .= $hookmanager->resPrint;
167$sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn_det as fd";
168$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = fd.fk_product";
170 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
172$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
173$sql .=
" JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f ON f.rowid = fd.fk_facture_fourn";
174$sql .=
" JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
175$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co ON co.rowid = s.fk_pays ";
177 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
179$parameters = array();
180$reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters);
181$sql .= $hookmanager->resPrint;
182$sql .=
" WHERE f.fk_statut > 0";
183$sql .=
" AND fd.fk_code_ventilation > 0";
184$sql .=
" AND f.entity IN (".getEntity(
'facture_fourn', 0).
")";
190if ($date_start && $date_end) {
191 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
195 $sql .=
" AND f.datef >= '".$db->idate(
getDolGlobalInt(
'ACCOUNTING_DATE_START_BINDING')).
"'";
198if ($in_bookkeeping ==
'already') {
199 $sql .=
" AND f.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='supplier_invoice')";
201if ($in_bookkeeping ==
'notyet') {
202 $sql .=
" AND f.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='supplier_invoice')";
204$parameters = array();
205$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
206$sql .= $hookmanager->resPrint;
207$sql .=
" ORDER BY f.datef";
209dol_syslog(
'accountancy/journal/purchasesjournal.php', LOG_DEBUG);
215$tablocaltax1 = array();
216$tablocaltax2 = array();
217$tabcompany = array();
220$tabrclocaltax1 = array();
221$tabrclocaltax2 = array();
222$vatdata_cache = array();
227$rcctva =
getDolGlobalString(
'ACCOUNTING_VAT_BUY_REVERSE_CHARGES_CREDIT',
'NotDefined');
228$rcdtva =
getDolGlobalString(
'ACCOUNTING_VAT_BUY_REVERSE_CHARGES_DEBIT',
'NotDefined');
230$rcclocaltax1 =
getDolGlobalString(
'ACCOUNTING_LT1_BUY_REVERSE_CHARGES_CREDIT',
'NotDefined');
231$rcdlocaltax1 =
getDolGlobalString(
'ACCOUNTING_LT1_BUY_REVERSE_CHARGES_DEBIT',
'NotDefined');
233$rcclocaltax2 =
getDolGlobalString(
'ACCOUNTING_LT2_BUY_REVERSE_CHARGES_CREDIT',
'NotDefined');
234$rcdlocaltax2 =
getDolGlobalString(
'ACCOUNTING_LT2_BUY_REVERSE_CHARGES_DEBIT',
'NotDefined');
235$noTaxDispatchingKeepWithLines =
getDolGlobalInt(
'ACCOUNTING_PURCHASES_DO_NOT_DISPATCH_TAXES');
238$result = $db->query($sql);
240 $num = $db->num_rows($result);
244 $obj = $db->fetch_object($result);
247 $accountancy_code_supplier_general = (!empty($obj->accountancy_code_supplier_general)) ? $obj->accountancy_code_supplier_general : $cptfour;
248 $compta_soc = ($obj->code_compta_fournisseur !=
"") ? $obj->code_compta_fournisseur : $cptfour;
250 $compta_prod = $obj->compte;
251 if (empty($compta_prod)) {
252 if ($obj->product_type == 0) {
259 $tax_id = $obj->tva_tx . ($obj->vat_src_code ?
' (' . $obj->vat_src_code .
')' :
'');
260 if (array_key_exists($tax_id, $vatdata_cache)) {
261 $vatdata = $vatdata_cache[$tax_id];
264 $vatdata_cache[$tax_id] = $vatdata;
266 $compta_tva = (!empty($vatdata[
'accountancy_code_buy']) ? $vatdata[
'accountancy_code_buy'] : $cpttva);
267 $compta_localtax1 = (!empty($vatdata[
'accountancy_code_buy']) ? $vatdata[
'accountancy_code_buy'] : $cptlocaltax1);
268 $compta_localtax2 = (!empty($vatdata[
'accountancy_code_buy']) ? $vatdata[
'accountancy_code_buy'] : $cptlocaltax2);
269 $compta_counterpart_tva_npr =
getDolGlobalString(
'ACCOUNTING_COUNTERPART_VAT_NPR',
'NotDefined');
272 if (
price2num($obj->tva_tx) || !empty($obj->vat_src_code)) {
273 $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.
')' :
''));
274 if ($obj->localtax1_tx > 0.0) {
275 $def_tva[$obj->rowid][$compta_localtax1][
vatrate($obj->localtax1_tx).($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
'').
' LT1'] = (
vatrate($obj->localtax1_tx).($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''));
277 if ($obj->localtax2_tx > 0.0) {
278 $def_tva[$obj->rowid][$compta_localtax2][
vatrate($obj->localtax2_tx).($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
'').
' LT2'] = (
vatrate($obj->localtax2_tx).($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''));
285 $tabfac[$obj->rowid][
"date"] = $db->jdate($obj->df);
286 $tabfac[$obj->rowid][
"datereg"] = $db->jdate($obj->dlr);
287 $tabfac[$obj->rowid][
"ref"] = $obj->ref_supplier.
' ('.$obj->ref.
')';
288 $tabfac[$obj->rowid][
"refsologest"] = $obj->ref;
289 $tabfac[$obj->rowid][
"refsuppliersologest"] = $obj->ref_supplier;
290 $tabfac[$obj->rowid][
"type"] = $obj->type;
291 $tabfac[$obj->rowid][
"description"] = $obj->description;
292 $tabfac[$obj->rowid][
"close_code"] = $obj->close_code;
296 if (!isset($tabttc[$obj->rowid][$compta_soc])) {
297 $tabttc[$obj->rowid][$compta_soc] = 0;
299 if (!isset($tabht[$obj->rowid][$compta_prod])) {
300 $tabht[$obj->rowid][$compta_prod] = 0;
302 if (!isset($tabtva[$obj->rowid][$compta_tva])) {
303 $tabtva[$obj->rowid][$compta_tva] = 0;
305 if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
306 $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
308 if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
309 $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
313 if ((
$mysoc->country_code ==
'FR' ||
getDolGlobalString(
'ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) && $obj->vat_reverse_charge == 1 && (in_array($obj->country_code, $country_code_in_EEC) ||
getDolGlobalString(
'ACCOUNTING_REVERSE_CHARGE_ALSO_NON_EEC'))) {
314 $rcvatdata =
getTaxesFromId($obj->product_buy_vat . ($obj->product_buy_default_vat_code ?
' (' . $obj->product_buy_default_vat_code .
')' :
''),
$mysoc,
$mysoc, 0);
315 $rcc_compta_tva = (!empty($vatdata[
'accountancy_code_vat_reverse_charge_credit']) ? $vatdata[
'accountancy_code_vat_reverse_charge_credit'] : $rcctva);
316 $rcd_compta_tva = (!empty($vatdata[
'accountancy_code_vat_reverse_charge_debit']) ? $vatdata[
'accountancy_code_vat_reverse_charge_debit'] : $rcdtva);
317 $rcc_compta_localtax1 = (!empty($vatdata[
'accountancy_code_vat_reverse_charge_credit']) ? $vatdata[
'accountancy_code_vat_reverse_charge_credit'] : $rcclocaltax1);
318 $rcd_compta_localtax1 = (!empty($vatdata[
'accountancy_code_vat_reverse_charge_debit']) ? $vatdata[
'accountancy_code_vat_reverse_charge_debit'] : $rcdlocaltax1);
319 $rcc_compta_localtax2 = (!empty($vatdata[
'accountancy_code_vat_reverse_charge_credit']) ? $vatdata[
'accountancy_code_vat_reverse_charge_credit'] : $rcclocaltax2);
320 $rcd_compta_localtax2 = (!empty($vatdata[
'accountancy_code_vat_reverse_charge_debit']) ? $vatdata[
'accountancy_code_vat_reverse_charge_debit'] : $rcdlocaltax2);
321 if (
price2num($obj->product_buy_vat) || !empty($obj->product_buy_default_vat_code)) {
322 $vat_key =
vatrate($obj->product_buy_vat) . ($obj->product_buy_default_vat_code ?
' (' . $obj->product_buy_default_vat_code .
')' :
'');
323 $val_value = $vat_key;
324 $def_tva[$obj->rowid][$rcc_compta_tva][$vat_key] = $val_value;
325 $def_tva[$obj->rowid][$rcd_compta_tva][$vat_key] = $val_value;
328 if (!isset($tabrctva[$obj->rowid][$rcc_compta_tva])) {
329 $tabrctva[$obj->rowid][$rcc_compta_tva] = 0;
331 if (!isset($tabrctva[$obj->rowid][$rcd_compta_tva])) {
332 $tabrctva[$obj->rowid][$rcd_compta_tva] = 0;
334 if (!isset($tabrclocaltax1[$obj->rowid][$rcc_compta_localtax1])) {
335 $tabrclocaltax1[$obj->rowid][$rcc_compta_localtax1] = 0;
337 if (!isset($tabrclocaltax1[$obj->rowid][$rcd_compta_localtax1])) {
338 $tabrclocaltax1[$obj->rowid][$rcd_compta_localtax1] = 0;
340 if (!isset($tabrclocaltax2[$obj->rowid][$rcc_compta_localtax2])) {
341 $tabrclocaltax2[$obj->rowid][$rcc_compta_localtax2] = 0;
343 if (!isset($tabrclocaltax2[$obj->rowid][$rcd_compta_localtax2])) {
344 $tabrclocaltax2[$obj->rowid][$rcd_compta_localtax2] = 0;
347 $rcvat = (float)
price2num($obj->total_ttc * $obj->product_buy_vat / 100,
'MT');
348 $rclocalvat1 = (float)
price2num($obj->total_ttc * $obj->product_buy_localvat1 / 100,
'MT');
349 $rclocalvat2 = (float)
price2num($obj->total_ttc * $obj->product_buy_localvat2 / 100,
'MT');
351 $tabrctva[$obj->rowid][$rcd_compta_tva] += $rcvat;
352 $tabrctva[$obj->rowid][$rcc_compta_tva] -= $rcvat;
353 $tabrclocaltax1[$obj->rowid][$rcd_compta_localtax1] += $rclocalvat1;
354 $tabrclocaltax1[$obj->rowid][$rcc_compta_localtax1] -= $rclocalvat1;
355 $tabrclocaltax2[$obj->rowid][$rcd_compta_localtax2] += $rclocalvat2;
356 $tabrclocaltax2[$obj->rowid][$rcc_compta_localtax2] -= $rclocalvat2;
359 $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc;
361 if ($noTaxDispatchingKeepWithLines) {
362 $tabht[$obj->rowid][$compta_prod] += $obj->total_ttc;
364 $tabht[$obj->rowid][$compta_prod] += $obj->total_ht;
365 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
366 $tva_npr = ((($obj->info_bits & 1) == 1) ? 1 : 0);
368 $tabother[$obj->rowid][$compta_counterpart_tva_npr] += $obj->total_tva;
370 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
371 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
373 $tabcompany[$obj->rowid] = array(
375 'name' => $obj->name,
376 'code_fournisseur' => $obj->code_fournisseur,
377 'accountancy_code_supplier_general' => $accountancy_code_supplier_general,
378 'code_compta_fournisseur' => $compta_soc
384 if ($i >
getDolGlobalInt(
'ACCOUNTANCY_MAX_TOO_MANY_LINES_TO_PROCESS', 10000)) {
386 setEventMessages(
"ErrorTooManyLinesToProcessPleaseUseAMoreSelectiveFilter",
null,
'errors');
394$errorforinvoice = array();
417if (!empty($tabfac)) {
421 COUNT(fd.rowid) as nb
423 " . MAIN_DB_PREFIX .
"facture_fourn_det as fd
426 AND fd.fk_code_ventilation <= 0
427 AND fd.total_ttc <> 0
428 AND fk_facture_fourn IN (".$db->sanitize(implode(
",", array_keys($tabfac))).
")
429 GROUP BY fk_facture_fourn
431 $resql = $db->query($sql);
433 $num = $db->num_rows($resql);
436 $obj = $db->fetch_object($resql);
438 $errorforinvoice[$obj->fk_facture_fourn] =
'somelinesarenotbound';
445if ($action ==
'writebookkeeping' && !$error && $user->hasRight(
'accounting',
'bind',
'write')) {
449 $companystatic =
new Societe($db);
454 $accountingaccountsupplier->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUPPLIER'),
true);
456 foreach ($tabfac as $key => $val) {
464 $companystatic->id = $tabcompany[$key][
'id'];
465 $companystatic->name = $tabcompany[$key][
'name'];
466 $companystatic->accountancy_code_supplier_general = $tabcompany[$key][
'accountancy_code_supplier_general'];
467 $companystatic->code_compta_fournisseur = $tabcompany[$key][
'code_compta_fournisseur'];
468 $companystatic->code_fournisseur = $tabcompany[$key][
'code_fournisseur'];
469 $companystatic->fournisseur = 1;
471 $invoicestatic->id = $key;
472 $invoicestatic->ref = (string) $val[
"refsologest"];
473 $invoicestatic->ref_supplier = $val[
"refsuppliersologest"];
474 $invoicestatic->type = $val[
"type"];
475 $invoicestatic->description = html_entity_decode(
dol_trunc($val[
"description"], 32));
476 $invoicestatic->close_code = $val[
"close_code"];
481 $replacedinvoice = 0;
482 if ($invoicestatic->close_code == FactureFournisseur::CLOSECODE_REPLACED) {
483 $replacedinvoice = 1;
484 $alreadydispatched = $invoicestatic->getVentilExportCompta();
485 if ($alreadydispatched) {
486 $replacedinvoice = 2;
491 if ($replacedinvoice == 1) {
497 if (isset($errorforinvoice[$key]) && $errorforinvoice[$key] ==
'somelinesarenotbound') {
500 setEventMessages($langs->trans(
'ErrorInvoiceContainsLinesNotYetBounded', $val[
'ref']),
null,
'errors');
504 if (!$errorforline) {
505 foreach ($tabttc[$key] as $k => $mt) {
507 $bookkeeping->doc_date = $val[
"date"];
508 $bookkeeping->date_lim_reglement = $val[
"datereg"];
509 $bookkeeping->doc_ref = $val[
"refsologest"];
510 $bookkeeping->date_creation = $now;
511 $bookkeeping->doc_type =
'supplier_invoice';
512 $bookkeeping->fk_doc = $key;
513 $bookkeeping->fk_docdet = 0;
514 $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
516 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta_fournisseur'];
517 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
519 $bookkeeping->numero_compte = $tabcompany[$key][
'accountancy_code_supplier_general'];
520 $bookkeeping->label_compte = $accountingaccountsupplier->label;
522 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref_supplier, $langs->trans(
"SubledgerAccount"));
523 $bookkeeping->montant = $mt;
524 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
525 $bookkeeping->debit = ($mt <= 0) ? -$mt : 0;
526 $bookkeeping->credit = ($mt > 0) ? $mt : 0;
527 $bookkeeping->code_journal = $journal;
528 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
529 $bookkeeping->fk_user_author = $user->id;
530 $bookkeeping->entity = $conf->entity;
532 $totaldebit += $bookkeeping->debit;
533 $totalcredit += $bookkeeping->credit;
535 $result = $bookkeeping->create($user);
537 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
540 $errorforinvoice[$key] =
'alreadyjournalized';
545 $errorforinvoice[$key] =
'other';
550 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/lettering.class.php';
553 $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id));
560 if (!$errorforline) {
561 foreach ($tabht[$key] as $k => $mt) {
562 if (empty($conf->cache[
'accountingaccountincurrententity'][$k])) {
564 $accountingaccount->fetch(0, $k,
true);
565 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
567 $accountingaccount = $conf->cache[
'accountingaccountincurrententity'][$k];
570 $label_account = $accountingaccount->label;
573 if ($accountingaccount->id > 0) {
575 $bookkeeping->doc_date = $val[
"date"];
576 $bookkeeping->date_lim_reglement = $val[
"datereg"];
577 $bookkeeping->doc_ref = $val[
"refsologest"];
578 $bookkeeping->date_creation = $now;
579 $bookkeeping->doc_type =
'supplier_invoice';
580 $bookkeeping->fk_doc = $key;
581 $bookkeeping->fk_docdet = 0;
582 $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
586 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta_fournisseur'];
587 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
589 $bookkeeping->subledger_account =
'';
590 $bookkeeping->subledger_label =
'';
593 $bookkeeping->subledger_account =
'';
594 $bookkeeping->subledger_label =
'';
597 $bookkeeping->numero_compte = $k;
598 $bookkeeping->label_compte = $label_account;
600 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref_supplier, $label_account);
601 $bookkeeping->montant = $mt;
602 $bookkeeping->sens = ($mt < 0) ?
'C' :
'D';
603 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
604 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
605 $bookkeeping->code_journal = $journal;
606 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
607 $bookkeeping->fk_user_author = $user->id;
608 $bookkeeping->entity = $conf->entity;
610 $totaldebit += $bookkeeping->debit;
611 $totalcredit += $bookkeeping->credit;
613 $result = $bookkeeping->create($user);
615 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
618 $errorforinvoice[$key] =
'alreadyjournalized';
623 $errorforinvoice[$key] =
'other';
633 if (!$errorforline) {
634 $listoftax = array(0, 1, 2);
635 foreach ($listoftax as $numtax) {
636 $arrayofvat = $tabtva;
638 $arrayofvat = $tablocaltax1;
641 $arrayofvat = $tablocaltax2;
647 foreach ($arrayofvat[$key] as $k => $mt) {
654 $arrayofvat = $tabrctva;
656 $arrayofvat = $tabrclocaltax1;
659 $arrayofvat = $tabrclocaltax2;
661 if (!isset($arrayofvat[$key]) || !is_array($arrayofvat[$key])) {
662 $arrayofvat[$key] = array();
667 foreach ($arrayofvat[$key] as $k => $mt) {
669 if (empty($conf->cache[
'accountingaccountincurrententity_vat'][$k])) {
671 $accountingaccount->fetch(0, $k,
true);
672 $conf->cache[
'accountingaccountincurrententity_vat'][$k] = $accountingaccount;
674 $accountingaccount = $conf->cache[
'accountingaccountincurrententity_vat'][$k];
677 $label_account = $accountingaccount->label;
680 $bookkeeping->doc_date = $val[
"date"];
681 $bookkeeping->date_lim_reglement = $val[
"datereg"];
682 $bookkeeping->doc_ref = $val[
"refsologest"];
683 $bookkeeping->date_creation = $now;
684 $bookkeeping->doc_type =
'supplier_invoice';
685 $bookkeeping->fk_doc = $key;
686 $bookkeeping->fk_docdet = 0;
687 $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
689 $bookkeeping->subledger_account =
'';
690 $bookkeeping->subledger_label =
'';
692 $bookkeeping->numero_compte = $k;
693 $bookkeeping->label_compte = $label_account;
695 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
696 $labelvataccount = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
697 $labelvataccount .= ($numtax ?
' - Localtax '.$numtax :
'');
698 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref_supplier, $labelvataccount);
700 $bookkeeping->montant = $mt;
701 $bookkeeping->sens = ($mt < 0) ?
'C' :
'D';
702 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
703 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
704 $bookkeeping->code_journal = $journal;
705 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
706 $bookkeeping->fk_user_author = $user->id;
707 $bookkeeping->entity = $conf->entity;
709 $totaldebit += $bookkeeping->debit;
710 $totalcredit += $bookkeeping->credit;
712 $result = $bookkeeping->create($user);
714 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
717 $errorforinvoice[$key] =
'alreadyjournalized';
722 $errorforinvoice[$key] =
'other';
733 if (!$errorforline && isset($tabother[$key]) && is_array($tabother[$key])) {
734 foreach ($tabother[$key] as $k => $mt) {
737 $bookkeeping->doc_date = $val[
"date"];
738 $bookkeeping->date_lim_reglement = $val[
"datereg"];
739 $bookkeeping->doc_ref = $val[
"refsologest"];
740 $bookkeeping->date_creation = $now;
741 $bookkeeping->doc_type =
'supplier_invoice';
742 $bookkeeping->fk_doc = $key;
743 $bookkeeping->fk_docdet = 0;
744 $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
746 $bookkeeping->subledger_account =
'';
747 $bookkeeping->subledger_label =
'';
749 $bookkeeping->numero_compte = $k;
751 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref_supplier, $langs->trans(
"VAT").
' NPR');
752 $bookkeeping->montant = $mt;
753 $bookkeeping->sens = ($mt < 0) ?
'C' :
'D';
754 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
755 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
756 $bookkeeping->code_journal = $journal;
757 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
758 $bookkeeping->fk_user_author = $user->id;
759 $bookkeeping->entity = $conf->entity;
761 $totaldebit += $bookkeeping->debit;
762 $totalcredit += $bookkeeping->credit;
764 $result = $bookkeeping->create($user);
766 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
769 $errorforinvoice[$key] =
'alreadyjournalized';
774 $errorforinvoice[$key] =
'other';
783 if (!$errorforline && (
price2num($totaldebit,
'MT') !=
price2num($totalcredit,
'MT'))) {
786 $errorforinvoice[$key] =
'amountsnotbalanced';
787 setEventMessages(
'We tried to insert a non balanced transaction in book for '.$invoicestatic->ref.
'. Canceled. Surely a bug.',
null,
'errors');
790 if (!$errorforline) {
796 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped"),
null,
'errors');
804 if (empty($error) && count($tabpay) > 0) {
806 } elseif (count($tabpay) == $error) {
809 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
815 if (count($tabpay) != $error) {
816 $param =
'id_journal='.$id_journal;
817 $param .=
'&date_startday='.$date_startday;
818 $param .=
'&date_startmonth='.$date_startmonth;
819 $param .=
'&date_startyear='.$date_startyear;
820 $param .=
'&date_endday='.$date_endday;
821 $param .=
'&date_endmonth='.$date_endmonth;
822 $param .=
'&date_endyear='.$date_endyear;
823 $param .=
'&in_bookkeeping='.$in_bookkeeping;
824 header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
833$form =
new Form($db);
836if ($action ==
'exportcsv' && !$error) {
839 $filename =
'journal';
840 $type_export =
'journal';
841 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
847 foreach ($tabfac as $key => $val) {
848 $companystatic->id = $tabcompany[$key][
'id'];
849 $companystatic->name = $tabcompany[$key][
'name'];
850 $companystatic->accountancy_code_supplier_general = !empty($tabcompany[$key][
'accountancy_code_supplier_general']) ? $tabcompany[$key][
'accountancy_code_supplier_general'] : $cptfour;
851 $companystatic->code_compta_fournisseur = $tabcompany[$key][
'code_compta_fournisseur'];
852 $companystatic->code_fournisseur = $tabcompany[$key][
'code_fournisseur'];
853 $companystatic->fournisseur = 1;
855 $invoicestatic->id = $key;
856 $invoicestatic->ref = $val[
"refsologest"];
857 $invoicestatic->ref_supplier = $val[
"refsuppliersologest"];
858 $invoicestatic->type = $val[
"type"];
859 $invoicestatic->description =
dol_trunc(html_entity_decode($val[
"description"]), 32);
860 $invoicestatic->close_code = $val[
"close_code"];
865 $replacedinvoice = 0;
866 if ($invoicestatic->close_code == FactureFournisseur::CLOSECODE_REPLACED) {
867 $replacedinvoice = 1;
868 $alreadydispatched = $invoicestatic->getVentilExportCompta();
869 if ($alreadydispatched) {
870 $replacedinvoice = 2;
875 if ($replacedinvoice == 1) {
880 foreach ($tabttc[$key] as $k => $mt) {
882 print
'"'.$key.
'"'.$sep;
883 print
'"'.$date.
'"'.$sep;
884 print
'"'.$val[
"refsologest"].
'"'.$sep;
885 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
886 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
887 print
'"'.length_accountg($companystatic->accountancy_code_supplier_general).
'"'.$sep;
888 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
889 print
'"'.$langs->trans(
"ThirdParty").
'"'.$sep;
890 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $val[
"refsuppliersologest"], $langs->trans(
"ThirdParty"))).
'"'.$sep;
891 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
892 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
893 print
'"'.$journal.
'"';
899 foreach ($tabht[$key] as $k => $mt) {
901 $accountingaccount->fetch(0, $k,
true);
903 print
'"'.$key.
'"'.$sep;
904 print
'"'.$date.
'"'.$sep;
905 print
'"'.$val[
"refsologest"].
'"'.$sep;
906 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
907 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
908 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
910 print
'"'.csvClean(
dol_trunc($accountingaccount->label, 32)).
'"'.$sep;
911 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $val[
"refsuppliersologest"], $accountingaccount->label)).
'"'.$sep;
912 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
913 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
914 print
'"'.$journal.
'"';
920 $listoftax = array(0, 1, 2);
921 foreach ($listoftax as $numtax) {
922 $arrayofvat = $tabtva;
924 $arrayofvat = $tablocaltax1;
927 $arrayofvat = $tablocaltax2;
933 foreach ($arrayofvat[$key] as $k => $mt) {
940 $arrayofvat = $tabrctva;
942 $arrayofvat = $tabrclocaltax1;
945 $arrayofvat = $tabrclocaltax2;
947 if (!isset($arrayofvat[$key]) || !is_array($arrayofvat[$key])) {
948 $arrayofvat[$key] = array();
953 foreach ($arrayofvat[$key] as $k => $mt) {
955 print
'"'.$key.
'"'.$sep;
956 print
'"'.$date.
'"'.$sep;
957 print
'"'.$val[
"refsologest"].
'"'.$sep;
958 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
959 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
960 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
962 print
'"'.$langs->trans(
"VAT").
' - '.implode(
', ', $def_tva[$key][$k]).
' %"'.$sep;
963 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $val[
"refsuppliersologest"], $langs->trans(
"VAT").implode($def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
''))).
'"'.$sep;
964 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
965 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
966 print
'"'.$journal.
'"';
972 if (isset($tabother[$key]) && is_array($tabother[$key])) {
973 foreach ($tabother[$key] as $k => $mt) {
975 print
'"'.$key.
'"'.$sep;
976 print
'"'.$date.
'"'.$sep;
977 print
'"'.$val[
"refsologest"].
'"'.$sep;
978 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
979 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
980 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
981 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
982 print
'"'.$langs->trans(
"ThirdParty").
'"'.$sep;
983 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $val[
"refsuppliersologest"], $langs->trans(
"VAT").
' NPR')).
'"'.$sep;
984 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
985 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
986 print
'"'.$journal.
'"';
995if (empty($action) || $action ==
'view') {
996 $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1,
'', 1);
997 $help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
998 llxHeader(
'',
dol_string_nohtmltag($title), $help_url,
'', 0, 0,
'',
'',
'',
'mod-accountancy accountancy-generation page-purchasesjournal');
1005 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
1007 $description .= $langs->trans(
"DepositsAreNotIncluded");
1009 $description .= $langs->trans(
"DepositsAreIncluded");
1012 $listofchoices = array(
'notyet' => $langs->trans(
"NotYetInGeneralLedger"),
'already' => $langs->trans(
"AlreadyInGeneralLedger"));
1013 $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);
1014 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
1016 $varlink =
'id_journal='.$id_journal;
1018 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
1023 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_fiscalyear WHERE entity = ".((int) $conf->entity);
1024 $resql = $db->query($sql);
1026 $obj = $db->fetch_object($resql);
1027 if ($obj->nb == 0) {
1028 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheFiscalPeriodIsNotDefined");
1029 $desc =
' : '.$langs->trans(
"AccountancyAreaDescFiscalPeriod", 4,
'{link}');
1030 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"FiscalPeriod").
'</strong>', $desc);
1040 $acctSupplierNotConfigured = in_array(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUPPLIER'), [
'',
'-1']);
1041 if ($acctSupplierNotConfigured) {
1042 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
1043 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
1044 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
1048 print
'<br><div class="tabsAction tabsActionNoBottom centerimp">';
1049 if (
getDolGlobalString(
'ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping ==
'notyet') {
1050 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
1052 if ($acctSupplierNotConfigured) {
1053 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
1055 if ($in_bookkeeping ==
'notyet') {
1056 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
1058 print
'<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
1065 <script type="text/javascript">
1066 function launch_export() {
1067 $("div.fiche form input[name=\"action\"]").val("exportcsv");
1068 $("div.fiche form input[type=\"submit\"]").click();
1069 $("div.fiche form input[name=\"action\"]").val("");
1071 function writebookkeeping() {
1072 console.log("click on writebookkeeping");
1073 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
1074 $("div.fiche form input[type=\"submit\"]").click();
1075 $("div.fiche form input[name=\"action\"]").val("");
1084 print
'<div class="div-table-responsive">';
1085 print
"<table class=\"noborder\" width=\"100%\">";
1086 print
"<tr class=\"liste_titre\">";
1087 print
"<td>".$langs->trans(
"Date").
"</td>";
1088 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"InvoiceRef").
")</td>";
1089 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
1090 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
1091 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
1092 print
'<td class="center">'.$langs->trans(
"AccountingDebit").
"</td>";
1093 print
'<td class="center">'.$langs->trans(
"AccountingCredit").
"</td>";
1102 foreach ($tabfac as $key => $val) {
1103 $companystatic->id = $tabcompany[$key][
'id'];
1104 $companystatic->name = $tabcompany[$key][
'name'];
1105 $companystatic->accountancy_code_supplier_general = !empty($tabcompany[$key][
'accountancy_code_supplier_general']) ? $tabcompany[$key][
'accountancy_code_supplier_general'] : $cptfour;
1106 $companystatic->code_compta_fournisseur = $tabcompany[$key][
'code_compta_fournisseur'];
1107 $companystatic->code_fournisseur = $tabcompany[$key][
'code_fournisseur'];
1108 $companystatic->fournisseur = 1;
1110 $invoicestatic->id = $key;
1111 $invoicestatic->ref = $val[
"refsologest"];
1112 $invoicestatic->ref_supplier = $val[
"refsuppliersologest"];
1113 $invoicestatic->type = $val[
"type"];
1114 $invoicestatic->description =
dol_trunc(html_entity_decode($val[
"description"]), 32);
1115 $invoicestatic->close_code = $val[
"close_code"];
1120 $replacedinvoice = 0;
1121 if ($invoicestatic->close_code == FactureFournisseur::CLOSECODE_REPLACED) {
1122 $replacedinvoice = 1;
1123 $alreadydispatched = $invoicestatic->getVentilExportCompta();
1124 if ($alreadydispatched) {
1125 $replacedinvoice = 2;
1130 if ($replacedinvoice == 1) {
1131 print
'<tr class="oddeven">';
1132 print
"<!-- Replaced invoice -->";
1133 print
"<td>".$date.
"</td>";
1134 print
"<td><strike>".$invoicestatic->getNomUrl(1).
"</strike></td>";
1137 print $langs->trans(
"Replaced");
1144 print
'<td class="right"></td>';
1145 print
'<td class="right"></td>';
1151 if (isset($errorforinvoice[$key]) && $errorforinvoice[$key] ==
'somelinesarenotbound') {
1152 print
'<tr class="oddeven">';
1153 print
"<!-- Some lines are not bound -->";
1154 print
"<td>".$date.
"</td>";
1155 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1158 print
'<span class="error">'.$langs->trans(
'ErrorInvoiceContainsLinesNotYetBoundedShort', $val[
'ref']).
'</span>';
1165 print
'<td class="right"></td>';
1166 print
'<td class="right"></td>';
1173 foreach ($tabttc[$key] as $k => $mt) {
1174 print
'<tr class="oddeven">';
1175 print
"<!-- Thirdparty -->";
1176 print
"<td>".$date.
"</td>";
1177 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1180 $accountoshow =
length_accountg(!empty($tabcompany[$key][
'accountancy_code_supplier_general']) ? $tabcompany[$key][
'accountancy_code_supplier_general'] : $cptfour);
1181 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1182 print
'<span class="error">'.$langs->trans(
"MainAccountForSuppliersNotDefined").
'</span>';
1184 print $accountoshow;
1190 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1191 print
'<span class="error">'.$langs->trans(
"ThirdpartyAccountNotDefined").
'</span>';
1193 print $accountoshow;
1196 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'supplier'), $invoicestatic->ref_supplier, $langs->trans(
"SubledgerAccount"), 1) .
"</td>";
1197 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1198 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1205 foreach ($tabht[$key] as $k => $mt) {
1206 if (empty($conf->cache[
'accountingaccountincurrententity'][$k])) {
1208 $accountingaccount->fetch(0, $k,
true);
1209 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
1211 $accountingaccount = $conf->cache[
'accountingaccountincurrententity'][$k];
1214 print
'<tr class="oddeven">';
1215 print
"<!-- Product -->";
1216 print
"<td>".$date.
"</td>";
1217 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1221 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1222 print
'<span class="error">'.$langs->trans(
"ProductAccountNotDefined").
'</span>';
1224 print $accountoshow;
1233 } elseif (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1234 print
'<span class="error">' . $langs->trans(
"ThirdpartyAccountNotDefined") .
'</span>';
1237 $companystatic->id = $tabcompany[$key][
'id'];
1238 $companystatic->name = $tabcompany[$key][
'name'];
1239 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'supplier'), $invoicestatic->ref_supplier, $accountingaccount->label, 1) .
"</td>";
1240 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1241 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1248 $listoftax = array(0, 1, 2);
1249 foreach ($listoftax as $numtax) {
1250 $arrayofvat = $tabtva;
1252 $arrayofvat = $tablocaltax1;
1255 $arrayofvat = $tablocaltax2;
1261 foreach ($arrayofvat[$key] as $k => $mt) {
1268 $arrayofvat = $tabrctva;
1270 $arrayofvat = $tabrclocaltax1;
1273 $arrayofvat = $tabrclocaltax2;
1275 if (!isset($arrayofvat[$key]) || !is_array($arrayofvat[$key])) {
1276 $arrayofvat[$key] = array();
1281 foreach ($arrayofvat[$key] as $k => $mt) {
1283 print
'<tr class="oddeven">';
1284 print
"<!-- VAT -->";
1285 print
"<td>".$date.
"</td>";
1286 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1290 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1291 print
'<span class="error">'.$langs->trans(
"VATAccountNotDefined").
' ('.$langs->trans(
"AccountingJournalType3").
')</span>';
1293 print $accountoshow;
1299 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
1300 $labelvatrate = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
1301 $labelvatrate .= ($numtax ?
' - Localtax '.$numtax :
'');
1302 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'supplier'), $invoicestatic->ref_supplier, $labelvatrate, 1) .
"</td>";
1303 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1304 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1313 if (isset($tabother[$key]) && is_array($tabother[$key])) {
1314 foreach ($tabother[$key] as $k => $mt) {
1316 print
'<tr class="oddeven">';
1317 print
'<!-- VAT counterpart NPR -->';
1318 print
"<td>".$date.
"</td>";
1319 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1323 if ($accountoshow ==
'' || $accountoshow ==
'NotDefined') {
1324 print
'<span class="error">'.$langs->trans(
"VATAccountNotDefined").
' ('.$langs->trans(
"NPR counterpart").
'). Set ACCOUNTING_COUNTERPART_VAT_NPR to the subvention account</span>';
1326 print $accountoshow;
1332 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'supplier'), $invoicestatic->ref_supplier, $langs->trans(
"VAT").
" NPR (counterpart)", 1) .
"</td>";
1333 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1334 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1344 print
'<tr class="oddeven"><td colspan="7"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
journalHead($nom, $variant, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='', $moreoptions=array())
Show header of a page used to transfer/dispatch data in accounting.
getDefaultDatesForTransfer()
Return Default dates for transfer based on periodicity option in accountancy setup.
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage accounting accounts.
Class to manage accounting journals.
Class to manage Ledger (General Ledger and Subledger)
const TYPE_SITUATION
Situation invoice.
Class to manage suppliers invoices.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
const TYPE_REPLACEMENT
Replacement invoice.
Class to manage suppliers.
Class to manage third parties objects (customers, suppliers, prospects...)
getCountriesInEEC()
Return list of countries that are inside the EEC (European Economic Community) Note: Try to keep this...
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_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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 '.
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.
getDolGlobalInt($key, $default=0)
Return a 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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.