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