dolibarr 22.0.5
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2004 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) 2015 Charlene Benke <charlene@patas-monkey.com>
6 * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
7 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
33require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
34require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
35
44if (!$user->hasRight('ficheinter', 'lire')) {
46}
47
48// Load translation files required by the page
49$langs->load("interventions");
50
51// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
52$hookmanager->initHooks(array('interventionindex'));
53
54
55// Security check
56$socid = GETPOSTINT('socid');
57if ($user->socid > 0) {
58 $action = '';
59 $socid = $user->socid;
60}
61
62$max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
63
64
65/*
66 * View
67 */
68
69$fichinterstatic = new Fichinter($db);
70$companystatic = new Societe($db);
71$form = new Form($db);
72$formfile = new FormFile($db);
73
74$help_url = "EN:ModuleFichinters|FR:Module_Fiche_Interventions|ES:Módulo_FichaInterventiones";
75
76llxHeader("", $langs->trans("Interventions"), $help_url, '', 0, 0, '', '', '', 'mod-fichinter page-index');
77
78print load_fiche_titre($langs->trans("InterventionsArea"), '', 'intervention');
79
80print '<div class="fichecenter"><div class="fichethirdleft">';
81
82// Statistics
83
84$sql = "SELECT count(f.rowid), f.fk_statut";
85$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
86$sql .= ", ".MAIN_DB_PREFIX."fichinter as f";
87if (!$user->hasRight('societe', 'client', 'voir')) {
88 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
89}
90$sql .= " WHERE f.entity IN (".getEntity('intervention').")";
91$sql .= " AND f.fk_soc = s.rowid";
92if ($user->socid) {
93 $sql .= ' AND f.fk_soc = '.((int) $user->socid);
94}
95if (!$user->hasRight('societe', 'client', 'voir')) {
96 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
97}
98$sql .= " GROUP BY f.fk_statut";
99$resql = $db->query($sql);
100if ($resql) {
101 $num = $db->num_rows($resql);
102
103 $total = 0;
104 $totalinprocess = 0;
105 $dataseries = array();
106 $colorseries = array();
107 $vals = array();
108 $bool = false;
109 // -1=Canceled, 0=Draft, 1=Validated, 2=Accepted/On process, 3=Closed (Sent/Received, billed or not)
110 if ($num > 0) {
111 while ($row = $db->fetch_row($resql)) {
112 if (!isset($vals[$row[1]])) {
113 $vals[$row[1]] = 0;
114 }
115 $vals[$row[1]] += $row[0];
116 $totalinprocess += $row[0];
117
118 $total += $row[0];
119 }
120 }
121 $db->free($resql);
122
123 include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
130 '
131 @phan-var-force string $badgeStatus0
132 @phan-var-force string $badgeStatus1
133 @phan-var-force string $badgeStatus2
134 @phan-var-force string $badgeStatus4
135 ';
136
137 print '<div class="div-table-responsive-no-min">';
138 print '<table class="noborder nohover centpercent">';
139 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("Interventions").'</th></tr>'."\n";
141 if (getDolGlobalString('FICHINTER_CLASSIFY_BILLED')) {
142 $listofstatus[] = Fichinter::STATUS_BILLED;
143 }
144
145 foreach ($listofstatus as $status) {
146 $dataseries[] = array($fichinterstatic->LibStatut($status, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0));
147
148 if ($status == Fichinter::STATUS_DRAFT) {
149 $colorseries[$status] = '-'.$badgeStatus0;
150 }
151 if ($status == Fichinter::STATUS_VALIDATED) {
152 $colorseries[$status] = $badgeStatus1;
153 }
154 if ($status == Fichinter::STATUS_CLOSED) {
155 $colorseries[$status] = $badgeStatus2;
156 }
157 if ($status == Fichinter::STATUS_BILLED) {
158 $colorseries[$status] = $badgeStatus4;
159 }
160 }
161
162 if ($conf->use_javascript_ajax) {
163 print '<tr class="impair"><td class="center" colspan="2">';
164
165 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
166 $dolgraph = new DolGraph();
167 $dolgraph->SetData($dataseries);
168 $dolgraph->SetDataColor(array_values($colorseries));
169 $dolgraph->setShowLegend(2);
170 $dolgraph->setShowPercent(1);
171 $dolgraph->SetType(array('pie'));
172 $dolgraph->setHeight('200');
173 $dolgraph->draw('idgraphstatus');
174 print $dolgraph->show($total ? 0 : 1);
175
176 print '</td></tr>';
177 }
178 foreach ($listofstatus as $status) {
179 if (!$conf->use_javascript_ajax) {
180 print '<tr class="oddeven">';
181 print '<td>'.$fichinterstatic->LibStatut($status, 0).'</td>';
182 print '<td class="right"><a href="list.php?search_status='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).' ';
183 print $fichinterstatic->LibStatut($status, 3);
184 print '</a>';
185 print '</td>';
186 print "</tr>\n";
187 }
188 }
189 //if ($totalinprocess != $total)
190 //print '<tr class="liste_total"><td>'.$langs->trans("Total").' ('.$langs->trans("CustomersOrdersRunning").')</td><td class="right">'.$totalinprocess.'</td></tr>';
191 print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$total.'</td></tr>';
192 print "</table></div><br>";
193} else {
194 dol_print_error($db);
195}
196
197
198/*
199 * Draft interventions
200 */
201if (isModEnabled('intervention')) {
202 $sql = "SELECT f.rowid, f.ref, s.nom as name, s.rowid as socid";
203 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
204 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
205 if (!$user->hasRight('societe', 'client', 'voir')) {
206 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
207 }
208 $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
209 $sql .= " AND f.fk_soc = s.rowid";
210 $sql .= " AND f.fk_statut = 0";
211 if ($socid) {
212 $sql .= " AND f.fk_soc = ".((int) $socid);
213 }
214 if (!$user->hasRight('societe', 'client', 'voir')) {
215 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
216 }
217
218 $resql = $db->query($sql);
219 if ($resql) {
220 print '<div class="div-table-responsive-no-min">';
221 print '<table class="noborder centpercent">';
222 print '<tr class="liste_titre">';
223 print '<th colspan="2">'.$langs->trans("DraftFichinter").'</th></tr>';
224 $langs->load("interventions");
225 $num = $db->num_rows($resql);
226 if ($num) {
227 $i = 0;
228 while ($i < $num) {
229 $obj = $db->fetch_object($resql);
230 $fichinterstatic->id = $obj->rowid;
231 $fichinterstatic->ref = $obj->ref;
232 print '<tr class="oddeven">';
233 print '<td class="nowrap">'.$fichinterstatic->getNomUrl(1).'</td>';
234 $companystatic->id = $obj->socid;
235 $companystatic->name = $obj->name;
236 print '<td>'.$companystatic->getNomUrl(1, 'customer').'</td>';
237 print '</tr>';
238 $i++;
239 }
240 }
241 print "</table></div><br>";
242 }
243}
244
245
246print '</div><div class="fichetwothirdright">';
247
248
249/*
250 * Last modified interventions
251 */
252
253$sql = "SELECT f.rowid, f.ref, f.fk_statut, f.date_valid as datec, f.tms as datem,";
254$sql .= " s.nom as name, s.rowid as socid";
255$sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f,";
256$sql .= " ".MAIN_DB_PREFIX."societe as s";
257if (!$user->hasRight('societe', 'client', 'voir')) {
258 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
259}
260$sql .= " WHERE f.entity IN (".getEntity('intervention').")";
261$sql .= " AND f.fk_soc = s.rowid";
262//$sql.= " AND c.fk_statut > 2";
263if ($socid) {
264 $sql .= " AND f.fk_soc = ".((int) $socid);
265}
266if (!$user->hasRight('societe', 'client', 'voir')) {
267 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
268}
269$sql .= " ORDER BY f.tms DESC";
270$sql .= $db->plimit($max, 0);
271
272$resql = $db->query($sql);
273if ($resql) {
274 print '<div class="div-table-responsive-no-min">';
275 print '<table class="noborder centpercent">';
276 print '<tr class="liste_titre">';
277 print '<th colspan="4">'.$langs->trans("LastModifiedInterventions", $max).'</th></tr>';
278
279 $num = $db->num_rows($resql);
280 if ($num) {
281 $i = 0;
282 while ($i < $num) {
283 $obj = $db->fetch_object($resql);
284
285 print '<tr class="oddeven">';
286 print '<td width="20%" class="nowrap">';
287
288 $fichinterstatic->id = $obj->rowid;
289 $fichinterstatic->ref = $obj->ref;
290
291 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
292 print '<td width="96" class="nobordernopadding nowrap">';
293 print $fichinterstatic->getNomUrl(1);
294 print '</td>';
295
296 print '<td width="16" class="nobordernopadding nowrap">';
297 print '&nbsp;';
298 print '</td>';
299
300 print '<td width="16" class="right nobordernopadding hideonsmartphone">';
301 $filename = dol_sanitizeFileName($obj->ref);
302 $filedir = $conf->ficheinter->dir_output.'/'.dol_sanitizeFileName($obj->ref);
303 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
304 print $formfile->getDocumentsLink($fichinterstatic->element, $filename, $filedir);
305 print '</td></tr></table>';
306
307 print '</td>';
308 $companystatic->id = $obj->socid;
309 $companystatic->name = $obj->name;
310 print '<td>'.$companystatic->getNomUrl(1, 'customer').'</td>';
311 print '<td>'.dol_print_date($db->jdate($obj->datem), 'day').'</td>';
312 print '<td class="right">'.$fichinterstatic->LibStatut($obj->fk_statut, 5).'</td>';
313 print '</tr>';
314 $i++;
315 }
316 }
317 print "</table></div><br>";
318} else {
319 dol_print_error($db);
320}
321
322
323/*
324 * interventions to process
325 */
326
327if (isModEnabled('intervention')) {
328 $sql = "SELECT f.rowid, f.ref, f.fk_statut, s.nom as name, s.rowid as socid";
329 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
330 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
331 if (!$user->hasRight('societe', 'client', 'voir')) {
332 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
333 }
334 $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
335 $sql .= " AND f.fk_soc = s.rowid";
336 $sql .= " AND f.fk_statut = 1";
337 if ($socid) {
338 $sql .= " AND f.fk_soc = ".((int) $socid);
339 }
340 if (!$user->hasRight('societe', 'client', 'voir')) {
341 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
342 }
343 $sql .= " ORDER BY f.rowid DESC";
344
345 $resql = $db->query($sql);
346 if ($resql) {
347 $num = $db->num_rows($resql);
348
349 print '<div class="div-table-responsive-no-min">';
350 print '<table class="noborder centpercent">';
351 print '<tr class="liste_titre">';
352 print '<th colspan="3">'.$langs->trans("FichinterToProcess").' <a href="'.DOL_URL_ROOT.'/fichinter/list.php?search_status=1"><span class="badge">'.$num.'</span></a></th></tr>';
353
354 if ($num) {
355 $i = 0;
356 while ($i < $num) {
357 $obj = $db->fetch_object($resql);
358 print '<tr class="oddeven">';
359 print '<td class="nowrap" width="20%">';
360
361 $fichinterstatic->id = $obj->rowid;
362 $fichinterstatic->ref = $obj->ref;
363
364 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
365 print '<td width="96" class="nobordernopadding nowrap">';
366 print $fichinterstatic->getNomUrl(1);
367 print '</td>';
368
369 print '<td width="16" class="nobordernopadding nowrap">';
370 print '&nbsp;';
371 print '</td>';
372
373 print '<td width="16" class="right nobordernopadding hideonsmartphone">';
374 $filename = dol_sanitizeFileName($obj->ref);
375 $filedir = $conf->ficheinter->dir_output.'/'.dol_sanitizeFileName($obj->ref);
376 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
377 print $formfile->getDocumentsLink($fichinterstatic->element, $filename, $filedir);
378 print '</td></tr></table>';
379
380 print '</td>';
381 $companystatic->id = $obj->socid;
382 $companystatic->name = $obj->name;
383 print '<td>'.$companystatic->getNomUrl(1, 'customer').'</td>';
384 print '<td class="right">'.$fichinterstatic->LibStatut($obj->fk_statut, 5).'</td>';
385 print '</tr>';
386 $i++;
387 }
388 }
389
390 print "</table></div><br>";
391 } else {
392 dol_print_error($db);
393 }
394}
395
396print '</div></div>';
397
398$parameters = array('user' => $user);
399$reshook = $hookmanager->executeHooks('dashboardInterventions', $parameters, $object); // Note that $action and $object may have been modified by hook
400
401llxFooter();
402
403$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
Class to build graphs.
const STATUS_BILLED
Billed.
const STATUS_DRAFT
Draft status.
const STATUS_VALIDATED
Validated status.
const STATUS_CLOSED
Closed.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.