dolibarr 19.0.3
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 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
32require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
33
34if (!$user->hasRight('ficheinter', 'lire')) {
36}
37
38$hookmanager = new HookManager($db);
39
40// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
41$hookmanager->initHooks(array('interventionindex'));
42
43// Load translation files required by the page
44$langs->load("interventions");
45
46// Security check
47$socid = GETPOST('socid', 'int');
48if ($user->socid > 0) {
49 $action = '';
50 $socid = $user->socid;
51}
52
53
54
55/*
56 * View
57 */
58
59$fichinterstatic = new Fichinter($db);
60$form = new Form($db);
61$formfile = new FormFile($db);
62
63$help_url = "EN:ModuleFichinters|FR:Module_Fiche_Interventions|ES:Módulo_FichaInterventiones";
64
65llxHeader("", $langs->trans("Interventions"), $help_url);
66
67print load_fiche_titre($langs->trans("InterventionsArea"), '', 'intervention');
68
69print '<div class="fichecenter"><div class="fichethirdleft">';
70
71/*
72 * Statistics
73 */
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') && !$socid) {
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') && !$socid) {
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 $vals = array();
98 $bool = false;
99 // -1=Canceled, 0=Draft, 1=Validated, 2=Accepted/On process, 3=Closed (Sent/Received, billed or not)
100 if ($num>0) {
101 while ($row = $db->fetch_row($resql)) {
102 if (!isset($vals[$row[1]])) {
103 $vals[$row[1]] = 0;
104 }
105 $vals[$row[1]] += $row[0];
106 $totalinprocess += $row[0];
107
108 $total += $row[0];
109 }
110 }
111 $db->free($resql);
112 include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
113
114 print '<div class="div-table-responsive-no-min">';
115 print '<table class="noborder nohover centpercent">';
116 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("Interventions").'</th></tr>'."\n";
118 if (getDolGlobalString('FICHINTER_CLASSIFY_BILLED')) {
119 $listofstatus[] = Fichinter::STATUS_BILLED;
120 }
121
122 foreach ($listofstatus as $status) {
123 $dataseries[] = array($fichinterstatic->LibStatut($status, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0));
124
125 if ($status == Fichinter::STATUS_DRAFT) {
126 $colorseries[$status] = '-'.$badgeStatus0;
127 }
128 if ($status == Fichinter::STATUS_VALIDATED) {
129 $colorseries[$status] = $badgeStatus1;
130 }
131 if ($status == Fichinter::STATUS_BILLED) {
132 $colorseries[$status] = $badgeStatus4;
133 }
134 }
135
136 if ($conf->use_javascript_ajax) {
137 print '<tr class="impair"><td class="center" colspan="2">';
138
139 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
140 $dolgraph = new DolGraph();
141 $dolgraph->SetData($dataseries);
142 $dolgraph->SetDataColor(array_values($colorseries));
143 $dolgraph->setShowLegend(2);
144 $dolgraph->setShowPercent(1);
145 $dolgraph->SetType(array('pie'));
146 $dolgraph->setHeight('200');
147 $dolgraph->draw('idgraphstatus');
148 print $dolgraph->show($total ? 0 : 1);
149
150 print '</td></tr>';
151 }
152 foreach ($listofstatus as $status) {
153 if (!$conf->use_javascript_ajax) {
154 print '<tr class="oddeven">';
155 print '<td>'.$fichinterstatic->LibStatut($status, 0).'</td>';
156 print '<td class="right"><a href="list.php?search_status='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).' ';
157 print $fichinterstatic->LibStatut($status, 3);
158 print '</a>';
159 print '</td>';
160 print "</tr>\n";
161 }
162 }
163 //if ($totalinprocess != $total)
164 //print '<tr class="liste_total"><td>'.$langs->trans("Total").' ('.$langs->trans("CustomersOrdersRunning").')</td><td class="right">'.$totalinprocess.'</td></tr>';
165 print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$total.'</td></tr>';
166 print "</table></div><br>";
167} else {
168 dol_print_error($db);
169}
170
171
172/*
173 * Draft orders
174 */
175if (isModEnabled('ficheinter')) {
176 $sql = "SELECT f.rowid, f.ref, s.nom as name, s.rowid as socid";
177 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
178 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
179 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
180 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
181 }
182 $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
183 $sql .= " AND f.fk_soc = s.rowid";
184 $sql .= " AND f.fk_statut = 0";
185 if ($socid) {
186 $sql .= " AND f.fk_soc = ".((int) $socid);
187 }
188 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
189 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
190 }
191
192 $resql = $db->query($sql);
193 if ($resql) {
194 print '<div class="div-table-responsive-no-min">';
195 print '<table class="noborder centpercent">';
196 print '<tr class="liste_titre">';
197 print '<th colspan="2">'.$langs->trans("DraftFichinter").'</th></tr>';
198 $langs->load("fichinter");
199 $num = $db->num_rows($resql);
200 if ($num) {
201 $i = 0;
202 while ($i < $num) {
203 $obj = $db->fetch_object($resql);
204 print '<tr class="oddeven">';
205 print '<td class="nowrap">';
206 print "<a href=\"card.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowFichinter"), "intervention").' '.$obj->ref."</a></td>";
207 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>';
208 $i++;
209 }
210 }
211 print "</table></div><br>";
212 }
213}
214
215
216print '</div><div class="fichetwothirdright">';
217
218
219$max = 5;
220
221/*
222 * Last modified interventions
223 */
224
225$sql = "SELECT f.rowid, f.ref, f.fk_statut, f.date_valid as datec, f.tms as datem,";
226$sql .= " s.nom as name, s.rowid as socid";
227$sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f,";
228$sql .= " ".MAIN_DB_PREFIX."societe as s";
229if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
230 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
231}
232$sql .= " WHERE f.entity IN (".getEntity('intervention').")";
233$sql .= " AND f.fk_soc = s.rowid";
234//$sql.= " AND c.fk_statut > 2";
235if ($socid) {
236 $sql .= " AND f.fk_soc = ".((int) $socid);
237}
238if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
239 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
240}
241$sql .= " ORDER BY f.tms DESC";
242$sql .= $db->plimit($max, 0);
243
244$resql = $db->query($sql);
245if ($resql) {
246 print '<div class="div-table-responsive-no-min">';
247 print '<table class="noborder centpercent">';
248 print '<tr class="liste_titre">';
249 print '<th colspan="4">'.$langs->trans("LastModifiedInterventions", $max).'</th></tr>';
250
251 $num = $db->num_rows($resql);
252 if ($num) {
253 $i = 0;
254 while ($i < $num) {
255 $obj = $db->fetch_object($resql);
256
257 print '<tr class="oddeven">';
258 print '<td width="20%" class="nowrap">';
259
260 $fichinterstatic->id = $obj->rowid;
261 $fichinterstatic->ref = $obj->ref;
262
263 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
264 print '<td width="96" class="nobordernopadding nowrap">';
265 print $fichinterstatic->getNomUrl(1);
266 print '</td>';
267
268 print '<td width="16" class="nobordernopadding nowrap">';
269 print '&nbsp;';
270 print '</td>';
271
272 print '<td width="16" class="right nobordernopadding hideonsmartphone">';
273 $filename = dol_sanitizeFileName($obj->ref);
274 $filedir = $conf->ficheinter->dir_output.'/'.dol_sanitizeFileName($obj->ref);
275 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
276 print $formfile->getDocumentsLink($fichinterstatic->element, $filename, $filedir);
277 print '</td></tr></table>';
278
279 print '</td>';
280
281 print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.'</a></td>';
282 print '<td>'.dol_print_date($db->jdate($obj->datem), 'day').'</td>';
283 print '<td class="right">'.$fichinterstatic->LibStatut($obj->fk_statut, 5).'</td>';
284 print '</tr>';
285 $i++;
286 }
287 }
288 print "</table></div><br>";
289} else {
290 dol_print_error($db);
291}
292
293
294/*
295 * interventions to process
296 */
297
298if (isModEnabled('ficheinter')) {
299 $sql = "SELECT f.rowid, f.ref, f.fk_statut, s.nom as name, s.rowid as socid";
300 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
301 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
302 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
303 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
304 }
305 $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
306 $sql .= " AND f.fk_soc = s.rowid";
307 $sql .= " AND f.fk_statut = 1";
308 if ($socid) {
309 $sql .= " AND f.fk_soc = ".((int) $socid);
310 }
311 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
312 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
313 }
314 $sql .= " ORDER BY f.rowid DESC";
315
316 $resql = $db->query($sql);
317 if ($resql) {
318 $num = $db->num_rows($resql);
319
320 print '<div class="div-table-responsive-no-min">';
321 print '<table class="noborder centpercent">';
322 print '<tr class="liste_titre">';
323 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>';
324
325 if ($num) {
326 $i = 0;
327 while ($i < $num) {
328 $obj = $db->fetch_object($resql);
329 print '<tr class="oddeven">';
330 print '<td class="nowrap" width="20%">';
331
332 $fichinterstatic->id = $obj->rowid;
333 $fichinterstatic->ref = $obj->ref;
334
335 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
336 print '<td width="96" class="nobordernopadding nowrap">';
337 print $fichinterstatic->getNomUrl(1);
338 print '</td>';
339
340 print '<td width="16" class="nobordernopadding nowrap">';
341 print '&nbsp;';
342 print '</td>';
343
344 print '<td width="16" class="right nobordernopadding hideonsmartphone">';
345 $filename = dol_sanitizeFileName($obj->ref);
346 $filedir = $conf->ficheinter->dir_output.'/'.dol_sanitizeFileName($obj->ref);
347 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
348 print $formfile->getDocumentsLink($fichinterstatic->element, $filename, $filedir);
349 print '</td></tr></table>';
350
351 print '</td>';
352
353 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>';
354
355 print '<td class="right">'.$fichinterstatic->LibStatut($obj->fk_statut, 5).'</td>';
356
357 print '</tr>';
358 $i++;
359 }
360 }
361
362 print "</table></div><br>";
363 } else {
364 dol_print_error($db);
365 }
366}
367
368print '</div></div>';
369
370$parameters = array('user' => $user);
371$reshook = $hookmanager->executeHooks('dashboardInterventions', $parameters, $object); // Note that $action and $object may have been modified by hook
372
373llxFooter();
374
375$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to build graphs.
Class to manage interventions.
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.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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 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.