PageRenderTime 262ms CodeModel.GetById 41ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/compta/deplacement/fiche.php

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