card-rec.php 32 KB

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