35require
'../../main.inc.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
48require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
55$langs->loadLangs(array(
"commercial",
"compta",
"bills",
"other",
"accountancy"));
58$action =
GETPOST(
'action',
'aZ09');
60$date_startmonth =
GETPOSTINT(
'date_startmonth');
66$in_bookkeeping =
GETPOST(
'in_bookkeeping');
67if ($in_bookkeeping ==
'' || $action ==
'writebookkeeping') {
68 $in_bookkeeping =
'notyet';
73$hookmanager->initHooks(array(
'purchasesjournal'));
80if ($user->socid > 0) {
83if (!$user->hasRight(
'accounting',
'bind',
'write')) {
93$tablocaltax1 = array();
94$tablocaltax2 = array();
96$tabrclocaltax1 = array();
97$tabrclocaltax2 = array();
100$cptcli =
'NotDefined';
101$cptfour =
'NotDefined';
107$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $user, $action);
113$accountingjournalstatic->fetch($id_journal);
114$journal = $accountingjournalstatic->code;
115$journal_label = $accountingjournalstatic->label;
118$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
121$pastmonthyear =
null;
123if (empty($date_startmonth)) {
127 $pastmonthyear = $dates[
'pastmonthyear'];
128 $pastmonth = $dates[
'pastmonth'];
130if (empty($date_endmonth)) {
133 $date_end = $dates[
'date_end'];
134 $pastmonthyear = $dates[
'pastmonthyear'];
135 $pastmonth = $dates[
'pastmonth'];
138if (!
GETPOSTISSET(
'date_startmonth') && (empty($date_start) || empty($date_end))) {
140 $date_end =
dol_get_last_day((
int) $pastmonthyear, (
int) $pastmonth,
false);
143$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,";
144$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,";
145$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,";
146$sql .=
" co.code as country_code, co.label as country_label,";
147$sql .=
" s.rowid as socid, s.nom as name, s.fournisseur, s.code_client, s.code_fournisseur, s.fk_pays,";
149 $sql .=
" spe.accountancy_code_customer_general,";
150 $sql .=
" spe.accountancy_code_customer as code_compta,";
151 $sql .=
" spe.accountancy_code_supplier_general,";
152 $sql .=
" spe.accountancy_code_supplier as code_compta_fournisseur,";
154 $sql .=
" s.accountancy_code_customer_general,";
155 $sql .=
" s.code_compta as code_compta,";
156 $sql .=
" s.accountancy_code_supplier_general,";
157 $sql .=
" s.code_compta_fournisseur,";
160 $sql .=
" ppe.accountancy_code_buy,";
162 $sql .=
" p.accountancy_code_buy,";
164$sql .=
" aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte";
165$parameters = array();
166$reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
167$sql .= $hookmanager->resPrint;
168$sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn_det as fd";
169$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = fd.fk_product";
171 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int)
$conf->entity);
173$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
174$sql .=
" JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f ON f.rowid = fd.fk_facture_fourn";
175$sql .=
" JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
176$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co ON co.rowid = s.fk_pays ";
178 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int)
$conf->entity);
180$parameters = array();
181$reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters);
182$sql .= $hookmanager->resPrint;
183$sql .=
" WHERE f.fk_statut > 0";
184$sql .=
" AND fd.fk_code_ventilation > 0";
185$sql .=
" AND f.entity IN (".getEntity(
'facture_fourn', 0).
")";
191if ($date_start && $date_end) {
192 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
196 $sql .=
" AND f.datef >= '".$db->idate(
getDolGlobalInt(
'ACCOUNTING_DATE_START_BINDING')).
"'";
199if ($in_bookkeeping ==
'already') {
200 $sql .=
" AND f.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='supplier_invoice')";
202if ($in_bookkeeping ==
'notyet') {
203 $sql .=
" AND f.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='supplier_invoice')";
205$parameters = array();
206$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
207$sql .= $hookmanager->resPrint;
208$sql .=
" ORDER BY f.datef";
210dol_syslog(
'accountancy/journal/purchasesjournal.php', LOG_DEBUG);
216$tablocaltax1 = array();
217$tablocaltax2 = array();
218$tabcompany = array();
221$tabrclocaltax1 = array();
222$tabrclocaltax2 = array();
223$vatdata_cache = array();
233$assetaccountprefixlist = array();
235if ($cpttvaasset !==
'') {
236 $assetaccountprefixlist = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_ASSET_ACCOUNT_PREFIXES',
'2'))));
239$rcctva =
getDolGlobalString(
'ACCOUNTING_VAT_BUY_REVERSE_CHARGES_CREDIT',
'NotDefined');
240$rcdtva =
getDolGlobalString(
'ACCOUNTING_VAT_BUY_REVERSE_CHARGES_DEBIT',
'NotDefined');
242$rcclocaltax1 =
getDolGlobalString(
'ACCOUNTING_LT1_BUY_REVERSE_CHARGES_CREDIT',
'NotDefined');
243$rcdlocaltax1 =
getDolGlobalString(
'ACCOUNTING_LT1_BUY_REVERSE_CHARGES_DEBIT',
'NotDefined');
245$rcclocaltax2 =
getDolGlobalString(
'ACCOUNTING_LT2_BUY_REVERSE_CHARGES_CREDIT',
'NotDefined');
246$rcdlocaltax2 =
getDolGlobalString(
'ACCOUNTING_LT2_BUY_REVERSE_CHARGES_DEBIT',
'NotDefined');
247$noTaxDispatchingKeepWithLines =
getDolGlobalInt(
'ACCOUNTING_PURCHASES_DO_NOT_DISPATCH_TAXES');
250$result = $db->query($sql);
252 $num = $db->num_rows($result);
256 $obj = $db->fetch_object($result);
259 $accountancy_code_supplier_general = (!empty($obj->accountancy_code_supplier_general)) ? $obj->accountancy_code_supplier_general : $cptfour;
262 $compta_prod = $obj->compte;
263 if (empty($compta_prod)) {
264 if ($obj->product_type == 0) {
271 $tax_id = $obj->tva_tx . ($obj->vat_src_code ?
' (' . $obj->vat_src_code .
')' :
'');
272 if (array_key_exists($tax_id, $vatdata_cache)) {
273 $vatdata = $vatdata_cache[$tax_id];
276 $vatdata_cache[$tax_id] = $vatdata;
278 $compta_tva = (!empty($vatdata[
'accountancy_code_buy']) ? $vatdata[
'accountancy_code_buy'] : $cpttva);
280 foreach ($assetaccountprefixlist as $assetaccountprefix) {
281 if (strpos((
string) $compta_prod, $assetaccountprefix) === 0) {
282 $compta_tva = $cpttvaasset;
286 $compta_localtax1 = (!empty($vatdata[
'accountancy_code_buy']) ? $vatdata[
'accountancy_code_buy'] : $cptlocaltax1);
287 $compta_localtax2 = (!empty($vatdata[
'accountancy_code_buy']) ? $vatdata[
'accountancy_code_buy'] : $cptlocaltax2);
288 $compta_counterpart_tva_npr =
getDolGlobalString(
'ACCOUNTING_COUNTERPART_VAT_NPR',
'NotDefined');
291 if (
price2num($obj->tva_tx) || !empty($obj->vat_src_code)) {
292 $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.
')' :
''));
293 if ($obj->localtax1_tx > 0.0) {
294 $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.
')' :
''));
296 if ($obj->localtax2_tx > 0.0) {
297 $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.
')' :
''));
305 if (!array_key_exists($obj->rowid, $tabfac)) {
306 $tabfac[$obj->rowid] = array();
307 $tabttc[$obj->rowid] = array();
308 $tabht[$obj->rowid] = array();
309 $tabtva[$obj->rowid] = array();
310 $tablocaltax1[$obj->rowid] = array();
311 $tablocaltax2[$obj->rowid] = array();
313 if (!isset($tabttc[$obj->rowid][$compta_soc])) {
314 $tabttc[$obj->rowid][$compta_soc] = 0;
316 if (!isset($tabht[$obj->rowid][$compta_prod])) {
317 $tabht[$obj->rowid][$compta_prod] = 0;
319 if (!isset($tabtva[$obj->rowid][$compta_tva])) {
320 $tabtva[$obj->rowid][$compta_tva] = 0;
322 if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
323 $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
325 if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
326 $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
329 $tabfac[$obj->rowid][
"date"] = $db->jdate($obj->df);
330 $tabfac[$obj->rowid][
"datereg"] = $db->jdate($obj->dlr);
331 $tabfac[$obj->rowid][
"ref"] = $obj->ref_supplier.
' ('.$obj->ref.
')';
332 $tabfac[$obj->rowid][
"refsologest"] = $obj->ref;
333 $tabfac[$obj->rowid][
"refsuppliersologest"] = $obj->ref_supplier;
334 $tabfac[$obj->rowid][
"type"] = $obj->type;
335 $tabfac[$obj->rowid][
"description"] = $obj->description;
336 $tabfac[$obj->rowid][
"close_code"] = $obj->close_code;
340 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'))) {
341 $rcvatdata =
getTaxesFromId($obj->product_buy_vat . ($obj->product_buy_default_vat_code ?
' (' . $obj->product_buy_default_vat_code .
')' :
''),
$mysoc,
$mysoc, 0);
342 $rcc_compta_tva = (!empty($vatdata[
'accountancy_code_vat_reverse_charge_credit']) ? $vatdata[
'accountancy_code_vat_reverse_charge_credit'] : $rcctva);
343 $rcd_compta_tva = (!empty($vatdata[
'accountancy_code_vat_reverse_charge_debit']) ? $vatdata[
'accountancy_code_vat_reverse_charge_debit'] : $rcdtva);
344 $rcc_compta_localtax1 = (!empty($vatdata[
'accountancy_code_vat_reverse_charge_credit']) ? $vatdata[
'accountancy_code_vat_reverse_charge_credit'] : $rcclocaltax1);
345 $rcd_compta_localtax1 = (!empty($vatdata[
'accountancy_code_vat_reverse_charge_debit']) ? $vatdata[
'accountancy_code_vat_reverse_charge_debit'] : $rcdlocaltax1);
346 $rcc_compta_localtax2 = (!empty($vatdata[
'accountancy_code_vat_reverse_charge_credit']) ? $vatdata[
'accountancy_code_vat_reverse_charge_credit'] : $rcclocaltax2);
347 $rcd_compta_localtax2 = (!empty($vatdata[
'accountancy_code_vat_reverse_charge_debit']) ? $vatdata[
'accountancy_code_vat_reverse_charge_debit'] : $rcdlocaltax2);
348 if (
price2num($obj->product_buy_vat) || !empty($obj->product_buy_default_vat_code)) {
349 $vat_key =
vatrate($obj->product_buy_vat) . ($obj->product_buy_default_vat_code ?
' (' . $obj->product_buy_default_vat_code .
')' :
'');
350 $val_value = $vat_key;
351 $def_tva[$obj->rowid][$rcc_compta_tva][$vat_key] = $val_value;
352 $def_tva[$obj->rowid][$rcd_compta_tva][$vat_key] = $val_value;
355 if (!array_key_exists($obj->rowid, $tabrctva)) {
356 $tabrctva[$obj->rowid] = array();
357 $tabrclocaltax1[$obj->rowid] = array();
358 $tabrclocaltax2[$obj->rowid] = array();
360 if (!isset($tabrctva[$obj->rowid][$rcc_compta_tva])) {
361 $tabrctva[$obj->rowid][$rcc_compta_tva] = 0;
363 if (!isset($tabrctva[$obj->rowid][$rcd_compta_tva])) {
364 $tabrctva[$obj->rowid][$rcd_compta_tva] = 0;
366 if (!isset($tabrclocaltax1[$obj->rowid][$rcc_compta_localtax1])) {
367 $tabrclocaltax1[$obj->rowid][$rcc_compta_localtax1] = 0;
369 if (!isset($tabrclocaltax1[$obj->rowid][$rcd_compta_localtax1])) {
370 $tabrclocaltax1[$obj->rowid][$rcd_compta_localtax1] = 0;
372 if (!isset($tabrclocaltax2[$obj->rowid][$rcc_compta_localtax2])) {
373 $tabrclocaltax2[$obj->rowid][$rcc_compta_localtax2] = 0;
375 if (!isset($tabrclocaltax2[$obj->rowid][$rcd_compta_localtax2])) {
376 $tabrclocaltax2[$obj->rowid][$rcd_compta_localtax2] = 0;
379 $rcvat = (float)
price2num($obj->total_ttc * $obj->product_buy_vat / 100,
'MT');
380 $rclocalvat1 = (float)
price2num($obj->total_ttc * $obj->product_buy_localvat1 / 100,
'MT');
381 $rclocalvat2 = (float)
price2num($obj->total_ttc * $obj->product_buy_localvat2 / 100,
'MT');
383 $tabrctva[$obj->rowid][$rcd_compta_tva] += $rcvat;
384 $tabrctva[$obj->rowid][$rcc_compta_tva] -= $rcvat;
385 $tabrclocaltax1[$obj->rowid][$rcd_compta_localtax1] += $rclocalvat1;
386 $tabrclocaltax1[$obj->rowid][$rcc_compta_localtax1] -= $rclocalvat1;
387 $tabrclocaltax2[$obj->rowid][$rcd_compta_localtax2] += $rclocalvat2;
388 $tabrclocaltax2[$obj->rowid][$rcc_compta_localtax2] -= $rclocalvat2;
391 $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc;
393 if ($noTaxDispatchingKeepWithLines) {
394 $tabht[$obj->rowid][$compta_prod] += $obj->total_ttc;
396 $tabht[$obj->rowid][$compta_prod] += $obj->total_ht;
397 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
398 $tva_npr = ((($obj->info_bits & 1) == 1) ? 1 : 0);
400 if (!array_key_exists($obj->rowid, $tabother)) {
401 $tabother[$obj->rowid] = array();
403 if (!array_key_exists($compta_counterpart_tva_npr, $tabother[$obj->rowid])) {
404 $tabother[$obj->rowid][$compta_counterpart_tva_npr] = 0;
406 $tabother[$obj->rowid][$compta_counterpart_tva_npr] += (float) $obj->total_tva;
408 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
409 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
411 $tabcompany[$obj->rowid] = array(
413 'name' => $obj->name,
414 'code_fournisseur' => $obj->code_fournisseur,
415 'accountancy_code_supplier_general' => $accountancy_code_supplier_general,
416 'code_compta_fournisseur' => $compta_soc
422 if ($i >
getDolGlobalInt(
'ACCOUNTANCY_MAX_TOO_MANY_LINES_TO_PROCESS', 10000)) {
424 setEventMessages(
"ErrorTooManyLinesToProcessPleaseUseAMoreSelectiveFilter",
null,
'errors');
429 dol_print_error($db);
432$errorforinvoice = array();
455if (!empty($tabfac)) {
459 COUNT(fd.rowid) as nb
461 " . MAIN_DB_PREFIX .
"facture_fourn_det as fd
464 AND fd.fk_code_ventilation <= 0
465 AND fd.total_ttc <> 0
466 AND fk_facture_fourn IN (".$db->sanitize(implode(
",", array_keys($tabfac))).
")
467 GROUP BY fk_facture_fourn
469 $resql = $db->query($sql);
471 $num = $db->num_rows($resql);
474 $obj = $db->fetch_object($resql);
476 $errorforinvoice[$obj->fk_facture_fourn] =
'somelinesarenotbound';
483if ($action ==
'writebookkeeping' && !$error && $user->hasRight(
'accounting',
'bind',
'write')) {
487 $companystatic =
new Societe($db);
492 $accountingaccountsupplier->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUPPLIER'),
true);
494 foreach ($tabfac as $key => $val) {
502 $companystatic->id = $tabcompany[$key][
'id'];
503 $companystatic->name = $tabcompany[$key][
'name'];
504 $companystatic->accountancy_code_supplier_general = $tabcompany[$key][
'accountancy_code_supplier_general'];
505 $companystatic->code_compta_fournisseur = $tabcompany[$key][
'code_compta_fournisseur'];
506 $companystatic->code_fournisseur = $tabcompany[$key][
'code_fournisseur'];
507 $companystatic->fournisseur = 1;
509 $invoicestatic->id = (int) $key;
510 $invoicestatic->ref = (string) $val[
"refsologest"];
511 $invoicestatic->ref_supplier = (string) $val[
"refsuppliersologest"];
512 $invoicestatic->type = $val[
"type"];
513 $invoicestatic->description = html_entity_decode(
dol_trunc((
string) $val[
"description"], 32));
514 $invoicestatic->close_code = (string) $val[
"close_code"];
519 $replacedinvoice = 0;
520 if ($invoicestatic->close_code == FactureFournisseur::CLOSECODE_REPLACED) {
521 $replacedinvoice = 1;
522 $alreadydispatched = $invoicestatic->getVentilExportCompta();
523 if ($alreadydispatched) {
524 $replacedinvoice = 2;
529 if ($replacedinvoice == 1) {
535 if (isset($errorforinvoice[$key]) && $errorforinvoice[$key] ==
'somelinesarenotbound') {
538 setEventMessages($langs->trans(
'ErrorInvoiceContainsLinesNotYetBounded', $val[
'ref']),
null,
'errors');
542 if (!$errorforline) {
543 foreach ($tabttc[$key] as $k => $mt) {
545 $bookkeeping->doc_date = $val[
"date"];
546 $bookkeeping->date_lim_reglement = $val[
"datereg"];
547 $bookkeeping->doc_ref = $val[
"refsologest"];
548 $bookkeeping->date_creation = $now;
549 $bookkeeping->doc_type =
'supplier_invoice';
550 $bookkeeping->fk_doc = (int) $key;
551 $bookkeeping->fk_docdet = 0;
552 $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
554 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta_fournisseur'];
555 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
557 $bookkeeping->numero_compte = $tabcompany[$key][
'accountancy_code_supplier_general'];
558 $bookkeeping->label_compte = $accountingaccountsupplier->label;
560 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref_supplier, $langs->trans(
"SubledgerAccount"));
561 $bookkeeping->montant = $mt;
562 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
563 $bookkeeping->debit = ($mt <= 0) ? -$mt : 0;
564 $bookkeeping->credit = ($mt > 0) ? $mt : 0;
565 $bookkeeping->code_journal = $journal;
566 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
567 $bookkeeping->fk_user_author = $user->id;
568 $bookkeeping->entity =
$conf->entity;
570 $totaldebit += $bookkeeping->debit;
571 $totalcredit += $bookkeeping->credit;
573 $result = $bookkeeping->create($user);
575 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
578 $errorforinvoice[$key] =
'alreadyjournalized';
583 $errorforinvoice[$key] =
'other';
584 setEventMessages($bookkeeping->error, $bookkeeping->errors,
'errors');
588 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/lettering.class.php';
591 $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id));
598 if (!$errorforline) {
599 foreach ($tabht[$key] as $k => $mt) {
600 if (empty(
$conf->cache[
'accountingaccountincurrententity'][$k])) {
602 $accountingaccount->fetch(0, $k,
true);
603 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
605 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity'][$k];
608 $label_account = $accountingaccount->label;
611 if ($accountingaccount->id > 0) {
613 $bookkeeping->doc_date = $val[
"date"];
614 $bookkeeping->date_lim_reglement = $val[
"datereg"];
615 $bookkeeping->doc_ref = $val[
"refsologest"];
616 $bookkeeping->date_creation = $now;
617 $bookkeeping->doc_type =
'supplier_invoice';
618 $bookkeeping->fk_doc = (int) $key;
619 $bookkeeping->fk_docdet = 0;
620 $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
624 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta_fournisseur'];
625 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
627 $bookkeeping->subledger_account =
'';
628 $bookkeeping->subledger_label =
'';
631 $bookkeeping->subledger_account =
'';
632 $bookkeeping->subledger_label =
'';
635 $bookkeeping->numero_compte = $k;
636 $bookkeeping->label_compte = $label_account;
638 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref_supplier, $label_account);
639 $bookkeeping->montant = $mt;
640 $bookkeeping->sens = ($mt < 0) ?
'C' :
'D';
641 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
642 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
643 $bookkeeping->code_journal = $journal;
644 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
645 $bookkeeping->fk_user_author = $user->id;
646 $bookkeeping->entity =
$conf->entity;
648 $totaldebit += $bookkeeping->debit;
649 $totalcredit += $bookkeeping->credit;
651 $result = $bookkeeping->create($user);
653 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
656 $errorforinvoice[$key] =
'alreadyjournalized';
661 $errorforinvoice[$key] =
'other';
662 setEventMessages($bookkeeping->error, $bookkeeping->errors,
'errors');
671 if (!$errorforline) {
672 $listoftax = array(0, 1, 2);
673 foreach ($listoftax as $numtax) {
674 $arrayofvat = $tabtva;
676 $arrayofvat = $tablocaltax1;
679 $arrayofvat = $tablocaltax2;
685 foreach ($arrayofvat[$key] as $k => $mt) {
692 $arrayofvat = $tabrctva;
694 $arrayofvat = $tabrclocaltax1;
697 $arrayofvat = $tabrclocaltax2;
699 if (!isset($arrayofvat[$key]) || !is_array($arrayofvat[$key])) {
700 $arrayofvat[$key] = array();
705 foreach ($arrayofvat[$key] as $k => $mt) {
707 if (empty(
$conf->cache[
'accountingaccountincurrententity_vat'][$k])) {
709 $accountingaccount->fetch(0, $k,
true);
710 $conf->cache[
'accountingaccountincurrententity_vat'][$k] = $accountingaccount;
712 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity_vat'][$k];
715 $label_account = $accountingaccount->label;
718 $bookkeeping->doc_date = $val[
"date"];
719 $bookkeeping->date_lim_reglement = $val[
"datereg"];
720 $bookkeeping->doc_ref = $val[
"refsologest"];
721 $bookkeeping->date_creation = $now;
722 $bookkeeping->doc_type =
'supplier_invoice';
723 $bookkeeping->fk_doc = (int) $key;
724 $bookkeeping->fk_docdet = 0;
725 $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
727 $bookkeeping->subledger_account =
'';
728 $bookkeeping->subledger_label =
'';
730 $bookkeeping->numero_compte = $k;
731 $bookkeeping->label_compte = $label_account;
733 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
734 $labelvataccount = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
735 $labelvataccount .= ($numtax ?
' - Localtax '.$numtax :
'');
736 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref_supplier, $labelvataccount);
738 $bookkeeping->montant = $mt;
739 $bookkeeping->sens = ($mt < 0) ?
'C' :
'D';
740 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
741 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
742 $bookkeeping->code_journal = $journal;
743 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
744 $bookkeeping->fk_user_author = $user->id;
745 $bookkeeping->entity =
$conf->entity;
747 $totaldebit += $bookkeeping->debit;
748 $totalcredit += $bookkeeping->credit;
750 $result = $bookkeeping->create($user);
752 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
755 $errorforinvoice[$key] =
'alreadyjournalized';
760 $errorforinvoice[$key] =
'other';
761 setEventMessages($bookkeeping->error, $bookkeeping->errors,
'errors');
771 if (!$errorforline && isset($tabother[$key]) && is_array($tabother[$key])) {
772 foreach ($tabother[$key] as $k => $mt) {
775 $bookkeeping->doc_date = $val[
"date"];
776 $bookkeeping->date_lim_reglement = $val[
"datereg"];
777 $bookkeeping->doc_ref = $val[
"refsologest"];
778 $bookkeeping->date_creation = $now;
779 $bookkeeping->doc_type =
'supplier_invoice';
780 $bookkeeping->fk_doc = (int) $key;
781 $bookkeeping->fk_docdet = 0;
782 $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
784 $bookkeeping->subledger_account =
'';
785 $bookkeeping->subledger_label =
'';
787 $bookkeeping->numero_compte = $k;
789 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref_supplier, $langs->trans(
"VAT").
' NPR');
790 $bookkeeping->montant = $mt;
791 $bookkeeping->sens = ($mt < 0) ?
'C' :
'D';
792 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
793 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
794 $bookkeeping->code_journal = $journal;
795 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
796 $bookkeeping->fk_user_author = $user->id;
797 $bookkeeping->entity =
$conf->entity;
799 $totaldebit += $bookkeeping->debit;
800 $totalcredit += $bookkeeping->credit;
802 $result = $bookkeeping->create($user);
804 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
807 $errorforinvoice[$key] =
'alreadyjournalized';
812 $errorforinvoice[$key] =
'other';
813 setEventMessages($bookkeeping->error, $bookkeeping->errors,
'errors');
821 if (!$errorforline && (
price2num($totaldebit,
'MT') !=
price2num($totalcredit,
'MT'))) {
824 $errorforinvoice[$key] =
'amountsnotbalanced';
825 setEventMessages(
'We tried to insert a non balanced transaction in book for '.$invoicestatic->ref.
'. Canceled. Surely a bug.',
null,
'errors');
828 if (!$errorforline) {
834 $langs->load(
'errors');
835 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped"),
null,
'errors');
843 if (empty($error) && count($tabpay) > 0) {
844 setEventMessages($langs->trans(
"GeneralLedgerIsWritten"),
null,
'mesgs');
845 } elseif (count($tabpay) == $error) {
846 setEventMessages($langs->trans(
"NoNewRecordSaved"),
null,
'warnings');
848 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
854 if (count($tabpay) != $error) {
855 $param =
'id_journal='.$id_journal;
856 $param .=
'&date_startday='.$date_startday;
857 $param .=
'&date_startmonth='.$date_startmonth;
858 $param .=
'&date_startyear='.$date_startyear;
859 $param .=
'&date_endday='.$date_endday;
860 $param .=
'&date_endmonth='.$date_endmonth;
861 $param .=
'&date_endyear='.$date_endyear;
862 $param .=
'&in_bookkeeping='.$in_bookkeeping;
863 header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
872$form =
new Form($db);
875if ($action ==
'exportcsv' && !$error) {
878 $filename =
'journal';
879 $type_export =
'journal';
880 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
886 foreach ($tabfac as $key => $val) {
887 $companystatic->id = $tabcompany[$key][
'id'];
888 $companystatic->name = $tabcompany[$key][
'name'];
889 $companystatic->accountancy_code_supplier_general = !empty($tabcompany[$key][
'accountancy_code_supplier_general']) ? $tabcompany[$key][
'accountancy_code_supplier_general'] : $cptfour;
890 $companystatic->code_compta_fournisseur = $tabcompany[$key][
'code_compta_fournisseur'];
891 $companystatic->code_fournisseur = $tabcompany[$key][
'code_fournisseur'];
892 $companystatic->fournisseur = 1;
894 $invoicestatic->id = (int) $key;
895 $invoicestatic->ref = (string) $val[
"refsologest"];
896 $invoicestatic->ref_supplier = (string) $val[
"refsuppliersologest"];
897 $invoicestatic->type = $val[
"type"];
898 $invoicestatic->description =
dol_trunc(html_entity_decode((
string) $val[
"description"]), 32);
899 $invoicestatic->close_code = (string) $val[
"close_code"];
904 $replacedinvoice = 0;
905 if ($invoicestatic->close_code == FactureFournisseur::CLOSECODE_REPLACED) {
906 $replacedinvoice = 1;
907 $alreadydispatched = $invoicestatic->getVentilExportCompta();
908 if ($alreadydispatched) {
909 $replacedinvoice = 2;
914 if ($replacedinvoice == 1) {
919 foreach ($tabttc[$key] as $k => $mt) {
921 print
'"'.$key.
'"'.$sep;
922 print
'"'.$date.
'"'.$sep;
923 print
'"'.((string) $val[
"refsologest"]).
'"'.$sep;
924 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
925 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
926 print
'"'.length_accountg($companystatic->accountancy_code_supplier_general).
'"'.$sep;
927 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
928 print
'"'.$langs->trans(
"ThirdParty").
'"'.$sep;
929 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $val[
"refsuppliersologest"], $langs->trans(
"ThirdParty"))).
'"'.$sep;
930 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
931 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
932 print
'"'.$journal.
'"';
938 foreach ($tabht[$key] as $k => $mt) {
940 $accountingaccount->fetch(0, $k,
true);
942 print
'"'.$key.
'"'.$sep;
943 print
'"'.$date.
'"'.$sep;
944 print
'"'.((string) $val[
"refsologest"]).
'"'.$sep;
945 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
946 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
947 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
949 print
'"'.csvClean(
dol_trunc($accountingaccount->label, 32)).
'"'.$sep;
950 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $val[
"refsuppliersologest"], $accountingaccount->label)).
'"'.$sep;
951 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
952 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
953 print
'"'.$journal.
'"';
959 $listoftax = array(0, 1, 2);
960 foreach ($listoftax as $numtax) {
961 $arrayofvat = $tabtva;
963 $arrayofvat = $tablocaltax1;
966 $arrayofvat = $tablocaltax2;
972 foreach ($arrayofvat[$key] as $k => $mt) {
979 $arrayofvat = $tabrctva;
981 $arrayofvat = $tabrclocaltax1;
984 $arrayofvat = $tabrclocaltax2;
986 if (!isset($arrayofvat[$key]) || !is_array($arrayofvat[$key])) {
987 $arrayofvat[$key] = array();
992 foreach ($arrayofvat[$key] as $k => $mt) {
994 print
'"'.$key.
'"'.$sep;
995 print
'"'.$date.
'"'.$sep;
996 print
'"'.((string) $val[
"refsologest"]).
'"'.$sep;
997 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
998 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
999 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1001 print
'"'.$langs->trans(
"VAT").
' - '.implode(
', ', $def_tva[$key][$k]).
' %"'.$sep;
1002 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $val[
"refsuppliersologest"], $langs->trans(
"VAT").implode($def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
''))).
'"'.$sep;
1003 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1004 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1005 print
'"'.$journal.
'"';
1011 if (isset($tabother[$key]) && is_array($tabother[$key])) {
1012 foreach ($tabother[$key] as $k => $mt) {
1014 print
'"'.$key.
'"'.$sep;
1015 print
'"'.$date.
'"'.$sep;
1016 print
'"'.((string) $val[
"refsologest"]).
'"'.$sep;
1017 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
1018 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1019 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1020 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1021 print
'"'.$langs->trans(
"ThirdParty").
'"'.$sep;
1022 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $val[
"refsuppliersologest"], $langs->trans(
"VAT").
' NPR')).
'"'.$sep;
1023 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1024 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1025 print
'"'.$journal.
'"';
1034if (empty($action) || $action ==
'view') {
1035 $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1,
'', 1);
1036 $help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
1037 llxHeader(
'',
dol_string_nohtmltag($title), $help_url,
'', 0, 0,
'',
'',
'',
'mod-accountancy accountancy-generation page-purchasesjournal');
1044 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
1046 $description .= $langs->trans(
"DepositsAreNotIncluded");
1048 $description .= $langs->trans(
"DepositsAreIncluded");
1051 $listofchoices = array(
'notyet' => $langs->trans(
"NotYetInGeneralLedger"),
'already' => $langs->trans(
"AlreadyInGeneralLedger"));
1052 $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);
1053 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
1055 $varlink =
'id_journal='.$id_journal;
1057 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
1062 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_fiscalyear WHERE entity = ".((int)
$conf->entity);
1063 $resql = $db->query($sql);
1065 $obj = $db->fetch_object($resql);
1066 if ($obj->nb == 0) {
1067 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheFiscalPeriodIsNotDefined");
1068 $desc =
' : '.$langs->trans(
"AccountancyAreaDescFiscalPeriod", 4,
'{link}');
1069 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"FiscalPeriod").
'</strong>', $desc);
1074 dol_print_error($db);
1079 $acctSupplierNotConfigured = in_array(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUPPLIER'), [
'',
'-1']);
1080 if ($acctSupplierNotConfigured) {
1081 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
1082 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
1083 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
1087 print
'<br><div class="tabsAction tabsActionNoBottom centerimp">';
1088 if (
getDolGlobalString(
'ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping ==
'notyet') {
1089 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
1091 if ($acctSupplierNotConfigured) {
1092 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
1094 if ($in_bookkeeping ==
'notyet') {
1095 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
1097 print
'<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
1104 <script type="text/javascript">
1105 function launch_export() {
1106 $("div.fiche form input[name=\"action\"]").val("exportcsv");
1107 $("div.fiche form input[type=\"submit\"]").click();
1108 $("div.fiche form input[name=\"action\"]").val("");
1110 function writebookkeeping() {
1111 console.log("click on writebookkeeping");
1112 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
1113 $("div.fiche form input[type=\"submit\"]").click();
1114 $("div.fiche form input[name=\"action\"]").val("");
1123 print
'<div class="div-table-responsive">';
1124 print
"<table class=\"noborder\" width=\"100%\">";
1125 print
"<tr class=\"liste_titre\">";
1126 print
"<td>".$langs->trans(
"Date").
"</td>";
1127 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"InvoiceRef").
")</td>";
1128 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
1129 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
1130 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
1131 print
'<td class="center">'.$langs->trans(
"AccountingDebit").
"</td>";
1132 print
'<td class="center">'.$langs->trans(
"AccountingCredit").
"</td>";
1141 foreach ($tabfac as $key => $val) {
1142 $companystatic->id = $tabcompany[$key][
'id'];
1143 $companystatic->name = $tabcompany[$key][
'name'];
1144 $companystatic->accountancy_code_supplier_general = !empty($tabcompany[$key][
'accountancy_code_supplier_general']) ? $tabcompany[$key][
'accountancy_code_supplier_general'] : $cptfour;
1145 $companystatic->code_compta_fournisseur = $tabcompany[$key][
'code_compta_fournisseur'];
1146 $companystatic->code_fournisseur = $tabcompany[$key][
'code_fournisseur'];
1147 $companystatic->fournisseur = 1;
1149 $invoicestatic->id = (int) $key;
1150 $invoicestatic->ref = (string) $val[
"refsologest"];
1151 $invoicestatic->ref_supplier = (string) $val[
"refsuppliersologest"];
1152 $invoicestatic->type = $val[
"type"];
1153 $invoicestatic->description =
dol_trunc(html_entity_decode((
string) $val[
"description"]), 32);
1154 $invoicestatic->close_code = (string) $val[
"close_code"];
1159 $replacedinvoice = 0;
1160 if ($invoicestatic->close_code == FactureFournisseur::CLOSECODE_REPLACED) {
1161 $replacedinvoice = 1;
1162 $alreadydispatched = $invoicestatic->getVentilExportCompta();
1163 if ($alreadydispatched) {
1164 $replacedinvoice = 2;
1169 if ($replacedinvoice == 1) {
1170 print
'<tr class="oddeven">';
1171 print
"<!-- Replaced invoice -->";
1172 print
"<td>".$date.
"</td>";
1173 print
"<td><strike>".$invoicestatic->getNomUrl(1).
"</strike></td>";
1176 print $langs->trans(
"Replaced");
1183 print
'<td class="right"></td>';
1184 print
'<td class="right"></td>';
1190 if (isset($errorforinvoice[$key]) && $errorforinvoice[$key] ==
'somelinesarenotbound') {
1191 print
'<tr class="oddeven">';
1192 print
"<!-- Some lines are not bound -->";
1193 print
"<td>".$date.
"</td>";
1194 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1197 print
'<span class="error">'.$langs->trans(
'ErrorInvoiceContainsLinesNotYetBoundedShort', $val[
'ref']).
'</span>';
1204 print
'<td class="right"></td>';
1205 print
'<td class="right"></td>';
1212 foreach ($tabttc[$key] as $k => $mt) {
1213 print
'<tr class="oddeven">';
1214 print
"<!-- Thirdparty -->";
1215 print
"<td>".$date.
"</td>";
1216 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1219 $accountoshow =
length_accountg(!empty($tabcompany[$key][
'accountancy_code_supplier_general']) ? $tabcompany[$key][
'accountancy_code_supplier_general'] : $cptfour);
1220 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1221 print
'<span class="error">'.$langs->trans(
"MainAccountForSuppliersNotDefined").
'</span>';
1223 print $accountoshow;
1229 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1230 print
'<span class="error">'.$langs->trans(
"ThirdpartyAccountNotDefined").
'</span>';
1232 print $accountoshow;
1235 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'supplier'), $invoicestatic->ref_supplier, $langs->trans(
"SubledgerAccount"), 1) .
"</td>";
1236 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1237 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1244 foreach ($tabht[$key] as $k => $mt) {
1245 if (empty(
$conf->cache[
'accountingaccountincurrententity'][$k])) {
1247 $accountingaccount->fetch(0, $k,
true);
1248 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
1250 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity'][$k];
1253 print
'<tr class="oddeven">';
1254 print
"<!-- Product -->";
1255 print
"<td>".$date.
"</td>";
1256 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1260 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1261 print
'<span class="error">'.$langs->trans(
"ProductAccountNotDefined").
'</span>';
1263 print $accountoshow;
1272 } elseif (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1273 print
'<span class="error">' . $langs->trans(
"ThirdpartyAccountNotDefined") .
'</span>';
1276 $companystatic->id = $tabcompany[$key][
'id'];
1277 $companystatic->name = $tabcompany[$key][
'name'];
1278 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'supplier'), $invoicestatic->ref_supplier, $accountingaccount->label, 1) .
"</td>";
1279 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1280 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1287 $listoftax = array(0, 1, 2);
1288 foreach ($listoftax as $numtax) {
1289 $arrayofvat = $tabtva;
1291 $arrayofvat = $tablocaltax1;
1294 $arrayofvat = $tablocaltax2;
1300 foreach ($arrayofvat[$key] as $k => $mt) {
1307 $arrayofvat = $tabrctva;
1309 $arrayofvat = $tabrclocaltax1;
1312 $arrayofvat = $tabrclocaltax2;
1314 if (!isset($arrayofvat[$key]) || !is_array($arrayofvat[$key])) {
1315 $arrayofvat[$key] = array();
1320 foreach ($arrayofvat[$key] as $k => $mt) {
1322 print
'<tr class="oddeven">';
1323 print
"<!-- VAT -->";
1324 print
"<td>".$date.
"</td>";
1325 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1329 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1330 print
'<span class="error">'.$langs->trans(
"VATAccountNotDefined").
' ('.$langs->trans(
"AccountingJournalType3").
')</span>';
1332 print $accountoshow;
1338 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
1339 $labelvatrate = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
1340 $labelvatrate .= ($numtax ?
' - Localtax '.$numtax :
'');
1341 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'supplier'), $invoicestatic->ref_supplier, $labelvatrate, 1) .
"</td>";
1342 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1343 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1352 if (isset($tabother[$key]) && is_array($tabother[$key])) {
1353 foreach ($tabother[$key] as $k => $mt) {
1355 print
'<tr class="oddeven">';
1356 print
'<!-- VAT counterpart NPR -->';
1357 print
"<td>".$date.
"</td>";
1358 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1362 if ($accountoshow ==
'' || $accountoshow ==
'NotDefined') {
1363 print
'<span class="error">'.$langs->trans(
"VATAccountNotDefined").
' ('.$langs->trans(
"NPR counterpart").
'). Set ACCOUNTING_COUNTERPART_VAT_NPR to the subvention account</span>';
1365 print $accountoshow;
1371 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'supplier'), $invoicestatic->ref_supplier, $langs->trans(
"VAT").
" NPR (counterpart)", 1) .
"</td>";
1372 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1373 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1383 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)
getSubledgerAccountWithDefault($thirdpartyCode, $type='customer')
Return the subledger account to use for a thirdparty.
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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.
$date_start
Variables from include:
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...
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.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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.