Issues (2811)

public/htdocs/fichinter/card-rec.php (7 issues)

1
<?php
2
3
/* Copyright (C) 2002-2003  Rodolphe Quiedeville        <[email protected]>
4
 * Copyright (C) 2004-2015  Laurent Destailleur         <[email protected]>
5
 * Copyright (C) 2005-2012  Regis Houssin               <[email protected]>
6
 * Copyright (C) 2013       Florian Henry               <[email protected]>
7
 * Copyright (C) 2013       Juanjo Menent               <[email protected]>
8
 * Copyright (C) 2015       Jean-François Ferry         <[email protected]>
9
 * Copyright (C) 2012       Cedric Salvador             <[email protected]>
10
 * Copyright (C) 2015       Alexandre Spangaro          <[email protected]>
11
 * Copyright (C) 2016-2018  Charlie Benke               <[email protected]>
12
 * Copyright (C) 2018-2024  Frédéric France             <[email protected]>
13
 * Copyright (C) 2024		William Mead			    <[email protected]>
14
 * Copyright (C) 2024		MDW							<[email protected]>
15
 * Copyright (C) 2024       Rafael San José             <[email protected]>
16
 *
17
 * This program is free software; you can redistribute it and/or modify
18
 * it under the terms of the GNU General Public License as published by
19
 * the Free Software Foundation; either version 3 of the License, or
20
 * (at your option) any later version.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 * GNU General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU General Public License
28
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
29
 */
30
31
use Dolibarr\Code\Contrat\Classes\Contrat;
32
use Dolibarr\Code\Core\Classes\ExtraFields;
33
use Dolibarr\Code\Core\Classes\Form;
34
use Dolibarr\Code\Core\Classes\FormContract;
35
use Dolibarr\Code\Core\Classes\FormProjets;
36
use Dolibarr\Code\FichInter\Classes\Fichinter;
37
use Dolibarr\Code\FichInter\Classes\FichinterRec;
38
use Dolibarr\Code\Projet\Classes\Project;
39
use Dolibarr\Code\Societe\Classes\Societe;
40
use Dolibarr\Code\User\Classes\User;
41
use Dolibarr\Lib\ViewMain;
42
43
/**
44
 *  \file        htdocs/fichinter/card-rec.php
45
 *  \ingroup     intervention
46
 *  \brief       Page to show predefined fichinter
47
 */
48
49
// Load Dolibarr environment
50
require constant('DOL_DOCUMENT_ROOT') . '/main.inc.php';
51
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/fichinter.lib.php';
52
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/date.lib.php';
53
54
// Load translation files required by the page
55
$langs->loadLangs(array("interventions", "admin", "compta", "bills"));
56
57
// Security check
58
$id = (GETPOSTINT('fichinterid') ? GETPOSTINT('fichinterid') : GETPOSTINT('id'));
59
$ref = GETPOST('ref', 'alpha');
60
$date_next_execution = GETPOST('date_next_execution', 'alpha');
61
$action = GETPOST('action', 'aZ09');
62
$cancel = GETPOST('cancel', 'aZ09');
63
$backtopage = GETPOST('backtopage', 'alpha');
64
$socid = GETPOSTINT('socid');
65
if ($user->socid) {
66
    $socid = $user->socid;
67
}
68
$objecttype = 'fichinter_rec';
69
if ($action == "create" || $action == "add") {
70
    $objecttype = '';
71
}
72
$result = restrictedArea($user, 'ficheinter', $id, $objecttype);
73
74
// Load variable for pagination
75
$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
76
$sortfield = GETPOST('sortfield', 'aZ09comma');
77
$sortorder = GETPOST('sortorder', 'aZ09comma');
78
$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
79
if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
80
    // If $page is not defined, or '' or -1 or if we click on clear filters
81
    $page = 0;
82
}
83
$offset = $limit * $page;
84
$pageprev = $page - 1;
85
$pagenext = $page + 1;
86
87
88
$sortorder = GETPOST('sortorder', 'aZ09comma');
89
$sortfield = GETPOST('sortfield', 'aZ09comma');
90
if ($sortorder == "") {
91
    $sortorder = "DESC";
92
}
93
94
if ($sortfield == "") {
95
    $sortfield = "f.datec";
96
}
97
98
$object = new FichinterRec($db);
99
$extrafields = new ExtraFields($db);
100
101
102
$arrayfields = array(
103
    'f.title' => array('label' => "Ref", 'checked' => 1),
104
    's.nom' => array('label' => "ThirdParty", 'checked' => 1),
105
    'f.fk_contrat' => array('label' => "Contract", 'checked' => 1),
106
    'f.duree' => array('label' => "Duration", 'checked' => 1),
107
    'f.total_ttc' => array('label' => "AmountTTC", 'checked' => 1),
108
    'f.frequency' => array('label' => "RecurringInvoiceTemplate", 'checked' => 1),
109
    'f.nb_gen_done' => array('label' => "NbOfGenerationDoneShort", 'checked' => 1),
110
    'f.date_last_gen' => array('label' => "DateLastGeneration", 'checked' => 1),
111
    'f.date_when' => array('label' => "NextDateToExecution", 'checked' => 1),
112
    'f.datec' => array('label' => "DateCreation", 'checked' => 0, 'position' => 500),
113
    'f.tms' => array('label' => "DateModificationShort", 'checked' => 0, 'position' => 500),
114
);
115
116
117
/*
118
 * Actions
119
 */
120
121
if ($cancel) {
122
    /*var_dump($cancel);var_dump($backtopage);var_dump($backtopageforcancel);exit;*/
123
    if (!empty($backtopageforcancel)) {
124
        header("Location: " . $backtopageforcancel);
125
        exit;
126
    } elseif (!empty($backtopage)) {
127
        header("Location: " . $backtopage);
128
        exit;
129
    }
130
    $action = '';
131
}
132
133
// Create predefined intervention
134
if ($action == 'add') {
135
    if (!GETPOST('title')) {
136
        setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("Title")), null, 'errors');
137
        $action = "create";
138
        $error++;
139
    }
140
141
    if (!GETPOST('socid')) {
142
        setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("Customer")), null, 'errors');
143
        $action = "create";
144
        $error++;
145
    }
146
147
    // gestion des fréquences et des échéances
148
    $frequency = GETPOSTINT('frequency');
149
    $reyear = GETPOST('reyear');
150
    $remonth = GETPOST('remonth');
151
    $reday = GETPOST('reday');
152
    $rehour = GETPOST('rehour');
153
    $remin = GETPOST('remin');
154
    $nb_gen_max = GETPOSTINT('nb_gen_max');
155
    if ($frequency) {
156
        if (empty($reyear) || empty($remonth) || empty($reday)) {
157
            setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("Date")), null, 'errors');
158
            $action = "create";
159
            $error++;
160
        } else {
161
            $date_next_execution = dol_mktime($rehour, $remin, 0, $remonth, $reday, $reyear);
162
        }
163
        if ($nb_gen_max === 0) {
164
            setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("MaxPeriodNumber")), null, 'errors');
165
            $action = "create";
166
            $error++;
167
        }
168
    }
169
170
    if (!$error) {
171
        $object->id_origin = $id;
172
        $object->title          = GETPOST('title', 'alpha');
0 ignored issues
show
Documentation Bug introduced by
It seems like GETPOST('title', 'alpha') can also be of type array or array or array. However, the property $title is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
173
        $object->description    = GETPOST('description', 'restricthtml');
0 ignored issues
show
Documentation Bug introduced by
It seems like GETPOST('description', 'restricthtml') can also be of type array or array or array. However, the property $description is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
174
        $object->socid          = GETPOSTINT('socid');
175
        $object->fk_project     = GETPOSTINT('projectid');
176
        $object->fk_contrat     = GETPOSTINT('contractid');
177
178
        $object->frequency = $frequency;
179
        $object->unit_frequency = GETPOST('unit_frequency', 'alpha');
0 ignored issues
show
Documentation Bug introduced by
It seems like GETPOST('unit_frequency', 'alpha') can also be of type array or array or array. However, the property $unit_frequency is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
180
        $object->nb_gen_max = $nb_gen_max;
181
        $object->auto_validate = GETPOSTINT('auto_validate');
182
183
        $object->date_when = $date_next_execution;
184
185
        if ($object->create($user) > 0) {
186
            $id = $object->id;
187
            $action = '';
188
        } else {
189
            setEventMessages($object->error, $object->errors, 'errors');
190
            $action = "create";
191
        }
192
    }
193
} elseif ($action == 'createfrommodel') {
194
    $newinter = new Fichinter($db);
195
196
    // Fetch the stored data
197
    $object->fetch($id);
198
    $res = $object->fetch_lines();
199
    // Transfer the data from one to the other
200
    if ($object->socid > 0) {
201
        $newinter->socid = $object->socid;
202
        $newinter->fk_project = $object->fk_project;
203
        $newinter->fk_contrat = $object->fk_contrat;
204
    } else {
205
        $newinter->socid = GETPOSTINT("socid");
206
    }
207
208
    $newinter->entity = $object->entity;
209
    $newinter->duree = $object->duree;
0 ignored issues
show
Bug Best Practice introduced by
The property duree does not exist on Dolibarr\Code\FichInter\Classes\Fichinter. Since you implemented __set, consider adding a @property annotation.
Loading history...
210
211
    $newinter->description = $object->description;
212
    $newinter->note_private = $object->note_private;
213
    $newinter->note_public = $object->note_public;
214
215
    // on créer un nouvelle intervention
216
    $extrafields->fetch_name_optionals_label($newinter->table_element);
217
218
    $array_options = $extrafields->getOptionalsFromPost($newinter->table_element);
219
    $newinter->array_options = $array_options;
0 ignored issues
show
Documentation Bug introduced by
It seems like $array_options can also be of type integer. However, the property $array_options is declared as type array<string,mixed>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
220
221
    $newfichinterid = $newinter->create($user);
222
223
    if ($newfichinterid > 0) {
224
        // Now we add line of details
225
        foreach ($object->lines as $line) {
226
            $newinter->addline($user, $newfichinterid, $line->desc, $line->datei, $line->duree, '');
227
        }
228
229
        // on update le nombre d'inter crée à partir du modèle
230
        $object->updateNbGenDone();
231
        //on redirige vers la fiche d'intervention nouvellement crée
232
        header('Location: ' . constant('BASE_URL') . '/fichinter/card.php?id=' . $newfichinterid);
233
        exit;
234
    } else {
235
        setEventMessages($newinter->error, $newinter->errors, 'errors');
236
        $action = '';
237
    }
238
} elseif ($action == 'delete' && $user->hasRight('ficheinter', 'supprimer')) {
239
    // delete modele
240
    $object->fetch($id);
241
    $object->delete($user);
242
    $id = 0;
243
    header('Location: ' . $_SERVER["PHP_SELF"]);
244
    exit;
245
} elseif ($action == 'setfrequency' && $user->hasRight('ficheinter', 'creer')) {
246
    // Set frequency and unit frequency
247
    $object->fetch($id);
248
    $object->setFrequencyAndUnit(GETPOST('frequency', 'int'), GETPOST('unit_frequency', 'alpha'));
249
} elseif ($action == 'setdate_when' && $user->hasRight('ficheinter', 'creer')) {
250
    // Set next date of execution
251
    $object->fetch($id);
252
    $date = dol_mktime(GETPOST('date_whenhour'), GETPOST('date_whenmin'), 0, GETPOST('date_whenmonth'), GETPOST('date_whenday'), GETPOST('date_whenyear'));
253
    if (!empty($date)) {
254
        $object->setNextDate($date);
255
    }
256
} elseif ($action == 'setnb_gen_max' && $user->hasRight('ficheinter', 'creer')) {
257
    // Set max period
258
    $object->fetch($id);
259
    $object->setMaxPeriod(GETPOSTINT('nb_gen_max'));
260
}
261
262
263
/*
264
 *	View
265
 */
266
267
$help_url = '';
268
269
ViewMain::llxHeader('', $langs->trans("RepeatableIntervention"), $help_url);
270
271
$form = new Form($db);
272
$companystatic = new Societe($db);
273
if (isModEnabled('contract')) {
274
    $contratstatic = new Contrat($db);
275
}
276
if (isModEnabled('project')) {
277
    $projectstatic = new Project($db);
278
}
279
280
$now = dol_now();
281
$tmparray = dol_getdate($now);
282
$today = dol_mktime(23, 59, 59, $tmparray['mon'], $tmparray['mday'], $tmparray['year']); // Today is last second of current day
283
284
285
286
/*
287
 * Create mode
288
 */
289
if ($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')) {
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="' . constant('BASE_URL') . '/projet/card.php?socid=' . $object->thirdparty->id;
354
            print '&action=create&status=1&backtopage=' . $_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
372
        /// frequency & duration
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
    /*
496
     * View mode
497
     *
498
     */
499
    if ($id > 0) {
500
        if ($object->fetch($id) > 0) {
501
            $object->fetch_thirdparty();
502
503
            $author = new User($db);
504
            $author->fetch($object->user_author);
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$user_author has been deprecated: Store only id in user_creation_id ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

504
            $author->fetch(/** @scrutinizer ignore-deprecated */ $object->user_author);

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
505
506
            $head = fichinter_rec_prepare_head($object);
507
508
            print dol_get_fiche_head($head, 'card', $langs->trans("PredefinedInterventional"), 0, 'intervention');
509
510
            // Intervention card
511
            $linkback = '<a href="card-rec.php">' . $langs->trans("BackToList") . '</a>';
512
513
            $morehtmlref = '<div class="refidno">';
514
            // Thirdparty
515
516
            $morehtmlref .= $langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
0 ignored issues
show
The method getNomUrl() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

516
            $morehtmlref .= $langs->trans('ThirdParty') . ' : ' . $object->thirdparty->/** @scrutinizer ignore-call */ getNomUrl(1);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
517
            // Project
518
            if (isModEnabled('project')) {
519
                $formproject = new FormProjets($db);
520
                $langs->load("projects");
521
                $morehtmlref .= '<br>' . $langs->trans('Project') . ' ';
522
                if ($user->hasRight('ficheinter', 'creer')) {
523
                    if ($action != 'classify') {
524
                        $morehtmlref .= '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token=' . newToken() . '&id=' . $object->id . '">';
525
                        $morehtmlref .= img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
526
                    }
527
                    if ($action == 'classify') {
528
                        $morehtmlref .= '<form method="post" action="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '">';
529
                        $morehtmlref .= '<input type="hidden" name="action" value="classin">';
530
                        $morehtmlref .= '<input type="hidden" name="token" value="' . newToken() . '">';
531
                        $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
532
                        $morehtmlref .= '<input type="submit" class="button valignmiddle" value="' . $langs->trans("Modify") . '">';
533
                        $morehtmlref .= '</form>';
534
                    } else {
535
                        $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
536
                    }
537
                } else {
538
                    if (!empty($object->fk_project)) {
539
                        $proj = new Project($db);
540
                        $proj->fetch($object->fk_project);
541
                        $morehtmlref .= ' : ' . $proj->getNomUrl(1);
542
                        if ($proj->title) {
543
                            $morehtmlref .= ' - ' . $proj->title;
544
                        }
545
                    } else {
546
                        $morehtmlref .= '';
547
                    }
548
                }
549
            }
550
            $morehtmlref .= '</div>';
551
552
            dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
553
554
            print '<div class="fichecenter">';
555
            print '<div class="fichehalfleft">';
556
            print '<div class="underbanner clearboth"></div>';
557
558
            print '<table class="border centpercent">';
559
560
            print "<tr><td>" . $langs->trans("Author") . '</td><td colspan="3">' . $author->getFullName($langs) . "</td></tr>";
561
562
            if (!getDolGlobalString('FICHINTER_DISABLE_DETAILS')) {
563
                // Duration
564
                print '<tr><td class="titlefield">' . $langs->trans("TotalDuration") . '</td>';
565
                print '<td colspan="3">';
566
                print convertSecondToTime($object->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
567
                print '</td></tr>';
568
            }
569
570
            print '<tr><td>' . $langs->trans("Description") . '</td><td colspan="3">' . nl2br($object->description) . "</td></tr>";
571
572
            // Contract
573
            if (isModEnabled('contract')) {
574
                $langs->load('contracts');
575
                print '<tr>';
576
                print '<td>';
577
578
                print '<table class="nobordernopadding" width="100%"><tr><td>';
579
                print $langs->trans('Contract');
580
                print '</td>';
581
                if ($action != 'contrat') {
582
                    print '<td class="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=contrat&id=' . $object->id . '&token=' . newToken() . '">';
583
                    print img_edit($langs->trans('SetContract'), 1);
584
                    print '</a></td>';
585
                }
586
                print '</tr></table>';
587
                print '</td><td>';
588
                if ($action == 'contrat') {
589
                    $formcontract = new FormContract($db);
590
                    $formcontract->formSelectContract($_SERVER["PHP_SELF"] . '?id=' . $object->id, $object->socid, $object->fk_contrat, 'contratid', 0, 1);
591
                } else {
592
                    if ($object->fk_contrat) {
593
                        $contratstatic = new Contrat($db);
594
                        $contratstatic->fetch($object->fk_contrat);
595
                        print $contratstatic->getNomUrl(0, '', 1);
596
                    } else {
597
                        print "&nbsp;";
598
                    }
599
                }
600
                print '</td>';
601
                print '</tr>';
602
            }
603
            print "</table>";
604
            print '</div>';
605
606
            print '<div class="fichehalfright">';
607
            print '<div class="underbanner clearboth"></div>';
608
609
            $title = $langs->trans("Recurrence");
610
            print load_fiche_titre($title, '', 'calendar');
611
612
            print '<table class="border centpercent">';
613
614
            // if "frequency" is empty or = 0, the recurrence is disabled
615
            print '<tr><td class="titlefield">';
616
            print '<table class="nobordernopadding" width="100%"><tr><td>';
617
            print $langs->trans('Frequency');
618
            print '</td>';
619
            if ($action != 'editfrequency' && $user->hasRight('ficheinter', 'creer')) {
620
                print '<td class="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editfrequency&token=' . newToken() . '&id=' . $id . '">';
621
                print img_edit($langs->trans('Edit'), 1) . '</a></td>';
622
            }
623
            print '</tr></table>';
624
            print '</td><td>';
625
            if ($action == 'editfrequency') {
626
                print '<form method="post" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '">';
627
                print '<input type="hidden" name="action" value="setfrequency">';
628
                print '<input type="hidden" name="token" value="' . newToken() . '">';
629
                print '<table class="nobordernopadding">';
630
                print '<tr><td>';
631
                print '<input type="text" name="frequency" value="' . $object->frequency . '" size="5">&nbsp;';
632
                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'));
633
                print '</td>';
634
                print '<td class="left"><input type="submit" class="button button-edit" value="' . $langs->trans("Modify") . '"></td>';
635
                print '</tr></table></form>';
636
            } else {
637
                if ($object->frequency > 0) {
638
                    print $langs->trans('FrequencyPer_' . $object->unit_frequency, $object->frequency);
639
                } else {
640
                    print $langs->trans("NotARecurringInterventionalTemplate");
641
                }
642
            }
643
            print '</td></tr>';
644
645
            // Date when
646
            print '<tr><td>';
647
            if ($user->hasRight('ficheinter', 'creer') && ($action == 'date_when' || $object->frequency > 0)) {
648
                print $form->editfieldkey($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $user->hasRight('facture', 'creer'), 'day');
649
            } else {
650
                print $langs->trans("NextDateToExecution");
651
            }
652
            print '</td><td>';
653
            if ($action == 'date_when' || $object->frequency > 0) {
654
                print $form->editfieldval($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $user->hasRight('facture', 'creer'), 'day');
655
            }
656
            print '</td>';
657
            print '</tr>';
658
659
            // Max period / Rest period
660
            print '<tr><td>';
661
            if ($user->hasRight('ficheinter', 'creer') && ($action == 'nb_gen_max' || $object->frequency > 0)) {
662
                print $form->editfieldkey($langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max, $object, $user->hasRight('facture', 'creer'));
663
            } else {
664
                print $langs->trans("MaxPeriodNumber");
665
            }
666
667
            print '</td><td>';
668
            if ($action == 'nb_gen_max' || $object->frequency > 0) {
669
                print $form->editfieldval($langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max ? $object->nb_gen_max : '', $object, $user->hasRight('facture', 'creer'));
670
            } else {
671
                print '';
672
            }
673
674
            print '</td>';
675
            print '</tr>';
676
677
            print '</table>';
678
679
            // Frequencry/Recurring section
680
            if ($object->frequency > 0) {
681
                print '<br>';
682
                if (empty($conf->cron->enabled)) {
683
                    $txtinfoadmin = $langs->trans("EnableAndSetupModuleCron", $langs->transnoentitiesnoconv("Module2300Name"));
684
                    print info_admin($txtinfoadmin);
685
                }
686
                print '<div class="underbanner clearboth"></div>';
687
                print '<table class="border centpercent">';
688
689
                // Nb of generation already done
690
                print '<tr><td class="titlefield">' . $langs->trans("NbOfGenerationOfRecordDone") . '</td>';
691
                print '<td>';
692
                print $object->nb_gen_done ? $object->nb_gen_done : '0';
693
                print '</td>';
694
                print '</tr>';
695
696
                // Date last
697
                print '<tr><td>';
698
                print $langs->trans("DateLastGeneration");
699
                print '</td><td>';
700
                print dol_print_date($object->date_last_gen, 'dayhour');
701
                print '</td>';
702
                print '</tr>';
703
                print '</table>';
704
                print '<br>';
705
            }
706
707
            print '</div>';
708
            print '</div>';
709
710
            print '<div class="clearboth"></div><br>';
711
712
            /*
713
             * Lines
714
             */
715
716
            $title = $langs->trans("ProductsAndServices");
717
            if (!isModEnabled("service")) {
718
                $title = $langs->trans("Products");
719
            } elseif (!isModEnabled("product")) {
720
                $title = $langs->trans("Services");
721
            }
722
723
            print load_fiche_titre($title);
724
725
            print '<table class="noborder centpercent">';
726
            print '<tr class="liste_titre">';
727
            print '<td>' . $langs->trans("Description") . '</td>';
728
            print '<td class="center">' . $langs->trans("Duration") . '</td>';
729
            print '</tr>';
730
731
            $num = count($object->lines);
732
            $i = 0;
733
            while ($i < $num) {
734
                // Show product and description
735
                if (isset($object->lines[$i]->product_type)) {
736
                    $type = $object->lines[$i]->product_type;
737
                } // else { $object->lines[$i]->fk_product_type; }
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
                // Show line
748
                print '<tr class="oddeven">';
749
                print '<td>';
750
                $text = img_object($langs->trans('Service'), 'service');
751
                print $text . ' ' . nl2br($object->lines[$i]->desc);
752
                print '</td>';
753
754
                print '<td class="center">' . convertSecondToTime($object->lines[$i]->duree) . '</td>';
755
                print "</tr>\n";
756
                $i++;
757
            }
758
            print '</table>';
759
760
            /*
761
             * Action bar
762
             */
763
            print '<div class="tabsAction">';
764
765
            if ($user->hasRight('ficheinter', 'creer')) {
766
                print '<div class="inline-block divButAction">';
767
                print '<a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?action=createfrommodel&token=' . newToken();
768
                print '&socid=' . $object->thirdparty->id . '&id=' . $object->id . '">';
769
                print $langs->trans("AddIntervention") . '</a></div>';
770
            }
771
772
            // Delete
773
            print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=delete&token=' . newToken(), 'delete', $user->hasRight('ficheinter', 'supprimer'));
774
775
            print '</div>';
776
        } else {
777
            print $langs->trans("ErrorRecordNotFound");
778
        }
779
    } else {
780
        /*
781
         *  List mode
782
         */
783
        $sql = "SELECT f.rowid as fich_rec, s.nom as name, s.rowid as socid, f.rowid as facid, f.title,";
784
        $sql .= " f.duree, f.fk_contrat, f.fk_projet as fk_project, f.frequency, f.nb_gen_done, f.nb_gen_max,";
785
        $sql .= " f.date_last_gen, f.date_when, f.datec, f.status";
786
787
        $sql .= " FROM " . MAIN_DB_PREFIX . "fichinter_rec as f";
788
        $sql .= " , " . MAIN_DB_PREFIX . "societe as s ";
789
        if (!$user->hasRight('societe', 'client', 'voir')) {
790
            $sql .= " , " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
791
        }
792
        $sql .= " WHERE f.fk_soc = s.rowid";
793
        $sql .= " AND f.entity = " . $conf->entity;
794
        if (!empty($socid)) {
795
            $sql .= " AND s.rowid = " . ((int) $socid);
796
        }
797
        if (!$user->hasRight('societe', 'client', 'voir')) {
798
            $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . ((int) $user->id);
799
        }
800
        /*
801
        if (!empty($search_ref)) {
802
            $sql .= natural_search('f.title', $search_ref);
803
        }
804
        */
805
        if (!empty($search_societe)) {
806
            $sql .= natural_search('s.nom', $search_societe);
807
        }
808
        if (!empty($search_frequency) && $search_frequency == '1') {
809
            $sql .= ' AND f.frequency > 0';
810
        }
811
        if (isset($search_frequency) && (string) $search_frequency == '0') {
812
            $sql .= ' AND (f.frequency IS NULL or f.frequency = 0)';
813
        }
814
815
816
        //$sql .= " ORDER BY $sortfield $sortorder, rowid DESC ";
817
        //  $sql .= $db->plimit($limit + 1, $offset);
818
819
        $resql = $db->query($sql);
820
        if ($resql) {
821
            $num = $db->num_rows($resql);
822
823
            print_barre_liste($langs->trans("RepeatableIntervention"), $page, $_SERVER['PHP_SELF'], "&socid=$socid", $sortfield, $sortorder, '', $num, '', 'intervention');
824
825
            print '<span class="opacitymedium">' . $langs->trans("ToCreateAPredefinedIntervention") . '</span><br><br>';
826
827
            $i = 0;
828
            print '<table class="noborder centpercent">';
829
            print '<tr class="liste_titre">';
830
            print_liste_field_titre("Ref", $_SERVER['PHP_SELF'], "f.title", "", "", 'width="200px"', $sortfield, $sortorder, 'left ');
831
            print_liste_field_titre("Company", $_SERVER['PHP_SELF'], "s.nom", "", "", 'width="200px"', $sortfield, $sortorder, 'left ');
832
            if (isModEnabled('contract')) {
833
                print_liste_field_titre("Contract", $_SERVER['PHP_SELF'], "f.fk_contrat", "", "", 'width="100px"', $sortfield, $sortorder, 'left ');
834
            }
835
            if (isModEnabled('project')) {
836
                print_liste_field_titre("Project", $_SERVER['PHP_SELF'], "f.fk_project", "", "", 'width="100px"', $sortfield, $sortorder, 'left ');
837
            }
838
            print_liste_field_titre("Duration", $_SERVER['PHP_SELF'], 'f.duree', '', '', 'width="50px"', $sortfield, $sortorder, 'right ');
839
            // Recurring or not
840
            print_liste_field_titre("Frequency", $_SERVER['PHP_SELF'], "f.frequency", "", "", 'width="100px"', $sortfield, $sortorder, 'center ');
841
            print_liste_field_titre("NbOfGenerationDoneShort", $_SERVER['PHP_SELF'], "f.nb_gen_done", "", "", 'width="100px"', $sortfield, $sortorder, 'center ');
842
            print_liste_field_titre("DateLastGeneration", $_SERVER['PHP_SELF'], "f.date_last_gen", "", "", 'width="100px"', $sortfield, $sortorder, 'center ');
843
            print_liste_field_titre("NextDateToIntervention", $_SERVER['PHP_SELF'], "f.date_when", "", "", 'width="100px"', $sortfield, $sortorder, 'center ');
844
            print '<th width="100px"></th>';
845
            print "</tr>\n";
846
847
848
            // les filtres à faire ensuite
849
850
            if ($num > 0) {
851
                while ($i < min($num, $limit)) {
852
                    $objp = $db->fetch_object($resql);
853
854
                    print '<tr class="oddeven">';
855
                    print '<td><a href="' . $_SERVER['PHP_SELF'] . '?id=' . $objp->fich_rec . '">';
856
                    print img_object($langs->trans("ShowIntervention"), "intervention") . ' ' . $objp->title;
857
                    print "</a></td>\n";
858
                    if ($objp->socid) {
859
                        $companystatic->id = $objp->socid;
860
                        $companystatic->name = $objp->name;
861
                        print '<td>' . $companystatic->getNomUrl(1, 'customer') . '</td>';
862
                    } else {
863
                        print '<td>' . $langs->trans("None") . '</td>';
864
                    }
865
866
                    if (isModEnabled('contract')) {
867
                        print '<td>';
868
                        if ($objp->fk_contrat > 0) {
869
                            $contratstatic->fetch($objp->fk_contrat);
870
                            print $contratstatic->getNomUrl(1);
871
                        }
872
                        print '</td>';
873
                    }
874
                    if (isModEnabled('project')) {
875
                        print '<td>';
876
                        if ($objp->fk_project > 0) {
877
                            $projectstatic->fetch($objp->fk_project);
878
                            print $projectstatic->getNomUrl(1);
879
                        }
880
                        print '</td>';
881
                    }
882
883
                    print '<td class=right>' . convertSecondToTime($objp->duree) . '</td>';
884
885
                    print '<td class="center">' . yn($objp->frequency ? 1 : 0) . '</td>';
886
887
                    print '<td class="center">';
888
                    if ($objp->frequency) {
889
                        print $objp->nb_gen_done . ($objp->nb_gen_max > 0 ? ' / ' . $objp->nb_gen_max : '');
890
                        print '</td>';
891
892
                        print '<td class="center">';
893
                        print dol_print_date($db->jdate($objp->date_last_gen), 'day');
894
                        print '</td>';
895
896
                        print '<td class="center">';
897
                        print dol_print_date($db->jdate($objp->date_when), 'day');
898
                        print '</td>';
899
                    } else {
900
                        print '<span class="opacitymedium">' . $langs->trans('NA') . '</span>';
901
                        print '</td>';
902
                        print '<td class="center">';
903
                        print '<span class="opacitymedium">' . $langs->trans('NA') . '</span>';
904
                        print '</td>';
905
                        print '<td class="center">';
906
                        print '<span class="opacitymedium">' . $langs->trans('NA') . '</span>';
907
                        print '</td>';
908
                    }
909
910
                    if ($user->hasRight('ficheinter', 'creer')) {
911
                        // Action column
912
                        print '<td class="center">';
913
                        if ($user->hasRight('ficheinter', 'creer')) {
914
                            if (empty($objp->frequency) || $db->jdate($objp->date_when) <= $today) {
915
                                print '<a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?action=createfrommodel';
916
                                print '&socid=' . $objp->socid . '&id=' . $objp->fich_rec . '&token=' . newToken() . '">';
917
                                print $langs->trans("NewIntervention") . '</a>';
918
                            } else {
919
                                print $langs->trans("DateIsNotEnough");
920
                            }
921
                        } else {
922
                            print "&nbsp;";
923
                        }
924
925
                        print "</td>";
926
927
                        print "</tr>\n";
928
                        $i++;
929
                    }
930
                }
931
            } else {
932
                print '<tr class="oddeven"><td colspan="10"><span class="opacitymedium">' . $langs->trans("None") . '</span></td></tr>';
933
            }
934
935
            print "</table>";
936
            $db->free($resql);
937
        } else {
938
            dol_print_error($db);
939
        }
940
    }
941
}
942
ViewMain::llxFooter();
943
$db->close();
944