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