card-rec.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  1. <?php
  2. /* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  6. * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  8. * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
  9. * Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
  10. * Copyright (C) 2016-2018 Charlie Benke <charlie@patas-monkey.com>
  11. * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 3 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  25. */
  26. /**
  27. * \file fichinter/card-rec.php
  28. * \ingroup intervention
  29. * \brief Page to show predefined fichinter
  30. */
  31. require '../main.inc.php';
  32. require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinterrec.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  37. if (!empty($conf->projet->enabled)) {
  38. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  40. }
  41. if (!empty($conf->contrat->enabled)) {
  42. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcontract.class.php';
  44. }
  45. // Load translation files required by the page
  46. $langs->loadLangs(array("interventions", "admin", "compta", "bills"));
  47. // Security check
  48. $id = (GETPOST('fichinterid', 'int') ?GETPOST('fichinterid', 'int') : GETPOST('id', 'int'));
  49. $action = GETPOST('action', 'aZ09');
  50. if ($user->socid) {
  51. $socid = $user->socid;
  52. }
  53. $objecttype = 'fichinter_rec';
  54. if ($action == "create" || $action == "add") {
  55. $objecttype = '';
  56. }
  57. $result = restrictedArea($user, 'ficheinter', $id, $objecttype);
  58. if ($page == -1) {
  59. $page = 0;
  60. }
  61. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  62. $offset = $limit * $page;
  63. $sortorder = GETPOST('sortorder', 'aZ09comma');
  64. $sortfield = GETPOST('sortfield', 'aZ09comma');
  65. if ($sortorder == "") {
  66. $sortorder = "DESC";
  67. }
  68. if ($sortfield == "") {
  69. $sortfield = "f.datec";
  70. }
  71. $object = new FichinterRec($db);
  72. $extrafields = new ExtraFields($db);
  73. $arrayfields = array(
  74. 'f.titre'=>array('label'=>"Ref", 'checked'=>1),
  75. 's.nom'=>array('label'=>"ThirdParty", 'checked'=>1),
  76. 'f.fk_contrat'=>array('label'=>"Contract", 'checked'=>1),
  77. 'f.duree'=>array('label'=>"Duration", 'checked'=>1),
  78. 'f.total_ttc'=>array('label'=>"AmountTTC", 'checked'=>1),
  79. 'f.frequency'=>array('label'=>"RecurringInvoiceTemplate", 'checked'=>1),
  80. 'f.nb_gen_done'=>array('label'=>"NbOfGenerationDoneShort", 'checked'=>1),
  81. 'f.date_last_gen'=>array('label'=>"DateLastGeneration", 'checked'=>1),
  82. 'f.date_when'=>array('label'=>"NextDateToExecution", 'checked'=>1),
  83. 'f.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500),
  84. 'f.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500),
  85. );
  86. /*
  87. * Actions
  88. */
  89. // Create predefined intervention
  90. if ($action == 'add') {
  91. if (!GETPOST('titre')) {
  92. setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("Title")), null, 'errors');
  93. $action = "create";
  94. $error++;
  95. }
  96. if (!GETPOST('socid')) {
  97. setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("Customer")), null, 'errors');
  98. $action = "create";
  99. $error++;
  100. }
  101. // gestion des fréquences et des échéances
  102. $frequency = GETPOST('frequency', 'int');
  103. $reyear = GETPOST('reyear');
  104. $remonth = GETPOST('remonth');
  105. $reday = GETPOST('reday');
  106. $rehour = GETPOST('rehour');
  107. $remin = GETPOST('remin');
  108. $nb_gen_max = (GETPOST('nb_gen_max', 'int') ?GETPOST('nb_gen_max', 'int') : 0);
  109. if (GETPOST('frequency')) {
  110. if (empty($reyear) || empty($remonth) || empty($reday)) {
  111. setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("Date")), null, 'errors');
  112. $action = "create";
  113. $error++;
  114. }
  115. if ($nb_gen_max === '') {
  116. setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("MaxPeriodNumber")), null, 'errors');
  117. $action = "create";
  118. $error++;
  119. }
  120. }
  121. if (!$error) {
  122. $object->id_origin = $id;
  123. $object->title = GETPOST('titre', 'alpha');
  124. $object->description = GETPOST('description', 'restricthtml');
  125. $object->socid = GETPOST('socid', 'alpha');
  126. $object->fk_project = GETPOST('projectid', 'int');
  127. $object->fk_contract = GETPOST('contractid', 'int');
  128. $object->frequency = $frequency;
  129. $object->unit_frequency = GETPOST('unit_frequency', 'alpha');
  130. $object->nb_gen_max = $nb_gen_max;
  131. $object->auto_validate = GETPOST('auto_validate', 'int');
  132. $date_next_execution = dol_mktime($rehour, $remin, 0, $remonth, $reday, $reyear);
  133. $object->date_when = $date_next_execution;
  134. if ($object->create($user) > 0) {
  135. $id = $object->id;
  136. $action = '';
  137. } else {
  138. setEventMessages($object->error, $object->errors, 'errors');
  139. $action = "create";
  140. }
  141. }
  142. } elseif ($action == 'createfrommodel') {
  143. $newinter = new Fichinter($db);
  144. // on récupère les enregistrements
  145. $object->fetch($id);
  146. $res = $object->fetch_lines();
  147. // on transfert les données de l'un vers l'autre
  148. if ($object->socid > 0) {
  149. $newinter->socid = $object->socid;
  150. $newinter->fk_project = $object->fk_project;
  151. $newinter->fk_contrat = $object->fk_contrat;
  152. } else {
  153. $newinter->socid = GETPOST("socid");
  154. }
  155. $newinter->entity = $object->entity;
  156. $newinter->duree = $object->duree;
  157. $newinter->datei = $object->date;
  158. $newinter->description = $object->description;
  159. $newinter->note_private = $object->note_private;
  160. $newinter->note_public = $object->note_public;
  161. // on créer un nouvelle intervention
  162. $extrafields->fetch_name_optionals_label($newinter->table_element);
  163. $array_options = $extrafields->getOptionalsFromPost($newinter->table_element);
  164. $newinter->array_options = $array_options;
  165. $newfichinterid = $newinter->create($user);
  166. if ($newfichinterid > 0) {
  167. // Now we add line of details
  168. foreach ($object->lines as $line) {
  169. $newinter->addline($user, $newfichinterid, $line->desc, $line->datei, $line->duree, '');
  170. }
  171. // on update le nombre d'inter crée à partir du modèle
  172. $object->updateNbGenDone();
  173. //on redirige vers la fiche d'intervention nouvellement crée
  174. header('Location: '.DOL_URL_ROOT.'/fichinter/card.php?id='.$newfichinterid);
  175. exit;
  176. } else {
  177. setEventMessages($newinter->error, $newinter->errors, 'errors');
  178. $action = '';
  179. }
  180. } elseif ($action == 'delete' && $user->rights->ficheinter->supprimer) {
  181. // delete modele
  182. $object->fetch($id);
  183. $object->delete();
  184. $id = 0;
  185. header('Location: '.$_SERVER["PHP_SELF"]);
  186. exit;
  187. } elseif ($action == 'setfrequency' && $user->rights->ficheinter->creer) {
  188. // Set frequency and unit frequency
  189. $object->fetch($id);
  190. $object->setFrequencyAndUnit(GETPOST('frequency', 'int'), GETPOST('unit_frequency', 'alpha'));
  191. } elseif ($action == 'setdate_when' && $user->rights->ficheinter->creer) {
  192. // Set next date of execution
  193. $object->fetch($id);
  194. $date = dol_mktime(GETPOST('date_whenhour'), GETPOST('date_whenmin'), 0, GETPOST('date_whenmonth'), GETPOST('date_whenday'), GETPOST('date_whenyear'));
  195. if (!empty($date)) {
  196. $object->setNextDate($date);
  197. }
  198. } elseif ($action == 'setnb_gen_max' && $user->rights->ficheinter->creer) {
  199. // Set max period
  200. $object->fetch($id);
  201. $object->setMaxPeriod(GETPOST('nb_gen_max', 'int'));
  202. }
  203. /*
  204. * View
  205. */
  206. $help_url = '';
  207. llxHeader('', $langs->trans("RepeatableIntervention"), $help_url);
  208. $form = new Form($db);
  209. $companystatic = new Societe($db);
  210. if (!empty($conf->contrat->enabled)) {
  211. $contratstatic = new Contrat($db);
  212. }
  213. if (!empty($conf->projet->enabled)) {
  214. $projectstatic = new Project($db);
  215. }
  216. $now = dol_now();
  217. $tmparray = dol_getdate($now);
  218. $today = dol_mktime(23, 59, 59, $tmparray['mon'], $tmparray['mday'], $tmparray['year']); // Today is last second of current day
  219. /*
  220. * Create mode
  221. */
  222. if ($action == 'create') {
  223. print load_fiche_titre($langs->trans("CreateRepeatableIntervention"), '', 'intervention');
  224. $object = new Fichinter($db); // Source invoice
  225. //$object = new Managementfichinter($db); // Source invoice
  226. if ($object->fetch($id, $ref) > 0) {
  227. print '<form action="card-rec.php" method="post">';
  228. print '<input type="hidden" name="token" value="'.newToken().'">';
  229. print '<input type="hidden" name="action" value="add">';
  230. print '<input type="hidden" name="fichinterid" value="'.$object->id.'">';
  231. print dol_get_fiche_head();
  232. $rowspan = 4;
  233. if (!empty($conf->projet->enabled) && $object->fk_project > 0) {
  234. $rowspan++;
  235. }
  236. if (!empty($conf->contrat->enabled) && $object->fk_contrat > 0) {
  237. $rowspan++;
  238. }
  239. print '<table class="border centpercent">';
  240. $object->fetch_thirdparty();
  241. // Third party
  242. print '<tr><td>'.$langs->trans("Customer").'</td><td>';
  243. print $form->select_company($object->thirdparty->id, 'socid', '', 0, 1);
  244. //.$object->thirdparty->getNomUrl(1,'customer').
  245. print '</td><td>';
  246. print $langs->trans("Comment");
  247. print '</td></tr>';
  248. // Title
  249. print '<tr><td class="fieldrequired">'.$langs->trans("Title").'</td><td>';
  250. print '<input class="flat quatrevingtpercent" type="text" name="titre" value="'.dol_escape_htmltag(GETPOST("titre", "alphanohtml")).'">';
  251. print '</td>';
  252. // Note
  253. print '<td rowspan="'.$rowspan.'" valign="top">';
  254. print '<textarea class="flat" name="description" wrap="soft" cols="60" rows="'.ROWS_4.'">';
  255. print $object->description.'</textarea>';
  256. print '</td></tr>';
  257. // Author
  258. print "<tr><td>".$langs->trans("Author")."</td><td>".$user->getFullName($langs)."</td></tr>";
  259. if (empty($conf->global->FICHINTER_DISABLE_DETAILS)) {
  260. // Duration
  261. print '<tr><td>'.$langs->trans("TotalDuration").'</td>';
  262. print '<td colspan="3">'.convertSecondToTime($object->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY).'</td>';
  263. print '</tr>';
  264. }
  265. // Project
  266. if (!empty($conf->projet->enabled)) {
  267. $formproject = new FormProjets($db);
  268. print "<tr><td>".$langs->trans("Project")."</td><td>";
  269. $projectid = GETPOST('projectid') ?GETPOST('projectid') : $object->fk_project;
  270. $numprojet = $formproject->select_projects($object->thirdparty->id, $projectid, 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 0, 0, '');
  271. print ' &nbsp; <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$object->thirdparty->id;
  272. print '&action=create&status=1&backtopage='.urlencode($_SERVER["PHP_SELF"]).'?action=create';
  273. print '&socid='.$object->thirdparty->id.(!empty($id) ? '&id='.$id : '').'">';
  274. print $langs->trans("AddProject").'</a>';
  275. print "</td></tr>";
  276. }
  277. // Contrat
  278. if (!empty($conf->contrat->enabled)) {
  279. $formcontract = new FormContract($db);
  280. print "<tr><td>".$langs->trans("Contract")."</td><td>";
  281. $contractid = GETPOST('contractid') ?GETPOST('contractid') : $object->fk_contract;
  282. $numcontract = $formcontract->select_contract($object->thirdparty->id, $contractid, 'contracttid');
  283. print "</td></tr>";
  284. }
  285. print "</table>";
  286. print '<br><br>';
  287. /// frequency & duration
  288. // Autogeneration
  289. $title = $langs->trans("Recurrence");
  290. print load_fiche_titre($title, '', 'calendar');
  291. print '<table class="border centpercent">';
  292. // Frequency
  293. print '<tr><td class="titlefieldcreate">';
  294. print $form->textwithpicto($langs->trans("Frequency"), $langs->transnoentitiesnoconv('toolTipFrequency'));
  295. print "</td><td>";
  296. print '<input type="text" name="frequency" value="'.GETPOST('frequency', 'int').'" size="4">&nbsp;';
  297. print $form->selectarray('unit_frequency', array('d'=>$langs->trans('Day'), 'm'=>$langs->trans('Month'), 'y'=>$langs->trans('Year')), (GETPOST('unit_frequency') ?GETPOST('unit_frequency') : 'm'));
  298. print "</td></tr>";
  299. // First date of execution for cron
  300. print "<tr><td>".$langs->trans('NextDateToExecution')."</td><td>";
  301. if ($date_next_execution != "") {
  302. $date_next_execution = (GETPOST('remonth') ? dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')) : -1);
  303. }
  304. print $form->selectDate($date_next_execution, '', 1, 1, '', "add", 1, 1);
  305. print "</td></tr>";
  306. // Number max of generation
  307. print "<tr><td>".$langs->trans("MaxPeriodNumber")."</td><td>";
  308. print '<input type="text" name="nb_gen_max" value="'.GETPOST('nb_gen_max', 'int').'" size="5">';
  309. print "</td></tr>";
  310. print "</table>";
  311. print '<br>';
  312. $title = $langs->trans("ProductsAndServices");
  313. if (empty($conf->service->enabled)) {
  314. $title = $langs->trans("Products");
  315. } elseif (empty($conf->product->enabled)) {
  316. $title = $langs->trans("Services");
  317. }
  318. print load_fiche_titre($title, '', '');
  319. /*
  320. * Fichinter lines
  321. */
  322. print '<table class="notopnoleftnoright" width="100%">';
  323. print '<tr><td colspan="3">';
  324. $sql = 'SELECT l.rowid, l.description, l.duree';
  325. $sql .= " FROM ".MAIN_DB_PREFIX."fichinterdet as l";
  326. $sql .= " WHERE l.fk_fichinter= ".((int) $object->id);
  327. //$sql.= " AND l.fk_product is null ";
  328. $sql .= " ORDER BY l.rang";
  329. $result = $db->query($sql);
  330. if ($result) {
  331. $num = $db->num_rows($result);
  332. $i = 0;
  333. $total = 0;
  334. echo '<table class="noborder centpercent">';
  335. if ($num) {
  336. print '<tr class="liste_titre">';
  337. print '<td>'.$langs->trans("Description").'</td>';
  338. print '<td class="center">'.$langs->trans("Duration").'</td>';
  339. print "</tr>\n";
  340. }
  341. while ($i < $num) {
  342. $objp = $db->fetch_object($result);
  343. print '<tr class="oddeven">';
  344. // Show product and description
  345. print '<td>';
  346. print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
  347. $text = img_object($langs->trans('Service'), 'service');
  348. print $text.' '.nl2br($objp->description);
  349. // Duration
  350. print '<td class="center">'.convertSecondToTime($objp->duree).'</td>';
  351. print "</tr>";
  352. $i++;
  353. }
  354. $db->free($result);
  355. } else {
  356. print $db->error();
  357. }
  358. print "</table>";
  359. print '</td></tr>';
  360. print "</table>\n";
  361. print dol_get_fiche_end();
  362. print $form->buttonsSaveCancel("Create");
  363. print "</form>\n";
  364. } else {
  365. dol_print_error('', "Error, no fichinter ".$object->id);
  366. }
  367. } elseif ($action == 'selsocforcreatefrommodel') {
  368. print load_fiche_titre($langs->trans("CreateRepeatableIntervention"), '', 'intervention');
  369. print dol_get_fiche_head('');
  370. print '<form name="fichinter" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
  371. print '<table class="border centpercent">';
  372. print '<tr><td class="fieldrequired">'.$langs->trans("ThirdParty").'</td><td>';
  373. print $form->select_company('', 'socid', '', 1, 1);
  374. print '</td></tr>';
  375. print '</table>';
  376. print dol_get_fiche_end();
  377. print '<input type="hidden" name="action" value="createfrommodel">';
  378. print '<input type="hidden" name="id" value="'.$id.'">';
  379. print $form->buttonsSaveCancel("CreateDraftIntervention", '');
  380. print '</form>';
  381. } else {
  382. /*
  383. * View mode
  384. *
  385. */
  386. if ($id > 0) {
  387. if ($object->fetch($id) > 0) {
  388. $object->fetch_thirdparty();
  389. $author = new User($db);
  390. $author->fetch($object->user_author);
  391. $head = fichinter_rec_prepare_head($object);
  392. print dol_get_fiche_head($head, 'card', $langs->trans("PredefinedInterventional"), 0, 'intervention');
  393. // Intervention card
  394. $linkback = '<a href="card-rec.php">'.$langs->trans("BackToList").'</a>';
  395. $morehtmlref = '<div class="refidno">';
  396. // Thirdparty
  397. $morehtmlref .= $langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
  398. // Project
  399. if (!empty($conf->projet->enabled)) {
  400. $formproject = new FormProjets($db);
  401. $langs->load("projects");
  402. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  403. if ($user->rights->ficheinter->creer) {
  404. if ($action != 'classify') {
  405. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">';
  406. $morehtmlref .= img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
  407. }
  408. if ($action == 'classify') {
  409. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  410. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  411. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  412. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  413. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  414. $morehtmlref .= '</form>';
  415. } else {
  416. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  417. }
  418. } else {
  419. if (!empty($object->fk_project)) {
  420. $proj = new Project($db);
  421. $proj->fetch($object->fk_project);
  422. $morehtmlref .= ' : '.$proj->getNomUrl(1);
  423. if ($proj->title) {
  424. $morehtmlref .= ' - '.$proj->title;
  425. }
  426. } else {
  427. $morehtmlref .= '';
  428. }
  429. }
  430. }
  431. $morehtmlref .= '</div>';
  432. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  433. print '<div class="fichecenter">';
  434. print '<div class="fichehalfleft">';
  435. print '<div class="underbanner clearboth"></div>';
  436. print '<table class="border centpercent">';
  437. print "<tr><td>".$langs->trans("Author").'</td><td colspan="3">'.$author->getFullName($langs)."</td></tr>";
  438. if (empty($conf->global->FICHINTER_DISABLE_DETAILS)) {
  439. // Duration
  440. print '<tr><td class="titlefield">'.$langs->trans("TotalDuration").'</td>';
  441. print '<td colspan="3">';
  442. print convertSecondToTime($object->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
  443. print '</td></tr>';
  444. }
  445. print '<tr><td>'.$langs->trans("Description").'</td><td colspan="3">'.nl2br($object->description)."</td></tr>";
  446. // Contract
  447. if (!empty($conf->contrat->enabled)) {
  448. $langs->load('contracts');
  449. print '<tr>';
  450. print '<td>';
  451. print '<table class="nobordernopadding" width="100%"><tr><td>';
  452. print $langs->trans('Contract');
  453. print '</td>';
  454. if ($action != 'contrat') {
  455. print '<td class="right"><a href="'.$_SERVER["PHP_SELF"].'?action=contrat&amp;id='.$object->id.'">';
  456. print img_edit($langs->trans('SetContract'), 1);
  457. print '</a></td>';
  458. }
  459. print '</tr></table>';
  460. print '</td><td>';
  461. if ($action == 'contrat') {
  462. $formcontract = new Formcontract($db);
  463. $formcontract->formSelectContract($_SERVER["PHP_SELF"].'?id='.$object->id, $object->socid, $object->fk_contrat, 'contratid', 0, 1);
  464. } else {
  465. if ($object->fk_contrat) {
  466. $contratstatic = new Contrat($db);
  467. $contratstatic->fetch($object->fk_contrat);
  468. print $contratstatic->getNomUrl(0, '', 1);
  469. } else {
  470. print "&nbsp;";
  471. }
  472. }
  473. print '</td>';
  474. print '</tr>';
  475. }
  476. print "</table>";
  477. print '</div>';
  478. print '<div class="fichehalfright">';
  479. print '<div class="underbanner clearboth"></div>';
  480. $title = $langs->trans("Recurrence");
  481. print load_fiche_titre($title, '', 'calendar');
  482. print '<table class="border centpercent">';
  483. // if "frequency" is empty or = 0, the reccurence is disabled
  484. print '<tr><td class="titlefield">';
  485. print '<table class="nobordernopadding" width="100%"><tr><td>';
  486. print $langs->trans('Frequency');
  487. print '</td>';
  488. if ($action != 'editfrequency' && $user->rights->ficheinter->creer) {
  489. print '<td class="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editfrequency&token='.newToken().'&id='.$id.'">';
  490. print img_edit($langs->trans('Edit'), 1).'</a></td>';
  491. }
  492. print '</tr></table>';
  493. print '</td><td>';
  494. if ($action == 'editfrequency') {
  495. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
  496. print '<input type="hidden" name="action" value="setfrequency">';
  497. print '<input type="hidden" name="token" value="'.newToken().'">';
  498. print '<table class="nobordernopadding">';
  499. print '<tr><td>';
  500. print '<input type="text" name="frequency" value="'.$object->frequency.'" size="5">&nbsp;';
  501. print $form->selectarray('unit_frequency', array('d'=>$langs->trans('Day'), 'm'=>$langs->trans('Month'), 'y'=>$langs->trans('Year')), ($object->unit_frequency ? $object->unit_frequency : 'm'));
  502. print '</td>';
  503. print '<td class="left"><input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
  504. print '</tr></table></form>';
  505. } else {
  506. if ($object->frequency > 0) {
  507. print $langs->trans('FrequencyPer_'.$object->unit_frequency, $object->frequency);
  508. } else {
  509. print $langs->trans("NotARecurringInterventionalTemplate");
  510. }
  511. }
  512. print '</td></tr>';
  513. // Date when
  514. print '<tr><td>';
  515. if ($user->rights->ficheinter->creer && ($action == 'date_when' || $object->frequency > 0)) {
  516. print $form->editfieldkey($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $user->rights->facture->creer, 'day');
  517. } else {
  518. print $langs->trans("NextDateToExecution");
  519. }
  520. print '</td><td>';
  521. if ($action == 'date_when' || $object->frequency > 0) {
  522. print $form->editfieldval($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $user->rights->facture->creer, 'day');
  523. }
  524. print '</td>';
  525. print '</tr>';
  526. // Max period / Rest period
  527. print '<tr><td>';
  528. if ($user->rights->ficheinter->creer && ($action == 'nb_gen_max' || $object->frequency > 0)) {
  529. print $form->editfieldkey($langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max, $object, $user->rights->facture->creer);
  530. } else {
  531. print $langs->trans("MaxPeriodNumber");
  532. }
  533. print '</td><td>';
  534. if ($action == 'nb_gen_max' || $object->frequency > 0) {
  535. print $form->editfieldval($langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max ? $object->nb_gen_max : '', $object, $user->rights->facture->creer);
  536. } else {
  537. print '';
  538. }
  539. print '</td>';
  540. print '</tr>';
  541. print '</table>';
  542. // Frequencry/Recurring section
  543. if ($object->frequency > 0) {
  544. print '<br>';
  545. if (empty($conf->cron->enabled)) {
  546. $txtinfoadmin = $langs->trans("EnableAndSetupModuleCron", $langs->transnoentitiesnoconv("Module2300Name"));
  547. print info_admin($txtinfoadmin);
  548. }
  549. print '<div class="underbanner clearboth"></div>';
  550. print '<table class="border centpercent">';
  551. // Nb of generation already done
  552. print '<tr><td class="titlefield">'.$langs->trans("NbOfGenerationOfRecordDone").'</td>';
  553. print '<td>';
  554. print $object->nb_gen_done ? $object->nb_gen_done : '0';
  555. print '</td>';
  556. print '</tr>';
  557. // Date last
  558. print '<tr><td>';
  559. print $langs->trans("DateLastGeneration");
  560. print '</td><td>';
  561. print dol_print_date($object->date_last_gen, 'dayhour');
  562. print '</td>';
  563. print '</tr>';
  564. print '</table>';
  565. print '<br>';
  566. }
  567. print '</div>';
  568. print '</div>';
  569. print '<div class="clearboth"></div><br>';
  570. /*
  571. * Lines
  572. */
  573. $title = $langs->trans("ProductsAndServices");
  574. if (empty($conf->service->enabled)) {
  575. $title = $langs->trans("Products");
  576. } elseif (empty($conf->product->enabled)) {
  577. $title = $langs->trans("Services");
  578. }
  579. print load_fiche_titre($title);
  580. print '<table class="noborder centpercent">';
  581. print '<tr class="liste_titre">';
  582. print '<td>'.$langs->trans("Description").'</td>';
  583. print '<td class="center">'.$langs->trans("Duration").'</td>';
  584. print '</tr>';
  585. $num = count($object->lines);
  586. $i = 0;
  587. while ($i < $num) {
  588. // Show product and description
  589. if (isset($object->lines[$i]->product_type)) {
  590. $type = $object->lines[$i]->product_type;
  591. } else {
  592. $object->lines[$i]->fk_product_type;
  593. }
  594. // Try to enhance type detection using date_start and date_end for free lines when type
  595. // was not saved.
  596. if (!empty($objp->date_start)) {
  597. $type = 1;
  598. }
  599. if (!empty($objp->date_end)) {
  600. $type = 1;
  601. }
  602. // Show line
  603. print '<tr class="oddeven">';
  604. print '<td>';
  605. $text = img_object($langs->trans('Service'), 'service');
  606. print $text.' '.nl2br($object->lines[$i]->desc);
  607. print '</td>';
  608. print '<td class="center">'.convertSecondToTime($object->lines[$i]->duree).'</td>';
  609. print "</tr>\n";
  610. $i++;
  611. }
  612. print '</table>';
  613. /*
  614. * Action bar
  615. */
  616. print '<div class="tabsAction">';
  617. if ($user->rights->ficheinter->creer) {
  618. print '<div class="inline-block divButAction">';
  619. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=createfrommodel&token='.newToken().'';
  620. print '&socid='.$object->thirdparty->id.'&id='.$object->id.'">';
  621. print $langs->trans("AddIntervention").'</a></div>';
  622. }
  623. if ($user->rights->ficheinter->supprimer) {
  624. print '<div class="inline-block divButAction">';
  625. print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&id='.$object->id.'">';
  626. print $langs->trans('Delete').'</a></div>';
  627. }
  628. print '</div>';
  629. } else {
  630. print $langs->trans("ErrorRecordNotFound");
  631. }
  632. } else {
  633. /*
  634. * List mode
  635. */
  636. $sql = "SELECT f.rowid as fich_rec, s.nom as name, s.rowid as socid, f.rowid as facid, f.titre as title,";
  637. $sql .= " f.duree, f.fk_contrat, f.fk_projet as fk_project, f.frequency, f.nb_gen_done, f.nb_gen_max,";
  638. $sql .= " f.date_last_gen, f.date_when, f.datec";
  639. $sql .= " FROM ".MAIN_DB_PREFIX."fichinter_rec as f";
  640. $sql .= " , ".MAIN_DB_PREFIX."societe as s ";
  641. if (empty($user->rights->societe->client->voir) && !$socid) {
  642. $sql .= " , ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  643. }
  644. $sql .= " WHERE f.fk_soc = s.rowid";
  645. $sql .= " AND f.entity = ".$conf->entity;
  646. if ($socid) {
  647. $sql .= " AND s.rowid = ".((int) $socid);
  648. }
  649. if (empty($user->rights->societe->client->voir) && !$socid) {
  650. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  651. }
  652. if ($search_ref) {
  653. $sql .= natural_search('f.titre', $search_ref);
  654. }
  655. if ($search_societe) {
  656. $sql .= natural_search('s.nom', $search_societe);
  657. }
  658. if ($search_frequency == '1') {
  659. $sql .= ' AND f.frequency > 0';
  660. }
  661. if ($search_frequency == '0') {
  662. $sql .= ' AND (f.frequency IS NULL or f.frequency = 0)';
  663. }
  664. //$sql .= " ORDER BY $sortfield $sortorder, rowid DESC ";
  665. // $sql .= $db->plimit($limit + 1, $offset);
  666. $resql = $db->query($sql);
  667. if ($resql) {
  668. $num = $db->num_rows($resql);
  669. print_barre_liste($langs->trans("RepeatableIntervention"), $page, $_SERVER['PHP_SELF'], "&socid=$socid", $sortfield, $sortorder, '', $num, '', 'intervention');
  670. print '<span class="opacitymedium">'.$langs->trans("ToCreateAPredefinedIntervention").'</span><br><br>';
  671. $i = 0;
  672. print '<table class="noborder centpercent">';
  673. print '<tr class="liste_titre">';
  674. print_liste_field_titre("Ref", $_SERVER['PHP_SELF'], "f.titre", "", "", 'width="200px"', $sortfield, $sortorder, 'left ');
  675. print_liste_field_titre("Company", $_SERVER['PHP_SELF'], "s.nom", "", "", 'width="200px"', $sortfield, $sortorder, 'left ');
  676. if (!empty($conf->contrat->enabled)) {
  677. print_liste_field_titre("Contract", $_SERVER['PHP_SELF'], "f.fk_contrat", "", "", 'width="100px"', $sortfield, $sortorder, 'left ');
  678. }
  679. if (!empty($conf->projet->enabled)) {
  680. print_liste_field_titre("Project", $_SERVER['PHP_SELF'], "f.fk_project", "", "", 'width="100px"', $sortfield, $sortorder, 'left ');
  681. }
  682. print_liste_field_titre("Duration", $_SERVER['PHP_SELF'], 'f.duree', '', '', 'width="50px"', $sortfield, $sortorder, 'right ');
  683. // Recurring or not
  684. print_liste_field_titre("Frequency", $_SERVER['PHP_SELF'], "f.frequency", "", "", 'width="100px"', $sortfield, $sortorder, 'center ');
  685. print_liste_field_titre("NbOfGenerationDoneShort", $_SERVER['PHP_SELF'], "f.nb_gen_done", "", "", 'width="100px"', $sortfield, $sortorder, 'center ');
  686. print_liste_field_titre("DateLastGeneration", $_SERVER['PHP_SELF'], "f.date_last_gen", "", "", 'width="100px"', $sortfield, $sortorder, 'center ');
  687. print_liste_field_titre("NextDateToIntervention", $_SERVER['PHP_SELF'], "f.date_when", "", "", 'width="100px"', $sortfield, $sortorder, 'center ');
  688. print '<th width="100px"></th>';
  689. print "</tr>\n";
  690. // les filtres à faire ensuite
  691. if ($num > 0) {
  692. while ($i < min($num, $limit)) {
  693. $objp = $db->fetch_object($resql);
  694. print '<tr class="oddeven">';
  695. print '<td><a href="'.$_SERVER['PHP_SELF'].'?id='.$objp->fich_rec.'">';
  696. print img_object($langs->trans("ShowIntervention"), "intervention").' '.$objp->title;
  697. print "</a></td>\n";
  698. if ($objp->socid) {
  699. $companystatic->id = $objp->socid;
  700. $companystatic->name = $objp->name;
  701. print '<td>'.$companystatic->getNomUrl(1, 'customer').'</td>';
  702. } else {
  703. print '<td>'.$langs->trans("None").'</td>';
  704. }
  705. if (!empty($conf->contrat->enabled)) {
  706. print '<td>';
  707. if ($objp->fk_contrat > 0) {
  708. $contratstatic->fetch($objp->fk_contrat);
  709. print $contratstatic->getNomUrl(1);
  710. }
  711. print '</td>';
  712. }
  713. if (!empty($conf->projet->enabled)) {
  714. print '<td>';
  715. if ($objp->fk_project > 0) {
  716. $projectstatic->fetch($objp->fk_project);
  717. print $projectstatic->getNomUrl(1);
  718. }
  719. print '</td>';
  720. }
  721. print '<td class=right>'.convertSecondToTime($objp->duree).'</td>';
  722. print '<td class="center">'.yn($objp->frequency ? 1 : 0).'</td>';
  723. print '<td class="center">';
  724. if ($objp->frequency) {
  725. print $objp->nb_gen_done.($objp->nb_gen_max > 0 ? ' / '.$objp->nb_gen_max : '');
  726. print '</td>';
  727. print '<td class="center">';
  728. print dol_print_date($db->jdate($objp->date_last_gen), 'day');
  729. print '</td>';
  730. print '<td class="center">';
  731. print dol_print_date($db->jdate($objp->date_when), 'day');
  732. print '</td>';
  733. } else {
  734. print '<span class="opacitymedium">'.$langs->trans('NA').'</span>';
  735. print '</td>';
  736. print '<td class="center">';
  737. print '<span class="opacitymedium">'.$langs->trans('NA').'</span>';
  738. print '</td>';
  739. print '<td class="center">';
  740. print '<span class="opacitymedium">'.$langs->trans('NA').'</span>';
  741. print '</td>';
  742. }
  743. if ($user->rights->ficheinter->creer) {
  744. // Action column
  745. print '<td class="center">';
  746. if ($user->rights->ficheinter->creer) {
  747. if (empty($objp->frequency) || $db->jdate($objp->date_when) <= $today) {
  748. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=createfrommodel';
  749. print '&socid='.$objp->socid.'&id='.$objp->fich_rec.'">';
  750. print $langs->trans("CreateFichInter").'</a>';
  751. } else {
  752. print $langs->trans("DateIsNotEnough");
  753. }
  754. } else {
  755. print "&nbsp;";
  756. }
  757. print "</td>";
  758. print "</tr>\n";
  759. $i++;
  760. }
  761. }
  762. } else {
  763. print '<tr class="oddeven"><td colspan="10"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  764. }
  765. print "</table>";
  766. $db->free($resql);
  767. } else {
  768. dol_print_error($db);
  769. }
  770. }
  771. }
  772. llxFooter();
  773. $db->close();