dolibarr 21.0.0-beta
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 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 include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
123
124 print '<div class="div-table-responsive-no-min">';
125 print '<table class="noborder nohover centpercent">';
126 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("Interventions").'</th></tr>'."\n";
128 if (getDolGlobalString('FICHINTER_CLASSIFY_BILLED')) {
129 $listofstatus[] = Fichinter::STATUS_BILLED;
130 }
131
132 foreach ($listofstatus as $status) {
133 $dataseries[] = array($fichinterstatic->LibStatut($status, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0));
134
135 if ($status == Fichinter::STATUS_DRAFT) {
136 $colorseries[$status] = '-'.$badgeStatus0;
137 }
138 if ($status == Fichinter::STATUS_VALIDATED) {
139 $colorseries[$status] = $badgeStatus1;
140 }
141 if ($status == Fichinter::STATUS_BILLED) {
142 $colorseries[$status] = $badgeStatus4;
143 }
144 }
145
146 if ($conf->use_javascript_ajax) {
147 print '<tr class="impair"><td class="center" colspan="2">';
148
149 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
150 $dolgraph = new DolGraph();
151 $dolgraph->SetData($dataseries);
152 $dolgraph->SetDataColor(array_values($colorseries));
153 $dolgraph->setShowLegend(2);
154 $dolgraph->setShowPercent(1);
155 $dolgraph->SetType(array('pie'));
156 $dolgraph->setHeight('200');
157 $dolgraph->draw('idgraphstatus');
158 print $dolgraph->show($total ? 0 : 1);
159
160 print '</td></tr>';
161 }
162 foreach ($listofstatus as $status) {
163 if (!$conf->use_javascript_ajax) {
164 print '<tr class="oddeven">';
165 print '<td>'.$fichinterstatic->LibStatut($status, 0).'</td>';
166 print '<td class="right"><a href="list.php?search_status='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).' ';
167 print $fichinterstatic->LibStatut($status, 3);
168 print '</a>';
169 print '</td>';
170 print "</tr>\n";
171 }
172 }
173 //if ($totalinprocess != $total)
174 //print '<tr class="liste_total"><td>'.$langs->trans("Total").' ('.$langs->trans("CustomersOrdersRunning").')</td><td class="right">'.$totalinprocess.'</td></tr>';
175 print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$total.'</td></tr>';
176 print "</table></div><br>";
177} else {
178 dol_print_error($db);
179}
180
181
182/*
183 * Draft interventions
184 */
185if (isModEnabled('intervention')) {
186 $sql = "SELECT f.rowid, f.ref, s.nom as name, s.rowid as socid";
187 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
188 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
189 if (!$user->hasRight('societe', 'client', 'voir')) {
190 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
191 }
192 $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
193 $sql .= " AND f.fk_soc = s.rowid";
194 $sql .= " AND f.fk_statut = 0";
195 if ($socid) {
196 $sql .= " AND f.fk_soc = ".((int) $socid);
197 }
198 if (!$user->hasRight('societe', 'client', 'voir')) {
199 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
200 }
201
202 $resql = $db->query($sql);
203 if ($resql) {
204 print '<div class="div-table-responsive-no-min">';
205 print '<table class="noborder centpercent">';
206 print '<tr class="liste_titre">';
207 print '<th colspan="2">'.$langs->trans("DraftFichinter").'</th></tr>';
208 $langs->load("interventions");
209 $num = $db->num_rows($resql);
210 if ($num) {
211 $i = 0;
212 while ($i < $num) {
213 $obj = $db->fetch_object($resql);
214 $fichinterstatic->id = $obj->rowid;
215 $fichinterstatic->ref = $obj->ref;
216 print '<tr class="oddeven">';
217 print '<td class="nowrap">'.$fichinterstatic->getNomUrl(1).'</td>';
218 $companystatic->id = $obj->socid;
219 $companystatic->name = $obj->name;
220 print '<td>'.$companystatic->getNomUrl(1, 'customer').'</td>';
221 print '</tr>';
222 $i++;
223 }
224 }
225 print "</table></div><br>";
226 }
227}
228
229
230print '</div><div class="fichetwothirdright">';
231
232
233/*
234 * Last modified interventions
235 */
236
237$sql = "SELECT f.rowid, f.ref, f.fk_statut, f.date_valid as datec, f.tms as datem,";
238$sql .= " s.nom as name, s.rowid as socid";
239$sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f,";
240$sql .= " ".MAIN_DB_PREFIX."societe as s";
241if (!$user->hasRight('societe', 'client', 'voir')) {
242 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
243}
244$sql .= " WHERE f.entity IN (".getEntity('intervention').")";
245$sql .= " AND f.fk_soc = s.rowid";
246//$sql.= " AND c.fk_statut > 2";
247if ($socid) {
248 $sql .= " AND f.fk_soc = ".((int) $socid);
249}
250if (!$user->hasRight('societe', 'client', 'voir')) {
251 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
252}
253$sql .= " ORDER BY f.tms DESC";
254$sql .= $db->plimit($max, 0);
255
256$resql = $db->query($sql);
257if ($resql) {
258 print '<div class="div-table-responsive-no-min">';
259 print '<table class="noborder centpercent">';
260 print '<tr class="liste_titre">';
261 print '<th colspan="4">'.$langs->trans("LastModifiedInterventions", $max).'</th></tr>';
262
263 $num = $db->num_rows($resql);
264 if ($num) {
265 $i = 0;
266 while ($i < $num) {
267 $obj = $db->fetch_object($resql);
268
269 print '<tr class="oddeven">';
270 print '<td width="20%" class="nowrap">';
271
272 $fichinterstatic->id = $obj->rowid;
273 $fichinterstatic->ref = $obj->ref;
274
275 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
276 print '<td width="96" class="nobordernopadding nowrap">';
277 print $fichinterstatic->getNomUrl(1);
278 print '</td>';
279
280 print '<td width="16" class="nobordernopadding nowrap">';
281 print '&nbsp;';
282 print '</td>';
283
284 print '<td width="16" class="right nobordernopadding hideonsmartphone">';
285 $filename = dol_sanitizeFileName($obj->ref);
286 $filedir = $conf->ficheinter->dir_output.'/'.dol_sanitizeFileName($obj->ref);
287 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
288 print $formfile->getDocumentsLink($fichinterstatic->element, $filename, $filedir);
289 print '</td></tr></table>';
290
291 print '</td>';
292 $companystatic->id = $obj->socid;
293 $companystatic->name = $obj->name;
294 print '<td>'.$companystatic->getNomUrl(1, 'customer').'</td>';
295 print '<td>'.dol_print_date($db->jdate($obj->datem), 'day').'</td>';
296 print '<td class="right">'.$fichinterstatic->LibStatut($obj->fk_statut, 5).'</td>';
297 print '</tr>';
298 $i++;
299 }
300 }
301 print "</table></div><br>";
302} else {
303 dol_print_error($db);
304}
305
306
307/*
308 * interventions to process
309 */
310
311if (isModEnabled('intervention')) {
312 $sql = "SELECT f.rowid, f.ref, f.fk_statut, s.nom as name, s.rowid as socid";
313 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
314 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
315 if (!$user->hasRight('societe', 'client', 'voir')) {
316 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
317 }
318 $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
319 $sql .= " AND f.fk_soc = s.rowid";
320 $sql .= " AND f.fk_statut = 1";
321 if ($socid) {
322 $sql .= " AND f.fk_soc = ".((int) $socid);
323 }
324 if (!$user->hasRight('societe', 'client', 'voir')) {
325 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
326 }
327 $sql .= " ORDER BY f.rowid DESC";
328
329 $resql = $db->query($sql);
330 if ($resql) {
331 $num = $db->num_rows($resql);
332
333 print '<div class="div-table-responsive-no-min">';
334 print '<table class="noborder centpercent">';
335 print '<tr class="liste_titre">';
336 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>';
337
338 if ($num) {
339 $i = 0;
340 while ($i < $num) {
341 $obj = $db->fetch_object($resql);
342 print '<tr class="oddeven">';
343 print '<td class="nowrap" width="20%">';
344
345 $fichinterstatic->id = $obj->rowid;
346 $fichinterstatic->ref = $obj->ref;
347
348 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
349 print '<td width="96" class="nobordernopadding nowrap">';
350 print $fichinterstatic->getNomUrl(1);
351 print '</td>';
352
353 print '<td width="16" class="nobordernopadding nowrap">';
354 print '&nbsp;';
355 print '</td>';
356
357 print '<td width="16" class="right nobordernopadding hideonsmartphone">';
358 $filename = dol_sanitizeFileName($obj->ref);
359 $filedir = $conf->ficheinter->dir_output.'/'.dol_sanitizeFileName($obj->ref);
360 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
361 print $formfile->getDocumentsLink($fichinterstatic->element, $filename, $filedir);
362 print '</td></tr></table>';
363
364 print '</td>';
365 $companystatic->id = $obj->socid;
366 $companystatic->name = $obj->name;
367 print '<td>'.$companystatic->getNomUrl(1, 'customer').'</td>';
368 print '<td class="right">'.$fichinterstatic->LibStatut($obj->fk_statut, 5).'</td>';
369 print '</tr>';
370 $i++;
371 }
372 }
373
374 print "</table></div><br>";
375 } else {
376 dol_print_error($db);
377 }
378}
379
380print '</div></div>';
381
382$parameters = array('user' => $user);
383$reshook = $hookmanager->executeHooks('dashboardInterventions', $parameters, $object); // Note that $action and $object may have been modified by hook
384
385llxFooter();
386
387$db->close();
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 build graphs.
const STATUS_BILLED
Billed.
const STATUS_DRAFT
Draft status.
const STATUS_VALIDATED
Validated status.
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...)
llxFooter()
Footer empty.
Definition document.php:107
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_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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.
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.