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