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