dolibarr  19.0.0-dev
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 Charlie Benke <charlie@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
29 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
33 
34 if (!$user->rights->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');
48 if ($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 
65 llxHeader("", $langs->trans("Interventions"), $help_url);
66 
67 print load_fiche_titre($langs->trans("InterventionsArea"), '', 'intervention');
68 
69 print '<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";
78 if (empty($user->rights->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";
83 if ($user->socid) {
84  $sql .= ' AND f.fk_soc = '.((int) $user->socid);
85 }
86 if (empty($user->rights->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);
91 if ($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 (!empty($conf->global->FICHINTER_CLASSIFY_BILLED)) $listofstatus[] = Fichinter::STATUS_BILLED;
119 
120  foreach ($listofstatus as $status) {
121  $dataseries[] = array($fichinterstatic->LibStatut($status, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0));
122 
123  if ($status == Fichinter::STATUS_DRAFT) {
124  $colorseries[$status] = '-'.$badgeStatus0;
125  }
126  if ($status == Fichinter::STATUS_VALIDATED) {
127  $colorseries[$status] = $badgeStatus1;
128  }
129  if ($status == Fichinter::STATUS_BILLED) {
130  $colorseries[$status] = $badgeStatus4;
131  }
132  }
133 
134  if ($conf->use_javascript_ajax) {
135  print '<tr class="impair"><td class="center" colspan="2">';
136 
137  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
138  $dolgraph = new DolGraph();
139  $dolgraph->SetData($dataseries);
140  $dolgraph->SetDataColor(array_values($colorseries));
141  $dolgraph->setShowLegend(2);
142  $dolgraph->setShowPercent(1);
143  $dolgraph->SetType(array('pie'));
144  $dolgraph->setHeight('200');
145  $dolgraph->draw('idgraphstatus');
146  print $dolgraph->show($total ? 0 : 1);
147 
148  print '</td></tr>';
149  }
150  foreach ($listofstatus as $status) {
151  if (!$conf->use_javascript_ajax) {
152  print '<tr class="oddeven">';
153  print '<td>'.$fichinterstatic->LibStatut($status, 0).'</td>';
154  print '<td class="right"><a href="list.php?search_status='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).' ';
155  print $fichinterstatic->LibStatut($status, 3);
156  print '</a>';
157  print '</td>';
158  print "</tr>\n";
159  }
160  }
161  //if ($totalinprocess != $total)
162  //print '<tr class="liste_total"><td>'.$langs->trans("Total").' ('.$langs->trans("CustomersOrdersRunning").')</td><td class="right">'.$totalinprocess.'</td></tr>';
163  print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$total.'</td></tr>';
164  print "</table></div><br>";
165 } else {
166  dol_print_error($db);
167 }
168 
169 
170 /*
171  * Draft orders
172  */
173 if (isModEnabled('ficheinter')) {
174  $sql = "SELECT f.rowid, f.ref, s.nom as name, s.rowid as socid";
175  $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
176  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
177  if (empty($user->rights->societe->client->voir) && !$socid) {
178  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
179  }
180  $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
181  $sql .= " AND f.fk_soc = s.rowid";
182  $sql .= " AND f.fk_statut = 0";
183  if ($socid) {
184  $sql .= " AND f.fk_soc = ".((int) $socid);
185  }
186  if (empty($user->rights->societe->client->voir) && !$socid) {
187  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
188  }
189 
190  $resql = $db->query($sql);
191  if ($resql) {
192  print '<div class="div-table-responsive-no-min">';
193  print '<table class="noborder centpercent">';
194  print '<tr class="liste_titre">';
195  print '<th colspan="2">'.$langs->trans("DraftFichinter").'</th></tr>';
196  $langs->load("fichinter");
197  $num = $db->num_rows($resql);
198  if ($num) {
199  $i = 0;
200  while ($i < $num) {
201  $obj = $db->fetch_object($resql);
202  print '<tr class="oddeven">';
203  print '<td class="nowrap">';
204  print "<a href=\"card.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowFichinter"), "intervention").' '.$obj->ref."</a></td>";
205  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>';
206  $i++;
207  }
208  }
209  print "</table></div><br>";
210  }
211 }
212 
213 
214 print '</div><div class="fichetwothirdright">';
215 
216 
217 $max = 5;
218 
219 /*
220  * Last modified interventions
221  */
222 
223 $sql = "SELECT f.rowid, f.ref, f.fk_statut, f.date_valid as datec, f.tms as datem,";
224 $sql .= " s.nom as name, s.rowid as socid";
225 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f,";
226 $sql .= " ".MAIN_DB_PREFIX."societe as s";
227 if (empty($user->rights->societe->client->voir) && !$socid) {
228  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
229 }
230 $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
231 $sql .= " AND f.fk_soc = s.rowid";
232 //$sql.= " AND c.fk_statut > 2";
233 if ($socid) {
234  $sql .= " AND f.fk_soc = ".((int) $socid);
235 }
236 if (empty($user->rights->societe->client->voir) && !$socid) {
237  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
238 }
239 $sql .= " ORDER BY f.tms DESC";
240 $sql .= $db->plimit($max, 0);
241 
242 $resql = $db->query($sql);
243 if ($resql) {
244  print '<div class="div-table-responsive-no-min">';
245  print '<table class="noborder centpercent">';
246  print '<tr class="liste_titre">';
247  print '<th colspan="4">'.$langs->trans("LastModifiedInterventions", $max).'</th></tr>';
248 
249  $num = $db->num_rows($resql);
250  if ($num) {
251  $i = 0;
252  while ($i < $num) {
253  $obj = $db->fetch_object($resql);
254 
255  print '<tr class="oddeven">';
256  print '<td width="20%" class="nowrap">';
257 
258  $fichinterstatic->id = $obj->rowid;
259  $fichinterstatic->ref = $obj->ref;
260 
261  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
262  print '<td width="96" class="nobordernopadding nowrap">';
263  print $fichinterstatic->getNomUrl(1);
264  print '</td>';
265 
266  print '<td width="16" class="nobordernopadding nowrap">';
267  print '&nbsp;';
268  print '</td>';
269 
270  print '<td width="16" class="right nobordernopadding hideonsmartphone">';
271  $filename = dol_sanitizeFileName($obj->ref);
272  $filedir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
273  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
274  print $formfile->getDocumentsLink($fichinterstatic->element, $filename, $filedir);
275  print '</td></tr></table>';
276 
277  print '</td>';
278 
279  print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.'</a></td>';
280  print '<td>'.dol_print_date($db->jdate($obj->datem), 'day').'</td>';
281  print '<td class="right">'.$fichinterstatic->LibStatut($obj->fk_statut, 5).'</td>';
282  print '</tr>';
283  $i++;
284  }
285  }
286  print "</table></div><br>";
287 } else {
288  dol_print_error($db);
289 }
290 
291 
292 /*
293  * interventions to process
294  */
295 
296 if (isModEnabled('ficheinter')) {
297  $sql = "SELECT f.rowid, f.ref, f.fk_statut, s.nom as name, s.rowid as socid";
298  $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
299  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
300  if (empty($user->rights->societe->client->voir) && !$socid) {
301  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
302  }
303  $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
304  $sql .= " AND f.fk_soc = s.rowid";
305  $sql .= " AND f.fk_statut = 1";
306  if ($socid) {
307  $sql .= " AND f.fk_soc = ".((int) $socid);
308  }
309  if (empty($user->rights->societe->client->voir) && !$socid) {
310  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
311  }
312  $sql .= " ORDER BY f.rowid DESC";
313 
314  $resql = $db->query($sql);
315  if ($resql) {
316  $num = $db->num_rows($resql);
317 
318  print '<div class="div-table-responsive-no-min">';
319  print '<table class="noborder centpercent">';
320  print '<tr class="liste_titre">';
321  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>';
322 
323  if ($num) {
324  $i = 0;
325  while ($i < $num) {
326  $obj = $db->fetch_object($resql);
327  print '<tr class="oddeven">';
328  print '<td class="nowrap" width="20%">';
329 
330  $fichinterstatic->id = $obj->rowid;
331  $fichinterstatic->ref = $obj->ref;
332 
333  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
334  print '<td width="96" class="nobordernopadding nowrap">';
335  print $fichinterstatic->getNomUrl(1);
336  print '</td>';
337 
338  print '<td width="16" class="nobordernopadding nowrap">';
339  print '&nbsp;';
340  print '</td>';
341 
342  print '<td width="16" class="right nobordernopadding hideonsmartphone">';
343  $filename = dol_sanitizeFileName($obj->ref);
344  $filedir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
345  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
346  print $formfile->getDocumentsLink($fichinterstatic->element, $filename, $filedir);
347  print '</td></tr></table>';
348 
349  print '</td>';
350 
351  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>';
352 
353  print '<td class="right">'.$fichinterstatic->LibStatut($obj->fk_statut, 5).'</td>';
354 
355  print '</tr>';
356  $i++;
357  }
358  }
359 
360  print "</table></div><br>";
361  } else {
362  dol_print_error($db);
363  }
364 }
365 
366 print '</div></div>';
367 
368 $parameters = array('user' => $user);
369 $reshook = $hookmanager->executeHooks('dashboardInterventions', $parameters, $object); // Note that $action and $object may have been modified by hook
370 
371 llxFooter();
372 
373 $db->close();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
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.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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.
isModEnabled($module)
Is Dolibarr module enabled.
llxFooter()
Footer empty.
Definition: index.php:71
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:63
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.