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;
117$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
120$pastmonthyear =
null;
122if (empty($date_startmonth)) {
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');
239$result =
$db->query($sql);
241 $num =
$db->num_rows($result);
245 $obj =
$db->fetch_object($result);
248 $accountancy_code_supplier_general = (!empty($obj->accountancy_code_supplier_general)) ? $obj->accountancy_code_supplier_general : $cptfour;
249 $compta_soc = ($obj->code_compta_fournisseur !=
"") ? $obj->code_compta_fournisseur : $cptfour;
251 $compta_prod = $obj->compte;
252 if (empty($compta_prod)) {
253 if ($obj->product_type == 0) {
260 $tax_id = $obj->tva_tx . ($obj->vat_src_code ?
' (' . $obj->vat_src_code .
')' :
'');
261 $suppliercountrycode = $obj->country_code ? $obj->country_code :
$mysoc->country_code;
262 $vatdata_cache_key = $suppliercountrycode.
'|'.$tax_id;
263 if (array_key_exists($vatdata_cache_key, $vatdata_cache)) {
264 $vatdata = $vatdata_cache[$vatdata_cache_key];
266 $supplierstatic->country_code = $suppliercountrycode;
268 $vatdata_cache[$vatdata_cache_key] = $vatdata;
270 $compta_tva = (!empty($vatdata[
'accountancy_code_buy']) ? $vatdata[
'accountancy_code_buy'] : $cpttva);
271 $compta_localtax1 = (!empty($vatdata[
'accountancy_code_buy']) ? $vatdata[
'accountancy_code_buy'] : $cptlocaltax1);
272 $compta_localtax2 = (!empty($vatdata[
'accountancy_code_buy']) ? $vatdata[
'accountancy_code_buy'] : $cptlocaltax2);
273 $compta_counterpart_tva_npr =
getDolGlobalString(
'ACCOUNTING_COUNTERPART_VAT_NPR',
'NotDefined');
276 if (
price2num($obj->tva_tx) || !empty($obj->vat_src_code)) {
277 $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.
')' :
''));
278 if ($obj->localtax1_tx > 0.0) {
279 $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.
')' :
''));
281 if ($obj->localtax2_tx > 0.0) {
282 $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.
')' :
''));
290 if (!array_key_exists($obj->rowid, $tabfac)) {
291 $tabfac[$obj->rowid] = array();
292 $tabttc[$obj->rowid] = array();
293 $tabht[$obj->rowid] = array();
294 $tabtva[$obj->rowid] = array();
295 $tablocaltax1[$obj->rowid] = array();
296 $tablocaltax2[$obj->rowid] = array();
298 if (!isset($tabttc[$obj->rowid][$compta_soc])) {
299 $tabttc[$obj->rowid][$compta_soc] = 0;
301 if (!isset($tabht[$obj->rowid][$compta_prod])) {
302 $tabht[$obj->rowid][$compta_prod] = 0;
304 if (!isset($tabtva[$obj->rowid][$compta_tva])) {
305 $tabtva[$obj->rowid][$compta_tva] = 0;
307 if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
308 $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
310 if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
311 $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
314 $tabfac[$obj->rowid][
"date"] =
$db->jdate($obj->df);
315 $tabfac[$obj->rowid][
"datereg"] =
$db->jdate($obj->dlr);
316 $tabfac[$obj->rowid][
"ref"] = $obj->ref_supplier.
' ('.$obj->ref.
')';
317 $tabfac[$obj->rowid][
"refsologest"] = $obj->ref;
318 $tabfac[$obj->rowid][
"refsuppliersologest"] = $obj->ref_supplier;
319 $tabfac[$obj->rowid][
"type"] = $obj->type;
320 $tabfac[$obj->rowid][
"description"] = $obj->description;
321 $tabfac[$obj->rowid][
"close_code"] = $obj->close_code;
325 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'))) {
326 $rcvatdata =
getTaxesFromId($obj->product_buy_vat . ($obj->product_buy_default_vat_code ?
' (' . $obj->product_buy_default_vat_code .
')' :
''),
$mysoc,
$mysoc, 0);
327 $rcc_compta_tva = (!empty($vatdata[
'accountancy_code_vat_reverse_charge_credit']) ? $vatdata[
'accountancy_code_vat_reverse_charge_credit'] : $rcctva);
328 $rcd_compta_tva = (!empty($vatdata[
'accountancy_code_vat_reverse_charge_debit']) ? $vatdata[
'accountancy_code_vat_reverse_charge_debit'] : $rcdtva);
329 $rcc_compta_localtax1 = (!empty($vatdata[
'accountancy_code_vat_reverse_charge_credit']) ? $vatdata[
'accountancy_code_vat_reverse_charge_credit'] : $rcclocaltax1);
330 $rcd_compta_localtax1 = (!empty($vatdata[
'accountancy_code_vat_reverse_charge_debit']) ? $vatdata[
'accountancy_code_vat_reverse_charge_debit'] : $rcdlocaltax1);
331 $rcc_compta_localtax2 = (!empty($vatdata[
'accountancy_code_vat_reverse_charge_credit']) ? $vatdata[
'accountancy_code_vat_reverse_charge_credit'] : $rcclocaltax2);
332 $rcd_compta_localtax2 = (!empty($vatdata[
'accountancy_code_vat_reverse_charge_debit']) ? $vatdata[
'accountancy_code_vat_reverse_charge_debit'] : $rcdlocaltax2);
333 if (
price2num($obj->product_buy_vat) || !empty($obj->product_buy_default_vat_code)) {
334 $vat_key =
vatrate($obj->product_buy_vat) . ($obj->product_buy_default_vat_code ?
' (' . $obj->product_buy_default_vat_code .
')' :
'');
335 $val_value = $vat_key;
336 $def_tva[$obj->rowid][$rcc_compta_tva][$vat_key] = $val_value;
337 $def_tva[$obj->rowid][$rcd_compta_tva][$vat_key] = $val_value;
340 if (!array_key_exists($obj->rowid, $tabrctva)) {
341 $tabrctva[$obj->rowid] = array();
342 $tabrclocaltax1[$obj->rowid] = array();
343 $tabrclocaltax2[$obj->rowid] = array();
345 if (!isset($tabrctva[$obj->rowid][$rcc_compta_tva])) {
346 $tabrctva[$obj->rowid][$rcc_compta_tva] = 0;
348 if (!isset($tabrctva[$obj->rowid][$rcd_compta_tva])) {
349 $tabrctva[$obj->rowid][$rcd_compta_tva] = 0;
351 if (!isset($tabrclocaltax1[$obj->rowid][$rcc_compta_localtax1])) {
352 $tabrclocaltax1[$obj->rowid][$rcc_compta_localtax1] = 0;
354 if (!isset($tabrclocaltax1[$obj->rowid][$rcd_compta_localtax1])) {
355 $tabrclocaltax1[$obj->rowid][$rcd_compta_localtax1] = 0;
357 if (!isset($tabrclocaltax2[$obj->rowid][$rcc_compta_localtax2])) {
358 $tabrclocaltax2[$obj->rowid][$rcc_compta_localtax2] = 0;
360 if (!isset($tabrclocaltax2[$obj->rowid][$rcd_compta_localtax2])) {
361 $tabrclocaltax2[$obj->rowid][$rcd_compta_localtax2] = 0;
364 $rcvat = (float)
price2num($obj->total_ttc * $obj->product_buy_vat / 100,
'MT');
365 $rclocalvat1 = (float)
price2num($obj->total_ttc * $obj->product_buy_localvat1 / 100,
'MT');
366 $rclocalvat2 = (float)
price2num($obj->total_ttc * $obj->product_buy_localvat2 / 100,
'MT');
368 $tabrctva[$obj->rowid][$rcd_compta_tva] += $rcvat;
369 $tabrctva[$obj->rowid][$rcc_compta_tva] -= $rcvat;
370 $tabrclocaltax1[$obj->rowid][$rcd_compta_localtax1] += $rclocalvat1;
371 $tabrclocaltax1[$obj->rowid][$rcc_compta_localtax1] -= $rclocalvat1;
372 $tabrclocaltax2[$obj->rowid][$rcd_compta_localtax2] += $rclocalvat2;
373 $tabrclocaltax2[$obj->rowid][$rcc_compta_localtax2] -= $rclocalvat2;
376 $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc;
378 if ($noTaxDispatchingKeepWithLines) {
379 $tabht[$obj->rowid][$compta_prod] += $obj->total_ttc;
381 $tabht[$obj->rowid][$compta_prod] += $obj->total_ht;
382 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
383 $tva_npr = ((($obj->info_bits & 1) == 1) ? 1 : 0);
385 if (!array_key_exists($obj->rowid, $tabother)) {
386 $tabother[$obj->rowid] = array();
388 if (!array_key_exists($compta_counterpart_tva_npr, $tabother[$obj->rowid])) {
389 $tabother[$obj->rowid][$compta_counterpart_tva_npr] = 0;
391 $tabother[$obj->rowid][$compta_counterpart_tva_npr] += (float) $obj->total_tva;
393 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
394 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
396 $tabcompany[$obj->rowid] = array(
398 'name' => $obj->name,
399 'code_fournisseur' => $obj->code_fournisseur,
400 'accountancy_code_supplier_general' => $accountancy_code_supplier_general,
401 'code_compta_fournisseur' => $compta_soc
407 if ($i >
getDolGlobalInt(
'ACCOUNTANCY_MAX_TOO_MANY_LINES_TO_PROCESS', 10000)) {
409 setEventMessages(
"ErrorTooManyLinesToProcessPleaseUseAMoreSelectiveFilter",
null,
'errors');
417$errorforinvoice = array();
440if (!empty($tabfac)) {
444 COUNT(fd.rowid) as nb
446 " . MAIN_DB_PREFIX .
"facture_fourn_det as fd
449 AND fd.fk_code_ventilation <= 0
450 AND fd.total_ttc <> 0
451 AND fk_facture_fourn IN (".$db->sanitize(implode(
",", array_keys($tabfac))).
")
452 GROUP BY fk_facture_fourn
454 $resql =
$db->query($sql);
456 $num =
$db->num_rows($resql);
459 $obj =
$db->fetch_object($resql);
461 $errorforinvoice[$obj->fk_facture_fourn] =
'somelinesarenotbound';
468if ($action ==
'writebookkeeping' && !$error && $user->hasRight(
'accounting',
'bind',
'write')) {
477 $accountingaccountsupplier->fetch(0,
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUPPLIER'),
true);
479 foreach ($tabfac as $key => $val) {
487 $companystatic->id = $tabcompany[$key][
'id'];
488 $companystatic->name = $tabcompany[$key][
'name'];
489 $companystatic->accountancy_code_supplier_general = $tabcompany[$key][
'accountancy_code_supplier_general'];
490 $companystatic->code_compta_fournisseur = $tabcompany[$key][
'code_compta_fournisseur'];
491 $companystatic->code_fournisseur = $tabcompany[$key][
'code_fournisseur'];
492 $companystatic->fournisseur = 1;
494 $invoicestatic->id = (int) $key;
495 $invoicestatic->ref = (
string) $val[
"refsologest"];
496 $invoicestatic->ref_supplier = (
string) $val[
"refsuppliersologest"];
497 $invoicestatic->type = $val[
"type"];
498 $invoicestatic->description = html_entity_decode(
dol_trunc((
string) $val[
"description"], 32));
499 $invoicestatic->close_code = (
string) $val[
"close_code"];
504 $replacedinvoice = 0;
505 if ($invoicestatic->close_code == FactureFournisseur::CLOSECODE_REPLACED) {
506 $replacedinvoice = 1;
507 $alreadydispatched = $invoicestatic->getVentilExportCompta();
508 if ($alreadydispatched) {
509 $replacedinvoice = 2;
514 if ($replacedinvoice == 1) {
520 if (isset($errorforinvoice[$key]) && $errorforinvoice[$key] ==
'somelinesarenotbound') {
523 setEventMessages($langs->trans(
'ErrorInvoiceContainsLinesNotYetBounded', $val[
'ref']),
null,
'errors');
527 if (!$errorforline) {
528 foreach ($tabttc[$key] as $k => $mt) {
530 $bookkeeping->doc_date = $val[
"date"];
531 $bookkeeping->date_lim_reglement = $val[
"datereg"];
532 $bookkeeping->doc_ref = $val[
"refsologest"];
533 $bookkeeping->date_creation = $now;
534 $bookkeeping->doc_type =
'supplier_invoice';
535 $bookkeeping->fk_doc = (int) $key;
536 $bookkeeping->fk_docdet = 0;
537 $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
539 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta_fournisseur'];
540 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
542 $bookkeeping->numero_compte = $tabcompany[$key][
'accountancy_code_supplier_general'];
543 $bookkeeping->label_compte = $accountingaccountsupplier->label;
545 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref_supplier, $langs->trans(
"SubledgerAccount"));
546 $bookkeeping->montant = $mt;
547 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
548 $bookkeeping->debit = ($mt <= 0) ? -$mt : 0;
549 $bookkeeping->credit = ($mt > 0) ? $mt : 0;
550 $bookkeeping->code_journal = $journal;
551 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
552 $bookkeeping->fk_user_author = $user->id;
553 $bookkeeping->entity =
$conf->entity;
555 $totaldebit += $bookkeeping->debit;
556 $totalcredit += $bookkeeping->credit;
558 $result = $bookkeeping->create($user);
560 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
563 $errorforinvoice[$key] =
'alreadyjournalized';
568 $errorforinvoice[$key] =
'other';
573 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/lettering.class.php';
576 $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id));
583 if (!$errorforline) {
584 foreach ($tabht[$key] as $k => $mt) {
585 if (empty(
$conf->cache[
'accountingaccountincurrententity'][$k])) {
587 $accountingaccount->fetch(0, $k,
true);
588 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
590 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity'][$k];
593 $label_account = $accountingaccount->label;
596 if ($accountingaccount->id > 0) {
598 $bookkeeping->doc_date = $val[
"date"];
599 $bookkeeping->date_lim_reglement = $val[
"datereg"];
600 $bookkeeping->doc_ref = $val[
"refsologest"];
601 $bookkeeping->date_creation = $now;
602 $bookkeeping->doc_type =
'supplier_invoice';
603 $bookkeeping->fk_doc = (int) $key;
604 $bookkeeping->fk_docdet = 0;
605 $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
609 $bookkeeping->subledger_account = $tabcompany[$key][
'code_compta_fournisseur'];
610 $bookkeeping->subledger_label = $tabcompany[$key][
'name'];
612 $bookkeeping->subledger_account =
'';
613 $bookkeeping->subledger_label =
'';
616 $bookkeeping->subledger_account =
'';
617 $bookkeeping->subledger_label =
'';
620 $bookkeeping->numero_compte = $k;
621 $bookkeeping->label_compte = $label_account;
623 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref_supplier, $label_account);
624 $bookkeeping->montant = $mt;
625 $bookkeeping->sens = ($mt < 0) ?
'C' :
'D';
626 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
627 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
628 $bookkeeping->code_journal = $journal;
629 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
630 $bookkeeping->fk_user_author = $user->id;
631 $bookkeeping->entity =
$conf->entity;
633 $totaldebit += $bookkeeping->debit;
634 $totalcredit += $bookkeeping->credit;
636 $result = $bookkeeping->create($user);
638 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
641 $errorforinvoice[$key] =
'alreadyjournalized';
646 $errorforinvoice[$key] =
'other';
656 if (!$errorforline) {
657 $listoftax = array(0, 1, 2);
658 foreach ($listoftax as $numtax) {
659 $arrayofvat = $tabtva;
661 $arrayofvat = $tablocaltax1;
664 $arrayofvat = $tablocaltax2;
670 foreach ($arrayofvat[$key] as $k => $mt) {
677 $arrayofvat = $tabrctva;
679 $arrayofvat = $tabrclocaltax1;
682 $arrayofvat = $tabrclocaltax2;
684 if (!isset($arrayofvat[$key]) || !is_array($arrayofvat[$key])) {
685 $arrayofvat[$key] = array();
690 foreach ($arrayofvat[$key] as $k => $mt) {
692 if (empty(
$conf->cache[
'accountingaccountincurrententity_vat'][$k])) {
694 $accountingaccount->fetch(0, $k,
true);
695 $conf->cache[
'accountingaccountincurrententity_vat'][$k] = $accountingaccount;
697 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity_vat'][$k];
700 $label_account = $accountingaccount->label;
703 $bookkeeping->doc_date = $val[
"date"];
704 $bookkeeping->date_lim_reglement = $val[
"datereg"];
705 $bookkeeping->doc_ref = $val[
"refsologest"];
706 $bookkeeping->date_creation = $now;
707 $bookkeeping->doc_type =
'supplier_invoice';
708 $bookkeeping->fk_doc = (int) $key;
709 $bookkeeping->fk_docdet = 0;
710 $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
712 $bookkeeping->subledger_account =
'';
713 $bookkeeping->subledger_label =
'';
715 $bookkeeping->numero_compte = $k;
716 $bookkeeping->label_compte = $label_account;
718 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
719 $labelvataccount = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
720 $labelvataccount .= ($numtax ?
' - Localtax '.$numtax :
'');
721 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref_supplier, $labelvataccount);
723 $bookkeeping->montant = $mt;
724 $bookkeeping->sens = ($mt < 0) ?
'C' :
'D';
725 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
726 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
727 $bookkeeping->code_journal = $journal;
728 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
729 $bookkeeping->fk_user_author = $user->id;
730 $bookkeeping->entity =
$conf->entity;
732 $totaldebit += $bookkeeping->debit;
733 $totalcredit += $bookkeeping->credit;
735 $result = $bookkeeping->create($user);
737 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
740 $errorforinvoice[$key] =
'alreadyjournalized';
745 $errorforinvoice[$key] =
'other';
756 if (!$errorforline && isset($tabother[$key]) && is_array($tabother[$key])) {
757 foreach ($tabother[$key] as $k => $mt) {
760 $bookkeeping->doc_date = $val[
"date"];
761 $bookkeeping->date_lim_reglement = $val[
"datereg"];
762 $bookkeeping->doc_ref = $val[
"refsologest"];
763 $bookkeeping->date_creation = $now;
764 $bookkeeping->doc_type =
'supplier_invoice';
765 $bookkeeping->fk_doc = (int) $key;
766 $bookkeeping->fk_docdet = 0;
767 $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
769 $bookkeeping->subledger_account =
'';
770 $bookkeeping->subledger_label =
'';
772 $bookkeeping->numero_compte = $k;
774 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref_supplier, $langs->trans(
"VAT").
' NPR');
775 $bookkeeping->montant = $mt;
776 $bookkeeping->sens = ($mt < 0) ?
'C' :
'D';
777 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
778 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
779 $bookkeeping->code_journal = $journal;
780 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
781 $bookkeeping->fk_user_author = $user->id;
782 $bookkeeping->entity =
$conf->entity;
784 $totaldebit += $bookkeeping->debit;
785 $totalcredit += $bookkeeping->credit;
787 $result = $bookkeeping->create($user);
789 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
792 $errorforinvoice[$key] =
'alreadyjournalized';
797 $errorforinvoice[$key] =
'other';
806 if (!$errorforline && (
price2num($totaldebit,
'MT') !=
price2num($totalcredit,
'MT'))) {
809 $errorforinvoice[$key] =
'amountsnotbalanced';
810 setEventMessages(
'We tried to insert a non balanced transaction in book for '.$invoicestatic->ref.
'. Canceled. Surely a bug.',
null,
'errors');
813 if (!$errorforline) {
819 setEventMessages($langs->trans(
"ErrorTooManyErrorsProcessStopped"),
null,
'errors');
827 if (empty($error) && count($tabpay) > 0) {
829 } elseif (count($tabpay) == $error) {
832 setEventMessages($langs->trans(
"GeneralLedgerSomeRecordWasNotRecorded"),
null,
'warnings');
838 if (count($tabpay) != $error) {
839 $param =
'id_journal='.$id_journal;
840 $param .=
'&date_startday='.$date_startday;
841 $param .=
'&date_startmonth='.$date_startmonth;
842 $param .=
'&date_startyear='.$date_startyear;
843 $param .=
'&date_endday='.$date_endday;
844 $param .=
'&date_endmonth='.$date_endmonth;
845 $param .=
'&date_endyear='.$date_endyear;
846 $param .=
'&in_bookkeeping='.$in_bookkeeping;
847 header(
"Location: ".$_SERVER[
'PHP_SELF'].($param ?
'?'.$param :
''));
859if ($action ==
'exportcsv' && !$error) {
862 $filename =
'journal';
863 $type_export =
'journal';
864 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
870 foreach ($tabfac as $key => $val) {
871 $companystatic->id = $tabcompany[$key][
'id'];
872 $companystatic->name = $tabcompany[$key][
'name'];
873 $companystatic->accountancy_code_supplier_general = !empty($tabcompany[$key][
'accountancy_code_supplier_general']) ? $tabcompany[$key][
'accountancy_code_supplier_general'] : $cptfour;
874 $companystatic->code_compta_fournisseur = $tabcompany[$key][
'code_compta_fournisseur'];
875 $companystatic->code_fournisseur = $tabcompany[$key][
'code_fournisseur'];
876 $companystatic->fournisseur = 1;
878 $invoicestatic->id = (int) $key;
879 $invoicestatic->ref = (
string) $val[
"refsologest"];
880 $invoicestatic->ref_supplier = (
string) $val[
"refsuppliersologest"];
881 $invoicestatic->type = $val[
"type"];
882 $invoicestatic->description =
dol_trunc(html_entity_decode((
string) $val[
"description"]), 32);
883 $invoicestatic->close_code = (
string) $val[
"close_code"];
888 $replacedinvoice = 0;
889 if ($invoicestatic->close_code == FactureFournisseur::CLOSECODE_REPLACED) {
890 $replacedinvoice = 1;
891 $alreadydispatched = $invoicestatic->getVentilExportCompta();
892 if ($alreadydispatched) {
893 $replacedinvoice = 2;
898 if ($replacedinvoice == 1) {
903 foreach ($tabttc[$key] as $k => $mt) {
905 print
'"'.$key.
'"'.$sep;
906 print
'"'.$date.
'"'.$sep;
907 print
'"'.((string) $val[
"refsologest"]).
'"'.$sep;
908 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
909 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
910 print
'"'.length_accountg($companystatic->accountancy_code_supplier_general).
'"'.$sep;
911 print
'"'.length_accounta(html_entity_decode($k)).
'"'.$sep;
912 print
'"'.$langs->trans(
"ThirdParty").
'"'.$sep;
913 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $val[
"refsuppliersologest"], $langs->trans(
"ThirdParty"))).
'"'.$sep;
914 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
915 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
916 print
'"'.$journal.
'"';
922 foreach ($tabht[$key] as $k => $mt) {
924 $accountingaccount->fetch(0, $k,
true);
926 print
'"'.$key.
'"'.$sep;
927 print
'"'.$date.
'"'.$sep;
928 print
'"'.((string) $val[
"refsologest"]).
'"'.$sep;
929 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
930 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
931 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
933 print
'"'.csvClean(
dol_trunc($accountingaccount->label, 32)).
'"'.$sep;
934 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $val[
"refsuppliersologest"], $accountingaccount->label)).
'"'.$sep;
935 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
936 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
937 print
'"'.$journal.
'"';
943 $listoftax = array(0, 1, 2);
944 foreach ($listoftax as $numtax) {
945 $arrayofvat = $tabtva;
947 $arrayofvat = $tablocaltax1;
950 $arrayofvat = $tablocaltax2;
956 foreach ($arrayofvat[$key] as $k => $mt) {
963 $arrayofvat = $tabrctva;
965 $arrayofvat = $tabrclocaltax1;
968 $arrayofvat = $tabrclocaltax2;
970 if (!isset($arrayofvat[$key]) || !is_array($arrayofvat[$key])) {
971 $arrayofvat[$key] = array();
976 foreach ($arrayofvat[$key] as $k => $mt) {
978 print
'"'.$key.
'"'.$sep;
979 print
'"'.$date.
'"'.$sep;
980 print
'"'.((string) $val[
"refsologest"]).
'"'.$sep;
981 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
982 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
983 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
985 print
'"'.$langs->trans(
"VAT").
' - '.implode(
', ', $def_tva[$key][$k]).
' %"'.$sep;
986 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $val[
"refsuppliersologest"], $langs->trans(
"VAT").implode($def_tva[$key][$k]).
' %'.($numtax ?
' - Localtax '.$numtax :
''))).
'"'.$sep;
987 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
988 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
989 print
'"'.$journal.
'"';
995 if (isset($tabother[$key]) && is_array($tabother[$key])) {
996 foreach ($tabother[$key] as $k => $mt) {
998 print
'"'.$key.
'"'.$sep;
999 print
'"'.$date.
'"'.$sep;
1000 print
'"'.((string) $val[
"refsologest"]).
'"'.$sep;
1001 print
'"'.csvClean(
dol_trunc($companystatic->name, 32)).
'"'.$sep;
1002 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1003 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1004 print
'"'.length_accountg(html_entity_decode($k)).
'"'.$sep;
1005 print
'"'.$langs->trans(
"ThirdParty").
'"'.$sep;
1006 print
'"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $val[
"refsuppliersologest"], $langs->trans(
"VAT").
' NPR')).
'"'.$sep;
1007 print
'"'.($mt < 0 ?
price(-$mt) :
'').
'"'.$sep;
1008 print
'"'.($mt >= 0 ?
price($mt) :
'').
'"'.$sep;
1009 print
'"'.$journal.
'"';
1018if (empty($action) || $action ==
'view') {
1019 $title = $langs->trans(
"GenerationOfAccountingEntries").
' - '.$accountingjournalstatic->getNomUrl(0, 2, 1,
'', 1);
1020 $help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
1021 llxHeader(
'',
dol_string_nohtmltag($title), $help_url,
'', 0, 0,
'',
'',
'',
'mod-accountancy accountancy-generation page-purchasesjournal');
1028 $description = $langs->trans(
"DescJournalOnlyBindedVisible").
'<br>';
1030 $description .= $langs->trans(
"DepositsAreNotIncluded");
1032 $description .= $langs->trans(
"DepositsAreIncluded");
1035 $listofchoices = array(
'notyet' => $langs->trans(
"NotYetInGeneralLedger"),
'already' => $langs->trans(
"AlreadyInGeneralLedger"));
1036 $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);
1037 $period .=
' - '.$langs->trans(
"JournalizationInLedgerStatus").
' '.$form->selectarray(
'in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
1039 $varlink =
'id_journal='.$id_journal;
1041 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array(
'action' =>
''),
'', $varlink);
1046 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_fiscalyear WHERE entity = ".((int)
$conf->entity);
1047 $resql =
$db->query($sql);
1049 $obj =
$db->fetch_object($resql);
1050 if ($obj->nb == 0) {
1051 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"TheFiscalPeriodIsNotDefined");
1052 $desc =
' : '.$langs->trans(
"AccountancyAreaDescFiscalPeriod", 4,
'{link}');
1053 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"FiscalPeriod").
'</strong>', $desc);
1063 $acctSupplierNotConfigured = in_array(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUPPLIER'), [
'',
'-1']);
1064 if ($acctSupplierNotConfigured) {
1065 print
'<br><div class="warning">'.img_warning().
' '.$langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone");
1066 $desc =
' : '.$langs->trans(
"AccountancyAreaDescMisc", 4,
'{link}');
1067 $desc = str_replace(
'{link}',
'<strong>'.$langs->transnoentitiesnoconv(
"MenuAccountancy").
'-'.$langs->transnoentitiesnoconv(
"Setup").
"-".$langs->transnoentitiesnoconv(
"MenuDefaultAccounts").
'</strong>', $desc);
1071 print
'<br><div class="tabsAction tabsActionNoBottom centerimp">';
1072 if (
getDolGlobalString(
'ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping ==
'notyet') {
1073 print
'<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans(
"ExportDraftJournal").
'" onclick="launch_export();" />';
1075 if ($acctSupplierNotConfigured) {
1076 print
'<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans(
"SomeMandatoryStepsOfSetupWereNotDone")).
'" value="'.$langs->trans(
"WriteBookKeeping").
'" />';
1078 if ($in_bookkeeping ==
'notyet') {
1079 print
'<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans(
"WriteBookKeeping").
'" onclick="writebookkeeping();" />';
1081 print
'<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans(
"WriteBookKeeping").
'</a>';
1088 <script type="text/javascript">
1089 function launch_export() {
1090 $("div.fiche form input[name=\"action\"]").val("exportcsv");
1091 $("div.fiche form input[type=\"submit\"]").click();
1092 $("div.fiche form input[name=\"action\"]").val("");
1094 function writebookkeeping() {
1095 console.log("click on writebookkeeping");
1096 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
1097 $("div.fiche form input[type=\"submit\"]").click();
1098 $("div.fiche form input[name=\"action\"]").val("");
1107 print
'<div class="div-table-responsive">';
1108 print
"<table class=\"noborder\" width=\"100%\">";
1109 print
"<tr class=\"liste_titre\">";
1110 print
"<td>".$langs->trans(
"Date").
"</td>";
1111 print
"<td>".$langs->trans(
"Piece").
' ('.$langs->trans(
"InvoiceRef").
")</td>";
1112 print
"<td>".$langs->trans(
"AccountAccounting").
"</td>";
1113 print
"<td>".$langs->trans(
"SubledgerAccount").
"</td>";
1114 print
"<td>".$langs->trans(
"LabelOperation").
"</td>";
1115 print
'<td class="center">'.$langs->trans(
"AccountingDebit").
"</td>";
1116 print
'<td class="center">'.$langs->trans(
"AccountingCredit").
"</td>";
1125 foreach ($tabfac as $key => $val) {
1126 $companystatic->id = $tabcompany[$key][
'id'];
1127 $companystatic->name = $tabcompany[$key][
'name'];
1128 $companystatic->accountancy_code_supplier_general = !empty($tabcompany[$key][
'accountancy_code_supplier_general']) ? $tabcompany[$key][
'accountancy_code_supplier_general'] : $cptfour;
1129 $companystatic->code_compta_fournisseur = $tabcompany[$key][
'code_compta_fournisseur'];
1130 $companystatic->code_fournisseur = $tabcompany[$key][
'code_fournisseur'];
1131 $companystatic->fournisseur = 1;
1133 $invoicestatic->id = (int) $key;
1134 $invoicestatic->ref = (
string) $val[
"refsologest"];
1135 $invoicestatic->ref_supplier = (
string) $val[
"refsuppliersologest"];
1136 $invoicestatic->type = $val[
"type"];
1137 $invoicestatic->description =
dol_trunc(html_entity_decode((
string) $val[
"description"]), 32);
1138 $invoicestatic->close_code = (
string) $val[
"close_code"];
1143 $replacedinvoice = 0;
1144 if ($invoicestatic->close_code == FactureFournisseur::CLOSECODE_REPLACED) {
1145 $replacedinvoice = 1;
1146 $alreadydispatched = $invoicestatic->getVentilExportCompta();
1147 if ($alreadydispatched) {
1148 $replacedinvoice = 2;
1153 if ($replacedinvoice == 1) {
1154 print
'<tr class="oddeven">';
1155 print
"<!-- Replaced invoice -->";
1156 print
"<td>".$date.
"</td>";
1157 print
"<td><strike>".$invoicestatic->getNomUrl(1).
"</strike></td>";
1160 print $langs->trans(
"Replaced");
1167 print
'<td class="right"></td>';
1168 print
'<td class="right"></td>';
1174 if (isset($errorforinvoice[$key]) && $errorforinvoice[$key] ==
'somelinesarenotbound') {
1175 print
'<tr class="oddeven">';
1176 print
"<!-- Some lines are not bound -->";
1177 print
"<td>".$date.
"</td>";
1178 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1181 print
'<span class="error">'.$langs->trans(
'ErrorInvoiceContainsLinesNotYetBoundedShort', $val[
'ref']).
'</span>';
1188 print
'<td class="right"></td>';
1189 print
'<td class="right"></td>';
1196 foreach ($tabttc[$key] as $k => $mt) {
1197 print
'<tr class="oddeven">';
1198 print
"<!-- Thirdparty -->";
1199 print
"<td>".$date.
"</td>";
1200 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1203 $accountoshow =
length_accountg(!empty($tabcompany[$key][
'accountancy_code_supplier_general']) ? $tabcompany[$key][
'accountancy_code_supplier_general'] : $cptfour);
1204 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1205 print
'<span class="error">'.$langs->trans(
"MainAccountForSuppliersNotDefined").
'</span>';
1207 print $accountoshow;
1213 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1214 print
'<span class="error">'.$langs->trans(
"ThirdpartyAccountNotDefined").
'</span>';
1216 print $accountoshow;
1219 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'supplier'), $invoicestatic->ref_supplier, $langs->trans(
"SubledgerAccount"), 1) .
"</td>";
1220 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1221 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1228 foreach ($tabht[$key] as $k => $mt) {
1229 if (empty(
$conf->cache[
'accountingaccountincurrententity'][$k])) {
1231 $accountingaccount->fetch(0, $k,
true);
1232 $conf->cache[
'accountingaccountincurrententity'][$k] = $accountingaccount;
1234 $accountingaccount =
$conf->cache[
'accountingaccountincurrententity'][$k];
1237 print
'<tr class="oddeven">';
1238 print
"<!-- Product -->";
1239 print
"<td>".$date.
"</td>";
1240 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1244 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1245 print
'<span class="error">'.$langs->trans(
"ProductAccountNotDefined").
'</span>';
1247 print $accountoshow;
1256 } elseif (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1257 print
'<span class="error">' . $langs->trans(
"ThirdpartyAccountNotDefined") .
'</span>';
1260 $companystatic->id = $tabcompany[$key][
'id'];
1261 $companystatic->name = $tabcompany[$key][
'name'];
1262 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'supplier'), $invoicestatic->ref_supplier, $accountingaccount->label, 1) .
"</td>";
1263 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1264 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1271 $listoftax = array(0, 1, 2);
1272 foreach ($listoftax as $numtax) {
1273 $arrayofvat = $tabtva;
1275 $arrayofvat = $tablocaltax1;
1278 $arrayofvat = $tablocaltax2;
1284 foreach ($arrayofvat[$key] as $k => $mt) {
1291 $arrayofvat = $tabrctva;
1293 $arrayofvat = $tabrclocaltax1;
1296 $arrayofvat = $tabrclocaltax2;
1298 if (!isset($arrayofvat[$key]) || !is_array($arrayofvat[$key])) {
1299 $arrayofvat[$key] = array();
1304 foreach ($arrayofvat[$key] as $k => $mt) {
1306 print
'<tr class="oddeven">';
1307 print
"<!-- VAT -->";
1308 print
"<td>".$date.
"</td>";
1309 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1313 if (($accountoshow ==
"") || $accountoshow ==
'NotDefined') {
1314 print
'<span class="error">'.$langs->trans(
"VATAccountNotDefined").
' ('.$langs->trans(
"AccountingJournalType3").
')</span>';
1316 print $accountoshow;
1322 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ?
'' : $arrayofvat[$key][$k]) : implode(
', ', $def_tva[$key][$k]));
1323 $labelvatrate = $langs->trans(
"Taxes").
' '.$tmpvatrate.
' %';
1324 $labelvatrate .= ($numtax ?
' - Localtax '.$numtax :
'');
1325 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'supplier'), $invoicestatic->ref_supplier, $labelvatrate, 1) .
"</td>";
1326 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1327 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1336 if (isset($tabother[$key]) && is_array($tabother[$key])) {
1337 foreach ($tabother[$key] as $k => $mt) {
1339 print
'<tr class="oddeven">';
1340 print
'<!-- VAT counterpart NPR -->';
1341 print
"<td>".$date.
"</td>";
1342 print
"<td>".$invoicestatic->getNomUrl(1).
"</td>";
1346 if ($accountoshow ==
'' || $accountoshow ==
'NotDefined') {
1347 print
'<span class="error">'.$langs->trans(
"VATAccountNotDefined").
' ('.$langs->trans(
"NPR counterpart").
'). Set ACCOUNTING_COUNTERPART_VAT_NPR to the subvention account</span>';
1349 print $accountoshow;
1355 print
"<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0,
'supplier'), $invoicestatic->ref_supplier, $langs->trans(
"VAT").
" NPR (counterpart)", 1) .
"</td>";
1356 print
'<td class="right nowraponall amount">'.($mt < 0 ?
price(-$mt) :
'').
"</td>";
1357 print
'<td class="right nowraponall amount">'.($mt >= 0 ?
price($mt) :
'').
"</td>";
1367 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.
$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...
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.
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, $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_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.
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.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.