card-rec.php 32 KB

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