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