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