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