PageRenderTime 67ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/expensereport/card.php

https://github.com/atm-maximep/dolibarr
PHP | 2085 lines | 1643 code | 248 blank | 194 comment | 336 complexity | c3f215c18eaa4b1dac4479f8ee921f2e MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, Apache-2.0, LGPL-3.0, GPL-2.0, GPL-3.0, CC-BY-SA-4.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
  5. * Copyright (C) 2015 Alexandre Spangaro <alexandre.spangaro@gmail.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/expensereport/card.php
  22. * \ingroup expensereport
  23. * \brief Page for trip and expense report card
  24. */
  25. $res=0;
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
  28. require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php';
  29. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
  30. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
  31. require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
  32. require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
  33. require_once DOL_DOCUMENT_ROOT . '/core/lib/expensereport.lib.php';
  34. require_once DOL_DOCUMENT_ROOT . '/core/lib/price.lib.php';
  35. require_once DOL_DOCUMENT_ROOT . '/core/modules/expensereport/modules_expensereport.php';
  36. require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php';
  37. require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php';
  38. require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
  39. $langs->load("trips");
  40. $langs->load("bills");
  41. $langs->load("mails");
  42. $action=GETPOST('action');
  43. $cancel=GETPOST('cancel');
  44. $date_start = dol_mktime(0, 0, 0, GETPOST('date_debutmonth'), GETPOST('date_debutday'), GETPOST('date_debutyear'));
  45. $date_end = dol_mktime(0, 0, 0, GETPOST('date_finmonth'), GETPOST('date_finday'), GETPOST('date_finyear'));
  46. $date = dol_mktime(0, 0, 0, GETPOST('datemonth'), GETPOST('dateday'), GETPOST('dateyear'));
  47. $fk_projet=GETPOST('fk_projet');
  48. $ref=GETPOST("ref",'alpha');
  49. // If socid provided by ajax company selector
  50. if (! empty($_REQUEST['socid_id']))
  51. {
  52. $_GET['socid'] = $_GET['socid_id'];
  53. $_POST['socid'] = $_POST['socid_id'];
  54. $_REQUEST['socid'] = $_REQUEST['socid_id'];
  55. }
  56. // Security check
  57. $id=GETPOST("id",'int');
  58. if ($user->societe_id) $socid=$user->societe_id;
  59. $result = restrictedArea($user, 'expensereport', 0, 'expensereport');
  60. // Hack to use expensereport dir
  61. $rootfordata = DOL_DATA_ROOT;
  62. $rootforuser = DOL_DATA_ROOT;
  63. // If multicompany module is enabled, we redefine the root of data
  64. if (! empty($conf->multicompany->enabled) && ! empty($conf->entity) && $conf->entity > 1)
  65. {
  66. $rootfordata.='/'.$conf->entity;
  67. }
  68. $conf->expensereport->dir_output = $rootfordata.'/expensereport';
  69. // Define $urlwithroot
  70. $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
  71. $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  72. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  73. // PDF
  74. $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  75. $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
  76. $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  77. /*
  78. * Actions
  79. */
  80. if ($cancel) $action='';
  81. if ($action == 'confirm_delete' && GETPOST("confirm") == "yes" && $id > 0 && $user->rights->expensereport->supprimer)
  82. {
  83. $object = new ExpenseReport($db);
  84. $result=$object->delete($id, $user);
  85. if ($result >= 0)
  86. {
  87. header("Location: index.php");
  88. exit;
  89. }
  90. else
  91. {
  92. setEventMessages($object->error, $object->errors, 'errors');
  93. }
  94. }
  95. if ($action == 'add' && $user->rights->expensereport->creer)
  96. {
  97. $object = new ExpenseReport($db);
  98. $object->date_debut = $date_start;
  99. $object->date_fin = $date_end;
  100. $object->fk_statut = 1;
  101. $object->fk_c_paiement = GETPOST('fk_c_paiement','int');
  102. $object->fk_user_validator = GETPOST('fk_user_validator','int');
  103. $object->note_public = GETPOST('note_public');
  104. $object->note_private = GETPOST('note_private');
  105. if ($object->periode_existe($user,$object->date_debut,$object->date_fin))
  106. {
  107. $error++;
  108. setEventMessage($langs->trans("ErrorDoubleDeclaration"),'errors');
  109. $action='create';
  110. }
  111. if (! $error)
  112. {
  113. $db->begin();
  114. $id = $object->create($user);
  115. if ($id > 0)
  116. {
  117. $db->commit();
  118. Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  119. exit;
  120. }
  121. else
  122. {
  123. setEventMessages($object->error, $object->errors, 'errors');
  124. $db->rollback();
  125. $action='create';
  126. }
  127. }
  128. }
  129. if ($action == 'update' && $user->rights->expensereport->creer)
  130. {
  131. $object = new ExpenseReport($db);
  132. $object->fetch($id);
  133. $object->date_debut = $date_start;
  134. $object->date_fin = $date_end;
  135. if($object->fk_statut < 3)
  136. {
  137. $object->fk_user_validator = GETPOST('fk_user_validator','int');
  138. }
  139. $object->fk_c_paiement = GETPOST('fk_c_paiement','int');
  140. $object->note_public = GETPOST('note_public');
  141. $object->note_private = GETPOST('note_private');
  142. $result = $object->update($user);
  143. if ($result > 0)
  144. {
  145. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_POST['id']);
  146. exit;
  147. }
  148. else
  149. {
  150. setEventMessages($object->error, $object->errors, 'errors');
  151. }
  152. }
  153. if ($action == "confirm_save" && GETPOST("confirm") == "yes" && $id > 0 && $user->rights->expensereport->creer)
  154. {
  155. $object = new ExpenseReport($db);
  156. $object->fetch($id);
  157. $result = $object->setValidate($user);
  158. if ($result > 0)
  159. {
  160. // Define output language
  161. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  162. {
  163. $outputlangs = $langs;
  164. $newlang = '';
  165. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha');
  166. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
  167. if (! empty($newlang)) {
  168. $outputlangs = new Translate("", $conf);
  169. $outputlangs->setDefaultLang($newlang);
  170. }
  171. $model=$object->modelpdf;
  172. $ret = $object->fetch($id); // Reload to get new records
  173. $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  174. }
  175. }
  176. if ($result > 0 && $object->fk_user_validator > 0)
  177. {
  178. $langs->load("mails");
  179. // TO
  180. $destinataire = new User($db);
  181. $destinataire->fetch($object->fk_user_validator);
  182. $emailTo = $destinataire->email;
  183. // FROM
  184. $expediteur = new User($db);
  185. $expediteur->fetch($object->fk_user_author);
  186. $emailFrom = $expediteur->email;
  187. if ($emailTo && $emailFrom)
  188. {
  189. // SUBJECT
  190. $subject = $langs->trans("ExpenseReportWaitingForApproval");
  191. // CONTENT
  192. $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
  193. $message = $langs->trans("ExpenseReportWaitingForApprovalMessage", $expediteur->getFullName($langs), get_date_range($object->date_debut,$object->date_fin,'',$langs), $link);
  194. // Rebuild pdf
  195. /*
  196. $object->setDocModel($user,"");
  197. $resultPDF = expensereport_pdf_create($db,$id,'',"",$langs);
  198. if($resultPDF):
  199. // ATTACHMENT
  200. $filename=array(); $filedir=array(); $mimetype=array();
  201. array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
  202. array_push($filedir,$conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref) . "/" . dol_sanitizeFileName($object->ref).".pdf");
  203. array_push($mimetype,"application/pdf");
  204. */
  205. // PREPARE SEND
  206. $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename);
  207. if ($mailfile)
  208. {
  209. // SEND
  210. $result=$mailfile->sendfile();
  211. if ($result)
  212. {
  213. $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2));
  214. setEventMessage($mesg);
  215. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  216. exit;
  217. }
  218. else
  219. {
  220. $langs->load("other");
  221. if ($mailfile->error)
  222. {
  223. $mesg='';
  224. $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
  225. $mesg.='<br>'.$mailfile->error;
  226. setEventMessage($mesg,'errors');
  227. }
  228. else
  229. {
  230. setEventMessage('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', 'warnings');
  231. }
  232. }
  233. }
  234. else
  235. {
  236. setEventMessages($mailfile->error,$mailfile->errors,'errors');
  237. $action='';
  238. }
  239. }
  240. else
  241. {
  242. setEventMessage($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), 'warnings');
  243. $action='';
  244. }
  245. }
  246. else
  247. {
  248. setEventMessages($object->error, $object->errors, 'errors');
  249. }
  250. }
  251. if ($action == "confirm_save_from_refuse" && GETPOST("confirm") == "yes" && $id > 0 && $user->rights->expensereport->creer)
  252. {
  253. $object = new ExpenseReport($db);
  254. $object->fetch($id);
  255. $result = $object->set_save_from_refuse($user);
  256. if ($result > 0)
  257. {
  258. // Define output language
  259. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  260. {
  261. $outputlangs = $langs;
  262. $newlang = '';
  263. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha');
  264. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
  265. if (! empty($newlang)) {
  266. $outputlangs = new Translate("", $conf);
  267. $outputlangs->setDefaultLang($newlang);
  268. }
  269. $model=$object->modelpdf;
  270. $ret = $object->fetch($id); // Reload to get new records
  271. $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  272. }
  273. }
  274. if ($result > 0)
  275. {
  276. if (! empty($conf->global->DEPLACEMENT_TO_CLEAN))
  277. {
  278. // Send mail
  279. // TO
  280. $destinataire = new User($db);
  281. $destinataire->fetch($object->fk_user_validator);
  282. $emailTo = $destinataire->email;
  283. if ($emailTo)
  284. {
  285. // FROM
  286. $expediteur = new User($db);
  287. $expediteur->fetch($object->fk_user_author);
  288. $emailFrom = $expediteur->email;
  289. // SUBJECT
  290. $subject = "' ERP - Note de frais à re-approuver";
  291. // CONTENT
  292. $dateRefusEx = explode(" ",$object->date_refuse);
  293. $message = "Bonjour {$destinataire->firstname},\n\n";
  294. $message.= "Le {$dateRefusEx[0]} à {$dateRefusEx[1]} vous avez refusé d'approuver la note de frais \"{$object->ref}\". Vous aviez émis le motif suivant : {$object->detail_refuse}\n\n";
  295. $message.= "L'auteur vient de modifier la note de frais, veuillez trouver la nouvelle version en pièce jointe.\n";
  296. $message.= "- Déclarant : {$expediteur->firstname} {$expediteur->lastname}\n";
  297. $message.= "- Période : du {$object->date_debut} au {$object->date_fin}\n";
  298. $message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n";
  299. $message.= "Bien cordialement,\n' SI";
  300. // Génération du pdf avant attachement
  301. $object->setDocModel($user,"");
  302. $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs);
  303. if($resultPDF)
  304. {
  305. // ATTACHMENT
  306. $filename=array(); $filedir=array(); $mimetype=array();
  307. array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
  308. array_push($filedir,$conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref) . "/" . dol_sanitizeFileName($object->ref_number).".pdf");
  309. array_push($mimetype,"application/pdf");
  310. // PREPARE SEND
  311. $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename);
  312. if (! $mailfile->error)
  313. {
  314. // SEND
  315. $result=$mailfile->sendfile();
  316. if ($result)
  317. {
  318. Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  319. exit;
  320. }
  321. else
  322. {
  323. $mesg=$mailfile->error;
  324. }
  325. // END - Send mail
  326. }
  327. else
  328. {
  329. dol_print_error($db,$resultPDF);
  330. exit;
  331. }
  332. }
  333. }
  334. }
  335. }
  336. else
  337. {
  338. setEventMessages($object->error, $object->errors, 'errors');
  339. }
  340. }
  341. // Approve
  342. if ($action == "confirm_approve" && GETPOST("confirm") == "yes" && $id > 0 && $user->rights->expensereport->approve)
  343. {
  344. $object = new ExpenseReport($db);
  345. $object->fetch($id);
  346. $result = $object->setApproved($user);
  347. if ($result > 0)
  348. {
  349. // Define output language
  350. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  351. {
  352. $outputlangs = $langs;
  353. $newlang = '';
  354. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha');
  355. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
  356. if (! empty($newlang)) {
  357. $outputlangs = new Translate("", $conf);
  358. $outputlangs->setDefaultLang($newlang);
  359. }
  360. $model=$object->modelpdf;
  361. $ret = $object->fetch($id); // Reload to get new records
  362. $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  363. }
  364. }
  365. if ($result > 0)
  366. {
  367. if (! empty($conf->global->DEPLACEMENT_TO_CLEAN))
  368. {
  369. // Send mail
  370. // TO
  371. $destinataire = new User($db);
  372. $destinataire->fetch($object->fk_user_author);
  373. $emailTo = $destinataire->email;
  374. // CC
  375. $emailCC = $conf->global->NDF_CC_EMAILS;
  376. // FROM
  377. $expediteur = new User($db);
  378. $expediteur->fetch($object->fk_user_valid);
  379. $emailFrom = $expediteur->email;
  380. // SUBJECT
  381. $subject = "' ERP - Note de frais validée";
  382. // CONTENT
  383. $message = "Bonjour {$destinataire->firstname},\n\n";
  384. $message.= "Votre note de frais \"{$object->ref}\" vient d'être approuvé!\n";
  385. $message.= "- Approbateur : {$expediteur->firstname} {$expediteur->lastname}\n";
  386. $message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n";
  387. $message.= "Bien cordialement,\n' SI";
  388. // Génération du pdf avant attachement
  389. $object->setDocModel($user,"");
  390. $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs);
  391. if($resultPDF):
  392. // ATTACHMENT
  393. $filename=array(); $filedir=array(); $mimetype=array();
  394. array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
  395. array_push($filedir, $conf->expensereport->dir_output.
  396. "/".
  397. dol_sanitizeFileName($object->ref) .
  398. "/".
  399. dol_sanitizeFileName($object->ref).
  400. ".pdf"
  401. );
  402. array_push($mimetype,"application/pdf");
  403. // PREPARE SEND
  404. $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename,$emailCC);
  405. if(!$mailfile->error):
  406. // SEND
  407. $result=$mailfile->sendfile();
  408. if ($result):
  409. setEventMessage($langs->trans("MailSuccessfulySent",$emailFrom,$emailTo));
  410. Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  411. exit;
  412. else:
  413. setEventMessage($langs->trans("ErrorFailedToSendMail",$emailFrom,$emailTo),'errors');
  414. endif;
  415. else:
  416. setEventMessage($langs->trans("ErrorFailedToSendMail",$emailFrom,$emailTo),'errors');
  417. endif;
  418. // END - Send mail
  419. else : // if ($resultPDF)
  420. dol_print_error($db,$resultPDF);
  421. exit;
  422. endif;
  423. }
  424. }
  425. else
  426. {
  427. setEventMessages($object->error, $object->errors, 'errors');
  428. }
  429. }
  430. if ($action == "confirm_refuse" && GETPOST('confirm')=="yes" && $id > 0 && $user->rights->expensereport->approve)
  431. {
  432. $object = new ExpenseReport($db);
  433. $object->fetch($id);
  434. $result = $object->setDeny($user,GETPOST('detail_refuse'));
  435. if ($result > 0)
  436. {
  437. // Define output language
  438. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  439. {
  440. $outputlangs = $langs;
  441. $newlang = '';
  442. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha');
  443. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
  444. if (! empty($newlang)) {
  445. $outputlangs = new Translate("", $conf);
  446. $outputlangs->setDefaultLang($newlang);
  447. }
  448. $model=$object->modelpdf;
  449. $ret = $object->fetch($id); // Reload to get new records
  450. $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  451. }
  452. }
  453. if ($result > 0)
  454. {
  455. if (! empty($conf->global->DEPLACEMENT_TO_CLEAN))
  456. {
  457. // Send mail
  458. // TO
  459. $destinataire = new User($db);
  460. $destinataire->fetch($object->fk_user_author);
  461. $emailTo = $destinataire->email;
  462. // FROM
  463. $expediteur = new User($db);
  464. $expediteur->fetch($object->fk_user_refuse);
  465. $emailFrom = $expediteur->email;
  466. // SUBJECT
  467. $subject = "' ERP - Note de frais refusée";
  468. // CONTENT
  469. $message = "Bonjour {$destinataire->firstname},\n\n";
  470. $message.= "Votre note de frais \"{$object->ref}\" vient d'être refusée.\n";
  471. $message.= "- Refuseur : {$expediteur->firstname} {$expediteur->lastname}\n";
  472. $message.= "- Motif de refus : {$_POST['detail_refuse']}\n";
  473. $message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n";
  474. $message.= "Bien cordialement,\n' SI";
  475. // PREPARE SEND
  476. $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message);
  477. if(!$mailfile->error)
  478. {
  479. // SEND
  480. $result=$mailfile->sendfile();
  481. if ($result)
  482. {
  483. setEventMessage($langs->trans("MailSuccessfulySent",$emailFrom,$emailTo));
  484. Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  485. exit;
  486. }
  487. else
  488. {
  489. setEventMessage($langs->trans("ErrorFailedToSendMail",$emailFrom,$emailTo),'errors');
  490. $mesg="Impossible d'envoyer l'email.";
  491. }
  492. // END - Send mail
  493. }
  494. }
  495. }
  496. else
  497. {
  498. setEventMessage($object->error, $object->errors);
  499. }
  500. }
  501. //var_dump($user->id == $object->fk_user_validator);exit;
  502. if ($action == "confirm_cancel" && GETPOST('confirm')=="yes" && GETPOST('detail_cancel') && $id > 0 && $user->rights->expensereport->creer)
  503. {
  504. $object = new ExpenseReport($db);
  505. $object->fetch($id);
  506. if ($user->id == $object->fk_user_valid || $user->id == $object->fk_user_author)
  507. {
  508. $result = $object->set_cancel($user,GETPOST('detail_cancel'));
  509. if ($result > 0)
  510. {
  511. // Define output language
  512. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  513. {
  514. $outputlangs = $langs;
  515. $newlang = '';
  516. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha');
  517. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
  518. if (! empty($newlang)) {
  519. $outputlangs = new Translate("", $conf);
  520. $outputlangs->setDefaultLang($newlang);
  521. }
  522. $model=$object->modelpdf;
  523. $ret = $object->fetch($id); // Reload to get new records
  524. $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  525. }
  526. }
  527. if ($result > 0)
  528. {
  529. if (! empty($conf->global->DEPLACEMENT_TO_CLEAN))
  530. {
  531. // Send mail
  532. // TO
  533. $destinataire = new User($db);
  534. $destinataire->fetch($object->fk_user_author);
  535. $emailTo = $destinataire->email;
  536. // FROM
  537. $expediteur = new User($db);
  538. $expediteur->fetch($object->fk_user_cancel);
  539. $emailFrom = $expediteur->email;
  540. // SUBJECT
  541. $subject = "' ERP - Note de frais annulée";
  542. // CONTENT
  543. $message = "Bonjour {$destinataire->firstname},\n\n";
  544. $message.= "Votre note de frais \"{$object->ref}\" vient d'être annulée.\n";
  545. $message.= "- Annuleur : {$expediteur->firstname} {$expediteur->lastname}\n";
  546. $message.= "- Motif d'annulation : {$_POST['detail_cancel']}\n";
  547. $message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n";
  548. $message.= "Bien cordialement,\n' SI";
  549. // PREPARE SEND
  550. $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message);
  551. if(!$mailfile->error)
  552. {
  553. // SEND
  554. $result=$mailfile->sendfile();
  555. if ($result)
  556. {
  557. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  558. exit;
  559. }
  560. else
  561. {
  562. $mesg="Impossible d'envoyer l'email.";
  563. }
  564. // END - Send mail
  565. }
  566. else
  567. {
  568. setEventMessages($mail->error, $mail->errors, 'errors');
  569. }
  570. }
  571. }
  572. else
  573. {
  574. setEventMessages($object->error, $object->errors, 'errors');
  575. }
  576. }
  577. }
  578. if ($action == "confirm_paid" && GETPOST('confirm')=="yes" && $id > 0 && $user->rights->expensereport->to_paid)
  579. {
  580. $object = new ExpenseReport($db);
  581. $object->fetch($id);
  582. $result = $object->setPaid($user);
  583. if ($result > 0)
  584. {
  585. // Define output language
  586. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  587. {
  588. $outputlangs = $langs;
  589. $newlang = '';
  590. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha');
  591. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
  592. if (! empty($newlang)) {
  593. $outputlangs = new Translate("", $conf);
  594. $outputlangs->setDefaultLang($newlang);
  595. }
  596. $model=$object->modelpdf;
  597. $ret = $object->fetch($id); // Reload to get new records
  598. $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  599. }
  600. }
  601. if ($result > 0)
  602. {
  603. if (! empty($conf->global->DEPLACEMENT_TO_CLEAN))
  604. {
  605. // Send mail
  606. // TO
  607. $destinataire = new User($db);
  608. $destinataire->fetch($object->fk_user_author);
  609. $emailTo = $destinataire->email;
  610. // FROM
  611. $expediteur = new User($db);
  612. $expediteur->fetch($object->fk_user_paid);
  613. $emailFrom = $expediteur->email;
  614. // SUBJECT
  615. $subject = "' ERP - Note de frais payée";
  616. // CONTENT
  617. $message = "Bonjour {$destinataire->firstname},\n\n";
  618. $message.= "Votre note de frais \"{$object->ref}\" vient d'être payée.\n";
  619. $message.= "- Payeur : {$expediteur->firstname} {$expediteur->lastname}\n";
  620. $message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n";
  621. $message.= "Bien cordialement,\n' SI";
  622. // Génération du pdf avant attachement
  623. $object->setDocModel($user,"");
  624. $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs);
  625. // PREPARE SEND
  626. $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message);
  627. if(!$mailfile->error):
  628. // SEND
  629. $result=$mailfile->sendfile();
  630. if ($result):
  631. // Insert écriture dans le compte courant
  632. $idTrip = $id;
  633. $idAccount = 1;
  634. $object = new ExpenseReport($db);
  635. $object->fetch($idTrip);
  636. $datePaiement = explode("-",$object->date_paiement);
  637. $dateop = dol_mktime(12,0,0,$datePaiement[1],$datePaiement[2],$datePaiement[0]);
  638. $operation = $object->code_paiement;
  639. $label = "Règlement ".$object->ref;
  640. $amount = - price2num($object->total_ttc);
  641. $num_chq = '';
  642. $cat1 = '';
  643. $user = new User($db);
  644. $user->fetch($object->fk_user_paid);
  645. $acct=new Account($db,$idAccount);
  646. $insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, $cat1, $user);
  647. if ($insertid > 0):
  648. $sql = " UPDATE ".MAIN_DB_PREFIX."expensereport as d";
  649. $sql.= " SET integration_compta = 1, fk_bank_account = $idAccount";
  650. $sql.= " WHERE rowid = $idTrip";
  651. $resql=$db->query($sql);
  652. if($result):
  653. Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  654. exit;
  655. else:
  656. dol_print_error($db);
  657. endif;
  658. else:
  659. dol_print_error($db,$acct->error);
  660. endif;
  661. endif;
  662. else:
  663. $mesg="Impossible d'envoyer l'email.";
  664. endif;
  665. // END - Send mail
  666. }
  667. }
  668. else
  669. {
  670. setEventMessages($object->error, $object->errors, 'errors');
  671. }
  672. }
  673. if ($action == "confirm_brouillonner" && GETPOST('confirm')=="yes" && $id > 0 && $user->rights->expensereport->creer)
  674. {
  675. $object = new ExpenseReport($db);
  676. $object->fetch($id);
  677. if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid)
  678. {
  679. $result = $object->setStatut(0);
  680. if ($result > 0)
  681. {
  682. // Define output language
  683. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  684. {
  685. $outputlangs = $langs;
  686. $newlang = '';
  687. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha');
  688. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
  689. if (! empty($newlang)) {
  690. $outputlangs = new Translate("", $conf);
  691. $outputlangs->setDefaultLang($newlang);
  692. }
  693. $model=$object->modelpdf;
  694. $ret = $object->fetch($id); // Reload to get new records
  695. $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  696. }
  697. }
  698. if ($result > 0)
  699. {
  700. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  701. exit;
  702. }
  703. else
  704. {
  705. setEventMessages($object->error, $object->errors, 'errors');
  706. }
  707. }
  708. else
  709. {
  710. setEventMessages($langs->transnoentitiesnoconv("NOT_AUTHOR"), '', 'errors');
  711. }
  712. }
  713. if ($action == 'set_paid')
  714. {
  715. if ($object->set_paid($id) >= 0)
  716. {
  717. header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
  718. exit;
  719. }
  720. else {
  721. setEventMessage($object->error, 'errors');
  722. }
  723. }
  724. if ($action == "addline")
  725. {
  726. $error = 0;
  727. $db->begin();
  728. $object_ligne = new ExpenseReportLine($db);
  729. $object_ligne->comments = GETPOST('comments');
  730. $qty = GETPOST('qty','int');
  731. if (empty($qty)) $qty=1;
  732. $object_ligne->qty = $qty;
  733. $up=price2num(GETPOST('value_unit'),'MU');
  734. $object_ligne->value_unit = $up;
  735. $object_ligne->date = $date;
  736. $object_ligne->fk_c_type_fees = GETPOST('fk_c_type_fees');
  737. $object_ligne->fk_c_tva = GETPOST('fk_c_tva');
  738. $object_ligne->vatrate = price2num(GETPOST('vatrate'));
  739. $object_ligne->fk_projet = $fk_projet;
  740. if (! GETPOST('fk_c_type_fees') > 0)
  741. {
  742. $error++;
  743. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")),'errors');
  744. $action='';
  745. }
  746. if (GETPOST('vatrate') < 0 || GETPOST('vatrate') == '')
  747. {
  748. $error++;
  749. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Vat")),'errors');
  750. $action='';
  751. }
  752. /* Projects are never required. To force them, check module forceproject
  753. if ($conf->projet->enabled)
  754. {
  755. if (empty($object_ligne->fk_projet) || $object_ligne->fk_projet==-1)
  756. {
  757. $error++;
  758. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Project")), 'errors');
  759. }
  760. }*/
  761. // Si aucune date n'est rentrée
  762. if (empty($object_ligne->date) || $object_ligne->date=="--")
  763. {
  764. $error++;
  765. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")), 'errors');
  766. }
  767. // Si aucun prix n'est rentré
  768. if($object_ligne->value_unit==0)
  769. {
  770. $error++;
  771. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("UP")), 'errors');
  772. }
  773. // S'il y'a eu au moins une erreur
  774. if (! $error)
  775. {
  776. $object_ligne->fk_expensereport = $_POST['fk_expensereport'];
  777. $type = 0; // TODO What if service
  778. $tmp = calcul_price_total($qty, $up, 0, $vatrate, 0, 0, 0, 'TTC', 0, $type);
  779. $object_ligne->vatrate = price2num(GETPOST('vatrate'));
  780. $object_ligne->total_ttc = $tmp[2];
  781. $object_ligne->total_ht = $tmp[0];
  782. $object_ligne->total_tva = $tmp[1];
  783. $result = $object_ligne->insert();
  784. if ($result > 0)
  785. {
  786. $db->commit();
  787. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  788. exit;
  789. }
  790. else
  791. {
  792. dol_print_error($db,$object->error);
  793. $db->rollback();
  794. }
  795. }
  796. $action='';
  797. }
  798. if ($action == 'confirm_delete_line' && GETPOST("confirm") == "yes")
  799. {
  800. $object = new ExpenseReport($db);
  801. $object->fetch($id);
  802. $object_ligne = new ExpenseReportLine($db);
  803. $object_ligne->fetch(GETPOST("rowid"));
  804. $total_ht = $object_ligne->total_ht;
  805. $total_tva = $object_ligne->total_tva;
  806. $result=$object->deleteline(GETPOST("rowid"));
  807. if ($result >= 0)
  808. {
  809. if ($result > 0)
  810. {
  811. // Define output language
  812. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  813. {
  814. $outputlangs = $langs;
  815. $newlang = '';
  816. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha');
  817. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
  818. if (! empty($newlang)) {
  819. $outputlangs = new Translate("", $conf);
  820. $outputlangs->setDefaultLang($newlang);
  821. }
  822. $model=$object->modelpdf;
  823. $ret = $object->fetch($id); // Reload to get new records
  824. $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  825. }
  826. }
  827. $object->update_totaux_del($object_ligne->total_ht,$object_ligne->total_tva);
  828. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_GET['id']);
  829. exit;
  830. }
  831. else
  832. {
  833. setEventMessages($object->error, $object->errors, 'errors');
  834. }
  835. }
  836. if ($action == "updateligne" )
  837. {
  838. $object = new ExpenseReport($db);
  839. $object->fetch($id);
  840. $rowid = $_POST['rowid'];
  841. $type_fees_id = GETPOST('fk_c_type_fees');
  842. $object_ligne->fk_c_tva = GETPOST('fk_c_tva');
  843. $object_ligne->vatrate = price2num(GETPOST('vatrate'));
  844. $projet_id = $fk_projet;
  845. $comments = GETPOST('comments');
  846. $qty = GETPOST('qty');
  847. $value_unit = GETPOST('value_unit');
  848. $vatrate = GETPOST('vatrate');
  849. if (! GETPOST('fk_c_type_fees') > 0)
  850. {
  851. $error++;
  852. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")),'errors');
  853. $action='';
  854. }
  855. if (GETPOST('vatrate') < 0 || GETPOST('vatrate') == '')
  856. {
  857. $error++;
  858. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Vat")),'errors');
  859. $action='';
  860. }
  861. if (! $error)
  862. {
  863. $result = $object->updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $id);
  864. if ($result >= 0)
  865. {
  866. if ($result > 0)
  867. {
  868. // Define output language
  869. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  870. {
  871. $outputlangs = $langs;
  872. $newlang = '';
  873. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha');
  874. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
  875. if (! empty($newlang)) {
  876. $outputlangs = new Translate("", $conf);
  877. $outputlangs->setDefaultLang($newlang);
  878. }
  879. $model=$object->modelpdf;
  880. $ret = $object->fetch($id); // Reload to get new records
  881. $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  882. }
  883. }
  884. $result = $object->recalculer($id);
  885. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  886. exit;
  887. }
  888. else
  889. {
  890. setEventMessages($object->error, $object->errors, 'errors');
  891. }
  892. }
  893. }
  894. /*
  895. * Generate or regenerate the PDF document
  896. */
  897. if ($action == 'builddoc') // GET or POST
  898. {
  899. $depl = new ExpenseReport($db, 0, $_GET['id']);
  900. $depl->fetch($id);
  901. if ($_REQUEST['model'])
  902. {
  903. $depl->setDocModel($user, $_REQUEST['model']);
  904. }
  905. $outputlangs = $langs;
  906. if (! empty($_REQUEST['lang_id']))
  907. {
  908. $outputlangs = new Translate("",$conf);
  909. $outputlangs->setDefaultLang($_REQUEST['lang_id']);
  910. }
  911. $result=expensereport_pdf_create($db, $depl, '', $depl->modelpdf, $outputlangs);
  912. if ($result <= 0)
  913. {
  914. setEventMessages($object->error, $object->errors, 'errors');
  915. $action='';
  916. }
  917. }
  918. // Remove file in doc form
  919. else if ($action == 'remove_file')
  920. {
  921. $object = new ExpenseReport($db, 0, $_GET['id']);
  922. if ($object->fetch($id))
  923. {
  924. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  925. $object->fetch_thirdparty();
  926. $langs->load("other");
  927. $upload_dir = $conf->expensereport->dir_output;
  928. $file = $upload_dir . '/' . GETPOST('file');
  929. $ret=dol_delete_file($file,0,0,0,$object);
  930. if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
  931. else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
  932. $action='';
  933. }
  934. }
  935. /*
  936. * View
  937. */
  938. llxHeader('', $langs->trans("ExpenseReport"));
  939. $form = new Form($db);
  940. $formfile = new FormFile($db);
  941. $formproject = new FormProjets($db);
  942. $projecttmp = new Project($db);
  943. if (! empty($conf->global->DEPLACEMENT_TO_CLEAN))
  944. {
  945. if(!empty($_GET['mesg']))
  946. {
  947. $text_mesg = explode(",",$_GET['mesg']);
  948. foreach($text_mesg as $text)
  949. {
  950. $mesg.= "- ".$langs->trans($text)."<br />";
  951. }
  952. print "<div class=\"error\" style=\"font-size:15px;background-color:#FFB3B3;\">";
  953. print $langs->trans("LINE_NOT_ADDED")."<br />";
  954. print $mesg;
  955. print "</div>";
  956. }
  957. else
  958. {
  959. if ($mesg) print "<div class=\"error\" style=\"font-size:16px;background-color:red;\">".$mesg."</div>";
  960. }
  961. }
  962. // Create
  963. if ($action == 'create')
  964. {
  965. print print_fiche_titre($langs->trans("NewTrip"));
  966. print '<form action="'.$_SERVER['PHP_SELF'].'" method="post" name="create">';
  967. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  968. print '<input type="hidden" name="action" value="add">';
  969. dol_fiche_head('');
  970. print '<table class="border" width="100%">';
  971. print '<tbody>';
  972. print '<tr>';
  973. print '<td>'.$langs->trans("DateStart").'</td>';
  974. print '<td>';
  975. $form->select_date($date_start?$date_start:-1,'date_debut',0,0,0,'',1,1);
  976. print '</td>';
  977. print '</tr>';
  978. print '<tr>';
  979. print '<td>'.$langs->trans("DateEnd").'</td>';
  980. print '<td>';
  981. $form->select_date($date_end?$date_end:-1,'date_fin',0,0,0,'',1,1);
  982. print '</td>';
  983. print '</tr>';
  984. print '<tr>';
  985. print '<td>'.$langs->trans("VALIDATOR").'</td>';
  986. print '<td>';
  987. $object = new ExpenseReport($db);
  988. $include_users = $object->fetch_users_approver_expensereport();
  989. $s=$form->select_dolusers((GETPOST('fk_user_validator')?GETPOST('fk_user_validator'):$conf->global->EXPENSEREPORT_DEFAULT_VALIDATOR), "fk_user_validator", 1, "", 0, $include_users);
  990. print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
  991. print '</td>';
  992. print '</tr>';
  993. if (! empty($conf->global->EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION))
  994. {
  995. print '<tr>';
  996. print '<td>'.$langs->trans("ModePaiement").'</td>';
  997. print '<td>';
  998. $form->select_types_paiements(2,'fk_c_paiement');
  999. print '</td>';
  1000. print '</tr>';
  1001. }
  1002. // Public note
  1003. print '<tr>';
  1004. print '<td class="border" valign="top">' . $langs->trans('NotePublic') . '</td>';
  1005. print '<td valign="top" colspan="2">';
  1006. $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
  1007. print $doleditor->Create(1);
  1008. print '</td></tr>';
  1009. // Private note
  1010. if (empty($user->societe_id)) {
  1011. print '<tr>';
  1012. print '<td class="border" valign="top">' . $langs->trans('NotePrivate') . '</td>';
  1013. print '<td valign="top" colspan="2">';
  1014. $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
  1015. print $doleditor->Create(1);
  1016. print '</td></tr>';
  1017. }
  1018. print '<tbody>';
  1019. print '</table>';
  1020. dol_fiche_end();
  1021. print '<div align="center">';
  1022. print '<input type="submit" value="'.$langs->trans("AddTrip").'" name="bouton" class="button" />';
  1023. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="'.$langs->trans("Cancel").'" class="button" onclick="history.go(-1)" />';
  1024. print '</div>';
  1025. print '</form>';
  1026. }
  1027. else
  1028. {
  1029. if($id > 0 || $ref)
  1030. {
  1031. $object = new ExpenseReport($db);
  1032. $result = $object->fetch($id, $ref);
  1033. if ($result > 0)
  1034. {
  1035. if ($object->fk_user_author != $user->id)
  1036. {
  1037. if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous))
  1038. {
  1039. print_fiche_titre($langs->trans('TripCard'));
  1040. print '<div class="tabBar">';
  1041. print $langs->trans('NotUserRightToView');
  1042. print '</div>';
  1043. $db->close();
  1044. llxFooter();
  1045. exit;
  1046. }
  1047. }
  1048. $head = expensereport_prepare_head($object);
  1049. if ($action == 'edit' && ($object->fk_statut < 3 || $object->fk_statut==99))
  1050. {
  1051. print "<form name='update' action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">\n";
  1052. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1053. print '<input type="hidden" name="id" value="'.$id.'">';
  1054. dol_fiche_head($head, 'card', $langs->trans("TripCard"), 0, 'trip');
  1055. if($object->fk_statut==99)
  1056. {
  1057. print '<input type="hidden" name="action" value="updateFromRefuse">';
  1058. }
  1059. else
  1060. {
  1061. print '<input type="hidden" name="action" value="update">';
  1062. }
  1063. print '<table class="border" style="width:100%;">';
  1064. $linkback = '<a href="'.DOL_URL_ROOT.'/expensereport/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  1065. // Ref
  1066. print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td>';
  1067. print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '');
  1068. print '</td></tr>';
  1069. print '<tr>';
  1070. print '<td>'.$langs->trans("DateStart").'</td>';
  1071. print '<td>';
  1072. $form->select_date($object->date_debut,'date_debut');
  1073. print '</td>';
  1074. print '</tr>';
  1075. print '<tr>';
  1076. print '<td>'.$langs->trans("DateEnd").'</td>';
  1077. print '<td>';
  1078. $form->select_date($object->date_fin,'date_fin');
  1079. print '</td>';
  1080. print '</tr>';
  1081. if (! empty($conf->global->EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION))
  1082. {
  1083. print '<tr>';
  1084. print '<td>'.$langs->trans("ModePaiement").'</td>';
  1085. print '<td>';
  1086. $form->select_types_paiements($object->fk_c_paiement,'fk_c_paiement');
  1087. print '</td>';
  1088. print '</tr>';
  1089. }
  1090. if($object->fk_statut<3)
  1091. {
  1092. print '<tr>';
  1093. print '<td>'.$langs->trans("VALIDATOR").'</td>'; // Approbator
  1094. print '<td>';
  1095. $include_users = $object->fetch_users_approver_expensereport();
  1096. $s=$form->select_dolusers($object->fk_user_validator,"fk_user_validator",1,"",0,$include_users);
  1097. print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
  1098. print '</td>';
  1099. print '</tr>';
  1100. }
  1101. else
  1102. {
  1103. print '<tr>';
  1104. print '<td>'.$langs->trans("VALIDOR").'</td>';
  1105. print '<td>';
  1106. $userfee=new User($db);
  1107. $userfee->fetch($object->fk_user_valid);
  1108. print $userfee->getNomUrl(1);
  1109. print '</td></tr>';
  1110. }
  1111. print '<tr>';
  1112. print '<td>'.$langs->trans("AUTHOR").'</td>';
  1113. print '<td>';
  1114. $userfee=new User($db);
  1115. $userfee->fetch($object->fk_user_author);
  1116. print $userfee->getNomUrl(1);
  1117. print '</td></tr>';
  1118. if ($object->fk_statut==6)
  1119. {
  1120. print '<tr>';
  1121. print '<td>'.$langs->trans("AUTHORPAIEMENT").'</td>';
  1122. print '<td>';
  1123. $userfee=new User($db);
  1124. $userfee->fetch($object->fk_user_paid);
  1125. print $userfee->getNomUrl(1);
  1126. print '</td></tr>';
  1127. }
  1128. // Public note
  1129. print '<tr>';
  1130. print '<td class="border" valign="top">' . $langs->trans('NotePublic') . '</td>';
  1131. print '<td valign="top" colspan="2">';
  1132. $doleditor = new DolEditor('note_public', $object->note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
  1133. print $doleditor->Create(1);
  1134. print '</td></tr>';
  1135. // Private note
  1136. if (empty($user->societe_id)) {
  1137. print '<tr>';
  1138. print '<td class="border" valign="top">' . $langs->trans('NotePrivate') . '</td>';
  1139. print '<td valign="top" colspan="2">';
  1140. $doleditor = new DolEditor('note_private', $object->note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
  1141. print $doleditor->Create(1);
  1142. print '</td></tr>';
  1143. }
  1144. print '</table>';
  1145. dol_fiche_end();
  1146. print '<div class="center">';
  1147. print '<input type="submit" value="'.$langs->trans("Modify").'" name="bouton" class="button">';
  1148. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="'.$langs->trans("Cancel").'" class="button" onclick="history.go(-1)" />';
  1149. print '</div>';
  1150. print '</form>';
  1151. }
  1152. else
  1153. {
  1154. dol_fiche_head($head, 'card', $langs->trans("TripCard"), 0, 'trip');
  1155. if ($action == 'save'):
  1156. $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("SaveTrip"),$langs->trans("ConfirmSaveTrip"),"confirm_save","","",1);
  1157. if ($ret == 'html') print '<br>';
  1158. endif;
  1159. if ($action == 'save_from_refuse'):
  1160. $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("SaveTrip"),$langs->trans("ConfirmSaveTrip"),"confirm_save_from_refuse","","",1);
  1161. if ($ret == 'html') print '<br>';
  1162. endif;
  1163. if ($action == 'delete'):
  1164. $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("DeleteTrip"),$langs->trans("ConfirmDeleteTrip"),"confirm_delete","","",1);
  1165. if ($ret == 'html') print '<br>';
  1166. endif;
  1167. if ($action == 'validate'):
  1168. $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("ValideTrip"),$langs->trans("ConfirmValideTrip"),"confirm_approve","","",1);
  1169. if ($ret == 'html') print '<br>';
  1170. endif;
  1171. if ($action == 'paid'):
  1172. $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("PaidTrip"),$langs->trans("ConfirmPaidTrip"),"confirm_paid","","",1);
  1173. if ($ret == 'html') print '<br>';
  1174. endif;
  1175. if ($action == 'cancel')
  1176. {
  1177. $array_input = array('text'=>$langs->trans("ConfirmCancelTrip"), array('type'=>"text",'label'=>$langs->trans("Comment"),'name'=>"detail_cancel",'size'=>"50",'value'=>""));
  1178. $ret=$form->form_confirm($_SEVER["PHP_SELF"]."?id=".$id,$langs->trans("Cancel"),"","confirm_cancel",$array_input,"",1);
  1179. if ($ret == 'html') print '<br>';
  1180. }
  1181. if ($action == 'brouillonner'):
  1182. $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("BrouillonnerTrip"),$langs->trans("ConfirmBrouillonnerTrip"),"confirm_brouillonner","","",1);
  1183. if ($ret == 'html') print '<br>';
  1184. endif;
  1185. if ($action == 'refuse') // Deny
  1186. {
  1187. $array_input = array('text'=>$langs->trans("ConfirmRefuseTrip"), array('type'=>"text",'label'=>$langs->trans("Comment"),'name'=>"detail_refuse",'size'=>"50",'value'=>""));
  1188. $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("Deny"),'',"confirm_refuse",$array_input,"yes",1);
  1189. if ($ret == 'html') print '<br>';
  1190. }
  1191. if ($action == 'delete_line')
  1192. {
  1193. $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id."&rowid=".GETPOST('rowid'),$langs->trans("DeleteLine"),$langs->trans("ConfirmDeleteLine"),"confirm_delete_line",'','yes',1);
  1194. if ($ret == 'html') print '<br>';
  1195. }
  1196. print '<table class="border" width="100%">';
  1197. $linkback = '<a href="'.DOL_URL_ROOT.'/expensereport/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  1198. // Ref
  1199. print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="2">';
  1200. print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '');
  1201. print '</td></tr>';
  1202. print '<tr>';
  1203. print '<td>'.$langs->trans("Period").'</td>';
  1204. print '<td colspan="2">';
  1205. print get_date_range($object->date_debut,$object->date_fin,'',$langs,0);
  1206. print '</td>';
  1207. print '</tr>';
  1208. if (! empty($conf->global->EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION))
  1209. {
  1210. print '<tr>';
  1211. print '<td>'.$langs->trans("ModePaiement").'</td>';
  1212. print '<td colspan="2">'.$object->libelle_paiement.'</td>';
  1213. print '</tr>';
  1214. }
  1215. // Status
  1216. print '<tr>';
  1217. print '<td>'.$langs->trans("Statut").'</td>';
  1218. print '<td colspan="2">'.$object->getLibStatut(4).'</td>';
  1219. print '</tr>';
  1220. print '<tr>';
  1221. print '<td>'.$langs->trans("NotePublic").'</td>';
  1222. print '<td colspan="2">'.$object->note_public.'</td>';
  1223. print '</tr>';
  1224. print '<tr>';
  1225. print '<td>'.$langs->trans("NotePrivate").'</td>';
  1226. print '<td colspan="2">'.$object->note_private.'</td>';
  1227. print '</tr>';
  1228. print '<tr>';
  1229. print '<td>'.$langs->trans("AmountHT").'</td>';
  1230. print '<td>'.price($object->total_ht).'</td>';
  1231. print '<td rowspan="7" valign="top">';
  1232. /*
  1233. * Payments
  1234. */
  1235. $sql = "SELECT p.rowid, p.num_payment, p.datep as dp, p.amount,";
  1236. $sql.= "c.code as type_code,c.libelle as payment_type";
  1237. $sql.= " FROM ".MAIN_DB_PREFIX."payment_expensereport as p";
  1238. $sql.= ", ".MAIN_DB_PREFIX."c_paiement as c ";
  1239. $sql.= ", ".MAIN_DB_PREFIX."expensereport as e";
  1240. $sql.= " WHERE e.rowid = '".$id."'";
  1241. $sql.= " AND p.fk_expensereport = e.rowid";
  1242. $sql.= " AND e.entity = ".$conf->entity;
  1243. $sql.= " AND p.fk_typepayment = c.id";
  1244. $sql.= " ORDER BY dp";
  1245. //print $sql;
  1246. $resql = $db->query($sql);
  1247. if ($resql)
  1248. {
  1249. $num = $db->num_rows($resql);
  1250. $i = 0; $total = 0;
  1251. print '<table class="nobordernopadding" width="100%">';
  1252. print '<tr class="liste_titre">';
  1253. print '<td>'.$langs->trans("RefPayment").'</td>';
  1254. print '<td>'.$langs->trans("Date").'</td>';
  1255. print '<td>'.$langs->trans("Type").'</td>';
  1256. print '<td align="right">'.$langs->trans("Amount").'</td>';
  1257. print '<td>&nbsp;</td>';
  1258. print '</tr>';
  1259. $var=True;
  1260. while ($i < $num)
  1261. {
  1262. $objp = $db->fetch_object($resql);
  1263. $var=!$var;
  1264. print "<tr ".$bc[$var]."><td>";
  1265. print '<a href="'.DOL_URL_ROOT.'/expensereport/payment/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.'</a></td>';
  1266. print '<td>'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
  1267. $labeltype=$langs->trans("PaymentType".$object->type_code)!=("PaymentType".$object->type_code)?$langs->trans("PaymentType".$object->type_code):$object->fk_typepayment;
  1268. print "<td>".$labeltype.' '.$object->num_payment."</td>\n";
  1269. print '<td align="right">'.price($objp->amount)."</td><td>&nbsp;".$langs->trans("Currency".$conf->currency)."</td>\n";
  1270. print "</tr>";
  1271. $totalpaid += $objp->amount;
  1272. $i++;
  1273. }
  1274. if ($object->paid == 0)
  1275. {
  1276. print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("AlreadyPaid")." :</td><td align=\"right\"><b>".price($totalpaid)."</b></td><td>&nbsp;".$langs->trans("Currency".$conf->currency)."</td></tr>\n";
  1277. print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("AmountExpected")." :</td><td align=\"right\" bgcolor=\"#d0d0d0\">".price($object->total_ttc)."</td><td bgcolor=\"#d0d0d0\">&nbsp;".$langs->trans("Currency".$conf->currency)."</td></tr>\n";
  1278. $remaintopay = $object->total_ttc - $totalpaid;
  1279. print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("RemainderToPay")." :</td>";
  1280. print "<td align=\"right\" bgcolor=\"#f0f0f0\"><b>".price($remaintopay)."</b></td><td bgcolor=\"#f0f0f0\">&nbsp;".$langs->trans("Currency".$conf->currency)."</td></tr>\n";
  1281. }
  1282. print "</table>";
  1283. $db->free($resql);
  1284. }
  1285. else
  1286. {
  1287. dol_print_error($db);
  1288. }
  1289. print "</td>";
  1290. print '</tr>';
  1291. print '<tr>';
  1292. print '<td>'.$langs->trans("AmountVAT").'</td>';
  1293. print '<td>'.price($object->total_tva).'</td>';
  1294. print '</tr>';
  1295. print '<tr>';
  1296. print '<td>'.$langs->trans("AmountTTC").'</td>';
  1297. print '<td>'.price($object->total_ttc).'</td>';
  1298. print '</tr>';
  1299. // Author
  1300. print '<tr>';
  1301. print '<td>'.$langs->trans("AUTHOR").'</td>';
  1302. print '<td>';
  1303. if ($object->fk_user_author > 0)
  1304. {
  1305. $userauthor=new User($db);
  1306. $result=$userauthor->fetch($object->fk_user_author);
  1307. if ($result < 0) dol_print_error('',$userauthor->error);
  1308. print $userauthor->getNomUrl(1);
  1309. }
  1310. print '</td></tr>';
  1311. print '<tr>';
  1312. print '<td>'.$langs->trans("DATE_SAVE").'</td>';
  1313. print '<td>'.dol_print_date($object->date_create,'dayhour').'</td></tr>';
  1314. print '</tr>';
  1315. if($object->fk_statut==6)
  1316. {
  1317. print '<tr>';
  1318. print '<td>'.$langs->trans("AUTHORPAIEMENT").'</td>';
  1319. print '<td>';
  1320. $userfee=new User($db);
  1321. $userfee->fetch($object->fk_user_paid);
  1322. print $userfee->getNomUrl(1);
  1323. print '</td></tr>';
  1324. print '<tr>';
  1325. print '<td>'.$langs->trans("DATE_PAIEMENT").'</td>';
  1326. print '<td>'.$object->date_paiement.'</td></tr>';
  1327. print '</tr>';
  1328. }
  1329. // User to inform
  1330. if($object->fk_statut<3) // informed
  1331. {
  1332. print '<tr>';
  1333. print '<td>'.$langs->trans("VALIDATOR").'</td>';
  1334. print '<td>';
  1335. if ($object->fk_user_validator > 0)
  1336. {
  1337. $userfee=new User($db);
  1338. $userfee->fetch($object->fk_user_validator);
  1339. print $userfee->getNomUrl(1);
  1340. if (empty($userfee->email) || ! isValidEmail($userfee->email)) print img_warning($langs->trans("EmailNotValid"));
  1341. }
  1342. print '</td></tr>';
  1343. }
  1344. elseif($object->fk_statut==4)
  1345. {
  1346. print '<tr>';
  1347. print '<td>'.$langs->trans("CANCEL_USER").'</span></td>';
  1348. print '<td>';
  1349. if ($object->fk_user_cancel > 0)
  1350. {
  1351. $userfee=new User($db);
  1352. $userfee->fetch($object->fk_user_cancel);
  1353. print $userfee->getNomUrl(1);
  1354. }
  1355. print '</td></tr>';
  1356. print '<tr>';
  1357. print '<td>'.$langs->trans("MOTIF_CANCEL").'</td>';
  1358. print '<td>'.$object->detail_cancel.'</td></tr>';
  1359. print '</tr>';
  1360. print '<tr>';
  1361. print '<td>'.$langs->trans("DATE_CANCEL").'</td>';
  1362. print '<td>'.dol_print_date($object->date_cancel,'dayhour').'</td></tr>';
  1363. print '</tr>';
  1364. }
  1365. else
  1366. {
  1367. print '<tr>';
  1368. print '<td>'.$langs->trans("Approbator").'</td>';
  1369. print '<td>';
  1370. if ($object->fk_user_approve > 0)
  1371. {
  1372. $userapp=new User($db);
  1373. $userapp->fetch($object->fk_user_approve);
  1374. print $userapp->getNomUrl(1);
  1375. }
  1376. print '</td></tr>';
  1377. print '<tr>';
  1378. print '<td>'.$langs->trans("DateApprove").'</td>';
  1379. print '<td>'.dol_print_date($object->date_approve,'dayhour').'</td></tr>';
  1380. print '</tr>';
  1381. }
  1382. if($object->fk_statut==99 || !empty($object->detail_refuse))
  1383. {
  1384. print '<tr>';
  1385. print '<td>'.$langs->trans("REFUSEUR").'</td>';
  1386. print '<td>';
  1387. $userfee=new User($db);
  1388. $userfee->fetch($object->fk_user_refuse);
  1389. print $userfee->getNomUrl(1);
  1390. print '</td></tr>';
  1391. print '<tr>';
  1392. print '<td>'.$langs->trans("DATE_REFUS").'</td>';
  1393. print '<td>'.dol_print_date($object->date_refuse,'dayhour');
  1394. if ($object->detail_refuse) print ' - '.$object->detail_refuse;
  1395. print '</td>';
  1396. print '</tr>';
  1397. }
  1398. print '</table>';
  1399. print '<br>';
  1400. // Fetch Lines of current expense …

Large files files are truncated, but you can click here to view the full file