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-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
6  * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
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.'/societe/class/client.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
33 
34 if (!$user->rights->commande->lire) accessforbidden();
35 
36 $hookmanager = new HookManager($db);
37 
38 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
39 $hookmanager->initHooks(array('ordersindex'));
40 
41 // Load translation files required by the page
42 $langs->loadLangs(array('orders', 'bills'));
43 
44 // Security check
45 $socid = GETPOST('socid', 'int');
46 if ($user->socid > 0)
47 {
48  $action = '';
49  $socid = $user->socid;
50 }
51 
52 
53 
54 /*
55  * View
56  */
57 
58 $commandestatic = new Commande($db);
59 $companystatic = new Societe($db);
60 $form = new Form($db);
61 $formfile = new FormFile($db);
62 $help_url = "EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes";
63 
64 llxHeader("", $langs->trans("Orders"), $help_url);
65 
66 
67 print load_fiche_titre($langs->trans("OrdersArea"), '', 'order');
68 
69 
70 print '<div class="fichecenter"><div class="fichethirdleft">';
71 
72 if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
73 {
74  // Search customer orders
75  print '<form method="post" action="'.DOL_URL_ROOT.'/commande/list.php">';
76  print '<input type="hidden" name="token" value="'.newToken().'">';
77  print '<div class="div-table-responsive-no-min">';
78  print '<table class="noborder nohover centpercent">';
79  print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
80  print '<tr class="oddeven"><td>';
81  print $langs->trans("CustomerOrder").':</td><td><input type="text" class="flat" name="sall" size=18></td><td><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
82  print "</table></div></form><br>\n";
83 }
84 
85 
86 /*
87  * Statistics
88  */
89 
90 $sql = "SELECT count(c.rowid) as nb, c.fk_statut as status";
91 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
92 $sql .= ", ".MAIN_DB_PREFIX."commande as c";
93 if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
94 $sql .= " WHERE c.fk_soc = s.rowid";
95 $sql .= " AND c.entity IN (".getEntity('societe').")";
96 if ($user->socid) $sql .= ' AND c.fk_soc = '.$user->socid;
97 if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
98 $sql .= " GROUP BY c.fk_statut";
99 
100 $resql = $db->query($sql);
101 if ($resql)
102 {
103  $num = $db->num_rows($resql);
104  $i = 0;
105 
106  $total = 0;
107  $totalinprocess = 0;
108  $dataseries = array();
109  $colorseries = array();
110  $vals = array();
111  // -1=Canceled, 0=Draft, 1=Validated, 2=Accepted/On process, 3=Closed (Sent/Received, billed or not)
112  while ($i < $num)
113  {
114  $row = $db->fetch_row($resql);
115  if ($row)
116  {
117  //if ($row[1]!=-1 && ($row[1]!=3 || $row[2]!=1))
118  {
119  if (!isset($vals[$row[1]])) $vals[$row[1]] = 0;
120  $vals[$row[1]] += $row[0];
121  $totalinprocess += $row[0];
122  }
123  $total += $row[0];
124  }
125  $i++;
126  }
127  $db->free($resql);
128 
129  include_once DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
130 
131  print '<div class="div-table-responsive-no-min">';
132  print '<table class="noborder nohover centpercent">';
133  print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("CustomersOrders").'</th></tr>'."\n";
134  $listofstatus = array(0, 1, 2, 3, -1);
135  foreach ($listofstatus as $status)
136  {
137  $dataseries[] = array($commandestatic->LibStatut($status, 0, 1, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0));
138  if ($status == Commande::STATUS_DRAFT) $colorseries[$status] = '-'.$badgeStatus0;
139  if ($status == Commande::STATUS_VALIDATED) $colorseries[$status] = $badgeStatus1;
140  if ($status == Commande::STATUS_SHIPMENTONPROCESS) $colorseries[$status] = $badgeStatus4;
141  if ($status == Commande::STATUS_CLOSED && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) $colorseries[$status] = $badgeStatus6;
142  if ($status == Commande::STATUS_CLOSED && (!empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) $colorseries[$status] = $badgeStatus6;
143  if ($status == Commande::STATUS_CANCELED) $colorseries[$status] = $badgeStatus9;
144 
145  if (empty($conf->use_javascript_ajax))
146  {
147  print '<tr class="oddeven">';
148  print '<td>'.$commandestatic->LibStatut($status, 0, 0, 1).'</td>';
149  print '<td class="right"><a href="list.php?statut='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).' ';
150  print $commandestatic->LibStatut($status, 0, 3, 1);
151  print '</a></td>';
152  print "</tr>\n";
153  }
154  }
155  if ($conf->use_javascript_ajax)
156  {
157  print '<tr class="impair"><td align="center" colspan="2">';
158 
159  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
160  $dolgraph = new DolGraph();
161  $dolgraph->SetData($dataseries);
162  $dolgraph->SetDataColor(array_values($colorseries));
163  $dolgraph->setShowLegend(2);
164  $dolgraph->setShowPercent(1);
165  $dolgraph->SetType(array('pie'));
166  $dolgraph->setHeight('200');
167  $dolgraph->draw('idgraphstatus');
168  print $dolgraph->show($total ? 0 : 1);
169 
170  print '</td></tr>';
171  }
172 
173  //if ($totalinprocess != $total)
174  print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$total.'</td></tr>';
175  print "</table></div><br>";
176 } else {
177  dol_print_error($db);
178 }
179 
180 
181 /*
182  * Draft orders
183  */
184 if (!empty($conf->commande->enabled))
185 {
186  $sql = "SELECT c.rowid, c.ref, s.nom as name, s.rowid as socid";
187  $sql .= ", s.client";
188  $sql .= ", s.code_client";
189  $sql .= ", s.canvas";
190  $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
191  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
192  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
193  $sql .= " WHERE c.fk_soc = s.rowid";
194  $sql .= " AND c.entity IN (".getEntity('commande').")";
195  $sql .= " AND c.fk_statut = 0";
196  if ($socid) $sql .= " AND c.fk_soc = ".$socid;
197  if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
198 
199  $resql = $db->query($sql);
200  if ($resql)
201  {
202  print '<div class="div-table-responsive-no-min">';
203  print '<table class="noborder centpercent">';
204  print '<tr class="liste_titre">';
205  print '<th colspan="2">'.$langs->trans("DraftOrders").'</th></tr>';
206  $langs->load("orders");
207  $num = $db->num_rows($resql);
208  if ($num)
209  {
210  $i = 0;
211  while ($i < $num)
212  {
213  $obj = $db->fetch_object($resql);
214 
215  $commandestatic->id = $obj->rowid;
216  $commandestatic->ref = $obj->ref;
217 
218  $companystatic->id = $obj->socid;
219  $companystatic->name = $obj->name;
220  $companystatic->client = $obj->client;
221  $companystatic->code_client = $obj->code_client;
222  $companystatic->canvas = $obj->canvas;
223 
224  print '<tr class="oddeven">';
225  print '<td class="nowrap">';
226  print $commandestatic->getNomUrl(1);
227  print "</td>";
228  print '<td class="nowrap">';
229  print $companystatic->getNomUrl(1, 'company', 16);
230  print '</td></tr>';
231  $i++;
232  }
233  } else {
234  print '<tr class="oddeven"><td colspan="3">'.$langs->trans("NoOrder").'</td></tr>';
235  }
236  print "</table></div><br>";
237  }
238 }
239 
240 
241 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
242 
243 
244 $max = 5;
245 
246 /*
247  * Lattest modified orders
248  */
249 
250 $sql = "SELECT c.rowid, c.entity, c.ref, c.fk_statut, c.facture, c.date_cloture as datec, c.tms as datem,";
251 $sql .= " s.nom as name, s.rowid as socid";
252 $sql .= ", s.client";
253 $sql .= ", s.code_client";
254 $sql .= ", s.canvas";
255 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c,";
256 $sql .= " ".MAIN_DB_PREFIX."societe as s";
257 if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
258 $sql .= " WHERE c.fk_soc = s.rowid";
259 $sql .= " AND c.entity IN (".getEntity('commande').")";
260 //$sql.= " AND c.fk_statut > 2";
261 if ($socid) $sql .= " AND c.fk_soc = ".$socid;
262 if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
263 $sql .= " ORDER BY c.tms DESC";
264 $sql .= $db->plimit($max, 0);
265 
266 $resql = $db->query($sql);
267 if ($resql)
268 {
269  print '<div class="div-table-responsive-no-min">';
270  print '<table class="noborder centpercent">';
271  print '<tr class="liste_titre">';
272  print '<th colspan="4">'.$langs->trans("LastModifiedOrders", $max).'</th></tr>';
273 
274  $num = $db->num_rows($resql);
275  if ($num)
276  {
277  $i = 0;
278  while ($i < $num)
279  {
280  $obj = $db->fetch_object($resql);
281 
282  print '<tr class="oddeven">';
283  print '<td width="20%" class="nowrap">';
284 
285  $commandestatic->id = $obj->rowid;
286  $commandestatic->ref = $obj->ref;
287 
288  $companystatic->id = $obj->socid;
289  $companystatic->name = $obj->name;
290  $companystatic->client = $obj->client;
291  $companystatic->code_client = $obj->code_client;
292  $companystatic->canvas = $obj->canvas;
293 
294  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
295  print '<td width="96" class="nobordernopadding nowrap">';
296  print $commandestatic->getNomUrl(1);
297  print '</td>';
298 
299  print '<td width="16" class="nobordernopadding nowrap">';
300  print '&nbsp;';
301  print '</td>';
302 
303  print '<td width="16" class="nobordernopadding hideonsmartphone right">';
304  $filename = dol_sanitizeFileName($obj->ref);
305  $filedir = $conf->commande->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
306  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
307  print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
308  print '</td></tr></table>';
309 
310  print '</td>';
311 
312  print '<td class="nowrap">';
313  print $companystatic->getNomUrl(1, 'company', 16);
314  print '</td>';
315  print '<td>'.dol_print_date($db->jdate($obj->datem), 'day').'</td>';
316  print '<td class="right">'.$commandestatic->LibStatut($obj->fk_statut, $obj->facture, 3).'</td>';
317  print '</tr>';
318  $i++;
319  }
320  }
321  print "</table></div><br>";
322 } else dol_print_error($db);
323 
324 $max = 10;
325 
326 /*
327  * Orders to process
328  */
329 if (!empty($conf->commande->enabled))
330 {
331  $sql = "SELECT c.rowid, c.entity, c.ref, c.fk_statut, c.facture, c.date_commande as date, s.nom as name, s.rowid as socid";
332  $sql .= ", s.client";
333  $sql .= ", s.code_client";
334  $sql .= ", s.canvas";
335  $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
336  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
337  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
338  $sql .= " WHERE c.fk_soc = s.rowid";
339  $sql .= " AND c.entity IN (".getEntity('commande').")";
340  $sql .= " AND c.fk_statut = ".Commande::STATUS_VALIDATED;
341  if ($socid) $sql .= " AND c.fk_soc = ".$socid;
342  if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
343  $sql .= " ORDER BY c.rowid DESC";
344 
345  $resql = $db->query($sql);
346  if ($resql)
347  {
348  $num = $db->num_rows($resql);
349 
350  print '<div class="div-table-responsive-no-min">';
351  print '<table class="noborder centpercent">';
352  print '<tr class="liste_titre">';
353  print '<th colspan="4">'.$langs->trans("OrdersToProcess").' <a href="'.DOL_URL_ROOT.'/commande/list.php?search_status='.Commande::STATUS_VALIDATED.'"><span class="badge">'.$num.'</span></a></th></tr>';
354 
355  if ($num)
356  {
357  $i = 0;
358  while ($i < $num && $i < $max)
359  {
360  $obj = $db->fetch_object($resql);
361  print '<tr class="oddeven">';
362  print '<td class="nowrap" width="20%">';
363 
364  $commandestatic->id = $obj->rowid;
365  $commandestatic->ref = $obj->ref;
366 
367  $companystatic->id = $obj->socid;
368  $companystatic->name = $obj->name;
369  $companystatic->client = $obj->client;
370  $companystatic->code_client = $obj->code_client;
371  $companystatic->canvas = $obj->canvas;
372 
373  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
374  print '<td width="96" class="nobordernopadding nowrap">';
375  print $commandestatic->getNomUrl(1);
376  print '</td>';
377 
378  print '<td width="16" class="nobordernopadding nowrap">';
379  print '&nbsp;';
380  print '</td>';
381 
382  print '<td width="16" class="nobordernopadding hideonsmartphone right">';
383  $filename = dol_sanitizeFileName($obj->ref);
384  $filedir = $conf->commande->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
385  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
386  print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
387  print '</td></tr></table>';
388 
389  print '</td>';
390 
391  print '<td class="nowrap">';
392  print $companystatic->getNomUrl(1, 'company', 24);
393  print '</td>';
394 
395  print '<td class="right">'.dol_print_date($db->jdate($obj->date), 'day').'</td>'."\n";
396 
397  print '<td class="right">'.$commandestatic->LibStatut($obj->fk_statut, $obj->facture, 3).'</td>';
398 
399  print '</tr>';
400  $i++;
401  }
402  if ($i < $num) {
403  print '<tr><td><span class="opacitymedium">'.$langs->trans("More").'...</span></td><td></td><td></td><td></td></tr>';
404  }
405  }
406 
407  print "</table></div><br>";
408  } else dol_print_error($db);
409 }
410 
411 /*
412  * Orders that are in process
413  */
414 if (!empty($conf->commande->enabled))
415 {
416  $sql = "SELECT c.rowid, c.entity, c.ref, c.fk_statut, c.facture, c.date_commande as date, s.nom as name, s.rowid as socid";
417  $sql .= ", s.client";
418  $sql .= ", s.code_client";
419  $sql .= ", s.canvas";
420  $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
421  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
422  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
423  $sql .= " WHERE c.fk_soc = s.rowid";
424  $sql .= " AND c.entity IN (".getEntity('commande').")";
425  $sql .= " AND c.fk_statut = ".Commande::STATUS_ACCEPTED;
426  if ($socid) $sql .= " AND c.fk_soc = ".$socid;
427  if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
428  $sql .= " ORDER BY c.rowid DESC";
429 
430  $resql = $db->query($sql);
431  if ($resql)
432  {
433  $num = $db->num_rows($resql);
434 
435  print '<div class="div-table-responsive-no-min">';
436  print '<table class="noborder centpercent">';
437  print '<tr class="liste_titre">';
438  print '<th colspan="4">'.$langs->trans("OnProcessOrders").' <a href="'.DOL_URL_ROOT.'/commande/list.php?search_status='.Commande::STATUS_ACCEPTED.'"><span class="badge">'.$num.'</span></a></th></tr>';
439 
440  if ($num)
441  {
442  $i = 0;
443  while ($i < $num && $i < $max)
444  {
445  $obj = $db->fetch_object($resql);
446  print '<tr class="oddeven">';
447  print '<td width="20%" class="nowrap">';
448 
449  $commandestatic->id = $obj->rowid;
450  $commandestatic->ref = $obj->ref;
451 
452  $companystatic->id = $obj->socid;
453  $companystatic->name = $obj->name;
454  $companystatic->client = $obj->client;
455  $companystatic->code_client = $obj->code_client;
456  $companystatic->canvas = $obj->canvas;
457 
458  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
459  print '<td width="96" class="nobordernopadding nowrap">';
460  print $commandestatic->getNomUrl(1);
461  print '</td>';
462 
463  print '<td width="16" class="nobordernopadding nowrap">';
464  print '&nbsp;';
465  print '</td>';
466 
467  print '<td width="16" class="nobordernopadding hideonsmartphone right">';
468  $filename = dol_sanitizeFileName($obj->ref);
469  $filedir = $conf->commande->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
470  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
471  print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
472  print '</td></tr></table>';
473 
474  print '</td>';
475 
476  print '<td>';
477  print $companystatic->getNomUrl(1, 'company');
478  print '</td>';
479 
480  print '<td class="right">'.dol_print_date($db->jdate($obj->date), 'day').'</td>'."\n";
481 
482  print '<td class="right">'.$commandestatic->LibStatut($obj->fk_statut, $obj->facture, 3).'</td>';
483 
484  print '</tr>';
485  $i++;
486  }
487  if ($i < $num) {
488  print '<tr><td><span class="opacitymedium">'.$langs->trans("More").'...</span></td><td></td><td></td><td></td></tr>';
489  }
490  }
491  print "</table></div><br>";
492  } else dol_print_error($db);
493 }
494 
495 
496 print '</div></div></div>';
497 
498 $parameters = array('user' => $user);
499 $reshook = $hookmanager->executeHooks('dashboardOrders', $parameters, $object); // Note that $action and $object may have been modified by hook
500 
501 // End of page
502 llxFooter();
503 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
const STATUS_CLOSED
Closed (Sent, billed or not)
const STATUS_SHIPMENTONPROCESS
Shipment on process.
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage hooks.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
Class to manage customers orders.
const STATUS_DRAFT
Draft status.
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.
Class to offer components to list and upload files.
print $_SERVER["PHP_SELF"]
Edit parameters.
const STATUS_VALIDATED
Validated status.
print
Draft customers invoices.
Definition: index.php:89
Class to build graphs.
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...
llxFooter()
Empty footer.
Definition: wrapper.php:59
const STATUS_CANCELED
Canceled status.