dolibarr 24.0.0-beta
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-2026 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 // Avoid warnings
286 if (!array_key_exists($obj->rowid, $tabfac)) {
287 $tabfac[$obj->rowid] = array();
288 $tabttc[$obj->rowid] = array();
289 $tabht[$obj->rowid] = array();
290 $tabtva[$obj->rowid] = array();
291 $tablocaltax1[$obj->rowid] = array();
292 $tablocaltax2[$obj->rowid] = array();
293 }
294 if (!isset($tabttc[$obj->rowid][$compta_soc])) {
295 $tabttc[$obj->rowid][$compta_soc] = 0;
296 }
297 if (!isset($tabht[$obj->rowid][$compta_prod])) {
298 $tabht[$obj->rowid][$compta_prod] = 0;
299 }
300 if (!isset($tabtva[$obj->rowid][$compta_tva])) {
301 $tabtva[$obj->rowid][$compta_tva] = 0;
302 }
303 if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
304 $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
305 }
306 if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
307 $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
308 }
309
310 $tabfac[$obj->rowid]["date"] = $db->jdate($obj->df);
311 $tabfac[$obj->rowid]["datereg"] = $db->jdate($obj->dlr);
312 $tabfac[$obj->rowid]["ref"] = $obj->ref_supplier.' ('.$obj->ref.')';
313 $tabfac[$obj->rowid]["refsologest"] = $obj->ref;
314 $tabfac[$obj->rowid]["refsuppliersologest"] = $obj->ref_supplier;
315 $tabfac[$obj->rowid]["type"] = $obj->type;
316 $tabfac[$obj->rowid]["description"] = $obj->description;
317 $tabfac[$obj->rowid]["close_code"] = $obj->close_code; // close_code = 'replaced' for replacement invoices (not used in most european countries)
318 //$tabfac[$obj->rowid]["fk_facturefourndet"] = $obj->fdid;
319
320 // VAT Reverse charge
321 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'))) {
322 $rcvatdata = getTaxesFromId($obj->product_buy_vat . ($obj->product_buy_default_vat_code ? ' (' . $obj->product_buy_default_vat_code . ')' : ''), $mysoc, $mysoc, 0);
323 $rcc_compta_tva = (!empty($vatdata['accountancy_code_vat_reverse_charge_credit']) ? $vatdata['accountancy_code_vat_reverse_charge_credit'] : $rcctva);
324 $rcd_compta_tva = (!empty($vatdata['accountancy_code_vat_reverse_charge_debit']) ? $vatdata['accountancy_code_vat_reverse_charge_debit'] : $rcdtva);
325 $rcc_compta_localtax1 = (!empty($vatdata['accountancy_code_vat_reverse_charge_credit']) ? $vatdata['accountancy_code_vat_reverse_charge_credit'] : $rcclocaltax1);
326 $rcd_compta_localtax1 = (!empty($vatdata['accountancy_code_vat_reverse_charge_debit']) ? $vatdata['accountancy_code_vat_reverse_charge_debit'] : $rcdlocaltax1);
327 $rcc_compta_localtax2 = (!empty($vatdata['accountancy_code_vat_reverse_charge_credit']) ? $vatdata['accountancy_code_vat_reverse_charge_credit'] : $rcclocaltax2);
328 $rcd_compta_localtax2 = (!empty($vatdata['accountancy_code_vat_reverse_charge_debit']) ? $vatdata['accountancy_code_vat_reverse_charge_debit'] : $rcdlocaltax2);
329 if (price2num($obj->product_buy_vat) || !empty($obj->product_buy_default_vat_code)) {
330 $vat_key = vatrate($obj->product_buy_vat) . ($obj->product_buy_default_vat_code ? ' (' . $obj->product_buy_default_vat_code . ')' : '');
331 $val_value = $vat_key;
332 $def_tva[$obj->rowid][$rcc_compta_tva][$vat_key] = $val_value;
333 $def_tva[$obj->rowid][$rcd_compta_tva][$vat_key] = $val_value;
334 }
335
336 if (!array_key_exists($obj->rowid, $tabrctva)) {
337 $tabrctva[$obj->rowid] = array();
338 $tabrclocaltax1[$obj->rowid] = array();
339 $tabrclocaltax2[$obj->rowid] = array();
340 }
341 if (!isset($tabrctva[$obj->rowid][$rcc_compta_tva])) {
342 $tabrctva[$obj->rowid][$rcc_compta_tva] = 0;
343 }
344 if (!isset($tabrctva[$obj->rowid][$rcd_compta_tva])) {
345 $tabrctva[$obj->rowid][$rcd_compta_tva] = 0;
346 }
347 if (!isset($tabrclocaltax1[$obj->rowid][$rcc_compta_localtax1])) {
348 $tabrclocaltax1[$obj->rowid][$rcc_compta_localtax1] = 0;
349 }
350 if (!isset($tabrclocaltax1[$obj->rowid][$rcd_compta_localtax1])) {
351 $tabrclocaltax1[$obj->rowid][$rcd_compta_localtax1] = 0;
352 }
353 if (!isset($tabrclocaltax2[$obj->rowid][$rcc_compta_localtax2])) {
354 $tabrclocaltax2[$obj->rowid][$rcc_compta_localtax2] = 0;
355 }
356 if (!isset($tabrclocaltax2[$obj->rowid][$rcd_compta_localtax2])) {
357 $tabrclocaltax2[$obj->rowid][$rcd_compta_localtax2] = 0;
358 }
359
360 $rcvat = (float) price2num($obj->total_ttc * $obj->product_buy_vat / 100, 'MT');
361 $rclocalvat1 = (float) price2num($obj->total_ttc * $obj->product_buy_localvat1 / 100, 'MT');
362 $rclocalvat2 = (float) price2num($obj->total_ttc * $obj->product_buy_localvat2 / 100, 'MT');
363
364 $tabrctva[$obj->rowid][$rcd_compta_tva] += $rcvat;
365 $tabrctva[$obj->rowid][$rcc_compta_tva] -= $rcvat;
366 $tabrclocaltax1[$obj->rowid][$rcd_compta_localtax1] += $rclocalvat1;
367 $tabrclocaltax1[$obj->rowid][$rcc_compta_localtax1] -= $rclocalvat1;
368 $tabrclocaltax2[$obj->rowid][$rcd_compta_localtax2] += $rclocalvat2;
369 $tabrclocaltax2[$obj->rowid][$rcc_compta_localtax2] -= $rclocalvat2;
370 }
371
372 $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc;
373
374 if ($noTaxDispatchingKeepWithLines) { //case where all taxes paid should be grouped with the same account as the main expense (best for USA)
375 $tabht[$obj->rowid][$compta_prod] += $obj->total_ttc;
376 } else { //case where every tax paid should be broken out into its own account for future recovery (best for VAT countries)
377 $tabht[$obj->rowid][$compta_prod] += $obj->total_ht;
378 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
379 $tva_npr = ((($obj->info_bits & 1) == 1) ? 1 : 0);
380 if ($tva_npr) { // If NPR, we add an entry for counterpartWe into tabother
381 if (!array_key_exists($obj->rowid, $tabother)) {
382 $tabother[$obj->rowid] = array();
383 }
384 if (!array_key_exists($compta_counterpart_tva_npr, $tabother[$obj->rowid])) {
385 $tabother[$obj->rowid][$compta_counterpart_tva_npr] = 0;
386 }
387 $tabother[$obj->rowid][$compta_counterpart_tva_npr] += (float) $obj->total_tva;
388 }
389 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
390 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
391 }
392 $tabcompany[$obj->rowid] = array(
393 'id' => $obj->socid,
394 'name' => $obj->name,
395 'code_fournisseur' => $obj->code_fournisseur,
396 'accountancy_code_supplier_general' => $accountancy_code_supplier_general,
397 'code_compta_fournisseur' => $compta_soc
398 );
399
400 $i++;
401
402 // Check for too many lines.
403 if ($i > getDolGlobalInt('ACCOUNTANCY_MAX_TOO_MANY_LINES_TO_PROCESS', 10000)) {
404 $error++;
405 setEventMessages("ErrorTooManyLinesToProcessPleaseUseAMoreSelectiveFilter", null, 'errors');
406 break;
407 }
408 }
409} else {
411}
412
413$errorforinvoice = array();
414
415/*
416// Old way, 1 query for each invoice
417// Loop in invoices to detect lines with not binding lines
418foreach ($tabfac as $key => $val) { // Loop on each invoice
419 $sql = "SELECT COUNT(fd.rowid) as nb";
420 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn_det as fd";
421 $sql .= " WHERE fd.product_type <= 2 AND fd.fk_code_ventilation <= 0";
422 $sql .= " AND fd.total_ttc <> 0 AND fk_facture_fourn = ".((int) $key);
423 $resql = $db->query($sql);
424 if ($resql) {
425 $obj = $db->fetch_object($resql);
426 if ($obj->nb > 0) {
427 $errorforinvoice[$key] = 'somelinesarenotbound';
428 }
429 } else {
430 dol_print_error($db);
431 }
432}
433*/
434
435// New way, single query, load all unbound lines
436if (!empty($tabfac)) {
437 $sql = "
438 SELECT
439 fk_facture_fourn,
440 COUNT(fd.rowid) as nb
441 FROM
442 " . MAIN_DB_PREFIX . "facture_fourn_det as fd
443 WHERE
444 fd.product_type <= 2
445 AND fd.fk_code_ventilation <= 0
446 AND fd.total_ttc <> 0
447 AND fk_facture_fourn IN (".$db->sanitize(implode(",", array_keys($tabfac))).")
448 GROUP BY fk_facture_fourn
449 ";
450 $resql = $db->query($sql);
451
452 $num = $db->num_rows($resql);
453 $i = 0;
454 while ($i < $num) {
455 $obj = $db->fetch_object($resql);
456 if ($obj->nb > 0) {
457 $errorforinvoice[$obj->fk_facture_fourn] = 'somelinesarenotbound';
458 }
459 $i++;
460 }
461}
462
463// Bookkeeping Write
464if ($action == 'writebookkeeping' && !$error && $user->hasRight('accounting', 'bind', 'write')) {
465 $now = dol_now();
466 $error = 0;
467
468 $companystatic = new Societe($db);
469 $invoicestatic = new FactureFournisseur($db);
470 $accountingaccountsupplier = new AccountingAccount($db);
471 $bookkeepingstatic = new BookKeeping($db);
472
473 $accountingaccountsupplier->fetch(0, getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER'), true);
474
475 foreach ($tabfac as $key => $val) { // Loop on each invoice
476 $errorforline = 0;
477
478 $totalcredit = 0;
479 $totaldebit = 0;
480
481 $db->begin(); // We accept transaction into loop, so if we hang, we can continue transfer from the last error
482
483 $companystatic->id = $tabcompany[$key]['id'];
484 $companystatic->name = $tabcompany[$key]['name'];
485 $companystatic->accountancy_code_supplier_general = $tabcompany[$key]['accountancy_code_supplier_general'];
486 $companystatic->code_compta_fournisseur = $tabcompany[$key]['code_compta_fournisseur'];
487 $companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur'];
488 $companystatic->fournisseur = 1;
489
490 $invoicestatic->id = (int) $key;
491 $invoicestatic->ref = (string) $val["refsologest"];
492 $invoicestatic->ref_supplier = (string) $val["refsuppliersologest"];
493 $invoicestatic->type = $val["type"];
494 $invoicestatic->description = html_entity_decode(dol_trunc((string) $val["description"], 32));
495 $invoicestatic->close_code = (string) $val["close_code"];
496
497 $date = dol_print_date($val["date"], 'day');
498
499 // Is it a replaced invoice? 0=not a replaced invoice, 1=replaced invoice not yet dispatched, 2=replaced invoice dispatched
500 $replacedinvoice = 0;
501 if ($invoicestatic->close_code == FactureFournisseur::CLOSECODE_REPLACED) {
502 $replacedinvoice = 1;
503 $alreadydispatched = $invoicestatic->getVentilExportCompta(); // Test if replaced invoice already into bookkeeping.
504 if ($alreadydispatched) {
505 $replacedinvoice = 2;
506 }
507 }
508
509 // 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)
510 if ($replacedinvoice == 1) {
511 $db->rollback();
512 continue;
513 }
514
515 // Error if some lines are not binded/ready to be journalized
516 if (isset($errorforinvoice[$key]) && $errorforinvoice[$key] == 'somelinesarenotbound') {
517 $error++;
518 $errorforline++;
519 setEventMessages($langs->trans('ErrorInvoiceContainsLinesNotYetBounded', $val['ref']), null, 'errors');
520 }
521
522 // Thirdparty
523 if (!$errorforline) {
524 foreach ($tabttc[$key] as $k => $mt) {
525 $bookkeeping = new BookKeeping($db);
526 $bookkeeping->doc_date = $val["date"];
527 $bookkeeping->date_lim_reglement = $val["datereg"];
528 $bookkeeping->doc_ref = $val["refsologest"];
529 $bookkeeping->date_creation = $now;
530 $bookkeeping->doc_type = 'supplier_invoice';
531 $bookkeeping->fk_doc = (int) $key;
532 $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
533 $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
534
535 $bookkeeping->subledger_account = $tabcompany[$key]['code_compta_fournisseur'];
536 $bookkeeping->subledger_label = $tabcompany[$key]['name'];
537
538 $bookkeeping->numero_compte = $tabcompany[$key]['accountancy_code_supplier_general'];
539 $bookkeeping->label_compte = $accountingaccountsupplier->label;
540
541 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref_supplier, $langs->trans("SubledgerAccount"));
542 $bookkeeping->montant = $mt;
543 $bookkeeping->sens = ($mt >= 0) ? 'C' : 'D';
544 $bookkeeping->debit = ($mt <= 0) ? -$mt : 0;
545 $bookkeeping->credit = ($mt > 0) ? $mt : 0;
546 $bookkeeping->code_journal = $journal;
547 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
548 $bookkeeping->fk_user_author = $user->id;
549 $bookkeeping->entity = $conf->entity;
550
551 $totaldebit += $bookkeeping->debit;
552 $totalcredit += $bookkeeping->credit;
553
554 $result = $bookkeeping->create($user);
555 if ($result < 0) {
556 if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists
557 $error++;
558 $errorforline++;
559 $errorforinvoice[$key] = 'alreadyjournalized';
560 //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
561 } else {
562 $error++;
563 $errorforline++;
564 $errorforinvoice[$key] = 'other';
565 setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
566 }
567 } else {
568 if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && getDolGlobalInt('ACCOUNTING_ENABLE_AUTOLETTERING')) {
569 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/lettering.class.php';
570 $lettering_static = new Lettering($db);
571
572 $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id));
573 }
574 }
575 }
576 }
577
578 // Product / Service
579 if (!$errorforline) {
580 foreach ($tabht[$key] as $k => $mt) {
581 if (empty($conf->cache['accountingaccountincurrententity'][$k])) {
582 $accountingaccount = new AccountingAccount($db);
583 $accountingaccount->fetch(0, $k, true);
584 $conf->cache['accountingaccountincurrententity'][$k] = $accountingaccount;
585 } else {
586 $accountingaccount = $conf->cache['accountingaccountincurrententity'][$k];
587 }
588
589 $label_account = $accountingaccount->label;
590
591 // get compte id and label
592 if ($accountingaccount->id > 0) {
593 $bookkeeping = new BookKeeping($db);
594 $bookkeeping->doc_date = $val["date"];
595 $bookkeeping->date_lim_reglement = $val["datereg"];
596 $bookkeeping->doc_ref = $val["refsologest"];
597 $bookkeeping->date_creation = $now;
598 $bookkeeping->doc_type = 'supplier_invoice';
599 $bookkeeping->fk_doc = (int) $key;
600 $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
601 $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
602
603 if (getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT')) {
604 if ($k == getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT')) {
605 $bookkeeping->subledger_account = $tabcompany[$key]['code_compta_fournisseur'];
606 $bookkeeping->subledger_label = $tabcompany[$key]['name'];
607 } else {
608 $bookkeeping->subledger_account = '';
609 $bookkeeping->subledger_label = '';
610 }
611 } else {
612 $bookkeeping->subledger_account = '';
613 $bookkeeping->subledger_label = '';
614 }
615
616 $bookkeeping->numero_compte = $k;
617 $bookkeeping->label_compte = $label_account;
618
619 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref_supplier, $label_account);
620 $bookkeeping->montant = $mt;
621 $bookkeeping->sens = ($mt < 0) ? 'C' : 'D';
622 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
623 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
624 $bookkeeping->code_journal = $journal;
625 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
626 $bookkeeping->fk_user_author = $user->id;
627 $bookkeeping->entity = $conf->entity;
628
629 $totaldebit += $bookkeeping->debit;
630 $totalcredit += $bookkeeping->credit;
631
632 $result = $bookkeeping->create($user);
633 if ($result < 0) {
634 if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists
635 $error++;
636 $errorforline++;
637 $errorforinvoice[$key] = 'alreadyjournalized';
638 //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
639 } else {
640 $error++;
641 $errorforline++;
642 $errorforinvoice[$key] = 'other';
643 setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
644 }
645 }
646 }
647 }
648 }
649
650 // VAT
651 // var_dump($tabtva);
652 if (!$errorforline) {
653 $listoftax = array(0, 1, 2);
654 foreach ($listoftax as $numtax) {
655 $arrayofvat = $tabtva;
656 if ($numtax == 1) {
657 $arrayofvat = $tablocaltax1;
658 }
659 if ($numtax == 2) {
660 $arrayofvat = $tablocaltax2;
661 }
662
663 // VAT Reverse charge
664 if ($mysoc->country_code == 'FR' || getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) {
665 $has_vat = false;
666 foreach ($arrayofvat[$key] as $k => $mt) {
667 if ($mt) {
668 $has_vat = true;
669 }
670 }
671
672 if (!$has_vat) {
673 $arrayofvat = $tabrctva;
674 if ($numtax == 1) {
675 $arrayofvat = $tabrclocaltax1;
676 }
677 if ($numtax == 2) {
678 $arrayofvat = $tabrclocaltax2;
679 }
680 if (!isset($arrayofvat[$key]) || !is_array($arrayofvat[$key])) {
681 $arrayofvat[$key] = array();
682 }
683 }
684 }
685
686 foreach ($arrayofvat[$key] as $k => $mt) {
687 if ($mt) {
688 if (empty($conf->cache['accountingaccountincurrententity_vat'][$k])) {
689 $accountingaccount = new AccountingAccount($db);
690 $accountingaccount->fetch(0, $k, true);
691 $conf->cache['accountingaccountincurrententity_vat'][$k] = $accountingaccount;
692 } else {
693 $accountingaccount = $conf->cache['accountingaccountincurrententity_vat'][$k];
694 }
695
696 $label_account = $accountingaccount->label;
697
698 $bookkeeping = new BookKeeping($db);
699 $bookkeeping->doc_date = $val["date"];
700 $bookkeeping->date_lim_reglement = $val["datereg"];
701 $bookkeeping->doc_ref = $val["refsologest"];
702 $bookkeeping->date_creation = $now;
703 $bookkeeping->doc_type = 'supplier_invoice';
704 $bookkeeping->fk_doc = (int) $key;
705 $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
706 $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
707
708 $bookkeeping->subledger_account = '';
709 $bookkeeping->subledger_label = '';
710
711 $bookkeeping->numero_compte = $k;
712 $bookkeeping->label_compte = $label_account;
713
714 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ? '' : $arrayofvat[$key][$k]) : implode(', ', $def_tva[$key][$k]));
715 $labelvataccount = $langs->trans("Taxes").' '.$tmpvatrate.' %';
716 $labelvataccount .= ($numtax ? ' - Localtax '.$numtax : '');
717 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref_supplier, $labelvataccount);
718
719 $bookkeeping->montant = $mt;
720 $bookkeeping->sens = ($mt < 0) ? 'C' : 'D';
721 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
722 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
723 $bookkeeping->code_journal = $journal;
724 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
725 $bookkeeping->fk_user_author = $user->id;
726 $bookkeeping->entity = $conf->entity;
727
728 $totaldebit += $bookkeeping->debit;
729 $totalcredit += $bookkeeping->credit;
730
731 $result = $bookkeeping->create($user);
732 if ($result < 0) {
733 if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists
734 $error++;
735 $errorforline++;
736 $errorforinvoice[$key] = 'alreadyjournalized';
737 //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
738 } else {
739 $error++;
740 $errorforline++;
741 $errorforinvoice[$key] = 'other';
742 setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
743 }
744 }
745 }
746 }
747 }
748 }
749
750 // Counterpart of VAT for VAT NPR
751 // var_dump($tabother);
752 if (!$errorforline && isset($tabother[$key]) && is_array($tabother[$key])) {
753 foreach ($tabother[$key] as $k => $mt) {
754 if ($mt) {
755 $bookkeeping = new BookKeeping($db);
756 $bookkeeping->doc_date = $val["date"];
757 $bookkeeping->date_lim_reglement = $val["datereg"];
758 $bookkeeping->doc_ref = $val["refsologest"];
759 $bookkeeping->date_creation = $now;
760 $bookkeeping->doc_type = 'supplier_invoice';
761 $bookkeeping->fk_doc = (int) $key;
762 $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
763 $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
764
765 $bookkeeping->subledger_account = '';
766 $bookkeeping->subledger_label = '';
767
768 $bookkeeping->numero_compte = $k;
769
770 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref_supplier, $langs->trans("VAT").' NPR');
771 $bookkeeping->montant = $mt;
772 $bookkeeping->sens = ($mt < 0) ? 'C' : 'D';
773 $bookkeeping->debit = ($mt > 0) ? $mt : 0;
774 $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
775 $bookkeeping->code_journal = $journal;
776 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
777 $bookkeeping->fk_user_author = $user->id;
778 $bookkeeping->entity = $conf->entity;
779
780 $totaldebit += $bookkeeping->debit;
781 $totalcredit += $bookkeeping->credit;
782
783 $result = $bookkeeping->create($user);
784 if ($result < 0) {
785 if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists
786 $error++;
787 $errorforline++;
788 $errorforinvoice[$key] = 'alreadyjournalized';
789 //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
790 } else {
791 $error++;
792 $errorforline++;
793 $errorforinvoice[$key] = 'other';
794 setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
795 }
796 }
797 }
798 }
799 }
800
801 // Protection against a bug on lines before
802 if (!$errorforline && (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT'))) {
803 $error++;
804 $errorforline++;
805 $errorforinvoice[$key] = 'amountsnotbalanced';
806 setEventMessages('We tried to insert a non balanced transaction in book for '.$invoicestatic->ref.'. Canceled. Surely a bug.', null, 'errors');
807 }
808
809 if (!$errorforline) {
810 $db->commit();
811 } else {
812 $db->rollback();
813
814 if ($error >= 10) {
815 setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped"), null, 'errors');
816 break; // Break in the foreach
817 }
818 }
819 }
820
821 $tabpay = $tabfac;
822
823 if (empty($error) && count($tabpay) > 0) {
824 setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
825 } elseif (count($tabpay) == $error) {
826 setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings');
827 } else {
828 setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings');
829 }
830
831 $action = '';
832
833 // Must reload data, so we make a redirect
834 if (count($tabpay) != $error) {
835 $param = 'id_journal='.$id_journal;
836 $param .= '&date_startday='.$date_startday;
837 $param .= '&date_startmonth='.$date_startmonth;
838 $param .= '&date_startyear='.$date_startyear;
839 $param .= '&date_endday='.$date_endday;
840 $param .= '&date_endmonth='.$date_endmonth;
841 $param .= '&date_endyear='.$date_endyear;
842 $param .= '&in_bookkeeping='.$in_bookkeeping;
843 header("Location: ".$_SERVER['PHP_SELF'].($param ? '?'.$param : ''));
844 exit;
845 }
846}
847
848/*
849 * View
850 */
851
852$form = new Form($db);
853
854// Export
855if ($action == 'exportcsv' && !$error) { // ISO and not UTF8 !
856 $sep = getDolGlobalString('ACCOUNTING_EXPORT_SEPARATORCSV');
857
858 $filename = 'journal';
859 $type_export = 'journal';
860 include DOL_DOCUMENT_ROOT.'/accountancy/tpl/export_journal.tpl.php';
861
862 $companystatic = new Fournisseur($db);
863 $invoicestatic = new FactureFournisseur($db);
864 $bookkeepingstatic = new BookKeeping($db);
865
866 foreach ($tabfac as $key => $val) {
867 $companystatic->id = $tabcompany[$key]['id'];
868 $companystatic->name = $tabcompany[$key]['name'];
869 $companystatic->accountancy_code_supplier_general = !empty($tabcompany[$key]['accountancy_code_supplier_general']) ? $tabcompany[$key]['accountancy_code_supplier_general'] : $cptfour;
870 $companystatic->code_compta_fournisseur = $tabcompany[$key]['code_compta_fournisseur'];
871 $companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur'];
872 $companystatic->fournisseur = 1;
873
874 $invoicestatic->id = (int) $key;
875 $invoicestatic->ref = (string) $val["refsologest"];
876 $invoicestatic->ref_supplier = (string) $val["refsuppliersologest"];
877 $invoicestatic->type = $val["type"];
878 $invoicestatic->description = dol_trunc(html_entity_decode((string) $val["description"]), 32);
879 $invoicestatic->close_code = (string) $val["close_code"];
880
881 $date = dol_print_date($val["date"], 'day');
882
883 // Is it a replaced invoice? 0=not a replaced invoice, 1=replaced invoice not yet dispatched, 2=replaced invoice dispatched
884 $replacedinvoice = 0;
885 if ($invoicestatic->close_code == FactureFournisseur::CLOSECODE_REPLACED) {
886 $replacedinvoice = 1;
887 $alreadydispatched = $invoicestatic->getVentilExportCompta(); // Test if replaced invoice already into bookkeeping.
888 if ($alreadydispatched) {
889 $replacedinvoice = 2;
890 }
891 }
892
893 // 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)
894 if ($replacedinvoice == 1) {
895 continue;
896 }
897
898 // Third party
899 foreach ($tabttc[$key] as $k => $mt) {
900 //if ($mt) {
901 print '"'.$key.'"'.$sep;
902 print '"'.$date.'"'.$sep;
903 print '"'.((string) $val["refsologest"]).'"'.$sep;
904 print '"'.csvClean(dol_trunc($companystatic->name, 32)).'"'.$sep;
905 print '"'.length_accounta(html_entity_decode($k)).'"'.$sep;
906 print '"'.length_accountg($companystatic->accountancy_code_supplier_general).'"'.$sep;
907 print '"'.length_accounta(html_entity_decode($k)).'"'.$sep;
908 print '"'.$langs->trans("ThirdParty").'"'.$sep;
909 print '"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $val["refsuppliersologest"], $langs->trans("ThirdParty"))).'"'.$sep;
910 print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
911 print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
912 print '"'.$journal.'"';
913 print "\n";
914 //}
915 }
916
917 // Product / Service
918 foreach ($tabht[$key] as $k => $mt) {
919 $accountingaccount = new AccountingAccount($db);
920 $accountingaccount->fetch(0, $k, true);
921 //if ($mt) {
922 print '"'.$key.'"'.$sep;
923 print '"'.$date.'"'.$sep;
924 print '"'.((string) $val["refsologest"]).'"'.$sep;
925 print '"'.csvClean(dol_trunc($companystatic->name, 32)).'"'.$sep;
926 print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
927 print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
928 print '""'.$sep;
929 print '"'.csvClean(dol_trunc($accountingaccount->label, 32)).'"'.$sep;
930 print '"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $val["refsuppliersologest"], $accountingaccount->label)).'"'.$sep;
931 print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
932 print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
933 print '"'.$journal.'"';
934 print "\n";
935 //}
936 }
937
938 // VAT
939 $listoftax = array(0, 1, 2);
940 foreach ($listoftax as $numtax) {
941 $arrayofvat = $tabtva;
942 if ($numtax == 1) {
943 $arrayofvat = $tablocaltax1;
944 }
945 if ($numtax == 2) {
946 $arrayofvat = $tablocaltax2;
947 }
948
949 // VAT Reverse charge
950 if ($mysoc->country_code == 'FR' || getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) {
951 $has_vat = false;
952 foreach ($arrayofvat[$key] as $k => $mt) {
953 if ($mt) {
954 $has_vat = true;
955 }
956 }
957
958 if (!$has_vat) {
959 $arrayofvat = $tabrctva;
960 if ($numtax == 1) {
961 $arrayofvat = $tabrclocaltax1;
962 }
963 if ($numtax == 2) {
964 $arrayofvat = $tabrclocaltax2;
965 }
966 if (!isset($arrayofvat[$key]) || !is_array($arrayofvat[$key])) {
967 $arrayofvat[$key] = array();
968 }
969 }
970 }
971
972 foreach ($arrayofvat[$key] as $k => $mt) {
973 if ($mt) {
974 print '"'.$key.'"'.$sep;
975 print '"'.$date.'"'.$sep;
976 print '"'.((string) $val["refsologest"]).'"'.$sep;
977 print '"'.csvClean(dol_trunc($companystatic->name, 32)).'"'.$sep;
978 print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
979 print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
980 print '""'.$sep;
981 print '"'.$langs->trans("VAT").' - '.implode(', ', $def_tva[$key][$k]).' %"'.$sep;
982 print '"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $val["refsuppliersologest"], $langs->trans("VAT").implode($def_tva[$key][$k]).' %'.($numtax ? ' - Localtax '.$numtax : ''))).'"'.$sep;
983 print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
984 print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
985 print '"'.$journal.'"';
986 print "\n";
987 }
988 }
989
990 // VAT counterpart for NPR
991 if (isset($tabother[$key]) && is_array($tabother[$key])) {
992 foreach ($tabother[$key] as $k => $mt) {
993 if ($mt) {
994 print '"'.$key.'"'.$sep;
995 print '"'.$date.'"'.$sep;
996 print '"'.((string) $val["refsologest"]).'"'.$sep;
997 print '"'.csvClean(dol_trunc($companystatic->name, 32)).'"'.$sep;
998 print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
999 print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
1000 print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
1001 print '"'.$langs->trans("ThirdParty").'"'.$sep;
1002 print '"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $val["refsuppliersologest"], $langs->trans("VAT").' NPR')).'"'.$sep;
1003 print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
1004 print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
1005 print '"'.$journal.'"';
1006 print "\n";
1007 }
1008 }
1009 }
1010 }
1011 }
1012}
1013
1014if (empty($action) || $action == 'view') {
1015 $title = $langs->trans("GenerationOfAccountingEntries").' - '.$accountingjournalstatic->getNomUrl(0, 2, 1, '', 1);
1016 $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;';
1017 llxHeader('', dol_string_nohtmltag($title), $help_url, '', 0, 0, '', '', '', 'mod-accountancy accountancy-generation page-purchasesjournal');
1018
1019 $nom = $title;
1020 $nomlink = '';
1021 $periodlink = '';
1022 $exportlink = '';
1023 $builddate = dol_now();
1024 $description = $langs->trans("DescJournalOnlyBindedVisible").'<br>';
1025 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
1026 $description .= $langs->trans("DepositsAreNotIncluded");
1027 } else {
1028 $description .= $langs->trans("DepositsAreIncluded");
1029 }
1030
1031 $listofchoices = array('notyet' => $langs->trans("NotYetInGeneralLedger"), 'already' => $langs->trans("AlreadyInGeneralLedger"));
1032 $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);
1033 $period .= ' - '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
1034
1035 $varlink = 'id_journal='.$id_journal;
1036
1037 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink);
1038
1039 if (getDolGlobalString('ACCOUNTANCY_FISCAL_PERIOD_MODE') != 'blockedonclosed') {
1040 // Test that setup is complete (we are in accounting, so test on entity is always on $conf->entity only, no sharing allowed)
1041 // Fiscal period test
1042 $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_fiscalyear WHERE entity = ".((int) $conf->entity);
1043 $resql = $db->query($sql);
1044 if ($resql) {
1045 $obj = $db->fetch_object($resql);
1046 if ($obj->nb == 0) {
1047 print '<br><div class="warning">'.img_warning().' '.$langs->trans("TheFiscalPeriodIsNotDefined");
1048 $desc = ' : '.$langs->trans("AccountancyAreaDescFiscalPeriod", 4, '{link}');
1049 $desc = str_replace('{link}', '<strong>'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("FiscalPeriod").'</strong>', $desc);
1050 print $desc;
1051 print '</div>';
1052 }
1053 } else {
1055 }
1056 }
1057
1058 // Button to write into Ledger
1059 $acctSupplierNotConfigured = in_array(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER'), ['','-1']);
1060 if ($acctSupplierNotConfigured) {
1061 print '<br><div class="warning">'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone");
1062 $desc = ' : '.$langs->trans("AccountancyAreaDescMisc", 4, '{link}');
1063 $desc = str_replace('{link}', '<strong>'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'</strong>', $desc);
1064 print $desc;
1065 print '</div>';
1066 }
1067 print '<br><div class="tabsAction tabsActionNoBottom centerimp">';
1068 if (getDolGlobalString('ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping == 'notyet') {
1069 print '<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans("ExportDraftJournal").'" onclick="launch_export();" />';
1070 }
1071 if ($acctSupplierNotConfigured) {
1072 print '<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("SomeMandatoryStepsOfSetupWereNotDone")).'" value="'.$langs->trans("WriteBookKeeping").'" />';
1073 } else {
1074 if ($in_bookkeeping == 'notyet') {
1075 print '<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans("WriteBookKeeping").'" onclick="writebookkeeping();" />';
1076 } else {
1077 print '<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans("WriteBookKeeping").'</a>';
1078 }
1079 }
1080 print '</div>';
1081
1082 // TODO Avoid using js. We can use a direct link with $param
1083 print '
1084 <script type="text/javascript">
1085 function launch_export() {
1086 $("div.fiche form input[name=\"action\"]").val("exportcsv");
1087 $("div.fiche form input[type=\"submit\"]").click();
1088 $("div.fiche form input[name=\"action\"]").val("");
1089 }
1090 function writebookkeeping() {
1091 console.log("click on writebookkeeping");
1092 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
1093 $("div.fiche form input[type=\"submit\"]").click();
1094 $("div.fiche form input[name=\"action\"]").val("");
1095 }
1096 </script>';
1097
1098 /*
1099 * Show result array
1100 */
1101 print '<br>';
1102
1103 print '<div class="div-table-responsive">';
1104 print "<table class=\"noborder\" width=\"100%\">";
1105 print "<tr class=\"liste_titre\">";
1106 print "<td>".$langs->trans("Date")."</td>";
1107 print "<td>".$langs->trans("Piece").' ('.$langs->trans("InvoiceRef").")</td>";
1108 print "<td>".$langs->trans("AccountAccounting")."</td>";
1109 print "<td>".$langs->trans("SubledgerAccount")."</td>";
1110 print "<td>".$langs->trans("LabelOperation")."</td>";
1111 print '<td class="center">'.$langs->trans("AccountingDebit")."</td>";
1112 print '<td class="center">'.$langs->trans("AccountingCredit")."</td>";
1113 print "</tr>\n";
1114
1115 $i = 0;
1116
1117 $invoicestatic = new FactureFournisseur($db);
1118 $companystatic = new Fournisseur($db);
1119 $bookkeepingstatic = new BookKeeping($db);
1120
1121 foreach ($tabfac as $key => $val) {
1122 $companystatic->id = $tabcompany[$key]['id'];
1123 $companystatic->name = $tabcompany[$key]['name'];
1124 $companystatic->accountancy_code_supplier_general = !empty($tabcompany[$key]['accountancy_code_supplier_general']) ? $tabcompany[$key]['accountancy_code_supplier_general'] : $cptfour;
1125 $companystatic->code_compta_fournisseur = $tabcompany[$key]['code_compta_fournisseur'];
1126 $companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur'];
1127 $companystatic->fournisseur = 1;
1128
1129 $invoicestatic->id = (int) $key;
1130 $invoicestatic->ref = (string) $val["refsologest"];
1131 $invoicestatic->ref_supplier = (string) $val["refsuppliersologest"];
1132 $invoicestatic->type = $val["type"];
1133 $invoicestatic->description = dol_trunc(html_entity_decode((string) $val["description"]), 32);
1134 $invoicestatic->close_code = (string) $val["close_code"];
1135
1136 $date = dol_print_date($val["date"], 'day');
1137
1138 // Is it a replaced invoice? 0=not a replaced invoice, 1=replaced invoice not yet dispatched, 2=replaced invoice dispatched
1139 $replacedinvoice = 0;
1140 if ($invoicestatic->close_code == FactureFournisseur::CLOSECODE_REPLACED) {
1141 $replacedinvoice = 1;
1142 $alreadydispatched = $invoicestatic->getVentilExportCompta(); // Test if replaced invoice already into bookkeeping.
1143 if ($alreadydispatched) {
1144 $replacedinvoice = 2;
1145 }
1146 }
1147
1148 // If not already into bookkeeping, we won't add it, if yes, add the counterpart ???.
1149 if ($replacedinvoice == 1) {
1150 print '<tr class="oddeven">';
1151 print "<!-- Replaced invoice -->";
1152 print "<td>".$date."</td>";
1153 print "<td><strike>".$invoicestatic->getNomUrl(1)."</strike></td>";
1154 // Account
1155 print "<td>";
1156 print $langs->trans("Replaced");
1157 print '</td>';
1158 // Subledger account
1159 print "<td>";
1160 print '</td>';
1161 print "<td>";
1162 print "</td>";
1163 print '<td class="right"></td>';
1164 print '<td class="right"></td>';
1165 print "</tr>";
1166
1167 $i++;
1168 continue;
1169 }
1170 if (isset($errorforinvoice[$key]) && $errorforinvoice[$key] == 'somelinesarenotbound') {
1171 print '<tr class="oddeven">';
1172 print "<!-- Some lines are not bound -->";
1173 print "<td>".$date."</td>";
1174 print "<td>".$invoicestatic->getNomUrl(1)."</td>";
1175 // Account
1176 print "<td>";
1177 print '<span class="error">'.$langs->trans('ErrorInvoiceContainsLinesNotYetBoundedShort', $val['ref']).'</span>';
1178 print '</td>';
1179 // Subledger account
1180 print "<td>";
1181 print '</td>';
1182 print "<td>";
1183 print "</td>";
1184 print '<td class="right"></td>';
1185 print '<td class="right"></td>';
1186 print "</tr>";
1187
1188 $i++;
1189 }
1190
1191 // Third party
1192 foreach ($tabttc[$key] as $k => $mt) {
1193 print '<tr class="oddeven">';
1194 print "<!-- Thirdparty -->";
1195 print "<td>".$date."</td>";
1196 print "<td>".$invoicestatic->getNomUrl(1)."</td>";
1197 // Account
1198 print "<td>";
1199 $accountoshow = length_accountg(!empty($tabcompany[$key]['accountancy_code_supplier_general']) ? $tabcompany[$key]['accountancy_code_supplier_general'] : $cptfour);
1200 if (($accountoshow == "") || $accountoshow == 'NotDefined') {
1201 print '<span class="error">'.$langs->trans("MainAccountForSuppliersNotDefined").'</span>';
1202 } else {
1203 print $accountoshow;
1204 }
1205 print '</td>';
1206 // Subledger account
1207 print "<td>";
1208 $accountoshow = length_accounta($k);
1209 if (($accountoshow == "") || $accountoshow == 'NotDefined') {
1210 print '<span class="error">'.$langs->trans("ThirdpartyAccountNotDefined").'</span>';
1211 } else {
1212 print $accountoshow;
1213 }
1214 print '</td>';
1215 print "<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0, 'supplier'), $invoicestatic->ref_supplier, $langs->trans("SubledgerAccount"), 1) . "</td>";
1216 print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
1217 print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
1218 print "</tr>";
1219
1220 $i++;
1221 }
1222
1223 // Product / Service
1224 foreach ($tabht[$key] as $k => $mt) {
1225 if (empty($conf->cache['accountingaccountincurrententity'][$k])) {
1226 $accountingaccount = new AccountingAccount($db);
1227 $accountingaccount->fetch(0, $k, true);
1228 $conf->cache['accountingaccountincurrententity'][$k] = $accountingaccount;
1229 } else {
1230 $accountingaccount = $conf->cache['accountingaccountincurrententity'][$k];
1231 }
1232
1233 print '<tr class="oddeven">';
1234 print "<!-- Product -->";
1235 print "<td>".$date."</td>";
1236 print "<td>".$invoicestatic->getNomUrl(1)."</td>";
1237 // Account
1238 print "<td>";
1239 $accountoshow = length_accountg($k);
1240 if (($accountoshow == "") || $accountoshow == 'NotDefined') {
1241 print '<span class="error">'.$langs->trans("ProductAccountNotDefined").'</span>';
1242 } else {
1243 print $accountoshow;
1244 }
1245 print "</td>";
1246 // Subledger account
1247 print "<td>";
1248 if (getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT')) {
1249 if ($k == getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT')) {
1250 print length_accounta($tabcompany[$key]['code_compta_fournisseur']);
1251 }
1252 } elseif (($accountoshow == "") || $accountoshow == 'NotDefined') {
1253 print '<span class="error">' . $langs->trans("ThirdpartyAccountNotDefined") . '</span>';
1254 }
1255 print '</td>';
1256 $companystatic->id = $tabcompany[$key]['id'];
1257 $companystatic->name = $tabcompany[$key]['name'];
1258 print "<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0, 'supplier'), $invoicestatic->ref_supplier, $accountingaccount->label, 1) . "</td>";
1259 print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
1260 print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
1261 print "</tr>";
1262
1263 $i++;
1264 }
1265
1266 // VAT
1267 $listoftax = array(0, 1, 2);
1268 foreach ($listoftax as $numtax) {
1269 $arrayofvat = $tabtva;
1270 if ($numtax == 1) {
1271 $arrayofvat = $tablocaltax1;
1272 }
1273 if ($numtax == 2) {
1274 $arrayofvat = $tablocaltax2;
1275 }
1276
1277 // VAT Reverse charge
1278 if ($mysoc->country_code == 'FR' || getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) {
1279 $has_vat = false;
1280 foreach ($arrayofvat[$key] as $k => $mt) {
1281 if ($mt) {
1282 $has_vat = true;
1283 }
1284 }
1285
1286 if (!$has_vat) {
1287 $arrayofvat = $tabrctva;
1288 if ($numtax == 1) {
1289 $arrayofvat = $tabrclocaltax1;
1290 }
1291 if ($numtax == 2) {
1292 $arrayofvat = $tabrclocaltax2;
1293 }
1294 if (!isset($arrayofvat[$key]) || !is_array($arrayofvat[$key])) {
1295 $arrayofvat[$key] = array();
1296 }
1297 }
1298 }
1299
1300 foreach ($arrayofvat[$key] as $k => $mt) {
1301 if ($mt) {
1302 print '<tr class="oddeven">';
1303 print "<!-- VAT -->";
1304 print "<td>".$date."</td>";
1305 print "<td>".$invoicestatic->getNomUrl(1)."</td>";
1306 // Account
1307 print "<td>";
1308 $accountoshow = length_accountg($k);
1309 if (($accountoshow == "") || $accountoshow == 'NotDefined') {
1310 print '<span class="error">'.$langs->trans("VATAccountNotDefined").' ('.$langs->trans("AccountingJournalType3").')</span>';
1311 } else {
1312 print $accountoshow;
1313 }
1314 print "</td>";
1315 // Subledger account
1316 print "<td>";
1317 print '</td>';
1318 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ? '' : $arrayofvat[$key][$k]) : implode(', ', $def_tva[$key][$k]));
1319 $labelvatrate = $langs->trans("Taxes").' '.$tmpvatrate.' %';
1320 $labelvatrate .= ($numtax ? ' - Localtax '.$numtax : '');
1321 print "<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0, 'supplier'), $invoicestatic->ref_supplier, $labelvatrate, 1) . "</td>";
1322 print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
1323 print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
1324 print "</tr>";
1325
1326 $i++;
1327 }
1328 }
1329 }
1330
1331 // VAT counterpart for NPR
1332 if (isset($tabother[$key]) && is_array($tabother[$key])) {
1333 foreach ($tabother[$key] as $k => $mt) {
1334 if ($mt) {
1335 print '<tr class="oddeven">';
1336 print '<!-- VAT counterpart NPR -->';
1337 print "<td>".$date."</td>";
1338 print "<td>".$invoicestatic->getNomUrl(1)."</td>";
1339 // Account
1340 print '<td>';
1341 $accountoshow = length_accountg($k);
1342 if ($accountoshow == '' || $accountoshow == 'NotDefined') {
1343 print '<span class="error">'.$langs->trans("VATAccountNotDefined").' ('.$langs->trans("NPR counterpart").'). Set ACCOUNTING_COUNTERPART_VAT_NPR to the subvention account</span>';
1344 } else {
1345 print $accountoshow;
1346 }
1347 print '</td>';
1348 // Subledger account
1349 print "<td>";
1350 print '</td>';
1351 print "<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0, 'supplier'), $invoicestatic->ref_supplier, $langs->trans("VAT")." NPR (counterpart)", 1) . "</td>";
1352 print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
1353 print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
1354 print "</tr>";
1355
1356 $i++;
1357 }
1358 }
1359 }
1360 }
1361
1362 if (!$i) {
1363 print '<tr class="oddeven"><td colspan="7"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1364 }
1365
1366 print "</table>";
1367 print '</div>';
1368
1369 // End of page
1370 llxFooter();
1371}
1372$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:604
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:623
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
$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.
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.
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.