dolibarr  x.y.z
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-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
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-2021 Frédéric France <frederic.france@netlogic.fr>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program. If not, see <https://www.gnu.org/licenses/>.
25  */
26 
33 // Load Dolibarr environment
34 require '../../main.inc.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php';
43 
44 // Load translation files required by the page
45 $langs->loadLangs(array("commercial", "compta", "bills", "other", "accountancy", "errors"));
46 
47 $id_journal = GETPOST('id_journal', 'int');
48 $action = GETPOST('action', 'aZ09');
49 
50 $date_startmonth = GETPOST('date_startmonth');
51 $date_startday = GETPOST('date_startday');
52 $date_startyear = GETPOST('date_startyear');
53 $date_endmonth = GETPOST('date_endmonth');
54 $date_endday = GETPOST('date_endday');
55 $date_endyear = GETPOST('date_endyear');
56 $in_bookkeeping = GETPOST('in_bookkeeping');
57 if ($in_bookkeeping == '') {
58  $in_bookkeeping = 'notyet';
59 }
60 
61 $now = dol_now();
62 
63 $hookmanager->initHooks(array('sellsjournal'));
64 $parameters = array();
65 
66 // Security check
67 if (!isModEnabled('accounting')) {
69 }
70 if ($user->socid > 0) {
72 }
73 if (empty($user->rights->accounting->mouvements->lire)) {
75 }
76 
77 
78 /*
79  * Actions
80  */
81 
82 $reshook = $hookmanager->executeHooks('doActions', $parameters, $user, $action); // Note that $action and $object may have been modified by some hooks
83 
84 $accountingaccount = new AccountingAccount($db);
85 
86 // Get informations of journal
87 $accountingjournalstatic = new AccountingJournal($db);
88 $accountingjournalstatic->fetch($id_journal);
89 $journal = $accountingjournalstatic->code;
90 $journal_label = $accountingjournalstatic->label;
91 
92 $date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
93 $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
94 
95 if (empty($date_startmonth) || empty($date_endmonth)) {
96  // Period by default on transfer
97  $dates = getDefaultDatesForTransfer();
98  $date_start = $dates['date_start'];
99  $date_end = $dates['date_end'];
100  $pastmonthyear = $dates['pastmonthyear'];
101  $pastmonth = $dates['pastmonth'];
102 }
103 
104 if (!GETPOSTISSET('date_startmonth') && (empty($date_start) || empty($date_end))) { // We define date_start and date_end, only if we did not submit the form
105  $date_start = dol_get_first_day($pastmonthyear, $pastmonth, false);
106  $date_end = dol_get_last_day($pastmonthyear, $pastmonth, false);
107 }
108 
109 $sql = "SELECT f.rowid, f.ref, f.type, f.datef as df, f.ref_client, f.date_lim_reglement as dlr, f.close_code,";
110 $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,";
111 $sql .= " s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur,";
112 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
113  $sql .= " spe.accountancy_code_customer as code_compta,";
114  $sql .= " spe.accountancy_code_supplier as code_compta_fournisseur,";
115 } else {
116  $sql .= " s.code_compta as code_compta,";
117  $sql .= " s.code_compta_fournisseur,";
118 }
119 $sql .= " p.rowid as pid, p.ref as pref, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte,";
120 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
121  $sql .= " ppe.accountancy_code_sell";
122 } else {
123  $sql .= " p.accountancy_code_sell";
124 }
125 $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd";
126 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = fd.fk_product";
127 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
128  $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
129 }
130 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
131 $sql .= " JOIN ".MAIN_DB_PREFIX."facture as f ON f.rowid = fd.fk_facture";
132 $sql .= " JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
133 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
134  $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
135 }
136 $sql .= " WHERE fd.fk_code_ventilation > 0";
137 $sql .= " AND f.entity IN (".getEntity('invoice', 0).')'; // We don't share object for accountancy, we use source object sharing
138 $sql .= " AND f.fk_statut > 0";
139 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { // Non common setup
140  $sql .= " AND f.type IN (".Facture::TYPE_STANDARD.",".Facture::TYPE_REPLACEMENT.",".Facture::TYPE_CREDIT_NOTE.",".Facture::TYPE_SITUATION.")";
141 } else {
142  $sql .= " AND f.type IN (".Facture::TYPE_STANDARD.",".Facture::TYPE_REPLACEMENT.",".Facture::TYPE_CREDIT_NOTE.",".Facture::TYPE_DEPOSIT.",".Facture::TYPE_SITUATION.")";
143 }
144 $sql .= " AND fd.product_type IN (0,1)";
145 if ($date_start && $date_end) {
146  $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
147 }
148 // Define begin binding date
149 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
150  $sql .= " AND f.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING)."'";
151 }
152 // Already in bookkeeping or not
153 if ($in_bookkeeping == 'already') {
154  $sql .= " AND f.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')";
155  // $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
156 }
157 if ($in_bookkeeping == 'notyet') {
158  $sql .= " AND f.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')";
159  // $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
160 }
161 $sql .= " ORDER BY f.datef";
162 //print $sql; exit;
163 
164 dol_syslog('accountancy/journal/sellsjournal.php', LOG_DEBUG);
165 $result = $db->query($sql);
166 if ($result) {
167  $tabfac = array();
168  $tabht = array();
169  $tabtva = array();
170  $def_tva = array();
171  $tabttc = array();
172  $tablocaltax1 = array();
173  $tablocaltax2 = array();
174  $tabcompany = array();
175 
176  $num = $db->num_rows($result);
177 
178  // Variables
179  $cptcli = (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER != "")) ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : 'NotDefined';
180  $cpttva = (!empty($conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT : 'NotDefined';
181 
182  $i = 0;
183  while ($i < $num) {
184  $obj = $db->fetch_object($result);
185 
186  // Controls
187  $compta_soc = (!empty($obj->code_compta)) ? $obj->code_compta : $cptcli;
188 
189  $compta_prod = $obj->compte;
190  if (empty($compta_prod)) {
191  if ($obj->product_type == 0) {
192  $compta_prod = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : 'NotDefined';
193  } else {
194  $compta_prod = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : 'NotDefined';
195  }
196  }
197 
198  $vatdata = getTaxesFromId($obj->tva_tx.($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''), $mysoc, $mysoc, 0);
199  $compta_tva = (!empty($vatdata['accountancy_code_sell']) ? $vatdata['accountancy_code_sell'] : $cpttva);
200  $compta_localtax1 = (!empty($vatdata['accountancy_code_sell']) ? $vatdata['accountancy_code_sell'] : $cpttva);
201  $compta_localtax2 = (!empty($vatdata['accountancy_code_sell']) ? $vatdata['accountancy_code_sell'] : $cpttva);
202 
203  // Define array to display all VAT rates that use this accounting account $compta_tva
204  if (price2num($obj->tva_tx) || !empty($obj->vat_src_code)) {
205  $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.')' : ''));
206  }
207 
208  $line = new FactureLigne($db);
209  $line->fetch($obj->fdid);
210 
211  // Situation invoices handling
212  $prev_progress = $line->get_prev_progress($obj->rowid);
213 
214  if ($obj->type == Facture::TYPE_SITUATION) {
215  // Avoid divide by 0
216  if ($obj->situation_percent == 0) {
217  $situation_ratio = 0;
218  } else {
219  $situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent;
220  }
221  } else {
222  $situation_ratio = 1;
223  }
224 
225  // Invoice lines
226  $tabfac[$obj->rowid]["date"] = $db->jdate($obj->df);
227  $tabfac[$obj->rowid]["datereg"] = $db->jdate($obj->dlr);
228  $tabfac[$obj->rowid]["ref"] = $obj->ref;
229  $tabfac[$obj->rowid]["type"] = $obj->type;
230  $tabfac[$obj->rowid]["description"] = $obj->label_compte;
231  $tabfac[$obj->rowid]["close_code"] = $obj->close_code; // close_code = 'replaced' for replacement invoices (not used in most european countries)
232  //$tabfac[$obj->rowid]["fk_facturedet"] = $obj->fdid;
233 
234  // Avoid warnings
235  if (!isset($tabttc[$obj->rowid][$compta_soc])) {
236  $tabttc[$obj->rowid][$compta_soc] = 0;
237  }
238  if (!isset($tabht[$obj->rowid][$compta_prod])) {
239  $tabht[$obj->rowid][$compta_prod] = 0;
240  }
241  if (!isset($tabtva[$obj->rowid][$compta_tva])) {
242  $tabtva[$obj->rowid][$compta_tva] = 0;
243  }
244  if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
245  $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
246  }
247  if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
248  $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
249  }
250 
251  $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc * $situation_ratio;
252  $tabht[$obj->rowid][$compta_prod] += $obj->total_ht * $situation_ratio;
253  if (empty($line->tva_npr)) {
254  $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio; // We ignore line if VAT is a NPR
255  }
256  $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1 * $situation_ratio;
257  $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2 * $situation_ratio;
258  $tabcompany[$obj->rowid] = array(
259  'id' => $obj->socid,
260  'name' => $obj->name,
261  'code_client' => $obj->code_client,
262  'code_compta' => $compta_soc
263  );
264 
265  $i++;
266  }
267 } else {
268  dol_print_error($db);
269 }
270 
271 $errorforinvoice = array();
272 
273 // Loop in invoices to detect lines with not binding lines
274 foreach ($tabfac as $key => $val) { // Loop on each invoice
275  $sql = "SELECT COUNT(fd.rowid) as nb";
276  $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd";
277  $sql .= " WHERE fd.product_type <= 2 AND fd.fk_code_ventilation <= 0";
278  $sql .= " AND fd.total_ttc <> 0 AND fk_facture = ".((int) $key);
279  $resql = $db->query($sql);
280  if ($resql) {
281  $obj = $db->fetch_object($resql);
282  if ($obj->nb > 0) {
283  $errorforinvoice[$key] = 'somelinesarenotbound';
284  }
285  } else {
286  dol_print_error($db);
287  }
288 }
289 //var_dump($errorforinvoice);exit;
290 
291 
292 // Bookkeeping Write
293 if ($action == 'writebookkeeping') {
294  $now = dol_now();
295  $error = 0;
296 
297  $companystatic = new Societe($db);
298  $invoicestatic = new Facture($db);
299  $accountingaccountcustomer = new AccountingAccount($db);
300 
301  $accountingaccountcustomer->fetch(null, $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER, true);
302 
303  foreach ($tabfac as $key => $val) { // Loop on each invoice
304  $errorforline = 0;
305 
306  $totalcredit = 0;
307  $totaldebit = 0;
308 
309  $db->begin();
310 
311  $companystatic->id = $tabcompany[$key]['id'];
312  $companystatic->name = $tabcompany[$key]['name'];
313  $companystatic->code_compta = $tabcompany[$key]['code_compta'];
314  $companystatic->code_client = $tabcompany[$key]['code_client'];
315  $companystatic->client = 3;
316 
317  $invoicestatic->id = $key;
318  $invoicestatic->ref = (string) $val["ref"];
319  $invoicestatic->type = $val["type"];
320  $invoicestatic->close_code = $val["close_code"];
321 
322  $date = dol_print_date($val["date"], 'day');
323 
324  // Is it a replaced invoice ? 0=not a replaced invoice, 1=replaced invoice not yet dispatched, 2=replaced invoice dispatched
325  $replacedinvoice = 0;
326  if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
327  $replacedinvoice = 1;
328  $alreadydispatched = $invoicestatic->getVentilExportCompta(); // Test if replaced invoice already into bookkeeping.
329  if ($alreadydispatched) {
330  $replacedinvoice = 2;
331  }
332  }
333 
334  // 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)
335  if ($replacedinvoice == 1) {
336  $db->rollback();
337  continue;
338  }
339 
340  // Error if some lines are not binded/ready to be journalized
341  if ($errorforinvoice[$key] == 'somelinesarenotbound') {
342  $error++;
343  $errorforline++;
344  setEventMessages($langs->trans('ErrorInvoiceContainsLinesNotYetBounded', $val['ref']), null, 'errors');
345  }
346 
347  // Thirdparty
348  if (!$errorforline) {
349  foreach ($tabttc[$key] as $k => $mt) {
350  $bookkeeping = new BookKeeping($db);
351  $bookkeeping->doc_date = $val["date"];
352  $bookkeeping->date_lim_reglement = $val["datereg"];
353  $bookkeeping->doc_ref = $val["ref"];
354  $bookkeeping->date_creation = $now;
355  $bookkeeping->doc_type = 'customer_invoice';
356  $bookkeeping->fk_doc = $key;
357  $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
358  $bookkeeping->thirdparty_code = $companystatic->code_client;
359 
360  $bookkeeping->subledger_account = $tabcompany[$key]['code_compta'];
361  $bookkeeping->subledger_label = $tabcompany[$key]['name'];
362 
363  $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
364  $bookkeeping->label_compte = $accountingaccountcustomer->label;
365 
366  $bookkeeping->label_operation = dol_trunc($companystatic->name, 16).' - '.$invoicestatic->ref.' - '.$langs->trans("SubledgerAccount");
367  $bookkeeping->montant = $mt;
368  $bookkeeping->sens = ($mt >= 0) ? 'D' : 'C';
369  $bookkeeping->debit = ($mt >= 0) ? $mt : 0;
370  $bookkeeping->credit = ($mt < 0) ? -$mt : 0;
371  $bookkeeping->code_journal = $journal;
372  $bookkeeping->journal_label = $langs->transnoentities($journal_label);
373  $bookkeeping->fk_user_author = $user->id;
374  $bookkeeping->entity = $conf->entity;
375 
376  $totaldebit += $bookkeeping->debit;
377  $totalcredit += $bookkeeping->credit;
378 
379  $result = $bookkeeping->create($user);
380  if ($result < 0) {
381  if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists
382  $error++;
383  $errorforline++;
384  $errorforinvoice[$key] = 'alreadyjournalized';
385  //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
386  } else {
387  $error++;
388  $errorforline++;
389  $errorforinvoice[$key] = 'other';
390  setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
391  }
392  } else {
393  if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING')) {
394  require_once DOL_DOCUMENT_ROOT . '/accountancy/class/lettering.class.php';
395  $lettering_static = new Lettering($db);
396  $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id));
397  }
398  }
399  }
400  }
401 
402  // Product / Service
403  if (!$errorforline) {
404  foreach ($tabht[$key] as $k => $mt) {
405  $resultfetch = $accountingaccount->fetch(null, $k, true); // TODO Use a cache
406  $label_account = $accountingaccount->label;
407 
408  // get compte id and label
409  if ($resultfetch > 0) {
410  $bookkeeping = new BookKeeping($db);
411  $bookkeeping->doc_date = $val["date"];
412  $bookkeeping->date_lim_reglement = $val["datereg"];
413  $bookkeeping->doc_ref = $val["ref"];
414  $bookkeeping->date_creation = $now;
415  $bookkeeping->doc_type = 'customer_invoice';
416  $bookkeeping->fk_doc = $key;
417  $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
418  $bookkeeping->thirdparty_code = $companystatic->code_client;
419 
420  if (!empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT)) {
421  if ($k == getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT')) {
422  $bookkeeping->subledger_account = $tabcompany[$key]['code_compta'];
423  $bookkeeping->subledger_label = $tabcompany[$key]['name'];
424  } else {
425  $bookkeeping->subledger_account = '';
426  $bookkeeping->subledger_label = '';
427  }
428  } else {
429  $bookkeeping->subledger_account = '';
430  $bookkeeping->subledger_label = '';
431  }
432 
433  $bookkeeping->numero_compte = $k;
434  $bookkeeping->label_compte = $label_account;
435 
436  $bookkeeping->label_operation = dol_trunc($companystatic->name, 16).' - '.$invoicestatic->ref.' - '.$label_account;
437  $bookkeeping->montant = $mt;
438  $bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
439  $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
440  $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
441  $bookkeeping->code_journal = $journal;
442  $bookkeeping->journal_label = $langs->transnoentities($journal_label);
443  $bookkeeping->fk_user_author = $user->id;
444  $bookkeeping->entity = $conf->entity;
445 
446  $totaldebit += $bookkeeping->debit;
447  $totalcredit += $bookkeeping->credit;
448 
449  $result = $bookkeeping->create($user);
450  if ($result < 0) {
451  if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists
452  $error++;
453  $errorforline++;
454  $errorforinvoice[$key] = 'alreadyjournalized';
455  //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
456  } else {
457  $error++;
458  $errorforline++;
459  $errorforinvoice[$key] = 'other';
460  setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
461  }
462  }
463  }
464  }
465  }
466 
467  // VAT
468  if (!$errorforline) {
469  $listoftax = array(0, 1, 2);
470  foreach ($listoftax as $numtax) {
471  $arrayofvat = $tabtva;
472  if ($numtax == 1) {
473  $arrayofvat = $tablocaltax1;
474  }
475  if ($numtax == 2) {
476  $arrayofvat = $tablocaltax2;
477  }
478 
479  foreach ($arrayofvat[$key] as $k => $mt) {
480  if ($mt) {
481  $accountingaccount->fetch(null, $k, true); // TODO Use a cache for label
482  $label_account = $accountingaccount->label;
483 
484  $bookkeeping = new BookKeeping($db);
485  $bookkeeping->doc_date = $val["date"];
486  $bookkeeping->date_lim_reglement = $val["datereg"];
487  $bookkeeping->doc_ref = $val["ref"];
488  $bookkeeping->date_creation = $now;
489  $bookkeeping->doc_type = 'customer_invoice';
490  $bookkeeping->fk_doc = $key;
491  $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
492  $bookkeeping->thirdparty_code = $companystatic->code_client;
493 
494  $bookkeeping->subledger_account = '';
495  $bookkeeping->subledger_label = '';
496 
497  $bookkeeping->numero_compte = $k;
498  $bookkeeping->label_compte = $label_account;
499 
500  $bookkeeping->label_operation = dol_trunc($companystatic->name, 16).' - '.$invoicestatic->ref.' - '.$langs->trans("VAT").' '.join(', ', $def_tva[$key][$k]).' %'.($numtax ? ' - Localtax '.$numtax : '');
501  $bookkeeping->montant = $mt;
502  $bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
503  $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
504  $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
505  $bookkeeping->code_journal = $journal;
506  $bookkeeping->journal_label = $langs->transnoentities($journal_label);
507  $bookkeeping->fk_user_author = $user->id;
508  $bookkeeping->entity = $conf->entity;
509 
510  $totaldebit += $bookkeeping->debit;
511  $totalcredit += $bookkeeping->credit;
512 
513  $result = $bookkeeping->create($user);
514  if ($result < 0) {
515  if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists
516  $error++;
517  $errorforline++;
518  $errorforinvoice[$key] = 'alreadyjournalized';
519  //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
520  } else {
521  $error++;
522  $errorforline++;
523  $errorforinvoice[$key] = 'other';
524  setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
525  }
526  }
527  }
528  }
529  }
530  }
531 
532  // Protection against a bug on lines before
533  if (!$errorforline && (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT'))) {
534  $error++;
535  $errorforline++;
536  $errorforinvoice[$key] = 'amountsnotbalanced';
537  setEventMessages('Try to insert a non balanced transaction in book for '.$invoicestatic->ref.'. Canceled. Surely a bug.', null, 'errors');
538  }
539 
540  if (!$errorforline) {
541  $db->commit();
542  } else {
543  $db->rollback();
544 
545  if ($error >= 10) {
546  setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped"), null, 'errors');
547  break; // Break in the foreach
548  }
549  }
550  }
551 
552  $tabpay = $tabfac;
553 
554  if (empty($error) && count($tabpay) > 0) {
555  setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
556  } elseif (count($tabpay) == $error) {
557  setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings');
558  } else {
559  setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings');
560  }
561 
562  $action = '';
563 
564  // Must reload data, so we make a redirect
565  if (count($tabpay) != $error) {
566  $param = 'id_journal='.$id_journal;
567  $param .= '&date_startday='.$date_startday;
568  $param .= '&date_startmonth='.$date_startmonth;
569  $param .= '&date_startyear='.$date_startyear;
570  $param .= '&date_endday='.$date_endday;
571  $param .= '&date_endmonth='.$date_endmonth;
572  $param .= '&date_endyear='.$date_endyear;
573  $param .= '&in_bookkeeping='.$in_bookkeeping;
574  header("Location: ".$_SERVER['PHP_SELF'].($param ? '?'.$param : ''));
575  exit;
576  }
577 }
578 
579 
580 
581 /*
582  * View
583  */
584 
585 $form = new Form($db);
586 
587 // Export
588 if ($action == 'exportcsv') { // ISO and not UTF8 !
589  $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
590 
591  $filename = 'journal';
592  $type_export = 'journal';
593  include DOL_DOCUMENT_ROOT.'/accountancy/tpl/export_journal.tpl.php';
594 
595  $companystatic = new Client($db);
596  $invoicestatic = new Facture($db);
597 
598  foreach ($tabfac as $key => $val) {
599  $companystatic->id = $tabcompany[$key]['id'];
600  $companystatic->name = $tabcompany[$key]['name'];
601  $companystatic->code_compta = $tabcompany[$key]['code_compta'];
602  $companystatic->code_client = $tabcompany[$key]['code_client'];
603  $companystatic->client = 3;
604 
605  $invoicestatic->id = $key;
606  $invoicestatic->ref = (string) $val["ref"];
607  $invoicestatic->type = $val["type"];
608  $invoicestatic->close_code = $val["close_code"];
609 
610  $date = dol_print_date($val["date"], 'day');
611 
612  // Is it a replaced invoice ? 0=not a replaced invoice, 1=replaced invoice not yet dispatched, 2=replaced invoice dispatched
613  $replacedinvoice = 0;
614  if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
615  $replacedinvoice = 1;
616  $alreadydispatched = $invoicestatic->getVentilExportCompta(); // Test if replaced invoice already into bookkeeping.
617  if ($alreadydispatched) {
618  $replacedinvoice = 2;
619  }
620  }
621 
622  // 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)
623  if ($replacedinvoice == 1) {
624  continue;
625  }
626 
627  // Third party
628  foreach ($tabttc[$key] as $k => $mt) {
629  //if ($mt) {
630  print '"'.$key.'"'.$sep;
631  print '"'.$date.'"'.$sep;
632  print '"'.$val["ref"].'"'.$sep;
633  print '"'.utf8_decode(dol_trunc($companystatic->name, 32)).'"'.$sep;
634  print '"'.length_accounta(html_entity_decode($k)).'"'.$sep;
635  print '"'.length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER).'"'.$sep;
636  print '"'.length_accounta(html_entity_decode($k)).'"'.$sep;
637  print '"'.$langs->trans("Thirdparty").'"'.$sep;
638  print '"'.utf8_decode(dol_trunc($companystatic->name, 16)).' - '.$invoicestatic->ref.' - '.$langs->trans("Thirdparty").'"'.$sep;
639  print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
640  print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
641  print '"'.$journal.'"';
642  print "\n";
643  //}
644  }
645 
646  // Product / Service
647  foreach ($tabht[$key] as $k => $mt) {
648  $accountingaccount = new AccountingAccount($db);
649  $accountingaccount->fetch(null, $k, true);
650  //if ($mt) {
651  print '"'.$key.'"'.$sep;
652  print '"'.$date.'"'.$sep;
653  print '"'.$val["ref"].'"'.$sep;
654  print '"'.utf8_decode(dol_trunc($companystatic->name, 32)).'"'.$sep;
655  print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
656  print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
657  print '""'.$sep;
658  print '"'.utf8_decode(dol_trunc($accountingaccount->label, 32)).'"'.$sep;
659  print '"'.utf8_decode(dol_trunc($companystatic->name, 16)).' - '.dol_trunc($accountingaccount->label, 32).'"'.$sep;
660  print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
661  print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
662  print '"'.$journal.'"';
663  print "\n";
664  //}
665  }
666 
667  // VAT
668  $listoftax = array(0, 1, 2);
669  foreach ($listoftax as $numtax) {
670  $arrayofvat = $tabtva;
671  if ($numtax == 1) {
672  $arrayofvat = $tablocaltax1;
673  }
674  if ($numtax == 2) {
675  $arrayofvat = $tablocaltax2;
676  }
677 
678  foreach ($arrayofvat[$key] as $k => $mt) {
679  if ($mt) {
680  print '"'.$key.'"'.$sep;
681  print '"'.$date.'"'.$sep;
682  print '"'.$val["ref"].'"'.$sep;
683  print '"'.utf8_decode(dol_trunc($companystatic->name, 32)).'"'.$sep;
684  print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
685  print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
686  print '""'.$sep;
687  print '"'.$langs->trans("VAT").' - '.join(', ', $def_tva[$key][$k]).' %"'.$sep;
688  print '"'.utf8_decode(dol_trunc($companystatic->name, 16)).' - '.$invoicestatic->ref.' - '.$langs->trans("VAT").join(', ', $def_tva[$key][$k]).' %'.($numtax ? ' - Localtax '.$numtax : '').'"'.$sep;
689  print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
690  print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
691  print '"'.$journal.'"';
692  print "\n";
693  }
694  }
695  }
696  }
697 }
698 
699 
700 
701 if (empty($action) || $action == 'view') {
702  $title = $langs->trans("GenerationOfAccountingEntries").' - '.$accountingjournalstatic->getNomUrl(0, 2, 1, '', 1);
703 
704  llxHeader('', dol_string_nohtmltag($title));
705 
706  $nom = $title;
707  $nomlink = '';
708  $periodlink = '';
709  $exportlink = '';
710  $builddate = dol_now();
711  $description = $langs->trans("DescJournalOnlyBindedVisible").'<br>';
712  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
713  $description .= $langs->trans("DepositsAreNotIncluded");
714  } else {
715  $description .= $langs->trans("DepositsAreIncluded");
716  }
717 
718  $listofchoices = array('notyet'=>$langs->trans("NotYetInGeneralLedger"), 'already'=>$langs->trans("AlreadyInGeneralLedger"));
719  $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);
720  $period .= ' - '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
721 
722  $varlink = 'id_journal='.$id_journal;
723 
724  journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink);
725 
726  // Button to write into Ledger
727  if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == "") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1') {
728  print '<br><div class="warning">'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone");
729  $desc = ' : '.$langs->trans("AccountancyAreaDescMisc", 4, '{link}');
730  $desc = str_replace('{link}', '<strong>'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'</strong>', $desc);
731  print $desc;
732  print '</div>';
733  }
734  print '<div class="tabsAction tabsActionNoBottom centerimp">';
735  if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping == 'notyet') {
736  print '<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans("ExportDraftJournal").'" onclick="launch_export();" />';
737  }
738  if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == "") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1') {
739  print '<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("SomeMandatoryStepsOfSetupWereNotDone")).'" value="'.$langs->trans("WriteBookKeeping").'" />';
740  } else {
741  if ($in_bookkeeping == 'notyet') {
742  print '<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans("WriteBookKeeping").'" onclick="writebookkeeping();" />';
743  } else {
744  print '<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans("WriteBookKeeping").'</a>';
745  }
746  }
747  print '</div>';
748 
749  // TODO Avoid using js. We can use a direct link with $param
750  print '
751  <script type="text/javascript">
752  function launch_export() {
753  $("div.fiche form input[name=\"action\"]").val("exportcsv");
754  $("div.fiche form input[type=\"submit\"]").click();
755  $("div.fiche form input[name=\"action\"]").val("");
756  }
757  function writebookkeeping() {
758  console.log("click on writebookkeeping");
759  $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
760  $("div.fiche form input[type=\"submit\"]").click();
761  $("div.fiche form input[name=\"action\"]").val("");
762  }
763  </script>';
764 
765  /*
766  * Show result array
767  */
768  print '<br>';
769 
770  $i = 0;
771  print '<div class="div-table-responsive">';
772  print "<table class=\"noborder\" width=\"100%\">";
773  print "<tr class=\"liste_titre\">";
774  print "<td>".$langs->trans("Date")."</td>";
775  print "<td>".$langs->trans("Piece").' ('.$langs->trans("InvoiceRef").")</td>";
776  print "<td>".$langs->trans("AccountAccounting")."</td>";
777  print "<td>".$langs->trans("SubledgerAccount")."</td>";
778  print "<td>".$langs->trans("LabelOperation")."</td>";
779  print '<td class="center">'.$langs->trans("AccountingDebit")."</td>";
780  print '<td class="center">'.$langs->trans("AccountingCredit")."</td>";
781  print "</tr>\n";
782 
783  $r = '';
784 
785  $companystatic = new Client($db);
786  $invoicestatic = new Facture($db);
787 
788  foreach ($tabfac as $key => $val) {
789  $companystatic->id = $tabcompany[$key]['id'];
790  $companystatic->name = $tabcompany[$key]['name'];
791  $companystatic->code_compta = $tabcompany[$key]['code_compta'];
792  $companystatic->code_client = $tabcompany[$key]['code_client'];
793  $companystatic->client = 3;
794 
795  $invoicestatic->id = $key;
796  $invoicestatic->ref = (string) $val["ref"];
797  $invoicestatic->type = $val["type"];
798  $invoicestatic->close_code = $val["close_code"];
799 
800  $date = dol_print_date($val["date"], 'day');
801 
802  // Is it a replaced invoice ? 0=not a replaced invoice, 1=replaced invoice not yet dispatched, 2=replaced invoice dispatched
803  $replacedinvoice = 0;
804  if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
805  $replacedinvoice = 1;
806  $alreadydispatched = $invoicestatic->getVentilExportCompta(); // Test if replaced invoice already into bookkeeping.
807  if ($alreadydispatched) {
808  $replacedinvoice = 2;
809  }
810  }
811 
812  // If not already into bookkeeping, we won't add it, if yes, add the counterpart ???.
813  if ($replacedinvoice == 1) {
814  print '<tr class="oddeven">';
815  print "<!-- Replaced invoice -->";
816  print "<td>".$date."</td>";
817  print "<td><strike>".$invoicestatic->getNomUrl(1)."</strike></td>";
818  // Account
819  print "<td>";
820  print $langs->trans("Replaced");
821  print '</td>';
822  // Subledger account
823  print "<td>";
824  print '</td>';
825  print "<td>";
826  print "</td>";
827  print '<td class="right"></td>';
828  print '<td class="right"></td>';
829  print "</tr>";
830 
831  continue;
832  }
833  if ($errorforinvoice[$key] == 'somelinesarenotbound') {
834  print '<tr class="oddeven">';
835  print "<!-- Some lines are not bound -->";
836  print "<td>".$date."</td>";
837  print "<td>".$invoicestatic->getNomUrl(1)."</td>";
838  // Account
839  print "<td>";
840  print '<span class="error">'.$langs->trans('ErrorInvoiceContainsLinesNotYetBoundedShort', $val['ref']).'</span>';
841  print '</td>';
842  // Subledger account
843  print "<td>";
844  print '</td>';
845  print "<td>";
846  print "</td>";
847  print '<td class="right"></td>';
848  print '<td class="right"></td>';
849  print "</tr>";
850  }
851 
852  // Third party
853  foreach ($tabttc[$key] as $k => $mt) {
854  print '<tr class="oddeven">';
855  print "<!-- Thirdparty -->";
856  print "<td>".$date."</td>";
857  print "<td>".$invoicestatic->getNomUrl(1)."</td>";
858  // Account
859  print "<td>";
860  $accountoshow = length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER);
861  if (($accountoshow == "") || $accountoshow == 'NotDefined') {
862  print '<span class="error">'.$langs->trans("MainAccountForCustomersNotDefined").'</span>';
863  } else {
864  print $accountoshow;
865  }
866  print '</td>';
867  // Subledger account
868  print "<td>";
869  $accountoshow = length_accounta($k);
870  if (($accountoshow == "") || $accountoshow == 'NotDefined') {
871  print '<span class="error">'.$langs->trans("ThirdpartyAccountNotDefined").'</span>';
872  } else {
873  print $accountoshow;
874  }
875  print '</td>';
876  print "<td>".$companystatic->getNomUrl(0, 'customer', 16).' - '.$invoicestatic->ref.' - '.$langs->trans("SubledgerAccount")."</td>";
877  print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
878  print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
879  print "</tr>";
880  }
881 
882  // Product / Service
883  foreach ($tabht[$key] as $k => $mt) {
884  $accountingaccount = new AccountingAccount($db);
885  $accountingaccount->fetch(null, $k, true);
886 
887  print '<tr class="oddeven">';
888  print "<!-- Product -->";
889  print "<td>".$date."</td>";
890  print "<td>".$invoicestatic->getNomUrl(1)."</td>";
891  // Account
892  print "<td>";
893  $accountoshow = length_accountg($k);
894  if (($accountoshow == "") || $accountoshow == 'NotDefined') {
895  print '<span class="error">'.$langs->trans("ProductNotDefined").'</span>';
896  } else {
897  print $accountoshow;
898  }
899  print "</td>";
900  // Subledger account
901  print "<td>";
902  if (!empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT)) {
903  if ($k == getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT')) {
904  print length_accounta($tabcompany[$key]['code_compta']);
905  }
906  } elseif (($accountoshow == "") || $accountoshow == 'NotDefined') {
907  print '<span class="error">' . $langs->trans("ThirdpartyAccountNotDefined") . '</span>';
908  }
909  print '</td>';
910  $companystatic->id = $tabcompany[$key]['id'];
911  $companystatic->name = $tabcompany[$key]['name'];
912  print "<td>".$companystatic->getNomUrl(0, 'customer', 16).' - '.$invoicestatic->ref.' - '.$accountingaccount->label."</td>";
913  print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
914  print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
915  print "</tr>";
916  }
917 
918  // VAT
919  $listoftax = array(0, 1, 2);
920  foreach ($listoftax as $numtax) {
921  $arrayofvat = $tabtva;
922  if ($numtax == 1) {
923  $arrayofvat = $tablocaltax1;
924  }
925  if ($numtax == 2) {
926  $arrayofvat = $tablocaltax2;
927  }
928 
929  foreach ($arrayofvat[$key] as $k => $mt) {
930  if ($mt) {
931  print '<tr class="oddeven">';
932  print "<!-- VAT -->";
933  print "<td>".$date."</td>";
934  print "<td>".$invoicestatic->getNomUrl(1)."</td>";
935  // Account
936  print "<td>";
937  $accountoshow = length_accountg($k);
938  if (($accountoshow == "") || $accountoshow == 'NotDefined') {
939  print '<span class="error">'.$langs->trans("VATAccountNotDefined").' ('.$langs->trans("Sale").')</span>';
940  } else {
941  print $accountoshow;
942  }
943  print "</td>";
944  // Subledger account
945  print "<td>";
946  print '</td>';
947  print "<td>".$companystatic->getNomUrl(0, 'customer', 16).' - '.$invoicestatic->ref.' - '.$langs->trans("VAT").' '.join(', ', $def_tva[$key][$k]).' %'.($numtax ? ' - Localtax '.$numtax : '');
948  print "</td>";
949  print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
950  print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
951  print "</tr>";
952  }
953  }
954  }
955  }
956 
957  print "</table>";
958  print '</div>';
959 
960  // End of page
961  llxFooter();
962 }
963 
964 $db->close();
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
getDefaultDatesForTransfer()
Return Default dates for transfer based on periodicity option in accountancy setup.
journalHead($nom, $variante, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a page used to transfer/dispatch data in accounting.
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage accounting accounts.
Class to manage accounting accounts.
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...)
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:575
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:594
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.