dolibarr 21.0.0-alpha
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';
34
35if (!$user->hasRight('ficheinter', 'lire')) {
37}
38
39$hookmanager = new HookManager($db);
40
41// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
42$hookmanager->initHooks(array('interventionindex'));
43
44// Load translation files required by the page
45$langs->load("interventions");
46
47// Security check
48$socid = GETPOSTINT('socid');
49if ($user->socid > 0) {
50 $action = '';
51 $socid = $user->socid;
52}
53
54$max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
55
56
57/*
58 * View
59 */
60
61$fichinterstatic = new Fichinter($db);
62$form = new Form($db);
63$formfile = new FormFile($db);
64
65$help_url = "EN:ModuleFichinters|FR:Module_Fiche_Interventions|ES:Módulo_FichaInterventiones";
66
67llxHeader("", $langs->trans("Interventions"), $help_url, '', 0, 0, '', '', '', 'mod-fichinter page-index');
68
69print load_fiche_titre($langs->trans("InterventionsArea"), '', 'intervention');
70
71print '<div class="fichecenter"><div class="fichethirdleft">';
72
73// Statistics
74
75$sql = "SELECT count(f.rowid), f.fk_statut";
76$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
77$sql .= ", ".MAIN_DB_PREFIX."fichinter as f";
78if (!$user->hasRight('societe', 'client', 'voir')) {
79 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
80}
81$sql .= " WHERE f.entity IN (".getEntity('intervention').")";
82$sql .= " AND f.fk_soc = s.rowid";
83if ($user->socid) {
84 $sql .= ' AND f.fk_soc = '.((int) $user->socid);
85}
86if (!$user->hasRight('societe', 'client', 'voir')) {
87 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
88}
89$sql .= " GROUP BY f.fk_statut";
90$resql = $db->query($sql);
91if ($resql) {
92 $num = $db->num_rows($resql);
93
94 $total = 0;
95 $totalinprocess = 0;
96 $dataseries = array();
97 $colorseries = array();
98 $vals = array();
99 $bool = false;
100 // -1=Canceled, 0=Draft, 1=Validated, 2=Accepted/On process, 3=Closed (Sent/Received, billed or not)
101 if ($num > 0) {
102 while ($row = $db->fetch_row($resql)) {
103 if (!isset($vals[$row[1]])) {
104 $vals[$row[1]] = 0;
105 }
106 $vals[$row[1]] += $row[0];
107 $totalinprocess += $row[0];
108
109 $total += $row[0];
110 }
111 }
112 $db->free($resql);
113 include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
114
115 print '<div class="div-table-responsive-no-min">';
116 print '<table class="noborder nohover centpercent">';
117 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("Interventions").'</th></tr>'."\n";
119 if (getDolGlobalString('FICHINTER_CLASSIFY_BILLED')) {
120 $listofstatus[] = Fichinter::STATUS_BILLED;
121 }
122
123 foreach ($listofstatus as $status) {
124 $dataseries[] = array($fichinterstatic->LibStatut($status, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0));
125
126 if ($status == Fichinter::STATUS_DRAFT) {
127 $colorseries[$status] = '-'.$badgeStatus0;
128 }
129 if ($status == Fichinter::STATUS_VALIDATED) {
130 $colorseries[$status] = $badgeStatus1;
131 }
132 if ($status == Fichinter::STATUS_BILLED) {
133 $colorseries[$status] = $badgeStatus4;
134 }
135 }
136
137 if ($conf->use_javascript_ajax) {
138 print '<tr class="impair"><td class="center" colspan="2">';
139
140 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
141 $dolgraph = new DolGraph();
142 $dolgraph->SetData($dataseries);
143 $dolgraph->SetDataColor(array_values($colorseries));
144 $dolgraph->setShowLegend(2);
145 $dolgraph->setShowPercent(1);
146 $dolgraph->SetType(array('pie'));
147 $dolgraph->setHeight('200');
148 $dolgraph->draw('idgraphstatus');
149 print $dolgraph->show($total ? 0 : 1);
150
151 print '</td></tr>';
152 }
153 foreach ($listofstatus as $status) {
154 if (!$conf->use_javascript_ajax) {
155 print '<tr class="oddeven">';
156 print '<td>'.$fichinterstatic->LibStatut($status, 0).'</td>';
157 print '<td class="right"><a href="list.php?search_status='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).' ';
158 print $fichinterstatic->LibStatut($status, 3);
159 print '</a>';
160 print '</td>';
161 print "</tr>\n";
162 }
163 }
164 //if ($totalinprocess != $total)
165 //print '<tr class="liste_total"><td>'.$langs->trans("Total").' ('.$langs->trans("CustomersOrdersRunning").')</td><td class="right">'.$totalinprocess.'</td></tr>';
166 print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$total.'</td></tr>';
167 print "</table></div><br>";
168} else {
169 dol_print_error($db);
170}
171
172
173/*
174 * Draft orders
175 */
176if (isModEnabled('intervention')) {
177 $sql = "SELECT f.rowid, f.ref, s.nom as name, s.rowid as socid";
178 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
179 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
180 if (!$user->hasRight('societe', 'client', 'voir')) {
181 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
182 }
183 $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
184 $sql .= " AND f.fk_soc = s.rowid";
185 $sql .= " AND f.fk_statut = 0";
186 if ($socid) {
187 $sql .= " AND f.fk_soc = ".((int) $socid);
188 }
189 if (!$user->hasRight('societe', 'client', 'voir')) {
190 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
191 }
192
193 $resql = $db->query($sql);
194 if ($resql) {
195 print '<div class="div-table-responsive-no-min">';
196 print '<table class="noborder centpercent">';
197 print '<tr class="liste_titre">';
198 print '<th colspan="2">'.$langs->trans("DraftFichinter").'</th></tr>';
199 $langs->load("interventions");
200 $num = $db->num_rows($resql);
201 if ($num) {
202 $i = 0;
203 while ($i < $num) {
204 $obj = $db->fetch_object($resql);
205 print '<tr class="oddeven">';
206 print '<td class="nowrap">';
207 print "<a href=\"card.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowFichinter"), "intervention").' '.$obj->ref."</a></td>";
208 print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.dol_trunc($obj->name, 24).'</a></td></tr>';
209 $i++;
210 }
211 }
212 print "</table></div><br>";
213 }
214}
215
216
217print '</div><div class="fichetwothirdright">';
218
219
220/*
221 * Last modified interventions
222 */
223
224$sql = "SELECT f.rowid, f.ref, f.fk_statut, f.date_valid as datec, f.tms as datem,";
225$sql .= " s.nom as name, s.rowid as socid";
226$sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f,";
227$sql .= " ".MAIN_DB_PREFIX."societe as s";
228if (!$user->hasRight('societe', 'client', 'voir')) {
229 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
230}
231$sql .= " WHERE f.entity IN (".getEntity('intervention').")";
232$sql .= " AND f.fk_soc = s.rowid";
233//$sql.= " AND c.fk_statut > 2";
234if ($socid) {
235 $sql .= " AND f.fk_soc = ".((int) $socid);
236}
237if (!$user->hasRight('societe', 'client', 'voir')) {
238 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
239}
240$sql .= " ORDER BY f.tms DESC";
241$sql .= $db->plimit($max, 0);
242
243$resql = $db->query($sql);
244if ($resql) {
245 print '<div class="div-table-responsive-no-min">';
246 print '<table class="noborder centpercent">';
247 print '<tr class="liste_titre">';
248 print '<th colspan="4">'.$langs->trans("LastModifiedInterventions", $max).'</th></tr>';
249
250 $num = $db->num_rows($resql);
251 if ($num) {
252 $i = 0;
253 while ($i < $num) {
254 $obj = $db->fetch_object($resql);
255
256 print '<tr class="oddeven">';
257 print '<td width="20%" class="nowrap">';
258
259 $fichinterstatic->id = $obj->rowid;
260 $fichinterstatic->ref = $obj->ref;
261
262 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
263 print '<td width="96" class="nobordernopadding nowrap">';
264 print $fichinterstatic->getNomUrl(1);
265 print '</td>';
266
267 print '<td width="16" class="nobordernopadding nowrap">';
268 print '&nbsp;';
269 print '</td>';
270
271 print '<td width="16" class="right nobordernopadding hideonsmartphone">';
272 $filename = dol_sanitizeFileName($obj->ref);
273 $filedir = $conf->ficheinter->dir_output.'/'.dol_sanitizeFileName($obj->ref);
274 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
275 print $formfile->getDocumentsLink($fichinterstatic->element, $filename, $filedir);
276 print '</td></tr></table>';
277
278 print '</td>';
279
280 print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.'</a></td>';
281 print '<td>'.dol_print_date($db->jdate($obj->datem), 'day').'</td>';
282 print '<td class="right">'.$fichinterstatic->LibStatut($obj->fk_statut, 5).'</td>';
283 print '</tr>';
284 $i++;
285 }
286 }
287 print "</table></div><br>";
288} else {
289 dol_print_error($db);
290}
291
292
293/*
294 * interventions to process
295 */
296
297if (isModEnabled('intervention')) {
298 $sql = "SELECT f.rowid, f.ref, f.fk_statut, s.nom as name, s.rowid as socid";
299 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
300 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
301 if (!$user->hasRight('societe', 'client', 'voir')) {
302 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
303 }
304 $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
305 $sql .= " AND f.fk_soc = s.rowid";
306 $sql .= " AND f.fk_statut = 1";
307 if ($socid) {
308 $sql .= " AND f.fk_soc = ".((int) $socid);
309 }
310 if (!$user->hasRight('societe', 'client', 'voir')) {
311 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
312 }
313 $sql .= " ORDER BY f.rowid DESC";
314
315 $resql = $db->query($sql);
316 if ($resql) {
317 $num = $db->num_rows($resql);
318
319 print '<div class="div-table-responsive-no-min">';
320 print '<table class="noborder centpercent">';
321 print '<tr class="liste_titre">';
322 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>';
323
324 if ($num) {
325 $i = 0;
326 while ($i < $num) {
327 $obj = $db->fetch_object($resql);
328 print '<tr class="oddeven">';
329 print '<td class="nowrap" width="20%">';
330
331 $fichinterstatic->id = $obj->rowid;
332 $fichinterstatic->ref = $obj->ref;
333
334 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
335 print '<td width="96" class="nobordernopadding nowrap">';
336 print $fichinterstatic->getNomUrl(1);
337 print '</td>';
338
339 print '<td width="16" class="nobordernopadding nowrap">';
340 print '&nbsp;';
341 print '</td>';
342
343 print '<td width="16" class="right nobordernopadding hideonsmartphone">';
344 $filename = dol_sanitizeFileName($obj->ref);
345 $filedir = $conf->ficheinter->dir_output.'/'.dol_sanitizeFileName($obj->ref);
346 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
347 print $formfile->getDocumentsLink($fichinterstatic->element, $filename, $filedir);
348 print '</td></tr></table>';
349
350 print '</td>';
351
352 print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.dol_trunc($obj->name, 24).'</a></td>';
353
354 print '<td class="right">'.$fichinterstatic->LibStatut($obj->fk_statut, 5).'</td>';
355
356 print '</tr>';
357 $i++;
358 }
359 }
360
361 print "</table></div><br>";
362 } else {
363 dol_print_error($db);
364 }
365}
366
367print '</div></div>';
368
369$parameters = array('user' => $user);
370$reshook = $hookmanager->executeHooks('dashboardInterventions', $parameters, $object); // Note that $action and $object may have been modified by hook
371
372llxFooter();
373
374$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:70
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 hooks.
llxFooter()
Footer empty.
Definition document.php:107
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)
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...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.