dolibarr  13.0.2
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 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
32 
33 if (!$user->rights->ficheinter->lire) accessforbidden();
34 
35 $hookmanager = new HookManager($db);
36 
37 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
38 $hookmanager->initHooks(array('interventionindex'));
39 
40 // Load translation files required by the page
41 $langs->load("interventions");
42 
43 // Security check
44 $socid = GETPOST('socid', 'int');
45 if ($user->socid > 0)
46 {
47  $action = '';
48  $socid = $user->socid;
49 }
50 
51 
52 
53 /*
54  * View
55  */
56 
57 $fichinterstatic = new Fichinter($db);
58 $form = new Form($db);
59 $formfile = new FormFile($db);
60 
61 $help_url = "EN:ModuleFichinters|FR:Module_Fiche_Interventions|ES:Módulo_FichaInterventiones";
62 
63 llxHeader("", $langs->trans("Interventions"), $help_url);
64 
65 print load_fiche_titre($langs->trans("InterventionsArea"), '', 'intervention');
66 
67 print '<div class="fichecenter"><div class="fichethirdleft">';
68 
69 if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
70 {
71  // Search ficheinter
72  $var = false;
73  print '<form method="post" action="'.DOL_URL_ROOT.'/fichinter/list.php">';
74  print '<input type="hidden" name="token" value="'.newToken().'">';
75  print '<div class="div-table-responsive-no-min">';
76  print '<table class="noborder nohover centpercent">';
77  print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
78  print '<tr class="oddeven"><td>';
79  print $langs->trans("Intervention").':</td><td><input type="text" class="flat" name="sall" size="18"></td><td><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
80  print "</table></div></form><br>\n";
81 }
82 
83 
84 /*
85  * Statistics
86  */
87 
88 $sql = "SELECT count(f.rowid), f.fk_statut";
89 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
90 $sql .= ", ".MAIN_DB_PREFIX."fichinter as f";
91 if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
92 $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
93 $sql .= " AND f.fk_soc = s.rowid";
94 if ($user->socid) $sql .= ' AND f.fk_soc = '.$user->socid;
95 if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
96 $sql .= " GROUP BY f.fk_statut";
97 $resql = $db->query($sql);
98 if ($resql)
99 {
100  $num = $db->num_rows($resql);
101  $i = 0;
102 
103  $total = 0;
104  $totalinprocess = 0;
105  $dataseries = array();
106  $vals = array();
107  $bool = false;
108  // -1=Canceled, 0=Draft, 1=Validated, 2=Accepted/On process, 3=Closed (Sent/Received, billed or not)
109  while ($i < $num)
110  {
111  $row = $db->fetch_row($resql);
112  if ($row)
113  {
114  //if ($row[1]!=-1 && ($row[1]!=3 || $row[2]!=1))
115  {
116  $bool = (!empty($row[2]) ?true:false);
117  if (!isset($vals[$row[1].$bool])) $vals[$row[1].$bool] = 0;
118  $vals[$row[1].$bool] += $row[0];
119  $totalinprocess += $row[0];
120  }
121  $total += $row[0];
122  }
123  $i++;
124  }
125  $db->free($resql);
126 
127  include_once DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
128 
129  print '<div class="div-table-responsive-no-min">';
130  print '<table class="noborder nohover centpercent">';
131  print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("Interventions").'</th></tr>'."\n";
132  $listofstatus = array(0, 1, 3);
133  $bool = false;
134  foreach ($listofstatus as $status)
135  {
136  $dataseries[] = array($fichinterstatic->LibStatut($status, $bool, 1), (isset($vals[$status.$bool]) ? (int) $vals[$status.$bool] : 0));
137  if ($status == 3 && !$bool) $bool = true;
138  else $bool = false;
139 
140  if ($status == Fichinter::STATUS_DRAFT) $colorseries[$status] = '-'.$badgeStatus0;
141  if ($status == Fichinter::STATUS_VALIDATED) $colorseries[$status] = $badgeStatus1;
142  if ($status == Fichinter::STATUS_BILLED) $colorseries[$status] = $badgeStatus4;
143  if ($status == Fichinter::STATUS_CLOSED) $colorseries[$status] = $badgeStatus6;
144  }
145  if ($conf->use_javascript_ajax)
146  {
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  $bool = false;
163  foreach ($listofstatus as $status)
164  {
165  if (!$conf->use_javascript_ajax)
166  {
167  print '<tr class="oddeven">';
168  print '<td>'.$fichinterstatic->LibStatut($status, $bool, 0).'</td>';
169  print '<td class="right"><a href="list.php?search_status='.$status.'">'.(isset($vals[$status.$bool]) ? $vals[$status.$bool] : 0).' ';
170  print $fichinterstatic->LibStatut($status, $bool, 3);
171  print '</a>';
172  print '</td>';
173  print "</tr>\n";
174  if ($status == 3 && !$bool) $bool = true;
175  else $bool = false;
176  }
177  }
178  //if ($totalinprocess != $total)
179  //print '<tr class="liste_total"><td>'.$langs->trans("Total").' ('.$langs->trans("CustomersOrdersRunning").')</td><td class="right">'.$totalinprocess.'</td></tr>';
180  print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$total.'</td></tr>';
181  print "</table></div><br>";
182 } else {
183  dol_print_error($db);
184 }
185 
186 
187 /*
188  * Draft orders
189  */
190 if (!empty($conf->ficheinter->enabled))
191 {
192  $sql = "SELECT f.rowid, f.ref, s.nom as name, s.rowid as socid";
193  $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
194  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
195  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
196  $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
197  $sql .= " AND f.fk_soc = s.rowid";
198  $sql .= " AND f.fk_statut = 0";
199  if ($socid) $sql .= " AND f.fk_soc = ".$socid;
200  if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
201 
202  $resql = $db->query($sql);
203  if ($resql)
204  {
205  print '<div class="div-table-responsive-no-min">';
206  print '<table class="noborder centpercent">';
207  print '<tr class="liste_titre">';
208  print '<th colspan="2">'.$langs->trans("DraftFichinter").'</th></tr>';
209  $langs->load("fichinter");
210  $num = $db->num_rows($resql);
211  if ($num)
212  {
213  $i = 0;
214  while ($i < $num)
215  {
216  $obj = $db->fetch_object($resql);
217  print '<tr class="oddeven">';
218  print '<td class="nowrap">';
219  print "<a href=\"card.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowFichinter"), "intervention").' '.$obj->ref."</a></td>";
220  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>';
221  $i++;
222  }
223  }
224  print "</table></div><br>";
225  }
226 }
227 
228 
229 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
230 
231 
232 $max = 5;
233 
234 /*
235  * Last modified interventions
236  */
237 
238 $sql = "SELECT f.rowid, f.ref, f.fk_statut, f.date_valid as datec, f.tms as datem,";
239 $sql .= " s.nom as name, s.rowid as socid";
240 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f,";
241 $sql .= " ".MAIN_DB_PREFIX."societe as s";
242 if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
243 $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
244 $sql .= " AND f.fk_soc = s.rowid";
245 //$sql.= " AND c.fk_statut > 2";
246 if ($socid) $sql .= " AND f.fk_soc = ".$socid;
247 if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
248 $sql .= " ORDER BY f.tms DESC";
249 $sql .= $db->plimit($max, 0);
250 
251 $resql = $db->query($sql);
252 if ($resql)
253 {
254  print '<div class="div-table-responsive-no-min">';
255  print '<table class="noborder centpercent">';
256  print '<tr class="liste_titre">';
257  print '<th colspan="4">'.$langs->trans("LastModifiedInterventions", $max).'</th></tr>';
258 
259  $num = $db->num_rows($resql);
260  if ($num)
261  {
262  $i = 0;
263  while ($i < $num)
264  {
265  $obj = $db->fetch_object($resql);
266 
267  print '<tr class="oddeven">';
268  print '<td width="20%" class="nowrap">';
269 
270  $fichinterstatic->id = $obj->rowid;
271  $fichinterstatic->ref = $obj->ref;
272 
273  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
274  print '<td width="96" class="nobordernopadding nowrap">';
275  print $fichinterstatic->getNomUrl(1);
276  print '</td>';
277 
278  print '<td width="16" class="nobordernopadding nowrap">';
279  print '&nbsp;';
280  print '</td>';
281 
282  print '<td width="16" class="right nobordernopadding hideonsmartphone">';
283  $filename = dol_sanitizeFileName($obj->ref);
284  $filedir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
285  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
286  print $formfile->getDocumentsLink($fichinterstatic->element, $filename, $filedir);
287  print '</td></tr></table>';
288 
289  print '</td>';
290 
291  print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.'</a></td>';
292  print '<td>'.dol_print_date($db->jdate($obj->datem), 'day').'</td>';
293  print '<td class="right">'.$fichinterstatic->LibStatut($obj->fk_statut, 5).'</td>';
294  print '</tr>';
295  $i++;
296  }
297  }
298  print "</table></div><br>";
299 } else dol_print_error($db);
300 
301 
302 /*
303  * interventions to process
304  */
305 
306 if (!empty($conf->ficheinter->enabled))
307 {
308  $sql = "SELECT f.rowid, f.ref, f.fk_statut, s.nom as name, s.rowid as socid";
309  $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
310  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
311  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
312  $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
313  $sql .= " AND f.fk_soc = s.rowid";
314  $sql .= " AND f.fk_statut = 1";
315  if ($socid) $sql .= " AND f.fk_soc = ".$socid;
316  if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
317  $sql .= " ORDER BY f.rowid DESC";
318 
319  $resql = $db->query($sql);
320  if ($resql)
321  {
322  $num = $db->num_rows($resql);
323 
324  print '<div class="div-table-responsive-no-min">';
325  print '<table class="noborder centpercent">';
326  print '<tr class="liste_titre">';
327  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>';
328 
329  if ($num)
330  {
331  $i = 0;
332  while ($i < $num)
333  {
334  $obj = $db->fetch_object($resql);
335  print '<tr class="oddeven">';
336  print '<td class="nowrap" width="20%">';
337 
338  $fichinterstatic->id = $obj->rowid;
339  $fichinterstatic->ref = $obj->ref;
340 
341  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
342  print '<td width="96" class="nobordernopadding nowrap">';
343  print $fichinterstatic->getNomUrl(1);
344  print '</td>';
345 
346  print '<td width="16" class="nobordernopadding nowrap">';
347  print '&nbsp;';
348  print '</td>';
349 
350  print '<td width="16" class="right nobordernopadding hideonsmartphone">';
351  $filename = dol_sanitizeFileName($obj->ref);
352  $filedir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
353  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
354  print $formfile->getDocumentsLink($fichinterstatic->element, $filename, $filedir);
355  print '</td></tr></table>';
356 
357  print '</td>';
358 
359  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>';
360 
361  print '<td class="right">'.$fichinterstatic->LibStatut($obj->fk_statut, 5).'</td>';
362 
363  print '</tr>';
364  $i++;
365  }
366  }
367 
368  print "</table></div><br>";
369  } else dol_print_error($db);
370 }
371 
372 print '</div></div></div>';
373 
374 $parameters = array('user' => $user);
375 $reshook = $hookmanager->executeHooks('dashboardInterventions', $parameters, $object); // Note that $action and $object may have been modified by hook
376 
377 llxFooter();
378 
379 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage interventions.
const STATUS_DRAFT
Draft status.
const STATUS_VALIDATED
Validated status.
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage hooks.
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
const STATUS_CLOSED
Closed.
Class to offer components to list and upload files.
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
Class to build graphs.
const STATUS_BILLED
Billed.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $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 &#39;...&#39; if string larger than length.
llxFooter()
Empty footer.
Definition: wrapper.php:59