dolibarr  17.0.3
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-2023 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  }
410  }
411  }
412 
413  // Product / Service
414  if (!$errorforline) {
415  foreach ($tabht[$key] as $k => $mt) {
416  $resultfetch = $accountingaccount->fetch(null, $k, true); // TODO Use a cache
417  $label_account = $accountingaccount->label;
418 
419  // get compte id and label
420  if ($resultfetch > 0) {
421  $bookkeeping = new BookKeeping($db);
422  $bookkeeping->doc_date = $val["date"];
423  $bookkeeping->date_lim_reglement = $val["datereg"];
424  $bookkeeping->doc_ref = $val["ref"];
425  $bookkeeping->date_creation = $now;
426  $bookkeeping->doc_type = 'customer_invoice';
427  $bookkeeping->fk_doc = $key;
428  $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
429  $bookkeeping->thirdparty_code = $companystatic->code_client;
430 
431  if (!empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT)) {
432  if ($k == getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT')) {
433  $bookkeeping->subledger_account = $tabcompany[$key]['code_compta'];
434  $bookkeeping->subledger_label = $tabcompany[$key]['name'];
435  } else {
436  $bookkeeping->subledger_account = '';
437  $bookkeeping->subledger_label = '';
438  }
439  } else {
440  $bookkeeping->subledger_account = '';
441  $bookkeeping->subledger_label = '';
442  }
443 
444  $bookkeeping->numero_compte = $k;
445  $bookkeeping->label_compte = $label_account;
446 
447  $bookkeeping->label_operation = dol_trunc($companystatic->name, 16).' - '.$invoicestatic->ref.' - '.$label_account;
448  $bookkeeping->montant = $mt;
449  $bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
450  $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
451  $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
452  $bookkeeping->code_journal = $journal;
453  $bookkeeping->journal_label = $langs->transnoentities($journal_label);
454  $bookkeeping->fk_user_author = $user->id;
455  $bookkeeping->entity = $conf->entity;
456 
457  $totaldebit += $bookkeeping->debit;
458  $totalcredit += $bookkeeping->credit;
459 
460  $result = $bookkeeping->create($user);
461  if ($result < 0) {
462  if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists
463  $error++;
464  $errorforline++;
465  $errorforinvoice[$key] = 'alreadyjournalized';
466  //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
467  } else {
468  $error++;
469  $errorforline++;
470  $errorforinvoice[$key] = 'other';
471  setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
472  }
473  }
474  }
475  }
476  }
477 
478  // VAT
479  if (!$errorforline) {
480  $listoftax = array(0, 1, 2);
481  foreach ($listoftax as $numtax) {
482  $arrayofvat = $tabtva;
483  if ($numtax == 1) {
484  $arrayofvat = $tablocaltax1;
485  }
486  if ($numtax == 2) {
487  $arrayofvat = $tablocaltax2;
488  }
489 
490  foreach ($arrayofvat[$key] as $k => $mt) {
491  if ($mt) {
492  $accountingaccount->fetch(null, $k, true); // TODO Use a cache for label
493  $label_account = $accountingaccount->label;
494 
495  $bookkeeping = new BookKeeping($db);
496  $bookkeeping->doc_date = $val["date"];
497  $bookkeeping->date_lim_reglement = $val["datereg"];
498  $bookkeeping->doc_ref = $val["ref"];
499  $bookkeeping->date_creation = $now;
500  $bookkeeping->doc_type = 'customer_invoice';
501  $bookkeeping->fk_doc = $key;
502  $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
503  $bookkeeping->thirdparty_code = $companystatic->code_client;
504 
505  $bookkeeping->subledger_account = '';
506  $bookkeeping->subledger_label = '';
507 
508  $bookkeeping->numero_compte = $k;
509  $bookkeeping->label_compte = $label_account;
510 
511  $bookkeeping->label_operation = dol_trunc($companystatic->name, 16).' - '.$invoicestatic->ref.' - '.$langs->trans("VAT").' '.join(', ', $def_tva[$key][$k]).' %'.($numtax ? ' - Localtax '.$numtax : '');
512  $bookkeeping->montant = $mt;
513  $bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
514  $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
515  $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
516  $bookkeeping->code_journal = $journal;
517  $bookkeeping->journal_label = $langs->transnoentities($journal_label);
518  $bookkeeping->fk_user_author = $user->id;
519  $bookkeeping->entity = $conf->entity;
520 
521  $totaldebit += $bookkeeping->debit;
522  $totalcredit += $bookkeeping->credit;
523 
524  $result = $bookkeeping->create($user);
525  if ($result < 0) {
526  if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists
527  $error++;
528  $errorforline++;
529  $errorforinvoice[$key] = 'alreadyjournalized';
530  //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
531  } else {
532  $error++;
533  $errorforline++;
534  $errorforinvoice[$key] = 'other';
535  setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
536  }
537  }
538  }
539  }
540  }
541  }
542 
543  // Protection against a bug on lines before
544  if (!$errorforline && (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT'))) {
545  $error++;
546  $errorforline++;
547  $errorforinvoice[$key] = 'amountsnotbalanced';
548  setEventMessages('Try to insert a non balanced transaction in book for '.$invoicestatic->ref.'. Canceled. Surely a bug.', null, 'errors');
549  }
550 
551  if (!$errorforline) {
552  $db->commit();
553  } else {
554  $db->rollback();
555 
556  if ($error >= 10) {
557  setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped"), null, 'errors');
558  break; // Break in the foreach
559  }
560  }
561  }
562 
563  $tabpay = $tabfac;
564 
565  if (empty($error) && count($tabpay) > 0) {
566  setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
567  } elseif (count($tabpay) == $error) {
568  setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings');
569  } else {
570  setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings');
571  }
572 
573  $action = '';
574 
575  // Must reload data, so we make a redirect
576  if (count($tabpay) != $error) {
577  $param = 'id_journal='.$id_journal;
578  $param .= '&date_startday='.$date_startday;
579  $param .= '&date_startmonth='.$date_startmonth;
580  $param .= '&date_startyear='.$date_startyear;
581  $param .= '&date_endday='.$date_endday;
582  $param .= '&date_endmonth='.$date_endmonth;
583  $param .= '&date_endyear='.$date_endyear;
584  $param .= '&in_bookkeeping='.$in_bookkeeping;
585  header("Location: ".$_SERVER['PHP_SELF'].($param ? '?'.$param : ''));
586  exit;
587  }
588 }
589 
590 
591 
592 /*
593  * View
594  */
595 
596 $form = new Form($db);
597 
598 // Export
599 if ($action == 'exportcsv') { // ISO and not UTF8 !
600  $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
601 
602  $filename = 'journal';
603  $type_export = 'journal';
604  include DOL_DOCUMENT_ROOT.'/accountancy/tpl/export_journal.tpl.php';
605 
606  $companystatic = new Client($db);
607  $invoicestatic = new Facture($db);
608 
609  foreach ($tabfac as $key => $val) {
610  $companystatic->id = $tabcompany[$key]['id'];
611  $companystatic->name = $tabcompany[$key]['name'];
612  $companystatic->code_compta = $tabcompany[$key]['code_compta']; // deprecated
613  $companystatic->code_compta_client = $tabcompany[$key]['code_compta'];
614  $companystatic->code_client = $tabcompany[$key]['code_client'];
615  $companystatic->client = 3;
616 
617  $invoicestatic->id = $key;
618  $invoicestatic->ref = (string) $val["ref"];
619  $invoicestatic->type = $val["type"];
620  $invoicestatic->close_code = $val["close_code"];
621 
622  $date = dol_print_date($val["date"], 'day');
623 
624  // Is it a replaced invoice ? 0=not a replaced invoice, 1=replaced invoice not yet dispatched, 2=replaced invoice dispatched
625  $replacedinvoice = 0;
626  if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
627  $replacedinvoice = 1;
628  $alreadydispatched = $invoicestatic->getVentilExportCompta(); // Test if replaced invoice already into bookkeeping.
629  if ($alreadydispatched) {
630  $replacedinvoice = 2;
631  }
632  }
633 
634  // 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)
635  if ($replacedinvoice == 1) {
636  continue;
637  }
638 
639  // Third party
640  foreach ($tabttc[$key] as $k => $mt) {
641  //if ($mt) {
642  print '"'.$key.'"'.$sep;
643  print '"'.$date.'"'.$sep;
644  print '"'.$val["ref"].'"'.$sep;
645  print '"'.utf8_decode(dol_trunc($companystatic->name, 32)).'"'.$sep;
646  print '"'.length_accounta(html_entity_decode($k)).'"'.$sep;
647  print '"'.length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER).'"'.$sep;
648  print '"'.length_accounta(html_entity_decode($k)).'"'.$sep;
649  print '"'.$langs->trans("Thirdparty").'"'.$sep;
650  print '"'.utf8_decode(dol_trunc($companystatic->name, 16)).' - '.$invoicestatic->ref.' - '.$langs->trans("Thirdparty").'"'.$sep;
651  print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
652  print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
653  print '"'.$journal.'"';
654  print "\n";
655  //}
656  }
657 
658  // Product / Service
659  foreach ($tabht[$key] as $k => $mt) {
660  $accountingaccount = new AccountingAccount($db);
661  $accountingaccount->fetch(null, $k, true);
662  //if ($mt) {
663  print '"'.$key.'"'.$sep;
664  print '"'.$date.'"'.$sep;
665  print '"'.$val["ref"].'"'.$sep;
666  print '"'.utf8_decode(dol_trunc($companystatic->name, 32)).'"'.$sep;
667  print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
668  print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
669  print '""'.$sep;
670  print '"'.utf8_decode(dol_trunc($accountingaccount->label, 32)).'"'.$sep;
671  print '"'.utf8_decode(dol_trunc($companystatic->name, 16)).' - '.dol_trunc($accountingaccount->label, 32).'"'.$sep;
672  print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
673  print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
674  print '"'.$journal.'"';
675  print "\n";
676  //}
677  }
678 
679  // VAT
680  $listoftax = array(0, 1, 2);
681  foreach ($listoftax as $numtax) {
682  $arrayofvat = $tabtva;
683  if ($numtax == 1) {
684  $arrayofvat = $tablocaltax1;
685  }
686  if ($numtax == 2) {
687  $arrayofvat = $tablocaltax2;
688  }
689 
690  foreach ($arrayofvat[$key] as $k => $mt) {
691  if ($mt) {
692  print '"'.$key.'"'.$sep;
693  print '"'.$date.'"'.$sep;
694  print '"'.$val["ref"].'"'.$sep;
695  print '"'.utf8_decode(dol_trunc($companystatic->name, 32)).'"'.$sep;
696  print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
697  print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
698  print '""'.$sep;
699  print '"'.$langs->trans("VAT").' - '.join(', ', $def_tva[$key][$k]).' %"'.$sep;
700  print '"'.utf8_decode(dol_trunc($companystatic->name, 16)).' - '.$invoicestatic->ref.' - '.$langs->trans("VAT").join(', ', $def_tva[$key][$k]).' %'.($numtax ? ' - Localtax '.$numtax : '').'"'.$sep;
701  print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
702  print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
703  print '"'.$journal.'"';
704  print "\n";
705  }
706  }
707  }
708  }
709 }
710 
711 
712 
713 if (empty($action) || $action == 'view') {
714  $title = $langs->trans("GenerationOfAccountingEntries").' - '.$accountingjournalstatic->getNomUrl(0, 2, 1, '', 1);
715 
716  llxHeader('', dol_string_nohtmltag($title));
717 
718  $nom = $title;
719  $nomlink = '';
720  $periodlink = '';
721  $exportlink = '';
722  $builddate = dol_now();
723  $description = $langs->trans("DescJournalOnlyBindedVisible").'<br>';
724  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
725  $description .= $langs->trans("DepositsAreNotIncluded");
726  } else {
727  $description .= $langs->trans("DepositsAreIncluded");
728  }
729 
730  $listofchoices = array('notyet'=>$langs->trans("NotYetInGeneralLedger"), 'already'=>$langs->trans("AlreadyInGeneralLedger"));
731  $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);
732  $period .= ' - '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
733 
734  $varlink = 'id_journal='.$id_journal;
735 
736  journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink);
737 
738  // Button to write into Ledger
739  if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == "") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1') {
740  print '<br><div class="warning">'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone");
741  $desc = ' : '.$langs->trans("AccountancyAreaDescMisc", 4, '{link}');
742  $desc = str_replace('{link}', '<strong>'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'</strong>', $desc);
743  print $desc;
744  print '</div>';
745  }
746  print '<div class="tabsAction tabsActionNoBottom centerimp">';
747  if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping == 'notyet') {
748  print '<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans("ExportDraftJournal").'" onclick="launch_export();" />';
749  }
750  if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == "") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1') {
751  print '<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("SomeMandatoryStepsOfSetupWereNotDone")).'" value="'.$langs->trans("WriteBookKeeping").'" />';
752  } else {
753  if ($in_bookkeeping == 'notyet') {
754  print '<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans("WriteBookKeeping").'" onclick="writebookkeeping();" />';
755  } else {
756  print '<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans("WriteBookKeeping").'</a>';
757  }
758  }
759  print '</div>';
760 
761  // TODO Avoid using js. We can use a direct link with $param
762  print '
763  <script type="text/javascript">
764  function launch_export() {
765  $("div.fiche form input[name=\"action\"]").val("exportcsv");
766  $("div.fiche form input[type=\"submit\"]").click();
767  $("div.fiche form input[name=\"action\"]").val("");
768  }
769  function writebookkeeping() {
770  console.log("click on writebookkeeping");
771  $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
772  $("div.fiche form input[type=\"submit\"]").click();
773  $("div.fiche form input[name=\"action\"]").val("");
774  }
775  </script>';
776 
777  /*
778  * Show result array
779  */
780  print '<br>';
781 
782  print '<div class="div-table-responsive">';
783  print "<table class=\"noborder\" width=\"100%\">";
784  print "<tr class=\"liste_titre\">";
785  print "<td>".$langs->trans("Date")."</td>";
786  print "<td>".$langs->trans("Piece").' ('.$langs->trans("InvoiceRef").")</td>";
787  print "<td>".$langs->trans("AccountAccounting")."</td>";
788  print "<td>".$langs->trans("SubledgerAccount")."</td>";
789  print "<td>".$langs->trans("LabelOperation")."</td>";
790  print '<td class="center">'.$langs->trans("AccountingDebit")."</td>";
791  print '<td class="center">'.$langs->trans("AccountingCredit")."</td>";
792  print "</tr>\n";
793 
794  $i = 0;
795 
796  $companystatic = new Client($db);
797  $invoicestatic = new Facture($db);
798 
799  foreach ($tabfac as $key => $val) {
800  $companystatic->id = $tabcompany[$key]['id'];
801  $companystatic->name = $tabcompany[$key]['name'];
802  $companystatic->code_compta = $tabcompany[$key]['code_compta'];
803  $companystatic->code_client = $tabcompany[$key]['code_client'];
804  $companystatic->client = 3;
805 
806  $invoicestatic->id = $key;
807  $invoicestatic->ref = (string) $val["ref"];
808  $invoicestatic->type = $val["type"];
809  $invoicestatic->close_code = $val["close_code"];
810 
811  $date = dol_print_date($val["date"], 'day');
812 
813  // Is it a replaced invoice ? 0=not a replaced invoice, 1=replaced invoice not yet dispatched, 2=replaced invoice dispatched
814  $replacedinvoice = 0;
815  if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) {
816  $replacedinvoice = 1;
817  $alreadydispatched = $invoicestatic->getVentilExportCompta(); // Test if replaced invoice already into bookkeeping.
818  if ($alreadydispatched) {
819  $replacedinvoice = 2;
820  }
821  }
822 
823  // If not already into bookkeeping, we won't add it, if yes, add the counterpart ???.
824  if ($replacedinvoice == 1) {
825  print '<tr class="oddeven">';
826  print "<!-- Replaced invoice -->";
827  print "<td>".$date."</td>";
828  print "<td><strike>".$invoicestatic->getNomUrl(1)."</strike></td>";
829  // Account
830  print "<td>";
831  print $langs->trans("Replaced");
832  print '</td>';
833  // Subledger account
834  print "<td>";
835  print '</td>';
836  print "<td>";
837  print "</td>";
838  print '<td class="right"></td>';
839  print '<td class="right"></td>';
840  print "</tr>";
841 
842  $i++;
843  continue;
844  }
845  if ($errorforinvoice[$key] == 'somelinesarenotbound') {
846  print '<tr class="oddeven">';
847  print "<!-- Some lines are not bound -->";
848  print "<td>".$date."</td>";
849  print "<td>".$invoicestatic->getNomUrl(1)."</td>";
850  // Account
851  print "<td>";
852  print '<span class="error">'.$langs->trans('ErrorInvoiceContainsLinesNotYetBoundedShort', $val['ref']).'</span>';
853  print '</td>';
854  // Subledger account
855  print "<td>";
856  print '</td>';
857  print "<td>";
858  print "</td>";
859  print '<td class="right"></td>';
860  print '<td class="right"></td>';
861  print "</tr>";
862 
863  $i++;
864  }
865 
866  // Third party
867  foreach ($tabttc[$key] as $k => $mt) {
868  print '<tr class="oddeven">';
869  print "<!-- Thirdparty -->";
870  print "<td>".$date."</td>";
871  print "<td>".$invoicestatic->getNomUrl(1)."</td>";
872  // Account
873  print "<td>";
874  $accountoshow = length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER);
875  if (($accountoshow == "") || $accountoshow == 'NotDefined') {
876  print '<span class="error">'.$langs->trans("MainAccountForCustomersNotDefined").'</span>';
877  } else {
878  print $accountoshow;
879  }
880  print '</td>';
881  // Subledger account
882  print "<td>";
883  $accountoshow = length_accounta($k);
884  if (($accountoshow == "") || $accountoshow == 'NotDefined') {
885  print '<span class="error">'.$langs->trans("ThirdpartyAccountNotDefined").'</span>';
886  } else {
887  print $accountoshow;
888  }
889  print '</td>';
890  print "<td>".$companystatic->getNomUrl(0, 'customer', 16).' - '.$invoicestatic->ref.' - '.$langs->trans("SubledgerAccount")."</td>";
891  print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
892  print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
893  print "</tr>";
894 
895  $i++;
896  }
897 
898  // Product / Service
899  foreach ($tabht[$key] as $k => $mt) {
900  $accountingaccount = new AccountingAccount($db);
901  $accountingaccount->fetch(null, $k, true);
902 
903  print '<tr class="oddeven">';
904  print "<!-- Product -->";
905  print "<td>".$date."</td>";
906  print "<td>".$invoicestatic->getNomUrl(1)."</td>";
907  // Account
908  print "<td>";
909  $accountoshow = length_accountg($k);
910  if (($accountoshow == "") || $accountoshow == 'NotDefined') {
911  print '<span class="error">'.$langs->trans("ProductNotDefined").'</span>';
912  } else {
913  print $accountoshow;
914  }
915  print "</td>";
916  // Subledger account
917  print "<td>";
918  if (!empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT)) {
919  if ($k == getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT')) {
920  print length_accounta($tabcompany[$key]['code_compta']);
921  }
922  } elseif (($accountoshow == "") || $accountoshow == 'NotDefined') {
923  print '<span class="error">' . $langs->trans("ThirdpartyAccountNotDefined") . '</span>';
924  }
925  print '</td>';
926  $companystatic->id = $tabcompany[$key]['id'];
927  $companystatic->name = $tabcompany[$key]['name'];
928  print "<td>".$companystatic->getNomUrl(0, 'customer', 16).' - '.$invoicestatic->ref.' - '.$accountingaccount->label."</td>";
929  print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
930  print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
931  print "</tr>";
932 
933  $i++;
934  }
935 
936  // VAT
937  $listoftax = array(0, 1, 2);
938  foreach ($listoftax as $numtax) {
939  $arrayofvat = $tabtva;
940  if ($numtax == 1) {
941  $arrayofvat = $tablocaltax1;
942  }
943  if ($numtax == 2) {
944  $arrayofvat = $tablocaltax2;
945  }
946 
947  foreach ($arrayofvat[$key] as $k => $mt) {
948  if ($mt) {
949  print '<tr class="oddeven">';
950  print "<!-- VAT -->";
951  print "<td>".$date."</td>";
952  print "<td>".$invoicestatic->getNomUrl(1)."</td>";
953  // Account
954  print "<td>";
955  $accountoshow = length_accountg($k);
956  if (($accountoshow == "") || $accountoshow == 'NotDefined') {
957  print '<span class="error">'.$langs->trans("VATAccountNotDefined").' ('.$langs->trans("Sale").')</span>';
958  } else {
959  print $accountoshow;
960  }
961  print "</td>";
962  // Subledger account
963  print "<td>";
964  print '</td>';
965  print "<td>".$companystatic->getNomUrl(0, 'customer', 16).' - '.$invoicestatic->ref.' - '.$langs->trans("VAT").' '.join(', ', $def_tva[$key][$k]).' %'.($numtax ? ' - Localtax '.$numtax : '');
966  print "</td>";
967  print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
968  print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
969  print "</tr>";
970 
971  $i++;
972  }
973  }
974  }
975  }
976 
977  if (!$i) {
978  print '<tr class="oddeven"><td colspan="6"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
979  }
980 
981  print "</table>";
982  print '</div>';
983 
984  // End of page
985  llxFooter();
986 }
987 
988 $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:5759
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:8466
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:1125
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