dolibarr  13.0.2
expensereportsjournal.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-2018 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.'/expensereport/class/expensereport.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/user/class/user.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", "trips", "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 /*
63  * Actions
64  */
65 $accountingaccount = new AccountingAccount($db);
66 
67 // Get informations of journal
68 $accountingjournalstatic = new AccountingJournal($db);
69 $accountingjournalstatic->fetch($id_journal);
70 $journal = $accountingjournalstatic->code;
71 $journal_label = $accountingjournalstatic->label;
72 
73 $date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
74 $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
75 
76 if (empty($date_startmonth) || empty($date_endmonth))
77 {
78  // Period by default on transfer
79  $dates = getDefaultDatesForTransfer();
80  $date_start = $dates['date_start'];
81  $date_end = $dates['date_end'];
82  $pastmonthyear = $dates['pastmonthyear'];
83  $pastmonth = $dates['pastmonth'];
84 }
85 
86 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
87 {
88  $date_start = dol_get_first_day($pastmonthyear, $pastmonth, false);
89  $date_end = dol_get_last_day($pastmonthyear, $pastmonth, false);
90 }
91 
92 $sql = "SELECT er.rowid, er.ref, er.date_debut as de,";
93 $sql .= " erd.rowid as erdid, erd.comments, erd.total_ht, erd.total_tva, erd.total_localtax1, erd.total_localtax2, erd.tva_tx, erd.total_ttc, erd.fk_code_ventilation, erd.vat_src_code, ";
94 $sql .= " u.rowid as uid, u.firstname, u.lastname, u.accountancy_code as user_accountancy_account,";
95 $sql .= " f.accountancy_code, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte";
96 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport_det as erd";
97 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_fees as f ON f.id = erd.fk_c_type_fees";
98 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON aa.rowid = erd.fk_code_ventilation";
99 $sql .= " JOIN ".MAIN_DB_PREFIX."expensereport as er ON er.rowid = erd.fk_expensereport";
100 $sql .= " JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid = er.fk_user_author";
101 $sql .= " WHERE er.fk_statut > 0";
102 $sql .= " AND erd.fk_code_ventilation > 0";
103 $sql .= " AND er.entity IN (".getEntity('expensereport', 0).")"; // We don't share object for accountancy
104 if ($date_start && $date_end)
105  $sql .= " AND er.date_debut >= '".$db->idate($date_start)."' AND er.date_debut <= '".$db->idate($date_end)."'";
106 // Define begin binding date
107 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
108  $sql .= " AND er.date_debut >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING)."'";
109 }
110 // Already in bookkeeping or not
111 if ($in_bookkeeping == 'already')
112 {
113  $sql .= " AND er.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='expense_report')";
114 }
115 if ($in_bookkeeping == 'notyet')
116 {
117  $sql .= " AND er.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='expense_report')";
118 }
119 $sql .= " ORDER BY er.date_debut";
120 
121 dol_syslog('accountancy/journal/expensereportsjournal.php', LOG_DEBUG);
122 $result = $db->query($sql);
123 if ($result) {
124  $taber = array();
125  $tabht = array();
126  $tabtva = array();
127  $def_tva = array();
128  $tabttc = array();
129  $tablocaltax1 = array();
130  $tablocaltax2 = array();
131  $tabuser = array();
132 
133  $num = $db->num_rows($result);
134 
135  // Variables
136  $account_salary = (!empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT)) ? $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT : 'NotDefined';
137  $account_vat = (!empty($conf->global->ACCOUNTING_VAT_BUY_ACCOUNT)) ? $conf->global->ACCOUNTING_VAT_BUY_ACCOUNT : 'NotDefined';
138 
139  $i = 0;
140  while ($i < $num) {
141  $obj = $db->fetch_object($result);
142 
143  // Controls
144  $compta_user = (!empty($obj->user_accountancy_account)) ? $obj->user_accountancy_account : $account_salary;
145  $compta_fees = $obj->compte;
146 
147  $vatdata = getTaxesFromId($obj->tva_tx.($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''), $mysoc, $mysoc, 0);
148  $compta_tva = (!empty($vatdata['accountancy_code_buy']) ? $vatdata['accountancy_code_buy'] : $account_vat);
149  $compta_localtax1 = (!empty($vatdata['accountancy_code_buy']) ? $vatdata['accountancy_code_buy'] : $cpttva);
150  $compta_localtax2 = (!empty($vatdata['accountancy_code_buy']) ? $vatdata['accountancy_code_buy'] : $cpttva);
151 
152  // Define array to display all VAT rates that use this accounting account $compta_tva
153  if (price2num($obj->tva_tx) || !empty($obj->vat_src_code))
154  {
155  $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.')' : ''));
156  }
157 
158  $taber[$obj->rowid]["date"] = $db->jdate($obj->de);
159  $taber[$obj->rowid]["ref"] = $obj->ref;
160  $taber[$obj->rowid]["comments"] = $obj->comments;
161  $taber[$obj->rowid]["fk_expensereportdet"] = $obj->erdid;
162 
163  // Avoid warnings
164  if (!isset($tabttc[$obj->rowid][$compta_user])) $tabttc[$obj->rowid][$compta_user] = 0;
165  if (!isset($tabht[$obj->rowid][$compta_fees])) $tabht[$obj->rowid][$compta_fees] = 0;
166  if (!isset($tabtva[$obj->rowid][$compta_tva])) $tabtva[$obj->rowid][$compta_tva] = 0;
167  if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
168  if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
169 
170  $tabttc[$obj->rowid][$compta_user] += $obj->total_ttc;
171  $tabht[$obj->rowid][$compta_fees] += $obj->total_ht;
172  $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
173  $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
174  $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
175  $tabuser[$obj->rowid] = array(
176  'id' => $obj->uid,
177  'name' => dolGetFirstLastname($obj->firstname, $obj->lastname),
178  'user_accountancy_code' => $obj->user_accountancy_account
179  );
180 
181  $i++;
182  }
183 } else {
184  dol_print_error($db);
185 }
186 
187 // Bookkeeping Write
188 if ($action == 'writebookkeeping') {
189  $now = dol_now();
190  $error = 0;
191 
192  foreach ($taber as $key => $val) // Loop on each expense report
193  {
194  $errorforline = 0;
195 
196  $totalcredit = 0;
197  $totaldebit = 0;
198 
199  $db->begin();
200 
201  // Thirdparty
202  if (!$errorforline)
203  {
204  foreach ($tabttc[$key] as $k => $mt) {
205  if ($mt) {
206  $bookkeeping = new BookKeeping($db);
207  $bookkeeping->doc_date = $val["date"];
208  $bookkeeping->doc_ref = $val["ref"];
209  $bookkeeping->date_creation = $now;
210  $bookkeeping->doc_type = 'expense_report';
211  $bookkeeping->fk_doc = $key;
212  $bookkeeping->fk_docdet = $val["fk_expensereportdet"];
213  $bookkeeping->subledger_account = $tabuser[$key]['user_accountancy_code'];
214  $bookkeeping->subledger_label = $tabuser[$key]['name'];
215  $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT;
216 
217  $accountingaccount->fetch(null, $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT, true);
218  $bookkeeping->label_compte = $accountingaccount->label;
219 
220  $bookkeeping->label_operation = $tabuser[$key]['name'];
221  $bookkeeping->montant = $mt;
222  $bookkeeping->sens = ($mt >= 0) ? 'C' : 'D';
223  $bookkeeping->debit = ($mt <= 0) ? -$mt : 0;
224  $bookkeeping->credit = ($mt > 0) ? $mt : 0;
225  $bookkeeping->code_journal = $journal;
226  $bookkeeping->journal_label = $langs->transnoentities($journal_label);
227  $bookkeeping->fk_user_author = $user->id;
228  $bookkeeping->entity = $conf->entity;
229 
230  $totaldebit += $bookkeeping->debit;
231  $totalcredit += $bookkeeping->credit;
232 
233  $result = $bookkeeping->create($user);
234  if ($result < 0) {
235  if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
236  {
237  $error++;
238  $errorforline++;
239  //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
240  } else {
241  $error++;
242  $errorforline++;
243  setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
244  }
245  }
246  }
247  }
248  }
249 
250  // Fees
251  if (!$errorforline)
252  {
253  foreach ($tabht[$key] as $k => $mt) {
254  if ($mt) {
255  // get compte id and label
256  if ($accountingaccount->fetch(null, $k, true)) {
257  $bookkeeping = new BookKeeping($db);
258  $bookkeeping->doc_date = $val["date"];
259  $bookkeeping->doc_ref = $val["ref"];
260  $bookkeeping->date_creation = $now;
261  $bookkeeping->doc_type = 'expense_report';
262  $bookkeeping->fk_doc = $key;
263  $bookkeeping->fk_docdet = $val["fk_expensereportdet"];
264  $bookkeeping->subledger_account = '';
265  $bookkeeping->subledger_label = '';
266  $bookkeeping->numero_compte = $k;
267  $bookkeeping->label_compte = $accountingaccount->label;
268  $bookkeeping->label_operation = $accountingaccount->label;
269  $bookkeeping->montant = $mt;
270  $bookkeeping->sens = ($mt < 0) ? 'C' : 'D';
271  $bookkeeping->debit = ($mt > 0) ? $mt : 0;
272  $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
273  $bookkeeping->code_journal = $journal;
274  $bookkeeping->journal_label = $langs->transnoentities($journal_label);
275  $bookkeeping->fk_user_author = $user->id;
276  $bookkeeping->entity = $conf->entity;
277 
278  $totaldebit += $bookkeeping->debit;
279  $totalcredit += $bookkeeping->credit;
280 
281  $result = $bookkeeping->create($user);
282  if ($result < 0) {
283  if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
284  {
285  $error++;
286  $errorforline++;
287  //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
288  } else {
289  $error++;
290  $errorforline++;
291  setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
292  }
293  }
294  }
295  }
296  }
297  }
298 
299  // VAT
300  if (!$errorforline)
301  {
302  $listoftax = array(0, 1, 2);
303  foreach ($listoftax as $numtax)
304  {
305  $arrayofvat = $tabtva;
306  if ($numtax == 1) $arrayofvat = $tablocaltax1;
307  if ($numtax == 2) $arrayofvat = $tablocaltax2;
308 
309  foreach ($arrayofvat[$key] as $k => $mt) {
310  if ($mt) {
311  // get compte id and label
312  $bookkeeping = new BookKeeping($db);
313  $bookkeeping->doc_date = $val["date"];
314  $bookkeeping->doc_ref = $val["ref"];
315  $bookkeeping->date_creation = $now;
316  $bookkeeping->doc_type = 'expense_report';
317  $bookkeeping->fk_doc = $key;
318  $bookkeeping->fk_docdet = $val["fk_expensereportdet"];
319  $bookkeeping->subledger_account = '';
320  $bookkeeping->subledger_label = '';
321  $bookkeeping->numero_compte = $k;
322 
323  $accountingaccount->fetch($k, null, true);
324  $bookkeeping->label_compte = $accountingaccount->label;
325 
326  $bookkeeping->label_operation = $langs->trans("VAT").' '.join(', ', $def_tva[$key][$k]).' %';
327  $bookkeeping->montant = $mt;
328  $bookkeeping->sens = ($mt < 0) ? 'C' : 'D';
329  $bookkeeping->debit = ($mt > 0) ? $mt : 0;
330  $bookkeeping->credit = ($mt <= 0) ? -$mt : 0;
331  $bookkeeping->code_journal = $journal;
332  $bookkeeping->journal_label = $langs->transnoentities($journal_label);
333  $bookkeeping->fk_user_author = $user->id;
334  $bookkeeping->entity = $conf->entity;
335 
336  $totaldebit += $bookkeeping->debit;
337  $totalcredit += $bookkeeping->credit;
338 
339  $result = $bookkeeping->create($user);
340  if ($result < 0) {
341  if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
342  {
343  $error++;
344  $errorforline++;
345  //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
346  } else {
347  $error++;
348  $errorforline++;
349  setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
350  }
351  }
352  }
353  }
354  }
355  }
356 
357  // Protection against a bug on line before
358  if (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT'))
359  {
360  $error++;
361  $errorforline++;
362  setEventMessages('Try to insert a non balanced transaction in book for '.$val["ref"].'. Canceled. Surely a bug.', null, 'errors');
363  }
364 
365  if (!$errorforline)
366  {
367  $db->commit();
368  } else {
369  $db->rollback();
370 
371  if ($error >= 10)
372  {
373  setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped"), null, 'errors');
374  break; // Break in the foreach
375  }
376  }
377  }
378 
379  $tabpay = $taber;
380 
381  if (empty($error) && count($tabpay) > 0) {
382  setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
383  } elseif (count($tabpay) == $error)
384  {
385  setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings');
386  } else {
387  setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings');
388  }
389 
390  $action = '';
391 
392  // Must reload data, so we make a redirect
393  if (count($tabpay) != $error)
394  {
395  $param = 'id_journal='.$id_journal;
396  $param .= '&date_startday='.$date_startday;
397  $param .= '&date_startmonth='.$date_startmonth;
398  $param .= '&date_startyear='.$date_startyear;
399  $param .= '&date_endday='.$date_endday;
400  $param .= '&date_endmonth='.$date_endmonth;
401  $param .= '&date_endyear='.$date_endyear;
402  $param .= '&in_bookkeeping='.$in_bookkeeping;
403 
404  header("Location: ".$_SERVER['PHP_SELF'].($param ? '?'.$param : ''));
405  exit;
406  }
407 }
408 
409 
410 /*
411  * View
412  */
413 
414 $form = new Form($db);
415 
416 $userstatic = new User($db);
417 
418 // Export
419 if ($action == 'exportcsv') { // ISO and not UTF8 !
420  $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
421 
422  $filename = 'journal';
423  $type_export = 'journal';
424  include DOL_DOCUMENT_ROOT.'/accountancy/tpl/export_journal.tpl.php';
425 
426  // CSV header line
427  print '"'.$langs->transnoentitiesnoconv("Date").'"'.$sep;
428  print '"'.$langs->transnoentitiesnoconv("Piece").'"'.$sep;
429  print '"'.$langs->transnoentitiesnoconv("AccountAccounting").'"'.$sep;
430  print '"'.$langs->transnoentitiesnoconv("LabelOperation").'"'.$sep;
431  print '"'.$langs->transnoentitiesnoconv("Debit").'"'.$sep;
432  print '"'.$langs->transnoentitiesnoconv("Credit").'"'.$sep;
433  print "\n";
434 
435  foreach ($taber as $key => $val) {
436  $date = dol_print_date($val["date"], 'day');
437 
438  $userstatic->id = $tabuser[$key]['id'];
439  $userstatic->name = $tabuser[$key]['name'];
440 
441  // Fees
442  foreach ($tabht[$key] as $k => $mt) {
443  $accountingaccount = new AccountingAccount($db);
444  $accountingaccount->fetch(null, $k, true);
445  if ($mt) {
446  print '"'.$date.'"'.$sep;
447  print '"'.$val["ref"].'"'.$sep;
448  print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
449  print '"'.dol_trunc($accountingaccount->label, 32).'"'.$sep;
450  print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
451  print '"'.($mt < 0 ? price(-$mt) : '').'"';
452  print "\n";
453  }
454  }
455  // VAT
456  foreach ($tabtva[$key] as $k => $mt) {
457  if ($mt) {
458  print '"'.$date.'"'.$sep;
459  print '"'.$val["ref"].'"'.$sep;
460  print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
461  print '"'.dol_trunc($langs->trans("VAT")).'"'.$sep;
462  print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
463  print '"'.($mt < 0 ? price(-$mt) : '').'"';
464  print "\n";
465  }
466  }
467 
468  // Third party
469  foreach ($tabttc[$key] as $k => $mt) {
470  print '"'.$date.'"'.$sep;
471  print '"'.$val["ref"].'"'.$sep;
472  print '"'.length_accounta(html_entity_decode($k)).'"'.$sep;
473  print '"'.dol_trunc($userstatic->name).'"'.$sep;
474  print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
475  print '"'.($mt >= 0 ? price($mt) : '').'"';
476  }
477  print "\n";
478  }
479 }
480 
481 if (empty($action) || $action == 'view') {
482  llxHeader('', $langs->trans("ExpenseReportsJournal"));
483 
484  $nom = $langs->trans("ExpenseReportsJournal").' | '.$accountingjournalstatic->getNomUrl(0, 1, 1, '', 1);
485  $nomlink = '';
486  $periodlink = '';
487  $exportlink = '';
488  $builddate = dol_now();
489  $description .= $langs->trans("DescJournalOnlyBindedVisible").'<br>';
490 
491  $listofchoices = array('notyet'=>$langs->trans("NotYetInGeneralLedger"), 'already'=>$langs->trans("AlreadyInGeneralLedger"));
492  $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);
493  $period .= ' - '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
494 
495  $varlink = 'id_journal='.$id_journal;
496 
497  journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink);
498 
499  // Button to write into Ledger
500  if (empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) || $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT == '-1') {
501  print '<br>'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone");
502  print ' : '.$langs->trans("AccountancyAreaDescMisc", 4, '<strong>'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'</strong>');
503  }
504  print '<div class="tabsAction tabsActionNoBottom">';
505 
506  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();" />';
507  if (empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) || $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT == '-1') {
508  print '<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("SomeMandatoryStepsOfSetupWereNotDone")).'" value="'.$langs->trans("WriteBookKeeping").'" />';
509  } else {
510  if ($in_bookkeeping == 'notyet') print '<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans("WriteBookKeeping").'" onclick="writebookkeeping();" />';
511  else print '<a href="#" class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans("WriteBookKeeping").'</a>';
512  }
513  print '</div>';
514 
515  // TODO Avoid using js. We can use a direct link with $param
516  print '
517  <script type="text/javascript">
518  function launch_export() {
519  $("div.fiche form input[name=\"action\"]").val("exportcsv");
520  $("div.fiche form input[type=\"submit\"]").click();
521  $("div.fiche form input[name=\"action\"]").val("");
522  }
523  function writebookkeeping() {
524  console.log("click on writebookkeeping");
525  $("div.fiche form input[name=\"action\"]").val("writebookkeeping");
526  $("div.fiche form input[type=\"submit\"]").click();
527  $("div.fiche form input[name=\"action\"]").val("");
528  }
529  </script>';
530 
531  /*
532  * Show result array
533  */
534  print '<br>';
535 
536  $i = 0;
537  print '<div class="div-table-responsive">';
538  print "<table class=\"noborder\" width=\"100%\">";
539  print "<tr class=\"liste_titre\">";
540  print "<td>".$langs->trans("Date")."</td>";
541  print "<td>".$langs->trans("Piece").' ('.$langs->trans("ExpenseReportRef").")</td>";
542  print "<td>".$langs->trans("AccountAccounting")."</td>";
543  print "<td>".$langs->trans("SubledgerAccount")."</td>";
544  print "<td>".$langs->trans("LabelOperation")."</td>";
545  print '<td class="right">'.$langs->trans("Debit")."</td>";
546  print '<td class="right">'.$langs->trans("Credit")."</td>";
547  print "</tr>\n";
548 
549  $r = '';
550 
551  $expensereportstatic = new ExpenseReport($db);
552  $expensereportlinestatic = new ExpenseReportLine($db);
553 
554  foreach ($taber as $key => $val) {
555  $expensereportstatic->id = $key;
556  $expensereportstatic->ref = $val["ref"];
557  $expensereportlinestatic->comments = html_entity_decode(dol_trunc($val["comments"], 32));
558 
559  $date = dol_print_date($val["date"], 'day');
560 
561  // Fees
562  foreach ($tabht[$key] as $k => $mt) {
563  $accountingaccount = new AccountingAccount($db);
564  $accountingaccount->fetch(null, $k, true);
565 
566  if ($mt) {
567  print '<tr class="oddeven">';
568  print "<!-- Fees -->";
569  print "<td>".$date."</td>";
570  print "<td>".$expensereportstatic->getNomUrl(1)."</td>";
571  $userstatic->id = $tabuser[$key]['id'];
572  $userstatic->name = $tabuser[$key]['name'];
573  // Account
574  print "<td>";
575  $accountoshow = length_accountg($k);
576  if (($accountoshow == "") || $accountoshow == 'NotDefined')
577  {
578  print '<span class="error">'.$langs->trans("FeeAccountNotDefined").'</span>';
579  } else print $accountoshow;
580  print '</td>';
581  // Subledger account
582  print "<td>";
583  print '</td>';
584  $userstatic->id = $tabuser[$key]['id'];
585  $userstatic->name = $tabuser[$key]['name'];
586  print "<td>".$userstatic->getNomUrl(0, 'user', 16).' - '.$accountingaccount->label."</td>";
587  print '<td class="right nowraponall">'.($mt >= 0 ? price($mt) : '')."</td>";
588  print '<td class="right nowraponall">'.($mt < 0 ? price(-$mt) : '')."</td>";
589  print "</tr>";
590  }
591  }
592 
593  // Third party
594  foreach ($tabttc[$key] as $k => $mt) {
595  $userstatic->id = $tabuser[$key]['id'];
596  $userstatic->name = $tabuser[$key]['name'];
597 
598  print '<tr class="oddeven">';
599  print "<!-- Thirdparty -->";
600  print "<td>".$date."</td>";
601  print "<td>".$expensereportstatic->getNomUrl(1)."</td>";
602  // Account
603  print "<td>";
604  $accountoshow = length_accounta($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT);
605  if (($accountoshow == "") || $accountoshow == 'NotDefined')
606  {
607  print '<span class="error">'.$langs->trans("MainAccountForUsersNotDefined").'</span>';
608  } else print $accountoshow;
609  print "</td>";
610  // Subledger account
611  print "<td>";
612  $accountoshow = length_accounta($k);
613  if (($accountoshow == "") || $accountoshow == 'NotDefined')
614  {
615  print '<span class="error">'.$langs->trans("UserAccountNotDefined").'</span>';
616  } else print $accountoshow;
617  print '</td>';
618  print "<td>".$userstatic->getNomUrl(0, 'user', 16).' - '.$langs->trans("SubledgerAccount")."</td>";
619  print '<td class="right nowraponall">'.($mt < 0 ? price(-$mt) : '')."</td>";
620  print '<td class="right nowraponall">'.($mt >= 0 ? price($mt) : '')."</td>";
621  print "</tr>";
622  }
623 
624  // VAT
625  $listoftax = array(0, 1, 2);
626  foreach ($listoftax as $numtax) {
627  $arrayofvat = $tabtva;
628  if ($numtax == 1) $arrayofvat = $tablocaltax1;
629  if ($numtax == 2) $arrayofvat = $tablocaltax2;
630 
631  foreach ($arrayofvat[$key] as $k => $mt) {
632  if ($mt) {
633  print '<tr class="oddeven">';
634  print "<!-- VAT -->";
635  print "<td>".$date."</td>";
636  print "<td>".$expensereportstatic->getNomUrl(1)."</td>";
637  // Account
638  print "<td>";
639  $accountoshow = length_accountg($k);
640  if (($accountoshow == "") || $accountoshow == 'NotDefined')
641  {
642  print '<span class="error">'.$langs->trans("VATAccountNotDefined").'</span>';
643  } else print $accountoshow;
644  print "</td>";
645  // Subledger account
646  print "<td>";
647  print '</td>';
648  print "<td>".$userstatic->getNomUrl(0, 'user', 16).' - '.$langs->trans("VAT").' '.join(', ', $def_tva[$key][$k]).' %'.($numtax ? ' - Localtax '.$numtax : '');
649  print "</td>";
650  print '<td class="right nowraponall">'.($mt >= 0 ? price($mt) : '')."</td>";
651  print '<td class="right nowraponall">'.($mt < 0 ? price(-$mt) : '')."</td>";
652  print "</tr>";
653  }
654  }
655  }
656  }
657 
658  print "</table>";
659  print '</div>';
660 
661  // End of page
662  llxFooter();
663 }
664 $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...
Class of expense report details lines.
dol_now($mode= 'auto')
Return date for now.
getDefaultDatesForTransfer()
Return Default dates for transfer based on periodicity option in accountancy setup.
Class to manage Dolibarr users.
Definition: user.class.php:44
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
journalHead($nom, $variante, $period, $periodlink, $description, $builddate, $exportlink= '', $moreparam=array(), $calcmode= '', $varlink= '')
Show header of a page used to transfer/dispatch data in accounting.
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.
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.
Class to manage Trips and Expenses.
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.
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).
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
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.