card.php 84 KB

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