dolibarr 21.0.4
sellsjournal.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 Christophe Battarel <christophe.battarel@altairis.fr>
7 * Copyright (C) 2013-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
8 * Copyright (C) 2013-2016 Florian Henry <florian.henry@open-concept.pro>
9 * Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
10 * Copyright (C) 2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
11 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
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';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
40require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
41require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
42require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
43require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php';
44
54// Load translation files required by the page
55$langs->loadLangs(array("commercial", "compta", "bills", "other", "accountancy", "errors"));
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 == '') {
68 $in_bookkeeping = 'notyet';
69}
70
71$now = dol_now();
72
73$hookmanager->initHooks(array('sellsjournal'));
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$tabwarranty = array();
93$tabttc = array();
94$tablocaltax1 = array();
95$tablocaltax2 = array();
96
97$cptcli = 'NotDefined';
98
99/*
100 * Actions
101 */
102
103$reshook = $hookmanager->executeHooks('doActions', $parameters, $user, $action); // Note that $action and $object may have been modified by some hooks
104
105$accountingaccount = new AccountingAccount($db);
106
107// Get information of a journal
108$accountingjournalstatic = new AccountingJournal($db);
109$accountingjournalstatic->fetch($id_journal);
110$journal = $accountingjournalstatic->code;
111$journal_label = $accountingjournalstatic->label;
112
113$date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
114$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
115
116$pastmonth = null; // Initialise, could be unset
117$pastmonthyear = null; // Initialise, could be unset
118
119if (empty($date_startmonth)) {
120 // Period by default on transfer
122 $date_start = $dates['date_start'];
123 $pastmonthyear = $dates['pastmonthyear'];
124 $pastmonth = $dates['pastmonth'];
125}
126if (empty($date_endmonth)) {
127 // Period by default on transfer
129 $date_end = $dates['date_end'];
130 $pastmonthyear = $dates['pastmonthyear'];
131 $pastmonth = $dates['pastmonth'];
132}
133if (getDolGlobalString('ACCOUNTANCY_JOURNAL_USE_CURRENT_MONTH')) {
134 $pastmonth += 1;
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($pastmonthyear, $pastmonth, false);
139 $date_end = dol_get_last_day($pastmonthyear, $pastmonth, false);
140}
141
142$sql = "SELECT f.rowid, f.ref, f.type, f.situation_cycle_ref, f.datef as df, f.ref_client, f.date_lim_reglement as dlr, f.close_code, f.retained_warranty, f.revenuestamp,";
143$sql .= " fd.rowid as fdid, fd.description, fd.product_type, fd.total_ht, fd.total_tva, fd.total_localtax1, fd.total_localtax2, fd.tva_tx, fd.total_ttc, fd.situation_percent, fd.vat_src_code, fd.info_bits,";
144$sql .= " s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur,";
145if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
146 $sql .= " spe.accountancy_code_customer_general,";
147 $sql .= " spe.accountancy_code_customer as code_compta_client,";
148 $sql .= " spe.accountancy_code_supplier_general,";
149 $sql .= " spe.accountancy_code_supplier as code_compta_fournisseur,";
150} else {
151 $sql .= " s.accountancy_code_customer_general,";
152 $sql .= " s.code_compta as code_compta_client,";
153 $sql .= " s.accountancy_code_supplier_general,";
154 $sql .= " s.code_compta_fournisseur,";
155}
156$sql .= " p.rowid as pid, p.ref as pref, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte,";
157if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
158 $sql .= " ppe.accountancy_code_sell";
159} else {
160 $sql .= " p.accountancy_code_sell";
161}
162$parameters = array();
163$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
164$sql .= $hookmanager->resPrint;
165$sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd";
166$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = fd.fk_product";
167if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
168 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
169}
170$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
171$sql .= " JOIN ".MAIN_DB_PREFIX."facture as f ON f.rowid = fd.fk_facture";
172$sql .= " JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
173if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
174 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
175}
176$parameters = array();
177$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters); // Note that $action and $object may have been modified by hook
178$sql .= $hookmanager->resPrint;
179$sql .= " WHERE fd.fk_code_ventilation > 0";
180$sql .= " AND f.entity IN (".getEntity('invoice', 0).')'; // We don't share object for accountancy, we use source object sharing
181$sql .= " AND f.fk_statut > 0";
182if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) { // Non common setup
183 $sql .= " AND f.type IN (".Facture::TYPE_STANDARD.",".Facture::TYPE_REPLACEMENT.",".Facture::TYPE_CREDIT_NOTE.",".Facture::TYPE_SITUATION.")";
184} else {
185 $sql .= " AND f.type IN (".Facture::TYPE_STANDARD.",".Facture::TYPE_REPLACEMENT.",".Facture::TYPE_CREDIT_NOTE.",".Facture::TYPE_DEPOSIT.",".Facture::TYPE_SITUATION.")";
186}
187$sql .= " AND fd.product_type IN (0,1)";
188if ($date_start && $date_end) {
189 $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
190}
191// Define begin binding date
192if (getDolGlobalString('ACCOUNTING_DATE_START_BINDING')) {
193 $sql .= " AND f.datef >= '".$db->idate(getDolGlobalString('ACCOUNTING_DATE_START_BINDING'))."'";
194}
195// Already in bookkeeping or not
196if ($in_bookkeeping == 'already') {
197 $sql .= " AND f.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')";
198 // $sql .= " AND fd.rowid IN (SELECT fk_docdet FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')"; // Useless, we save one line for all products with same account
199}
200if ($in_bookkeeping == 'notyet') {
201 $sql .= " AND f.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')";
202 // $sql .= " AND fd.rowid NOT IN (SELECT fk_docdet FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')"; // Useless, we save one line for all products with same account
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, f.ref";
208//print $sql;
209
210dol_syslog('accountancy/journal/sellsjournal.php', LOG_DEBUG);
211$tabfac = array();
212$tabht = array();
213$tabtva = array();
214$def_tva = array();
215$tabwarranty = array();
216$tabrevenuestamp = array();
217$tabttc = array();
218$tablocaltax1 = array();
219$tablocaltax2 = array();
220$tabcompany = array();
221$vatdata_cache = array();
222
223// Variables
224$cptcli = getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER', 'NotDefined');
225$cpttva = getDolGlobalString('ACCOUNTING_VAT_SOLD_ACCOUNT', 'NotDefined');
226
227$result = $db->query($sql);
228if ($result) {
229 $num = $db->num_rows($result);
230
231 $i = 0;
232 while ($i < $num) {
233 $obj = $db->fetch_object($result);
234
235 // Controls
236 $accountancy_code_customer_general = (!empty($obj->accountancy_code_customer_general) && $obj->accountancy_code_customer_general != '-1') ? $obj->accountancy_code_customer_general : $cptcli;
237 $compta_soc = (!empty($obj->code_compta_client)) ? $obj->code_compta_client : $cptcli;
238
239 $compta_prod = $obj->compte;
240 if (empty($compta_prod)) {
241 if ($obj->product_type == 0) {
242 $compta_prod = getDolGlobalString('ACCOUNTING_PRODUCT_SOLD_ACCOUNT', 'NotDefined');
243 } else {
244 $compta_prod = getDolGlobalString('ACCOUNTING_SERVICE_SOLD_ACCOUNT', 'NotDefined');
245 }
246 }
247
248 // $compta_revenuestamp = getDolGlobalString('ACCOUNTING_REVENUESTAMP_SOLD_ACCOUNT', 'NotDefined');
249
250 $tax_id = $obj->tva_tx . ($obj->vat_src_code ? ' (' . $obj->vat_src_code . ')' : '');
251 if (array_key_exists($tax_id, $vatdata_cache)) {
252 $vatdata = $vatdata_cache[$tax_id];
253 } else {
254 if (getDolGlobalString('SERVICE_ARE_ECOMMERCE_200238EC')) {
255 $buyer = new Societe($db);
256 $buyer->fetch($obj->socid);
257 } else {
258 $buyer = null; // We don't need the buyer in this case
259 }
260 $seller = $mysoc;
261 $vatdata = getTaxesFromId($tax_id, $buyer, $seller, 0);
262 $vatdata_cache[$tax_id] = $vatdata;
263 }
264 $compta_tva = (!empty($vatdata['accountancy_code_sell']) ? $vatdata['accountancy_code_sell'] : $cpttva);
265 $compta_localtax1 = (!empty($vatdata['accountancy_code_sell']) ? $vatdata['accountancy_code_sell'] : $cpttva);
266 $compta_localtax2 = (!empty($vatdata['accountancy_code_sell']) ? $vatdata['accountancy_code_sell'] : $cpttva);
267
268 // Define the array to store the detail of each vat rate and code for lines
269 if (price2num($obj->tva_tx) || !empty($obj->vat_src_code)) {
270 $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.')' : ''));
271 }
272
273 // Create a compensation rate for situation invoice.
274 $situation_ratio = 1;
275 if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1) {
276 if ($obj->situation_cycle_ref) {
277 // Avoid divide by 0
278 if ($obj->situation_percent == 0) {
279 $situation_ratio = 0;
280 } else {
281 $line = new FactureLigne($db);
282 $line->fetch($obj->fdid);
283
284 // Situation invoices handling
285 $prev_progress = $line->get_prev_progress($obj->rowid);
286
287 $situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent;
288 }
289 }
290 }
291
292 $revenuestamp = (float) price2num($obj->revenuestamp, 'MT');
293
294 // Invoice lines
295 $tabfac[$obj->rowid]["date"] = $db->jdate($obj->df);
296 $tabfac[$obj->rowid]["datereg"] = $db->jdate($obj->dlr);
297 $tabfac[$obj->rowid]["ref"] = $obj->ref;
298 $tabfac[$obj->rowid]["type"] = $obj->type;
299 $tabfac[$obj->rowid]["description"] = $obj->label_compte;
300 $tabfac[$obj->rowid]["close_code"] = $obj->close_code; // close_code = 'replaced' for replacement invoices (not used in most european countries)
301 $tabfac[$obj->rowid]["revenuestamp"] = $revenuestamp;
302 //$tabfac[$obj->rowid]["fk_facturedet"] = $obj->fdid;
303
304 // Avoid warnings
305 if (!isset($tabttc[$obj->rowid][$compta_soc])) {
306 $tabttc[$obj->rowid][$compta_soc] = 0;
307 }
308 if (!isset($tabht[$obj->rowid][$compta_prod])) {
309 $tabht[$obj->rowid][$compta_prod] = 0;
310 }
311 if (!isset($tabtva[$obj->rowid][$compta_tva])) {
312 $tabtva[$obj->rowid][$compta_tva] = 0;
313 }
314 if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
315 $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
316 }
317 if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
318 $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
319 }
320
321 // Compensation of data for invoice situation by using $situation_ratio. This works (nearly) for invoice that was not correctly recorded
322 // but it may introduces an error for situation invoices that were correctly saved. There is still rounding problem that differs between
323 // real data we should have stored and result obtained with a compensation.
324 // It also seems that credit notes on situation invoices are correctly saved (but it depends on the version used in fact).
325 // For credit notes, we hope to have situation_ratio = 1 so the compensation has no effect to avoid introducing troubles with credit notes.
326 if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1) {
327 $total_ttc = $obj->total_ttc * $situation_ratio;
328 } else {
329 $total_ttc = $obj->total_ttc;
330 }
331
332 // Move a part of the retained warrenty into the account of warranty
333 if (getDolGlobalString('INVOICE_USE_RETAINED_WARRANTY') && $obj->retained_warranty > 0) {
334 $retained_warranty = (float) price2num($total_ttc * $obj->retained_warranty / 100, 'MT'); // Calculate the amount of warrenty for this line (using the percent value)
335 $tabwarranty[$obj->rowid][$compta_soc] += $retained_warranty;
336 $total_ttc -= $retained_warranty;
337 }
338
339 $tabttc[$obj->rowid][$compta_soc] += $total_ttc;
340 $tabht[$obj->rowid][$compta_prod] += $obj->total_ht * $situation_ratio;
341 $tva_npr = ((($obj->info_bits & 1) == 1) ? 1 : 0);
342 if (!$tva_npr) { // We ignore line if VAT is a NPR
343 if (getDolGlobalInt('INVOICE_USE_SITUATION') == 2) {
344 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
345 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
346 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
347 } else {
348 $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio;
349 $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1 * $situation_ratio;
350 $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2 * $situation_ratio;
351 }
352 }
353
354 $compta_revenuestamp = 'NotDefined';
355 if (!empty($revenuestamp)) {
356 $sqlrevenuestamp = "SELECT accountancy_code_sell FROM ".MAIN_DB_PREFIX."c_revenuestamp";
357 $sqlrevenuestamp .= " WHERE fk_pays = ".((int) $mysoc->country_id);
358 $sqlrevenuestamp .= " AND taux = ".((float) $revenuestamp);
359 $sqlrevenuestamp .= " AND active = 1";
360 $resqlrevenuestamp = $db->query($sqlrevenuestamp);
361
362 if ($resqlrevenuestamp) {
363 $num_rows_revenuestamp = $db->num_rows($resqlrevenuestamp);
364 if ($num_rows_revenuestamp > 1) {
365 dol_print_error($db, 'Failed 2 or more lines for the revenue stamp of your country. Check the dictionary of revenue stamp.');
366 } else {
367 $objrevenuestamp = $db->fetch_object($resqlrevenuestamp);
368 if ($objrevenuestamp) {
369 $compta_revenuestamp = $objrevenuestamp->accountancy_code_sell;
370 }
371 }
372 }
373 }
374
375 if (empty($tabrevenuestamp[$obj->rowid][$compta_revenuestamp]) && !empty($revenuestamp)) {
376 // The revenue stamp was never seen for this invoice id=$obj->rowid
377 $tabttc[$obj->rowid][$compta_soc] += $obj->revenuestamp;
378 $tabrevenuestamp[$obj->rowid][$compta_revenuestamp] = $obj->revenuestamp;
379 }
380
381 $tabcompany[$obj->rowid] = array(
382 'id' => $obj->socid,
383 'name' => $obj->name,
384 'code_client' => $obj->code_client,
385 'accountancy_code_customer_general' => $accountancy_code_customer_general,
386 'code_compta' => $compta_soc
387 );
388
389 // After the line is processed
390 $parameters = array(
391 'obj' => $obj,
392 'tabfac' => &$tabfac,
393 'tabht' => &$tabht,
394 'tabtva' => &$tabtva,
395 'def_tva' => &$def_tva,
396 'tabwarranty' => &$tabwarranty,
397 'tabrevenuestamp' => &$tabrevenuestamp,
398 'tabttc' => &$tabttc,
399 'tablocaltax1' => &$tablocaltax1,
400 'tablocaltax2' => &$tablocaltax2,
401 'tabcompany' => &$tabcompany,
402 'vatdata_cache' => &$vatdata_cache,
403 );
404 $reshook = $hookmanager->executeHooks('processingJournalData', $parameters); // Note that $action and $object may have been modified by hook
405
406 $i++;
407
408 // Check for too many lines.
409 if ($i > getDolGlobalInt('ACCOUNTANCY_MAX_TOO_MANY_LINES_TO_PROCESS', 10000)) {
410 $error++;
411 setEventMessages("ErrorTooManyLinesToProcessPleaseUseAMoreSelectiveFilter", null, 'errors');
412 break;
413 }
414 }
415
416 // After the loop on each line
417 $parameters = array(
418 'tabfac' => &$tabfac,
419 'tabht' => &$tabht,
420 'tabtva' => &$tabtva,
421 'def_tva' => &$def_tva,
422 'tabwarranty' => &$tabwarranty,
423 'tabrevenuestamp' => &$tabrevenuestamp,
424 'tabttc' => &$tabttc,
425 'tablocaltax1' => &$tablocaltax1,
426 'tablocaltax2' => &$tablocaltax2,
427 'tabcompany' => &$tabcompany,
428 'vatdata_cache' => &$vatdata_cache,
429 );
430 $reshook = $hookmanager->executeHooks('processedJournalData', $parameters); // Note that $action and $object may have been modified by hook
431} else {
432 dol_print_error($db);
433}
434
435
436$errorforinvoice = array();
437
438/*
439// Old way, 1 query for each invoice
440// Loop on all invoices to detect lines without binded code (fk_code_ventilation <= 0)
441foreach ($tabfac as $key => $val) { // Loop on each invoice
442 $sql = "SELECT COUNT(fd.rowid) as nb";
443 $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd";
444 $sql .= " WHERE fd.product_type <= 2 AND fd.fk_code_ventilation <= 0";
445 $sql .= " AND fd.total_ttc <> 0 AND fk_facture = ".((int) $key);
446 $resql = $db->query($sql);
447 if ($resql) {
448 $obj = $db->fetch_object($resql);
449 if ($obj->nb > 0) {
450 $errorforinvoice[$key] = 'somelinesarenotbound';
451 }
452 } else {
453 dol_print_error($db);
454 }
455}
456*/
457// New way, single query, load all unbound lines
458if (!empty($tabfac)) {
459 $sql = "
460 SELECT
461 fk_facture,
462 COUNT(fd.rowid) as nb
463 FROM
464 ".MAIN_DB_PREFIX."facturedet as fd
465 WHERE
466 fd.product_type <= 2
467 AND fd.fk_code_ventilation <= 0
468 AND fd.total_ttc <> 0
469 AND fk_facture IN (".$db->sanitize(implode(",", array_keys($tabfac))).")
470 GROUP BY fk_facture
471 ";
472 $resql = $db->query($sql);
473 if ($resql) {
474 $num = $db->num_rows($resql);
475 $i = 0;
476 while ($i < $num) {
477 $obj = $db->fetch_object($resql);
478 if ($obj->nb > 0) {
479 $errorforinvoice[$obj->fk_facture] = 'somelinesarenotbound';
480 }
481 $i++;
482 }
483 }
484}
485//var_dump($errorforinvoice);exit;
486
487// Bookkeeping Write
488if ($action == 'writebookkeeping' && !$error && $user->hasRight('accounting', 'bind', 'write')) {
489 $now = dol_now();
490 $error = 0;
491
492 $companystatic = new Societe($db);
493 $invoicestatic = new Facture($db);
494 $bookkeepingstatic = new BookKeeping($db);
495
496 $accountingaccountcustomer = new AccountingAccount($db);
497 $accountingaccountcustomer->fetch(0, getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER'), true);
498
499 $accountingaccountcustomerwarranty = new AccountingAccount($db);
500 $accountingaccountcustomerwarranty->fetch(0, getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY'), true);
501
502 foreach ($tabfac as $key => $val) { // Loop on each invoice
503 $errorforline = 0;
504
505 $totalcredit = 0;
506 $totaldebit = 0;
507
508 $db->begin(); // We accept transaction into loop, so if we hang, we can continue transfer from the last error
509
510 $companystatic->id = $tabcompany[$key]['id'];
511 $companystatic->name = $tabcompany[$key]['name'];
512 $companystatic->accountancy_code_customer_general = $tabcompany[$key]['accountancy_code_customer_general'];
513 $companystatic->code_compta = $tabcompany[$key]['code_compta'];
514 $companystatic->code_compta_client = $tabcompany[$key]['code_compta'];
515 $companystatic->code_client = $tabcompany[$key]['code_client'];
516 $companystatic->client = 3;
517
518 $invoicestatic->id = $key;
519 $invoicestatic->ref = (string) $val["ref"];
520 $invoicestatic->type = $val["type"];
521 $invoicestatic->close_code = $val["close_code"];
522
523 $date = dol_print_date($val["date"], 'day');
524
525 // Is it a replaced invoice? 0=not a replaced invoice, 1=replaced invoice not yet dispatched, 2=replaced invoice dispatched
526 $replacedinvoice = 0;
527 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
528 $replacedinvoice = 1;
529 $alreadydispatched = $invoicestatic->getVentilExportCompta(); // Test if replaced invoice already into bookkeeping.
530 if ($alreadydispatched) {
531 $replacedinvoice = 2;
532 }
533 }
534
535 // If not already into bookkeeping, we won't add it. If yes, do nothing (should not happen because creating a replacement is not possible if invoice is accounted)
536 if ($replacedinvoice == 1) {
537 $db->rollback();
538 continue;
539 }
540
541 // Error if some lines are not binded/ready to be journalized
542 if (isset($errorforinvoice[$key]) && $errorforinvoice[$key] == 'somelinesarenotbound') {
543 $error++;
544 $errorforline++;
545 setEventMessages($langs->trans('ErrorInvoiceContainsLinesNotYetBounded', $val['ref']), null, 'errors');
546 }
547
548 // Warranty
549 if (!$errorforline && getDolGlobalString('INVOICE_USE_RETAINED_WARRANTY')) {
550 if (isset($tabwarranty[$key]) && is_array($tabwarranty[$key])) {
551 foreach ($tabwarranty[$key] as $k => $mt) {
552 $bookkeeping = new BookKeeping($db);
553 $bookkeeping->doc_date = $val["date"];
554 $bookkeeping->date_lim_reglement = $val["datereg"];
555 $bookkeeping->doc_ref = $val["ref"];
556 $bookkeeping->date_creation = $now;
557 $bookkeeping->doc_type = 'customer_invoice';
558 $bookkeeping->fk_doc = $key;
559 $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are the source of this record to add
560 $bookkeeping->thirdparty_code = $companystatic->code_client;
561
562 $bookkeeping->subledger_account = $tabcompany[$key]['code_compta'];
563 $bookkeeping->subledger_label = $tabcompany[$key]['name'];
564
565 $bookkeeping->numero_compte = getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY');
566 $bookkeeping->label_compte = $accountingaccountcustomerwarranty->label;
567
568 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans("RetainedWarranty"));
569 $bookkeeping->montant = $mt;
570 $bookkeeping->sens = ($mt >= 0) ? 'D' : 'C';
571 $bookkeeping->debit = ($mt >= 0) ? $mt : 0;
572 $bookkeeping->credit = ($mt < 0) ? -$mt : 0;
573 $bookkeeping->code_journal = $journal;
574 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
575 $bookkeeping->fk_user_author = $user->id;
576 $bookkeeping->entity = $conf->entity;
577
578 $totaldebit += $bookkeeping->debit;
579 $totalcredit += $bookkeeping->credit;
580
581 $result = $bookkeeping->create($user);
582 if ($result < 0) {
583 if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists
584 $error++;
585 $errorforline++;
586 $errorforinvoice[$key] = 'alreadyjournalized';
587 //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
588 } else {
589 $error++;
590 $errorforline++;
591 $errorforinvoice[$key] = 'other';
592 setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
593 }
594 }
595 }
596 }
597 }
598
599 // Thirdparty
600 if (!$errorforline) {
601 foreach ($tabttc[$key] as $k => $mt) {
602 $bookkeeping = new BookKeeping($db);
603 $bookkeeping->doc_date = $val["date"];
604 $bookkeeping->date_lim_reglement = $val["datereg"];
605 $bookkeeping->doc_ref = $val["ref"];
606 $bookkeeping->date_creation = $now;
607 $bookkeeping->doc_type = 'customer_invoice';
608 $bookkeeping->fk_doc = $key;
609 $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
610 $bookkeeping->thirdparty_code = $companystatic->code_client;
611
612 $bookkeeping->subledger_account = $tabcompany[$key]['code_compta'];
613 $bookkeeping->subledger_label = $tabcompany[$key]['name'];
614
615 $bookkeeping->numero_compte = (!empty($tabcompany[$key]['accountancy_code_customer_general']) && $tabcompany[$key]['accountancy_code_customer_general'] != '-1') ? $tabcompany[$key]['accountancy_code_customer_general'] : $cptcli;
616 $bookkeeping->label_compte = $accountingaccountcustomer->label;
617
618 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans("SubledgerAccount"));
619 $bookkeeping->montant = $mt;
620 $bookkeeping->sens = ($mt >= 0) ? 'D' : 'C';
621 $bookkeeping->debit = ($mt >= 0) ? $mt : 0;
622 $bookkeeping->credit = ($mt < 0) ? -$mt : 0;
623 $bookkeeping->code_journal = $journal;
624 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
625 $bookkeeping->fk_user_author = $user->id;
626 $bookkeeping->entity = $conf->entity;
627
628 $totaldebit += $bookkeeping->debit;
629 $totalcredit += $bookkeeping->credit;
630
631 $result = $bookkeeping->create($user);
632 if ($result < 0) {
633 if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists
634 $error++;
635 $errorforline++;
636 $errorforinvoice[$key] = 'alreadyjournalized';
637 //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
638 } else {
639 $error++;
640 $errorforline++;
641 $errorforinvoice[$key] = 'other';
642 setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
643 }
644 } else {
645 if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && getDolGlobalInt('ACCOUNTING_ENABLE_AUTOLETTERING')) {
646 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/lettering.class.php';
647 $lettering_static = new Lettering($db);
648
649 $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id));
650 }
651 }
652 }
653 }
654
655 // Product / Service
656 if (!$errorforline) {
657 foreach ($tabht[$key] as $k => $mt) {
658 if (empty($conf->cache['accountingaccountincurrententity'][$k])) {
659 $accountingaccount = new AccountingAccount($db);
660 $accountingaccount->fetch(0, $k, true);
661 $conf->cache['accountingaccountincurrententity'][$k] = $accountingaccount;
662 } else {
663 $accountingaccount = $conf->cache['accountingaccountincurrententity'][$k];
664 }
665
666 $label_account = $accountingaccount->label;
667
668 // get compte id and label
669 if ($accountingaccount->id > 0) {
670 $bookkeeping = new BookKeeping($db);
671 $bookkeeping->doc_date = $val["date"];
672 $bookkeeping->date_lim_reglement = $val["datereg"];
673 $bookkeeping->doc_ref = $val["ref"];
674 $bookkeeping->date_creation = $now;
675 $bookkeeping->doc_type = 'customer_invoice';
676 $bookkeeping->fk_doc = $key;
677 $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
678 $bookkeeping->thirdparty_code = $companystatic->code_client;
679
680 if (getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT')) {
681 if ($k == getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT')) {
682 $bookkeeping->subledger_account = $tabcompany[$key]['code_compta'];
683 $bookkeeping->subledger_label = $tabcompany[$key]['name'];
684 } else {
685 $bookkeeping->subledger_account = '';
686 $bookkeeping->subledger_label = '';
687 }
688 } else {
689 $bookkeeping->subledger_account = '';
690 $bookkeeping->subledger_label = '';
691 }
692
693 $bookkeeping->numero_compte = $k;
694 $bookkeeping->label_compte = $label_account;
695
696 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $label_account);
697 $bookkeeping->montant = $mt;
698 $bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
699 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
700 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
701 $bookkeeping->code_journal = $journal;
702 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
703 $bookkeeping->fk_user_author = $user->id;
704 $bookkeeping->entity = $conf->entity;
705
706 $totaldebit += $bookkeeping->debit;
707 $totalcredit += $bookkeeping->credit;
708
709 $result = $bookkeeping->create($user);
710 if ($result < 0) {
711 if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists
712 $error++;
713 $errorforline++;
714 $errorforinvoice[$key] = 'alreadyjournalized';
715 //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
716 } else {
717 $error++;
718 $errorforline++;
719 $errorforinvoice[$key] = 'other';
720 setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
721 }
722 }
723 }
724 }
725 }
726
727 // VAT
728 if (!$errorforline) {
729 $listoftax = array(0, 1, 2);
730 foreach ($listoftax as $numtax) {
731 $arrayofvat = $tabtva;
732 if ($numtax == 1) {
733 $arrayofvat = $tablocaltax1;
734 }
735 if ($numtax == 2) {
736 $arrayofvat = $tablocaltax2;
737 }
738
739 foreach ($arrayofvat[$key] as $k => $mt) {
740 if ($mt) {
741 if (empty($conf->cache['accountingaccountincurrententity_vat'][$k])) {
742 $accountingaccount = new AccountingAccount($db);
743 $accountingaccount->fetch(0, $k, true);
744 $conf->cache['accountingaccountincurrententity_vat'][$k] = $accountingaccount;
745 } else {
746 $accountingaccount = $conf->cache['accountingaccountincurrententity_vat'][$k];
747 }
748
749 $label_account = $accountingaccount->label;
750
751 $bookkeeping = new BookKeeping($db);
752 $bookkeeping->doc_date = $val["date"];
753 $bookkeeping->date_lim_reglement = $val["datereg"];
754 $bookkeeping->doc_ref = $val["ref"];
755 $bookkeeping->date_creation = $now;
756 $bookkeeping->doc_type = 'customer_invoice';
757 $bookkeeping->fk_doc = $key;
758 $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
759 $bookkeeping->thirdparty_code = $companystatic->code_client;
760
761 $bookkeeping->subledger_account = '';
762 $bookkeeping->subledger_label = '';
763
764 $bookkeeping->numero_compte = $k;
765 $bookkeeping->label_compte = $label_account;
766
767
768 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ? '' : $arrayofvat[$key][$k]) : implode(', ', $def_tva[$key][$k]));
769 $labelvataccount = $langs->trans("Taxes").' '.$tmpvatrate.' %';
770 $labelvataccount .= ($numtax ? ' - Localtax '.$numtax : '');
771 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $labelvataccount);
772
773 $bookkeeping->montant = $mt;
774 $bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
775 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
776 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
777 $bookkeeping->code_journal = $journal;
778 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
779 $bookkeeping->fk_user_author = $user->id;
780 $bookkeeping->entity = $conf->entity;
781
782 $totaldebit += $bookkeeping->debit;
783 $totalcredit += $bookkeeping->credit;
784
785 $result = $bookkeeping->create($user);
786 if ($result < 0) {
787 if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists
788 $error++;
789 $errorforline++;
790 $errorforinvoice[$key] = 'alreadyjournalized';
791 //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
792 } else {
793 $error++;
794 $errorforline++;
795 $errorforinvoice[$key] = 'other';
796 setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
797 }
798 }
799 }
800 }
801 }
802 }
803
804 // Revenue stamp
805 if (!$errorforline) {
806 if (isset($tabrevenuestamp[$key]) && is_array($tabrevenuestamp[$key])) {
807 foreach ($tabrevenuestamp[$key] as $k => $mt) {
808 if ($mt) {
809 if (empty($conf->cache['accountingaccountincurrententity_rs'][$k])) {
810 $accountingaccount = new AccountingAccount($db);
811 $accountingaccount->fetch(0, $k, true);
812 $conf->cache['accountingaccountincurrententity_rs'][$k] = $accountingaccount;
813 } else {
814 $accountingaccount = $conf->cache['accountingaccountincurrententity_rs'][$k];
815 }
816
817 $label_account = $accountingaccount->label;
818
819 $bookkeeping = new BookKeeping($db);
820 $bookkeeping->doc_date = $val["date"];
821 $bookkeeping->date_lim_reglement = $val["datereg"];
822 $bookkeeping->doc_ref = $val["ref"];
823 $bookkeeping->date_creation = $now;
824 $bookkeeping->doc_type = 'customer_invoice';
825 $bookkeeping->fk_doc = $key;
826 $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
827 $bookkeeping->thirdparty_code = $companystatic->code_client;
828
829 $bookkeeping->subledger_account = '';
830 $bookkeeping->subledger_label = '';
831
832 $bookkeeping->numero_compte = $k;
833 $bookkeeping->label_compte = $label_account;
834
835 $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans("RevenueStamp"));
836 $bookkeeping->montant = $mt;
837 $bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
838 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
839 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
840 $bookkeeping->code_journal = $journal;
841 $bookkeeping->journal_label = $langs->transnoentities($journal_label);
842 $bookkeeping->fk_user_author = $user->id;
843 $bookkeeping->entity = $conf->entity;
844
845 $totaldebit += $bookkeeping->debit;
846 $totalcredit += $bookkeeping->credit;
847
848 $result = $bookkeeping->create($user);
849 if ($result < 0) {
850 if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists
851 $error++;
852 $errorforline++;
853 $errorforinvoice[$key] = 'alreadyjournalized';
854 //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
855 } else {
856 $error++;
857 $errorforline++;
858 $errorforinvoice[$key] = 'other';
859 setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
860 }
861 }
862 }
863 }
864 }
865 }
866
867 // Protection against a bug on lines before
868 if (!$errorforline && (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT'))) {
869 $error++;
870 $errorforline++;
871 $errorforinvoice[$key] = 'amountsnotbalanced';
872 setEventMessages('We Tried to insert a non balanced transaction in book for '.$invoicestatic->ref.'. Canceled. Surely a bug.', null, 'errors');
873 }
874
875 if (!$errorforline) {
876 $db->commit();
877 } else {
878 $db->rollback();
879
880 if ($error >= 10) {
881 setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped"), null, 'errors');
882 break; // Break in the foreach
883 }
884 }
885 }
886
887 $tabpay = $tabfac;
888
889 if (empty($error) && count($tabpay) > 0) {
890 setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
891 } elseif (count($tabpay) == $error) {
892 setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings');
893 } else {
894 setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings');
895 }
896
897 $action = '';
898
899 // Must reload data, so we make a redirect
900 if (count($tabpay) != $error) {
901 $param = 'id_journal='.$id_journal;
902 $param .= '&date_startday='.$date_startday;
903 $param .= '&date_startmonth='.$date_startmonth;
904 $param .= '&date_startyear='.$date_startyear;
905 $param .= '&date_endday='.$date_endday;
906 $param .= '&date_endmonth='.$date_endmonth;
907 $param .= '&date_endyear='.$date_endyear;
908 $param .= '&in_bookkeeping='.$in_bookkeeping;
909 header("Location: ".$_SERVER['PHP_SELF'].($param ? '?'.$param : ''));
910 exit;
911 }
912}
913
914
915
916/*
917 * View
918 */
919
920$form = new Form($db);
921
922// Export
923if ($action == 'exportcsv' && !$error) { // ISO and not UTF8 !
924 // Note that to have the button to get this feature enabled, you must enable ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL
925 $sep = getDolGlobalString('ACCOUNTING_EXPORT_SEPARATORCSV');
926
927 $filename = 'journal';
928 $type_export = 'journal';
929 include DOL_DOCUMENT_ROOT.'/accountancy/tpl/export_journal.tpl.php';
930
931 $companystatic = new Client($db);
932 $invoicestatic = new Facture($db);
933 $bookkeepingstatic = new BookKeeping($db);
934
935 foreach ($tabfac as $key => $val) {
936 $companystatic->id = $tabcompany[$key]['id'];
937 $companystatic->name = $tabcompany[$key]['name'];
938 $companystatic->accountancy_code_customer_general = (!empty($tabcompany[$key]['accountancy_code_customer_general']) && $tabcompany[$key]['accountancy_code_customer_general'] != '-1') ? $tabcompany[$key]['accountancy_code_customer_general'] : $cptcli;
939 $companystatic->code_compta = $tabcompany[$key]['code_compta']; // deprecated
940 $companystatic->code_compta_client = $tabcompany[$key]['code_compta'];
941 $companystatic->code_client = $tabcompany[$key]['code_client'];
942 $companystatic->client = 3;
943
944 $invoicestatic->id = $key;
945 $invoicestatic->ref = (string) $val["ref"];
946 $invoicestatic->type = $val["type"];
947 $invoicestatic->close_code = $val["close_code"];
948
949 $date = dol_print_date($val["date"], 'day');
950
951 // Is it a replaced invoice? 0=not a replaced invoice, 1=replaced invoice not yet dispatched, 2=replaced invoice dispatched
952 $replacedinvoice = 0;
953 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
954 $replacedinvoice = 1;
955 $alreadydispatched = $invoicestatic->getVentilExportCompta(); // Test if replaced invoice already into bookkeeping.
956 if ($alreadydispatched) {
957 $replacedinvoice = 2;
958 }
959 }
960
961 // 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)
962 if ($replacedinvoice == 1) {
963 continue;
964 }
965
966 // Warranty
967 if (getDolGlobalString('INVOICE_USE_RETAINED_WARRANTY') && isset($tabwarranty[$key])) {
968 foreach ($tabwarranty[$key] as $k => $mt) {
969 //if ($mt) {
970 print '"'.$key.'"'.$sep;
971 print '"'.$date.'"'.$sep;
972 print '"'.$val["ref"].'"'.$sep;
973 print '"'.csvClean(dol_trunc($companystatic->name, 32)).'"'.$sep;
974 print '"'.length_accounta(html_entity_decode($k)).'"'.$sep;
975 print '"'.length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY')).'"'.$sep;
976 print '"'.length_accounta(html_entity_decode($k)).'"'.$sep;
977 print '"'.$langs->trans("Thirdparty").'"'.$sep;
978 print '"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans("RetainedWarranty"))).'"'.$sep;
979 print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
980 print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
981 print '"'.$journal.'"';
982 print "\n";
983 //}
984 }
985 }
986
987 // Third party
988 foreach ($tabttc[$key] as $k => $mt) {
989 //if ($mt) {
990 print '"'.$key.'"'.$sep;
991 print '"'.$date.'"'.$sep;
992 print '"'.$val["ref"].'"'.$sep;
993 print '"'.csvClean(dol_trunc($companystatic->name, 32)).'"'.$sep;
994 print '"'.length_accounta(html_entity_decode($k)).'"'.$sep;
995 print '"'.length_accountg($companystatic->accountancy_code_customer_general).'"'.$sep;
996 print '"'.length_accounta(html_entity_decode($k)).'"'.$sep;
997 print '"'.$langs->trans("Thirdparty").'"'.$sep;
998 print '"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans("Thirdparty"))).'"'.$sep;
999 print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
1000 print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
1001 print '"'.$journal.'"';
1002 print "\n";
1003 //}
1004 }
1005
1006 // Product / Service
1007 foreach ($tabht[$key] as $k => $mt) {
1008 $accountingaccount = new AccountingAccount($db);
1009 $accountingaccount->fetch(0, $k, true);
1010 //if ($mt) {
1011 print '"'.$key.'"'.$sep;
1012 print '"'.$date.'"'.$sep;
1013 print '"'.$val["ref"].'"'.$sep;
1014 print '"'.csvClean(dol_trunc($companystatic->name, 32)).'"'.$sep;
1015 print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
1016 print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
1017 print '""'.$sep;
1018 print '"'.csvClean(dol_trunc($accountingaccount->label, 32)).'"'.$sep;
1019 print '"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $accountingaccount->label)).'"'.$sep;
1020 print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
1021 print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
1022 print '"'.$journal.'"';
1023 print "\n";
1024 //}
1025 }
1026
1027 // VAT
1028 $listoftax = array(0, 1, 2);
1029 foreach ($listoftax as $numtax) {
1030 $arrayofvat = $tabtva;
1031 if ($numtax == 1) {
1032 $arrayofvat = $tablocaltax1;
1033 }
1034 if ($numtax == 2) {
1035 $arrayofvat = $tablocaltax2;
1036 }
1037
1038 foreach ($arrayofvat[$key] as $k => $mt) {
1039 if ($mt) {
1040 print '"'.$key.'"'.$sep;
1041 print '"'.$date.'"'.$sep;
1042 print '"'.$val["ref"].'"'.$sep;
1043 print '"'.csvClean(dol_trunc($companystatic->name, 32)).'"'.$sep;
1044 print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
1045 print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
1046 print '""'.$sep;
1047 print '"'.$langs->trans("VAT").' - '.implode(', ', $def_tva[$key][$k]).' %"'.$sep;
1048 print '"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans("VAT").implode($def_tva[$key][$k]).' %'.($numtax ? ' - Localtax '.$numtax : ''))).'"'.$sep;
1049 print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
1050 print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
1051 print '"'.$journal.'"';
1052 print "\n";
1053 }
1054 }
1055 }
1056
1057 // Revenue stamp
1058 if (isset($tabrevenuestamp[$key])) {
1059 foreach ($tabrevenuestamp[$key] as $k => $mt) {
1060 //if ($mt) {
1061 print '"'.$key.'"'.$sep;
1062 print '"'.$date.'"'.$sep;
1063 print '"'.$val["ref"].'"'.$sep;
1064 print '"'.csvClean(dol_trunc($companystatic->name, 32)).'"'.$sep;
1065 print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
1066 print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
1067 print '""'.$sep;
1068 print '"'.$langs->trans("RevenueStamp").'"'.$sep;
1069 print '"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref, $langs->trans("RevenueStamp"))).'"'.$sep;
1070 print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
1071 print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
1072 print '"'.$journal.'"';
1073 print "\n";
1074 //}
1075 }
1076 }
1077 }
1078}
1079
1080
1081
1082if (empty($action) || $action == 'view') {
1083 $title = $langs->trans("GenerationOfAccountingEntries").' - '.$accountingjournalstatic->getNomUrl(0, 2, 1, '', 1);
1084 $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;';
1085 llxHeader('', dol_string_nohtmltag($title), $help_url, '', 0, 0, '', '', '', 'mod-accountancy accountancy-generation page-sellsjournal');
1086
1087 $nom = $title;
1088 $nomlink = '';
1089 $periodlink = '';
1090 $exportlink = '';
1091 $builddate = dol_now();
1092 $description = $langs->trans("DescJournalOnlyBindedVisible").'<br>';
1093 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
1094 $description .= $langs->trans("DepositsAreNotIncluded");
1095 } else {
1096 $description .= $langs->trans("DepositsAreIncluded");
1097 }
1098
1099 $listofchoices = array('notyet' => $langs->trans("NotYetInGeneralLedger"), 'already' => $langs->trans("AlreadyInGeneralLedger"));
1100 $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);
1101 $period .= ' - '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
1102
1103 $varlink = 'id_journal='.$id_journal;
1104
1105 journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink);
1106
1107 if (getDolGlobalString('ACCOUNTANCY_FISCAL_PERIOD_MODE') != 'blockedonclosed') {
1108 // Test that setup is complete (we are in accounting, so test on entity is always on $conf->entity only, no sharing allowed)
1109 // Fiscal period test
1110 $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_fiscalyear WHERE entity = ".((int) $conf->entity);
1111 $resql = $db->query($sql);
1112 if ($resql) {
1113 $obj = $db->fetch_object($resql);
1114 if ($obj->nb == 0) {
1115 print '<br><div class="warning">'.img_warning().' '.$langs->trans("TheFiscalPeriodIsNotDefined");
1116 $desc = ' : '.$langs->trans("AccountancyAreaDescFiscalPeriod", 4, '{link}');
1117 $desc = str_replace('{link}', '<strong>'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("FiscalPeriod").'</strong>', $desc);
1118 print $desc;
1119 print '</div>';
1120 }
1121 } else {
1122 dol_print_error($db);
1123 }
1124 }
1125
1126 // Button to write into Ledger
1127 $acctCustomerNotConfigured = in_array(getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER'), ['','-1']);
1128 if ($acctCustomerNotConfigured) {
1129 print '<br><div class="warning">'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone");
1130 $desc = ' : '.$langs->trans("AccountancyAreaDescMisc", 4, '{link}');
1131 $desc = str_replace('{link}', '<strong>'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'</strong>', $desc);
1132 print $desc;
1133 print '</div>';
1134 }
1135 print '<br><div class="tabsAction tabsActionNoBottom centerimp">';
1136 if (getDolGlobalString('ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping == 'notyet') {
1137 print '<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans("ExportDraftJournal").'" onclick="launch_export();" />';
1138 }
1139 if ($acctCustomerNotConfigured) {
1140 print '<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("SomeMandatoryStepsOfSetupWereNotDone")).'" value="'.$langs->trans("WriteBookKeeping").'" />';
1141 } else {
1142 if ($in_bookkeeping == 'notyet') {
1143 print '<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans("WriteBookKeeping").'" onclick="writebookkeeping();" />';
1144 } else {
1145 print '<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans("WriteBookKeeping").'</a>';
1146 }
1147 }
1148 print '</div>';
1149
1150 // TODO Avoid using js. We can use a direct link with $param
1151 print '
1152 <script type="text/javascript">
1153 function launch_export() {
1154 $("div.fiche form input[name=\"action\"]").val("exportcsv");
1155 $("div.fiche form input[type=\"submit\"]").click();
1156 $("div.fiche form input[name=\"action\"]").val("");
1157 }
1158 function writebookkeeping() {
1159 console.log("click on writebookkeeping");
1160 $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
1161 $("div.fiche form input[type=\"submit\"]").click();
1162 $("div.fiche form input[name=\"action\"]").val("");
1163 }
1164 </script>';
1165
1166 /*
1167 * Show result array
1168 */
1169 print '<br>';
1170
1171 print '<div class="div-table-responsive">';
1172 print "<table class=\"noborder\" width=\"100%\">";
1173 print "<tr class=\"liste_titre\">";
1174 print "<td>".$langs->trans("Date")."</td>";
1175 print "<td>".$langs->trans("Piece").' ('.$langs->trans("InvoiceRef").")</td>";
1176 print "<td>".$langs->trans("AccountAccounting")."</td>";
1177 print "<td>".$langs->trans("SubledgerAccount")."</td>";
1178 print "<td>".$langs->trans("LabelOperation")."</td>";
1179 print '<td class="center">'.$langs->trans("AccountingDebit")."</td>";
1180 print '<td class="center">'.$langs->trans("AccountingCredit")."</td>";
1181 print "</tr>\n";
1182
1183 $i = 0;
1184
1185 $companystatic = new Client($db);
1186 $invoicestatic = new Facture($db);
1187 $bookkeepingstatic = new BookKeeping($db);
1188
1189 foreach ($tabfac as $key => $val) {
1190 $companystatic->id = $tabcompany[$key]['id'];
1191 $companystatic->name = $tabcompany[$key]['name'];
1192 $companystatic->accountancy_code_customer_general = (!empty($tabcompany[$key]['accountancy_code_customer_general']) && $tabcompany[$key]['accountancy_code_customer_general'] != '-1') ? $tabcompany[$key]['accountancy_code_customer_general'] : $cptcli;
1193 $companystatic->code_compta = $tabcompany[$key]['code_compta'];
1194 $companystatic->code_compta_client = $tabcompany[$key]['code_compta'];
1195 $companystatic->code_client = $tabcompany[$key]['code_client'];
1196 $companystatic->client = 3;
1197
1198 $invoicestatic->id = $key;
1199 $invoicestatic->ref = (string) $val["ref"];
1200 $invoicestatic->type = $val["type"];
1201 $invoicestatic->close_code = $val["close_code"];
1202
1203 $date = dol_print_date($val["date"], 'day');
1204
1205 // Is it a replaced invoice? 0=not a replaced invoice, 1=replaced invoice not yet dispatched, 2=replaced invoice dispatched
1206 $replacedinvoice = 0;
1207 if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
1208 $replacedinvoice = 1;
1209 $alreadydispatched = $invoicestatic->getVentilExportCompta(); // Test if replaced invoice already into bookkeeping.
1210 if ($alreadydispatched) {
1211 $replacedinvoice = 2;
1212 }
1213 }
1214
1215 // If not already into bookkeeping, we won't add it, if yes, add the counterpart ???.
1216 if ($replacedinvoice == 1) {
1217 print '<tr class="oddeven">';
1218 print "<!-- Replaced invoice -->";
1219 print "<td>".$date."</td>";
1220 print "<td><strike>".$invoicestatic->getNomUrl(1)."</strike></td>";
1221 // Account
1222 print "<td>";
1223 print $langs->trans("Replaced");
1224 print '</td>';
1225 // Subledger account
1226 print "<td>";
1227 print '</td>';
1228 print "<td>";
1229 print "</td>";
1230 print '<td class="right"></td>';
1231 print '<td class="right"></td>';
1232 print "</tr>";
1233
1234 $i++;
1235 continue;
1236 }
1237 if (isset($errorforinvoice[$key]) && $errorforinvoice[$key] == 'somelinesarenotbound') {
1238 print '<tr class="oddeven">';
1239 print "<!-- Some lines are not bound -->";
1240 print "<td>".$date."</td>";
1241 print "<td>".$invoicestatic->getNomUrl(1)."</td>";
1242 // Account
1243 print "<td>";
1244 print '<span class="error">'.$langs->trans('ErrorInvoiceContainsLinesNotYetBoundedShort', $val['ref']).'</span>';
1245 print '</td>';
1246 // Subledger account
1247 print "<td>";
1248 print '</td>';
1249 print "<td>";
1250 print "</td>";
1251 print '<td class="right"></td>';
1252 print '<td class="right"></td>';
1253 print "</tr>";
1254
1255 $i++;
1256 }
1257
1258 // Warranty
1259 if (getDolGlobalString('INVOICE_USE_RETAINED_WARRANTY') && isset($tabwarranty[$key]) && is_array($tabwarranty[$key])) {
1260 foreach ($tabwarranty[$key] as $k => $mt) {
1261 print '<tr class="oddeven">';
1262 print "<!-- Thirdparty warranty -->";
1263 print "<td>" . $date . "</td>";
1264 print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
1265 // Account
1266 print "<td>";
1267 $accountoshow = length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY'));
1268 if (($accountoshow == "") || $accountoshow == 'NotDefined') {
1269 print '<span class="error">' . $langs->trans("MainAccountForRetainedWarrantyNotDefined") . '</span>';
1270 } else {
1271 print $accountoshow;
1272 }
1273 print '</td>';
1274 // Subledger account
1275 print "<td>";
1276 $accountoshow = length_accounta($k);
1277 if (($accountoshow == "") || $accountoshow == 'NotDefined') {
1278 print '<span class="error">' . $langs->trans("ThirdpartyAccountNotDefined") . '</span>';
1279 } else {
1280 print $accountoshow;
1281 }
1282 print '</td>';
1283 print "<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0), $invoicestatic->ref, $langs->trans("RetainedWarranty"), 1) . "</td>";
1284 print '<td class="right nowraponall amount">' . ($mt >= 0 ? price($mt) : '') . "</td>";
1285 print '<td class="right nowraponall amount">' . ($mt < 0 ? price(-$mt) : '') . "</td>";
1286 print "</tr>";
1287 }
1288 }
1289
1290 // Third party
1291 foreach ($tabttc[$key] as $k => $mt) {
1292 print '<tr class="oddeven">';
1293 print "<!-- Thirdparty -->";
1294 print "<td>".$date."</td>";
1295 print "<td>".$invoicestatic->getNomUrl(1)."</td>";
1296 // Account
1297 print "<td>";
1298 $accountoshow = length_accountg($companystatic->accountancy_code_customer_general);
1299 if (($accountoshow == "") || $accountoshow == "-1" || $accountoshow == 'NotDefined') {
1300 print '<span class="error">'.$langs->trans("MainAccountForCustomersNotDefined").'</span>';
1301 } else {
1302 print $accountoshow;
1303 }
1304 print '</td>';
1305 // Subledger account
1306 print "<td>";
1307 $accountoshow = length_accounta($k);
1308 if (($accountoshow == "") || $accountoshow == 'NotDefined') {
1309 print '<span class="error">'.$langs->trans("ThirdpartyAccountNotDefined").'</span>';
1310 } else {
1311 print $accountoshow;
1312 }
1313 print '</td>';
1314 print "<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0, 'customer'), $invoicestatic->ref, $langs->trans("SubledgerAccount"), 1) . "</td>";
1315 print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
1316 print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
1317 print "</tr>";
1318
1319 $i++;
1320 }
1321
1322 // Product / Service
1323 foreach ($tabht[$key] as $k => $mt) {
1324 if (empty($conf->cache['accountingaccountincurrententity'][$k])) {
1325 $accountingaccount = new AccountingAccount($db);
1326 $accountingaccount->fetch(0, $k, true);
1327 $conf->cache['accountingaccountincurrententity'][$k] = $accountingaccount;
1328 } else {
1329 $accountingaccount = $conf->cache['accountingaccountincurrententity'][$k];
1330 }
1331
1332 print '<tr class="oddeven">';
1333 print "<!-- Product -->";
1334 print "<td>".$date."</td>";
1335 print "<td>".$invoicestatic->getNomUrl(1)."</td>";
1336 // Account
1337 print "<td>";
1338 $accountoshow = length_accountg($k);
1339 if (($accountoshow == "") || $accountoshow == 'NotDefined') {
1340 print '<span class="error">'.$langs->trans("ProductNotDefined").'</span>';
1341 } else {
1342 print $accountoshow;
1343 }
1344 print "</td>";
1345 // Subledger account
1346 print "<td>";
1347 if (getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT')) {
1348 if ($k == getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT')) {
1349 print length_accounta($tabcompany[$key]['code_compta']);
1350 }
1351 } elseif (($accountoshow == "") || $accountoshow == 'NotDefined') {
1352 print '<span class="error">' . $langs->trans("ThirdpartyAccountNotDefined") . '</span>';
1353 }
1354 print '</td>';
1355 $companystatic->id = $tabcompany[$key]['id'];
1356 $companystatic->name = $tabcompany[$key]['name'];
1357 print "<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0, 'customer'), $invoicestatic->ref, $accountingaccount->label, 1) . "</td>";
1358 print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
1359 print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
1360 print "</tr>";
1361
1362 $i++;
1363 }
1364
1365 // VAT
1366 $listoftax = array(0, 1, 2);
1367 foreach ($listoftax as $numtax) {
1368 $arrayofvat = $tabtva;
1369 if ($numtax == 1) {
1370 $arrayofvat = $tablocaltax1;
1371 }
1372 if ($numtax == 2) {
1373 $arrayofvat = $tablocaltax2;
1374 }
1375
1376 // $key is id of invoice
1377 foreach ($arrayofvat[$key] as $k => $mt) {
1378 if ($mt) {
1379 print '<tr class="oddeven">';
1380 print "<!-- VAT -->";
1381 print "<td>".$date."</td>";
1382 print "<td>".$invoicestatic->getNomUrl(1)."</td>";
1383 // Account
1384 print "<td>";
1385 $accountoshow = length_accountg($k);
1386 if (($accountoshow == "") || $accountoshow == 'NotDefined') {
1387 print '<span class="error">'.$langs->trans("VATAccountNotDefined").' ('.$langs->trans("AccountingJournalType2").')</span>';
1388 } else {
1389 print $accountoshow;
1390 }
1391 print "</td>";
1392 // Subledger account
1393 print "<td>";
1394 print '</td>';
1395 // $def_tva is array[invoiceid][accountancy_code_sell_of_vat_rate_found][vatrate]=vatrate
1396 //var_dump($arrayofvat[$key]); //var_dump($key); //var_dump($k);
1397 $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ? '' : $arrayofvat[$key][$k]) : implode(', ', $def_tva[$key][$k]));
1398 $labelvatrate = $langs->trans("Taxes").' '.$tmpvatrate.' %';
1399 $labelvatrate .= ($numtax ? ' - Localtax '.$numtax : '');
1400 print "<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0, 'customer'), $invoicestatic->ref, $labelvatrate, 1) . "</td>";
1401 print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
1402 print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
1403 print "</tr>";
1404
1405 $i++;
1406 }
1407 }
1408 }
1409
1410 // Revenue stamp
1411 if (isset($tabrevenuestamp[$key]) && is_array($tabrevenuestamp[$key])) {
1412 foreach ($tabrevenuestamp[$key] as $k => $mt) {
1413 print '<tr class="oddeven">';
1414 print "<!-- Thirdparty revenuestamp -->";
1415 print "<td>" . $date . "</td>";
1416 print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
1417 // Account
1418 print "<td>";
1419 $accountoshow = length_accountg($k);
1420 if (($accountoshow == "") || $accountoshow == 'NotDefined') {
1421 print '<span class="error">' . $langs->trans("MainAccountForRevenueStampSaleNotDefined") . '</span>';
1422 } else {
1423 print $accountoshow;
1424 }
1425 print '</td>';
1426 // Subledger account
1427 print "<td>";
1428 print '</td>';
1429 print "<td>" . $bookkeepingstatic->accountingLabelForOperation($companystatic->getNomUrl(0, 'customer'), $invoicestatic->ref, $langs->trans("RevenueStamp"), 1) . "</td>";
1430 print '<td class="right nowraponall amount">' . ($mt < 0 ? price(-$mt) : '') . "</td>";
1431 print '<td class="right nowraponall amount">' . ($mt >= 0 ? price($mt) : '') . "</td>";
1432 print "</tr>";
1433 }
1434 }
1435 }
1436
1437 if (!$i) {
1438 print '<tr class="oddeven"><td colspan="7"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1439 }
1440
1441 print "</table>";
1442 print '</div>';
1443
1444 // End of page
1445 llxFooter();
1446}
1447
1448$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:87
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:71
Class to manage accounting accounts.
Class to manage accounting journals.
Class to manage Ledger (General Ledger and Subledger)
Class to manage customers or prospects.
Class to manage invoices.
const TYPE_REPLACEMENT
Replacement invoice.
const TYPE_SITUATION
Situation invoice.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage invoice lines.
Class to manage generation of HTML components Only common components must be here.
Class Lettering.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:600
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:619
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
getTaxesFromId($vatrate, $buyer=null, $seller=null, $firstparamisid=1)
Get tax (VAT) main information from Id.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.