dolibarr  16.0.1
card-rec.php
Go to the documentation of this file.
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 
33 require '../main.inc.php';
34 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinterrec.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
37 
38 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
40 if (!empty($conf->project->enabled)) {
41  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
42  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
43 }
44 if (!empty($conf->contrat->enabled)) {
45  require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
46  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcontract.class.php';
47 }
48 
49 // Load translation files required by the page
50 $langs->loadLangs(array("interventions", "admin", "compta", "bills"));
51 
52 // Security check
53 $id = (GETPOST('fichinterid', 'int') ?GETPOST('fichinterid', 'int') : GETPOST('id', 'int'));
54 $action = GETPOST('action', 'aZ09');
55 if ($user->socid) {
56  $socid = $user->socid;
57 }
58 $objecttype = 'fichinter_rec';
59 if ($action == "create" || $action == "add") {
60  $objecttype = '';
61 }
62 $result = restrictedArea($user, 'ficheinter', $id, $objecttype);
63 
64 if ($page == -1) {
65  $page = 0;
66 }
67 
68 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
69 $offset = $limit * $page;
70 
71 $sortorder = GETPOST('sortorder', 'aZ09comma');
72 $sortfield = GETPOST('sortfield', 'aZ09comma');
73 if ($sortorder == "") {
74  $sortorder = "DESC";
75 }
76 
77 if ($sortfield == "") {
78  $sortfield = "f.datec";
79 }
80 
81 $object = new FichinterRec($db);
82 $extrafields = new ExtraFields($db);
83 
84 
85 $arrayfields = array(
86  'f.titre'=>array('label'=>"Ref", 'checked'=>1),
87  's.nom'=>array('label'=>"ThirdParty", 'checked'=>1),
88  'f.fk_contrat'=>array('label'=>"Contract", 'checked'=>1),
89  'f.duree'=>array('label'=>"Duration", 'checked'=>1),
90  'f.total_ttc'=>array('label'=>"AmountTTC", 'checked'=>1),
91  'f.frequency'=>array('label'=>"RecurringInvoiceTemplate", 'checked'=>1),
92  'f.nb_gen_done'=>array('label'=>"NbOfGenerationDoneShort", 'checked'=>1),
93  'f.date_last_gen'=>array('label'=>"DateLastGeneration", 'checked'=>1),
94  'f.date_when'=>array('label'=>"NextDateToExecution", 'checked'=>1),
95  'f.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500),
96  'f.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500),
97 );
98 
99 
100 /*
101  * Actions
102  */
103 
104 
105 // Create predefined intervention
106 if ($action == 'add') {
107  if (!GETPOST('titre')) {
108  setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("Title")), null, 'errors');
109  $action = "create";
110  $error++;
111  }
112 
113  if (!GETPOST('socid')) {
114  setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("Customer")), null, 'errors');
115  $action = "create";
116  $error++;
117  }
118 
119  // gestion des fréquences et des échéances
120  $frequency = GETPOST('frequency', 'int');
121  $reyear = GETPOST('reyear');
122  $remonth = GETPOST('remonth');
123  $reday = GETPOST('reday');
124  $rehour = GETPOST('rehour');
125  $remin = GETPOST('remin');
126  $nb_gen_max = (GETPOST('nb_gen_max', 'int') ?GETPOST('nb_gen_max', 'int') : 0);
127  if (GETPOST('frequency')) {
128  if (empty($reyear) || empty($remonth) || empty($reday)) {
129  setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("Date")), null, 'errors');
130  $action = "create";
131  $error++;
132  }
133  if ($nb_gen_max === '') {
134  setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("MaxPeriodNumber")), null, 'errors');
135  $action = "create";
136  $error++;
137  }
138  }
139 
140  if (!$error) {
141  $object->id_origin = $id;
142  $object->title = GETPOST('titre', 'alpha');
143  $object->description = GETPOST('description', 'restricthtml');
144  $object->socid = GETPOST('socid', 'alpha');
145  $object->fk_project = GETPOST('projectid', 'int');
146  $object->fk_contract = GETPOST('contractid', 'int');
147 
148  $object->frequency = $frequency;
149  $object->unit_frequency = GETPOST('unit_frequency', 'alpha');
150  $object->nb_gen_max = $nb_gen_max;
151  $object->auto_validate = GETPOST('auto_validate', 'int');
152 
153  $date_next_execution = dol_mktime($rehour, $remin, 0, $remonth, $reday, $reyear);
154  $object->date_when = $date_next_execution;
155 
156  if ($object->create($user) > 0) {
157  $id = $object->id;
158  $action = '';
159  } else {
160  setEventMessages($object->error, $object->errors, 'errors');
161  $action = "create";
162  }
163  }
164 } elseif ($action == 'createfrommodel') {
165  $newinter = new Fichinter($db);
166 
167  // on récupère les enregistrements
168  $object->fetch($id);
169  $res = $object->fetch_lines();
170  // on transfert les données de l'un vers l'autre
171  if ($object->socid > 0) {
172  $newinter->socid = $object->socid;
173  $newinter->fk_project = $object->fk_project;
174  $newinter->fk_contrat = $object->fk_contrat;
175  } else {
176  $newinter->socid = GETPOST("socid");
177  }
178 
179  $newinter->entity = $object->entity;
180  $newinter->duree = $object->duree;
181 
182  $newinter->description = $object->description;
183  $newinter->note_private = $object->note_private;
184  $newinter->note_public = $object->note_public;
185 
186  // on créer un nouvelle intervention
187  $extrafields->fetch_name_optionals_label($newinter->table_element);
188 
189  $array_options = $extrafields->getOptionalsFromPost($newinter->table_element);
190  $newinter->array_options = $array_options;
191 
192  $newfichinterid = $newinter->create($user);
193 
194  if ($newfichinterid > 0) {
195  // Now we add line of details
196  foreach ($object->lines as $line) {
197  $newinter->addline($user, $newfichinterid, $line->desc, $line->datei, $line->duree, '');
198  }
199 
200  // on update le nombre d'inter crée à partir du modèle
201  $object->updateNbGenDone();
202  //on redirige vers la fiche d'intervention nouvellement crée
203  header('Location: '.DOL_URL_ROOT.'/fichinter/card.php?id='.$newfichinterid);
204  exit;
205  } else {
206  setEventMessages($newinter->error, $newinter->errors, 'errors');
207  $action = '';
208  }
209 } elseif ($action == 'delete' && $user->rights->ficheinter->supprimer) {
210  // delete modele
211  $object->fetch($id);
212  $object->delete();
213  $id = 0;
214  header('Location: '.$_SERVER["PHP_SELF"]);
215  exit;
216 } elseif ($action == 'setfrequency' && $user->rights->ficheinter->creer) {
217  // Set frequency and unit frequency
218  $object->fetch($id);
219  $object->setFrequencyAndUnit(GETPOST('frequency', 'int'), GETPOST('unit_frequency', 'alpha'));
220 } elseif ($action == 'setdate_when' && $user->rights->ficheinter->creer) {
221  // Set next date of execution
222  $object->fetch($id);
223  $date = dol_mktime(GETPOST('date_whenhour'), GETPOST('date_whenmin'), 0, GETPOST('date_whenmonth'), GETPOST('date_whenday'), GETPOST('date_whenyear'));
224  if (!empty($date)) {
225  $object->setNextDate($date);
226  }
227 } elseif ($action == 'setnb_gen_max' && $user->rights->ficheinter->creer) {
228  // Set max period
229  $object->fetch($id);
230  $object->setMaxPeriod(GETPOST('nb_gen_max', 'int'));
231 }
232 
233 
234 /*
235  * View
236  */
237 
238 $help_url = '';
239 
240 llxHeader('', $langs->trans("RepeatableIntervention"), $help_url);
241 
242 $form = new Form($db);
243 $companystatic = new Societe($db);
244 if (!empty($conf->contrat->enabled)) {
245  $contratstatic = new Contrat($db);
246 }
247 if (!empty($conf->project->enabled)) {
248  $projectstatic = new Project($db);
249 }
250 
251 $now = dol_now();
252 $tmparray = dol_getdate($now);
253 $today = dol_mktime(23, 59, 59, $tmparray['mon'], $tmparray['mday'], $tmparray['year']); // Today is last second of current day
254 
255 
256 
257 /*
258  * Create mode
259  */
260 if ($action == 'create') {
261  print load_fiche_titre($langs->trans("CreateRepeatableIntervention"), '', 'intervention');
262 
263  $object = new Fichinter($db); // Source invoice
264  //$object = new Managementfichinter($db); // Source invoice
265 
266  if ($object->fetch($id, $ref) > 0) {
267  print '<form action="card-rec.php" method="post">';
268  print '<input type="hidden" name="token" value="'.newToken().'">';
269  print '<input type="hidden" name="action" value="add">';
270  print '<input type="hidden" name="fichinterid" value="'.$object->id.'">';
271 
272  print dol_get_fiche_head();
273 
274  $rowspan = 4;
275  if (!empty($conf->project->enabled) && $object->fk_project > 0) {
276  $rowspan++;
277  }
278  if (!empty($conf->contrat->enabled) && $object->fk_contrat > 0) {
279  $rowspan++;
280  }
281 
282  print '<table class="border centpercent">';
283 
284  $object->fetch_thirdparty();
285 
286  // Third party
287  print '<tr><td>'.$langs->trans("Customer").'</td><td>';
288  print $form->select_company($object->thirdparty->id, 'socid', '', 0, 1);
289 
290  //.$object->thirdparty->getNomUrl(1,'customer').
291  print '</td><td>';
292  print $langs->trans("Comment");
293  print '</td></tr>';
294 
295  // Title
296  print '<tr><td class="fieldrequired">'.$langs->trans("Title").'</td><td>';
297  print '<input class="flat quatrevingtpercent" type="text" name="titre" value="'.dol_escape_htmltag(GETPOST("titre", "alphanohtml")).'">';
298  print '</td>';
299 
300  // Note
301  print '<td rowspan="'.$rowspan.'" valign="top">';
302  print '<textarea class="flat" name="description" wrap="soft" cols="60" rows="'.ROWS_4.'">';
303  print $object->description.'</textarea>';
304  print '</td></tr>';
305 
306  // Author
307  print "<tr><td>".$langs->trans("Author")."</td><td>".$user->getFullName($langs)."</td></tr>";
308 
309  if (empty($conf->global->FICHINTER_DISABLE_DETAILS)) {
310  // Duration
311  print '<tr><td>'.$langs->trans("TotalDuration").'</td>';
312  print '<td colspan="3">'.convertSecondToTime($object->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY).'</td>';
313  print '</tr>';
314  }
315 
316  // Project
317  if (!empty($conf->project->enabled)) {
318  $formproject = new FormProjets($db);
319  print "<tr><td>".$langs->trans("Project")."</td><td>";
320  $projectid = GETPOST('projectid') ?GETPOST('projectid') : $object->fk_project;
321 
322  $numprojet = $formproject->select_projects($object->thirdparty->id, $projectid, 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 0, 0, '');
323  print ' &nbsp; <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$object->thirdparty->id;
324  print '&action=create&status=1&backtopage='.urlencode($_SERVER["PHP_SELF"]).'?action=create';
325  print '&socid='.$object->thirdparty->id.(!empty($id) ? '&id='.$id : '').'">';
326  print $langs->trans("AddProject").'</a>';
327  print "</td></tr>";
328  }
329 
330  // Contrat
331  if (!empty($conf->contrat->enabled)) {
332  $formcontract = new FormContract($db);
333  print "<tr><td>".$langs->trans("Contract")."</td><td>";
334  $contractid = GETPOST('contractid') ?GETPOST('contractid') : $object->fk_contract;
335  $numcontract = $formcontract->select_contract($object->thirdparty->id, $contractid, 'contracttid');
336  print "</td></tr>";
337  }
338  print "</table>";
339 
340  print '<br><br>';
341 
343  // Autogeneration
344  $title = $langs->trans("Recurrence");
345  print load_fiche_titre($title, '', 'calendar');
346 
347  print '<table class="border centpercent">';
348 
349  // Frequency
350  print '<tr><td class="titlefieldcreate">';
351  print $form->textwithpicto($langs->trans("Frequency"), $langs->transnoentitiesnoconv('toolTipFrequency'));
352  print "</td><td>";
353  print '<input type="text" name="frequency" value="'.GETPOST('frequency', 'int').'" size="4">&nbsp;';
354  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'));
355  print "</td></tr>";
356 
357  // First date of execution for cron
358  print "<tr><td>".$langs->trans('NextDateToExecution')."</td><td>";
359  if ($date_next_execution != "") {
360  $date_next_execution = (GETPOST('remonth') ? dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')) : -1);
361  }
362  print $form->selectDate($date_next_execution, '', 1, 1, '', "add", 1, 1);
363  print "</td></tr>";
364 
365  // Number max of generation
366  print "<tr><td>".$langs->trans("MaxPeriodNumber")."</td><td>";
367  print '<input type="text" name="nb_gen_max" value="'.GETPOST('nb_gen_max', 'int').'" size="5">';
368  print "</td></tr>";
369 
370  print "</table>";
371 
372  print '<br>';
373 
374  $title = $langs->trans("ProductsAndServices");
375  if (empty($conf->service->enabled)) {
376  $title = $langs->trans("Products");
377  } elseif (empty($conf->product->enabled)) {
378  $title = $langs->trans("Services");
379  }
380 
381  print load_fiche_titre($title, '', '');
382 
383  /*
384  * Fichinter lines
385  */
386  print '<table class="notopnoleftnoright" width="100%">';
387  print '<tr><td colspan="3">';
388 
389  $sql = 'SELECT l.rowid, l.description, l.duree';
390  $sql .= " FROM ".MAIN_DB_PREFIX."fichinterdet as l";
391  $sql .= " WHERE l.fk_fichinter= ".((int) $object->id);
392  //$sql.= " AND l.fk_product is null ";
393  $sql .= " ORDER BY l.rang";
394 
395  $result = $db->query($sql);
396  if ($result) {
397  $num = $db->num_rows($result);
398  $i = 0;
399  $total = 0;
400 
401  echo '<table class="noborder centpercent">';
402  if ($num) {
403  print '<tr class="liste_titre">';
404  print '<td>'.$langs->trans("Description").'</td>';
405  print '<td class="center">'.$langs->trans("Duration").'</td>';
406  print "</tr>\n";
407  }
408  while ($i < $num) {
409  $objp = $db->fetch_object($result);
410  print '<tr class="oddeven">';
411 
412  // Show product and description
413 
414  print '<td>';
415  print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
416 
417  $text = img_object($langs->trans('Service'), 'service');
418 
419  print $text.' '.nl2br($objp->description);
420 
421  // Duration
422  print '<td class="center">'.convertSecondToTime($objp->duree).'</td>';
423  print "</tr>";
424 
425  $i++;
426  }
427  $db->free($result);
428  } else {
429  print $db->error();
430  }
431  print "</table>";
432 
433  print '</td></tr>';
434 
435  print "</table>\n";
436 
437  print dol_get_fiche_end();
438 
439  print $form->buttonsSaveCancel("Create");
440 
441  print "</form>\n";
442  } else {
443  dol_print_error('', "Error, no fichinter ".$object->id);
444  }
445 } elseif ($action == 'selsocforcreatefrommodel') {
446  print load_fiche_titre($langs->trans("CreateRepeatableIntervention"), '', 'intervention');
447  print dol_get_fiche_head('');
448 
449  print '<form name="fichinter" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
450  print '<table class="border centpercent">';
451  print '<tr><td class="fieldrequired">'.$langs->trans("ThirdParty").'</td><td>';
452  print $form->select_company('', 'socid', '', 1, 1);
453  print '</td></tr>';
454  print '</table>';
455 
456  print dol_get_fiche_end();
457 
458  print '<input type="hidden" name="action" value="createfrommodel">';
459  print '<input type="hidden" name="id" value="'.$id.'">';
460  print $form->buttonsSaveCancel("CreateDraftIntervention", '');
461 
462  print '</form>';
463 } else {
464  /*
465  * View mode
466  *
467  */
468  if ($id > 0) {
469  if ($object->fetch($id) > 0) {
470  $object->fetch_thirdparty();
471 
472  $author = new User($db);
473  $author->fetch($object->user_author);
474 
475  $head = fichinter_rec_prepare_head($object);
476 
477  print dol_get_fiche_head($head, 'card', $langs->trans("PredefinedInterventional"), 0, 'intervention');
478 
479  // Intervention card
480  $linkback = '<a href="card-rec.php">'.$langs->trans("BackToList").'</a>';
481 
482  $morehtmlref = '<div class="refidno">';
483  // Thirdparty
484 
485  $morehtmlref .= $langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
486  // Project
487  if (!empty($conf->project->enabled)) {
488  $formproject = new FormProjets($db);
489  $langs->load("projects");
490  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
491  if ($user->rights->ficheinter->creer) {
492  if ($action != 'classify') {
493  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">';
494  $morehtmlref .= img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
495  }
496  if ($action == 'classify') {
497  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
498  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
499  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
500  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
501  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
502  $morehtmlref .= '</form>';
503  } else {
504  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
505  }
506  } else {
507  if (!empty($object->fk_project)) {
508  $proj = new Project($db);
509  $proj->fetch($object->fk_project);
510  $morehtmlref .= ' : '.$proj->getNomUrl(1);
511  if ($proj->title) {
512  $morehtmlref .= ' - '.$proj->title;
513  }
514  } else {
515  $morehtmlref .= '';
516  }
517  }
518  }
519  $morehtmlref .= '</div>';
520 
521  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
522 
523  print '<div class="fichecenter">';
524  print '<div class="fichehalfleft">';
525  print '<div class="underbanner clearboth"></div>';
526 
527  print '<table class="border centpercent">';
528 
529  print "<tr><td>".$langs->trans("Author").'</td><td colspan="3">'.$author->getFullName($langs)."</td></tr>";
530 
531  if (empty($conf->global->FICHINTER_DISABLE_DETAILS)) {
532  // Duration
533  print '<tr><td class="titlefield">'.$langs->trans("TotalDuration").'</td>';
534  print '<td colspan="3">';
535  print convertSecondToTime($object->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
536  print '</td></tr>';
537  }
538 
539  print '<tr><td>'.$langs->trans("Description").'</td><td colspan="3">'.nl2br($object->description)."</td></tr>";
540 
541  // Contract
542  if (!empty($conf->contrat->enabled)) {
543  $langs->load('contracts');
544  print '<tr>';
545  print '<td>';
546 
547  print '<table class="nobordernopadding" width="100%"><tr><td>';
548  print $langs->trans('Contract');
549  print '</td>';
550  if ($action != 'contrat') {
551  print '<td class="right"><a href="'.$_SERVER["PHP_SELF"].'?action=contrat&amp;id='.$object->id.'">';
552  print img_edit($langs->trans('SetContract'), 1);
553  print '</a></td>';
554  }
555  print '</tr></table>';
556  print '</td><td>';
557  if ($action == 'contrat') {
558  $formcontract = new Formcontract($db);
559  $formcontract->formSelectContract($_SERVER["PHP_SELF"].'?id='.$object->id, $object->socid, $object->fk_contrat, 'contratid', 0, 1);
560  } else {
561  if ($object->fk_contrat) {
562  $contratstatic = new Contrat($db);
563  $contratstatic->fetch($object->fk_contrat);
564  print $contratstatic->getNomUrl(0, '', 1);
565  } else {
566  print "&nbsp;";
567  }
568  }
569  print '</td>';
570  print '</tr>';
571  }
572  print "</table>";
573  print '</div>';
574 
575  print '<div class="fichehalfright">';
576  print '<div class="underbanner clearboth"></div>';
577 
578  $title = $langs->trans("Recurrence");
579  print load_fiche_titre($title, '', 'calendar');
580 
581  print '<table class="border centpercent">';
582 
583  // if "frequency" is empty or = 0, the reccurence is disabled
584  print '<tr><td class="titlefield">';
585  print '<table class="nobordernopadding" width="100%"><tr><td>';
586  print $langs->trans('Frequency');
587  print '</td>';
588  if ($action != 'editfrequency' && $user->rights->ficheinter->creer) {
589  print '<td class="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editfrequency&token='.newToken().'&id='.$id.'">';
590  print img_edit($langs->trans('Edit'), 1).'</a></td>';
591  }
592  print '</tr></table>';
593  print '</td><td>';
594  if ($action == 'editfrequency') {
595  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
596  print '<input type="hidden" name="action" value="setfrequency">';
597  print '<input type="hidden" name="token" value="'.newToken().'">';
598  print '<table class="nobordernopadding">';
599  print '<tr><td>';
600  print '<input type="text" name="frequency" value="'.$object->frequency.'" size="5">&nbsp;';
601  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'));
602  print '</td>';
603  print '<td class="left"><input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
604  print '</tr></table></form>';
605  } else {
606  if ($object->frequency > 0) {
607  print $langs->trans('FrequencyPer_'.$object->unit_frequency, $object->frequency);
608  } else {
609  print $langs->trans("NotARecurringInterventionalTemplate");
610  }
611  }
612  print '</td></tr>';
613 
614  // Date when
615  print '<tr><td>';
616  if ($user->rights->ficheinter->creer && ($action == 'date_when' || $object->frequency > 0)) {
617  print $form->editfieldkey($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $user->rights->facture->creer, 'day');
618  } else {
619  print $langs->trans("NextDateToExecution");
620  }
621  print '</td><td>';
622  if ($action == 'date_when' || $object->frequency > 0) {
623  print $form->editfieldval($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $user->rights->facture->creer, 'day');
624  }
625  print '</td>';
626  print '</tr>';
627 
628  // Max period / Rest period
629  print '<tr><td>';
630  if ($user->rights->ficheinter->creer && ($action == 'nb_gen_max' || $object->frequency > 0)) {
631  print $form->editfieldkey($langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max, $object, $user->rights->facture->creer);
632  } else {
633  print $langs->trans("MaxPeriodNumber");
634  }
635 
636  print '</td><td>';
637  if ($action == 'nb_gen_max' || $object->frequency > 0) {
638  print $form->editfieldval($langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max ? $object->nb_gen_max : '', $object, $user->rights->facture->creer);
639  } else {
640  print '';
641  }
642 
643  print '</td>';
644  print '</tr>';
645 
646  print '</table>';
647 
648  // Frequencry/Recurring section
649  if ($object->frequency > 0) {
650  print '<br>';
651  if (empty($conf->cron->enabled)) {
652  $txtinfoadmin = $langs->trans("EnableAndSetupModuleCron", $langs->transnoentitiesnoconv("Module2300Name"));
653  print info_admin($txtinfoadmin);
654  }
655  print '<div class="underbanner clearboth"></div>';
656  print '<table class="border centpercent">';
657 
658  // Nb of generation already done
659  print '<tr><td class="titlefield">'.$langs->trans("NbOfGenerationOfRecordDone").'</td>';
660  print '<td>';
661  print $object->nb_gen_done ? $object->nb_gen_done : '0';
662  print '</td>';
663  print '</tr>';
664 
665  // Date last
666  print '<tr><td>';
667  print $langs->trans("DateLastGeneration");
668  print '</td><td>';
669  print dol_print_date($object->date_last_gen, 'dayhour');
670  print '</td>';
671  print '</tr>';
672  print '</table>';
673  print '<br>';
674  }
675 
676  print '</div>';
677  print '</div>';
678 
679  print '<div class="clearboth"></div><br>';
680 
681  /*
682  * Lines
683  */
684 
685  $title = $langs->trans("ProductsAndServices");
686  if (empty($conf->service->enabled)) {
687  $title = $langs->trans("Products");
688  } elseif (empty($conf->product->enabled)) {
689  $title = $langs->trans("Services");
690  }
691 
692  print load_fiche_titre($title);
693 
694  print '<table class="noborder centpercent">';
695  print '<tr class="liste_titre">';
696  print '<td>'.$langs->trans("Description").'</td>';
697  print '<td class="center">'.$langs->trans("Duration").'</td>';
698  print '</tr>';
699 
700  $num = count($object->lines);
701  $i = 0;
702  while ($i < $num) {
703  // Show product and description
704  if (isset($object->lines[$i]->product_type)) {
705  $type = $object->lines[$i]->product_type;
706  } else {
707  $object->lines[$i]->fk_product_type;
708  }
709  // Try to enhance type detection using date_start and date_end for free lines when type
710  // was not saved.
711  if (!empty($objp->date_start)) {
712  $type = 1;
713  }
714  if (!empty($objp->date_end)) {
715  $type = 1;
716  }
717 
718  // Show line
719  print '<tr class="oddeven">';
720  print '<td>';
721  $text = img_object($langs->trans('Service'), 'service');
722  print $text.' '.nl2br($object->lines[$i]->desc);
723  print '</td>';
724 
725  print '<td class="center">'.convertSecondToTime($object->lines[$i]->duree).'</td>';
726  print "</tr>\n";
727  $i++;
728  }
729  print '</table>';
730 
731  /*
732  * Action bar
733  */
734  print '<div class="tabsAction">';
735 
736  if ($user->rights->ficheinter->creer) {
737  print '<div class="inline-block divButAction">';
738  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=createfrommodel&token='.newToken().'';
739  print '&socid='.$object->thirdparty->id.'&id='.$object->id.'">';
740  print $langs->trans("AddIntervention").'</a></div>';
741  }
742 
743  if ($user->rights->ficheinter->supprimer) {
744  print '<div class="inline-block divButAction">';
745  print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&id='.$object->id.'">';
746  print $langs->trans('Delete').'</a></div>';
747  }
748  print '</div>';
749  } else {
750  print $langs->trans("ErrorRecordNotFound");
751  }
752  } else {
753  /*
754  * List mode
755  */
756  $sql = "SELECT f.rowid as fich_rec, s.nom as name, s.rowid as socid, f.rowid as facid, f.titre as title,";
757  $sql .= " f.duree, f.fk_contrat, f.fk_projet as fk_project, f.frequency, f.nb_gen_done, f.nb_gen_max,";
758  $sql .= " f.date_last_gen, f.date_when, f.datec";
759 
760  $sql .= " FROM ".MAIN_DB_PREFIX."fichinter_rec as f";
761  $sql .= " , ".MAIN_DB_PREFIX."societe as s ";
762  if (empty($user->rights->societe->client->voir) && !$socid) {
763  $sql .= " , ".MAIN_DB_PREFIX."societe_commerciaux as sc";
764  }
765  $sql .= " WHERE f.fk_soc = s.rowid";
766  $sql .= " AND f.entity = ".$conf->entity;
767  if ($socid) {
768  $sql .= " AND s.rowid = ".((int) $socid);
769  }
770  if (empty($user->rights->societe->client->voir) && !$socid) {
771  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
772  }
773  if ($search_ref) {
774  $sql .= natural_search('f.titre', $search_ref);
775  }
776  if ($search_societe) {
777  $sql .= natural_search('s.nom', $search_societe);
778  }
779  if ($search_frequency == '1') {
780  $sql .= ' AND f.frequency > 0';
781  }
782  if ($search_frequency == '0') {
783  $sql .= ' AND (f.frequency IS NULL or f.frequency = 0)';
784  }
785 
786 
787  //$sql .= " ORDER BY $sortfield $sortorder, rowid DESC ";
788  // $sql .= $db->plimit($limit + 1, $offset);
789 
790  $resql = $db->query($sql);
791  if ($resql) {
792  $num = $db->num_rows($resql);
793 
794  print_barre_liste($langs->trans("RepeatableIntervention"), $page, $_SERVER['PHP_SELF'], "&socid=$socid", $sortfield, $sortorder, '', $num, '', 'intervention');
795 
796  print '<span class="opacitymedium">'.$langs->trans("ToCreateAPredefinedIntervention").'</span><br><br>';
797 
798  $i = 0;
799  print '<table class="noborder centpercent">';
800  print '<tr class="liste_titre">';
801  print_liste_field_titre("Ref", $_SERVER['PHP_SELF'], "f.titre", "", "", 'width="200px"', $sortfield, $sortorder, 'left ');
802  print_liste_field_titre("Company", $_SERVER['PHP_SELF'], "s.nom", "", "", 'width="200px"', $sortfield, $sortorder, 'left ');
803  if (!empty($conf->contrat->enabled)) {
804  print_liste_field_titre("Contract", $_SERVER['PHP_SELF'], "f.fk_contrat", "", "", 'width="100px"', $sortfield, $sortorder, 'left ');
805  }
806  if (!empty($conf->project->enabled)) {
807  print_liste_field_titre("Project", $_SERVER['PHP_SELF'], "f.fk_project", "", "", 'width="100px"', $sortfield, $sortorder, 'left ');
808  }
809  print_liste_field_titre("Duration", $_SERVER['PHP_SELF'], 'f.duree', '', '', 'width="50px"', $sortfield, $sortorder, 'right ');
810  // Recurring or not
811  print_liste_field_titre("Frequency", $_SERVER['PHP_SELF'], "f.frequency", "", "", 'width="100px"', $sortfield, $sortorder, 'center ');
812  print_liste_field_titre("NbOfGenerationDoneShort", $_SERVER['PHP_SELF'], "f.nb_gen_done", "", "", 'width="100px"', $sortfield, $sortorder, 'center ');
813  print_liste_field_titre("DateLastGeneration", $_SERVER['PHP_SELF'], "f.date_last_gen", "", "", 'width="100px"', $sortfield, $sortorder, 'center ');
814  print_liste_field_titre("NextDateToIntervention", $_SERVER['PHP_SELF'], "f.date_when", "", "", 'width="100px"', $sortfield, $sortorder, 'center ');
815  print '<th width="100px"></th>';
816  print "</tr>\n";
817 
818 
819  // les filtres à faire ensuite
820 
821  if ($num > 0) {
822  while ($i < min($num, $limit)) {
823  $objp = $db->fetch_object($resql);
824 
825  print '<tr class="oddeven">';
826  print '<td><a href="'.$_SERVER['PHP_SELF'].'?id='.$objp->fich_rec.'">';
827  print img_object($langs->trans("ShowIntervention"), "intervention").' '.$objp->title;
828  print "</a></td>\n";
829  if ($objp->socid) {
830  $companystatic->id = $objp->socid;
831  $companystatic->name = $objp->name;
832  print '<td>'.$companystatic->getNomUrl(1, 'customer').'</td>';
833  } else {
834  print '<td>'.$langs->trans("None").'</td>';
835  }
836 
837  if (!empty($conf->contrat->enabled)) {
838  print '<td>';
839  if ($objp->fk_contrat > 0) {
840  $contratstatic->fetch($objp->fk_contrat);
841  print $contratstatic->getNomUrl(1);
842  }
843  print '</td>';
844  }
845  if (!empty($conf->project->enabled)) {
846  print '<td>';
847  if ($objp->fk_project > 0) {
848  $projectstatic->fetch($objp->fk_project);
849  print $projectstatic->getNomUrl(1);
850  }
851  print '</td>';
852  }
853 
854  print '<td class=right>'.convertSecondToTime($objp->duree).'</td>';
855 
856  print '<td class="center">'.yn($objp->frequency ? 1 : 0).'</td>';
857 
858  print '<td class="center">';
859  if ($objp->frequency) {
860  print $objp->nb_gen_done.($objp->nb_gen_max > 0 ? ' / '.$objp->nb_gen_max : '');
861  print '</td>';
862 
863  print '<td class="center">';
864  print dol_print_date($db->jdate($objp->date_last_gen), 'day');
865  print '</td>';
866 
867  print '<td class="center">';
868  print dol_print_date($db->jdate($objp->date_when), 'day');
869  print '</td>';
870  } else {
871  print '<span class="opacitymedium">'.$langs->trans('NA').'</span>';
872  print '</td>';
873  print '<td class="center">';
874  print '<span class="opacitymedium">'.$langs->trans('NA').'</span>';
875  print '</td>';
876  print '<td class="center">';
877  print '<span class="opacitymedium">'.$langs->trans('NA').'</span>';
878  print '</td>';
879  }
880 
881  if ($user->rights->ficheinter->creer) {
882  // Action column
883  print '<td class="center">';
884  if ($user->rights->ficheinter->creer) {
885  if (empty($objp->frequency) || $db->jdate($objp->date_when) <= $today) {
886  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=createfrommodel';
887  print '&socid='.$objp->socid.'&id='.$objp->fich_rec.'">';
888  print $langs->trans("CreateFichInter").'</a>';
889  } else {
890  print $langs->trans("DateIsNotEnough");
891  }
892  } else {
893  print "&nbsp;";
894  }
895 
896  print "</td>";
897 
898  print "</tr>\n";
899  $i++;
900  }
901  }
902  } else {
903  print '<tr class="oddeven"><td colspan="10"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
904  }
905 
906  print "</table>";
907  $db->free($resql);
908  } else {
909  dol_print_error($db);
910  }
911  }
912 }
913 llxFooter();
914 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Class to manage interventions.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Definition: user.class.php:44
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
fichinter_rec_prepare_head($object)
Prepare array with list of tabs.
Class to manage contracts.
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save"&&empty($cancel)) $help_url
View.
Definition: agenda.php:116
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= 'hideonsmartphone', $textfordropdown= '')
Show information for admin users or standard users.
Class to manage projects.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
Class to manage building of HTML components.
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->supplier_invoice->lire)) if(isModEnabled('don')&&!empty($user->rights->don->lire)) if(isModEnabled('tax')&&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture')&&isModEnabled('commande')&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
Class to manage generation of HTML components for contract module.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Classe de gestion des factures recurrentes/Modeles.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:73
convertSecondToTime($iSecond, $format= 'all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
Definition: date.lib.php:236