PageRenderTime 57ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/compta/deplacement/fiche.php

https://bitbucket.org/speedealing/speedealing
PHP | 582 lines | 390 code | 95 blank | 97 comment | 91 complexity | 4073a22df004ed4882add4fde030306b MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/compta/deplacement/fiche.php
  22. * \brief Page to show a trip card
  23. */
  24. require '../../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/trip.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  28. if (! empty($conf->projet->enabled))
  29. {
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  32. }
  33. $langs->load("trips");
  34. // Security check
  35. $id = GETPOST('id','int');
  36. if ($user->societe_id) $socid=$user->societe_id;
  37. $result = restrictedArea($user, 'deplacement', $id,'');
  38. $action = GETPOST('action','alpha');
  39. $confirm = GETPOST('confirm','alpha');
  40. $mesg = '';
  41. $object = new Deplacement($db);
  42. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  43. $hookmanager->initHooks(array('tripsandexpensescard'));
  44. /*
  45. * Actions
  46. */
  47. if ($action == 'validate' && $user->rights->deplacement->creer)
  48. {
  49. $object->fetch($id);
  50. if ($object->statut == 0)
  51. {
  52. $result = $object->setStatut(1);
  53. if ($result > 0)
  54. {
  55. header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
  56. exit;
  57. }
  58. else
  59. {
  60. $mesg=$object->error;
  61. }
  62. }
  63. }
  64. /*
  65. else if ($action == 'unblock' && $user->rights->deplacement->unvalidate)
  66. {
  67. $object->fetch($id);
  68. if ($object->fk_statut == '1') // Not blocked...
  69. {
  70. $mesg='<div class="error">'.$langs->trans("Error").'</div>';
  71. $action='';
  72. $error++;
  73. }
  74. else
  75. {
  76. $result = $object->fetch($id);
  77. $object->fk_statut = '1';
  78. $result = $object->update($user);
  79. if ($result > 0)
  80. {
  81. header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
  82. exit;
  83. }
  84. else
  85. {
  86. $mesg=$object->error;
  87. }
  88. }
  89. }*/
  90. else if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->deplacement->supprimer)
  91. {
  92. $result=$object->delete($id);
  93. if ($result >= 0)
  94. {
  95. header("Location: index.php");
  96. exit;
  97. }
  98. else
  99. {
  100. $mesg=$object->error;
  101. }
  102. }
  103. else if ($action == 'add' && $user->rights->deplacement->creer)
  104. {
  105. if (! GETPOST('cancel','alpha'))
  106. {
  107. $error=0;
  108. $object->date = dol_mktime(12, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int'));
  109. $object->km = GETPOST('km','int');
  110. $object->type = GETPOST('type','alpha');
  111. $object->socid = GETPOST('socid','int');
  112. $object->fk_user = GETPOST('fk_user','int');
  113. $object->note_private = GETPOST('note_private','alpha');
  114. $object->note_public = GETPOST('note_public','alpha');
  115. $object->statut = 0;
  116. if (! $object->date)
  117. {
  118. $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date"));
  119. $error++;
  120. }
  121. if ($object->type == '-1') // Otherwise it is TF_LUNCH,...
  122. {
  123. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")).'</div>';
  124. $error++;
  125. }
  126. if (! ($object->fk_user > 0))
  127. {
  128. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Person")).'</div>';
  129. $error++;
  130. }
  131. if (! $error)
  132. {
  133. $id = $object->create($user);
  134. if ($id > 0)
  135. {
  136. header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
  137. exit;
  138. }
  139. else
  140. {
  141. $mesg=$object->error;
  142. $action='create';
  143. }
  144. }
  145. else
  146. {
  147. $action='create';
  148. }
  149. }
  150. else
  151. {
  152. header("Location: index.php");
  153. exit;
  154. }
  155. }
  156. // Update record
  157. else if ($action == 'update' && $user->rights->deplacement->creer)
  158. {
  159. if (! GETPOST('cancel','alpha'))
  160. {
  161. $result = $object->fetch($id);
  162. $object->date = dol_mktime(12, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int'));
  163. $object->km = GETPOST('km','int');
  164. $object->type = GETPOST('type','alpha');
  165. $object->socid = GETPOST('socid','int');
  166. $object->fk_user = GETPOST('fk_user','int');
  167. $object->note_private = GETPOST('note_private','alpha');
  168. $object->note_public = GETPOST('note_public','alpha');
  169. $result = $object->update($user);
  170. if ($result > 0)
  171. {
  172. header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
  173. exit;
  174. }
  175. else
  176. {
  177. $mesg=$object->error;
  178. }
  179. }
  180. else
  181. {
  182. header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
  183. exit;
  184. }
  185. }
  186. // Set into a project
  187. else if ($action == 'classin' && $user->rights->deplacement->creer)
  188. {
  189. $object->fetch($id);
  190. $result=$object->setProject(GETPOST('projectid','int'));
  191. if ($result < 0) dol_print_error($db, $object->error);
  192. }
  193. // Set fields
  194. else if ($action == 'setdated' && $user->rights->deplacement->creer)
  195. {
  196. $dated=dol_mktime(GETPOST('datedhour','int'), GETPOST('datedmin','int'), GETPOST('datedsec','int'), GETPOST('datedmonth','int'), GETPOST('datedday','int'), GETPOST('datedyear','int'));
  197. $object->fetch($id);
  198. $result=$object->setValueFrom('dated',$dated,'','','date');
  199. if ($result < 0) dol_print_error($db, $object->error);
  200. }
  201. else if ($action == 'setkm' && $user->rights->deplacement->creer)
  202. {
  203. $object->fetch($id);
  204. $result=$object->setValueFrom('km',GETPOST('km','int'));
  205. if ($result < 0) dol_print_error($db, $object->error);
  206. }
  207. else if ($action == 'setnote_public' && $user->rights->deplacement->creer)
  208. {
  209. $object->fetch($id);
  210. $result=$object->setValueFrom('note_public',GETPOST('note_public','alpha'));
  211. if ($result < 0) dol_print_error($db, $object->error);
  212. }
  213. else if ($action == 'setnote' && $user->rights->deplacement->creer)
  214. {
  215. $object->fetch($id);
  216. $result=$object->setValueFrom('note',GETPOST('note','alpha'));
  217. if ($result < 0) dol_print_error($db, $object->error);
  218. }
  219. /*
  220. * View
  221. */
  222. llxHeader();
  223. $form = new Form($db);
  224. /*
  225. * Action create
  226. */
  227. if ($action == 'create')
  228. {
  229. //WYSIWYG Editor
  230. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  231. print_fiche_titre($langs->trans("NewTrip"));
  232. dol_htmloutput_errors($mesg);
  233. $datec = dol_mktime(12, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int'));
  234. print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
  235. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  236. print '<input type="hidden" name="action" value="add">';
  237. print '<table class="border" width="100%">';
  238. print "<tr>";
  239. print '<td width="25%" class="fieldrequired">'.$langs->trans("Type").'</td><td>';
  240. print $form->select_type_fees(GETPOST('type','int'),'type',1);
  241. print '</td></tr>';
  242. print "<tr>";
  243. print '<td class="fieldrequired">'.$langs->trans("Person").'</td><td>';
  244. print $form->select_users(GETPOST('fk_user','int'),'fk_user',1);
  245. print '</td></tr>';
  246. print "<tr>";
  247. print '<td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
  248. print $form->select_date($datec?$datec:-1,'','','','','add',1,1);
  249. print '</td></tr>';
  250. // Km
  251. print '<tr><td class="fieldrequired">'.$langs->trans("FeesKilometersOrAmout").'</td><td><input name="km" size="10" value="' . GETPOST("km") . '"></td></tr>';
  252. // Company
  253. print "<tr>";
  254. print '<td>'.$langs->trans("CompanyVisited").'</td><td>';
  255. print $form->select_company(GETPOST('socid','int'),'socid','',1);
  256. print '</td></tr>';
  257. // Public note
  258. print '<tr>';
  259. print '<td class="border" valign="top">'.$langs->trans('NotePublic').'</td>';
  260. print '<td valign="top" colspan="2">';
  261. $doleditor = new DolEditor('note_public', GETPOST('note_public', 'alpha'), 600, 200, 'dolibarr_notes', 'In', false, true, true, ROWS_8, 100);
  262. print $doleditor->Create(1);
  263. print '</td></tr>';
  264. // Private note
  265. if (! $user->societe_id)
  266. {
  267. print '<tr>';
  268. print '<td class="border" valign="top">'.$langs->trans('NotePrivate').'</td>';
  269. print '<td valign="top" colspan="2">';
  270. $doleditor = new DolEditor('note_private', GETPOST('note_private', 'alpha'), 600, 200, 'dolibarr_notes', 'In', false, true, true, ROWS_8, 100);
  271. print $doleditor->Create(1);
  272. print '</td></tr>';
  273. }
  274. // Other attributes
  275. $parameters=array('colspan' => ' colspan="2"');
  276. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  277. print '</table>';
  278. print '<br><center><input class="button" type="submit" value="'.$langs->trans("Save").'"> &nbsp; &nbsp; ';
  279. print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"></center';
  280. print '</form>';
  281. }
  282. else if ($id)
  283. {
  284. $result = $object->fetch($id);
  285. if ($result > 0)
  286. {
  287. dol_htmloutput_mesg($mesg);
  288. $head = trip_prepare_head($object);
  289. dol_fiche_head($head, 'card', $langs->trans("TripCard"), 0, 'trip');
  290. if ($action == 'edit' && $user->rights->deplacement->creer)
  291. {
  292. //WYSIWYG Editor
  293. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  294. $soc = new Societe($db);
  295. if ($object->socid)
  296. {
  297. $soc->fetch($object->socid);
  298. }
  299. print '<form name="update" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
  300. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  301. print '<input type="hidden" name="action" value="update">';
  302. print '<input type="hidden" name="id" value="'.$id.'">';
  303. print '<table class="border" width="100%">';
  304. // Ref
  305. print "<tr>";
  306. print '<td width="20%">'.$langs->trans("Ref").'</td><td>';
  307. print $object->ref;
  308. print '</td></tr>';
  309. // Type
  310. print "<tr>";
  311. print '<td class="fieldrequired">'.$langs->trans("Type").'</td><td>';
  312. print $form->select_type_fees(GETPOST('type','int')?GETPOST('type','int'):$object->type,'type',0);
  313. print '</td></tr>';
  314. // Who
  315. print "<tr>";
  316. print '<td class="fieldrequired">'.$langs->trans("Person").'</td><td>';
  317. print $form->select_users(GETPOST('fk_user','int')?GETPOST('fk_user','int'):$object->fk_user,'fk_user',0);
  318. print '</td></tr>';
  319. // Date
  320. print '<tr><td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
  321. print $form->select_date($object->date,'','','','','update');
  322. print '</td></tr>';
  323. // Km
  324. print '<tr><td class="fieldrequired">'.$langs->trans("FeesKilometersOrAmout").'</td><td>';
  325. print '<input name="km" class="flat" size="10" value="'.$object->km.'">';
  326. print '</td></tr>';
  327. // Where
  328. print "<tr>";
  329. print '<td>'.$langs->trans("CompanyVisited").'</td><td>';
  330. print $form->select_company($soc->id,'socid','',1);
  331. print '</td></tr>';
  332. // Public note
  333. print '<tr><td valign="top">'.$langs->trans("NotePublic").'</td>';
  334. print '<td valign="top" colspan="3">';
  335. $doleditor = new DolEditor('note_public', $object->note_public, 600, 200, 'dolibarr_notes', 'In', false, true, true, ROWS_8, '100');
  336. print $doleditor->Create(1);
  337. print "</td></tr>";
  338. // Private note
  339. if (! $user->societe_id)
  340. {
  341. print '<tr><td valign="top">'.$langs->trans("NotePrivate").'</td>';
  342. print '<td valign="top" colspan="3">';
  343. $doleditor = new DolEditor('note_private', $object->note_private, 600, 200, 'dolibarr_notes', 'In', false, true, true, ROWS_8, '100');
  344. print $doleditor->Create(1);
  345. print "</td></tr>";
  346. }
  347. // Other attributes
  348. $parameters=array('colspan' => ' colspan="3"');
  349. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  350. print '</table>';
  351. print '<br><center><input type="submit" class="button" value="'.$langs->trans("Save").'"> &nbsp; ';
  352. print '<input type="submit" name="cancel" class="button" value="'.$langs->trans("Cancel").'">';
  353. print '</center>';
  354. print '</form>';
  355. print '</div>';
  356. }
  357. else
  358. {
  359. /*
  360. * Confirmation de la suppression du deplacement
  361. */
  362. if ($action == 'delete')
  363. {
  364. $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("DeleteTrip"),$langs->trans("ConfirmDeleteTrip"),"confirm_delete");
  365. if ($ret == 'html') print '<br>';
  366. }
  367. $soc = new Societe($db);
  368. if ($object->socid) $soc->fetch($object->socid);
  369. print '<table class="border" width="100%">';
  370. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/deplacement/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  371. // Ref
  372. print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td>';
  373. print $form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'ref', '');
  374. print '</td></tr>';
  375. // Type
  376. print '<tr><td>';
  377. print $form->editfieldkey("Type",'type',$langs->trans($object->type),$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'select:types_fees');
  378. print '</td><td>';
  379. print $form->editfieldval("Type",'type',$langs->trans($object->type),$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'select:types_fees');
  380. print '</td></tr>';
  381. // Who
  382. print '<tr><td>'.$langs->trans("Person").'</td><td>';
  383. $userfee=new User($db);
  384. $userfee->fetch($object->fk_user);
  385. print $userfee->getNomUrl(1);
  386. print '</td></tr>';
  387. // Date
  388. print '<tr><td>';
  389. print $form->editfieldkey("Date",'dated',$object->date,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'datepicker');
  390. print '</td><td>';
  391. print $form->editfieldval("Date",'dated',$object->date,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'datepicker');
  392. print '</td></tr>';
  393. // Km/Price
  394. print '<tr><td valign="top">';
  395. print $form->editfieldkey("FeesKilometersOrAmout",'km',$object->km,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'numeric:6');
  396. print '</td><td>';
  397. print $form->editfieldval("FeesKilometersOrAmout",'km',$object->km,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'numeric:6');
  398. print "</td></tr>";
  399. // Where
  400. print '<tr><td>'.$langs->trans("CompanyVisited").'</td>';
  401. print '<td>';
  402. if ($soc->id) print $soc->getNomUrl(1);
  403. print '</td></tr>';
  404. // Project
  405. if (! empty($conf->projet->enabled))
  406. {
  407. $langs->load('projects');
  408. print '<tr>';
  409. print '<td>';
  410. print '<table class="nobordernopadding" width="100%"><tr><td>';
  411. print $langs->trans('Project');
  412. print '</td>';
  413. if ($action != 'classify' && $user->rights->deplacement->creer)
  414. {
  415. print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=classify&amp;id='.$object->id.'">';
  416. print img_edit($langs->trans('SetProject'),1);
  417. print '</a></td>';
  418. }
  419. print '</tr></table>';
  420. print '</td><td colspan="3">';
  421. if ($action == 'classify')
  422. {
  423. $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'projectid');
  424. }
  425. else
  426. {
  427. $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'none');
  428. }
  429. print '</td>';
  430. print '</tr>';
  431. }
  432. // Statut
  433. print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
  434. // Other attributes
  435. $parameters=array('colspan' => ' colspan="3"');
  436. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  437. print "</table><br>";
  438. // Notes
  439. $blocname = 'notes';
  440. $title = $langs->trans('Notes');
  441. include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
  442. print '</div>';
  443. /*
  444. * Barre d'actions
  445. */
  446. print '<div class="tabsAction">';
  447. if ($object->statut == 0) // if blocked...
  448. {
  449. if ($user->rights->deplacement->creer)
  450. {
  451. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=validate&id='.$id.'">'.$langs->trans('Validate').'</a>';
  452. }
  453. else
  454. {
  455. print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Validate').'</a>';
  456. }
  457. }
  458. if ($user->rights->deplacement->creer)
  459. {
  460. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&id='.$id.'">'.$langs->trans('Modify').'</a>';
  461. }
  462. else
  463. {
  464. print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Modify').'</a>';
  465. }
  466. if ($user->rights->deplacement->supprimer)
  467. {
  468. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&id='.$id.'">'.$langs->trans('Delete').'</a>';
  469. }
  470. else
  471. {
  472. print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Delete').'</a>';
  473. }
  474. print '</div>';
  475. }
  476. }
  477. else
  478. {
  479. dol_print_error($db);
  480. }
  481. }
  482. $db->close();
  483. llxFooter();
  484. ?>