dolibarr  16.0.5
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2015-2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
6  * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
7  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  */
22 
29 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formexpensereport.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/expensereport.lib.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
42 require_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php';
43 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
44 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php';
45 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
46 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
47 if (!empty($conf->accounting->enabled)) {
48  require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
49 }
50 
51 // Load translation files required by the page
52 $langs->loadLangs(array("trips", "bills", "mails"));
53 
54 $action = GETPOST('action', 'aZ09');
55 $cancel = GETPOST('cancel', 'alpha');
56 $confirm = GETPOST('confirm', 'alpha');
57 
58 $id = GETPOST('id', 'int');
59 $date_start = dol_mktime(0, 0, 0, GETPOST('date_debutmonth', 'int'), GETPOST('date_debutday', 'int'), GETPOST('date_debutyear', 'int'));
60 $date_end = dol_mktime(0, 0, 0, GETPOST('date_finmonth', 'int'), GETPOST('date_finday', 'int'), GETPOST('date_finyear', 'int'));
61 $date = dol_mktime(0, 0, 0, GETPOST('datemonth', 'int'), GETPOST('dateday', 'int'), GETPOST('dateyear', 'int'));
62 $fk_project = GETPOST('fk_project', 'int');
63 $vatrate = GETPOST('vatrate', 'alpha');
64 $ref = GETPOST("ref", 'alpha');
65 $comments = GETPOST('comments', 'restricthtml');
66 $fk_c_type_fees = GETPOST('fk_c_type_fees', 'int');
67 $socid = GETPOST('socid', 'int') ?GETPOST('socid', 'int') : GETPOST('socid_id', 'int');
68 
69 $childids = $user->getAllChildIds(1);
70 
71 if (! empty($conf->global->EXPENSEREPORT_PREFILL_DATES_WITH_CURRENT_MONTH)) {
72  if (empty($date_start)) {
73  $date_start = dol_mktime(0, 0, 0, (int) dol_print_date(dol_now(), '%m'), 1, (int) dol_print_date(dol_now(), '%Y'));
74  }
75 
76  if (empty($date_end)) {
77  // date('t') => number of days in the month, so last day of the month too
78  $date_end = dol_mktime(0, 0, 0, (int) dol_print_date(dol_now(), '%m'), (int) date('t'), (int) dol_print_date(dol_now(), '%Y'));
79  }
80 }
81 
82 // Hack to use expensereport dir
83 $rootfordata = DOL_DATA_ROOT;
84 $rootforuser = DOL_DATA_ROOT;
85 // If multicompany module is enabled, we redefine the root of data
86 if (!empty($conf->multicompany->enabled) && !empty($conf->entity) && $conf->entity > 1) {
87  $rootfordata .= '/'.$conf->entity;
88 }
89 $conf->expensereport->dir_output = $rootfordata.'/expensereport';
90 
91 // Define $urlwithroot
92 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
93 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
94 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
95 
96 // PDF
97 $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
98 $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
99 $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
100 
101 
102 $object = new ExpenseReport($db);
103 $extrafields = new ExtraFields($db);
104 
105 // fetch optionals attributes and labels
106 $extrafields->fetch_name_optionals_label($object->table_element);
107 
108 // Load object
109 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
110 
111 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
112 $hookmanager->initHooks(array('expensereportcard', 'globalcard'));
113 
114 $permissionnote = $user->rights->expensereport->creer; // Used by the include of actions_setnotes.inc.php
115 $permissiondellink = $user->rights->expensereport->creer; // Used by the include of actions_dellink.inc.php
116 $permissiontoadd = $user->rights->expensereport->creer; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
117 
118 $upload_dir = $conf->expensereport->dir_output.'/'.dol_sanitizeFileName($object->ref);
119 
120 $projectRequired = $conf->project->enabled && ! empty($conf->global->EXPENSEREPORT_PROJECT_IS_REQUIRED);
121 $fileRequired = !empty($conf->global->EXPENSEREPORT_FILE_IS_REQUIRED);
122 
123 if ($object->id > 0) {
124  // Check current user can read this expense report
125  $canread = 0;
126  if (!empty($user->rights->expensereport->readall)) {
127  $canread = 1;
128  }
129  if (!empty($user->rights->expensereport->lire) && in_array($object->fk_user_author, $childids)) {
130  $canread = 1;
131  }
132  if (!$canread) {
133  accessforbidden();
134  }
135 }
136 
137 $candelete = 0;
138 if (!empty($user->rights->expensereport->supprimer)) {
139  $candelete = 1;
140 }
141 if ($object->statut == ExpenseReport::STATUS_DRAFT && $user->hasRight('expensereport', 'write') && in_array($object->fk_user_author, $childids)) {
142  $candelete = 1;
143 }
144 
145 // Security check
146 if ($user->socid) {
147  $socid = $user->socid;
148 }
149 $result = restrictedArea($user, 'expensereport', $object->id, 'expensereport');
150 
151 $permissiontoadd = $user->rights->expensereport->creer; // Used by the include of actions_dellink.inc.php
152 
153 
154 /*
155  * Actions
156  */
157 
158 $parameters = array('socid' => $socid);
159 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
160 if ($reshook < 0) {
161  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
162 }
163 
164 if (empty($reshook)) {
165  $backurlforlist = DOL_URL_ROOT.'/expensereport/list.php';
166 
167  if (empty($backtopage) || ($cancel && empty($id))) {
168  if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
169  if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
170  $backtopage = $backurlforlist;
171  } else {
172  $backtopage = DOL_URL_ROOT.'/expensereport/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
173  }
174  }
175  }
176 
177  if ($cancel) {
178  if (!empty($backtopageforcancel)) {
179  header("Location: ".$backtopageforcancel);
180  exit;
181  } elseif (!empty($backtopage)) {
182  header("Location: ".$backtopage);
183  exit;
184  }
185  $action = '';
186 
187  $fk_project = '';
188  $date_start = '';
189  $date_end = '';
190  $date = '';
191  $comments = '';
192  $vatrate = '';
193  $value_unit_ht = '';
194  $value_unit = '';
195  $qty = 1;
196  $fk_c_type_fees = -1;
197  }
198 
199  include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
200 
201  if (!empty(GETPOST('sendit', 'alpha'))) { // If we just submit a file
202  if ($action == 'updateline') {
203  $action = 'editline'; // To avoid to make the updateline now
204  } else {
205  $action = ''; // To avoid to make the addline now
206  }
207  }
208 
209  include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
210 
211  include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
212 
213  include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
214 
215  // Action clone object
216  if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->expensereport->creer) {
217  if (1 == 0 && !GETPOST('clone_content', 'alpha') && !GETPOST('clone_receivers', 'alpha')) {
218  setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
219  } else {
220  if ($object->id > 0) {
221  // Because createFromClone modifies the object, we must clone it so that we can restore it later if it fails
222  $orig = clone $object;
223 
224  $result = $object->createFromClone($user, GETPOST('fk_user_author', 'int'));
225  if ($result > 0) {
226  header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
227  exit;
228  } else {
229  setEventMessages($object->error, $object->errors, 'errors');
230  $object = $orig;
231  $action = '';
232  }
233  }
234  }
235  }
236 
237  if ($action == 'confirm_delete' && GETPOST("confirm", 'alpha') == "yes" && $id > 0 && $candelete) {
238  $object = new ExpenseReport($db);
239  $result = $object->fetch($id);
240  $result = $object->delete($user);
241  if ($result >= 0) {
242  header("Location: index.php");
243  exit;
244  } else {
245  setEventMessages($object->error, $object->errors, 'errors');
246  }
247  }
248 
249  if ($action == 'add' && $user->rights->expensereport->creer) {
250  $error = 0;
251 
252  $object = new ExpenseReport($db);
253 
254  $object->date_debut = $date_start;
255  $object->date_fin = $date_end;
256 
257  $object->fk_user_author = GETPOST('fk_user_author', 'int');
258  if (!($object->fk_user_author > 0)) {
259  $object->fk_user_author = $user->id;
260  }
261 
262  // Check that expense report is for a user inside the hierarchy, or that advanced permission for all is set
263  if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->expensereport->creer))
264  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->expensereport->creer) && empty($user->rights->expensereport->writeall_advance))) {
265  $error++;
266  setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
267  }
268  if (!$error) {
269  if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance)) {
270  if (!in_array($object->fk_user_author, $childids)) {
271  $error++;
272  setEventMessages($langs->trans("UserNotInHierachy"), null, 'errors');
273  }
274  }
275  }
276 
277  $fuser = new User($db);
278  $fuser->fetch($object->fk_user_author);
279 
280  $object->status = 1;
281  $object->fk_c_paiement = GETPOST('fk_c_paiement', 'int');
282  $object->fk_user_validator = GETPOST('fk_user_validator', 'int');
283  $object->note_public = GETPOST('note_public', 'restricthtml');
284  $object->note_private = GETPOST('note_private', 'restricthtml');
285  // Fill array 'array_options' with data from add form
286  if (!$error) {
287  $ret = $extrafields->setOptionalsFromPost(null, $object);
288  if ($ret < 0) {
289  $error++;
290  }
291  }
292 
293  if (!$error && empty($conf->global->EXPENSEREPORT_ALLOW_OVERLAPPING_PERIODS)) {
294  $overlappingExpenseReportID = $object->periode_existe($fuser, $object->date_debut, $object->date_fin, true);
295 
296  if ($overlappingExpenseReportID > 0) {
297  $error++;
298  setEventMessages($langs->trans("ErrorDoubleDeclaration").' <a href="'.$_SERVER['PHP_SELF'].'?id='.$overlappingExpenseReportID.'">'. $langs->trans('ShowTrip').'</a>', null, 'errors');
299  $action = 'create';
300  }
301  }
302 
303  if (!$error) {
304  $db->begin();
305 
306  $id = $object->create($user);
307  if ($id <= 0) {
308  $error++;
309  }
310 
311  if (!$error) {
312  $db->commit();
313  Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
314  exit;
315  } else {
316  setEventMessages($object->error, $object->errors, 'errors');
317  $db->rollback();
318  $action = 'create';
319  }
320  }
321  }
322 
323  if (($action == 'update' || $action == 'updateFromRefuse') && $user->rights->expensereport->creer) {
324  $object = new ExpenseReport($db);
325  $object->fetch($id);
326 
327  $object->date_debut = $date_start;
328  $object->date_fin = $date_end;
329 
330  if ($object->status < 3) {
331  $object->fk_user_validator = GETPOST('fk_user_validator', 'int');
332  }
333 
334  $object->fk_c_paiement = GETPOST('fk_c_paiement', 'int');
335  $object->note_public = GETPOST('note_public', 'restricthtml');
336  $object->note_private = GETPOST('note_private', 'restricthtml');
337  $object->fk_user_modif = $user->id;
338 
339  $result = $object->update($user);
340  if ($result > 0) {
341  header("Location: ".$_SERVER["PHP_SELF"]."?id=".GETPOST('id', 'int'));
342  exit;
343  } else {
344  setEventMessages($object->error, $object->errors, 'errors');
345  }
346  }
347 
348  if ($action == 'update_extras') {
349  $object->oldcopy = dol_clone($object);
350 
351  // Fill array 'array_options' with data from update form
352  $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
353  if ($ret < 0) {
354  $error++;
355  }
356 
357  if (!$error) {
358  // Actions on extra fields
359  $result = $object->insertExtraFields('EXPENSEREPORT_MODIFY');
360  if ($result < 0) {
361  setEventMessages($object->error, $object->errors, 'errors');
362  $error++;
363  }
364  }
365 
366  if ($error) {
367  $action = 'edit_extras';
368  }
369  }
370 
371  if ($action == "confirm_validate" && GETPOST("confirm", 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->creer) {
372  $error = 0;
373 
374  $db->begin();
375 
376  $object = new ExpenseReport($db);
377  $object->fetch($id);
378 
379  $result = $object->setValidate($user);
380 
381  if ($result >= 0) {
382  // Define output language
383  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
384  $outputlangs = $langs;
385  $newlang = '';
386  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
387  $newlang = GETPOST('lang_id', 'aZ09');
388  }
389  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
390  $newlang = $object->thirdparty->default_lang;
391  }
392  if (!empty($newlang)) {
393  $outputlangs = new Translate("", $conf);
394  $outputlangs->setDefaultLang($newlang);
395  }
396  $model = $object->model_pdf;
397  $ret = $object->fetch($id); // Reload to get new records
398 
399  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
400  }
401  } else {
402  setEventMessages($object->error, $object->errors, 'errors');
403  $error++;
404  }
405 
406  if (!$error && $result > 0 && $object->fk_user_validator > 0) {
407  $langs->load("mails");
408 
409  // TO
410  $destinataire = new User($db);
411  $destinataire->fetch($object->fk_user_validator);
412  $emailTo = $destinataire->email;
413 
414  // FROM
415  $expediteur = new User($db);
416  $expediteur->fetch($object->fk_user_author);
417  $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
418 
419  if ($emailTo && $emailFrom) {
420  $filename = array(); $filedir = array(); $mimetype = array();
421 
422  // SUBJECT
423  $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
424  if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
425  $societeName = $conf->global->MAIN_APPLICATION_TITLE;
426  }
427 
428  $subject = $societeName." - ".$langs->transnoentities("ExpenseReportWaitingForApproval");
429 
430  // CONTENT
431  $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
432  $link = '<a href="'.$link.'">'.$link.'</a>';
433  $message = $langs->transnoentities("ExpenseReportWaitingForApprovalMessage", $expediteur->getFullName($langs), get_date_range($object->date_debut, $object->date_fin, '', $langs), $link);
434 
435  // Rebuild pdf
436  /*
437  $object->setDocModel($user,"");
438  $resultPDF = expensereport_pdf_create($db,$id,'',"",$langs);
439 
440  if($resultPDF):
441  // ATTACHMENT
442  array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
443  array_push($filedir,$conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref) . "/" . dol_sanitizeFileName($object->ref).".pdf");
444  array_push($mimetype,"application/pdf");
445  */
446 
447  // PREPARE SEND
448  $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1);
449 
450  if ($mailfile) {
451  // SEND
452  $result = $mailfile->sendfile();
453  if ($result) {
454  $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
455  setEventMessages($mesg, null, 'mesgs');
456  } else {
457  $langs->load("other");
458  if ($mailfile->error) {
459  $mesg = '';
460  $mesg .= $langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo);
461  $mesg .= '<br>'.$mailfile->error;
462  setEventMessages($mesg, null, 'errors');
463  } else {
464  setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings');
465  }
466  }
467  } else {
468  setEventMessages($mailfile->error, $mailfile->errors, 'errors');
469  $action = '';
470  }
471  } else {
472  setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings');
473  $action = '';
474  }
475  }
476 
477  if (!$error) {
478  $db->commit();
479  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
480  exit;
481  } else {
482  $db->rollback();
483  }
484  }
485 
486  if ($action == "confirm_save_from_refuse" && GETPOST("confirm", 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->creer) {
487  $object = new ExpenseReport($db);
488  $object->fetch($id);
489  $result = $object->set_save_from_refuse($user);
490 
491  if ($result > 0) {
492  // Define output language
493  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
494  $outputlangs = $langs;
495  $newlang = '';
496  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
497  $newlang = GETPOST('lang_id', 'aZ09');
498  }
499  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
500  $newlang = $object->thirdparty->default_lang;
501  }
502  if (!empty($newlang)) {
503  $outputlangs = new Translate("", $conf);
504  $outputlangs->setDefaultLang($newlang);
505  }
506  $model = $object->model_pdf;
507  $ret = $object->fetch($id); // Reload to get new records
508 
509  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
510  }
511  }
512 
513  if ($result > 0) {
514  // Send mail
515 
516  // TO
517  $destinataire = new User($db);
518  $destinataire->fetch($object->fk_user_validator);
519  $emailTo = $destinataire->email;
520 
521  // FROM
522  $expediteur = new User($db);
523  $expediteur->fetch($object->fk_user_author);
524  $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
525 
526  if ($emailFrom && $emailTo) {
527  $filename = array(); $filedir = array(); $mimetype = array();
528 
529  // SUBJECT
530  $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
531  if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
532  $societeName = $conf->global->MAIN_APPLICATION_TITLE;
533  }
534 
535  $subject = $societeName." - ".$langs->transnoentities("ExpenseReportWaitingForReApproval");
536 
537  // CONTENT
538  $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
539  $link = '<a href="'.$link.'">'.$link.'</a>';
540  $dateRefusEx = explode(" ", $object->date_refuse);
541  $message = $langs->transnoentities("ExpenseReportWaitingForReApprovalMessage", $dateRefusEx[0], $object->detail_refuse, $expediteur->getFullName($langs), $link);
542 
543  // Rebuild pdf
544  /*
545  $object->setDocModel($user,"");
546  $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs);
547 
548  if($resultPDF)
549  {
550  // ATTACHMENT
551  $filename=array(); $filedir=array(); $mimetype=array();
552  array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
553  array_push($filedir,$conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref) . "/" . dol_sanitizeFileName($object->ref_number).".pdf");
554  array_push($mimetype,"application/pdf");
555  }
556  */
557 
558 
559  // PREPARE SEND
560  $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1);
561 
562  if ($mailfile) {
563  // SEND
564  $result = $mailfile->sendfile();
565  if ($result) {
566  $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
567  setEventMessages($mesg, null, 'mesgs');
568  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
569  exit;
570  } else {
571  $langs->load("other");
572  if ($mailfile->error) {
573  $mesg = '';
574  $mesg .= $langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo);
575  $mesg .= '<br>'.$mailfile->error;
576  setEventMessages($mesg, null, 'errors');
577  } else {
578  setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings');
579  }
580  }
581  } else {
582  setEventMessages($mailfile->error, $mailfile->errors, 'errors');
583  $action = '';
584  }
585  } else {
586  setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings');
587  $action = '';
588  }
589  } else {
590  setEventMessages($object->error, $object->errors, 'errors');
591  }
592  }
593 
594  // Approve
595  if ($action == "confirm_approve" && GETPOST("confirm", 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->approve) {
596  $object = new ExpenseReport($db);
597  $object->fetch($id);
598 
599  $result = $object->setApproved($user);
600 
601  if ($result > 0) {
602  // Define output language
603  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
604  $outputlangs = $langs;
605  $newlang = '';
606  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
607  $newlang = GETPOST('lang_id', 'aZ09');
608  }
609  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
610  $newlang = $object->thirdparty->default_lang;
611  }
612  if (!empty($newlang)) {
613  $outputlangs = new Translate("", $conf);
614  $outputlangs->setDefaultLang($newlang);
615  }
616  $model = $object->model_pdf;
617  $ret = $object->fetch($id); // Reload to get new records
618 
619  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
620  }
621  }
622 
623  if ($result > 0) {
624  // Send mail
625 
626  // TO
627  $destinataire = new User($db);
628  $destinataire->fetch($object->fk_user_author);
629  $emailTo = $destinataire->email;
630 
631  // CC
632  $emailCC = $conf->global->NDF_CC_EMAILS;
633  if (empty($emailTo)) {
634  $emailTo = $emailCC;
635  }
636 
637  // FROM
638  $expediteur = new User($db);
639  $expediteur->fetch($object->fk_user_approve > 0 ? $object->fk_user_approve : $object->fk_user_validator);
640  $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
641 
642  if ($emailFrom && $emailTo) {
643  $filename = array(); $filedir = array(); $mimetype = array();
644 
645  // SUBJECT
646  $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
647  if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
648  $societeName = $conf->global->MAIN_APPLICATION_TITLE;
649  }
650 
651  $subject = $societeName." - ".$langs->transnoentities("ExpenseReportApproved");
652 
653  // CONTENT
654  $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
655  $link = '<a href="'.$link.'">'.$link.'</a>';
656  $message = $langs->transnoentities("ExpenseReportApprovedMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link);
657 
658  // Rebuilt pdf
659  /*
660  $object->setDocModel($user,"");
661  $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs);
662 
663  if($resultPDF
664  {
665  // ATTACHMENT
666  $filename=array(); $filedir=array(); $mimetype=array();
667  array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
668  array_push($filedir, $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref)."/".dol_sanitizeFileName($object->ref).".pdf");
669  array_push($mimetype,"application/pdf");
670  }
671  */
672 
673  $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1);
674 
675  if ($mailfile) {
676  // SEND
677  $result = $mailfile->sendfile();
678  if ($result) {
679  $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
680  setEventMessages($mesg, null, 'mesgs');
681  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
682  exit;
683  } else {
684  $langs->load("other");
685  if ($mailfile->error) {
686  $mesg = '';
687  $mesg .= $langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo);
688  $mesg .= '<br>'.$mailfile->error;
689  setEventMessages($mesg, null, 'errors');
690  } else {
691  setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings');
692  }
693  }
694  } else {
695  setEventMessages($mailfile->error, $mailfile->errors, 'errors');
696  $action = '';
697  }
698  } else {
699  setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings');
700  $action = '';
701  }
702  } else {
703  setEventMessages($langs->trans("FailedtoSetToApprove"), null, 'warnings');
704  $action = '';
705  }
706  }
707 
708  if ($action == "confirm_refuse" && GETPOST('confirm', 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->approve) {
709  $object = new ExpenseReport($db);
710  $object->fetch($id);
711 
712  $detailRefuse = GETPOST('detail_refuse', 'alpha');
713  $result = $object->setDeny($user, $detailRefuse);
714 
715  if ($result > 0) {
716  // Define output language
717  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
718  $outputlangs = $langs;
719  $newlang = '';
720  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
721  $newlang = GETPOST('lang_id', 'aZ09');
722  }
723  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
724  $newlang = $object->thirdparty->default_lang;
725  }
726  if (!empty($newlang)) {
727  $outputlangs = new Translate("", $conf);
728  $outputlangs->setDefaultLang($newlang);
729  }
730  $model = $object->model_pdf;
731  $ret = $object->fetch($id); // Reload to get new records
732 
733  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
734  }
735  }
736 
737  if ($result > 0) {
738  // Send mail
739 
740  // TO
741  $destinataire = new User($db);
742  $destinataire->fetch($object->fk_user_author);
743  $emailTo = $destinataire->email;
744 
745  // FROM
746  $expediteur = new User($db);
747  $expediteur->fetch($object->fk_user_refuse);
748  $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
749 
750  if ($emailFrom && $emailTo) {
751  $filename = array(); $filedir = array(); $mimetype = array();
752 
753  // SUBJECT
754  $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
755  if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
756  $societeName = $conf->global->MAIN_APPLICATION_TITLE;
757  }
758 
759  $subject = $societeName." - ".$langs->transnoentities("ExpenseReportRefused");
760 
761  // CONTENT
762  $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
763  $link = '<a href="'.$link.'">'.$link.'</a>';
764  $message = $langs->transnoentities("ExpenseReportRefusedMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $detailRefuse, $link);
765 
766  // Rebuilt pdf
767  /*
768  $object->setDocModel($user,"");
769  $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs);
770 
771  if($resultPDF
772  {
773  // ATTACHMENT
774  $filename=array(); $filedir=array(); $mimetype=array();
775  array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
776  array_push($filedir, $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref)."/".dol_sanitizeFileName($object->ref).".pdf");
777  array_push($mimetype,"application/pdf");
778  }
779  */
780 
781  // PREPARE SEND
782  $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1);
783 
784  if ($mailfile) {
785  // SEND
786  $result = $mailfile->sendfile();
787  if ($result) {
788  $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
789  setEventMessages($mesg, null, 'mesgs');
790  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
791  exit;
792  } else {
793  $langs->load("other");
794  if ($mailfile->error) {
795  $mesg = '';
796  $mesg .= $langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo);
797  $mesg .= '<br>'.$mailfile->error;
798  setEventMessages($mesg, null, 'errors');
799  } else {
800  setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings');
801  }
802  }
803  } else {
804  setEventMessages($mailfile->error, $mailfile->errors, 'errors');
805  $action = '';
806  }
807  } else {
808  setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings');
809  $action = '';
810  }
811  } else {
812  setEventMessages($langs->trans("FailedtoSetToDeny"), null, 'warnings');
813  $action = '';
814  }
815  }
816 
817  //var_dump($user->id == $object->fk_user_validator);exit;
818  if ($action == "confirm_cancel" && GETPOST('confirm', 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->creer) {
819  if (!GETPOST('detail_cancel', 'alpha')) {
820  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Comment")), null, 'errors');
821  } else {
822  $object = new ExpenseReport($db);
823  $object->fetch($id);
824 
825  if ($user->id == $object->fk_user_valid || $user->id == $object->fk_user_author) {
826  $detailCancel = GETPOST('detail_cancel', 'alpha');
827  $result = $object->set_cancel($user, $detailCancel);
828 
829  if ($result > 0) {
830  // Define output language
831  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
832  $outputlangs = $langs;
833  $newlang = '';
834  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
835  $newlang = GETPOST('lang_id', 'aZ09');
836  }
837  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
838  $newlang = $object->thirdparty->default_lang;
839  }
840  if (!empty($newlang)) {
841  $outputlangs = new Translate("", $conf);
842  $outputlangs->setDefaultLang($newlang);
843  }
844  $model = $object->model_pdf;
845  $ret = $object->fetch($id); // Reload to get new records
846 
847  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
848  }
849  }
850 
851  if ($result > 0) {
852  // Send mail
853 
854  // TO
855  $destinataire = new User($db);
856  $destinataire->fetch($object->fk_user_author);
857  $emailTo = $destinataire->email;
858 
859  // FROM
860  $expediteur = new User($db);
861  $expediteur->fetch($object->fk_user_cancel);
862  $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
863 
864  if ($emailFrom && $emailTo) {
865  $filename = array(); $filedir = array(); $mimetype = array();
866 
867  // SUBJECT
868  $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
869  if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
870  $societeName = $conf->global->MAIN_APPLICATION_TITLE;
871  }
872 
873  $subject = $societeName." - ".$langs->transnoentities("ExpenseReportCanceled");
874 
875  // CONTENT
876  $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
877  $link = '<a href="'.$link.'">'.$link.'</a>';
878  $message = $langs->transnoentities("ExpenseReportCanceledMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $detailCancel, $link);
879 
880  // Rebuilt pdf
881  /*
882  $object->setDocModel($user,"");
883  $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs);
884 
885  if($resultPDF
886  {
887  // ATTACHMENT
888  $filename=array(); $filedir=array(); $mimetype=array();
889  array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
890  array_push($filedir, $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref)."/".dol_sanitizeFileName($object->ref).".pdf");
891  array_push($mimetype,"application/pdf");
892  }
893  */
894 
895  // PREPARE SEND
896  $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1);
897 
898  if ($mailfile) {
899  // SEND
900  $result = $mailfile->sendfile();
901  if ($result) {
902  $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
903  setEventMessages($mesg, null, 'mesgs');
904  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
905  exit;
906  } else {
907  $langs->load("other");
908  if ($mailfile->error) {
909  $mesg = '';
910  $mesg .= $langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo);
911  $mesg .= '<br>'.$mailfile->error;
912  setEventMessages($mesg, null, 'errors');
913  } else {
914  setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings');
915  }
916  }
917  } else {
918  setEventMessages($mailfile->error, $mailfile->errors, 'errors');
919  $action = '';
920  }
921  } else {
922  setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings');
923  $action = '';
924  }
925  } else {
926  setEventMessages($langs->trans("FailedToSetToCancel"), null, 'warnings');
927  $action = '';
928  }
929  } else {
930  setEventMessages($object->error, $object->errors, 'errors');
931  }
932  }
933  }
934 
935  if ($action == "confirm_setdraft" && GETPOST('confirm', 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->creer) {
936  $object = new ExpenseReport($db);
937  $object->fetch($id);
938  if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) {
939  $result = $object->setStatut(0);
940 
941  if ($result > 0) {
942  // Define output language
943  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
944  $outputlangs = $langs;
945  $newlang = '';
946  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
947  $newlang = GETPOST('lang_id', 'aZ09');
948  }
949  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
950  $newlang = $object->thirdparty->default_lang;
951  }
952  if (!empty($newlang)) {
953  $outputlangs = new Translate("", $conf);
954  $outputlangs->setDefaultLang($newlang);
955  }
956  $model = $object->model_pdf;
957  $ret = $object->fetch($id); // Reload to get new records
958 
959  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
960  }
961  }
962 
963  if ($result > 0) {
964  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
965  exit;
966  } else {
967  setEventMessages($object->error, $object->errors, 'errors');
968  }
969  } else {
970  setEventMessages("NOT_AUTHOR", '', 'errors');
971  }
972  }
973 
974  if ($action == 'set_unpaid' && $id > 0 && $user->rights->expensereport->to_paid) {
975  $object = new ExpenseReport($db);
976  $object->fetch($id);
977 
978  $result = $object->setUnpaid($user);
979 
980  if ($result > 0) {
981  // Define output language
982  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
983  $outputlangs = $langs;
984  $newlang = '';
985  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
986  $newlang = GETPOST('lang_id', 'aZ09');
987  }
988  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
989  $newlang = $object->thirdparty->default_lang;
990  }
991  if (!empty($newlang)) {
992  $outputlangs = new Translate("", $conf);
993  $outputlangs->setDefaultLang($newlang);
994  }
995  $model = $object->model_pdf;
996  $ret = $object->fetch($id); // Reload to get new records
997 
998  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
999  }
1000  }
1001  }
1002 
1003  if ($action == 'set_paid' && $id > 0 && $user->rights->expensereport->to_paid) {
1004  $object = new ExpenseReport($db);
1005  $object->fetch($id);
1006 
1007  $result = $object->setPaid($id, $user);
1008 
1009  if ($result > 0) {
1010  // Define output language
1011  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1012  $outputlangs = $langs;
1013  $newlang = '';
1014  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
1015  $newlang = GETPOST('lang_id', 'aZ09');
1016  }
1017  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
1018  $newlang = $object->thirdparty->default_lang;
1019  }
1020  if (!empty($newlang)) {
1021  $outputlangs = new Translate("", $conf);
1022  $outputlangs->setDefaultLang($newlang);
1023  }
1024  $model = $object->model_pdf;
1025  $ret = $object->fetch($id); // Reload to get new records
1026 
1027  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1028  }
1029  }
1030 
1031  if ($result > 0) {
1032  // Send mail
1033 
1034  // TO
1035  $destinataire = new User($db);
1036  $destinataire->fetch($object->fk_user_author);
1037  $emailTo = $destinataire->email;
1038 
1039  // FROM
1040  $expediteur = new User($db);
1041  $expediteur->fetch($user->id);
1042  $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
1043 
1044  if ($emailFrom && $emailTo) {
1045  $filename = array(); $filedir = array(); $mimetype = array();
1046 
1047  // SUBJECT
1048  $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
1049  if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
1050  $societeName = $conf->global->MAIN_APPLICATION_TITLE;
1051  }
1052 
1053  $subject = $societeName." - ".$langs->transnoentities("ExpenseReportPaid");
1054 
1055  // CONTENT
1056  $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
1057  $link = '<a href="'.$link.'">'.$link.'</a>';
1058  $message = $langs->transnoentities("ExpenseReportPaidMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link);
1059 
1060  // Generate pdf before attachment
1061  $object->setDocModel($user, "");
1062  $resultPDF = expensereport_pdf_create($db, $object, '', "", $langs);
1063 
1064  // PREPARE SEND
1065  $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1);
1066 
1067  if ($mailfile) {
1068  // SEND
1069  $result = $mailfile->sendfile();
1070  if ($result) {
1071  $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
1072  setEventMessages($mesg, null, 'mesgs');
1073  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
1074  exit;
1075  } else {
1076  $langs->load("other");
1077  if ($mailfile->error) {
1078  $mesg = '';
1079  $mesg .= $langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo);
1080  $mesg .= '<br>'.$mailfile->error;
1081  setEventMessages($mesg, null, 'errors');
1082  } else {
1083  setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings');
1084  }
1085  }
1086  } else {
1087  setEventMessages($mailfile->error, $mailfile->errors, 'errors');
1088  $action = '';
1089  }
1090  } else {
1091  setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings');
1092  $action = '';
1093  }
1094  } else {
1095  setEventMessages($langs->trans("FailedToSetPaid"), null, 'warnings');
1096  $action = '';
1097  }
1098  }
1099 
1100  if ($action == "addline" && $user->rights->expensereport->creer) {
1101  $error = 0;
1102 
1103  // First save uploaded file
1104  $fk_ecm_files = 0;
1105  if (GETPOSTISSET('attachfile')) {
1106  $arrayoffiles = GETPOST('attachfile', 'array');
1107  if (is_array($arrayoffiles) && !empty($arrayoffiles[0])) {
1108  include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
1109  $entityprefix = ($conf->entity != '1') ? $conf->entity.'/' : '';
1110  $relativepath = 'expensereport/'.$object->ref.'/'.$arrayoffiles[0];
1111  $ecmfiles = new EcmFiles($db);
1112  $ecmfiles->fetch(0, '', $relativepath);
1113  $fk_ecm_files = $ecmfiles->id;
1114  }
1115  }
1116 
1117  // if VAT is not used in Dolibarr, set VAT rate to 0 because VAT rate is necessary.
1118  if (empty($vatrate)) {
1119  $vatrate = "0.000";
1120  }
1121  $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $vatrate));
1122 
1123  $value_unit_ht = price2num(GETPOST('value_unit_ht', 'alpha'), 'MU');
1124  $value_unit = price2num(GETPOST('value_unit', 'alpha'), 'MU');
1125  if (empty($value_unit)) {
1126  $value_unit = price2num($value_unit_ht + ($value_unit_ht * $tmpvat / 100), 'MU');
1127  }
1128 
1129  $fk_c_exp_tax_cat = GETPOST('fk_c_exp_tax_cat', 'int');
1130 
1131  $qty = price2num(GETPOST('qty', 'alpha'));
1132  if (empty($qty)) {
1133  $qty = 1;
1134  }
1135 
1136  if (!($fk_c_type_fees > 0)) {
1137  $error++;
1138  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
1139  $action = '';
1140  }
1141 
1142  if ((float) $tmpvat < 0 || $tmpvat === '') {
1143  $error++;
1144  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("VAT")), null, 'errors');
1145  $action = '';
1146  }
1147 
1148  // If no date entered
1149  if (empty($date) || $date == "--") {
1150  $error++;
1151  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
1152  } elseif ($date < $object->date_debut || $date > ($object->date_fin + (24 * 3600 - 1))) {
1153  // Warning if date out of range
1154  $langs->load("errors");
1155  setEventMessages($langs->trans("WarningDateOfLineMustBeInExpenseReportRange"), null, 'warnings');
1156  }
1157 
1158  // If no price entered
1159  if ($value_unit == 0) {
1160  $error++;
1161  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PriceUTTC")), null, 'errors');
1162  }
1163 
1164  // If no project entered
1165  if ($projectRequired && $fk_project <= 0) {
1166  $error++;
1167  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Project")), null, 'errors');
1168  }
1169 
1170  // If no file associated
1171  if ($fileRequired && $fk_ecm_files == 0) {
1172  $error++;
1173  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File")), null, 'errors');
1174  }
1175 
1176  if (!$error) {
1177  $type = 0; // TODO What if service ? We should take the type product/service from the type of expense report llx_c_type_fees
1178 
1179  // Insert line
1180  $result = $object->addline($qty, $value_unit, $fk_c_type_fees, $vatrate, $date, $comments, $fk_project, $fk_c_exp_tax_cat, $type, $fk_ecm_files);
1181  if ($result > 0) {
1182  $ret = $object->fetch($object->id); // Reload to get new records
1183 
1184  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1185  // Define output language
1186  $outputlangs = $langs;
1187  $newlang = GETPOST('lang_id', 'alpha');
1188  if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang)) {
1189  $newlang = $object->thirdparty->default_lang;
1190  }
1191  if (!empty($newlang)) {
1192  $outputlangs = new Translate("", $conf);
1193  $outputlangs->setDefaultLang($newlang);
1194  }
1195 
1196  $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1197  }
1198 
1199  unset($qty);
1200  unset($value_unit_ht);
1201  unset($value_unit);
1202  unset($vatrate);
1203  unset($comments);
1204  unset($fk_c_type_fees);
1205  unset($fk_project);
1206 
1207  unset($date);
1208  } else {
1209  $error++;
1210  setEventMessages($object->error, $object->errors, 'errors');
1211  }
1212  }
1213 
1214  if (!$error) {
1215  header("Location: ".$_SERVER["PHP_SELF"]."?id=".GETPOST('id', 'int'));
1216  exit;
1217  } else {
1218  $action = '';
1219  }
1220  }
1221 
1222  if ($action == 'confirm_delete_line' && GETPOST("confirm", 'alpha') == "yes" && $user->rights->expensereport->creer) {
1223  $object = new ExpenseReport($db);
1224  $object->fetch($id);
1225 
1226  $object_ligne = new ExpenseReportLine($db);
1227  $object_ligne->fetch(GETPOST("rowid", 'int'));
1228  $total_ht = $object_ligne->total_ht;
1229  $total_tva = $object_ligne->total_tva;
1230 
1231  $result = $object->deleteline(GETPOST("rowid", 'int'), $user);
1232  if ($result >= 0) {
1233  if ($result > 0) {
1234  // Define output language
1235  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1236  $outputlangs = $langs;
1237  $newlang = '';
1238  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
1239  $newlang = GETPOST('lang_id', 'aZ09');
1240  }
1241  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
1242  $newlang = $object->thirdparty->default_lang;
1243  }
1244  if (!empty($newlang)) {
1245  $outputlangs = new Translate("", $conf);
1246  $outputlangs->setDefaultLang($newlang);
1247  }
1248  $model = $object->model_pdf;
1249  $ret = $object->fetch($id); // Reload to get new records
1250 
1251  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1252  }
1253  }
1254 
1255  header("Location: ".$_SERVER["PHP_SELF"]."?id=".GETPOST('id', 'int'));
1256  exit;
1257  } else {
1258  setEventMessages($object->error, $object->errors, 'errors');
1259  }
1260  }
1261 
1262  if ($action == "updateline" && $user->rights->expensereport->creer) {
1263  $object = new ExpenseReport($db);
1264  $object->fetch($id);
1265 
1266  // First save uploaded file
1267  $fk_ecm_files = 0;
1268  if (GETPOSTISSET('attachfile')) {
1269  $arrayoffiles = GETPOST('attachfile', 'array');
1270  if (is_array($arrayoffiles) && !empty($arrayoffiles[0])) {
1271  include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
1272  $relativepath = 'expensereport/'.$object->ref.'/'.$arrayoffiles[0];
1273  $ecmfiles = new EcmFiles($db);
1274  $ecmfiles->fetch(0, '', $relativepath);
1275  $fk_ecm_files = $ecmfiles->id;
1276  }
1277  }
1278 
1279  $rowid = GETPOST('rowid', 'int');
1280  $type_fees_id = GETPOST('fk_c_type_fees', 'int');
1281  $fk_c_exp_tax_cat = GETPOST('fk_c_exp_tax_cat', 'int');
1282  $projet_id = $fk_project;
1283  $comments = GETPOST('comments', 'restricthtml');
1284  $qty = price2num(GETPOST('qty', 'alpha'));
1285  $vatrate = GETPOST('vatrate', 'alpha');
1286 
1287  // if VAT is not used in Dolibarr, set VAT rate to 0 because VAT rate is necessary.
1288  if (empty($vatrate)) {
1289  $vatrate = "0.000";
1290  }
1291  $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $vatrate));
1292 
1293  $value_unit_ht = price2num(GETPOST('value_unit_ht', 'alpha'), 'MU');
1294  $value_unit = price2num(GETPOST('value_unit', 'alpha'), 'MU');
1295  if (empty($value_unit)) {
1296  $value_unit = price2num($value_unit_ht + ($value_unit_ht * $tmpvat / 100), 'MU');
1297  }
1298 
1299  if (!GETPOST('fk_c_type_fees', 'int') > 0) {
1300  $error++;
1301  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
1302  $action = '';
1303  }
1304  if ((float) $tmpvat < 0 || $tmpvat == '') {
1305  $error++;
1306  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Vat")), null, 'errors');
1307  $action = '';
1308  }
1309  // Warning if date out of range
1310  if ($date < $object->date_debut || $date > ($object->date_fin + (24 * 3600 - 1))) {
1311  $langs->load("errors");
1312  setEventMessages($langs->trans("WarningDateOfLineMustBeInExpenseReportRange"), null, 'warnings');
1313  }
1314 
1315  // If no project entered
1316  if ($projectRequired && $projet_id <= 0) {
1317  $error++;
1318  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Project")), null, 'errors');
1319  }
1320 
1321  if (!$error) {
1322  // TODO Use update method of ExpenseReportLine
1323  $result = $object->updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $id, $fk_c_exp_tax_cat, $fk_ecm_files);
1324  if ($result >= 0) {
1325  if ($result > 0) {
1326  // Define output language
1327  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1328  $outputlangs = $langs;
1329  $newlang = '';
1330  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
1331  $newlang = GETPOST('lang_id', 'aZ09');
1332  }
1333  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
1334  $newlang = $object->thirdparty->default_lang;
1335  }
1336  if (!empty($newlang)) {
1337  $outputlangs = new Translate("", $conf);
1338  $outputlangs->setDefaultLang($newlang);
1339  }
1340  $model = $object->model_pdf;
1341  $ret = $object->fetch($id); // Reload to get new records
1342 
1343  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1344  }
1345 
1346  unset($qty);
1347  unset($value_unit_ht);
1348  unset($value_unit);
1349  unset($vatrate);
1350  unset($comments);
1351  unset($fk_c_type_fees);
1352  unset($fk_project);
1353  unset($date);
1354  }
1355 
1356  //header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
1357  //exit;
1358  } else {
1359  setEventMessages($object->error, $object->errors, 'errors');
1360  }
1361  }
1362  }
1363 
1364  // Actions when printing a doc from card
1365  include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
1366 
1367  // Actions to send emails
1368  $triggersendname = 'EXPENSEREPORT_SENTBYMAIL';
1369  $autocopy = 'MAIN_MAIL_AUTOCOPY_EXPENSEREPORT_TO';
1370  $trackid = 'exp'.$object->id;
1371  include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
1372 
1373  // Actions to build doc
1374  $upload_dir = $conf->expensereport->dir_output;
1375  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
1376 }
1377 
1378 
1379 /*
1380  * View
1381  */
1382 
1383 $title = $langs->trans("ExpenseReport")." - ".$langs->trans("Card");
1384 $help_url = "EN:Module_Expense_Reports|FR:Module_Notes_de_frais";
1385 
1386 llxHeader("", $title, $help_url);
1387 
1388 $form = new Form($db);
1389 $formfile = new FormFile($db);
1390 $formproject = new FormProjets($db);
1391 $projecttmp = new Project($db);
1392 $paymentexpensereportstatic = new PaymentExpenseReport($db);
1393 $bankaccountstatic = new Account($db);
1394 $ecmfilesstatic = new EcmFiles($db);
1395 $formexpensereport = new FormExpenseReport($db);
1396 
1397 // Create
1398 if ($action == 'create') {
1399  print load_fiche_titre($langs->trans("NewTrip"), '', 'trip');
1400 
1401  print '<form action="'.$_SERVER['PHP_SELF'].'" method="post" name="create">';
1402  print '<input type="hidden" name="token" value="'.newToken().'">';
1403  print '<input type="hidden" name="action" value="add">';
1404 
1405  print dol_get_fiche_head('');
1406 
1407  print '<table class="border centpercent">';
1408  print '<tbody>';
1409 
1410  // Date start
1411  print '<tr>';
1412  print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("DateStart").'</td>';
1413  print '<td>';
1414  print $form->selectDate($date_start ? $date_start : -1, 'date_debut', 0, 0, 0, '', 1, 1);
1415  print '</td>';
1416  print '</tr>';
1417 
1418  // Date end
1419  print '<tr>';
1420  print '<td class="fieldrequired">'.$langs->trans("DateEnd").'</td>';
1421  print '<td>';
1422  print $form->selectDate($date_end ? $date_end : -1, 'date_fin', 0, 0, 0, '', 1, 1);
1423  print '</td>';
1424  print '</tr>';
1425 
1426  // User for expense report
1427  print '<tr>';
1428  print '<td class="fieldrequired">'.$langs->trans("User").'</td>';
1429  print '<td>';
1430  $defaultselectuser = $user->id;
1431  if (GETPOST('fk_user_author', 'int') > 0) {
1432  $defaultselectuser = GETPOST('fk_user_author', 'int');
1433  }
1434  $include_users = 'hierarchyme';
1435  if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expensereport->writeall_advance)) {
1436  $include_users = array();
1437  }
1438  $s = $form->select_dolusers($defaultselectuser, "fk_user_author", 0, "", 0, $include_users, '', '0,'.$conf->entity);
1439  print $s;
1440  print '</td>';
1441  print '</tr>';
1442 
1443  // Approver
1444  print '<tr>';
1445  print '<td>'.$langs->trans("VALIDATOR").'</td>';
1446  print '<td>';
1447  $object = new ExpenseReport($db);
1448  $include_users = $object->fetch_users_approver_expensereport();
1449  if (empty($include_users)) {
1450  print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateExpenseReport");
1451  } else {
1452  $defaultselectuser = (empty($user->fk_user_expense_validator) ? $user->fk_user : $user->fk_user_expense_validator); // Will work only if supervisor has permission to approve so is inside include_users
1453  if (!empty($conf->global->EXPENSEREPORT_DEFAULT_VALIDATOR)) {
1454  $defaultselectuser = $conf->global->EXPENSEREPORT_DEFAULT_VALIDATOR; // Can force default approver
1455  }
1456  if (GETPOST('fk_user_validator', 'int') > 0) {
1457  $defaultselectuser = GETPOST('fk_user_validator', 'int');
1458  }
1459  $s = $form->select_dolusers($defaultselectuser, "fk_user_validator", 1, "", ((empty($defaultselectuser) || empty($conf->global->EXPENSEREPORT_DEFAULT_VALIDATOR_UNCHANGEABLE)) ? 0 : 1), $include_users);
1460  print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
1461  }
1462  print '</td>';
1463  print '</tr>';
1464 
1465  // Payment mode
1466  if (!empty($conf->global->EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION)) {
1467  print '<tr>';
1468  print '<td>'.$langs->trans("ModePaiement").'</td>';
1469  print '<td>';
1470  $form->select_types_paiements('', 'fk_c_paiement');
1471  print '</td>';
1472  print '</tr>';
1473  }
1474 
1475  // Public note
1476  $note_public = GETPOSTISSET('note_public') ? GETPOST('note_public', 'restricthtml') : '';
1477 
1478  print '<tr>';
1479  print '<td class="tdtop">'.$langs->trans('NotePublic').'</td>';
1480  print '<td>';
1481 
1482  $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3, '90%');
1483  print $doleditor->Create(1);
1484  print '</td></tr>';
1485 
1486  // Private note
1487  $note_private = GETPOSTISSET('note_private') ? GETPOST('note_private', 'restricthtml') : '';
1488 
1489  if (empty($user->socid)) {
1490  print '<tr>';
1491  print '<td class="tdtop">'.$langs->trans('NotePrivate').'</td>';
1492  print '<td>';
1493 
1494  $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3, '90%');
1495  print $doleditor->Create(1);
1496  print '</td></tr>';
1497  }
1498 
1499  // Other attributes
1500  $parameters = array('colspan' => ' colspan="3"', 'cols' => 3);
1501  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by
1502  print $hookmanager->resPrint;
1503  if (empty($reshook)) {
1504  print $object->showOptionals($extrafields, 'create', $parameters);
1505  }
1506 
1507  print '<tbody>';
1508  print '</table>';
1509 
1510  print dol_get_fiche_end();
1511 
1512  print $form->buttonsSaveCancel("AddTrip");
1513 
1514  print '</form>';
1515 } elseif ($id > 0 || $ref) {
1516  $result = $object->fetch($id, $ref);
1517 
1518  if ($result > 0) {
1519  if (!in_array($object->fk_user_author, $user->getAllChildIds(1))) {
1520  if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)
1521  && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance))) {
1522  print load_fiche_titre($langs->trans('TripCard'), '', 'trip');
1523 
1524  print '<div class="tabBar">';
1525  print $langs->trans('NotUserRightToView');
1526  print '</div>';
1527 
1528  // End of page
1529  llxFooter();
1530  $db->close();
1531 
1532  exit;
1533  }
1534  }
1535 
1536  $head = expensereport_prepare_head($object);
1537 
1538  if ($action == 'edit' && ($object->status < 3 || $object->status == 99)) {
1539  print "<form name='update' action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">\n";
1540  print '<input type="hidden" name="token" value="'.newToken().'">';
1541  print '<input type="hidden" name="id" value="'.$id.'">';
1542 
1543  print dol_get_fiche_head($head, 'card', $langs->trans("ExpenseReport"), 0, 'trip');
1544 
1545  if ($object->status == 99) {
1546  print '<input type="hidden" name="action" value="updateFromRefuse">';
1547  } else {
1548  print '<input type="hidden" name="action" value="update">';
1549  }
1550 
1551  $linkback = '<a href="'.DOL_URL_ROOT.'/expensereport/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
1552 
1553  print '<table class="border" style="width:100%;">';
1554 
1555  print '<tr>';
1556  print '<td>'.$langs->trans("User").'</td>';
1557  print '<td>';
1558  $userfee = new User($db);
1559  if ($object->fk_user_author > 0) {
1560  $userfee->fetch($object->fk_user_author);
1561  print $userfee->getNomUrl(-1);
1562  }
1563  print '</td></tr>';
1564 
1565  // Ref
1566  print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td>';
1567  print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '');
1568  print '</td></tr>';
1569 
1570  print '<tr>';
1571  print '<td>'.$langs->trans("DateStart").'</td>';
1572  print '<td>';
1573  print $form->selectDate($object->date_debut, 'date_debut');
1574  print '</td>';
1575  print '</tr>';
1576  print '<tr>';
1577  print '<td>'.$langs->trans("DateEnd").'</td>';
1578  print '<td>';
1579  print $form->selectDate($object->date_fin, 'date_fin');
1580  print '</td>';
1581  print '</tr>';
1582 
1583  if (!empty($conf->global->EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION)) {
1584  print '<tr>';
1585  print '<td>'.$langs->trans("ModePaiement").'</td>';
1586  print '<td>';
1587  $form->select_types_paiements($object->fk_c_paiement, 'fk_c_paiement');
1588  print '</td>';
1589  print '</tr>';
1590  }
1591 
1592  if ($object->status < 3) {
1593  print '<tr>';
1594  print '<td>'.$langs->trans("VALIDATOR").'</td>'; // Approbator
1595  print '<td>';
1596  $include_users = $object->fetch_users_approver_expensereport();
1597  $s = $form->select_dolusers($object->fk_user_validator, "fk_user_validator", 1, "", 0, $include_users);
1598  print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
1599  print '</td>';
1600  print '</tr>';
1601  } else {
1602  print '<tr>';
1603  print '<td>'.$langs->trans("VALIDOR").'</td>';
1604  print '<td>';
1605  $userfee = new User($db);
1606  $userfee->fetch($object->fk_user_valid);
1607  print $userfee->getNomUrl(-1);
1608  print '</td></tr>';
1609  }
1610 
1611  if ($object->status == 6) {
1612  print '<tr>';
1613  print '<td>'.$langs->trans("AUTHORPAIEMENT").'</td>';
1614  print '<td>';
1615  $userfee = new User($db);
1616  $userfee->fetch($user->id);
1617  print $userfee->getNomUrl(-1);
1618  print '</td></tr>';
1619  }
1620 
1621  // Other attributes
1622  //$cols = 3;
1623  //include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_edit.tpl.php';
1624 
1625  print '</table>';
1626 
1627  print dol_get_fiche_end();
1628 
1629  print $form->buttonsSaveCancel("Modify");
1630 
1631  print '</form>';
1632  } else {
1633  $taxlessUnitPriceDisabled = ! empty($conf->global->EXPENSEREPORT_FORCE_LINE_AMOUNTS_INCLUDING_TAXES_ONLY) ? ' disabled' : '';
1634 
1635  print dol_get_fiche_head($head, 'card', $langs->trans("ExpenseReport"), -1, 'trip');
1636 
1637  $formconfirm = '';
1638 
1639  // Clone confirmation
1640  if ($action == 'clone') {
1641  // Create an array for form
1642  $criteriaforfilter = 'hierarchyme';
1643  if (!empty($user->rights->expensereport->readall)) {
1644  $criteriaforfilter = '';
1645  }
1646  $formquestion = array(
1647  'text' => '',
1648  array('type' => 'other', 'name' => 'fk_user_author', 'label' => $langs->trans("SelectTargetUser"), 'value' => $form->select_dolusers((GETPOST('fk_user_author', 'int') > 0 ? GETPOST('fk_user_author', 'int') : $user->id), 'fk_user_author', 0, null, 0, $criteriaforfilter, '', '0', 0, 0, '', 0, '', 'maxwidth150'))
1649  );
1650  // Paiement incomplet. On demande si motif = escompte ou autre
1651  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneExpenseReport', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
1652  }
1653 
1654  if ($action == 'save') {
1655  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("SaveTrip"), $langs->trans("ConfirmSaveTrip"), "confirm_validate", "", "", 1);
1656  }
1657 
1658  if ($action == 'save_from_refuse') {
1659  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("SaveTrip"), $langs->trans("ConfirmSaveTrip"), "confirm_save_from_refuse", "", "", 1);
1660  }
1661 
1662  if ($action == 'delete') {
1663  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("DeleteTrip"), $langs->trans("ConfirmDeleteTrip"), "confirm_delete", "", "", 1);
1664  }
1665 
1666  if ($action == 'validate') {
1667  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("ValideTrip"), $langs->trans("ConfirmValideTrip"), "confirm_approve", "", "", 1);
1668  }
1669 
1670  if ($action == 'paid') {
1671  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("PaidTrip"), $langs->trans("ConfirmPaidTrip"), "confirm_paid", "", "", 1);
1672  }
1673 
1674  if ($action == 'cancel') {
1675  $array_input = array('text'=>$langs->trans("ConfirmCancelTrip"), array('type'=>"text", 'label'=>'<strong>'.$langs->trans("Comment").'</strong>', 'name'=>"detail_cancel", 'value'=>""));
1676  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("Cancel"), "", "confirm_cancel", $array_input, "", 1);
1677  }
1678 
1679  if ($action == 'setdraft') {
1680  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("BrouillonnerTrip"), $langs->trans("ConfirmBrouillonnerTrip"), "confirm_setdraft", "", "", 1);
1681  }
1682 
1683  if ($action == 'refuse') { // Deny
1684  $array_input = array('text'=>$langs->trans("ConfirmRefuseTrip"), array('type'=>"text", 'label'=>$langs->trans("Comment"), 'name'=>"detail_refuse", 'value'=>""));
1685  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("Deny"), '', "confirm_refuse", $array_input, "yes", 1);
1686  }
1687 
1688  if ($action == 'delete_line') {
1689  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id."&rowid=".GETPOST('rowid', 'int'), $langs->trans("DeleteLine"), $langs->trans("ConfirmDeleteLine"), "confirm_delete_line", '', 'yes', 1);
1690  }
1691 
1692  // Print form confirm
1693  print $formconfirm;
1694 
1695  // Expense report card
1696  $linkback = '<a href="'.DOL_URL_ROOT.'/expensereport/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
1697 
1698  $morehtmlref = '<div class="refidno">';
1699  /*
1700  // Ref customer
1701  $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->commande->creer, 'string', '', 0, 1);
1702  $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->commande->creer, 'string', '', null, null, '', 1);
1703  // Thirdparty
1704  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
1705  // Project
1706  if (! empty($conf->project->enabled))
1707  {
1708  $langs->load("projects");
1709  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
1710  if ($user->rights->commande->creer)
1711  {
1712  if ($action != 'classify')
1713  $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
1714  if ($action == 'classify') {
1715  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
1716  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
1717  $morehtmlref.='<input type="hidden" name="action" value="classin">';
1718  $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
1719  $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
1720  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
1721  $morehtmlref.='</form>';
1722  } else {
1723  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
1724  }
1725  } else {
1726  if (! empty($object->fk_project)) {
1727  $proj = new Project($db);
1728  $proj->fetch($object->fk_project);
1729  $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
1730  $morehtmlref.=$proj->ref;
1731  $morehtmlref.='</a>';
1732  } else {
1733  $morehtmlref.='';
1734  }
1735  }
1736  }*/
1737  $morehtmlref .= '</div>';
1738 
1739  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
1740 
1741  print '<div class="fichecenter">';
1742  print '<div class="fichehalfleft">';
1743  print '<div class="underbanner clearboth"></div>';
1744 
1745  print '<table class="border tableforfield centpercent">';
1746 
1747  // Author
1748  print '<tr>';
1749  print '<td class="titlefield">'.$langs->trans("User").'</td>';
1750  print '<td>';
1751  if ($object->fk_user_author > 0) {
1752  $userauthor = new User($db);
1753  $result = $userauthor->fetch($object->fk_user_author);
1754  if ($result < 0) {
1755  dol_print_error('', $userauthor->error);
1756  } elseif ($result > 0) {
1757  print $userauthor->getNomUrl(-1);
1758  }
1759  }
1760  print '</td></tr>';
1761 
1762  // Period
1763  print '<tr>';
1764  print '<td class="titlefield">'.$langs->trans("Period").'</td>';
1765  print '<td>';
1766  print get_date_range($object->date_debut, $object->date_fin, 'day', $langs, 0);
1767  print '</td>';
1768  print '</tr>';
1769  if (!empty($conf->global->EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION)) {
1770  print '<tr>';
1771  print '<td>'.$langs->trans("ModePaiement").'</td>';
1772  print '<td>'.$object->fk_c_paiement.'</td>';
1773  print '</tr>';
1774  }
1775 
1776  // Validation date
1777  print '<tr>';
1778  print '<td>'.$langs->trans("DATE_SAVE").'</td>';
1779  print '<td>'.dol_print_date($object->date_valid, 'dayhour', 'tzuser');
1780  if ($object->status == 2 && $object->hasDelay('toapprove')) {
1781  print ' '.img_warning($langs->trans("Late").' - '.$langs->trans("ToApprove"));
1782  }
1783  if ($object->status == 5 && $object->hasDelay('topay')) {
1784  print ' '.img_warning($langs->trans("Late").' - '.$langs->trans("ToPay"));
1785  }
1786  print '</td></tr>';
1787  print '</tr>';
1788 
1789  // User to inform for approval
1790  if ($object->status <= ExpenseReport::STATUS_VALIDATED) { // informed
1791  print '<tr>';
1792  print '<td>'.$langs->trans("VALIDATOR").'</td>'; // approver
1793  print '<td>';
1794  if ($object->fk_user_validator > 0) {
1795  $userfee = new User($db);
1796  $result = $userfee->fetch($object->fk_user_validator);
1797  if ($result > 0) {
1798  print $userfee->getNomUrl(-1);
1799  }
1800  if (empty($userfee->email) || !isValidEmail($userfee->email)) {
1801  $langs->load("errors");
1802  print img_warning($langs->trans("ErrorBadEMail", $userfee->email));
1803  }
1804  }
1805  print '</td></tr>';
1806  } elseif ($object->status == ExpenseReport::STATUS_CANCELED) {
1807  print '<tr>';
1808  print '<td>'.$langs->trans("CANCEL_USER").'</span></td>';
1809  print '<td>';
1810  if ($object->fk_user_cancel > 0) {
1811  $userfee = new User($db);
1812  $result = $userfee->fetch($object->fk_user_cancel);
1813  if ($result > 0) {
1814  print $userfee->getNomUrl(-1);
1815  }
1816  }
1817  print '</td></tr>';
1818 
1819  print '<tr>';
1820  print '<td>'.$langs->trans("MOTIF_CANCEL").'</td>';
1821  print '<td>'.$object->detail_cancel.'</td></tr>';
1822  print '</tr>';
1823  print '<tr>';
1824  print '<td>'.$langs->trans("DATE_CANCEL").'</td>';
1825  print '<td>'.dol_print_date($object->date_cancel, 'dayhour', 'tzuser').'</td></tr>';
1826  print '</tr>';
1827  } else {
1828  print '<tr>';
1829  print '<td>'.$langs->trans("ApprovedBy").'</td>';
1830  print '<td>';
1831  if ($object->fk_user_approve > 0) {
1832  $userapp = new User($db);
1833  $result = $userapp->fetch($object->fk_user_approve);
1834  if ($result > 0) {
1835  print $userapp->getNomUrl(-1);
1836  }
1837  }
1838  print '</td></tr>';
1839 
1840  print '<tr>';
1841  print '<td>'.$langs->trans("DateApprove").'</td>';
1842  print '<td>'.dol_print_date($object->date_approve, 'dayhour', 'tzuser').'</td></tr>';
1843  print '</tr>';
1844  }
1845 
1846  if ($object->status == 99 || !empty($object->detail_refuse)) {
1847  print '<tr>';
1848  print '<td>'.$langs->trans("REFUSEUR").'</td>';
1849  print '<td>';
1850  $userfee = new User($db);
1851  $result = $userfee->fetch($object->fk_user_refuse);
1852  if ($result > 0) {
1853  print $userfee->getNomUrl(-1);
1854  }
1855  print '</td></tr>';
1856 
1857  print '<tr>';
1858  print '<td>'.$langs->trans("DATE_REFUS").'</td>';
1859  print '<td>'.dol_print_date($object->date_refuse, 'dayhour', 'tzuser');
1860  if ($object->detail_refuse) {
1861  print ' - '.$object->detail_refuse;
1862  }
1863  print '</td>';
1864  print '</tr>';
1865  }
1866 
1867  if ($object->status == $object::STATUS_CLOSED) {
1868  /* TODO this fields are not yet filled
1869  print '<tr>';
1870  print '<td>'.$langs->trans("AUTHORPAIEMENT").'</td>';
1871  print '<td>';
1872  $userfee=new User($db);
1873  $userfee->fetch($object->fk_user_paid);
1874  print $userfee->getNomUrl(-1);
1875  print '</td></tr>';
1876  print '<tr>';
1877  print '<td>'.$langs->trans("DATE_PAIEMENT").'</td>';
1878  print '<td>'.$object->date_paiement.'</td></tr>';
1879  print '</tr>';
1880  */
1881  }
1882 
1883  // Other attributes
1884  $cols = 2;
1885  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1886 
1887  print '</table>';
1888 
1889  print '</div>';
1890  print '<div class="fichehalfright">';
1891  print '<div class="underbanner clearboth"></div>';
1892 
1893  print '<table class="border tableforfield centpercent">';
1894 
1895  // Amount
1896  print '<tr>';
1897  print '<td class="titlefieldmiddle">'.$langs->trans("AmountHT").'</td>';
1898  print '<td class="nowrap amountcard">'.price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency).'</td>';
1899  $rowspan = 5;
1900  if ($object->status <= ExpenseReport::STATUS_VALIDATED) {
1901  $rowspan++;
1902  } elseif ($object->status == ExpenseReport::STATUS_CANCELED) {
1903  $rowspan += 2;
1904  } else {
1905  $rowspan += 2;
1906  }
1907  if ($object->status == ExpenseReport::STATUS_REFUSED || !empty($object->detail_refuse)) {
1908  $rowspan += 2;
1909  }
1910  if ($object->status == ExpenseReport::STATUS_CLOSED) {
1911  $rowspan += 2;
1912  }
1913  print "</td>";
1914  print '</tr>';
1915 
1916  print '<tr>';
1917  print '<td>'.$langs->trans("AmountVAT").'</td>';
1918  print '<td class="nowrap amountcard">'.price($object->total_tva, 1, '', 1, -1, -1, $conf->currency).'</td>';
1919  print '</tr>';
1920 
1921  // Amount Local Taxes
1922  if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) { // Localtax1
1923  print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
1924  print '<td class="valuefield">'.price($object->total_localtax1, 1, '', 1, -1, -1, $conf->currency).'</td></tr>';
1925  }
1926  if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) { // Localtax2 IRPF
1927  print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
1928  print '<td class="valuefield">'.price($object->total_localtax2, 1, '', 1, -1, -1, $conf->currency).'</td></tr>';
1929  }
1930 
1931  print '<tr>';
1932  print '<td>'.$langs->trans("AmountTTC").'</td>';
1933  print '<td class="nowrap amountcard">'.price($object->total_ttc, 1, '', 1, -1, -1, $conf->currency).'</td>';
1934  print '</tr>';
1935 
1936  // List of payments already done
1937  $nbcols = 3;
1938  $nbrows = 0;
1939  if (!empty($conf->banque->enabled)) {
1940  $nbrows++;
1941  $nbcols++;
1942  }
1943 
1944  print '<table class="noborder paymenttable centpercent">';
1945 
1946  print '<tr class="liste_titre">';
1947  print '<td class="liste_titre">'.$langs->trans('Payments').'</td>';
1948  print '<td class="liste_titre">'.$langs->trans('Date').'</td>';
1949  print '<td class="liste_titre">'.$langs->trans('Type').'</td>';
1950  if (!empty($conf->banque->enabled)) {
1951  print '<td class="liste_titre right">'.$langs->trans('BankAccount').'</td>';
1952  }
1953  print '<td class="liste_titre right">'.$langs->trans('Amount').'</td>';
1954  print '<td class="liste_titre" width="18">&nbsp;</td>';
1955  print '</tr>';
1956 
1957  // Payments already done (from payment on this expensereport)
1958  $sql = "SELECT p.rowid, p.num_payment, p.datep as dp, p.amount, p.fk_bank,";
1959  $sql .= "c.code as payment_code, c.libelle as payment_type,";
1960  $sql .= "ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal";
1961  $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as e, ".MAIN_DB_PREFIX."payment_expensereport as p";
1962  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepayment = c.id";
1963  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
1964  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
1965  $sql .= " WHERE e.rowid = ".((int) $id);
1966  $sql .= " AND p.fk_expensereport = e.rowid";
1967  $sql .= ' AND e.entity IN ('.getEntity('expensereport').')';
1968  $sql .= " ORDER BY dp";
1969 
1970  $resql = $db->query($sql);
1971  if ($resql) {
1972  $num = $db->num_rows($resql);
1973  $i = 0; $totalpaid = 0;
1974  while ($i < $num) {
1975  $objp = $db->fetch_object($resql);
1976 
1977  $paymentexpensereportstatic->id = $objp->rowid;
1978  $paymentexpensereportstatic->datep = $db->jdate($objp->dp);
1979  $paymentexpensereportstatic->ref = $objp->rowid;
1980  $paymentexpensereportstatic->num_payment = $objp->num_payment;
1981  $paymentexpensereportstatic->type_code = $objp->payment_code;
1982  $paymentexpensereportstatic->type_label = $objp->payment_type;
1983 
1984  print '<tr class="oddseven">';
1985  print '<td>';
1986  print $paymentexpensereportstatic->getNomUrl(1);
1987  print '</td>';
1988  print '<td>'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n";
1989  $labeltype = $langs->trans("PaymentType".$objp->payment_code) != ("PaymentType".$objp->payment_code) ? $langs->trans("PaymentType".$objp->payment_code) : $objp->payment_type;
1990  print "<td>".$labeltype.' '.$objp->num_payment."</td>\n";
1991  // Bank account
1992  if (!empty($conf->banque->enabled)) {
1993  $bankaccountstatic->id = $objp->baid;
1994  $bankaccountstatic->ref = $objp->baref;
1995  $bankaccountstatic->label = $objp->baref;
1996  $bankaccountstatic->number = $objp->banumber;
1997 
1998  if (!empty($conf->accounting->enabled)) {
1999  $bankaccountstatic->account_number = $objp->account_number;
2000 
2001  $accountingjournal = new AccountingJournal($db);
2002  $accountingjournal->fetch($objp->fk_accountancy_journal);
2003  $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
2004  }
2005 
2006  print '<td class="right">';
2007  if ($bankaccountstatic->id) {
2008  print $bankaccountstatic->getNomUrl(1, 'transactions');
2009  }
2010  print '</td>';
2011  }
2012  print '<td class="right">'.price($objp->amount)."</td>";
2013  print '<td></td>';
2014  print "</tr>";
2015  $totalpaid += $objp->amount;
2016  $i++;
2017  }
2018  if (!is_null($totalpaid)) {
2019  $totalpaid = price2num($totalpaid); // Round $totalpaid to fix floating problem after addition into loop
2020  }
2021 
2022  $remaintopay = price2num($object->total_ttc - $totalpaid);
2023  $resteapayeraffiche = $remaintopay;
2024 
2025  $cssforamountpaymentcomplete = 'amountpaymentcomplete';
2026 
2027  if ($object->status == ExpenseReport::STATUS_REFUSED) {
2028  $cssforamountpaymentcomplete = 'amountpaymentneutral';
2029  $resteapayeraffiche = 0;
2030  } elseif ($object->paid == 0) {
2031  $cssforamountpaymentcomplete = 'amountpaymentneutral';
2032  }
2033  print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AlreadyPaid").':</td><td class="right">'.price($totalpaid).'</td><td></td></tr>';
2034  print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AmountExpected").':</td><td class="right">'.price($object->total_ttc).'</td><td></td></tr>';
2035 
2036  print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("RemainderToPay").':</td>';
2037  print '<td class="right'.($resteapayeraffiche ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.price($resteapayeraffiche).'</td><td></td></tr>';
2038 
2039  $db->free($resql);
2040  } else {
2041  dol_print_error($db);
2042  }
2043  print "</table>";
2044 
2045  print '</div>';
2046  print '</div>';
2047 
2048  print '<div class="clearboth"></div><br>';
2049 
2050  print '<div style="clear: both;"></div>';
2051 
2052  $actiontouse = 'updateline';
2053  if (($object->status == 0 || $object->status == 99) && $action != 'editline') {
2054  $actiontouse = 'addline';
2055  }
2056 
2057  print '<form name="expensereport" action="'.$_SERVER["PHP_SELF"].'" enctype="multipart/form-data" method="post" >';
2058  print '<input type="hidden" name="token" value="'.newToken().'">';
2059  print '<input type="hidden" name="action" value="'.$actiontouse.'">';
2060  print '<input type="hidden" name="id" value="'.$object->id.'">';
2061  print '<input type="hidden" name="fk_expensereport" value="'.$object->id.'" />';
2062 
2063  print '<div class="div-table-responsive-no-min">';
2064  print '<table id="tablelines" class="noborder centpercent">';
2065 
2066  if (!empty($object->lines)) {
2067  $i = 0; $total = 0;
2068 
2069  print '<tr class="liste_titre headerexpensereportdet">';
2070  print '<td class="center linecollinenb">'.$langs->trans('LineNb').'</td>';
2071  //print '<td class="center">'.$langs->trans('Piece').'</td>';
2072  print '<td class="center linecoldate">'.$langs->trans('Date').'</td>';
2073  if (!empty($conf->project->enabled)) {
2074  print '<td class="minwidth100imp linecolproject">'.$langs->trans('Project').'</td>';
2075  }
2076  print '<td class="center linecoltype">'.$langs->trans('Type').'</td>';
2077  if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) {
2078  print '<td class="center linecolcarcategory">'.$langs->trans('CarCategory').'</td>';
2079  }
2080  print '<td class="center linecoldescription">'.$langs->trans('Description').'</td>';
2081  print '<td class="right linecolvat">'.$langs->trans('VAT').'</td>';
2082  print '<td class="right linecolpriceuht">'.$langs->trans('PriceUHT').'</td>';
2083  print '<td class="right linecolpriceuttc">'.$langs->trans('PriceUTTC').'</td>';
2084  print '<td class="right linecolqty">'.$langs->trans('Qty').'</td>';
2085  if ($action != 'editline') {
2086  print '<td class="right linecolamountht">'.$langs->trans('AmountHT').'</td>';
2087  print '<td class="right linecolamountttc">'.$langs->trans('AmountTTC').'</td>';
2088  }
2089  // Picture
2090  print '<td>';
2091  print '</td>';
2092 
2093  // Information if theres a rule restriction
2094  print '<td>';
2095  print '</td>';
2096 
2097  // Ajout des boutons de modification/suppression
2098  if (($object->status < 2 || $object->status == 99) && $user->rights->expensereport->creer) {
2099  print '<td class="right"></td>';
2100  }
2101  print '</tr>';
2102 
2103  foreach ($object->lines as &$line) {
2104  $numline = $i + 1;
2105 
2106  if ($action != 'editline' || $line->rowid != GETPOST('rowid', 'int')) {
2107  print '<tr class="oddeven linetr" data-id="'.$line->id.'">';
2108 
2109  // Num
2110  print '<td class="center linecollinenb">';
2111  print $numline;
2112  print '</td>';
2113 
2114  // Date
2115  print '<td class="center linecoldate">'.dol_print_date($db->jdate($line->date), 'day').'</td>';
2116 
2117  // Project
2118  if (!empty($conf->project->enabled)) {
2119  print '<td class="center dateproject">';
2120  if ($line->fk_project > 0) {
2121  $projecttmp->id = $line->fk_project;
2122  $projecttmp->ref = $line->projet_ref;
2123  $projecttmp->title = $line->projet_title;
2124  print $projecttmp->getNomUrl(1);
2125  }
2126  print '</td>';
2127  }
2128 
2129  $titlealt = '';
2130  if (!empty($conf->accounting->enabled)) {
2131  require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
2132  $accountingaccount = new AccountingAccount($db);
2133  $resaccountingaccount = $accountingaccount->fetch(0, $line->type_fees_accountancy_code, 1);
2134  //$titlealt .= '<span class="opacitymedium">';
2135  $titlealt .= $langs->trans("AccountancyCode").': ';
2136  if ($resaccountingaccount > 0) {
2137  $titlealt .= $accountingaccount->account_number;
2138  } else {
2139  $titlealt .= $langs->trans("NotFound");
2140  }
2141  //$titlealt .= '</span>';
2142  }
2143 
2144  // Type of fee
2145  print '<td class="center linecoltype" title="'.dol_escape_htmltag($titlealt).'">';
2146  $labeltype = ($langs->trans(($line->type_fees_code)) == $line->type_fees_code ? $line->type_fees_libelle : $langs->trans($line->type_fees_code));
2147  print $labeltype;
2148  print '</td>';
2149 
2150  // IK
2151  if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) {
2152  print '<td class="fk_c_exp_tax_cat linecoltaxcat">';
2153  $exp_tax_cat_label = dol_getIdFromCode($db, $line->fk_c_exp_tax_cat, 'c_exp_tax_cat', 'rowid', 'label');
2154  print $langs->trans($exp_tax_cat_label);
2155  print '</td>';
2156  }
2157 
2158  // Comment
2159  print '<td class="left linecolcomment">'.dol_nl2br($line->comments).'</td>';
2160 
2161  // VAT rate
2162  print '<td class="right linecolvatrate">'.vatrate($line->vatrate.($line->vat_src_code ? ' ('.$line->vat_src_code.')' : ''), true).'</td>';
2163 
2164  // Unit price HT
2165  print '<td class="right linecolunitht">';
2166  if (!empty($line->value_unit_ht)) {
2167  print price($line->value_unit_ht);
2168  } else {
2169  $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $line->vatrate));
2170  $pricenettoshow = price2num($line->value_unit / (1 + $tmpvat / 100), 'MU');
2171  print price($pricenettoshow);
2172  }
2173  print '</td>';
2174 
2175  print '<td class="right linecolunitttc">'.price($line->value_unit).'</td>';
2176 
2177  print '<td class="right linecolqty">'.dol_escape_htmltag($line->qty).'</td>';
2178 
2179  if ($action != 'editline') {
2180  print '<td class="right linecoltotalht">'.price($line->total_ht).'</td>';
2181  print '<td class="right linecoltotalttc">'.price($line->total_ttc).'</td>';
2182  }
2183 
2184  // Column with preview
2185  print '<td class="center linecolpreview">';
2186  if ($line->fk_ecm_files > 0) {
2187  $modulepart = 'expensereport';
2188  $maxheightmini = 32;
2189 
2190  $result = $ecmfilesstatic->fetch($line->fk_ecm_files);
2191  if ($result > 0) {
2192  $relativepath = preg_replace('/expensereport\//', '', $ecmfilesstatic->filepath);
2193  $fileinfo = pathinfo($ecmfilesstatic->filepath.'/'.$ecmfilesstatic->filename);
2194  if (image_format_supported($fileinfo['basename']) > 0) {
2195  $minifile = getImageFileNameForSize($fileinfo['basename'], '_mini'); // For new thumbs using same ext (in lower case howerver) than original
2196  if (!dol_is_file($conf->expensereport->dir_output.'/'.$relativepath.'/'.$minifile)) {
2197  $minifile = getImageFileNameForSize($fileinfo['basename'], '_mini', '.png'); // For backward compatibility of old thumbs that were created with filename in lower case and with .png extension
2198  }
2199  //print $file['path'].'/'.$minifile.'<br>';
2200  $urlforhref = getAdvancedPreviewUrl($modulepart, $relativepath.'/'.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(!empty($object->entity) ? $object->entity : $conf->entity));
2201  if (empty($urlforhref)) {
2202  $urlforhref = DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity) ? $object->entity : $conf->entity).'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']));
2203  print '<a href="'.$urlforhref.'" class="aphoto" target="_blank" rel="noopener noreferrer">';
2204  } else {
2205  print '<a href="'.$urlforhref['url'].'" class="'.$urlforhref['css'].'" target="'.$urlforhref['target'].'" mime="'.$urlforhref['mime'].'">';
2206  }
2207  print '<img class="photo" height="'.$maxheightmini.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity) ? $object->entity : $conf->entity).'&file='.urlencode($relativepath.'/'.$minifile).'" title="">';
2208  print '</a>';
2209  } else {
2210  $modulepart = 'expensereport';
2211  $thumbshown = 0;
2212  if (preg_match('/\.pdf$/i', $ecmfilesstatic->filename)) {
2213  $filepdf = $conf->expensereport->dir_output.'/'.$relativepath.'/'.$ecmfilesstatic->filename;
2214  $fileimage = $conf->expensereport->dir_output.'/'.$relativepath.'/'.$ecmfilesstatic->filename.'_preview.png';
2215  $relativepathimage = $relativepath.'/'.$ecmfilesstatic->filename.'_preview.png';
2216 
2217  $pdfexists = file_exists($filepdf);
2218  if ($pdfexists) {
2219  // Conversion du PDF en image png si fichier png non existant
2220  if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) {
2221  if (empty($conf->global->MAIN_DISABLE_PDF_THUMBS)) { // If you experience trouble with pdf thumb generation and imagick, you can disable here.
2222  include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
2223  $ret = dol_convert_file($filepdf, 'png', $fileimage, '0'); // Convert first page of PDF into a file _preview.png
2224  if ($ret < 0) {
2225  $error++;
2226  }
2227  }
2228  }
2229  }
2230 
2231  if ($pdfexists && !$error) {
2232  $heightforphotref = 70;
2233  if (!empty($conf->dol_optimize_smallscreen)) {
2234  $heightforphotref = 60;
2235  }
2236  // If the preview file is found
2237  if (file_exists($fileimage)) {
2238  $thumbshown = 1;
2239  $urlforhref = getAdvancedPreviewUrl($modulepart, $relativepath.'/'.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(!empty($object->entity) ? $object->entity : $conf->entity));
2240  print '<a href="'.$urlforhref['url'].'" class="'.$urlforhref['css'].'" target="'.$urlforhref['target'].'" mime="'.$urlforhref['mime'].'">';
2241  print '<img height="'.$heightforphotref.'" class="photo photowithmargin photowithborder" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=apercu'.$modulepart.'&amp;file='.urlencode($relativepathimage).'">';
2242  print '</a>';
2243  }
2244  }
2245  }
2246 
2247  if (!$thumbshown) {
2248  print img_mime($ecmfilesstatic->filename);
2249  }
2250  }
2251  }
2252  }
2253  print '</td>';
2254 
2255  print '<td class="nowrap right linecolwarning">';
2256  print !empty($line->rule_warning_message) ? img_warning(html_entity_decode($line->rule_warning_message)) : '&nbsp;';
2257  print '</td>';
2258 
2259  // Ajout des boutons de modification/suppression
2260  if (($object->status < ExpenseReport::STATUS_VALIDATED || $object->status == ExpenseReport::STATUS_REFUSED) && $user->rights->expensereport->creer) {
2261  print '<td class="nowrap right linecolaction">';
2262 
2263  print '<a class="editfielda reposition paddingrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=editline&token='.newToken().'&rowid='.$line->rowid.'">';
2264  print img_edit();
2265  print '</a> &nbsp; ';
2266  print '<a class="paddingrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete_line&token='.newToken().'&rowid='.$line->rowid.'">';
2267  print img_delete();
2268  print '</a>';
2269 
2270  print '</td>';
2271  }
2272 
2273  print '</tr>';
2274  }
2275 
2276  if ($action == 'editline' && $line->rowid == GETPOST('rowid', 'int')) {
2277  // Add line with link to add new file or attach line to an existing file
2278  $colspan = 11;
2279  if (!empty($conf->project->enabled)) {
2280  $colspan++;
2281  }
2282  if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) {
2283  $colspan++;
2284  }
2285 
2286  print '<!-- line of expense report -->'."\n";
2287  print '<tr class="tredited">';
2288 
2289  print '<td class="center">';
2290  print $numline;
2291  print '</td>';
2292 
2293  print '<td colspan="'.($colspan - 1).'" class="liste_titre"> ';
2294  print '<a href="" class="commonlink auploadnewfilenow reposition">'.$langs->trans("UploadANewFileNow");
2295  print img_picto($langs->trans("UploadANewFileNow"), 'chevron-down', '', false, 0, 0, '', 'marginleftonly');
2296  print '</a>';
2297  if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES)) {
2298  print ' &nbsp; - &nbsp; <a href="" class="commonlink aattachtodoc reposition">'.$langs->trans("AttachTheNewLineToTheDocument");
2299  print img_picto($langs->trans("AttachTheNewLineToTheDocument"), 'chevron-down', '', false, 0, 0, '', 'marginleftonly');
2300  print '</a>';
2301  }
2302 
2303  print '<!-- Code to open/close section to submit or link files in edit mode -->'."\n";
2304  print '<script type="text/javascript">'."\n";
2305  print '$(document).ready(function() {
2306  $( ".auploadnewfilenow" ).click(function() {
2307  jQuery(".truploadnewfilenow").toggle();
2308  jQuery(".trattachnewfilenow").hide();
2309  return false;
2310  });
2311  $( ".aattachtodoc" ).click(function() {
2312  jQuery(".trattachnewfilenow").toggle();
2313  jQuery(".truploadnewfilenow").hide();
2314  return false;
2315  });';
2316  if (is_array(GETPOST('attachfile', 'array')) && count(GETPOST('attachfile', 'array'))) {
2317  print 'jQuery(".trattachnewfilenow").toggle();'."\n";
2318  }
2319  print '
2320  jQuery("form[name=\"expensereport\"]").submit(function() {
2321  if (jQuery(".truploadnewfilenow").is(":hidden")) {
2322  jQuery("input[name=\"sendit\"]").val("");
2323  }
2324  });
2325  ';
2326  print '
2327  });
2328  ';
2329  print '</script>'."\n";
2330  print '</td></tr>';
2331 
2332  $filenamelinked = '';
2333  if ($line->fk_ecm_files > 0) {
2334  $result = $ecmfilesstatic->fetch($line->fk_ecm_files);
2335  if ($result > 0) {
2336  $filenamelinked = $ecmfilesstatic->filename;
2337  }
2338  }
2339 
2340  $tredited = 'tredited';
2341  include DOL_DOCUMENT_ROOT.'/expensereport/tpl/expensereport_addfile.tpl.php';
2342  include DOL_DOCUMENT_ROOT.'/expensereport/tpl/expensereport_linktofile.tpl.php';
2343 
2344  print '<tr class="oddeven tredited">';
2345 
2346  print '<td></td>';
2347 
2348  // Select date
2349  print '<td class="center">';
2350  print $form->selectDate($line->date, 'date');
2351  print '</td>';
2352 
2353  // Select project
2354  if (!empty($conf->project->enabled)) {
2355  print '<td>';
2356  $formproject->select_projects(-1, $line->fk_project, 'fk_project', 0, 0, $projectRequired ? 0 : 1, 1, 0, 0, 0, '', 0, 0, 'maxwidth300');
2357  print '</td>';
2358  }
2359 
2360  // Select type
2361  print '<td class="center">';
2362  print $formexpensereport->selectTypeExpenseReport($line->fk_c_type_fees, 'fk_c_type_fees');
2363  print '</td>';
2364 
2365  if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) {
2366  print '<td class="fk_c_exp_tax_cat">';
2367  $params = array('fk_expense' => $object->id, 'fk_expense_det' => $line->rowid, 'date' => $line->dates);
2368  print $form->selectExpenseCategories($line->fk_c_exp_tax_cat, 'fk_c_exp_tax_cat', 1, array(), 'fk_c_type_fees', $userauthor->default_c_exp_tax_cat, $params);
2369  print '</td>';
2370  }
2371 
2372  // Add comments
2373  print '<td>';
2374  print '<textarea name="comments" class="flat_ndf centpercent">'.dol_escape_htmltag($line->comments, 0, 1).'</textarea>';
2375  print '</td>';
2376 
2377  // VAT
2378  $selectedvat = price2num($line->vatrate).($line->vat_src_code ? ' ('.$line->vat_src_code.')' : '');
2379  print '<td class="right">';
2380  print $form->load_tva('vatrate', (GETPOSTISSET("vatrate") ? GETPOST("vatrate") : $selectedvat), $mysoc, '', 0, 0, '', false, 1);
2381  print '</td>';
2382 
2383  // Unit price
2384  print '<td class="right">';
2385  print '<input type="text" min="0" class="right maxwidth50" id="value_unit_ht" name="value_unit_ht" value="'.dol_escape_htmltag(price2num($line->value_unit_ht)).'"'.$taxlessUnitPriceDisabled.' />';
2386  print '</td>';
2387 
2388  // Unit price with tax
2389  print '<td class="right">';
2390  print '<input type="text" min="0" class="right maxwidth50" id="value_unit" name="value_unit" value="'.dol_escape_htmltag(price2num($line->value_unit)).'" />';
2391  print '</td>';
2392 
2393  // Quantity
2394  print '<td class="right">';
2395  print '<input type="text" min="0" class="input_qty right maxwidth50" name="qty" value="'.dol_escape_htmltag($line->qty).'" />'; // We must be able to enter decimal qty
2396  print '</td>';
2397 
2398  //print '<td class="right">'.$langs->trans('AmountHT').'</td>';
2399  //print '<td class="right">'.$langs->trans('AmountTTC').'</td>';
2400 
2401  // Picture
2402  print '<td class="center">';
2403  //print $line->fk_ecm_files;
2404  print '</td>';
2405  // Information if theres a rule restriction
2406  print '<td class="center">';
2407  print '</td>';
2408 
2409  print '<td>';
2410  print '<input type="hidden" name="rowid" value="'.$line->rowid.'">';
2411  print $form->buttonsSaveCancel('Save', 'Cancel', array(), 0, 'small');
2412  print '</td>';
2413 
2414  print '</tr>';
2415  }
2416 
2417  $i++;
2418  }
2419  }
2420 
2421  // Add a new line
2422  if (($object->status == ExpenseReport::STATUS_DRAFT || $object->status == ExpenseReport::STATUS_REFUSED) && $action != 'editline' && $user->rights->expensereport->creer) {
2423  $colspan = 12;
2424  if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) {
2425  $colspan++;
2426  }
2427  if (!empty($conf->project->enabled)) {
2428  $colspan++;
2429  }
2430  if ($action != 'editline') {
2431  $colspan++;
2432  }
2433 
2434  $nbFiles = $nbLinks = 0;
2435  $arrayoffiles = array();
2436  if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES)) {
2437  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
2438  require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
2439  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
2440  $upload_dir = $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref);
2441  $arrayoffiles = dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png|'.preg_quote(dol_sanitizeFileName($object->ref.'.pdf'), '/').')$');
2442  $nbFiles = count($arrayoffiles);
2443  $nbLinks = Link::count($db, $object->element, $object->id);
2444  }
2445 
2446  // Add line with link to add new file or attach to an existing file
2447  print '<tr class="liste_titre">';
2448  print '<td colspan="'.$colspan.'" class="liste_titre expensereportautoload">';
2449  print '<a href="" class="commonlink auploadnewfilenow reposition">'.$langs->trans("UploadANewFileNow");
2450  print img_picto($langs->trans("UploadANewFileNow"), 'chevron-down', '', false, 0, 0, '', 'marginleftonly');
2451  print '</a>';
2452  if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES)) {
2453  print ' &nbsp; - &nbsp; <a href="" class="commonlink aattachtodoc reposition">'.$langs->trans("AttachTheNewLineToTheDocument");
2454  print img_picto($langs->trans("AttachTheNewLineToTheDocument"), 'chevron-down', '', false, 0, 0, '', 'marginleftonly');
2455  print '</a>';
2456  }
2457 
2458  print '<!-- Code to open/close section to submit or link files in the form to add new line -->'."\n";
2459  print '<script type="text/javascript">'."\n";
2460  print '$(document).ready(function() {
2461  $( ".auploadnewfilenow" ).click(function() {
2462  console.log("We click on toggle of auploadnewfilenow");
2463  jQuery(".truploadnewfilenow").toggle();
2464  jQuery(".trattachnewfilenow").hide();
2465  if (jQuery(".truploadnewfilenow").is(":hidden")) {
2466  jQuery("input[name=\"sendit\"]").prop("name", "senditdisabled");
2467  } else {
2468  jQuery("input[name=\"senditdisabled\"]").prop("name", "sendit");
2469  }
2470  return false;
2471  });
2472  $( ".aattachtodoc" ).click(function() {
2473  console.log("We click on toggle of aattachtodoc");
2474  jQuery(".trattachnewfilenow").toggle();
2475  jQuery(".truploadnewfilenow").hide();
2476  return false;
2477  });'."\n";
2478  if (is_array(GETPOST('attachfile', 'array')) && count(GETPOST('attachfile', 'array')) && $action != 'updateline') {
2479  print 'jQuery(".trattachnewfilenow").show();'."\n";
2480  }
2481  print '
2482  jQuery("form[name=\"expensereport\"]").submit(function() {
2483  if (jQuery(".truploadnewfilenow").is(":hidden")) {
2484  /* When section to send file is not expanded, we disable the button sendit that submit form to add a new file, so button to submit line will work. */
2485  jQuery("input[name=\"sendit\"]").val("");
2486  jQuery("input[name=\"sendit\"]").prop("name", "senditdisabled");
2487  } else {
2488  jQuery("input[name=\"senditdisabled\"]").prop("name", "sendit");
2489  }
2490  });
2491  ';
2492  print '
2493  });
2494  ';
2495  print '</script>'."\n";
2496  print '</td></tr>';
2497 
2498  include DOL_DOCUMENT_ROOT.'/expensereport/tpl/expensereport_linktofile.tpl.php';
2499  include DOL_DOCUMENT_ROOT.'/expensereport/tpl/expensereport_addfile.tpl.php';
2500 
2501  print '<tr class="liste_titre expensereportcreate">';
2502  print '<td></td>';
2503  print '<td class="center expensereportcreatedate">'.$langs->trans('Date').'</td>';
2504  if (!empty($conf->project->enabled)) {
2505  print '<td class="minwidth100imp">'.$form->textwithpicto($langs->trans('Project'), $langs->trans("ClosedProjectsAreHidden")).'</td>';
2506  }
2507  print '<td class="center expensereportcreatetype">'.$langs->trans('Type').'</td>';
2508  if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) {
2509  print '<td>'.$langs->trans('CarCategory').'</td>';
2510  }
2511  print '<td class="right expensereportcreatedescription">'.$langs->trans('Description').'</td>';
2512  print '<td class="right expensereportcreatevat">'.$langs->trans('VAT').'</td>';
2513  print '<td class="right expensereportcreatepriceuth">'.$langs->trans('PriceUHT').'</td>';
2514  print '<td class="right expensereportcreatepricettc">'.$langs->trans('PriceUTTC').'</td>';
2515  print '<td class="right expensereportcreateqty">'.$langs->trans('Qty').'</td>';
2516  print '<td></td>';
2517  print '<td></td>';
2518  print '<td></td>';
2519  print '<td></td>';
2520  print '<td></td>';
2521  print '</tr>';
2522  print '<tr class="oddeven nohover">';
2523 
2524  // Line number
2525  print '<td></td>';
2526 
2527  // Select date
2528  print '<td class="center inputdate">';
2529  print $form->selectDate($date ? $date : -1, 'date', 0, 0, 0, '', 1, 1);
2530  print '</td>';
2531 
2532  // Select project
2533  if (!empty($conf->project->enabled)) {
2534  print '<td class="inputproject">';
2535  $formproject->select_projects(-1, $fk_project, 'fk_project', 0, 0, $projectRequired ? 0 : 1, -1, 0, 0, 0, '', 0, 0, 'maxwidth300');
2536  print '</td>';
2537  }
2538 
2539  // Select type
2540  print '<td class="center inputtype">';
2541  print $formexpensereport->selectTypeExpenseReport($fk_c_type_fees, 'fk_c_type_fees', 1);
2542  print '</td>';
2543 
2544  if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) {
2545  print '<td class="fk_c_exp_tax_cat">';
2546  $params = array('fk_expense' => $object->id);
2547  print $form->selectExpenseCategories('', 'fk_c_exp_tax_cat', 1, array(), 'fk_c_type_fees', $userauthor->default_c_exp_tax_cat, $params, 0);
2548  print '</td>';
2549  }
2550 
2551  // Add comments
2552  print '<td class="inputcomment">';
2553  print '<textarea class="flat_ndf centpercent" name="comments" rows="'.ROWS_2.'">'.dol_escape_htmltag($comments, 0, 1).'</textarea>';
2554  print '</td>';
2555 
2556  // Select VAT
2557  print '<td class="right inputvat">';
2558  $defaultvat = -1;
2559  if (!empty($conf->global->EXPENSEREPORT_NO_DEFAULT_VAT)) {
2560  $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS = 'none';
2561  }
2562  print $form->load_tva('vatrate', ($vatrate != '' ? $vatrate : $defaultvat), $mysoc, '', 0, 0, '', false, 1);
2563  print '</td>';
2564 
2565  // Unit price net
2566  print '<td class="right inputpricenet">';
2567  print '<input type="text" class="right maxwidth50" id="value_unit_ht" name="value_unit_ht" value="'.dol_escape_htmltag($value_unit_ht).'"'.$taxlessUnitPriceDisabled.' />';
2568  print '</td>';
2569 
2570  // Unit price with tax
2571  print '<td class="right inputtax">';
2572  print '<input type="text" class="right maxwidth50" id="value_unit" name="value_unit" value="'.dol_escape_htmltag($value_unit).'">';
2573  print '</td>';
2574 
2575  // Quantity
2576  print '<td class="right inputqty">';
2577  print '<input type="text" min="0" class=" input_qty right maxwidth50" name="qty" value="'.dol_escape_htmltag($qty ? $qty : 1).'">'; // We must be able to enter decimal qty
2578  print '</td>';
2579 
2580  // Picture
2581  print '<td></td>';
2582 
2583  if ($action != 'editline') {
2584  print '<td class="right"></td>';
2585  print '<td class="right"></td>';
2586  }
2587 
2588  print '<td class="center inputbuttons">';
2589  print $form->buttonsSaveCancel("Add", '', '', 1);
2590  print '</td>';
2591 
2592  print '</tr>';
2593  } // Fin si c'est payé/validé
2594 
2595  print '</table>';
2596  print '</div>';
2597 
2598  print '<script>
2599 
2600  /* JQuery for product free or predefined select */
2601  jQuery(document).ready(function() {
2602  jQuery("#value_unit_ht").keyup(function(event) {
2603  console.log(event.which); // discard event tag and arrows
2604  if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#value_unit_ht").val() != "") {
2605  jQuery("#value_unit").val("");
2606  }
2607  });
2608  jQuery("#value_unit").keyup(function(event) {
2609  console.log(event.which); // discard event tag and arrows
2610  if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#value_unit").val() != "") {
2611  jQuery("#value_unit_ht").val("");
2612  }
2613  });
2614  ';
2615 
2616  if (! empty($conf->global->MAIN_USE_EXPENSE_IK)) {
2617  print '
2618 
2619  /* unit price coéf calculation */
2620  jQuery(".input_qty, #fk_c_type_fees, #select_fk_c_exp_tax_cat, #vatrate ").change(function(event) {
2621 
2622  let type_fee = jQuery("#fk_c_type_fees").find(":selected").val();
2623  let tax_cat = jQuery("#select_fk_c_exp_tax_cat").find(":selected").val();
2624  let tva = jQuery("#vatrate").find(":selected").val();
2625  let qty = jQuery(".input_qty").val();
2626 
2627 
2628 
2629  let path = "'.dol_buildpath("/expensereport/ajax/ajaxik.php", 1) .'";
2630  path += "?fk_c_exp_tax_cat="+tax_cat;
2631  path +="&fk_expense="+'.$object->id.';
2632  path += "&vatrate="+tva;
2633  path += "&qty="+qty;
2634 
2635  if (type_fee == 4) { // frais_kilométriques
2636 
2637  if (tax_cat == "" || parseInt(tax_cat) <= 0){
2638  return ;
2639  }
2640 
2641  jQuery.ajax({
2642  url: path
2643  ,async:false
2644  ,dataType:"json"
2645  ,success:function(response) {
2646  if (response.response_status == "success"){';
2647 
2648  if (!empty($conf->global->EXPENSEREPORT_FORCE_LINE_AMOUNTS_INCLUDING_TAXES_ONLY)) {
2649  print '
2650  jQuery("#value_unit").val(parseFloat(response.data) * (100 + parseFloat(tva)) / 100);
2651  jQuery("#value_unit").trigger("change");
2652  ';
2653  } else {
2654  print '
2655  jQuery("#value_unit_ht").val(response.data);
2656  jQuery("#value_unit_ht").trigger("change");
2657  jQuery("#value_unit").val("");
2658  ';
2659  }
2660 
2661  print '
2662  } else if(response.response_status == "error" && response.errorMessage != undefined && response.errorMessage.length > 0 ){
2663  $.jnotify(response.errorMessage, "error", {timeout: 0, type: "error"},{ remove: function (){} } );
2664  }
2665  },
2666 
2667  });
2668  }
2669 
2670  /*console.log(event.which); // discard event tag and arrows
2671  if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#value_unit").val() != "") {
2672  jQuery("#value_unit_ht").val("");
2673  }*/
2674  });
2675  ';
2676  }
2677 
2678  print '
2679 
2680  });
2681 
2682  </script>';
2683 
2684  print '</form>';
2685 
2686  print dol_get_fiche_end();
2687  }
2688  } else {
2689  dol_print_error($db);
2690  }
2691 } else {
2692  print 'Record not found';
2693 
2694  llxFooter();
2695  exit(1);
2696 }
2697 
2698 
2699 /*
2700  * Action bar
2701  */
2702 
2703 print '<div class="tabsAction">';
2704 
2705 if ($action != 'create' && $action != 'edit' && $action != 'editline') {
2706  $object = new ExpenseReport($db);
2707  $object->fetch($id, $ref);
2708 
2709  // Send
2710  if (empty($user->socid)) {
2711  if ($object->status > ExpenseReport::STATUS_DRAFT) {
2712  //if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->expensereport->expensereport_advance->send)) {
2713  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>';
2714  //} else
2715  // print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">' . $langs->trans('SendMail') . '</a></div>';
2716  }
2717  }
2718 
2719  /* Si l'état est "Brouillon"
2720  * ET user à droit "creer/supprimer"
2721  * ET fk_user_author == user courant
2722  * Afficher : "Enregistrer" / "Modifier" / "Supprimer"
2723  */
2724  if ($user->rights->expensereport->creer && $object->status == ExpenseReport::STATUS_DRAFT) {
2725  if (in_array($object->fk_user_author, $user->getAllChildIds(1)) || !empty($user->rights->expensereport->writeall_advance)) {
2726  // Modify
2727  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$object->id.'">'.$langs->trans('Modify').'</a></div>';
2728 
2729  // Validate
2730  if (count($object->lines) > 0) {
2731  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=save&token='.newToken().'&id='.$object->id.'">'.$langs->trans('ValidateAndSubmit').'</a></div>';
2732  }
2733  }
2734  }
2735 
2736  /* Si l'état est "Refusée"
2737  * ET user à droit "creer/supprimer"
2738  * ET fk_user_author == user courant
2739  * Afficher : "Enregistrer" / "Modifier" / "Supprimer"
2740  */
2741  if ($user->rights->expensereport->creer && $object->status == ExpenseReport::STATUS_REFUSED) {
2742  if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) {
2743  // Modify
2744  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$object->id.'">'.$langs->trans('Modify').'</a></div>';
2745 
2746  // setdraft (le statut refusée est identique à brouillon)
2747  //print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=brouillonner&id='.$id.'">'.$langs->trans('ReOpen').'</a>';
2748  // Enregistrer depuis le statut "Refusée"
2749  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=save_from_refuse&token='.newToken().'&id='.$object->id.'">'.$langs->trans('ValidateAndSubmit').'</a></div>';
2750  }
2751  }
2752 
2753  if ($user->rights->expensereport->to_paid && $object->status == ExpenseReport::STATUS_APPROVED) {
2754  if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) {
2755  // setdraft
2756  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=setdraft&token='.newToken().'&id='.$object->id.'">'.$langs->trans('SetToDraft').'</a></div>';
2757  }
2758  }
2759 
2760  /* Si l'état est "En attente d'approbation"
2761  * ET user à droit de "approve"
2762  * ET fk_user_validator == user courant
2763  * Afficher : "Valider" / "Refuser" / "Supprimer"
2764  */
2765  if ($object->status == ExpenseReport::STATUS_VALIDATED) {
2766  if (in_array($object->fk_user_author, $user->getAllChildIds(1))) {
2767  // set draft
2768  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=setdraft&token='.newToken().'&id='.$object->id.'">'.$langs->trans('SetToDraft').'</a></div>';
2769  }
2770  }
2771 
2772  if ($user->rights->expensereport->approve && $object->status == ExpenseReport::STATUS_VALIDATED) {
2773  //if($object->fk_user_validator==$user->id)
2774  //{
2775  // Validate
2776  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=validate&id='.$object->id.'">'.$langs->trans('Approve').'</a></div>';
2777  // Deny
2778  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=refuse&id='.$object->id.'">'.$langs->trans('Deny').'</a></div>';
2779  //}
2780 
2781  if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) {
2782  // Cancel
2783  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=cancel&id='.$object->id.'">'.$langs->trans("Cancel").'</a></div>';
2784  }
2785  }
2786 
2787 
2788  // If status is Approved
2789  // ---------------------
2790 
2791  if ($user->rights->expensereport->approve && $object->status == ExpenseReport::STATUS_APPROVED) {
2792  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=refuse&id='.$object->id.'">'.$langs->trans('Deny').'</a></div>';
2793  }
2794 
2795  // If bank module is used
2796  if ($user->rights->expensereport->to_paid && !empty($conf->banque->enabled) && $object->status == ExpenseReport::STATUS_APPROVED) {
2797  // Pay
2798  if ($remaintopay == 0) {
2799  print '<div class="inline-block divButAction"><span class="butActionRefused classfortooltip" title="'.$langs->trans("DisabledBecauseRemainderToPayIsZero").'">'.$langs->trans('DoPayment').'</span></div>';
2800  } else {
2801  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/expensereport/payment/payment.php?id='.$object->id.'&amp;action=create">'.$langs->trans('DoPayment').'</a></div>';
2802  }
2803  }
2804 
2805  // If bank module is not used
2806  if (($user->rights->expensereport->to_paid || empty($conf->banque->enabled)) && $object->status == ExpenseReport::STATUS_APPROVED) {
2807  //if ((round($remaintopay) == 0 || empty($conf->banque->enabled)) && $object->paid == 0)
2808  if ($object->paid == 0) {
2809  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=set_paid&token='.newToken().'">'.$langs->trans("ClassifyPaid")."</a></div>";
2810  }
2811  }
2812 
2813  if ($user->rights->expensereport->creer && ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) && $object->status == ExpenseReport::STATUS_APPROVED) {
2814  // Cancel
2815  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=cancel&token='.newToken().'&id='.$object->id.'">'.$langs->trans("Cancel").'</a></div>';
2816  }
2817 
2818  // TODO Replace this. It should be SetUnpaid and should go back to status unpaid not canceled.
2819  if (($user->rights->expensereport->approve || $user->rights->expensereport->to_paid) && $object->status == ExpenseReport::STATUS_CLOSED) {
2820  // Cancel
2821  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=cancel&token='.newToken().'&id='.$object->id.'">'.$langs->trans("Cancel").'</a></div>';
2822  }
2823 
2824  if ($user->rights->expensereport->to_paid && $object->paid && $object->status == ExpenseReport::STATUS_CLOSED) {
2825  // Set unpaid
2826  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=set_unpaid&token='.newToken().'&id='.$object->id.'">'.$langs->trans('ClassifyUnPaid').'</a></div>';
2827  }
2828 
2829  // Clone
2830  if ($user->rights->expensereport->creer) {
2831  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=clone&token='.newToken().'">'.$langs->trans("ToClone").'</a></div>';
2832  }
2833 
2834  /* If draft, validated, cancel, and user can create, he can always delete its card before it is approved */
2835  if ($user->rights->expensereport->creer && $user->id == $object->fk_user_author && $object->status < ExpenseReport::STATUS_APPROVED) {
2836  // Delete
2837  print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id.'">'.$langs->trans('Delete').'</a></div>';
2838  } elseif ($candelete && $object->status != ExpenseReport::STATUS_CLOSED) {
2839  // Delete
2840  print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id.'">'.$langs->trans('Delete').'</a></div>';
2841  }
2842 
2843  $parameters = array();
2844  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
2845 }
2846 
2847 print '</div>';
2848 
2849 
2850 // Select mail models is same action as presend
2851 if (GETPOST('modelselected', 'alpha')) {
2852  $action = 'presend';
2853 }
2854 
2855 if ($action != 'presend') {
2856  /*
2857  * Generate documents
2858  */
2859 
2860  print '<div class="fichecenter"><div class="fichehalfleft">';
2861  print '<a name="builddoc"></a>'; // ancre
2862 
2863  if ($user->rights->expensereport->creer && $action != 'create' && $action != 'edit') {
2864  $filename = dol_sanitizeFileName($object->ref);
2865  $filedir = $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref);
2866  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
2867  $genallowed = $user->rights->expensereport->creer;
2868  $delallowed = $user->rights->expensereport->creer;
2869  $var = true;
2870  print $formfile->showdocuments('expensereport', $filename, $filedir, $urlsource, $genallowed, $delallowed);
2871  $somethingshown = $formfile->numoffiles;
2872  }
2873 
2874  // Disabled for expensereport, there is no thirdparty on expensereport, so nothing to define the list of other object we can suggest to link to
2875  /*
2876  if ($action != 'create' && $action != 'edit' && ($id || $ref))
2877  {
2878  $linktoelem = $form->showLinkToObjectBlock($object, null, array('expensereport'));
2879  $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
2880  }
2881  */
2882 
2883  print '</div><div class="fichehalfright">';
2884  // List of actions on element
2885  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
2886  $formactions = new FormActions($db);
2887  $somethingshown = $formactions->showactions($object, 'expensereport', null);
2888 
2889  print '</div></div>';
2890 }
2891 
2892 // Presend form
2893 $modelmail = 'expensereport';
2894 $defaulttopic = 'SendExpenseReportRef';
2895 $diroutput = $conf->expensereport->dir_output;
2896 $trackid = 'exp'.$object->id;
2897 
2898 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
2899 
2900 
2901 llxFooter();
2902 
2903 $db->close();
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
ExpenseReport\STATUS_VALIDATED
const STATUS_VALIDATED
Validated (need to be paid)
Definition: expensereport.class.php:145
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
expensereport_prepare_head
expensereport_prepare_head($object)
Prepare array with list of tabs.
Definition: expensereport.lib.php:30
Project
Class to manage projects.
Definition: project.class.php:35
EcmFiles\fetch
fetch($id, $ref='', $relativepath='', $hashoffile='', $hashforshare='', $src_object_type='', $src_object_id=0)
Load object in memory from the database.
Definition: ecmfiles.class.php:374
ExpenseReport\STATUS_APPROVED
const STATUS_APPROVED
Classified approved.
Definition: expensereport.class.php:155
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
FormActions
Class to manage building of HTML components.
Definition: html.formactions.class.php:30
Translate
Class to manage translations.
Definition: translate.class.php:30
img_warning
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
Definition: functions.lib.php:4521
FormProjets
Class to manage building of HTML components.
Definition: html.formprojet.class.php:30
CMailFile
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Definition: CMailFile.class.php:38
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
image_format_supported
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
Definition: images.lib.php:80
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
dol_clone
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
Definition: functions.lib.php:1158
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4389
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
dol_is_file
dol_is_file($pathoffile)
Return if path is a file.
Definition: files.lib.php:477
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
get_date_range
get_date_range($date_start, $date_end, $format='', $outputlangs='', $withparenthesis=1)
Format output for start and end date.
Definition: functions.lib.php:8031
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
FormExpenseReport
Class to manage generation of HTML components for contract module.
Definition: html.formexpensereport.class.php:28
$formactions
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif($action=='specimen') elseif($action=='setmodel') elseif($action=='del') elseif($action=='setdoc') $formactions
View.
Definition: agenda_other.php:178
img_delete
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
Definition: functions.lib.php:4429
$formconfirm
$formconfirm
if ($action == 'delbookkeepingyear') {
Definition: listbyaccount.php:576
ExpenseReport\STATUS_CLOSED
const STATUS_CLOSED
Classified paid.
Definition: expensereport.class.php:165
dol_getIdFromCode
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
Definition: functions.lib.php:8535
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
ExpenseReport\STATUS_DRAFT
const STATUS_DRAFT
Draft status.
Definition: expensereport.class.php:140
dol_convert_file
dol_convert_file($fileinput, $ext='png', $fileoutput='', $page='')
Convert an image file or a PDF into another image format.
Definition: files.lib.php:1970
AccountingJournal
Class to manage accounting accounts.
Definition: accountingjournal.class.php:27
getAdvancedPreviewUrl
getAdvancedPreviewUrl($modulepart, $relativepath, $alldata=0, $param='')
Return URL we can use for advanced preview links.
Definition: functions.lib.php:9646
isValidEmail
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
Definition: functions.lib.php:3681
ExpenseReport\STATUS_REFUSED
const STATUS_REFUSED
Classified refused.
Definition: expensereport.class.php:160
PaymentExpenseReport
Class to manage payments of expense report.
Definition: paymentexpensereport.class.php:31
EcmFiles
Class to manage ECM files.
Definition: ecmfiles.class.php:35
ExpenseReportLine
Class of expense report details lines.
Definition: expensereport.class.php:2678
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
AccountingAccount
Class to manage accounting accounts.
Definition: accountingaccount.class.php:36
User
Class to manage Dolibarr users.
Definition: user.class.php:44
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
img_mime
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
Definition: functions.lib.php:4726
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
$parameters
$parameters
Actions.
Definition: card.php:78
ExpenseReport
Class to manage Trips and Expenses.
Definition: expensereport.class.php:36
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
getImageFileNameForSize
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
Definition: functions.lib.php:9595
price
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
Definition: functions.lib.php:5541
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
dol_mktime
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Definition: functions.lib.php:2757
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
DolEditor
Class to manage a WYSIWYG editor.
Definition: doleditor.class.php:30
ExpenseReport\STATUS_CANCELED
const STATUS_CANCELED
Classified canceled.
Definition: expensereport.class.php:150
Account
Class to manage bank accounts.
Definition: account.class.php:38