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