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