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