dolibarr  17.0.2
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.situation_cycle_ref, 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, fd.info_bits,";
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, f.ref";
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  // Create a compensation rate.
209  $situation_ratio = 1;
210  if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1) {
211  if ($obj->situation_cycle_ref) {
212  // Avoid divide by 0
213  if ($obj->situation_percent == 0) {
214  $situation_ratio = 0;
215  } else {
216  $line = new FactureLigne($db);
217  $line->fetch($obj->fdid);
218 
219  // Situation invoices handling
220  $prev_progress = $line->get_prev_progress($obj->rowid);
221 
222  $situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent;
223  }
224  }
225  }
226 
227  // Invoice lines
228  $tabfac[$obj->rowid]["date"] = $db->jdate($obj->df);
229  $tabfac[$obj->rowid]["datereg"] = $db->jdate($obj->dlr);
230  $tabfac[$obj->rowid]["ref"] = $obj->ref;
231  $tabfac[$obj->rowid]["type"] = $obj->type;
232  $tabfac[$obj->rowid]["description"] = $obj->label_compte;
233  $tabfac[$obj->rowid]["close_code"] = $obj->close_code; // close_code = 'replaced' for replacement invoices (not used in most european countries)
234  //$tabfac[$obj->rowid]["fk_facturedet"] = $obj->fdid;
235 
236  // Avoid warnings
237  if (!isset($tabttc[$obj->rowid][$compta_soc])) {
238  $tabttc[$obj->rowid][$compta_soc] = 0;
239  }
240  if (!isset($tabht[$obj->rowid][$compta_prod])) {
241  $tabht[$obj->rowid][$compta_prod] = 0;
242  }
243  if (!isset($tabtva[$obj->rowid][$compta_tva])) {
244  $tabtva[$obj->rowid][$compta_tva] = 0;
245  }
246  if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) {
247  $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
248  }
249  if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) {
250  $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
251  }
252 
253  // Compensation of data for invoice situation by using $situation_ratio. This works (nearly) for invoice that was not correctly recorded
254  // but it may introduces an error for situation invoices that were correctly saved. There is still rounding problem that differs between
255  // real data we should have stored and result obtained with a compensation.
256  // It also seems that credit notes on situation invoices are correctly saved (but it depends on the version used in fact).
257  // For credit notes, we hope to have situation_ratio = 1 so the compensation has no effect to avoid introducing troubles with credit notes.
258  $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc * $situation_ratio;
259  $tabht[$obj->rowid][$compta_prod] += $obj->total_ht * $situation_ratio;
260  $tva_npr = (($obj->info_bits & 1 == 1) ? 1 : 0);
261  if (!$tva_npr) { // We ignore line if VAT is a NPR
262  $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio;
263  }
264  $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1 * $situation_ratio;
265  $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2 * $situation_ratio;
266 
267 
268  $tabcompany[$obj->rowid] = array(
269  'id' => $obj->socid,
270  'name' => $obj->name,
271  'code_client' => $obj->code_client,
272  'code_compta' => $compta_soc
273  );
274 
275  $i++;
276  }
277 } else {
278  dol_print_error($db);
279 }
280 
281 $errorforinvoice = array();
282 
283 // Loop in invoices to detect lines with not binding lines
284 foreach ($tabfac as $key => $val) { // Loop on each invoice
285  $sql = "SELECT COUNT(fd.rowid) as nb";
286  $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd";
287  $sql .= " WHERE fd.product_type <= 2 AND fd.fk_code_ventilation <= 0";
288  $sql .= " AND fd.total_ttc <> 0 AND fk_facture = ".((int) $key);
289  $resql = $db->query($sql);
290  if ($resql) {
291  $obj = $db->fetch_object($resql);
292  if ($obj->nb > 0) {
293  $errorforinvoice[$key] = 'somelinesarenotbound';
294  }
295  } else {
296  dol_print_error($db);
297  }
298 }
299 //var_dump($errorforinvoice);exit;
300 
301 
302 // Bookkeeping Write
303 if ($action == 'writebookkeeping') {
304  $now = dol_now();
305  $error = 0;
306 
307  $companystatic = new Societe($db);
308  $invoicestatic = new Facture($db);
309  $accountingaccountcustomer = new AccountingAccount($db);
310 
311  $accountingaccountcustomer->fetch(null, $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER, true);
312 
313  foreach ($tabfac as $key => $val) { // Loop on each invoice
314  $errorforline = 0;
315 
316  $totalcredit = 0;
317  $totaldebit = 0;
318 
319  $db->begin();
320 
321  $companystatic->id = $tabcompany[$key]['id'];
322  $companystatic->name = $tabcompany[$key]['name'];
323  $companystatic->code_compta = $tabcompany[$key]['code_compta'];
324  $companystatic->code_client = $tabcompany[$key]['code_client'];
325  $companystatic->client = 3;
326 
327  $invoicestatic->id = $key;
328  $invoicestatic->ref = (string) $val["ref"];
329  $invoicestatic->type = $val["type"];
330  $invoicestatic->close_code = $val["close_code"];
331 
332  $date = dol_print_date($val["date"], 'day');
333 
334  // Is it a replaced invoice ? 0=not a replaced invoice, 1=replaced invoice not yet dispatched, 2=replaced invoice dispatched
335  $replacedinvoice = 0;
336  if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
337  $replacedinvoice = 1;
338  $alreadydispatched = $invoicestatic->getVentilExportCompta(); // Test if replaced invoice already into bookkeeping.
339  if ($alreadydispatched) {
340  $replacedinvoice = 2;
341  }
342  }
343 
344  // 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)
345  if ($replacedinvoice == 1) {
346  $db->rollback();
347  continue;
348  }
349 
350  // Error if some lines are not binded/ready to be journalized
351  if ($errorforinvoice[$key] == 'somelinesarenotbound') {
352  $error++;
353  $errorforline++;
354  setEventMessages($langs->trans('ErrorInvoiceContainsLinesNotYetBounded', $val['ref']), null, 'errors');
355  }
356 
357  // Thirdparty
358  if (!$errorforline) {
359  foreach ($tabttc[$key] as $k => $mt) {
360  $bookkeeping = new BookKeeping($db);
361  $bookkeeping->doc_date = $val["date"];
362  $bookkeeping->date_lim_reglement = $val["datereg"];
363  $bookkeeping->doc_ref = $val["ref"];
364  $bookkeeping->date_creation = $now;
365  $bookkeeping->doc_type = 'customer_invoice';
366  $bookkeeping->fk_doc = $key;
367  $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
368  $bookkeeping->thirdparty_code = $companystatic->code_client;
369 
370  $bookkeeping->subledger_account = $tabcompany[$key]['code_compta'];
371  $bookkeeping->subledger_label = $tabcompany[$key]['name'];
372 
373  $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
374  $bookkeeping->label_compte = $accountingaccountcustomer->label;
375 
376  $bookkeeping->label_operation = dol_trunc($companystatic->name, 16).' - '.$invoicestatic->ref.' - '.$langs->trans("SubledgerAccount");
377  $bookkeeping->montant = $mt;
378  $bookkeeping->sens = ($mt >= 0) ? 'D' : 'C';
379  $bookkeeping->debit = ($mt >= 0) ? $mt : 0;
380  $bookkeeping->credit = ($mt < 0) ? -$mt : 0;
381  $bookkeeping->code_journal = $journal;
382  $bookkeeping->journal_label = $langs->transnoentities($journal_label);
383  $bookkeeping->fk_user_author = $user->id;
384  $bookkeeping->entity = $conf->entity;
385 
386  $totaldebit += $bookkeeping->debit;
387  $totalcredit += $bookkeeping->credit;
388 
389  $result = $bookkeeping->create($user);
390  if ($result < 0) {
391  if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists
392  $error++;
393  $errorforline++;
394  $errorforinvoice[$key] = 'alreadyjournalized';
395  //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
396  } else {
397  $error++;
398  $errorforline++;
399  $errorforinvoice[$key] = 'other';
400  setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
401  }
402  } else {
403  if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && getDolGlobalInt('ACCOUNTING_ENABLE_AUTOLETTERING')) {
404  require_once DOL_DOCUMENT_ROOT . '/accountancy/class/lettering.class.php';
405  $lettering_static = new Lettering($db);
406 
407  $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id));
408 
409  if ($nb_lettering < 0) {
410  $error++;
411  $errorforline++;
412  $errorforinvoice[$key] = 'other';
413  setEventMessages($lettering_static->error, $lettering_static->errors, 'errors');
414  }
415  }
416  }
417  }
418  }
419 
420  // Product / Service
421  if (!$errorforline) {
422  foreach ($tabht[$key] as $k => $mt) {
423  $resultfetch = $accountingaccount->fetch(null, $k, true); // TODO Use a cache
424  $label_account = $accountingaccount->label;
425 
426  // get compte id and label
427  if ($resultfetch > 0) {
428  $bookkeeping = new BookKeeping($db);
429  $bookkeeping->doc_date = $val["date"];
430  $bookkeeping->date_lim_reglement = $val["datereg"];
431  $bookkeeping->doc_ref = $val["ref"];
432  $bookkeeping->date_creation = $now;
433  $bookkeeping->doc_type = 'customer_invoice';
434  $bookkeeping->fk_doc = $key;
435  $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
436  $bookkeeping->thirdparty_code = $companystatic->code_client;
437 
438  if (!empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT)) {
439  if ($k == getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT')) {
440  $bookkeeping->subledger_account = $tabcompany[$key]['code_compta'];
441  $bookkeeping->subledger_label = $tabcompany[$key]['name'];
442  } else {
443  $bookkeeping->subledger_account = '';
444  $bookkeeping->subledger_label = '';
445  }
446  } else {
447  $bookkeeping->subledger_account = '';
448  $bookkeeping->subledger_label = '';
449  }
450 
451  $bookkeeping->numero_compte = $k;
452  $bookkeeping->label_compte = $label_account;
453 
454  $bookkeeping->label_operation = dol_trunc($companystatic->name, 16).' - '.$invoicestatic->ref.' - '.$label_account;
455  $bookkeeping->montant = $mt;
456  $bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
457  $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
458  $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
459  $bookkeeping->code_journal = $journal;
460  $bookkeeping->journal_label = $langs->transnoentities($journal_label);
461  $bookkeeping->fk_user_author = $user->id;
462  $bookkeeping->entity = $conf->entity;
463 
464  $totaldebit += $bookkeeping->debit;
465  $totalcredit += $bookkeeping->credit;
466 
467  $result = $bookkeeping->create($user);
468  if ($result < 0) {
469  if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists
470  $error++;
471  $errorforline++;
472  $errorforinvoice[$key] = 'alreadyjournalized';
473  //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
474  } else {
475  $error++;
476  $errorforline++;
477  $errorforinvoice[$key] = 'other';
478  setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
479  }
480  }
481  }
482  }
483  }
484 
485  // VAT
486  if (!$errorforline) {
487  $listoftax = array(0, 1, 2);
488  foreach ($listoftax as $numtax) {
489  $arrayofvat = $tabtva;
490  if ($numtax == 1) {
491  $arrayofvat = $tablocaltax1;
492  }
493  if ($numtax == 2) {
494  $arrayofvat = $tablocaltax2;
495  }
496 
497  foreach ($arrayofvat[$key] as $k => $mt) {
498  if ($mt) {
499  $accountingaccount->fetch(null, $k, true); // TODO Use a cache for label
500  $label_account = $accountingaccount->label;
501 
502  $bookkeeping = new BookKeeping($db);
503  $bookkeeping->doc_date = $val["date"];
504  $bookkeeping->date_lim_reglement = $val["datereg"];
505  $bookkeeping->doc_ref = $val["ref"];
506  $bookkeeping->date_creation = $now;
507  $bookkeeping->doc_type = 'customer_invoice';
508  $bookkeeping->fk_doc = $key;
509  $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
510  $bookkeeping->thirdparty_code = $companystatic->code_client;
511 
512  $bookkeeping->subledger_account = '';
513  $bookkeeping->subledger_label = '';
514 
515  $bookkeeping->numero_compte = $k;
516  $bookkeeping->label_compte = $label_account;
517 
518  $bookkeeping->label_operation = dol_trunc($companystatic->name, 16).' - '.$invoicestatic->ref.' - '.$langs->trans("VAT").' '.join(', ', $def_tva[$key][$k]).' %'.($numtax ? ' - Localtax '.$numtax : '');
519  $bookkeeping->montant = $mt;
520  $bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
521  $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
522  $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
523  $bookkeeping->code_journal = $journal;
524  $bookkeeping->journal_label = $langs->transnoentities($journal_label);
525  $bookkeeping->fk_user_author = $user->id;
526  $bookkeeping->entity = $conf->entity;
527 
528  $totaldebit += $bookkeeping->debit;
529  $totalcredit += $bookkeeping->credit;
530 
531  $result = $bookkeeping->create($user);
532  if ($result < 0) {
533  if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists
534  $error++;
535  $errorforline++;
536  $errorforinvoice[$key] = 'alreadyjournalized';
537  //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
538  } else {
539  $error++;
540  $errorforline++;
541  $errorforinvoice[$key] = 'other';
542  setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
543  }
544  }
545  }
546  }
547  }
548  }
549 
550  // Protection against a bug on lines before
551  if (!$errorforline && (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT'))) {
552  $error++;
553  $errorforline++;
554  $errorforinvoice[$key] = 'amountsnotbalanced';
555  setEventMessages('Try to insert a non balanced transaction in book for '.$invoicestatic->ref.'. Canceled. Surely a bug.', null, 'errors');
556  }
557 
558  if (!$errorforline) {
559  $db->commit();
560  } else {
561  $db->rollback();
562 
563  if ($error >= 10) {
564  setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped"), null, 'errors');
565  break; // Break in the foreach
566  }
567  }
568  }
569 
570  $tabpay = $tabfac;
571 
572  if (empty($error) && count($tabpay) > 0) {
573  setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
574  } elseif (count($tabpay) == $error) {
575  setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings');
576  } else {
577  setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings');
578  }
579 
580  $action = '';
581 
582  // Must reload data, so we make a redirect
583  if (count($tabpay) != $error) {
584  $param = 'id_journal='.$id_journal;
585  $param .= '&date_startday='.$date_startday;
586  $param .= '&date_startmonth='.$date_startmonth;
587  $param .= '&date_startyear='.$date_startyear;
588  $param .= '&date_endday='.$date_endday;
589  $param .= '&date_endmonth='.$date_endmonth;
590  $param .= '&date_endyear='.$date_endyear;
591  $param .= '&in_bookkeeping='.$in_bookkeeping;
592  header("Location: ".$_SERVER['PHP_SELF'].($param ? '?'.$param : ''));
593  exit;
594  }
595 }
596 
597 
598 
599 /*
600  * View
601  */
602 
603 $form = new Form($db);
604 
605 // Export
606 if ($action == 'exportcsv') { // ISO and not UTF8 !
607  $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
608 
609  $filename = 'journal';
610  $type_export = 'journal';
611  include DOL_DOCUMENT_ROOT.'/accountancy/tpl/export_journal.tpl.php';
612 
613  $companystatic = new Client($db);
614  $invoicestatic = new Facture($db);
615 
616  foreach ($tabfac as $key => $val) {
617  $companystatic->id = $tabcompany[$key]['id'];
618  $companystatic->name = $tabcompany[$key]['name'];
619  $companystatic->code_compta = $tabcompany[$key]['code_compta']; // deprecated
620  $companystatic->code_compta_client = $tabcompany[$key]['code_compta'];
621  $companystatic->code_client = $tabcompany[$key]['code_client'];
622  $companystatic->client = 3;
623 
624  $invoicestatic->id = $key;
625  $invoicestatic->ref = (string) $val["ref"];
626  $invoicestatic->type = $val["type"];
627  $invoicestatic->close_code = $val["close_code"];
628 
629  $date = dol_print_date($val["date"], 'day');
630 
631  // Is it a replaced invoice ? 0=not a replaced invoice, 1=replaced invoice not yet dispatched, 2=replaced invoice dispatched
632  $replacedinvoice = 0;
633  if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
634  $replacedinvoice = 1;
635  $alreadydispatched = $invoicestatic->getVentilExportCompta(); // Test if replaced invoice already into bookkeeping.
636  if ($alreadydispatched) {
637  $replacedinvoice = 2;
638  }
639  }
640 
641  // 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)
642  if ($replacedinvoice == 1) {
643  continue;
644  }
645 
646  // Third party
647  foreach ($tabttc[$key] as $k => $mt) {
648  //if ($mt) {
649  print '"'.$key.'"'.$sep;
650  print '"'.$date.'"'.$sep;
651  print '"'.$val["ref"].'"'.$sep;
652  print '"'.utf8_decode(dol_trunc($companystatic->name, 32)).'"'.$sep;
653  print '"'.length_accounta(html_entity_decode($k)).'"'.$sep;
654  print '"'.length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER).'"'.$sep;
655  print '"'.length_accounta(html_entity_decode($k)).'"'.$sep;
656  print '"'.$langs->trans("Thirdparty").'"'.$sep;
657  print '"'.utf8_decode(dol_trunc($companystatic->name, 16)).' - '.$invoicestatic->ref.' - '.$langs->trans("Thirdparty").'"'.$sep;
658  print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
659  print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
660  print '"'.$journal.'"';
661  print "\n";
662  //}
663  }
664 
665  // Product / Service
666  foreach ($tabht[$key] as $k => $mt) {
667  $accountingaccount = new AccountingAccount($db);
668  $accountingaccount->fetch(null, $k, true);
669  //if ($mt) {
670  print '"'.$key.'"'.$sep;
671  print '"'.$date.'"'.$sep;
672  print '"'.$val["ref"].'"'.$sep;
673  print '"'.utf8_decode(dol_trunc($companystatic->name, 32)).'"'.$sep;
674  print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
675  print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
676  print '""'.$sep;
677  print '"'.utf8_decode(dol_trunc($accountingaccount->label, 32)).'"'.$sep;
678  print '"'.utf8_decode(dol_trunc($companystatic->name, 16)).' - '.dol_trunc($accountingaccount->label, 32).'"'.$sep;
679  print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
680  print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
681  print '"'.$journal.'"';
682  print "\n";
683  //}
684  }
685 
686  // VAT
687  $listoftax = array(0, 1, 2);
688  foreach ($listoftax as $numtax) {
689  $arrayofvat = $tabtva;
690  if ($numtax == 1) {
691  $arrayofvat = $tablocaltax1;
692  }
693  if ($numtax == 2) {
694  $arrayofvat = $tablocaltax2;
695  }
696 
697  foreach ($arrayofvat[$key] as $k => $mt) {
698  if ($mt) {
699  print '"'.$key.'"'.$sep;
700  print '"'.$date.'"'.$sep;
701  print '"'.$val["ref"].'"'.$sep;
702  print '"'.utf8_decode(dol_trunc($companystatic->name, 32)).'"'.$sep;
703  print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
704  print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
705  print '""'.$sep;
706  print '"'.$langs->trans("VAT").' - '.join(', ', $def_tva[$key][$k]).' %"'.$sep;
707  print '"'.utf8_decode(dol_trunc($companystatic->name, 16)).' - '.$invoicestatic->ref.' - '.$langs->trans("VAT").join(', ', $def_tva[$key][$k]).' %'.($numtax ? ' - Localtax '.$numtax : '').'"'.$sep;
708  print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
709  print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
710  print '"'.$journal.'"';
711  print "\n";
712  }
713  }
714  }
715  }
716 }
717 
718 
719 
720 if (empty($action) || $action == 'view') {
721  $title = $langs->trans("GenerationOfAccountingEntries").' - '.$accountingjournalstatic->getNomUrl(0, 2, 1, '', 1);
722 
723  llxHeader('', dol_string_nohtmltag($title));
724 
725  $nom = $title;
726  $nomlink = '';
727  $periodlink = '';
728  $exportlink = '';
729  $builddate = dol_now();
730  $description = $langs->trans("DescJournalOnlyBindedVisible").'<br>';
731  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
732  $description .= $langs->trans("DepositsAreNotIncluded");
733  } else {
734  $description .= $langs->trans("DepositsAreIncluded");
735  }
736 
737  $listofchoices = array('notyet'=>$langs->trans("NotYetInGeneralLedger"), 'already'=>$langs->trans("AlreadyInGeneralLedger"));
738  $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);
739  $period .= ' - '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
740 
741  $varlink = 'id_journal='.$id_journal;
742 
743  journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink);
744 
745  // Button to write into Ledger
746  if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == "") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1') {
747  print '<br><div class="warning">'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone");
748  $desc = ' : '.$langs->trans("AccountancyAreaDescMisc", 4, '{link}');
749  $desc = str_replace('{link}', '<strong>'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'</strong>', $desc);
750  print $desc;
751  print '</div>';
752  }
753  print '<div class="tabsAction tabsActionNoBottom centerimp">';
754  if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping == 'notyet') {
755  print '<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans("ExportDraftJournal").'" onclick="launch_export();" />';
756  }
757  if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == "") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1') {
758  print '<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("SomeMandatoryStepsOfSetupWereNotDone")).'" value="'.$langs->trans("WriteBookKeeping").'" />';
759  } else {
760  if ($in_bookkeeping == 'notyet') {
761  print '<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans("WriteBookKeeping").'" onclick="writebookkeeping();" />';
762  } else {
763  print '<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans("WriteBookKeeping").'</a>';
764  }
765  }
766  print '</div>';
767 
768  // TODO Avoid using js. We can use a direct link with $param
769  print '
770  <script type="text/javascript">
771  function launch_export() {
772  $("div.fiche form input[name=\"action\"]").val("exportcsv");
773  $("div.fiche form input[type=\"submit\"]").click();
774  $("div.fiche form input[name=\"action\"]").val("");
775  }
776  function writebookkeeping() {
777  console.log("click on writebookkeeping");
778  $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
779  $("div.fiche form input[type=\"submit\"]").click();
780  $("div.fiche form input[name=\"action\"]").val("");
781  }
782  </script>';
783 
784  /*
785  * Show result array
786  */
787  print '<br>';
788 
789  print '<div class="div-table-responsive">';
790  print "<table class=\"noborder\" width=\"100%\">";
791  print "<tr class=\"liste_titre\">";
792  print "<td>".$langs->trans("Date")."</td>";
793  print "<td>".$langs->trans("Piece").' ('.$langs->trans("InvoiceRef").")</td>";
794  print "<td>".$langs->trans("AccountAccounting")."</td>";
795  print "<td>".$langs->trans("SubledgerAccount")."</td>";
796  print "<td>".$langs->trans("LabelOperation")."</td>";
797  print '<td class="center">'.$langs->trans("AccountingDebit")."</td>";
798  print '<td class="center">'.$langs->trans("AccountingCredit")."</td>";
799  print "</tr>\n";
800 
801  $i = 0;
802 
803  $companystatic = new Client($db);
804  $invoicestatic = new Facture($db);
805 
806  foreach ($tabfac as $key => $val) {
807  $companystatic->id = $tabcompany[$key]['id'];
808  $companystatic->name = $tabcompany[$key]['name'];
809  $companystatic->code_compta = $tabcompany[$key]['code_compta'];
810  $companystatic->code_client = $tabcompany[$key]['code_client'];
811  $companystatic->client = 3;
812 
813  $invoicestatic->id = $key;
814  $invoicestatic->ref = (string) $val["ref"];
815  $invoicestatic->type = $val["type"];
816  $invoicestatic->close_code = $val["close_code"];
817 
818  $date = dol_print_date($val["date"], 'day');
819 
820  // Is it a replaced invoice ? 0=not a replaced invoice, 1=replaced invoice not yet dispatched, 2=replaced invoice dispatched
821  $replacedinvoice = 0;
822  if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
823  $replacedinvoice = 1;
824  $alreadydispatched = $invoicestatic->getVentilExportCompta(); // Test if replaced invoice already into bookkeeping.
825  if ($alreadydispatched) {
826  $replacedinvoice = 2;
827  }
828  }
829 
830  // If not already into bookkeeping, we won't add it, if yes, add the counterpart ???.
831  if ($replacedinvoice == 1) {
832  print '<tr class="oddeven">';
833  print "<!-- Replaced invoice -->";
834  print "<td>".$date."</td>";
835  print "<td><strike>".$invoicestatic->getNomUrl(1)."</strike></td>";
836  // Account
837  print "<td>";
838  print $langs->trans("Replaced");
839  print '</td>';
840  // Subledger account
841  print "<td>";
842  print '</td>';
843  print "<td>";
844  print "</td>";
845  print '<td class="right"></td>';
846  print '<td class="right"></td>';
847  print "</tr>";
848 
849  $i++;
850  continue;
851  }
852  if ($errorforinvoice[$key] == 'somelinesarenotbound') {
853  print '<tr class="oddeven">';
854  print "<!-- Some lines are not bound -->";
855  print "<td>".$date."</td>";
856  print "<td>".$invoicestatic->getNomUrl(1)."</td>";
857  // Account
858  print "<td>";
859  print '<span class="error">'.$langs->trans('ErrorInvoiceContainsLinesNotYetBoundedShort', $val['ref']).'</span>';
860  print '</td>';
861  // Subledger account
862  print "<td>";
863  print '</td>';
864  print "<td>";
865  print "</td>";
866  print '<td class="right"></td>';
867  print '<td class="right"></td>';
868  print "</tr>";
869 
870  $i++;
871  }
872 
873  // Third party
874  foreach ($tabttc[$key] as $k => $mt) {
875  print '<tr class="oddeven">';
876  print "<!-- Thirdparty -->";
877  print "<td>".$date."</td>";
878  print "<td>".$invoicestatic->getNomUrl(1)."</td>";
879  // Account
880  print "<td>";
881  $accountoshow = length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER);
882  if (($accountoshow == "") || $accountoshow == 'NotDefined') {
883  print '<span class="error">'.$langs->trans("MainAccountForCustomersNotDefined").'</span>';
884  } else {
885  print $accountoshow;
886  }
887  print '</td>';
888  // Subledger account
889  print "<td>";
890  $accountoshow = length_accounta($k);
891  if (($accountoshow == "") || $accountoshow == 'NotDefined') {
892  print '<span class="error">'.$langs->trans("ThirdpartyAccountNotDefined").'</span>';
893  } else {
894  print $accountoshow;
895  }
896  print '</td>';
897  print "<td>".$companystatic->getNomUrl(0, 'customer', 16).' - '.$invoicestatic->ref.' - '.$langs->trans("SubledgerAccount")."</td>";
898  print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
899  print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
900  print "</tr>";
901 
902  $i++;
903  }
904 
905  // Product / Service
906  foreach ($tabht[$key] as $k => $mt) {
907  $accountingaccount = new AccountingAccount($db);
908  $accountingaccount->fetch(null, $k, true);
909 
910  print '<tr class="oddeven">';
911  print "<!-- Product -->";
912  print "<td>".$date."</td>";
913  print "<td>".$invoicestatic->getNomUrl(1)."</td>";
914  // Account
915  print "<td>";
916  $accountoshow = length_accountg($k);
917  if (($accountoshow == "") || $accountoshow == 'NotDefined') {
918  print '<span class="error">'.$langs->trans("ProductNotDefined").'</span>';
919  } else {
920  print $accountoshow;
921  }
922  print "</td>";
923  // Subledger account
924  print "<td>";
925  if (!empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT)) {
926  if ($k == getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT')) {
927  print length_accounta($tabcompany[$key]['code_compta']);
928  }
929  } elseif (($accountoshow == "") || $accountoshow == 'NotDefined') {
930  print '<span class="error">' . $langs->trans("ThirdpartyAccountNotDefined") . '</span>';
931  }
932  print '</td>';
933  $companystatic->id = $tabcompany[$key]['id'];
934  $companystatic->name = $tabcompany[$key]['name'];
935  print "<td>".$companystatic->getNomUrl(0, 'customer', 16).' - '.$invoicestatic->ref.' - '.$accountingaccount->label."</td>";
936  print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
937  print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
938  print "</tr>";
939 
940  $i++;
941  }
942 
943  // VAT
944  $listoftax = array(0, 1, 2);
945  foreach ($listoftax as $numtax) {
946  $arrayofvat = $tabtva;
947  if ($numtax == 1) {
948  $arrayofvat = $tablocaltax1;
949  }
950  if ($numtax == 2) {
951  $arrayofvat = $tablocaltax2;
952  }
953 
954  foreach ($arrayofvat[$key] as $k => $mt) {
955  if ($mt) {
956  print '<tr class="oddeven">';
957  print "<!-- VAT -->";
958  print "<td>".$date."</td>";
959  print "<td>".$invoicestatic->getNomUrl(1)."</td>";
960  // Account
961  print "<td>";
962  $accountoshow = length_accountg($k);
963  if (($accountoshow == "") || $accountoshow == 'NotDefined') {
964  print '<span class="error">'.$langs->trans("VATAccountNotDefined").' ('.$langs->trans("Sale").')</span>';
965  } else {
966  print $accountoshow;
967  }
968  print "</td>";
969  // Subledger account
970  print "<td>";
971  print '</td>';
972  print "<td>".$companystatic->getNomUrl(0, 'customer', 16).' - '.$invoicestatic->ref.' - '.$langs->trans("VAT").' '.join(', ', $def_tva[$key][$k]).' %'.($numtax ? ' - Localtax '.$numtax : '');
973  print "</td>";
974  print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
975  print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
976  print "</tr>";
977 
978  $i++;
979  }
980  }
981  }
982  }
983 
984  if (!$i) {
985  print '<tr class="oddeven"><td colspan="6"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
986  }
987 
988  print "</table>";
989  print '</div>';
990 
991  // End of page
992  llxFooter();
993 }
994 
995 $db->close();
length_accounta
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
Definition: accounting.lib.php:133
getTaxesFromId
getTaxesFromId($vatrate, $buyer=null, $seller=null, $firstparamisid=1)
Get tax (VAT) main information from Id.
Definition: functions.lib.php:6191
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:49
dol_trunc
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.
Definition: functions.lib.php:3949
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:520
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4993
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
Facture
Class to manage invoices.
Definition: facture.class.php:60
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5823
Facture\TYPE_DEPOSIT
const TYPE_DEPOSIT
Deposit invoice.
Definition: facture.class.php:392
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2550
Facture\TYPE_REPLACEMENT
const TYPE_REPLACEMENT
Replacement invoice.
Definition: facture.class.php:382
llxHeader
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
FactureLigne
Class to manage invoice lines.
Definition: facture.class.php:5747
AccountingJournal
Class to manage accounting accounts.
Definition: accountingjournal.class.php:27
$resql
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
length_accountg
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
Definition: accounting.lib.php:94
dol_string_nohtmltag
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
Definition: functions.lib.php:6880
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1628
dol_get_first_day
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
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:82
journalHead
journalHead($nom, $variante, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a page used to transfer/dispatch data in accounting.
Definition: accounting.lib.php:183
dol_get_last_day
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
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
BookKeeping
Class to manage Ledger (General Ledger and Subledger)
Definition: bookkeeping.class.php:33
Facture\TYPE_CREDIT_NOTE
const TYPE_CREDIT_NOTE
Credit note invoice.
Definition: facture.class.php:387
AccountingAccount
Class to manage accounting accounts.
Definition: accountingaccount.class.php:36
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:421
Lettering
Class Lettering.
Definition: lettering.class.php:34
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:53
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2951
getDefaultDatesForTransfer
getDefaultDatesForTransfer()
Return Default dates for transfer based on periodicity option in accountancy setup.
Definition: accounting.lib.php:273
price
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.
Definition: functions.lib.php:5697
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8460
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
Definition: security.lib.php:1111
dol_mktime
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...
Definition: functions.lib.php:2863
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:96
Facture\TYPE_SITUATION
const TYPE_SITUATION
Situation invoice.
Definition: facture.class.php:402
Client
Class to manage customers or prospects.
Definition: client.class.php:31
vatrate
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.
Definition: functions.lib.php:5648
if
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
Definition: journals_list.php:25