dolibarr  9.0.0
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2015-2017 Alexandre Spangaro <aspangaro@zendsi.com>
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 <http://www.gnu.org/licenses/>.
21  */
22 
29 $res=0;
30 require '../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
32 require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php';
33 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
34 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
35 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
36 require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
37 require_once DOL_DOCUMENT_ROOT . '/core/lib/expensereport.lib.php';
38 require_once DOL_DOCUMENT_ROOT . '/core/lib/price.lib.php';
39 require_once DOL_DOCUMENT_ROOT . '/core/modules/expensereport/modules_expensereport.php';
40 require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php';
41 require_once DOL_DOCUMENT_ROOT . '/expensereport/class/paymentexpensereport.class.php';
42 require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
43 require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
44 if (! empty($conf->accounting->enabled)) {
45  require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
46 }
47 
48 // Load translation files required by the page
49 $langs->loadLangs(array("trips","bills","mails"));
50 
51 $action=GETPOST('action','aZ09');
52 $cancel=GETPOST('cancel','alpha');
53 $confirm = GETPOST('confirm', 'alpha');
54 
55 $date_start = dol_mktime(0, 0, 0, GETPOST('date_debutmonth','int'), GETPOST('date_debutday','int'), GETPOST('date_debutyear','int'));
56 $date_end = dol_mktime(0, 0, 0, GETPOST('date_finmonth','int'), GETPOST('date_finday','int'), GETPOST('date_finyear','int'));
57 $date = dol_mktime(0, 0, 0, GETPOST('datemonth','int'), GETPOST('dateday','int'), GETPOST('dateyear','int'));
58 $fk_projet=GETPOST('fk_projet','int');
59 $vatrate=GETPOST('vatrate','alpha');
60 $ref=GETPOST("ref",'alpha');
61 $comments=GETPOST('comments','none');
62 $fk_c_type_fees=GETPOST('fk_c_type_fees','int');
63 $socid = GETPOST('socid','int')?GETPOST('socid','int'):GETPOST('socid_id','int');
64 
65 // Security check
66 $id=GETPOST("id",'int');
67 if ($user->societe_id) $socid=$user->societe_id;
68 $result = restrictedArea($user, 'expensereport', 0, 'expensereport');
69 
70 
71 // Hack to use expensereport dir
72 $rootfordata = DOL_DATA_ROOT;
73 $rootforuser = DOL_DATA_ROOT;
74 // If multicompany module is enabled, we redefine the root of data
75 if (! empty($conf->multicompany->enabled) && ! empty($conf->entity) && $conf->entity > 1)
76 {
77  $rootfordata.='/'.$conf->entity;
78 }
79 $conf->expensereport->dir_output = $rootfordata.'/expensereport';
80 
81 // Define $urlwithroot
82 $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
83 $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
84 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
85 
86 // PDF
87 $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
88 $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
89 $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
90 
91 
92 $object=new ExpenseReport($db);
93 $extrafields = new ExtraFields($db);
94 
95 // fetch optionals attributes and labels
96 $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
97 
98 // Load object
99 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
100 
101 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
102 $hookmanager->initHooks(array('expensereportcard','globalcard'));
103 
104 $permissionnote = $user->rights->expensereport->creer; // Used by the include of actions_setnotes.inc.php
105 $permissiondellink = $user->rights->expensereport->creer; // Used by the include of actions_dellink.inc.php
106 $permissionedit = $user->rights->expensereport->creer; // Used by the include of actions_lineupdown.inc.php
107 
108 
109 
110 
111 /*
112  * Actions
113  */
114 
115 $parameters = array('socid' => $socid);
116 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
117 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
118 
119 if (empty($reshook))
120 {
121  if ($cancel)
122  {
123  if (! empty($backtopage))
124  {
125  header("Location: ".$backtopage);
126  exit;
127  }
128  $action='';
129 
130  $fk_projet='';
131  $date_start='';
132  $date_end='';
133  $date='';
134  $comments='';
135  $vatrate='';
136  $value_unit='';
137  $qty=1;
138  $fk_c_type_fees=-1;
139  }
140 
141  include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
142 
143  include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
144 
145  include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
146 
147  // Action clone object
148  if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->expensereport->creer)
149  {
150  if (1==0 && ! GETPOST('clone_content','alpha') && ! GETPOST('clone_receivers','alpha'))
151  {
152  setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
153  }
154  else
155  {
156  if ($object->id > 0)
157  {
158  // Because createFromClone modifies the object, we must clone it so that we can restore it later if it fails
159  $orig = clone $object;
160 
161  $result=$object->createFromClone(GETPOST('fk_user_author','int'));
162  if ($result > 0)
163  {
164  header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
165  exit;
166  }
167  else
168  {
169  setEventMessages($object->error, $object->errors, 'errors');
170  $object = $orig;
171  $action='';
172  }
173  }
174  }
175  }
176 
177  if ($action == 'confirm_delete' && GETPOST("confirm",'alpha') == "yes" && $id > 0 && $user->rights->expensereport->supprimer)
178  {
179  $object = new ExpenseReport($db);
180  $result = $object->fetch($id);
181  $result = $object->delete($user);
182  if ($result >= 0)
183  {
184  header("Location: index.php");
185  exit;
186  }
187  else
188  {
189  setEventMessages($object->error, $object->errors, 'errors');
190  }
191  }
192 
193  if ($action == 'add' && $user->rights->expensereport->creer)
194  {
195  $object = new ExpenseReport($db);
196 
197  $object->date_debut = $date_start;
198  $object->date_fin = $date_end;
199 
200  $object->fk_user_author = GETPOST('fk_user_author','int');
201  if (! ($object->fk_user_author > 0)) $object->fk_user_author = $user->id;
202 
203  $fuser=new User($db);
204  $fuser->fetch($object->fk_user_author);
205 
206  $object->fk_statut = 1;
207  $object->fk_c_paiement = GETPOST('fk_c_paiement','int');
208  $object->fk_user_validator = GETPOST('fk_user_validator','int');
209  $object->note_public = GETPOST('note_public','none');
210  $object->note_private = GETPOST('note_private','none');
211  // Fill array 'array_options' with data from add form
212  if (! $error)
213  {
214  $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
215  if ($ret < 0) $error++;
216  }
217 
218  if (empty($conf->global->EXPENSEREPORT_ALLOW_OVERLAPPING_PERIODS) && $object->periode_existe($fuser,$object->date_debut,$object->date_fin))
219  {
220  $error++;
221  setEventMessages($langs->trans("ErrorDoubleDeclaration"), null, 'errors');
222  $action='create';
223  }
224 
225  if (! $error)
226  {
227  $db->begin();
228 
229  $id = $object->create($user);
230  if ($id <= 0)
231  {
232  $error++;
233  }
234 
235  if (! $error)
236  {
237  $db->commit();
238  Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
239  exit;
240  }
241  else
242  {
243  setEventMessages($object->error, $object->errors, 'errors');
244  $db->rollback();
245  $action='create';
246  }
247  }
248  }
249 
250  if ($action == 'update' && $user->rights->expensereport->creer)
251  {
252  $object = new ExpenseReport($db);
253  $object->fetch($id);
254 
255  $object->date_debut = $date_start;
256  $object->date_fin = $date_end;
257 
258  if($object->fk_statut < 3)
259  {
260  $object->fk_user_validator = GETPOST('fk_user_validator','int');
261  }
262 
263  $object->fk_c_paiement = GETPOST('fk_c_paiement','int');
264  $object->note_public = GETPOST('note_public','none');
265  $object->note_private = GETPOST('note_private','none');
266  $object->fk_user_modif = $user->id;
267 
268  $result = $object->update($user);
269  if ($result > 0)
270  {
271  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_POST['id']);
272  exit;
273  }
274  else
275  {
276  setEventMessages($object->error, $object->errors, 'errors');
277  }
278  }
279 
280  if ($action == 'update_extras')
281  {
282  $object->oldcopy = dol_clone($object);
283 
284  // Fill array 'array_options' with data from update form
285  $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
286  $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute', 'none'));
287  if ($ret < 0) $error++;
288 
289  if (! $error)
290  {
291  // Actions on extra fields
292  $result = $object->insertExtraFields('EXPENSEREPORT_MODIFY');
293  if ($result < 0)
294  {
295  setEventMessages($object->error, $object->errors, 'errors');
296  $error++;
297  }
298  }
299 
300  if ($error)
301  $action = 'edit_extras';
302  }
303 
304  if ($action == "confirm_validate" && GETPOST("confirm", 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->creer)
305  {
306  $error = 0;
307 
308  $db->begin();
309 
310  $object = new ExpenseReport($db);
311  $object->fetch($id);
312 
313  $result = $object->setValidate($user);
314 
315  if ($result >= 0)
316  {
317  // Define output language
318  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
319  {
320  $outputlangs = $langs;
321  $newlang = '';
322  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
323  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
324  if (! empty($newlang)) {
325  $outputlangs = new Translate("", $conf);
326  $outputlangs->setDefaultLang($newlang);
327  }
328  $model=$object->modelpdf;
329  $ret = $object->fetch($id); // Reload to get new records
330 
331  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
332  }
333  }
334  else
335  {
336  setEventMessages($object->error, $object->errors, 'errors');
337  $error++;
338  }
339 
340  if (! $error && $result > 0 && $object->fk_user_validator > 0)
341  {
342  $langs->load("mails");
343 
344  // TO
345  $destinataire = new User($db);
346  $destinataire->fetch($object->fk_user_validator);
347  $emailTo = $destinataire->email;
348 
349  // FROM
350  $expediteur = new User($db);
351  $expediteur->fetch($object->fk_user_author);
352  $emailFrom = $expediteur->email;
353 
354  if ($emailTo && $emailFrom)
355  {
356  $filename=array(); $filedir=array(); $mimetype=array();
357 
358  // SUBJECT
359  $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
360  if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE;
361 
362  $subject = $societeName." - ".$langs->transnoentities("ExpenseReportWaitingForApproval");
363 
364  // CONTENT
365  $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
366  $message = $langs->transnoentities("ExpenseReportWaitingForApprovalMessage", $expediteur->getFullName($langs), get_date_range($object->date_debut,$object->date_fin,'',$langs), $link);
367 
368  // Rebuild pdf
369  /*
370  $object->setDocModel($user,"");
371  $resultPDF = expensereport_pdf_create($db,$id,'',"",$langs);
372 
373  if($resultPDF):
374  // ATTACHMENT
375  array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
376  array_push($filedir,$conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref) . "/" . dol_sanitizeFileName($object->ref).".pdf");
377  array_push($mimetype,"application/pdf");
378  */
379 
380  // PREPARE SEND
381  $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1);
382 
383  if ($mailfile)
384  {
385  // SEND
386  $result=$mailfile->sendfile();
387  if ($result)
388  {
389  $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2));
390  setEventMessages($mesg, null, 'mesgs');
391  }
392  else
393  {
394  $langs->load("other");
395  if ($mailfile->error)
396  {
397  $mesg='';
398  $mesg.=$langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo);
399  $mesg.='<br>'.$mailfile->error;
400  setEventMessages($mesg, null, 'errors');
401  }
402  else
403  {
404  setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings');
405  }
406  }
407  }
408  else
409  {
410  setEventMessages($mailfile->error,$mailfile->errors,'errors');
411  $action='';
412  }
413  }
414  else
415  {
416  setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings');
417  $action='';
418  }
419  }
420 
421  if (! $error)
422  {
423  $db->commit();
424  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
425  exit;
426  }
427  else
428  {
429  $db->rollback();
430  }
431  }
432 
433  if ($action == "confirm_save_from_refuse" && GETPOST("confirm", 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->creer)
434  {
435  $object = new ExpenseReport($db);
436  $object->fetch($id);
437  $result = $object->set_save_from_refuse($user);
438 
439  if ($result > 0)
440  {
441  // Define output language
442  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
443  {
444  $outputlangs = $langs;
445  $newlang = '';
446  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
447  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
448  if (! empty($newlang)) {
449  $outputlangs = new Translate("", $conf);
450  $outputlangs->setDefaultLang($newlang);
451  }
452  $model=$object->modelpdf;
453  $ret = $object->fetch($id); // Reload to get new records
454 
455  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
456  }
457  }
458 
459  if ($result > 0)
460  {
461  // Send mail
462 
463  // TO
464  $destinataire = new User($db);
465  $destinataire->fetch($object->fk_user_validator);
466  $emailTo = $destinataire->email;
467 
468  // FROM
469  $expediteur = new User($db);
470  $expediteur->fetch($object->fk_user_author);
471  $emailFrom = $expediteur->email;
472 
473  if ($emailFrom && $emailTo)
474  {
475  $filename=array(); $filedir=array(); $mimetype=array();
476 
477  // SUBJECT
478  $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
479  if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE;
480 
481  $subject = $societeName." - ".$langs->transnoentities("ExpenseReportWaitingForReApproval");
482 
483  // CONTENT
484  $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
485  $dateRefusEx = explode(" ",$object->date_refuse);
486  $message = $langs->transnoentities("ExpenseReportWaitingForReApprovalMessage", $dateRefusEx[0], $object->detail_refuse, $expediteur->getFullName($langs), $link);
487 
488  // Rebuild pdf
489  /*
490  $object->setDocModel($user,"");
491  $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs);
492 
493  if($resultPDF)
494  {
495  // ATTACHMENT
496  $filename=array(); $filedir=array(); $mimetype=array();
497  array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
498  array_push($filedir,$conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref) . "/" . dol_sanitizeFileName($object->ref_number).".pdf");
499  array_push($mimetype,"application/pdf");
500  }
501  */
502 
503 
504  // PREPARE SEND
505  $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1);
506 
507  if ($mailfile)
508  {
509  // SEND
510  $result=$mailfile->sendfile();
511  if ($result)
512  {
513  $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2));
514  setEventMessages($mesg, null, 'mesgs');
515  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
516  exit;
517  }
518  else
519  {
520  $langs->load("other");
521  if ($mailfile->error)
522  {
523  $mesg='';
524  $mesg.=$langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo);
525  $mesg.='<br>'.$mailfile->error;
526  setEventMessages($mesg, null, 'errors');
527  }
528  else
529  {
530  setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings');
531  }
532  }
533  }
534  else
535  {
536  setEventMessages($mailfile->error,$mailfile->errors,'errors');
537  $action='';
538  }
539  }
540  else
541  {
542  setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings');
543  $action='';
544  }
545  }
546  else
547  {
548  setEventMessages($object->error, $object->errors, 'errors');
549  }
550  }
551 
552  // Approve
553  if ($action == "confirm_approve" && GETPOST("confirm", 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->approve)
554  {
555  $object = new ExpenseReport($db);
556  $object->fetch($id);
557 
558  $result = $object->setApproved($user);
559 
560  if ($result > 0)
561  {
562  // Define output language
563  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
564  {
565  $outputlangs = $langs;
566  $newlang = '';
567  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
568  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
569  if (! empty($newlang)) {
570  $outputlangs = new Translate("", $conf);
571  $outputlangs->setDefaultLang($newlang);
572  }
573  $model=$object->modelpdf;
574  $ret = $object->fetch($id); // Reload to get new records
575 
576  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
577  }
578  }
579 
580  if ($result > 0)
581  {
582  // Send mail
583 
584  // TO
585  $destinataire = new User($db);
586  $destinataire->fetch($object->fk_user_author);
587  $emailTo = $destinataire->email;
588 
589  // CC
590  $emailCC = $conf->global->NDF_CC_EMAILS;
591  if (empty($emailTo)) $emailTo=$emailCC;
592 
593  // FROM
594  $expediteur = new User($db);
595  $expediteur->fetch($object->fk_user_approve > 0 ? $object->fk_user_approve : $object->fk_user_validator);
596  $emailFrom = $expediteur->email;
597 
598  if ($emailFrom && $emailTo)
599  {
600  $filename=array(); $filedir=array(); $mimetype=array();
601 
602  // SUBJECT
603  $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
604  if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE;
605 
606  $subject = $societeName." - ".$langs->transnoentities("ExpenseReportApproved");
607 
608  // CONTENT
609  $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
610  $message = $langs->transnoentities("ExpenseReportApprovedMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link);
611 
612  // Rebuilt pdf
613  /*
614  $object->setDocModel($user,"");
615  $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs);
616 
617  if($resultPDF
618  {
619  // ATTACHMENT
620  $filename=array(); $filedir=array(); $mimetype=array();
621  array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
622  array_push($filedir, $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref)."/".dol_sanitizeFileName($object->ref).".pdf");
623  array_push($mimetype,"application/pdf");
624  }
625  */
626 
627  $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1);
628 
629  if ($mailfile)
630  {
631  // SEND
632  $result=$mailfile->sendfile();
633  if ($result)
634  {
635  $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2));
636  setEventMessages($mesg, null, 'mesgs');
637  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
638  exit;
639  }
640  else
641  {
642  $langs->load("other");
643  if ($mailfile->error)
644  {
645  $mesg='';
646  $mesg.=$langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo);
647  $mesg.='<br>'.$mailfile->error;
648  setEventMessages($mesg, null, 'errors');
649  }
650  else
651  {
652  setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings');
653  }
654  }
655  }
656  else
657  {
658  setEventMessages($mailfile->error,$mailfile->errors,'errors');
659  $action='';
660  }
661  }
662  else
663  {
664  setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings');
665  $action='';
666  }
667  }
668  else
669  {
670  setEventMessages($langs->trans("FailedtoSetToApprove"), null, 'warnings');
671  $action='';
672  }
673  }
674  else
675  {
676  setEventMessages($object->error, $object->errors, 'errors');
677  }
678 
679  if ($action == "confirm_refuse" && GETPOST('confirm', 'alpha')=="yes" && $id > 0 && $user->rights->expensereport->approve)
680  {
681  $object = new ExpenseReport($db);
682  $object->fetch($id);
683 
684  $result = $object->setDeny($user, GETPOST('detail_refuse', 'alpha'));
685 
686  if ($result > 0)
687  {
688  // Define output language
689  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
690  {
691  $outputlangs = $langs;
692  $newlang = '';
693  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
694  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
695  if (! empty($newlang)) {
696  $outputlangs = new Translate("", $conf);
697  $outputlangs->setDefaultLang($newlang);
698  }
699  $model=$object->modelpdf;
700  $ret = $object->fetch($id); // Reload to get new records
701 
702  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
703  }
704  }
705 
706  if ($result > 0)
707  {
708  // Send mail
709 
710  // TO
711  $destinataire = new User($db);
712  $destinataire->fetch($object->fk_user_author);
713  $emailTo = $destinataire->email;
714 
715  // FROM
716  $expediteur = new User($db);
717  $expediteur->fetch($object->fk_user_refuse);
718  $emailFrom = $expediteur->email;
719 
720  if ($emailFrom && $emailTo)
721  {
722  $filename=array(); $filedir=array(); $mimetype=array();
723 
724  // SUBJECT
725  $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
726  if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE;
727 
728  $subject = $societeName." - ".$langs->transnoentities("ExpenseReportRefused");
729 
730  // CONTENT
731  $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
732  $message = $langs->transnoentities("ExpenseReportRefusedMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $_POST['detail_refuse'], $link);
733 
734  // Rebuilt pdf
735  /*
736  $object->setDocModel($user,"");
737  $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs);
738 
739  if($resultPDF
740  {
741  // ATTACHMENT
742  $filename=array(); $filedir=array(); $mimetype=array();
743  array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
744  array_push($filedir, $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref)."/".dol_sanitizeFileName($object->ref).".pdf");
745  array_push($mimetype,"application/pdf");
746  }
747  */
748 
749  // PREPARE SEND
750  $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1);
751 
752  if ($mailfile)
753  {
754  // SEND
755  $result=$mailfile->sendfile();
756  if ($result)
757  {
758  $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2));
759  setEventMessages($mesg, null, 'mesgs');
760  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
761  exit;
762  }
763  else
764  {
765  $langs->load("other");
766  if ($mailfile->error)
767  {
768  $mesg='';
769  $mesg.=$langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo);
770  $mesg.='<br>'.$mailfile->error;
771  setEventMessages($mesg, null, 'errors');
772  }
773  else
774  {
775  setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings');
776  }
777  }
778  }
779  else
780  {
781  setEventMessages($mailfile->error,$mailfile->errors,'errors');
782  $action='';
783  }
784  }
785  else
786  {
787  setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings');
788  $action='';
789  }
790  }
791  else
792  {
793  setEventMessages($langs->trans("FailedtoSetToDeny"), null, 'warnings');
794  $action='';
795  }
796  }
797  else
798  {
799  setEventMessages($object->error, $object->errors, 'errors');
800  }
801 
802  //var_dump($user->id == $object->fk_user_validator);exit;
803  if ($action == "confirm_cancel" && GETPOST('confirm', 'alpha')=="yes" && $id > 0 && $user->rights->expensereport->creer)
804  {
805  if (! GETPOST('detail_cancel', 'alpha'))
806  {
807  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Comment")), null, 'errors');
808  }
809  else
810  {
811  $object = new ExpenseReport($db);
812  $object->fetch($id);
813 
814  if ($user->id == $object->fk_user_valid || $user->id == $object->fk_user_author)
815  {
816  $result = $object->set_cancel($user, GETPOST('detail_cancel', 'alpha'));
817 
818  if ($result > 0)
819  {
820  // Define output language
821  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
822  {
823  $outputlangs = $langs;
824  $newlang = '';
825  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
826  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
827  if (! empty($newlang)) {
828  $outputlangs = new Translate("", $conf);
829  $outputlangs->setDefaultLang($newlang);
830  }
831  $model=$object->modelpdf;
832  $ret = $object->fetch($id); // Reload to get new records
833 
834  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
835  }
836  }
837 
838  if ($result > 0)
839  {
840  // Send mail
841 
842  // TO
843  $destinataire = new User($db);
844  $destinataire->fetch($object->fk_user_author);
845  $emailTo = $destinataire->email;
846 
847  // FROM
848  $expediteur = new User($db);
849  $expediteur->fetch($object->fk_user_cancel);
850  $emailFrom = $expediteur->email;
851 
852  if ($emailFrom && $emailTo)
853  {
854  $filename=array(); $filedir=array(); $mimetype=array();
855 
856  // SUBJECT
857  $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
858  if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE;
859 
860  $subject = $societeName." - ".$langs->transnoentities("ExpenseReportCanceled");
861 
862  // CONTENT
863  $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
864  $message = $langs->transnoentities("ExpenseReportCanceledMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), GETPOST('detail_cancel','alpha'), $link);
865 
866  // Rebuilt pdf
867  /*
868  $object->setDocModel($user,"");
869  $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs);
870 
871  if($resultPDF
872  {
873  // ATTACHMENT
874  $filename=array(); $filedir=array(); $mimetype=array();
875  array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
876  array_push($filedir, $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref)."/".dol_sanitizeFileName($object->ref).".pdf");
877  array_push($mimetype,"application/pdf");
878  }
879  */
880 
881  // PREPARE SEND
882  $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1);
883 
884  if ($mailfile)
885  {
886  // SEND
887  $result=$mailfile->sendfile();
888  if ($result)
889  {
890  $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2));
891  setEventMessages($mesg, null, 'mesgs');
892  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
893  exit;
894  }
895  else
896  {
897  $langs->load("other");
898  if ($mailfile->error)
899  {
900  $mesg='';
901  $mesg.=$langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo);
902  $mesg.='<br>'.$mailfile->error;
903  setEventMessages($mesg, null, 'errors');
904  }
905  else
906  {
907  setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings');
908  }
909  }
910  }
911  else
912  {
913  setEventMessages($mailfile->error,$mailfile->errors,'errors');
914  $action='';
915  }
916  }
917  else
918  {
919  setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings');
920  $action='';
921  }
922  }
923  else
924  {
925  setEventMessages($langs->trans("FailedToSetToCancel"), null, 'warnings');
926  $action='';
927  }
928  }
929  else
930  {
931  setEventMessages($object->error, $object->errors, 'errors');
932  }
933  }
934  }
935 
936  if ($action == "confirm_brouillonner" && GETPOST('confirm', 'alpha')=="yes" && $id > 0 && $user->rights->expensereport->creer)
937  {
938  $object = new ExpenseReport($db);
939  $object->fetch($id);
940  if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid)
941  {
942  $result = $object->setStatut(0);
943 
944  if ($result > 0)
945  {
946  // Define output language
947  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
948  {
949  $outputlangs = $langs;
950  $newlang = '';
951  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
952  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
953  if (! empty($newlang)) {
954  $outputlangs = new Translate("", $conf);
955  $outputlangs->setDefaultLang($newlang);
956  }
957  $model=$object->modelpdf;
958  $ret = $object->fetch($id); // Reload to get new records
959 
960  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
961  }
962  }
963 
964  if ($result > 0)
965  {
966  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
967  exit;
968  }
969  else
970  {
971  setEventMessages($object->error, $object->errors, 'errors');
972  }
973  }
974  else
975  {
976  setEventMessages("NOT_AUTHOR", '', 'errors');
977  }
978  }
979 
980  if ($action == 'set_paid' && $id > 0 && $user->rights->expensereport->to_paid)
981  {
982  $object = new ExpenseReport($db);
983  $object->fetch($id);
984 
985  $result = $object->set_paid($id, $user);
986 
987  if ($result > 0)
988  {
989  // Define output language
990  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
991  {
992  $outputlangs = $langs;
993  $newlang = '';
994  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
995  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
996  if (! empty($newlang)) {
997  $outputlangs = new Translate("", $conf);
998  $outputlangs->setDefaultLang($newlang);
999  }
1000  $model=$object->modelpdf;
1001  $ret = $object->fetch($id); // Reload to get new records
1002 
1003  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1004  }
1005  }
1006 
1007  if ($result > 0)
1008  {
1009  // Send mail
1010 
1011  // TO
1012  $destinataire = new User($db);
1013  $destinataire->fetch($object->fk_user_author);
1014  $emailTo = $destinataire->email;
1015 
1016  // FROM
1017  $expediteur = new User($db);
1018  $expediteur->fetch($user->id);
1019  $emailFrom = $expediteur->email;
1020 
1021  if ($emailFrom && $emailTo)
1022  {
1023  $filename=array(); $filedir=array(); $mimetype=array();
1024 
1025  // SUBJECT
1026  $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
1027  if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE;
1028 
1029  $subject = $societeName." - ".$langs->transnoentities("ExpenseReportPaid");
1030 
1031  // CONTENT
1032  $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
1033  $message = $langs->transnoentities("ExpenseReportPaidMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link);
1034 
1035  // Generate pdf before attachment
1036  $object->setDocModel($user,"");
1037  $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs);
1038 
1039  // PREPARE SEND
1040  $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1);
1041 
1042  if ($mailfile)
1043  {
1044  // SEND
1045  $result=$mailfile->sendfile();
1046  if ($result)
1047  {
1048  $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2));
1049  setEventMessages($mesg, null, 'mesgs');
1050  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
1051  exit;
1052  }
1053  else
1054  {
1055  $langs->load("other");
1056  if ($mailfile->error)
1057  {
1058  $mesg='';
1059  $mesg.=$langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo);
1060  $mesg.='<br>'.$mailfile->error;
1061  setEventMessages($mesg, null, 'errors');
1062  }
1063  else
1064  {
1065  setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings');
1066  }
1067  }
1068  }
1069  else
1070  {
1071  setEventMessages($mailfile->error,$mailfile->errors,'errors');
1072  $action='';
1073  }
1074  }
1075  else
1076  {
1077  setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings');
1078  $action='';
1079  }
1080  }
1081  else
1082  {
1083  setEventMessages($langs->trans("FailedToSetPaid"), null, 'warnings');
1084  $action='';
1085  }
1086  }
1087  else
1088  {
1089  setEventMessages($object->error, $object->errors, 'errors');
1090  }
1091 
1092  if ($action == "addline" && $user->rights->expensereport->creer)
1093  {
1094  $error = 0;
1095 
1096  // if VAT is not used in Dolibarr, set VAT rate to 0 because VAT rate is necessary.
1097  if (empty($vatrate)) $vatrate = "0.000";
1098  $vatrate = price2num($vatrate);
1099 
1100  $value_unit=price2num(GETPOST('value_unit', 'alpha'),'MU');
1101  $fk_c_exp_tax_cat = GETPOST('fk_c_exp_tax_cat', 'int');
1102 
1103  $qty = GETPOST('qty','int');
1104  if (empty($qty)) $qty=1;
1105 
1106  if (! $fk_c_type_fees > 0)
1107  {
1108  $error++;
1109  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
1110  $action='';
1111  }
1112 
1113  if ($vatrate < 0 || $vatrate == '')
1114  {
1115  $error++;
1116  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("VAT")), null, 'errors');
1117  $action='';
1118  }
1119 
1120  /* Projects are never required. To force them, check module forceproject
1121  if ($conf->projet->enabled)
1122  {
1123  if (empty($object_ligne->fk_projet) || $object_ligne->fk_projet==-1)
1124  {
1125  $error++;
1126  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Project")), null, 'errors');
1127  }
1128  }*/
1129 
1130  // Si aucune date n'est rentrée
1131  if (empty($date) || $date=="--")
1132  {
1133  $error++;
1134  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
1135  }
1136  // Si aucun prix n'est rentré
1137  if ($value_unit==0)
1138  {
1139  $error++;
1140  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PriceUTTC")), null, 'errors');
1141  }
1142  // Warning if date out of range
1143  if ($date < $object->date_debut || $date > ($object->date_fin + (24 * 3600 - 1)))
1144  {
1145  $langs->load("errors");
1146  setEventMessages($langs->trans("WarningDateOfLineMustBeInExpenseReportRange"), null, 'warnings');
1147  }
1148 
1149  // S'il y'a eu au moins une erreur
1150  if (! $error)
1151  {
1152  $type = 0; // TODO What if service ? We should take the type product/service from the type of expense report llx_c_type_fees
1153 
1154  // Insert line
1155  $result = $object->addline($qty,$value_unit,$fk_c_type_fees,$vatrate,$date,$comments,$fk_projet,$fk_c_exp_tax_cat,$type);
1156  if ($result > 0) {
1157  $ret = $object->fetch($object->id); // Reload to get new records
1158 
1159  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1160  // Define output language
1161  $outputlangs = $langs;
1162  $newlang = GETPOST('lang_id', 'alpha');
1163  if (! empty($conf->global->MAIN_MULTILANGS) && empty($newlang))
1164  $newlang = $object->thirdparty->default_lang;
1165  if (! empty($newlang)) {
1166  $outputlangs = new Translate("", $conf);
1167  $outputlangs->setDefaultLang($newlang);
1168  }
1169 
1170  $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1171  }
1172 
1173  unset($qty);
1174  unset($value_unit);
1175  unset($vatrate);
1176  unset($comments);
1177  unset($fk_c_type_fees);
1178  unset($fk_projet);
1179 
1180  unset($date);
1181  } else {
1182  setEventMessages($object->error, $object->errors, 'errors');
1183  }
1184  }
1185 
1186  $action='';
1187  }
1188 
1189  if ($action == 'confirm_delete_line' && GETPOST("confirm", 'alpha') == "yes" && $user->rights->expensereport->creer)
1190  {
1191  $object = new ExpenseReport($db);
1192  $object->fetch($id);
1193 
1194  $object_ligne = new ExpenseReportLine($db);
1195  $object_ligne->fetch(GETPOST("rowid", 'int'));
1196  $total_ht = $object_ligne->total_ht;
1197  $total_tva = $object_ligne->total_tva;
1198 
1199  $result=$object->deleteline(GETPOST("rowid", 'int'), $user);
1200  if ($result >= 0)
1201  {
1202  if ($result > 0)
1203  {
1204  // Define output language
1205  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
1206  {
1207  $outputlangs = $langs;
1208  $newlang = '';
1209  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
1210  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
1211  if (! empty($newlang)) {
1212  $outputlangs = new Translate("", $conf);
1213  $outputlangs->setDefaultLang($newlang);
1214  }
1215  $model=$object->modelpdf;
1216  $ret = $object->fetch($id); // Reload to get new records
1217 
1218  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1219  }
1220  }
1221 
1222  $object->update_totaux_del($object_ligne->total_ht,$object_ligne->total_tva);
1223  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_GET['id']);
1224  exit;
1225  }
1226  else
1227  {
1228  setEventMessages($object->error, $object->errors, 'errors');
1229  }
1230  }
1231 
1232  if ($action == "updateline" && $user->rights->expensereport->creer)
1233  {
1234  $object = new ExpenseReport($db);
1235  $object->fetch($id);
1236 
1237  $rowid = $_POST['rowid'];
1238  $type_fees_id = GETPOST('fk_c_type_fees', 'int');
1239  $fk_c_exp_tax_cat = GETPOST('fk_c_exp_tax_cat', 'int');
1240  $projet_id = $fk_projet;
1241  $comments = GETPOST('comments', 'none');
1242  $qty = GETPOST('qty', 'int');
1243  $value_unit = price2num(GETPOST('value_unit', 'alpha'), 'MU');
1244  $vatrate = GETPOST('vatrate', 'alpha');
1245 
1246  // if VAT is not used in Dolibarr, set VAT rate to 0 because VAT rate is necessary.
1247  if (empty($vatrate)) $vatrate = "0.000";
1248  $vatrate = price2num($vatrate);
1249 
1250  if (! GETPOST('fk_c_type_fees', 'int') > 0)
1251  {
1252  $error++;
1253  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
1254  $action='';
1255  }
1256  if ((int) $vatrate < 0 || $vatrate == '')
1257  {
1258  $error++;
1259  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Vat")), null, 'errors');
1260  $action='';
1261  }
1262  // Warning if date out of range
1263  if ($date < $object->date_debut || $date > ($object->date_fin + (24 * 3600 - 1)))
1264  {
1265  $langs->load("errors");
1266  setEventMessages($langs->trans("WarningDateOfLineMustBeInExpenseReportRange"), null, 'warnings');
1267  }
1268 
1269  if (! $error)
1270  {
1271  // TODO Use update method of ExpenseReportLine
1272  $result = $object->updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $id, $fk_c_exp_tax_cat);
1273  if ($result >= 0)
1274  {
1275  if ($result > 0)
1276  {
1277  // Define output language
1278  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
1279  {
1280  $outputlangs = $langs;
1281  $newlang = '';
1282  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
1283  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
1284  if (! empty($newlang)) {
1285  $outputlangs = new Translate("", $conf);
1286  $outputlangs->setDefaultLang($newlang);
1287  }
1288  $model=$object->modelpdf;
1289  $ret = $object->fetch($id); // Reload to get new records
1290 
1291  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1292  }
1293  }
1294 
1295  $result = $object->recalculer($id);
1296 
1297  //header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
1298  //exit;
1299  }
1300  else
1301  {
1302  setEventMessages($object->error, $object->errors, 'errors');
1303  }
1304  }
1305  }
1306 
1307  // Actions when printing a doc from card
1308  include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
1309 
1310  // Actions to send emails
1311  $trigger_name='EXPENSEREPORT_SENTBYMAIL';
1312  $autocopy='MAIN_MAIL_AUTOCOPY_EXPENSEREPORT_TO';
1313  $trackid='exp'.$object->id;
1314  include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
1315 
1316  // Actions to build doc
1317  $upload_dir = $conf->expensereport->dir_output;
1318  $permissioncreate = $user->rights->expensereport->creer;
1319  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
1320 }
1321 
1322 
1323 /*
1324  * View
1325  */
1326 
1327 $title=$langs->trans("ExpenseReport") . " - " . $langs->trans("Card");
1328 $helpurl="EN:Module_Expense_Reports";
1329 llxHeader("",$title,$helpurl);
1330 
1331 $form = new Form($db);
1332 $formfile = new FormFile($db);
1333 $formproject = new FormProjets($db);
1334 $projecttmp = new Project($db);
1335 $paymentexpensereportstatic=new PaymentExpenseReport($db);
1336 $bankaccountstatic = new Account($db);
1337 
1338 // Create
1339 if ($action == 'create')
1340 {
1341  print load_fiche_titre($langs->trans("NewTrip"));
1342 
1343  print '<form action="'.$_SERVER['PHP_SELF'].'" method="post" name="create">';
1344  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1345  print '<input type="hidden" name="action" value="add">';
1346 
1347  dol_fiche_head('');
1348 
1349  print '<table class="border" width="100%">';
1350  print '<tbody>';
1351 
1352  // Date start
1353  print '<tr>';
1354  print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("DateStart").'</td>';
1355  print '<td>';
1356  print $form->selectDate($date_start?$date_start:-1, 'date_debut', 0, 0, 0, '', 1, 1);
1357  print '</td>';
1358  print '</tr>';
1359 
1360  // Date end
1361  print '<tr>';
1362  print '<td class="fieldrequired">'.$langs->trans("DateEnd").'</td>';
1363  print '<td>';
1364  print $form->selectDate($date_end?$date_end:-1, 'date_fin', 0, 0, 0, '', 1, 1);
1365  print '</td>';
1366  print '</tr>';
1367 
1368  // User for expense report
1369  print '<tr>';
1370  print '<td class="fieldrequired">'.$langs->trans("User").'</td>';
1371  print '<td>';
1372  $defaultselectuser=$user->id;
1373  if (GETPOST('fk_user_author', 'int') > 0) $defaultselectuser=GETPOST('fk_user_author', 'int');
1374  $include_users = 'hierarchyme';
1375  if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expensereport->writeall_advance)) $include_users=array();
1376  $s=$form->select_dolusers($defaultselectuser, "fk_user_author", 0, "", 0, $include_users, '', '0,'.$conf->entity);
1377  print $s;
1378  print '</td>';
1379  print '</tr>';
1380 
1381  // Approver
1382  print '<tr>';
1383  print '<td>'.$langs->trans("VALIDATOR").'</td>';
1384  print '<td>';
1385  $object = new ExpenseReport($db);
1386  $include_users = $object->fetch_users_approver_expensereport();
1387  if (empty($include_users)) print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateExpenseReport");
1388  else
1389  {
1390  $defaultselectuser=$user->fk_user; // Will work only if supervisor has permission to approve so is inside include_users
1391  if (! empty($conf->global->EXPENSEREPORT_DEFAULT_VALIDATOR)) $defaultselectuser=$conf->global->EXPENSEREPORT_DEFAULT_VALIDATOR; // Can force default approver
1392  if (GETPOST('fk_user_validator', 'int') > 0) $defaultselectuser=GETPOST('fk_user_validator', 'int');
1393  $s=$form->select_dolusers($defaultselectuser, "fk_user_validator", 1, "", ((empty($defaultselectuser) || empty($conf->global->EXPENSEREPORT_DEFAULT_VALIDATOR_UNCHANGEABLE))?0:1), $include_users);
1394  print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
1395  }
1396  print '</td>';
1397  print '</tr>';
1398 
1399  // Payment mode
1400  if (! empty($conf->global->EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION))
1401  {
1402  print '<tr>';
1403  print '<td>'.$langs->trans("ModePaiement").'</td>';
1404  print '<td>';
1405  $form->select_types_paiements(2,'fk_c_paiement');
1406  print '</td>';
1407  print '</tr>';
1408  }
1409 
1410  // Public note
1411  print '<tr>';
1412  print '<td class="tdtop">' . $langs->trans('NotePublic') . '</td>';
1413  print '<td>';
1414 
1415  $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
1416  print $doleditor->Create(1);
1417  print '</td></tr>';
1418 
1419  // Private note
1420  if (empty($user->societe_id)) {
1421  print '<tr>';
1422  print '<td class="tdtop">' . $langs->trans('NotePrivate') . '</td>';
1423  print '<td>';
1424 
1425  $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
1426  print $doleditor->Create(1);
1427  print '</td></tr>';
1428  }
1429 
1430  // Other attributes
1431  $parameters = array('colspan' => ' colspan="3"');
1432  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by
1433  print $hookmanager->resPrint;
1434  if (empty($reshook)) {
1435  print $object->showOptionals($extrafields, 'edit');
1436  }
1437 
1438  print '<tbody>';
1439  print '</table>';
1440 
1441  dol_fiche_end();
1442 
1443  print '<div class="center">';
1444  print '<input type="submit" value="'.$langs->trans("AddTrip").'" name="bouton" class="button" />';
1445  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="'.$langs->trans("Cancel").'" class="button" onclick="history.go(-1)" />';
1446  print '</div>';
1447 
1448  print '</form>';
1449 }
1450 else
1451 {
1452  if($id > 0 || $ref)
1453  {
1454  $result = $object->fetch($id, $ref);
1455 
1456  $res = $object->fetch_optionals();
1457 
1458  if ($result > 0)
1459  {
1460  if (! in_array($object->fk_user_author, $user->getAllChildIds(1)))
1461  {
1462  if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)
1463  && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance)))
1464  {
1465  print load_fiche_titre($langs->trans('TripCard'));
1466 
1467  print '<div class="tabBar">';
1468  print $langs->trans('NotUserRightToView');
1469  print '</div>';
1470 
1471  // End of page
1472  llxFooter();
1473  $db->close();
1474 
1475  exit;
1476  }
1477  }
1478 
1479  $head = expensereport_prepare_head($object);
1480 
1481  if ($action == 'edit' && ($object->fk_statut < 3 || $object->fk_statut==99))
1482  {
1483  print "<form name='update' action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">\n";
1484  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1485  print '<input type="hidden" name="id" value="'.$id.'">';
1486 
1487  dol_fiche_head($head, 'card', $langs->trans("ExpenseReport"), 0, 'trip');
1488 
1489  if($object->fk_statut==99)
1490  {
1491  print '<input type="hidden" name="action" value="updateFromRefuse">';
1492  }
1493  else
1494  {
1495  print '<input type="hidden" name="action" value="update">';
1496  }
1497 
1498  $linkback = '<a href="'.DOL_URL_ROOT.'/expensereport/list.php?restore_lastsearch_values=1'.(! empty($socid)?'&socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
1499 
1500  print '<table class="border" style="width:100%;">';
1501 
1502  print '<tr>';
1503  print '<td>'.$langs->trans("User").'</td>';
1504  print '<td>';
1505  $userfee=new User($db);
1506  if ($object->fk_user_author > 0)
1507  {
1508  $userfee->fetch($object->fk_user_author);
1509  print $userfee->getNomUrl(-1);
1510  }
1511  print '</td></tr>';
1512 
1513  // Ref
1514  print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td>';
1515  print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '');
1516  print '</td></tr>';
1517 
1518  print '<tr>';
1519  print '<td>'.$langs->trans("DateStart").'</td>';
1520  print '<td>';
1521  print $form->selectDate($object->date_debut, 'date_debut');
1522  print '</td>';
1523  print '</tr>';
1524  print '<tr>';
1525  print '<td>'.$langs->trans("DateEnd").'</td>';
1526  print '<td>';
1527  print $form->selectDate($object->date_fin, 'date_fin');
1528  print '</td>';
1529  print '</tr>';
1530 
1531  if (! empty($conf->global->EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION))
1532  {
1533  print '<tr>';
1534  print '<td>'.$langs->trans("ModePaiement").'</td>';
1535  print '<td>';
1536  $form->select_types_paiements($object->fk_c_paiement,'fk_c_paiement');
1537  print '</td>';
1538  print '</tr>';
1539  }
1540 
1541  if($object->fk_statut<3)
1542  {
1543  print '<tr>';
1544  print '<td>'.$langs->trans("VALIDATOR").'</td>'; // Approbator
1545  print '<td>';
1546  $include_users = $object->fetch_users_approver_expensereport();
1547  $s=$form->select_dolusers($object->fk_user_validator,"fk_user_validator",1,"",0,$include_users);
1548  print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
1549  print '</td>';
1550  print '</tr>';
1551  }
1552  else
1553  {
1554  print '<tr>';
1555  print '<td>'.$langs->trans("VALIDOR").'</td>';
1556  print '<td>';
1557  $userfee=new User($db);
1558  $userfee->fetch($object->fk_user_valid);
1559  print $userfee->getNomUrl(-1);
1560  print '</td></tr>';
1561  }
1562 
1563  if ($object->fk_statut==6)
1564  {
1565  print '<tr>';
1566  print '<td>'.$langs->trans("AUTHORPAIEMENT").'</td>';
1567  print '<td>';
1568  $userfee=new User($db);
1569  $userfee->fetch($user->id);
1570  print $userfee->getNomUrl(-1);
1571  print '</td></tr>';
1572  }
1573 
1574  // Other attributes
1575  //$cols = 3;
1576  //include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_edit.tpl.php';
1577 
1578  print '</table>';
1579 
1580  dol_fiche_end();
1581 
1582  print '<div class="center">';
1583  print '<input type="submit" value="'.$langs->trans("Modify").'" name="bouton" class="button">';
1584  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="'.$langs->trans("Cancel").'" class="button" onclick="history.go(-1)" />';
1585  print '</div>';
1586 
1587  print '</form>';
1588  }
1589  else
1590  {
1591  dol_fiche_head($head, 'card', $langs->trans("ExpenseReport"), -1, 'trip');
1592 
1593  // Clone confirmation
1594  if ($action == 'clone') {
1595  // Create an array for form
1596  $criteriaforfilter='hierarchyme';
1597  if (! empty($user->rights->expensereport->readall)) $criteriaforfilter='';
1598  $formquestion = array(
1599  'text' => '',
1600  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))
1601  );
1602  // Paiement incomplet. On demande si motif = escompte ou autre
1603  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('CloneExpenseReport'), $langs->trans('ConfirmCloneExpenseReport', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
1604  }
1605 
1606  if ($action == 'save')
1607  {
1608  $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("SaveTrip"),$langs->trans("ConfirmSaveTrip"),"confirm_validate","","",1);
1609  }
1610 
1611  if ($action == 'save_from_refuse')
1612  {
1613  $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("SaveTrip"),$langs->trans("ConfirmSaveTrip"),"confirm_save_from_refuse","","",1);
1614  }
1615 
1616  if ($action == 'delete')
1617  {
1618  $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("DeleteTrip"),$langs->trans("ConfirmDeleteTrip"),"confirm_delete","","",1);
1619  }
1620 
1621  if ($action == 'validate')
1622  {
1623  $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("ValideTrip"),$langs->trans("ConfirmValideTrip"),"confirm_approve","","",1);
1624  }
1625 
1626  if ($action == 'paid')
1627  {
1628  $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("PaidTrip"),$langs->trans("ConfirmPaidTrip"),"confirm_paid","","",1);
1629  }
1630 
1631  if ($action == 'cancel')
1632  {
1633  $array_input = array('text'=>$langs->trans("ConfirmCancelTrip"), array('type'=>"text",'label'=>'<strong>'.$langs->trans("Comment").'</strong>','name'=>"detail_cancel",'size'=>"50",'value'=>""));
1634  $formconfirm=$form->formconfirm($_SEVER["PHP_SELF"]."?id=".$id,$langs->trans("Cancel"),"","confirm_cancel",$array_input,"",1);
1635  }
1636 
1637  if ($action == 'brouillonner')
1638  {
1639  $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("BrouillonnerTrip"),$langs->trans("ConfirmBrouillonnerTrip"),"confirm_brouillonner","","",1);
1640  }
1641 
1642  if ($action == 'refuse') // Deny
1643  {
1644  $array_input = array('text'=>$langs->trans("ConfirmRefuseTrip"), array('type'=>"text",'label'=>$langs->trans("Comment"),'name'=>"detail_refuse",'size'=>"50",'value'=>""));
1645  $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("Deny"),'',"confirm_refuse",$array_input,"yes",1);
1646  }
1647 
1648  if ($action == 'delete_line')
1649  {
1650  $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id."&rowid=".GETPOST('rowid','int'),$langs->trans("DeleteLine"),$langs->trans("ConfirmDeleteLine"),"confirm_delete_line",'','yes',1);
1651  }
1652 
1653  // Print form confirm
1654  print $formconfirm;
1655 
1656  // Expense report card
1657  $linkback = '<a href="'.DOL_URL_ROOT.'/expensereport/list.php?restore_lastsearch_values=1'.(! empty($socid)?'&socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
1658 
1659  $morehtmlref='<div class="refidno">';
1660  /*
1661  // Ref customer
1662  $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->commande->creer, 'string', '', 0, 1);
1663  $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->commande->creer, 'string', '', null, null, '', 1);
1664  // Thirdparty
1665  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
1666  // Project
1667  if (! empty($conf->projet->enabled))
1668  {
1669  $langs->load("projects");
1670  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
1671  if ($user->rights->commande->creer)
1672  {
1673  if ($action != 'classify')
1674  $morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
1675  if ($action == 'classify') {
1676  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
1677  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
1678  $morehtmlref.='<input type="hidden" name="action" value="classin">';
1679  $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1680  $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
1681  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
1682  $morehtmlref.='</form>';
1683  } else {
1684  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
1685  }
1686  } else {
1687  if (! empty($object->fk_project)) {
1688  $proj = new Project($db);
1689  $proj->fetch($object->fk_project);
1690  $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
1691  $morehtmlref.=$proj->ref;
1692  $morehtmlref.='</a>';
1693  } else {
1694  $morehtmlref.='';
1695  }
1696  }
1697  }*/
1698  $morehtmlref.='</div>';
1699 
1700  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
1701 
1702  print '<div class="fichecenter">';
1703  print '<div class="fichehalfleft">';
1704  print '<div class="underbanner clearboth"></div>';
1705 
1706  print '<table class="border centpercent">';
1707 
1708  // Author
1709  print '<tr>';
1710  print '<td class="titlefield">'.$langs->trans("User").'</td>';
1711  print '<td>';
1712  if ($object->fk_user_author > 0)
1713  {
1714  $userauthor=new User($db);
1715  $result=$userauthor->fetch($object->fk_user_author);
1716  if ($result < 0) dol_print_error('',$userauthor->error);
1717  elseif ($result > 0) print $userauthor->getNomUrl(-1);
1718  }
1719  print '</td></tr>';
1720 
1721  print '<tr>';
1722  print '<td class="titlefield">'.$langs->trans("Period").'</td>';
1723  print '<td>';
1724  print get_date_range($object->date_debut,$object->date_fin,'day',$langs,0);
1725  print '</td>';
1726  print '</tr>';
1727  if (! empty($conf->global->EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION))
1728  {
1729  print '<tr>';
1730  print '<td>'.$langs->trans("ModePaiement").'</td>';
1731  print '<td>'.$object->libelle_paiement.'</td>';
1732  print '</tr>';
1733  }
1734 
1735  // Validation date
1736  print '<tr>';
1737  print '<td>'.$langs->trans("DATE_SAVE").'</td>';
1738  print '<td>'.dol_print_date($object->date_valid,'dayhour');
1739  if ($object->status == 2 && $object->hasDelay('toapprove')) print ' '.img_warning($langs->trans("Late"));
1740  if ($object->status == 5 && $object->hasDelay('topay')) print ' '.img_warning($langs->trans("Late"));
1741  print '</td></tr>';
1742  print '</tr>';
1743 
1744  // User to inform for approval
1745  if ($object->fk_statut < 3) // informed
1746  {
1747  print '<tr>';
1748  print '<td>'.$langs->trans("VALIDATOR").'</td>'; // approver
1749  print '<td>';
1750  if ($object->fk_user_validator > 0)
1751  {
1752  $userfee=new User($db);
1753  $result = $userfee->fetch($object->fk_user_validator);
1754  if ($result > 0) print $userfee->getNomUrl(-1);
1755  if (empty($userfee->email) || ! isValidEmail($userfee->email))
1756  {
1757  $langs->load("errors");
1758  print img_warning($langs->trans("ErrorBadEMail", $userfee->email));
1759  }
1760  }
1761  print '</td></tr>';
1762  }
1763  elseif($object->fk_statut == 4)
1764  {
1765  print '<tr>';
1766  print '<td>'.$langs->trans("CANCEL_USER").'</span></td>';
1767  print '<td>';
1768  if ($object->fk_user_cancel > 0)
1769  {
1770  $userfee=new User($db);
1771  $result = $userfee->fetch($object->fk_user_cancel);
1772  if ($result > 0) print $userfee->getNomUrl(-1);
1773  }
1774  print '</td></tr>';
1775 
1776  print '<tr>';
1777  print '<td>'.$langs->trans("MOTIF_CANCEL").'</td>';
1778  print '<td>'.$object->detail_cancel.'</td></tr>';
1779  print '</tr>';
1780  print '<tr>';
1781  print '<td>'.$langs->trans("DATE_CANCEL").'</td>';
1782  print '<td>'.dol_print_date($object->date_cancel,'dayhour').'</td></tr>';
1783  print '</tr>';
1784  }
1785  else
1786  {
1787  print '<tr>';
1788  print '<td>'.$langs->trans("ApprovedBy").'</td>';
1789  print '<td>';
1790  if ($object->fk_user_approve > 0)
1791  {
1792  $userapp=new User($db);
1793  $result = $userapp->fetch($object->fk_user_approve);
1794  if ($result > 0) print $userapp->getNomUrl(-1);
1795  }
1796  print '</td></tr>';
1797 
1798  print '<tr>';
1799  print '<td>'.$langs->trans("DateApprove").'</td>';
1800  print '<td>'.dol_print_date($object->date_approve,'dayhour').'</td></tr>';
1801  print '</tr>';
1802  }
1803 
1804  if ($object->fk_statut==99 || !empty($object->detail_refuse))
1805  {
1806  print '<tr>';
1807  print '<td>'.$langs->trans("REFUSEUR").'</td>';
1808  print '<td>';
1809  $userfee=new User($db);
1810  $result = $userfee->fetch($object->fk_user_refuse);
1811  if ($result > 0) print $userfee->getNomUrl(-1);
1812  print '</td></tr>';
1813 
1814  print '<tr>';
1815  print '<td>'.$langs->trans("DATE_REFUS").'</td>';
1816  print '<td>'.dol_print_date($object->date_refuse,'dayhour');
1817  if ($object->detail_refuse) print ' - '.$object->detail_refuse;
1818  print '</td>';
1819  print '</tr>';
1820  }
1821 
1822  if($object->fk_statut==6)
1823  {
1824  /* TODO this fields are not yet filled
1825  print '<tr>';
1826  print '<td>'.$langs->trans("AUTHORPAIEMENT").'</td>';
1827  print '<td>';
1828  $userfee=new User($db);
1829  $userfee->fetch($object->fk_user_paid);
1830  print $userfee->getNomUrl(-1);
1831  print '</td></tr>';
1832  print '<tr>';
1833  print '<td>'.$langs->trans("DATE_PAIEMENT").'</td>';
1834  print '<td>'.$object->date_paiement.'</td></tr>';
1835  print '</tr>';
1836  */
1837  }
1838 
1839  // Other attributes
1840  $cols = 2;
1841  include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
1842 
1843  print '</table>';
1844 
1845  print '</div>';
1846  print '<div class="fichehalfright">';
1847  print '<div class="ficheaddleft">';
1848  print '<div class="underbanner clearboth"></div>';
1849 
1850  print '<table class="border centpercent">';
1851 
1852  // Amount
1853  print '<tr>';
1854  print '<td class="titlefieldmiddle">'.$langs->trans("AmountHT").'</td>';
1855  print '<td class="nowrap amountcard">'.price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency).'</td>';
1856  $rowspan = 5;
1857  if ($object->fk_statut < 3) $rowspan++;
1858  elseif($object->fk_statut == 4) $rowspan+=2;
1859  else $rowspan+=2;
1860  if ($object->fk_statut==99 || !empty($object->detail_refuse)) $rowspan+=2;
1861  if($object->fk_statut==6) $rowspan+=2;
1862  print "</td>";
1863  print '</tr>';
1864 
1865  print '<tr>';
1866  print '<td>'.$langs->trans("AmountVAT").'</td>';
1867  print '<td class="nowrap amountcard">'.price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency).'</td>';
1868  print '</tr>';
1869 
1870  print '<tr>';
1871  print '<td>'.$langs->trans("AmountTTC").'</td>';
1872  print '<td class="nowrap amountcard">'.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency).'</td>';
1873  print '</tr>';
1874 
1875  // List of payments already done
1876  $nbcols = 3;
1877  if (! empty($conf->banque->enabled)) {
1878  $nbrows ++;
1879  $nbcols ++;
1880  }
1881 
1882  print '<table class="noborder paymenttable" width="100%">';
1883 
1884  print '<tr class="liste_titre">';
1885  print '<td class="liste_titre">' . $langs->trans('Payments') . '</td>';
1886  print '<td class="liste_titre">' . $langs->trans('Date') . '</td>';
1887  print '<td class="liste_titre">' . $langs->trans('Type') . '</td>';
1888  if (! empty($conf->banque->enabled)) {
1889  print '<td class="liste_titre" align="right">' . $langs->trans('BankAccount') . '</td>';
1890  }
1891  print '<td class="liste_titre" align="right">' . $langs->trans('Amount') . '</td>';
1892  print '<td class="liste_titre" width="18">&nbsp;</td>';
1893  print '</tr>';
1894 
1895  // Payments already done (from payment on this expensereport)
1896  $sql = "SELECT p.rowid, p.num_payment, p.datep as dp, p.amount, p.fk_bank,";
1897  $sql.= "c.code as p_code, c.libelle as payment_type,";
1898  $sql.= "ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal";
1899  $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as e, ".MAIN_DB_PREFIX."payment_expensereport as p";
1900  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepayment = c.id";
1901  $sql.= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank as b ON p.fk_bank = b.rowid';
1902  $sql.= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank_account as ba ON b.fk_account = ba.rowid';
1903  $sql.= " WHERE e.rowid = '".$id."'";
1904  $sql.= " AND p.fk_expensereport = e.rowid";
1905  $sql.= ' AND e.entity IN ('.getEntity('expensereport').')';
1906  $sql.= " ORDER BY dp";
1907 
1908  $resql = $db->query($sql);
1909  if ($resql)
1910  {
1911  $num = $db->num_rows($resql);
1912  $i = 0; $total = 0;
1913  while ($i < $num)
1914  {
1915  $objp = $db->fetch_object($resql);
1916 
1917  $paymentexpensereportstatic->id = $objp->rowid;
1918  $paymentexpensereportstatic->datepaye = $db->jdate($objp->dp);
1919  $paymentexpensereportstatic->ref = $objp->rowid;
1920  $paymentexpensereportstatic->num_paiement = $objp->num_paiement;
1921  $paymentexpensereportstatic->payment_code = $objp->payment_code;
1922 
1923  print '<tr class="oddseven">';
1924  print '<td>';
1925  print $paymentexpensereportstatic->getNomUrl(1);
1926  print '</td>';
1927  print '<td>'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
1928  $labeltype=$langs->trans("PaymentType".$objp->p_code)!=("PaymentType".$objp->p_code)?$langs->trans("PaymentType".$objp->p_code):$objp->payment_type;
1929  print "<td>".$labeltype.' '.$objp->num_payment."</td>\n";
1930  if (! empty($conf->banque->enabled))
1931  {
1932  $bankaccountstatic->id = $objp->baid;
1933  $bankaccountstatic->ref = $objp->baref;
1934  $bankaccountstatic->label = $objp->baref;
1935  $bankaccountstatic->number = $objp->banumber;
1936 
1937  if (! empty($conf->accounting->enabled)) {
1938  $bankaccountstatic->account_number = $objp->account_number;
1939 
1940  $accountingjournal = new AccountingJournal($db);
1941  $accountingjournal->fetch($objp->fk_accountancy_journal);
1942  $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0,1,1,'',1);
1943  }
1944 
1945  print '<td align="right">';
1946  if ($bankaccountstatic->id)
1947  print $bankaccountstatic->getNomUrl(1, 'transactions');
1948  print '</td>';
1949  }
1950  print '<td align="right">'.price($objp->amount)."</td>";
1951  print '<td></td>';
1952  print "</tr>";
1953  $totalpaid += $objp->amount;
1954  $i++;
1955  }
1956  $totalpaid = price2num($totalpaid); // Round $totalpaid to fix floating problem after addition into loop
1957 
1958  $remaintopay = price2num($object->total_ttc - $totalpaid);
1959  $resteapayeraffiche = $remaintopay;
1960 
1961  $cssforamountpaymentcomplete = 'amountpaymentcomplete';
1962 
1963  if ($object->status == ExpenseReport::STATUS_REFUSED)
1964  {
1965  $cssforamountpaymentcomplete = 'amountpaymentneutral';
1966  $resteapayeraffiche = 0;
1967  }
1968  elseif ($object->paid == 0)
1969  {
1970  $cssforamountpaymentcomplete = 'amountpaymentneutral';
1971  }
1972  print '<tr><td colspan="' . $nbcols . '" align="right">'.$langs->trans("AlreadyPaid").':</td><td align="right">'.price($totalpaid).'</td><td></td></tr>';
1973  print '<tr><td colspan="' . $nbcols . '" align="right">'.$langs->trans("AmountExpected").':</td><td align="right">'.price($object->total_ttc).'</td><td></td></tr>';
1974 
1975  print '<tr><td colspan="' . $nbcols . '" align="right">'.$langs->trans("RemainderToPay").':</td>';
1976  print '<td align="right"'.($resteapayeraffiche?' class="amountremaintopay"':(' class="'.$cssforamountpaymentcomplete.'"')).'>'.price($resteapayeraffiche).'</td><td></td></tr>';
1977 
1978  $db->free($resql);
1979  }
1980  else
1981  {
1982  dol_print_error($db);
1983  }
1984  print "</table>";
1985 
1986  print '</div>';
1987  print '</div>';
1988  print '</div>';
1989 
1990  print '<div class="clearboth"></div><br>';
1991 
1992  print '<div style="clear: both;"></div>';
1993 
1994  $actiontouse='updateline';
1995  if (($object->fk_statut==0 || $object->fk_statut==99) && $action != 'editline') $actiontouse='addline';
1996 
1997  print '<form name="expensereport" action="'.$_SERVER["PHP_SELF"].'" method="post">';
1998  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1999  print '<input type="hidden" name="action" value="'.$actiontouse.'">';
2000  print '<input type="hidden" name="id" value="'.$object->id.'">';
2001  print '<input type="hidden" name="fk_expensereport" value="'.$object->id.'" />';
2002 
2003  print '<div class="div-table-responsive-no-min">';
2004  print '<table id="tablelines" class="noborder" width="100%">';
2005 
2006  if (!empty($object->lines))
2007  {
2008  $i = 0;$total = 0;
2009 
2010  print '<tr class="liste_titre">';
2011  print '<td style="text-align:center;">'.$langs->trans('LineNb').'</td>';
2012  //print '<td style="text-align:center;">'.$langs->trans('Piece').'</td>';
2013  print '<td style="text-align:center;">'.$langs->trans('Date').'</td>';
2014  if (! empty($conf->projet->enabled)) print '<td class="minwidth100imp">'.$langs->trans('Project').'</td>';
2015  if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) print '<td>'.$langs->trans('CarCategory').'</td>';
2016  print '<td style="text-align:center;">'.$langs->trans('Type').'</td>';
2017  print '<td style="text-align:left;">'.$langs->trans('Description').'</td>';
2018  print '<td style="text-align:right;">'.$langs->trans('VAT').'</td>';
2019  print '<td style="text-align:right;">'.$langs->trans('PriceUTTC').'</td>';
2020  print '<td style="text-align:right;">'.$langs->trans('Qty').'</td>';
2021  if ($action != 'editline')
2022  {
2023  print '<td style="text-align:right;">'.$langs->trans('AmountHT').'</td>';
2024  print '<td style="text-align:right;">'.$langs->trans('AmountTTC').'</td>';
2025  }
2026  // Ajout des boutons de modification/suppression
2027  if (($object->fk_statut < 2 || $object->fk_statut == 99) && $user->rights->expensereport->creer)
2028  {
2029  print '<td style="text-align:right;"></td>';
2030  }
2031  print '</tr>';
2032 
2033  foreach ($object->lines as &$line)
2034  {
2035  $numline = $i + 1;
2036 
2037  if ($action != 'editline' || $line->rowid != GETPOST('rowid', 'int'))
2038  {
2039  print '<tr class="oddeven">';
2040 
2041  print '<td style="text-align:center;">';
2042  print $numline;
2043  print '</td>';
2044 
2045  /*print '<td style="text-align:center;">';
2046  print img_picto($langs->trans("Document"), "object_generic");
2047  print ' <span>'.$piece_comptable.'</span>';
2048  print '</td>';*/
2049 
2050  print '<td style="text-align:center;">'.dol_print_date($db->jdate($line->date), 'day').'</td>';
2051  if (! empty($conf->projet->enabled))
2052  {
2053  print '<td>';
2054  if ($line->fk_projet > 0)
2055  {
2056  $projecttmp->id=$line->fk_projet;
2057  $projecttmp->ref=$line->projet_ref;
2058  print $projecttmp->getNomUrl(1);
2059  }
2060  print '</td>';
2061  }
2062  if (!empty($conf->global->MAIN_USE_EXPENSE_IK))
2063  {
2064  print '<td class="fk_c_exp_tax_cat">';
2065  print dol_getIdFromCode($db, $line->fk_c_exp_tax_cat, 'c_exp_tax_cat', 'rowid', 'label');
2066  print '</td>';
2067  }
2068  print '<td class="center">';
2069  $labeltype = ($langs->trans(($line->type_fees_code)) == $line->type_fees_code ? $line->type_fees_libelle : $langs->trans($line->type_fees_code));
2070  print $labeltype;
2071  print '</td>';
2072  print '<td style="text-align:left;">'.dol_escape_htmltag($line->comments).'</td>';
2073  print '<td style="text-align:right;">'.vatrate($line->vatrate,true).'</td>';
2074  print '<td style="text-align:right;">'.price($line->value_unit).'</td>';
2075  print '<td style="text-align:right;">'.dol_escape_htmltag($line->qty).'</td>';
2076 
2077  if ($action != 'editline')
2078  {
2079  print '<td style="text-align:right;">'.price($line->total_ht).'</td>';
2080  print '<td style="text-align:right;">'.price($line->total_ttc).'</td>';
2081  }
2082 
2083  // Ajout des boutons de modification/suppression
2084  if (($object->fk_statut < 2 || $object->fk_statut == 99) && $user->rights->expensereport->creer)
2085  {
2086  print '<td style="text-align:right;" class="nowrap">';
2087 
2088  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=editline&amp;rowid='.$line->rowid.'#'.$line->rowid.'">';
2089  print img_edit();
2090  print '</a> &nbsp; ';
2091  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete_line&amp;rowid='.$line->rowid.'">';
2092  print img_delete();
2093  print '</a>';
2094 
2095  print '</td>';
2096  }
2097 
2098  print '</tr>';
2099  }
2100 
2101  if ($action == 'editline' && $line->rowid == GETPOST('rowid', 'int'))
2102  {
2103  print '<tr class="oddeven">';
2104 
2105  print '<td></td>';
2106 
2107  // Select date
2108  print '<td class="center">';
2109  print $form->selectDate($line->date,'date');
2110  print '</td>';
2111 
2112  // Select project
2113  if (! empty($conf->projet->enabled))
2114  {
2115  print '<td>';
2116  $formproject->select_projects(-1, $line->fk_projet,'fk_projet', 0, 0, 1, 1, 0, 0, 0, '', 0, 0, 'maxwidth300');
2117  print '</td>';
2118  }
2119 
2120  if (!empty($conf->global->MAIN_USE_EXPENSE_IK))
2121  {
2122  print '<td class="fk_c_exp_tax_cat">';
2123  $params = array('fk_expense' => $object->id, 'fk_expense_det' => $line->rowid, 'date' => $line->dates);
2124  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);
2125  print '</td>';
2126  }
2127 
2128  // Select type
2129  print '<td class="center">';
2130  select_type_fees_id($line->fk_c_type_fees,'fk_c_type_fees');
2131  print '</td>';
2132 
2133  // Add comments
2134  print '<td>';
2135  print '<textarea name="comments" class="flat_ndf centpercent">'.dol_escape_htmltag($line->comments).'</textarea>';
2136  print '</td>';
2137 
2138  // VAT
2139  print '<td style="text-align:right;">';
2140  print $form->load_tva('vatrate', (isset($_POST["vatrate"])?$_POST["vatrate"]:$line->vatrate), $mysoc, '');
2141  print '</td>';
2142 
2143  // Unit price
2144  print '<td style="text-align:right;">';
2145  print '<input type="text" min="0" class="maxwidth100" name="value_unit" value="'.dol_escape_htmltag($line->value_unit).'" />';
2146  print '</td>';
2147 
2148  // Quantity
2149  print '<td style="text-align:right;">';
2150  print '<input type="number" min="0" class="maxwidth100" name="qty" value="'.dol_escape_htmltag($line->qty).'" />';
2151  print '</td>';
2152 
2153  if ($action != 'editline')
2154  {
2155  print '<td style="text-align:right;">'.$langs->trans('AmountHT').'</td>';
2156  print '<td style="text-align:right;">'.$langs->trans('AmountTTC').'</td>';
2157  }
2158 
2159  print '<td style="text-align:center;">';
2160  print '<input type="hidden" name="rowid" value="'.$line->rowid.'">';
2161  print '<input type="submit" class="button" name="save" value="'.$langs->trans('Save').'">';
2162  print '<br><input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'">';
2163  print '</td>';
2164  }
2165 
2166  $i++;
2167  }
2168  }
2169 
2170  // Add a line
2171  if (($object->fk_statut==0 || $object->fk_statut==99) && $action != 'editline' && $user->rights->expensereport->creer)
2172  {
2173  print '<tr class="liste_titre">';
2174  print '<td></td>';
2175  print '<td align="center">'.$langs->trans('Date').'</td>';
2176  if (! empty($conf->projet->enabled)) print '<td class="minwidth100imp">'.$langs->trans('Project').'</td>';
2177  if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) print '<td>'.$langs->trans('CarCategory').'</td>';
2178  print '<td align="center">'.$langs->trans('Type').'</td>';
2179  print '<td>'.$langs->trans('Description').'</td>';
2180  print '<td align="right">'.$langs->trans('VAT').'</td>';
2181  print '<td align="right">'.$langs->trans('PriceUTTC').'</td>';
2182  print '<td align="right">'.$langs->trans('Qty').'</td>';
2183  print '<td colspan="3"></td>';
2184  print '</tr>';
2185 
2186  print '<tr class="oddeven">';
2187 
2188  print '<td></td>';
2189 
2190  // Select date
2191  print '<td align="center">';
2192  print $form->selectDate($date?$date:-1, 'date');
2193  print '</td>';
2194 
2195  // Select project
2196  if (! empty($conf->projet->enabled))
2197  {
2198  print '<td>';
2199  $formproject->select_projects(-1, $fk_projet, 'fk_projet', 0, 0, 1, 1, 0, 0, 0, '', 0, 0, 'maxwidth300');
2200  print '</td>';
2201  }
2202 
2203  if (!empty($conf->global->MAIN_USE_EXPENSE_IK))
2204  {
2205  print '<td class="fk_c_exp_tax_cat">';
2206  $params = array('fk_expense' => $object->id);
2207  print $form->selectExpenseCategories('', 'fk_c_exp_tax_cat', 1, array(), 'fk_c_type_fees', $userauthor->default_c_exp_tax_cat, $params);
2208  print '</td>';
2209  }
2210 
2211  // Select type
2212  print '<td align="center">';
2213  select_type_fees_id($fk_c_type_fees,'fk_c_type_fees',1);
2214  print '</td>';
2215 
2216  // Add comments
2217  print '<td>';
2218  print '<textarea class="flat_ndf centpercent" name="comments">'.dol_escape_htmltag($comments).'</textarea>';
2219  print '</td>';
2220 
2221  // Select VAT
2222  print '<td align="right">';
2223  $defaultvat=-1;
2224  if (! empty($conf->global->EXPENSEREPORT_NO_DEFAULT_VAT)) $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS = 'none';
2225  print $form->load_tva('vatrate', ($vatrate!=''?$vatrate:$defaultvat), $mysoc, '', 0, 0, '', false, 1);
2226  print '</td>';
2227 
2228  // Unit price
2229  print '<td align="right">';
2230  print '<input type="text" class="right maxwidth50" name="value_unit" value="'.dol_escape_htmltag($value_unit).'">';
2231  print '</td>';
2232 
2233  // Quantity
2234  print '<td align="right">';
2235  print '<input type="text" min="0" class="right maxwidth50" name="qty" value="'.dol_escape_htmltag($qty?$qty:1).'">'; // We must be able to enter decimal qty
2236  print '</td>';
2237 
2238  if ($action != 'editline')
2239  {
2240  print '<td align="right"></td>';
2241  print '<td align="right"></td>';
2242  }
2243 
2244  print '<td align="center"><input type="submit" value="'.$langs->trans("Add").'" name="bouton" class="button"></td>';
2245 
2246  print '</tr>';
2247  } // Fin si c'est payé/validé
2248 
2249  print '</table>';
2250  print '</div>';
2251 
2252  print '</form>';
2253 
2254  dol_fiche_end();
2255  } // end edit or not edit
2256  } // end of if result
2257  else
2258  {
2259  dol_print_error($db);
2260  }
2261  } //fin si id > 0
2262 }
2263 
2264 /*
2265  * Barre d'actions
2266  */
2267 
2268 print '<div class="tabsAction">';
2269 
2270 if ($action != 'create' && $action != 'edit')
2271 {
2272  $object = new ExpenseReport($db);
2273  $object->fetch($id, $ref);
2274 
2275  // Send
2276  if ($object->fk_statut > ExpenseReport::STATUS_DRAFT) {
2277  //if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->expensereport->expensereport_advance->send)) {
2278  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>';
2279  //} else
2280  // print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">' . $langs->trans('SendMail') . '</a></div>';
2281  }
2282 
2283 
2284  /* Si l'état est "Brouillon"
2285  * ET user à droit "creer/supprimer"
2286  * ET fk_user_author == user courant
2287  * Afficher : "Enregistrer" / "Modifier" / "Supprimer"
2288  */
2289  if ($user->rights->expensereport->creer && $object->fk_statut==0)
2290  {
2291  if (in_array($object->fk_user_author, $user->getAllChildIds(1)) || !empty($user->rights->expensereport->writeall_advance))
2292  {
2293  // Modify
2294  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&id='.$object->id.'">'.$langs->trans('Modify').'</a></div>';
2295 
2296  // Validate
2297  if (count($object->lines) > 0)
2298  {
2299  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=save&id='.$object->id.'">'.$langs->trans('ValidateAndSubmit').'</a></div>';
2300  }
2301  }
2302  }
2303 
2304  /* Si l'état est "Refusée"
2305  * ET user à droit "creer/supprimer"
2306  * ET fk_user_author == user courant
2307  * Afficher : "Enregistrer" / "Modifier" / "Supprimer"
2308  */
2309  if($user->rights->expensereport->creer && $object->fk_statut==99)
2310  {
2311  if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid)
2312  {
2313  // Modify
2314  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&id='.$object->id.'">'.$langs->trans('Modify').'</a></div>';
2315 
2316  // Brouillonner (le statut refusée est identique à brouillon)
2317  //print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=brouillonner&id='.$id.'">'.$langs->trans('BROUILLONNER').'</a>';
2318  // Enregistrer depuis le statut "Refusée"
2319  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=save_from_refuse&id='.$object->id.'">'.$langs->trans('ValidateAndSubmit').'</a></div>';
2320  }
2321  }
2322 
2323  if ($user->rights->expensereport->to_paid && $object->fk_statut==5)
2324  {
2325  if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid)
2326  {
2327  // Brouillonner
2328  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=brouillonner&id='.$object->id.'">'.$langs->trans('SetToDraft').'</a></div>';
2329  }
2330  }
2331 
2332  /* Si l'état est "En attente d'approbation"
2333  * ET user à droit de "approve"
2334  * ET fk_user_validator == user courant
2335  * Afficher : "Valider" / "Refuser" / "Supprimer"
2336  */
2337  if ($object->fk_statut == 2)
2338  {
2339  if (in_array($object->fk_user_author, $user->getAllChildIds(1)))
2340  {
2341  // Brouillonner
2342  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=brouillonner&id='.$object->id.'">'.$langs->trans('SetToDraft').'</a></div>';
2343  }
2344  }
2345 
2346  if ($user->rights->expensereport->approve && $object->fk_statut == 2)
2347  {
2348  //if($object->fk_user_validator==$user->id)
2349  //{
2350  // Validate
2351  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=validate&id='.$object->id.'">'.$langs->trans('Approve').'</a></div>';
2352  // Deny
2353  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=refuse&id='.$object->id.'">'.$langs->trans('Deny').'</a></div>';
2354  //}
2355 
2356  if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid)
2357  {
2358  // Cancel
2359  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=cancel&id='.$object->id.'">'.$langs->trans('Cancel').'</a></div>';
2360  }
2361  }
2362 
2363 
2364  // If status is Appoved
2365  // --------------------
2366 
2367  if ($user->rights->expensereport->approve && $object->fk_statut == 5)
2368  {
2369  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=refuse&id='.$object->id.'">'.$langs->trans('Deny').'</a></div>';
2370  }
2371 
2372  // If bank module is used
2373  if ($user->rights->expensereport->to_paid && ! empty($conf->banque->enabled) && $object->fk_statut == 5)
2374  {
2375  // Pay
2376  if ($remaintopay == 0)
2377  {
2378  print '<div class="inline-block divButAction"><span class="butActionRefused" title="' . $langs->trans("DisabledBecauseRemainderToPayIsZero") . '">' . $langs->trans('DoPayment') . '</span></div>';
2379  }
2380  else
2381  {
2382  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>';
2383  }
2384  }
2385 
2386  // If bank module is not used
2387  if (($user->rights->expensereport->to_paid || empty($conf->banque->enabled)) && $object->fk_statut == 5)
2388  {
2389  //if ((round($remaintopay) == 0 || empty($conf->banque->enabled)) && $object->paid == 0)
2390  if ($object->paid == 0)
2391  {
2392  print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id='.$object->id.'&action=set_paid">'.$langs->trans("ClassifyPaid")."</a></div>";
2393  }
2394  }
2395 
2396  if ($user->rights->expensereport->creer && ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) && $object->fk_statut == 5)
2397  {
2398  // Cancel
2399  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=cancel&id='.$object->id.'">'.$langs->trans('Cancel').'</a></div>';
2400  }
2401 
2402  // TODO Replace this. It should be SetUnpaid and should go back to status unpaid not canceled.
2403  if (($user->rights->expensereport->approve || $user->rights->expensereport->to_paid) && $object->fk_statut == 6)
2404  {
2405  // Cancel
2406  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=cancel&id='.$object->id.'">'.$langs->trans('Cancel').'</a></div>';
2407  }
2408 
2409  // Clone
2410  if ($user->rights->expensereport->creer) {
2411  print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&amp;action=clone">' . $langs->trans("ToClone") . '</a></div>';
2412  }
2413 
2414  /* If draft, validated, cancel, and user can create, he can always delete its card before it is approved */
2415  if ($user->rights->expensereport->creer && $user->id == $object->fk_user_author && $object->fk_statut <= 4)
2416  {
2417  // Delete
2418  print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&id='.$object->id.'">'.$langs->trans('Delete').'</a></div>';
2419  }
2420  else if($user->rights->expensereport->supprimer && $object->fk_statut != 6)
2421  {
2422  // Delete
2423  print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&id='.$object->id.'">'.$langs->trans('Delete').'</a></div>';
2424  }
2425 
2426  $parameters = array();
2427  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
2428 }
2429 
2430 print '</div>';
2431 
2432 
2433 //$conf->global->DOL_URL_ROOT_DOCUMENT_PHP=dol_buildpath('/expensereport/documentwrapper.php',1);
2434 
2435 
2436 // Select mail models is same action as presend
2437 if (GETPOST('modelselected', 'alpha')) {
2438  $action = 'presend';
2439 }
2440 
2441 if ($action != 'presend')
2442 {
2443 
2444  /*
2445  * Generate documents
2446  */
2447 
2448  print '<div class="fichecenter"><div class="fichehalfleft">';
2449  print '<a name="builddoc"></a>'; // ancre
2450 
2451  if($user->rights->expensereport->creer && $action != 'create' && $action != 'edit')
2452  {
2453  $filename = dol_sanitizeFileName($object->ref);
2454  $filedir = $conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref);
2455  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
2456  $genallowed = $user->rights->expensereport->creer;
2457  $delallowed = $user->rights->expensereport->creer;
2458  $var = true;
2459  print $formfile->showdocuments('expensereport', $filename, $filedir, $urlsource, $genallowed, $delallowed);
2460  $somethingshown = $formfile->numoffiles;
2461  }
2462 
2463  if ($action != 'create' && $action != 'edit' && ($id || $ref))
2464  {
2465  $linktoelem = $form->showLinkToObjectBlock($object, null, array('expensereport'));
2466  $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
2467  }
2468  print '</div><div class="fichehalfright"><div class="ficheaddleft">';
2469  // List of actions on element
2470  include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
2471  $formactions = new FormActions($db);
2472  $somethingshown = $formactions->showactions($object, 'expensereport', null);
2473 
2474  print '</div></div></div>';
2475 }
2476 
2477 // Presend form
2478 $modelmail='expensereport';
2479 $defaulttopic='SendExpenseReportRef';
2480 $diroutput = $conf->expensereport->dir_output;
2481 $trackid = 'exp'.$object->id;
2482 
2483 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
2484 
2485 
2486 llxFooter();
2487 
2488 $db->close();
img_warning($titlealt='default', $moreatt='')
Show warning logo.
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
Class to manage building of HTML components.
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') else if($action=='specimen') else if($action=='setmodel') else if($action=='del') else if($action=='setdoc') $formactions
View.
Class of expense report details lines.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
img_edit($titlealt='default', $float=0, $other='class="pictoedit"')
Show logo editer/modifier fiche.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
select_type_fees_id($selected='', $htmlname='type', $showempty=0, $active=1)
Return list of types of notes with select value = id.
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.
Class to manage Dolibarr users.
Definition: user.class.php:41
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0)
Return an id or code from a code or id.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for properties) With native = 0: P...
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
const STATUS_REFUSED
Classified refused.
Class to manage bank accounts.
img_delete($titlealt='default', $other='class="pictodelete"')
Show delete logo.
if(! GETPOST('transkey', 'alphanohtml') &&! GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:43
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
Class to manage building of HTML components.
dol_fiche_end($notab=0)
Show tab footer of a card.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext); $mailfile->sendfile();.
expensereport_prepare_head($object)
Prepare array with list of tabs.
llxHeader()
Empty header.
Definition: wrapper.php:44
get_date_range($date_start, $date_end, $format='', $outputlangs='', $withparenthesis=1)
Format output for start and end date.
Class to manage translations.
if($_POST["cancel"]==$langs->trans("Cancel") &&! $id) if($action=='add' && $_POST["cancel"]<> $langs->trans("Cancel")) if($action=='delete') if($id) $form
Actions.
Definition: card.php:153
Class to manage Trips and Expenses.
Class to offer components to list and upload files.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
Class to manage payments of expense report.
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
Class to manage a WYSIWYG editor.
Class to manage accounting accounts.
isValidEmail($address, $acceptsupervisorkey=0)
Return true if email syntax is ok.
const STATUS_DRAFT
Draft status.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
$parameters
Actions.
Definition: card.php:114