dolibarr  7.0.0-beta
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@capnetworks.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  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
29 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT . '/core/lib/report.lib.php';
31 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
32 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
33 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
34 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
35 require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php';
36 require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php';
37 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
38 
39 $langs->loadLangs(array("commercial", "compta","bills","other","accountancy","trips","errors"));
40 
41 $id_journal = GETPOST('id_journal', 'int');
42 $action = GETPOST('action','aZ09');
43 
44 $date_startmonth = GETPOST('date_startmonth');
45 $date_startday = GETPOST('date_startday');
46 $date_startyear = GETPOST('date_startyear');
47 $date_endmonth = GETPOST('date_endmonth');
48 $date_endday = GETPOST('date_endday');
49 $date_endyear = GETPOST('date_endyear');
50 $in_bookkeeping = GETPOST('in_bookkeeping');
51 if ($in_bookkeeping == '') $in_bookkeeping = 'notyet';
52 
53 $now = dol_now();
54 
55 // Security check
56 if ($user->societe_id > 0)
58 
59 /*
60  * Actions
61  */
62 
63 // Get informations of journal
64 $accountingjournalstatic = new AccountingJournal($db);
65 $accountingjournalstatic->fetch($id_journal);
66 $journal = $accountingjournalstatic->code;
67 $journal_label = $accountingjournalstatic->label;
68 
69 $year_current = strftime("%Y", dol_now());
70 $pastmonth = strftime("%m", dol_now()) - 1;
71 $pastmonthyear = $year_current;
72 if ($pastmonth == 0) {
73  $pastmonth = 12;
74  $pastmonthyear --;
75 }
76 
77 $date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
78 $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
79 
80 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
81 {
82  $date_start = dol_get_first_day($pastmonthyear, $pastmonth, false);
83  $date_end = dol_get_last_day($pastmonthyear, $pastmonth, false);
84 }
85 
86 $idpays = $mysoc->country_id;
87 
88 $sql = "SELECT er.rowid, er.ref, er.date_debut as de,";
89 $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, ";
90 $sql .= " u.rowid as uid, u.firstname, u.lastname, u.accountancy_code as user_accountancy_account,";
91 $sql .= " f.accountancy_code, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte";
92 //$sql .= " ct.accountancy_code_buy as account_tva";
93 $sql .= " FROM " . MAIN_DB_PREFIX . "expensereport_det as erd";
94 //$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_tva as ct ON erd.tva_tx = ct.taux AND ct.fk_pays = '" . $idpays . "'";
95 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_type_fees as f ON f.id = erd.fk_c_type_fees";
96 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = erd.fk_code_ventilation";
97 $sql .= " JOIN " . MAIN_DB_PREFIX . "expensereport as er ON er.rowid = erd.fk_expensereport";
98 $sql .= " JOIN " . MAIN_DB_PREFIX . "user as u ON u.rowid = er.fk_user_author";
99 $sql .= " WHERE er.fk_statut > 0";
100 $sql .= " AND erd.fk_code_ventilation > 0";
101 $sql .= " AND er.entity IN (" . getEntity('expensereport', 0) . ")"; // We don't share object for accountancy
102 if ($date_start && $date_end)
103  $sql .= " AND er.date_debut >= '" . $db->idate($date_start) . "' AND er.date_debut <= '" . $db->idate($date_end) . "'";
104 // Already in bookkeeping or not
105 if ($in_bookkeeping == 'already')
106 {
107  $sql .= " AND er.rowid IN (SELECT fk_doc FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab WHERE ab.doc_type='expense_report')";
108 }
109 if ($in_bookkeeping == 'notyet')
110 {
111  $sql .= " AND er.rowid NOT IN (SELECT fk_doc FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab WHERE ab.doc_type='expense_report')";
112 }
113 $sql .= " ORDER BY er.date_debut";
114 
115 dol_syslog('accountancy/journal/expensereportsjournal.php', LOG_DEBUG);
116 $result = $db->query($sql);
117 if ($result) {
118 
119  $taber = array ();
120  $tabht = array ();
121  $tabtva = array ();
122  $def_tva = array ();
123  $tabttc = array ();
124  $tablocaltax1 = array ();
125  $tablocaltax2 = array ();
126  $tabuser = array ();
127 
128  $num = $db->num_rows($result);
129 
130  // Variables
131  $account_salary = (! empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT)) ? $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT : 'NotDefined';
132  $account_vat = (! empty($conf->global->ACCOUNTING_VAT_BUY_ACCOUNT)) ? $conf->global->ACCOUNTING_VAT_BUY_ACCOUNT : 'NotDefined';
133 
134  $i = 0;
135  while ( $i < $num ) {
136  $obj = $db->fetch_object($result);
137 
138  // Controls
139  $compta_user = (! empty($obj->user_accountancy_account)) ? $obj->user_accountancy_account : $account_salary;
140  $compta_fees = $obj->compte;
141 
142  $vatdata = getTaxesFromId($obj->tva_tx.($obj->vat_src_code?' ('.$obj->vat_src_code.')':''), $mysoc, $mysoc, 0);
143  $compta_tva = (! empty($vatdata['accountancy_code_sell']) ? $vatdata['accountancy_code_sell'] : $account_vat);
144  $compta_localtax1 = (! empty($vatdata['accountancy_code_sell']) ? $vatdata['accountancy_code_sell'] : $cpttva);
145  $compta_localtax2 = (! empty($vatdata['accountancy_code_sell']) ? $vatdata['accountancy_code_sell'] : $cpttva);
146 
147  // Define array to display all VAT rates that use this accounting account $compta_tva
148  if (price2num($obj->tva_tx) || ! empty($obj->vat_src_code))
149  {
150  $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.')':''));
151  }
152 
153  $taber[$obj->rowid]["date"] = $db->jdate($obj->de);
154  $taber[$obj->rowid]["ref"] = $obj->ref;
155  $taber[$obj->rowid]["comments"] = $obj->comments;
156  $taber[$obj->rowid]["fk_expensereportdet"] = $obj->erdid;
157 
158  // Avoid warnings
159  if (! isset($tabttc[$obj->rowid][$compta_user])) $tabttc[$obj->rowid][$compta_user] = 0;
160  if (! isset($tabht[$obj->rowid][$compta_fees])) $tabht[$obj->rowid][$compta_fees] = 0;
161  if (! isset($tabtva[$obj->rowid][$compta_tva])) $tabtva[$obj->rowid][$compta_tva] = 0;
162  if (! isset($tablocaltax1[$obj->rowid][$compta_localtax1])) $tablocaltax1[$obj->rowid][$compta_localtax1] = 0;
163  if (! isset($tablocaltax2[$obj->rowid][$compta_localtax2])) $tablocaltax2[$obj->rowid][$compta_localtax2] = 0;
164 
165  $tabttc[$obj->rowid][$compta_user] += $obj->total_ttc;
166  $tabht[$obj->rowid][$compta_fees] += $obj->total_ht;
167  $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
168  $tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
169  $tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
170  $tabuser[$obj->rowid] = array (
171  'id' => $obj->uid,
172  'name' => dolGetFirstLastname($obj->firstname, $obj->lastname),
173  'user_accountancy_code' => $obj->user_accountancy_account
174  );
175 
176  $i ++;
177  }
178 } else {
179  dol_print_error($db);
180 }
181 
182 // Bookkeeping Write
183 if ($action == 'writebookkeeping') {
184  $now = dol_now();
185  $error = 0;
186 
187  foreach ($taber as $key => $val) // Loop on each expense report
188  {
189  $errorforline = 0;
190 
191  $totalcredit = 0;
192  $totaldebit = 0;
193 
194  $db->begin();
195 
196  // Thirdparty
197  if (! $errorforline)
198  {
199  foreach ( $tabttc[$key] as $k => $mt ) {
200  if ($mt) {
201  $bookkeeping = new BookKeeping($db);
202  $bookkeeping->doc_date = $val["date"];
203  $bookkeeping->doc_ref = $val["ref"];
204  $bookkeeping->date_create = $now;
205  $bookkeeping->doc_type = 'expense_report';
206  $bookkeeping->fk_doc = $key;
207  $bookkeeping->fk_docdet = $val["fk_expensereportdet"];
208  $bookkeeping->subledger_account = $tabuser[$key]['user_accountancy_code'];
209  $bookkeeping->subledger_label = $tabuser[$key]['user_accountancy_code'];
210  $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT;
211  $bookkeeping->label_operation = $tabuser[$key]['name'];
212  $bookkeeping->montant = $mt;
213  $bookkeeping->sens = ($mt >= 0) ? 'C' : 'D';
214  $bookkeeping->debit = ($mt <= 0) ? -$mt : 0;
215  $bookkeeping->credit = ($mt > 0) ? $mt : 0;
216  $bookkeeping->code_journal = $journal;
217  $bookkeeping->journal_label = $journal_label;
218  $bookkeeping->fk_user_author = $user->id;
219 
220  $totaldebit += $bookkeeping->debit;
221  $totalcredit += $bookkeeping->credit;
222 
223  $result = $bookkeeping->create($user);
224  if ($result < 0) {
225  if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
226  {
227  $error++;
228  $errorforline++;
229  //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
230  }
231  else
232  {
233  $error++;
234  $errorforline++;
235  setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
236  }
237  }
238  }
239  }
240  }
241 
242  // Fees
243  if (! $errorforline)
244  {
245  foreach ( $tabht[$key] as $k => $mt ) {
246  if ($mt) {
247  // get compte id and label
248  $accountingaccount = new AccountingAccount($db);
249  if ($accountingaccount->fetch(null, $k, true)) {
250  $bookkeeping = new BookKeeping($db);
251  $bookkeeping->doc_date = $val["date"];
252  $bookkeeping->doc_ref = $val["ref"];
253  $bookkeeping->date_create = $now;
254  $bookkeeping->doc_type = 'expense_report';
255  $bookkeeping->fk_doc = $key;
256  $bookkeeping->fk_docdet = $val["fk_expensereportdet"];
257  $bookkeeping->subledger_account = '';
258  $bookkeeping->subledger_label = '';
259  $bookkeeping->numero_compte = $k;
260  $bookkeeping->label_operation = $accountingaccount->label;
261  $bookkeeping->montant = $mt;
262  $bookkeeping->sens = ($mt < 0) ? 'C' : 'D';
263  $bookkeeping->debit = ($mt > 0) ? $mt : 0;
264  $bookkeeping->credit = ($mt <= 0) ? $mt : 0;
265  $bookkeeping->code_journal = $journal;
266  $bookkeeping->journal_label = $journal_label;
267  $bookkeeping->fk_user_author = $user->id;
268 
269  $totaldebit += $bookkeeping->debit;
270  $totalcredit += $bookkeeping->credit;
271 
272  $result = $bookkeeping->create($user);
273  if ($result < 0) {
274  if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
275  {
276  $error++;
277  $errorforline++;
278  //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
279  }
280  else
281  {
282  $error++;
283  $errorforline++;
284  setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
285  }
286  }
287  }
288  }
289  }
290  }
291 
292  // VAT
293  if (! $errorforline)
294  {
295  $listoftax=array(0, 1, 2);
296  foreach($listoftax as $numtax)
297  {
298  $arrayofvat = $tabtva;
299  if ($numtax == 1) $arrayofvat = $tablocaltax1;
300  if ($numtax == 2) $arrayofvat = $tablocaltax2;
301 
302  foreach ( $arrayofvat[$key] as $k => $mt ) {
303  if ($mt) {
304  // get compte id and label
305  $bookkeeping = new BookKeeping($db);
306  $bookkeeping->doc_date = $val["date"];
307  $bookkeeping->doc_ref = $val["ref"];
308  $bookkeeping->date_create = $now;
309  $bookkeeping->doc_type = 'expense_report';
310  $bookkeeping->fk_doc = $key;
311  $bookkeeping->fk_docdet = $val["fk_expensereportdet"];
312  $bookkeeping->subledger_account = '';
313  $bookkeeping->subledger_label = '';
314  $bookkeeping->numero_compte = $k;
315  $bookkeeping->label_operation = $langs->trans("VAT"). ' '.join(', ',$def_tva[$key][$k]).' %';
316  $bookkeeping->montant = $mt;
317  $bookkeeping->sens = ($mt < 0) ? 'C' : 'D';
318  $bookkeeping->debit = ($mt > 0) ? $mt : 0;
319  $bookkeeping->credit = ($mt <= 0) ? $mt : 0;
320  $bookkeeping->code_journal = $journal;
321  $bookkeeping->journal_label = $journal_label;
322  $bookkeeping->fk_user_author = $user->id;
323 
324  $totaldebit += $bookkeeping->debit;
325  $totalcredit += $bookkeeping->credit;
326 
327  $result = $bookkeeping->create($user);
328  if ($result < 0) {
329  if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
330  {
331  $error++;
332  $errorforline++;
333  //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
334  }
335  else
336  {
337  $error++;
338  $errorforline++;
339  setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
340  }
341  }
342  }
343  }
344  }
345  }
346 
347  if ($totaldebit != $totalcredit)
348  {
349  $error++;
350  $errorforline++;
351  setEventMessages('Try to insert a non balanced transaction in book for '.$val["ref"].'. Canceled. Surely a bug.', null, 'errors');
352  }
353 
354  if (! $errorforline)
355  {
356  $db->commit();
357  }
358  else
359  {
360  $db->rollback();
361 
362  if ($error >= 10)
363  {
364  setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped"), null, 'errors');
365  break; // Break in the foreach
366  }
367  }
368  }
369 
370  $tabpay = $taber;
371 
372  if (empty($error) && count($tabpay) > 0) {
373  setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
374  }
375  elseif (count($tabpay) == $error)
376  {
377  setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings');
378  }
379  else
380  {
381  setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings');
382  }
383 
384  $action='';
385 
386  // Must reload data, so we make a redirect
387  if (count($tabpay) != $error)
388  {
389  $param='id_journal='.$id_journal;
390  $param.='&date_startday='.$date_startday;
391  $param.='&date_startmonth='.$date_startmonth;
392  $param.='&date_startyear='.$date_startyear;
393  $param.='&date_endday='.$date_endday;
394  $param.='&date_endmonth='.$date_endmonth;
395  $param.='&date_endyear='.$date_endyear;
396  $param.='&in_bookkeeping='.$in_bookkeeping;
397  header("Location: ".$_SERVER['PHP_SELF'].($param?'?'.$param:''));
398  exit;
399  }
400 }
401 
402 /*
403  * View
404  */
405 
406 $form = new Form($db);
407 
408 $userstatic = new User($db);
409 
410 // Export
411 /*if ($action == 'exportcsv') {
412  $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
413 
414  include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php';
415 
416  // Model Cegid Expert Export
417  if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) {
418  $sep = ";";
419 
420  foreach ( $taber as $key => $val ) {
421  $date = dol_print_date($val["date"], '%d%m%Y');
422 
423  // Fees
424  foreach ( $tabht[$key] as $k => $mt ) {
425  $userstatic->id = $tabuser[$key]['id'];
426  $userstatic->name = $tabuser[$key]['name'];
427  $userstatic->client = $tabuser[$key]['code_client'];
428 
429  if ($mt) {
430  print $date . $sep;
431  print $journal . $sep;
432  print length_accountg(html_entity_decode($k)) . $sep;
433  print $sep;
434  print ($mt < 0 ? 'C' : 'D') . $sep;
435  print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
436  print dol_trunc($val["comments"], 32) . $sep;
437  print $val["ref"];
438  print "\n";
439  }
440  }
441 
442  // VAT
443  foreach ( $tabtva[$key] as $k => $mt ) {
444  if ($mt) {
445  print $date . $sep;
446  print $journal . $sep;
447  print length_accountg(html_entity_decode($k)) . $sep;
448  print $sep;
449  print ($mt < 0 ? 'C' : 'D') . $sep;
450  print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
451  print $langs->trans("VAT") . $sep;
452  print $val["ref"];
453  print "\n";
454  }
455  }
456 
457  foreach ( $tabttc[$key] as $k => $mt ) {
458  print $date . $sep;
459  print $journal . $sep;
460  print length_accountg($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) . $sep;
461  print length_accounta(html_entity_decode($k)) . $sep;
462  print ($mt < 0 ? 'D' : 'C') . $sep;
463  print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
464  print $userstatic->name . $sep;
465  print $val["ref"];
466  print "\n";
467  }
468  }
469  } elseif ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 1) {
470  // Model Classic Export
471  foreach ( $taber as $key => $val ) {
472  $date = dol_print_date($val["date"], 'day');
473 
474  $userstatic->id = $tabuser[$key]['id'];
475  $userstatic->name = $tabuser[$key]['name'];
476 
477  // Fees
478  foreach ( $tabht[$key] as $k => $mt ) {
479  $accountingaccount = new AccountingAccount($db);
480  $accountingaccount->fetch(null, $k, true);
481  if ($mt) {
482  print '"' . $date . '"' . $sep;
483  print '"' . $val["ref"] . '"' . $sep;
484  print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
485  print '"' . dol_trunc($accountingaccount->label, 32) . '"' . $sep;
486  print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
487  print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
488  print "\n";
489  }
490  }
491  // VAT
492  foreach ( $tabtva[$key] as $k => $mt ) {
493  if ($mt) {
494  print '"' . $date . '"' . $sep;
495  print '"' . $val["ref"] . '"' . $sep;
496  print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
497  print '"' . dol_trunc($langs->trans("VAT")) . '"' . $sep;
498  print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
499  print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
500  print "\n";
501  }
502  }
503 
504  // Third party
505  foreach ( $tabttc[$key] as $k => $mt ) {
506  print '"' . $date . '"' . $sep;
507  print '"' . $val["ref"] . '"' . $sep;
508  print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
509  print '"' . dol_trunc($userstatic->name) . '"' . $sep;
510  print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
511  print '"' . ($mt >= 0 ? price($mt) : '') . '"';
512  }
513  print "\n";
514  }
515  }
516 }
517 */
518 
519 if (empty($action) || $action == 'view') {
520 
521  llxHeader('', $langs->trans("ExpenseReportsJournal"));
522 
523  $nom = $langs->trans("ExpenseReportsJournal") . ' - ' . $accountingjournalstatic->getNomUrl(1);
524  $nomlink = '';
525  $periodlink = '';
526  $exportlink = '';
527  $builddate=dol_now();
528  $description.= $langs->trans("DescJournalOnlyBindedVisible").'<br>';
529 
530  $listofchoices=array('already'=>$langs->trans("AlreadyInGeneralLedger"), 'notyet'=>$langs->trans("NotYetInGeneralLedger"));
531  $period = $form->select_date($date_start?$date_start:-1, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end?$date_end:-1, 'date_end', 0, 0, 0, '', 1, 0, 1). ' - ' .$langs->trans("JournalizationInLedgerStatus").' '. $form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
532 
533  $varlink = 'id_journal=' . $id_journal;
534 
535  journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink);
536 
537  // Button to write into Ledger
538  if (empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) || $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT == '-1') {
539  print '<br>'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone");
540  print ' : '.$langs->trans("AccountancyAreaDescMisc", 4, '<strong>'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'</strong>');
541  }
542  print '<div class="tabsAction tabsActionNoBottom">';
543  if (empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) || $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT == '-1') {
544  print '<input type="button" class="butActionRefused" title="'.dol_escape_htmltag($langs->trans("SomeMandatoryStepsOfSetupWereNotDone")).'" value="' . $langs->trans("WriteBookKeeping") . '" />';
545  }
546  else {
547  if ($in_bookkeeping == 'notyet') print '<input type="button" class="butAction" name="writebookkeeping" value="' . $langs->trans("WriteBookKeeping") . '" onclick="writebookkeeping();" />';
548  else print '<a href="#" class="butActionRefused" name="writebookkeeping">' . $langs->trans("WriteBookKeeping") . '</a>';
549  }
550  //print '<input type="button" class="butAction" name="exportcsv" value="' . $langs->trans("ExportDraftJournal") . '" onclick="launch_export();" />';
551  print '</div>';
552 
553  // TODO Avoid using js. We can use a direct link with $param
554  print '
555  <script type="text/javascript">
556  function launch_export() {
557  $("div.fiche div.tabBar form input[name=\"action\"]").val("exportcsv");
558  $("div.fiche div.tabBar form input[type=\"submit\"]").click();
559  $("div.fiche div.tabBar form input[name=\"action\"]").val("");
560  }
561  function writebookkeeping() {
562  $("div.fiche div.tabBar form input[name=\"action\"]").val("writebookkeeping");
563  $("div.fiche div.tabBar form input[type=\"submit\"]").click();
564  $("div.fiche div.tabBar form input[name=\"action\"]").val("");
565  }
566  </script>';
567 
568  /*
569  * Show result array
570  */
571  print '<br>';
572 
573  $i = 0;
574  print '<div class="div-table-responsive">';
575  print "<table class=\"noborder\" width=\"100%\">";
576  print "<tr class=\"liste_titre\">";
577  print "<td></td>";
578  print "<td>" . $langs->trans("Date") . "</td>";
579  print "<td>" . $langs->trans("Piece") . ' (' . $langs->trans("ExpenseReportRef") . ")</td>";
580  print "<td>" . $langs->trans("AccountAccounting") . "</td>";
581  print "<td>" . $langs->trans("SubledgerAccount") . "</td>";
582  print "<td>" . $langs->trans("LabelOperation") . "</td>";
583  print "<td align='right'>" . $langs->trans("Debit") . "</td>";
584  print "<td align='right'>" . $langs->trans("Credit") . "</td>";
585  print "</tr>\n";
586 
587  $r = '';
588 
589  $expensereportstatic = new ExpenseReport($db);
590  $expensereportlinestatic = new ExpenseReportLine($db);
591 
592  foreach ( $taber as $key => $val ) {
593  $expensereportstatic->id = $key;
594  $expensereportstatic->ref = $val["ref"];
595  $expensereportlinestatic->comments = html_entity_decode(dol_trunc($val["comments"], 32));
596 
597  $date = dol_print_date($val["date"], 'day');
598 
599  // Fees
600  foreach ( $tabht[$key] as $k => $mt ) {
601  $accountingaccount = new AccountingAccount($db);
602  $accountingaccount->fetch(null, $k, true);
603 
604  if ($mt) {
605  print '<tr class="oddeven">';
606  print "<td><!-- Fees --></td>";
607  print "<td>" . $date . "</td>";
608  print "<td>" . $expensereportstatic->getNomUrl(1) . "</td>";
609  $userstatic->id = $tabuser[$key]['id'];
610  $userstatic->name = $tabuser[$key]['name'];
611  // Account
612  print "<td>";
613  $accountoshow = length_accountg($k);
614  if (empty($accountoshow) || $accountoshow == 'NotDefined')
615  {
616  print '<span class="error">'.$langs->trans("FeeAccountNotDefined").'</span>';
617  }
618  else print $accountoshow;
619  print '</td>';
620  // Subledger account
621  print "<td>";
622  print '</td>';
623  $userstatic->id = $tabuser[$key]['id'];
624  $userstatic->name = $tabuser[$key]['name'];
625  print "<td>" . $userstatic->getNomUrl(0, 'user', 16) . ' - ' . $accountingaccount->label . "</td>";
626  print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
627  print '<td align="right">' . ($mt < 0 ? price(- $mt) : '') . "</td>";
628  print "</tr>";
629  }
630  }
631 
632  // Third party
633  foreach ( $tabttc[$key] as $k => $mt ) {
634  print '<tr class="oddeven">';
635  print "<td><!-- Thirdparty --></td>";
636  print "<td>" . $date . "</td>";
637  print "<td>" . $expensereportstatic->getNomUrl(1) . "</td>";
638  $userstatic->id = $tabuser[$key]['id'];
639  $userstatic->name = $tabuser[$key]['name'];
640  // Account
641  print "<td>";
642  $accountoshow = length_accounta($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT);
643  if (empty($accountoshow) || $accountoshow == 'NotDefined')
644  {
645  print '<span class="error">'.$langs->trans("MainAccountForUsersNotDefined").'</span>';
646  }
647  else print $accountoshow;
648  print "</td>";
649  // Subledger account
650  print "<td>";
651  $accountoshow = length_accounta($k);
652  if (empty($accountoshow) || $accountoshow == 'NotDefined')
653  {
654  print '<span class="error">'.$langs->trans("UserAccountNotDefined").'</span>';
655  }
656  else print $accountoshow;
657  print '</td>';
658  print "<td>" . $userstatic->getNomUrl(0, 'user', 16) . ' - ' . $langs->trans("SubledgerAccount") . "</td>";
659  print '<td align="right">' . ($mt < 0 ? - price(- $mt) : '') . "</td>";
660  print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
661  print "</tr>";
662  }
663 
664  // VAT
665  $listoftax = array(0, 1, 2);
666  foreach ($listoftax as $numtax) {
667  $arrayofvat = $tabtva;
668  if ($numtax == 1) $arrayofvat = $tablocaltax1;
669  if ($numtax == 2) $arrayofvat = $tablocaltax2;
670 
671  foreach ( $arrayofvat[$key] as $k => $mt ) {
672  if ($mt) {
673  print '<tr class="oddeven">';
674  print "<td><!-- VAT --></td>";
675  print "<td>" . $date . "</td>";
676  print "<td>" . $expensereportstatic->getNomUrl(1) . "</td>";
677  // Account
678  print "<td>";
679  $accountoshow = length_accountg($k);
680  if (empty($accountoshow) || $accountoshow == 'NotDefined')
681  {
682  print '<span class="error">'.$langs->trans("VATAccountNotDefined").'</span>';
683  }
684  else print $accountoshow;
685  print "</td>";
686  // Subledger account
687  print "<td>";
688  print '</td>';
689  print "<td>" . $userstatic->getNomUrl(0, 'user', 16) . ' - ' . $langs->trans("VAT"). ' '.join(', ',$def_tva[$key][$k]).' %'.($numtax?' - Localtax '.$numtax:'');
690  print "</td>";
691  print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
692  print '<td align="right">' . ($mt < 0 ? price(- $mt) : '') . "</td>";
693  print "</tr>";
694  }
695  }
696  }
697  }
698 
699  print "</table>";
700  print '</div>';
701 
702  // End of page
703  llxFooter();
704 }
705 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
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 '...' if string larger than length.
Class of expense report details lines.
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 Dolibarr users.
Definition: user.class.php:39
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:445
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
llxHeader()
Empty header.
Definition: wrapper.php:46
getEntity($element, $shared=1, $forceentity=null)
Get list of entity id to use.
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
dol_now($mode='gmt')
Return date for now.
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...
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).
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:459
print
Draft customers invoices.
Definition: index.php:91
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 '...
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.