dolibarr 23.0.3
purchasesjournal.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2007-2010 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2007-2010 Jean Heimburger <jean@tiaris.info>
4 * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
5 * Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2013-2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
7 * Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
8 * Copyright (C) 2013-2016 Florian Henry <florian.henry@open-concept.pro>
9 * Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2018 Eric Seigne <eric.seigne@cap-rel.fr>
11 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
12 * Copyright (C) 2025 Vincent de Grandporé <vincent@de-grandpre.quebec>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27
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';
43
53// Load translation files required by the page
54$langs->loadLangs(array("commercial", "compta", "bills", "other", "accountancy", "errors"));
55
56$id_journal = GETPOSTINT('id_journal');
57$action = GETPOST('action', 'aZ09');
58
59$date_startmonth = GETPOSTINT('date_startmonth');
60$date_startday = GETPOSTINT('date_startday');
61$date_startyear = GETPOSTINT('date_startyear');
62$date_endmonth = GETPOSTINT('date_endmonth');
63$date_endday = GETPOSTINT('date_endday');
64$date_endyear = GETPOSTINT('date_endyear');
65$in_bookkeeping = GETPOST('in_bookkeeping');
66if ($in_bookkeeping == '') {
67 $in_bookkeeping = 'notyet';
68}
69
70$now = dol_now();
71
72$hookmanager->initHooks(array('purchasesjournal'));
73$parameters = array();
74
75// Security check
76if (!isModEnabled('accounting')) {
78}
79if ($user->socid > 0) {
81}
82if (!$user->hasRight('accounting', 'bind', 'write')) {
84}
85
86$error = 0;
87
88$tabfac = array();
89$tabht = array();
90$tabtva = array();
91$tabttc = array();
92$tablocaltax1 = array();
93$tablocaltax2 = array();
94$tabrctva = array();
95$tabrclocaltax1 = array();
96$tabrclocaltax2 = array();
97$tabpay = array();
98
99$cptcli = 'NotDefined';
100$cptfour = 'NotDefined';
101
102/*
103 * Actions
104 */
105
106$reshook = $hookmanager->executeHooks('doActions', $parameters, $user, $action); // Note that $action and $object may have been modified by some hooks
107
108$accountingaccount = new AccountingAccount($db);
109
110// Get information of a journal
111$accountingjournalstatic = new AccountingJournal($db);
112$accountingjournalstatic->fetch($id_journal);
113$journal = $accountingjournalstatic->code;
114$journal_label = $accountingjournalstatic->label;
115
116$date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
117$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
118
119$pastmonth = null; // Initialise, could be unset
120$pastmonthyear = null; // Initialise, could be unset
121
122if (empty($date_startmonth)) {
123 // Period by default on transfer
125 $date_start = $dates['date_start'];
126 $pastmonthyear = $dates['pastmonthyear'];
127 $pastmonth = $dates['pastmonth'];
128}
129if (empty($date_endmonth)) {
130 // Period by default on transfer
132 $date_end = $dates['date_end'];
133 $pastmonthyear = $dates['pastmonthyear'];
134 $pastmonth = $dates['pastmonth'];
135}
136
137if (!GETPOSTISSET('date_startmonth') && (empty($date_start) || empty($date_end))) { // We define date_start and date_end, only if we did not submit the form
138 $date_start = dol_get_first_day((int) $pastmonthyear, (int) $pastmonth, false);
139 $date_end = dol_get_last_day((int) $pastmonthyear, (int) $pastmonth, false);
140}
141
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,";
147if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
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,";
152} else {
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,";
157}
158if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
159 $sql .= " ppe.accountancy_code_buy,";
160} else {
161 $sql .= " p.accountancy_code_buy,";
162}
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); // Note that $action and $object may have been modified by hook
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";
169if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
170 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
171}
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 ";
176if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
177 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
178}
179$parameters = array();
180$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters); // Note that $action and $object may have been modified by hook
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).")"; // We don't share object for accountancy
185if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
186 $sql .= " AND f.type IN (".FactureFournisseur::TYPE_STANDARD.",".FactureFournisseur::TYPE_REPLACEMENT.",".FactureFournisseur::TYPE_CREDIT_NOTE.",".FactureFournisseur::TYPE_SITUATION.")";
187} else {
189}
190if ($date_start && $date_end) {
191 $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
192}
193// Define begin binding date
194if (getDolGlobalInt('ACCOUNTING_DATE_START_BINDING')) {
195 $sql .= " AND f.datef >= '".$db->idate(getDolGlobalInt('ACCOUNTING_DATE_START_BINDING'))."'";
196}
197// Already in bookkeeping or not
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')";
200}
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')";
203}
204$parameters = array();
205$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
206$sql .= $hookmanager->resPrint;
207$sql .= " ORDER BY f.datef";
208
209dol_syslog('accountancy/journal/purchasesjournal.php', LOG_DEBUG);
210$tabfac = array();
211$tabht = array();
212$tabtva = array();
213$def_tva = array();
214$tabttc = array();
215$tablocaltax1 = array();
216$tablocaltax2 = array();
217$tabcompany = array();
218$tabother = array();
219$tabrctva = array();
220$tabrclocaltax1 = array();
221$tabrclocaltax2 = array();
222$vatdata_cache = array();
223
224// Variables
225$cptfour = getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER', 'NotDefined');
226$cpttva = getDolGlobalString('ACCOUNTING_VAT_BUY_ACCOUNT', 'NotDefined');
227$rcctva = getDolGlobalString('ACCOUNTING_VAT_BUY_REVERSE_CHARGES_CREDIT', 'NotDefined');
228$rcdtva = getDolGlobalString('ACCOUNTING_VAT_BUY_REVERSE_CHARGES_DEBIT', 'NotDefined');
229$cptlocaltax1 = getDolGlobalString('ACCOUNTING_LT1_BUY_ACCOUNT', 'NotDefined');
230$rcclocaltax1 = getDolGlobalString('ACCOUNTING_LT1_BUY_REVERSE_CHARGES_CREDIT', 'NotDefined');
231$rcdlocaltax1 = getDolGlobalString('ACCOUNTING_LT1_BUY_REVERSE_CHARGES_DEBIT', 'NotDefined');
232$cptlocaltax2 = getDolGlobalString('ACCOUNTING_LT2_BUY_ACCOUNT', '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'); //If enabled, Tax will NOT get split off from the base entry and credited to a separate tax account (good for non-VAT countries like USA)
236$country_code_in_EEC = getCountriesInEEC(); // This make a database call but there is a cache done into $conf->cache['country_code_in_EEC']
237
238$result = $db->query($sql);
239if ($result) {
240 $num = $db->num_rows($result);
241
242 $i = 0;
243 while ($i < $num) {
244 $obj = $db->fetch_object($result);
245
246 // Controls
247 $accountancy_code_supplier_general = (!empty($obj->accountancy_code_supplier_general)) ? $obj->accountancy_code_supplier_general : $cptfour;
248 $compta_soc = ($obj->code_compta_fournisseur != "") ? $obj->code_compta_fournisseur : $cptfour;
249
250 $compta_prod = $obj->compte;
251 if (empty($compta_prod)) {
252 if ($obj->product_type == 0) {
253 $compta_prod = getDolGlobalString('ACCOUNTING_PRODUCT_BUY_ACCOUNT', 'NotDefined');
254 } else {
255 $compta_prod = getDolGlobalString('ACCOUNTING_SERVICE_BUY_ACCOUNT', 'NotDefined');
256 }
257 }
258
259 $tax_id = $obj->tva_tx . ($obj->vat_src_code ? ' (' . $obj->vat_src_code . ')' : '');
260 if (array_key_exists($tax_id, $vatdata_cache)) {
261 $vatdata = $vatdata_cache[$tax_id];
262 } else {
263 $vatdata = getTaxesFromId($tax_id, $mysoc, $mysoc, 0);
264 $vatdata_cache[$tax_id] = $vatdata;
265 }
266 $compta_tva = (!empty($vatdata['accountancy_code_buy']) ? $vatdata['accountancy_code_buy'] : $cpttva);
267 $compta_localtax1 = (!empty($vatdata['accountancy_code_buy']) ? $vatdata['accountancy_code_buy'] : $cptlocaltax1);
268 $compta_localtax2 = (!empty($vatdata['accountancy_code_buy']) ? $vatdata['accountancy_code_buy'] : $cptlocaltax2);
269 $compta_counterpart_tva_npr = getDolGlobalString('ACCOUNTING_COUNTERPART_VAT_NPR', 'NotDefined');
270
271 // Define an array to display all VAT rates that use this accounting account $compta_tva
272 if (price2num($obj->tva_tx) || !empty($obj->vat_src_code)) {
273 $def_tva[$obj->rowid][$compta_tva][vatrate($obj->tva_tx).($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : '')] = (vatrate($obj->tva_tx).($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''));
274 if ($obj->localtax1_tx > 0.0) {
275 $def_tva[$obj->rowid][$compta_localtax1][vatrate($obj->localtax1_tx).($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : '').' LT1'] = (vatrate($obj->localtax1_tx).($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''));
276 }
277 if ($obj->localtax2_tx > 0.0) {
278 $def_tva[$obj->rowid][$compta_localtax2][vatrate($obj->localtax2_tx).($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : '').' LT2'] = (vatrate($obj->localtax2_tx).($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''));
279 }
280 }
281
282 //$line = new SupplierInvoiceLine($db);
283 //$line->fetch($obj->fdid);
284
285 $tabfac[$obj->rowid]["date"] = $db->jdate($obj->df);
286 $tabfac[$obj->rowid]["datereg"] = $db->jdate($obj->dlr);
287 $tabfac[$obj->rowid]["ref"] = $obj->ref_supplier.' ('.$obj->ref.')';
288 $tabfac[$obj->rowid]["refsologest"] = $obj->ref;
289 $tabfac[$obj->rowid]["refsuppliersologest"] = $obj->ref_supplier;
290 $tabfac[$obj->rowid]["type"] = $obj->type;
291 $tabfac[$obj->rowid]["description"] = $obj->description;
292 $tabfac[$obj->rowid]["close_code"] = $obj->close_code; // close_code = 'replaced' for replacement invoices (not used in most european countries)
293 //$tabfac[$obj->rowid]["fk_facturefourndet"] = $obj->fdid;
294
295 // Avoid warnings
296 if (!isset($tabttc[$obj->rowid][$compta_soc])) {
297 $tabttc[$obj->rowid][$compta_soc] = 0;
298 }
299 if (!isset($tabht[$obj->rowid][$compta_prod])) {
300 $tabht[$obj->rowid][$compta_prod] = 0;
301 }
302 if (!isset($tabtva[$obj->rowid][$compta_tva])) {
303 $tabtva[$obj->rowid][$compta_tva] = 0;
304 }
305 if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
306 $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
307 }
308 if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
309 $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
310 }
311
312 // VAT Reverse charge
313 if (($mysoc->country_code == 'FR' || getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) && $obj->vat_reverse_charge == 1 && (in_array($obj->country_code, $country_code_in_EEC) || getDolGlobalString('ACCOUNTING_REVERSE_CHARGE_ALSO_NON_EEC'))) {
314 $rcvatdata = getTaxesFromId($obj->product_buy_vat . ($obj->product_buy_default_vat_code ? ' (' . $obj->product_buy_default_vat_code . ')' : ''), $mysoc, $mysoc, 0);
315 $rcc_compta_tva = (!empty($vatdata['accountancy_code_vat_reverse_charge_credit']) ? $vatdata['accountancy_code_vat_reverse_charge_credit'] : $rcctva);
316 $rcd_compta_tva = (!empty($vatdata['accountancy_code_vat_reverse_charge_debit']) ? $vatdata['accountancy_code_vat_reverse_charge_debit'] : $rcdtva);
317 $rcc_compta_localtax1 = (!empty($vatdata['accountancy_code_vat_reverse_charge_credit']) ? $vatdata['accountancy_code_vat_reverse_charge_credit'] : $rcclocaltax1);
318 $rcd_compta_localtax1 = (!empty($vatdata['accountancy_code_vat_reverse_charge_debit']) ? $vatdata['accountancy_code_vat_reverse_charge_debit'] : $rcdlocaltax1);
319 $rcc_compta_localtax2 = (!empty($vatdata['accountancy_code_vat_reverse_charge_credit']) ? $vatdata['accountancy_code_vat_reverse_charge_credit'] : $rcclocaltax2);
320 $rcd_compta_localtax2 = (!empty($vatdata['accountancy_code_vat_reverse_charge_debit']) ? $vatdata['accountancy_code_vat_reverse_charge_debit'] : $rcdlocaltax2);
321 if (price2num($obj->product_buy_vat) || !empty($obj->product_buy_default_vat_code)) {
322 $vat_key = vatrate($obj->product_buy_vat) . ($obj->product_buy_default_vat_code ? ' (' . $obj->product_buy_default_vat_code . ')' : '');
323 $val_value = $vat_key;
324 $def_tva[$obj->rowid][$rcc_compta_tva][$vat_key] = $val_value;
325 $def_tva[$obj->rowid][$rcd_compta_tva][$vat_key] = $val_value;
326 }
327
328 if (!isset($tabrctva[$obj->rowid][$rcc_compta_tva])) {
329 $tabrctva[$obj->rowid][$rcc_compta_tva] = 0;
330 }
331 if (!isset($tabrctva[$obj->rowid][$rcd_compta_tva])) {
332 $tabrctva[$obj->rowid][$rcd_compta_tva] = 0;
333 }
334 if (!isset($tabrclocaltax1[$obj->rowid][$rcc_compta_localtax1])) {
335 $tabrclocaltax1[$obj->rowid][$rcc_compta_localtax1] = 0;
336 }
337 if (!isset($tabrclocaltax1[$obj->rowid][$rcd_compta_localtax1])) {
338 $tabrclocaltax1[$obj->rowid][$rcd_compta_localtax1] = 0;
339 }
340 if (!isset($tabrclocaltax2[$obj->rowid][$rcc_compta_localtax2])) {
341 $tabrclocaltax2[$obj->rowid][$rcc_compta_localtax2] = 0;
342 }
343 if (!isset($tabrclocaltax2[$obj->rowid][$rcd_compta_localtax2])) {
344 $tabrclocaltax2[$obj->rowid][$rcd_compta_localtax2] = 0;
345 }
346
347 $rcvat = (float) price2num($obj->total_ttc * $obj->product_buy_vat / 100, 'MT');
348 $rclocalvat1 = (float) price2num($obj->total_ttc * $obj->product_buy_localvat1 / 100, 'MT');
349 $rclocalvat2 = (float) price2num($obj->total_ttc * $obj->product_buy_localvat2 / 100, 'MT');
350
351 $tabrctva[$obj->rowid][$rcd_compta_tva] += $rcvat;
352 $tabrctva[$obj->rowid][$rcc_compta_tva] -= $rcvat;
353 $tabrclocaltax1[$obj->rowid][$rcd_compta_localtax1] += $rclocalvat1;
354 $tabrclocaltax1[$obj->rowid][$rcc_compta_localtax1] -= $rclocalvat1;
355 $tabrclocaltax2[$obj->rowid][$rcd_compta_localtax2] += $rclocalvat2;
356 $tabrclocaltax2[$obj->rowid][$rcc_compta_localtax2] -= $rclocalvat2;
357 }
358
359 $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc;
360
361 if ($noTaxDispatchingKeepWithLines) { //case where all taxes paid should be grouped with the same account as the main expense (best for USA)
362 $tabht[$obj->rowid][$compta_prod] += $obj->total_ttc;
363 } else { //case where every tax paid should be broken out into its own account for future recovery (best for VAT countries)
364 $tabht[$obj->rowid][$compta_prod] += $obj->total_ht;
365 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
366 $tva_npr = ((($obj->info_bits & 1) == 1) ? 1 : 0);
367 if ($tva_npr) { // If NPR, we add an entry for counterpartWe into tabother
368 $tabother[$obj->rowid][$compta_counterpart_tva_npr] += $obj->total_tva;
369 }
370 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
371 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
372 }
373 $tabcompany[$obj->rowid] = array(
374 'id' => $obj->socid,
375 'name' => $obj->name,
376 'code_fournisseur' => $obj->code_fournisseur,
377 'accountancy_code_supplier_general' => $accountancy_code_supplier_general,
378 'code_compta_fournisseur' => $compta_soc
379 );
380
381 $i++;
382
383 // Check for too many lines.
384 if ($i > getDolGlobalInt('ACCOUNTANCY_MAX_TOO_MANY_LINES_TO_PROCESS', 10000)) {
385 $error++;
386 setEventMessages("ErrorTooManyLinesToProcessPleaseUseAMoreSelectiveFilter", null, 'errors');
387 break;
388 }
389 }
390} else {
391 dol_print_error($db);
392}
393
394$errorforinvoice = array();
395
396/*
397// Old way, 1 query for each invoice
398// Loop in invoices to detect lines with not binding lines
399foreach ($tabfac as $key => $val) { // Loop on each invoice
400 $sql = "SELECT COUNT(fd.rowid) as nb";
401 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn_det as fd";
402 $sql .= " WHERE fd.product_type <= 2 AND fd.fk_code_ventilation <= 0";
403 $sql .= " AND fd.total_ttc <> 0 AND fk_facture_fourn = ".((int) $key);
404 $resql = $db->query($sql);
405 if ($resql) {
406 $obj = $db->fetch_object($resql);
407 if ($obj->nb > 0) {
408 $errorforinvoice[$key] = 'somelinesarenotbound';
409 }
410 } else {
411 dol_print_error($db);
412 }
413}
414*/
415
416// New way, single query, load all unbound lines
417if (!empty($tabfac)) {
418 $sql = "
419 SELECT
420 fk_facture_fourn,
421 COUNT(fd.rowid) as nb
422 FROM
423 " . MAIN_DB_PREFIX . "facture_fourn_det as fd
424 WHERE
425 fd.product_type <= 2
426 AND fd.fk_code_ventilation <= 0
427 AND fd.total_ttc <> 0
428 AND fk_facture_fourn IN (".$db->sanitize(implode(",", array_keys($tabfac))).")
429 GROUP BY fk_facture_fourn
430 ";
431 $resql = $db->query($sql);
432
433 $num = $db->num_rows($resql);
434 $i = 0;
435 while ($i < $num) {
436 $obj = $db->fetch_object($resql);
437 if ($obj->nb > 0) {
438 $errorforinvoice[$obj->fk_facture_fourn] = 'somelinesarenotbound';
439 }
440 $i++;
441 }
442}
443
444// Bookkeeping Write
445if ($action == 'writebookkeeping' && !$error && $user->hasRight('accounting', 'bind', 'write')) {
446 $now = dol_now();
447 $error = 0;
448
449 $companystatic = new Societe($db);
450 $invoicestatic = new FactureFournisseur($db);
451 $accountingaccountsupplier = new AccountingAccount($db);
452 $bookkeepingstatic = new BookKeeping($db);
453
454 $accountingaccountsupplier->fetch(0, getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER'), true);
455
456 foreach ($tabfac as $key => $val) { // Loop on each invoice
457 $errorforline = 0;
458
459 $totalcredit = 0;
460 $totaldebit = 0;
461
462 $db->begin(); // We accept transaction into loop, so if we hang, we can continue transfer from the last error
463
464 $companystatic->id = $tabcompany[$key]['id'];
465 $companystatic->name = $tabcompany[$key]['name'];
466 $companystatic->accountancy_code_supplier_general = $tabcompany[$key]['accountancy_code_supplier_general'];
467 $companystatic->code_compta_fournisseur = $tabcompany[$key]['code_compta_fournisseur'];
468 $companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur'];
469 $companystatic->fournisseur = 1;
470
471 $invoicestatic->id = $key;
472 $invoicestatic->ref = (string) $val["refsologest"];
473 $invoicestatic->ref_supplier = $val["refsuppliersologest"];
474 $invoicestatic->type = $val["type"];
475 $invoicestatic->description = html_entity_decode(dol_trunc($val["description"], 32));
476 $invoicestatic->close_code = $val["close_code"];
477
478 $date = dol_print_date($val["date"], 'day');
479
480 // Is it a replaced invoice? 0=not a replaced invoice, 1=replaced invoice not yet dispatched, 2=replaced invoice dispatched
481 $replacedinvoice = 0;
482 if ($invoicestatic->close_code == FactureFournisseur::CLOSECODE_REPLACED) {
483 $replacedinvoice = 1;
484 $alreadydispatched = $invoicestatic->getVentilExportCompta(); // Test if replaced invoice already into bookkeeping.
485 if ($alreadydispatched) {
486 $replacedinvoice = 2;
487 }
488 }
489
490 // If not already into bookkeeping, we won't add it. If yes, do nothing (should not happen because creating replacement not possible if invoice is accounted)
491 if ($replacedinvoice == 1) {
492 $db->rollback();
493 continue;
494 }
495
496 // Error if some lines are not binded/ready to be journalized
497 if (isset($errorforinvoice[$key]) && $errorforinvoice[$key] == 'somelinesarenotbound') {
498 $error++;
499 $errorforline++;
500 setEventMessages($langs->trans('ErrorInvoiceContainsLinesNotYetBounded', $val['ref']), null, 'errors');
501 }
502
503 // Thirdparty
504 if (!$errorforline) {
505 foreach ($tabttc[$key] as $k => $mt) {
506 $bookkeeping = new BookKeeping($db);
507 $bookkeeping->doc_date = $val["date"];
508 $bookkeeping->date_lim_reglement = $val["datereg"];
509 $bookkeeping->doc_ref = $val["refsologest"];
510 $bookkeeping->date_creation = $now;
511 $bookkeeping->doc_type = 'supplier_invoice';
512 $bookkeeping->fk_doc = $key;
513 $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
514 $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
515
516 $bookkeeping->subledger_account = $tabcompany[$key]['code_compta_fournisseur'];
517 $bookkeeping->subledger_label = $tabcompany[$key]['name'];
518
519 $bookkeeping->numero_compte = $tabcompany[$key]['accountancy_code_supplier_general'];
520 $bookkeeping->label_compte = $accountingaccountsupplier->label;
521
522 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref_supplier, $langs->trans("SubledgerAccount"));
523 $bookkeeping->montant = $mt;
524 $bookkeeping->sens = ($mt >= 0) ? 'C' : 'D';
525 $bookkeeping->debit = ($mt <= 0) ? -$mt : 0;
526 $bookkeeping->credit = ($mt > 0) ? $mt : 0;
527 $bookkeeping->code_journal = $journal;
528 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
529 $bookkeeping->fk_user_author = $user->id;
530 $bookkeeping->entity = $conf->entity;
531
532 $totaldebit += $bookkeeping->debit;
533 $totalcredit += $bookkeeping->credit;
534
535 $result = $bookkeeping->create($user);
536 if ($result < 0) {
537 if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists
538 $error++;
539 $errorforline++;
540 $errorforinvoice[$key] = 'alreadyjournalized';
541 //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
542 } else {
543 $error++;
544 $errorforline++;
545 $errorforinvoice[$key] = 'other';
546 setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
547 }
548 } else {
549 if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && getDolGlobalInt('ACCOUNTING_ENABLE_AUTOLETTERING')) {
550 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/lettering.class.php';
551 $lettering_static = new Lettering($db);
552
553 $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id));
554 }
555 }
556 }
557 }
558
559 // Product / Service
560 if (!$errorforline) {
561 foreach ($tabht[$key] as $k => $mt) {
562 if (empty($conf->cache['accountingaccountincurrententity'][$k])) {
563 $accountingaccount = new AccountingAccount($db);
564 $accountingaccount->fetch(0, $k, true);
565 $conf->cache['accountingaccountincurrententity'][$k] = $accountingaccount;
566 } else {
567 $accountingaccount = $conf->cache['accountingaccountincurrententity'][$k];
568 }
569
570 $label_account = $accountingaccount->label;
571
572 // get compte id and label
573 if ($accountingaccount->id > 0) {
574 $bookkeeping = new BookKeeping($db);
575 $bookkeeping->doc_date = $val["date"];
576 $bookkeeping->date_lim_reglement = $val["datereg"];
577 $bookkeeping->doc_ref = $val["refsologest"];
578 $bookkeeping->date_creation = $now;
579 $bookkeeping->doc_type = 'supplier_invoice';
580 $bookkeeping->fk_doc = $key;
581 $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
582 $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
583
584 if (getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT')) {
585 if ($k == getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT')) {
586 $bookkeeping->subledger_account = $tabcompany[$key]['code_compta_fournisseur'];
587 $bookkeeping->subledger_label = $tabcompany[$key]['name'];
588 } else {
589 $bookkeeping->subledger_account = '';
590 $bookkeeping->subledger_label = '';
591 }
592 } else {
593 $bookkeeping->subledger_account = '';
594 $bookkeeping->subledger_label = '';
595 }
596
597 $bookkeeping->numero_compte = $k;
598 $bookkeeping->label_compte = $label_account;
599
600 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref_supplier, $label_account);
601 $bookkeeping->montant = $mt;
602 $bookkeeping->sens = ($mt < 0) ? 'C' : 'D';
603 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
604 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
605 $bookkeeping->code_journal = $journal;
606 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
607 $bookkeeping->fk_user_author = $user->id;
608 $bookkeeping->entity = $conf->entity;
609
610 $totaldebit += $bookkeeping->debit;
611 $totalcredit += $bookkeeping->credit;
612
613 $result = $bookkeeping->create($user);
614 if ($result < 0) {
615 if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists
616 $error++;
617 $errorforline++;
618 $errorforinvoice[$key] = 'alreadyjournalized';
619 //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
620 } else {
621 $error++;
622 $errorforline++;
623 $errorforinvoice[$key] = 'other';
624 setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
625 }
626 }
627 }
628 }
629 }
630
631 // VAT
632 // var_dump($tabtva);
633 if (!$errorforline) {
634 $listoftax = array(0, 1, 2);
635 foreach ($listoftax as $numtax) {
636 $arrayofvat = $tabtva;
637 if ($numtax == 1) {
638 $arrayofvat = $tablocaltax1;
639 }
640 if ($numtax == 2) {
641 $arrayofvat = $tablocaltax2;
642 }
643
644 // VAT Reverse charge
645 if ($mysoc->country_code == 'FR' || getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) {
646 $has_vat = false;
647 foreach ($arrayofvat[$key] as $k => $mt) {
648 if ($mt) {
649 $has_vat = true;
650 }
651 }
652
653 if (!$has_vat) {
654 $arrayofvat = $tabrctva;
655 if ($numtax == 1) {
656 $arrayofvat = $tabrclocaltax1;
657 }
658 if ($numtax == 2) {
659 $arrayofvat = $tabrclocaltax2;
660 }
661 if (!isset($arrayofvat[$key]) || !is_array($arrayofvat[$key])) {
662 $arrayofvat[$key] = array();
663 }
664 }
665 }
666
667 foreach ($arrayofvat[$key] as $k => $mt) {
668 if ($mt) {
669 if (empty($conf->cache['accountingaccountincurrententity_vat'][$k])) {
670 $accountingaccount = new AccountingAccount($db);
671 $accountingaccount->fetch(0, $k, true);
672 $conf->cache['accountingaccountincurrententity_vat'][$k] = $accountingaccount;
673 } else {
674 $accountingaccount = $conf->cache['accountingaccountincurrententity_vat'][$k];
675 }
676
677 $label_account = $accountingaccount->label;
678
679 $bookkeeping = new BookKeeping($db);
680 $bookkeeping->doc_date = $val["date"];
681 $bookkeeping->date_lim_reglement = $val["datereg"];
682 $bookkeeping->doc_ref = $val["refsologest"];
683 $bookkeeping->date_creation = $now;
684 $bookkeeping->doc_type = 'supplier_invoice';
685 $bookkeeping->fk_doc = $key;
686 $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
687 $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
688
689 $bookkeeping->subledger_account = '';
690 $bookkeeping->subledger_label = '';
691
692 $bookkeeping->numero_compte = $k;
693 $bookkeeping->label_compte = $label_account;
694
695 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ? '' : $arrayofvat[$key][$k]) : implode(', ', $def_tva[$key][$k]));
696 $labelvataccount = $langs->trans("Taxes").' '.$tmpvatrate.' %';
697 $labelvataccount .= ($numtax ? ' - Localtax '.$numtax : '');
698 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref_supplier, $labelvataccount);
699
700 $bookkeeping->montant = $mt;
701 $bookkeeping->sens = ($mt < 0) ? 'C' : 'D';
702 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
703 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
704 $bookkeeping->code_journal = $journal;
705 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
706 $bookkeeping->fk_user_author = $user->id;
707 $bookkeeping->entity = $conf->entity;
708
709 $totaldebit += $bookkeeping->debit;
710 $totalcredit += $bookkeeping->credit;
711
712 $result = $bookkeeping->create($user);
713 if ($result < 0) {
714 if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists
715 $error++;
716 $errorforline++;
717 $errorforinvoice[$key] = 'alreadyjournalized';
718 //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
719 } else {
720 $error++;
721 $errorforline++;
722 $errorforinvoice[$key] = 'other';
723 setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
724 }
725 }
726 }
727 }
728 }
729 }
730
731 // Counterpart of VAT for VAT NPR
732 // var_dump($tabother);
733 if (!$errorforline && isset($tabother[$key]) && is_array($tabother[$key])) {
734 foreach ($tabother[$key] as $k => $mt) {
735 if ($mt) {
736 $bookkeeping = new BookKeeping($db);
737 $bookkeeping->doc_date = $val["date"];
738 $bookkeeping->date_lim_reglement = $val["datereg"];
739 $bookkeeping->doc_ref = $val["refsologest"];
740 $bookkeeping->date_creation = $now;
741 $bookkeeping->doc_type = 'supplier_invoice';
742 $bookkeeping->fk_doc = $key;
743 $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
744 $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
745
746 $bookkeeping->subledger_account = '';
747 $bookkeeping->subledger_label = '';
748
749 $bookkeeping->numero_compte = $k;
750
751 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref_supplier, $langs->trans("VAT").' NPR');
752 $bookkeeping->montant = $mt;
753 $bookkeeping->sens = ($mt < 0) ? 'C' : 'D';
754 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
755 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
756 $bookkeeping->code_journal = $journal;
757 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
758 $bookkeeping->fk_user_author = $user->id;
759 $bookkeeping->entity = $conf->entity;
760
761 $totaldebit += $bookkeeping->debit;
762 $totalcredit += $bookkeeping->credit;
763
764 $result = $bookkeeping->create($user);
765 if ($result < 0) {
766 if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists
767 $error++;
768 $errorforline++;
769 $errorforinvoice[$key] = 'alreadyjournalized';
770 //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
771 } else {
772 $error++;
773 $errorforline++;
774 $errorforinvoice[$key] = 'other';
775 setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
776 }
777 }
778 }
779 }
780 }
781
782 // Protection against a bug on lines before
783 if (!$errorforline && (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT'))) {
784 $error++;
785 $errorforline++;
786 $errorforinvoice[$key] = 'amountsnotbalanced';
787 setEventMessages('We tried to insert a non balanced transaction in book for '.$invoicestatic->ref.'. Canceled. Surely a bug.', null, 'errors');
788 }
789
790 if (!$errorforline) {
791 $db->commit();
792 } else {
793 $db->rollback();
794
795 if ($error >= 10) {
796 setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped"), null, 'errors');
797 break; // Break in the foreach
798 }
799 }
800 }
801
802 $tabpay = $tabfac;
803
804 if (empty($error) && count($tabpay) > 0) {
805 setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
806 } elseif (count($tabpay) == $error) {
807 setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings');
808 } else {
809 setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings');
810 }
811
812 $action = '';
813
814 // Must reload data, so we make a redirect
815 if (count($tabpay) != $error) {
816 $param = 'id_journal='.$id_journal;
817 $param .= '&date_startday='.$date_startday;
818 $param .= '&date_startmonth='.$date_startmonth;
819 $param .= '&date_startyear='.$date_startyear;
820 $param .= '&date_endday='.$date_endday;
821 $param .= '&date_endmonth='.$date_endmonth;
822 $param .= '&date_endyear='.$date_endyear;
823 $param .= '&in_bookkeeping='.$in_bookkeeping;
824 header("Location: ".$_SERVER['PHP_SELF'].($param ? '?'.$param : ''));
825 exit;
826 }
827}
828
829/*
830 * View
831 */
832
833$form = new Form($db);
834
835// Export
836if ($action == 'exportcsv' && !$error) { // ISO and not UTF8 !
837 $sep = getDolGlobalString('ACCOUNTING_EXPORT_SEPARATORCSV');
838
839 $filename = 'journal';
840 $type_export = 'journal';
841 include DOL_DOCUMENT_ROOT.'/accountancy/tpl/export_journal.tpl.php';
842
843 $companystatic = new Fournisseur($db);
844 $invoicestatic = new FactureFournisseur($db);
845 $bookkeepingstatic = new BookKeeping($db);
846
847 foreach ($tabfac as $key => $val) {
848 $companystatic->id = $tabcompany[$key]['id'];
849 $companystatic->name = $tabcompany[$key]['name'];
850 $companystatic->accountancy_code_supplier_general = !empty($tabcompany[$key]['accountancy_code_supplier_general']) ? $tabcompany[$key]['accountancy_code_supplier_general'] : $cptfour;
851 $companystatic->code_compta_fournisseur = $tabcompany[$key]['code_compta_fournisseur'];
852 $companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur'];
853 $companystatic->fournisseur = 1;
854
855 $invoicestatic->id = $key;
856 $invoicestatic->ref = $val["refsologest"];
857 $invoicestatic->ref_supplier = $val["refsuppliersologest"];
858 $invoicestatic->type = $val["type"];
859 $invoicestatic->description = dol_trunc(html_entity_decode($val["description"]), 32);
860 $invoicestatic->close_code = $val["close_code"];
861
862 $date = dol_print_date($val["date"], 'day');
863
864 // Is it a replaced invoice? 0=not a replaced invoice, 1=replaced invoice not yet dispatched, 2=replaced invoice dispatched
865 $replacedinvoice = 0;
866 if ($invoicestatic->close_code == FactureFournisseur::CLOSECODE_REPLACED) {
867 $replacedinvoice = 1;
868 $alreadydispatched = $invoicestatic->getVentilExportCompta(); // Test if replaced invoice already into bookkeeping.
869 if ($alreadydispatched) {
870 $replacedinvoice = 2;
871 }
872 }
873
874 // If not already into bookkeeping, we won't add it. If yes, do nothing (should not happen because creating replacement not possible if invoice is accounted)
875 if ($replacedinvoice == 1) {
876 continue;
877 }
878
879 // Third party
880 foreach ($tabttc[$key] as $k => $mt) {
881 //if ($mt) {
882 print '"'.$key.'"'.$sep;
883 print '"'.$date.'"'.$sep;
884 print '"'.$val["refsologest"].'"'.$sep;
885 print '"'.csvClean(dol_trunc($companystatic->name, 32)).'"'.$sep;
886 print '"'.length_accounta(html_entity_decode($k)).'"'.$sep;
887 print '"'.length_accountg($companystatic->accountancy_code_supplier_general).'"'.$sep;
888 print '"'.length_accounta(html_entity_decode($k)).'"'.$sep;
889 print '"'.$langs->trans("ThirdParty").'"'.$sep;
890 print '"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $val["refsuppliersologest"], $langs->trans("ThirdParty"))).'"'.$sep;
891 print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
892 print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
893 print '"'.$journal.'"';
894 print "\n";
895 //}
896 }
897
898 // Product / Service
899 foreach ($tabht[$key] as $k => $mt) {
900 $accountingaccount = new AccountingAccount($db);
901 $accountingaccount->fetch(0, $k, true);
902 //if ($mt) {
903 print '"'.$key.'"'.$sep;
904 print '"'.$date.'"'.$sep;
905 print '"'.$val["refsologest"].'"'.$sep;
906 print '"'.csvClean(dol_trunc($companystatic->name, 32)).'"'.$sep;
907 print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
908 print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
909 print '""'.$sep;
910 print '"'.csvClean(dol_trunc($accountingaccount->label, 32)).'"'.$sep;
911 print '"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $val["refsuppliersologest"], $accountingaccount->label)).'"'.$sep;
912 print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
913 print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
914 print '"'.$journal.'"';
915 print "\n";
916 //}
917 }
918
919 // VAT
920 $listoftax = array(0, 1, 2);
921 foreach ($listoftax as $numtax) {
922 $arrayofvat = $tabtva;
923 if ($numtax == 1) {
924 $arrayofvat = $tablocaltax1;
925 }
926 if ($numtax == 2) {
927 $arrayofvat = $tablocaltax2;
928 }
929
930 // VAT Reverse charge
931 if ($mysoc->country_code == 'FR' || getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) {
932 $has_vat = false;
933 foreach ($arrayofvat[$key] as $k => $mt) {
934 if ($mt) {
935 $has_vat = true;
936 }
937 }
938
939 if (!$has_vat) {
940 $arrayofvat = $tabrctva;
941 if ($numtax == 1) {
942 $arrayofvat = $tabrclocaltax1;
943 }
944 if ($numtax == 2) {
945 $arrayofvat = $tabrclocaltax2;
946 }
947 if (!isset($arrayofvat[$key]) || !is_array($arrayofvat[$key])) {
948 $arrayofvat[$key] = array();
949 }
950 }
951 }
952
953 foreach ($arrayofvat[$key] as $k => $mt) {
954 if ($mt) {
955 print '"'.$key.'"'.$sep;
956 print '"'.$date.'"'.$sep;
957 print '"'.$val["refsologest"].'"'.$sep;
958 print '"'.csvClean(dol_trunc($companystatic->name, 32)).'"'.$sep;
959 print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
960 print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
961 print '""'.$sep;
962 print '"'.$langs->trans("VAT").' - '.implode(', ', $def_tva[$key][$k]).' %"'.$sep;
963 print '"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $val["refsuppliersologest"], $langs->trans("VAT").implode($def_tva[$key][$k]).' %'.($numtax ? ' - Localtax '.$numtax : ''))).'"'.$sep;
964 print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
965 print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
966 print '"'.$journal.'"';
967 print "\n";
968 }
969 }
970
971 // VAT counterpart for NPR
972 if (isset($tabother[$key]) && is_array($tabother[$key])) {
973 foreach ($tabother[$key] as $k => $mt) {
974 if ($mt) {
975 print '"'.$key.'"'.$sep;
976 print '"'.$date.'"'.$sep;
977 print '"'.$val["refsologest"].'"'.$sep;
978 print '"'.csvClean(dol_trunc($companystatic->name, 32)).'"'.$sep;
979 print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
980 print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
981 print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
982 print '"'.$langs->trans("ThirdParty").'"'.$sep;
983 print '"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $val["refsuppliersologest"], $langs->trans("VAT").' NPR')).'"'.$sep;
984 print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
985 print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
986 print '"'.$journal.'"';
987 print "\n";
988 }
989 }
990 }
991 }
992 }
993}
994
995if (empty($action) || $action == 'view') {
996 $title = $langs->trans("GenerationOfAccountingEntries").' - '.$accountingjournalstatic->getNomUrl(0, 2, 1, '', 1);
997 $help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilit&eacute;_en_Partie_Double#G&eacute;n&eacute;ration_des_&eacute;critures_en_comptabilit&eacute;';
998 llxHeader('', dol_string_nohtmltag($title), $help_url, '', 0, 0, '', '', '', 'mod-accountancy accountancy-generation page-purchasesjournal');
999
1000 $nom = $title;
1001 $nomlink = '';
1002 $periodlink = '';
1003 $exportlink = '';
1004 $builddate = dol_now();
1005 $description = $langs->trans("DescJournalOnlyBindedVisible").'<br>';
1006 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
1007 $description .= $langs->trans("DepositsAreNotIncluded");
1008 } else {
1009 $description .= $langs->trans("DepositsAreIncluded");
1010 }
1011
1012 $listofchoices = array('notyet' => $langs->trans("NotYetInGeneralLedger"), 'already' => $langs->trans("AlreadyInGeneralLedger"));
1013 $period = $form->selectDate($date_start ? $date_start : -1, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end ? $date_end : -1, 'date_end', 0, 0, 0, '', 1, 0);
1014 $period .= ' - '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
1015
1016 $varlink = 'id_journal='.$id_journal;
1017
1018 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink);
1019
1020 if (getDolGlobalString('ACCOUNTANCY_FISCAL_PERIOD_MODE') != 'blockedonclosed') {
1021 // Test that setup is complete (we are in accounting, so test on entity is always on $conf->entity only, no sharing allowed)
1022 // Fiscal period test
1023 $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_fiscalyear WHERE entity = ".((int) $conf->entity);
1024 $resql = $db->query($sql);
1025 if ($resql) {
1026 $obj = $db->fetch_object($resql);
1027 if ($obj->nb == 0) {
1028 print '<br><div class="warning">'.img_warning().' '.$langs->trans("TheFiscalPeriodIsNotDefined");
1029 $desc = ' : '.$langs->trans("AccountancyAreaDescFiscalPeriod", 4, '{link}');
1030 $desc = str_replace('{link}', '<strong>'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("FiscalPeriod").'</strong>', $desc);
1031 print $desc;
1032 print '</div>';
1033 }
1034 } else {
1035 dol_print_error($db);
1036 }
1037 }
1038
1039 // Button to write into Ledger
1040 $acctSupplierNotConfigured = in_array(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER'), ['','-1']);
1041 if ($acctSupplierNotConfigured) {
1042 print '<br><div class="warning">'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone");
1043 $desc = ' : '.$langs->trans("AccountancyAreaDescMisc", 4, '{link}');
1044 $desc = str_replace('{link}', '<strong>'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'</strong>', $desc);
1045 print $desc;
1046 print '</div>';
1047 }
1048 print '<br><div class="tabsAction tabsActionNoBottom centerimp">';
1049 if (getDolGlobalString('ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping == 'notyet') {
1050 print '<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans("ExportDraftJournal").'" onclick="launch_export();" />';
1051 }
1052 if ($acctSupplierNotConfigured) {
1053 print '<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("SomeMandatoryStepsOfSetupWereNotDone")).'" value="'.$langs->trans("WriteBookKeeping").'" />';
1054 } else {
1055 if ($in_bookkeeping == 'notyet') {
1056 print '<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans("WriteBookKeeping").'" onclick="writebookkeeping();" />';
1057 } else {
1058 print '<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans("WriteBookKeeping").'</a>';
1059 }
1060 }
1061 print '</div>';
1062
1063 // TODO Avoid using js. We can use a direct link with $param
1064 print '
1065 <script type="text/javascript">
1066 function launch_export() {
1067 $("div.fiche form input[name=\"action\"]").val("exportcsv");
1068 $("div.fiche form input[type=\"submit\"]").click();
1069 $("div.fiche form input[name=\"action\"]").val("");
1070 }
1071 function writebookkeeping() {
1072 console.log("click on writebookkeeping");
1073 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
1074 $("div.fiche form input[type=\"submit\"]").click();
1075 $("div.fiche form input[name=\"action\"]").val("");
1076 }
1077 </script>';
1078
1079 /*
1080 * Show result array
1081 */
1082 print '<br>';
1083
1084 print '<div class="div-table-responsive">';
1085 print "<table class=\"noborder\" width=\"100%\">";
1086 print "<tr class=\"liste_titre\">";
1087 print "<td>".$langs->trans("Date")."</td>";
1088 print "<td>".$langs->trans("Piece").' ('.$langs->trans("InvoiceRef").")</td>";
1089 print "<td>".$langs->trans("AccountAccounting")."</td>";
1090 print "<td>".$langs->trans("SubledgerAccount")."</td>";
1091 print "<td>".$langs->trans("LabelOperation")."</td>";
1092 print '<td class="center">'.$langs->trans("AccountingDebit")."</td>";
1093 print '<td class="center">'.$langs->trans("AccountingCredit")."</td>";
1094 print "</tr>\n";
1095
1096 $i = 0;
1097
1098 $invoicestatic = new FactureFournisseur($db);
1099 $companystatic = new Fournisseur($db);
1100 $bookkeepingstatic = new BookKeeping($db);
1101
1102 foreach ($tabfac as $key => $val) {
1103 $companystatic->id = $tabcompany[$key]['id'];
1104 $companystatic->name = $tabcompany[$key]['name'];
1105 $companystatic->accountancy_code_supplier_general = !empty($tabcompany[$key]['accountancy_code_supplier_general']) ? $tabcompany[$key]['accountancy_code_supplier_general'] : $cptfour;
1106 $companystatic->code_compta_fournisseur = $tabcompany[$key]['code_compta_fournisseur'];
1107 $companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur'];
1108 $companystatic->fournisseur = 1;
1109
1110 $invoicestatic->id = $key;
1111 $invoicestatic->ref = $val["refsologest"];
1112 $invoicestatic->ref_supplier = $val["refsuppliersologest"];
1113 $invoicestatic->type = $val["type"];
1114 $invoicestatic->description = dol_trunc(html_entity_decode($val["description"]), 32);
1115 $invoicestatic->close_code = $val["close_code"];
1116
1117 $date = dol_print_date($val["date"], 'day');
1118
1119 // Is it a replaced invoice? 0=not a replaced invoice, 1=replaced invoice not yet dispatched, 2=replaced invoice dispatched
1120 $replacedinvoice = 0;
1121 if ($invoicestatic->close_code == FactureFournisseur::CLOSECODE_REPLACED) {
1122 $replacedinvoice = 1;
1123 $alreadydispatched = $invoicestatic->getVentilExportCompta(); // Test if replaced invoice already into bookkeeping.
1124 if ($alreadydispatched) {
1125 $replacedinvoice = 2;
1126 }
1127 }
1128
1129 // If not already into bookkeeping, we won't add it, if yes, add the counterpart ???.
1130 if ($replacedinvoice == 1) {
1131 print '<tr class="oddeven">';
1132 print "<!-- Replaced invoice -->";
1133 print "<td>".$date."</td>";
1134 print "<td><strike>".$invoicestatic->getNomUrl(1)."</strike></td>";
1135 // Account
1136 print "<td>";
1137 print $langs->trans("Replaced");
1138 print '</td>';
1139 // Subledger account
1140 print "<td>";
1141 print '</td>';
1142 print "<td>";
1143 print "</td>";
1144 print '<td class="right"></td>';
1145 print '<td class="right"></td>';
1146 print "</tr>";
1147
1148 $i++;
1149 continue;
1150 }
1151 if (isset($errorforinvoice[$key]) && $errorforinvoice[$key] == 'somelinesarenotbound') {
1152 print '<tr class="oddeven">';
1153 print "<!-- Some lines are not bound -->";
1154 print "<td>".$date."</td>";
1155 print "<td>".$invoicestatic->getNomUrl(1)."</td>";
1156 // Account
1157 print "<td>";
1158 print '<span class="error">'.$langs->trans('ErrorInvoiceContainsLinesNotYetBoundedShort', $val['ref']).'</span>';
1159 print '</td>';
1160 // Subledger account
1161 print "<td>";
1162 print '</td>';
1163 print "<td>";
1164 print "</td>";
1165 print '<td class="right"></td>';
1166 print '<td class="right"></td>';
1167 print "</tr>";
1168
1169 $i++;
1170 }
1171
1172 // Third party
1173 foreach ($tabttc[$key] as $k => $mt) {
1174 print '<tr class="oddeven">';
1175 print "<!-- Thirdparty -->";
1176 print "<td>".$date."</td>";
1177 print "<td>".$invoicestatic->getNomUrl(1)."</td>";
1178 // Account
1179 print "<td>";
1180 $accountoshow = length_accountg(!empty($tabcompany[$key]['accountancy_code_supplier_general']) ? $tabcompany[$key]['accountancy_code_supplier_general'] : $cptfour);
1181 if (($accountoshow == "") || $accountoshow == 'NotDefined') {
1182 print '<span class="error">'.$langs->trans("MainAccountForSuppliersNotDefined").'</span>';
1183 } else {
1184 print $accountoshow;
1185 }
1186 print '</td>';
1187 // Subledger account
1188 print "<td>";
1189 $accountoshow = length_accounta($k);
1190 if (($accountoshow == "") || $accountoshow == 'NotDefined') {
1191 print '<span class="error">'.$langs->trans("ThirdpartyAccountNotDefined").'</span>';
1192 } else {
1193 print $accountoshow;
1194 }
1195 print '</td>';
1196 print "<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0, 'supplier'), $invoicestatic->ref_supplier, $langs->trans("SubledgerAccount"), 1) . "</td>";
1197 print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
1198 print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
1199 print "</tr>";
1200
1201 $i++;
1202 }
1203
1204 // Product / Service
1205 foreach ($tabht[$key] as $k => $mt) {
1206 if (empty($conf->cache['accountingaccountincurrententity'][$k])) {
1207 $accountingaccount = new AccountingAccount($db);
1208 $accountingaccount->fetch(0, $k, true);
1209 $conf->cache['accountingaccountincurrententity'][$k] = $accountingaccount;
1210 } else {
1211 $accountingaccount = $conf->cache['accountingaccountincurrententity'][$k];
1212 }
1213
1214 print '<tr class="oddeven">';
1215 print "<!-- Product -->";
1216 print "<td>".$date."</td>";
1217 print "<td>".$invoicestatic->getNomUrl(1)."</td>";
1218 // Account
1219 print "<td>";
1220 $accountoshow = length_accountg($k);
1221 if (($accountoshow == "") || $accountoshow == 'NotDefined') {
1222 print '<span class="error">'.$langs->trans("ProductAccountNotDefined").'</span>';
1223 } else {
1224 print $accountoshow;
1225 }
1226 print "</td>";
1227 // Subledger account
1228 print "<td>";
1229 if (getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT')) {
1230 if ($k == getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT')) {
1231 print length_accounta($tabcompany[$key]['code_compta_fournisseur']);
1232 }
1233 } elseif (($accountoshow == "") || $accountoshow == 'NotDefined') {
1234 print '<span class="error">' . $langs->trans("ThirdpartyAccountNotDefined") . '</span>';
1235 }
1236 print '</td>';
1237 $companystatic->id = $tabcompany[$key]['id'];
1238 $companystatic->name = $tabcompany[$key]['name'];
1239 print "<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0, 'supplier'), $invoicestatic->ref_supplier, $accountingaccount->label, 1) . "</td>";
1240 print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
1241 print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
1242 print "</tr>";
1243
1244 $i++;
1245 }
1246
1247 // VAT
1248 $listoftax = array(0, 1, 2);
1249 foreach ($listoftax as $numtax) {
1250 $arrayofvat = $tabtva;
1251 if ($numtax == 1) {
1252 $arrayofvat = $tablocaltax1;
1253 }
1254 if ($numtax == 2) {
1255 $arrayofvat = $tablocaltax2;
1256 }
1257
1258 // VAT Reverse charge
1259 if ($mysoc->country_code == 'FR' || getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) {
1260 $has_vat = false;
1261 foreach ($arrayofvat[$key] as $k => $mt) {
1262 if ($mt) {
1263 $has_vat = true;
1264 }
1265 }
1266
1267 if (!$has_vat) {
1268 $arrayofvat = $tabrctva;
1269 if ($numtax == 1) {
1270 $arrayofvat = $tabrclocaltax1;
1271 }
1272 if ($numtax == 2) {
1273 $arrayofvat = $tabrclocaltax2;
1274 }
1275 if (!isset($arrayofvat[$key]) || !is_array($arrayofvat[$key])) {
1276 $arrayofvat[$key] = array();
1277 }
1278 }
1279 }
1280
1281 foreach ($arrayofvat[$key] as $k => $mt) {
1282 if ($mt) {
1283 print '<tr class="oddeven">';
1284 print "<!-- VAT -->";
1285 print "<td>".$date."</td>";
1286 print "<td>".$invoicestatic->getNomUrl(1)."</td>";
1287 // Account
1288 print "<td>";
1289 $accountoshow = length_accountg($k);
1290 if (($accountoshow == "") || $accountoshow == 'NotDefined') {
1291 print '<span class="error">'.$langs->trans("VATAccountNotDefined").' ('.$langs->trans("AccountingJournalType3").')</span>';
1292 } else {
1293 print $accountoshow;
1294 }
1295 print "</td>";
1296 // Subledger account
1297 print "<td>";
1298 print '</td>';
1299 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ? '' : $arrayofvat[$key][$k]) : implode(', ', $def_tva[$key][$k]));
1300 $labelvatrate = $langs->trans("Taxes").' '.$tmpvatrate.' %';
1301 $labelvatrate .= ($numtax ? ' - Localtax '.$numtax : '');
1302 print "<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0, 'supplier'), $invoicestatic->ref_supplier, $labelvatrate, 1) . "</td>";
1303 print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
1304 print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
1305 print "</tr>";
1306
1307 $i++;
1308 }
1309 }
1310 }
1311
1312 // VAT counterpart for NPR
1313 if (isset($tabother[$key]) && is_array($tabother[$key])) {
1314 foreach ($tabother[$key] as $k => $mt) {
1315 if ($mt) {
1316 print '<tr class="oddeven">';
1317 print '<!-- VAT counterpart NPR -->';
1318 print "<td>".$date."</td>";
1319 print "<td>".$invoicestatic->getNomUrl(1)."</td>";
1320 // Account
1321 print '<td>';
1322 $accountoshow = length_accountg($k);
1323 if ($accountoshow == '' || $accountoshow == 'NotDefined') {
1324 print '<span class="error">'.$langs->trans("VATAccountNotDefined").' ('.$langs->trans("NPR counterpart").'). Set ACCOUNTING_COUNTERPART_VAT_NPR to the subvention account</span>';
1325 } else {
1326 print $accountoshow;
1327 }
1328 print '</td>';
1329 // Subledger account
1330 print "<td>";
1331 print '</td>';
1332 print "<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0, 'supplier'), $invoicestatic->ref_supplier, $langs->trans("VAT")." NPR (counterpart)", 1) . "</td>";
1333 print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
1334 print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
1335 print "</tr>";
1336
1337 $i++;
1338 }
1339 }
1340 }
1341 }
1342
1343 if (!$i) {
1344 print '<tr class="oddeven"><td colspan="7"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1345 }
1346
1347 print "</table>";
1348 print '</div>';
1349
1350 // End of page
1351 llxFooter();
1352}
1353$db->close();
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.
Definition wrapper.php:91
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.
Definition wrapper.php:73
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 generation of HTML components Only common components must be here.
Class to manage suppliers.
Class Lettering.
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...
global $mysoc
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:603
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:622
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
getTaxesFromId($vatrate, $buyer=null, $seller=null, $firstparamisid=1)
Get tax (VAT) main information from Id.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.