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-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 require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
34 
35 if (!$user->rights->commande->lire) {
37 }
38 
39 $hookmanager = new HookManager($db);
40 
41 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
42 $hookmanager->initHooks(array('ordersindex'));
43 
44 // Load translation files required by the page
45 $langs->loadLangs(array('orders', 'bills'));
46 
47 // Security check
48 $socid = GETPOST('socid', 'int');
49 if ($user->socid > 0) {
50  $action = '';
51  $socid = $user->socid;
52 }
53 
54 $max = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
55 
56 // Maximum elements of the tables
57 $maxDraftCount = empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
58 $maxLatestEditCount = 5;
59 $maxOpenCount = empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
60 
61 
62 /*
63  * View
64  */
65 
66 $commandestatic = new Commande($db);
67 $companystatic = new Societe($db);
68 $form = new Form($db);
69 $formfile = new FormFile($db);
70 $help_url = "EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes";
71 
72 llxHeader("", $langs->trans("Orders"), $help_url);
73 
74 
75 print load_fiche_titre($langs->trans("OrdersArea"), '', 'order');
76 
77 
78 print '<div class="fichecenter"><div class="fichethirdleft">';
79 
80 $tmp = getCustomerOrderPieChart($socid);
81 if ($tmp) {
82  print $tmp;
83  print '<br>';
84 }
85 
86 
87 /*
88  * Draft orders
89  */
90 if (!empty($conf->commande->enabled)) {
91  $sql = "SELECT c.rowid, c.ref, s.nom as name, s.rowid as socid";
92  $sql .= ", s.client";
93  $sql .= ", s.code_client";
94  $sql .= ", s.canvas";
95  $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
96  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
97  if (empty($user->rights->societe->client->voir) && !$socid) {
98  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
99  }
100  $sql .= " WHERE c.fk_soc = s.rowid";
101  $sql .= " AND c.entity IN (".getEntity('commande').")";
102  $sql .= " AND c.fk_statut = 0";
103  if ($socid) {
104  $sql .= " AND c.fk_soc = ".((int) $socid);
105  }
106  if (empty($user->rights->societe->client->voir) && !$socid) {
107  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
108  }
109 
110  $resql = $db->query($sql);
111  if ($resql) {
112  print '<div class="div-table-responsive-no-min">';
113  print '<table class="noborder centpercent">';
114  print '<tr class="liste_titre">';
115  print '<th colspan="2">'.$langs->trans("DraftOrders").'</th></tr>';
116  $langs->load("orders");
117  $num = $db->num_rows($resql);
118  if ($num) {
119  $i = 0;
120  while ($i < $num) {
121  $obj = $db->fetch_object($resql);
122 
123  $commandestatic->id = $obj->rowid;
124  $commandestatic->ref = $obj->ref;
125 
126  $companystatic->id = $obj->socid;
127  $companystatic->name = $obj->name;
128  $companystatic->client = $obj->client;
129  $companystatic->code_client = $obj->code_client;
130  $companystatic->canvas = $obj->canvas;
131 
132  print '<tr class="oddeven">';
133  print '<td class="nowrap">';
134  print $commandestatic->getNomUrl(1);
135  print "</td>";
136  print '<td class="nowrap">';
137  print $companystatic->getNomUrl(1, 'company', 16);
138  print '</td></tr>';
139  $i++;
140  }
141  } else {
142  print '<tr class="oddeven"><td colspan="3">'.$langs->trans("NoOrder").'</td></tr>';
143  }
144  print "</table></div><br>";
145  }
146 }
147 
148 
149 print '</div><div class="fichetwothirdright">';
150 
151 
152 $max = 5;
153 
154 /*
155  * Lattest modified orders
156  */
157 
158 $sql = "SELECT c.rowid, c.entity, c.ref, c.fk_statut, c.facture, c.date_cloture as datec, c.tms as datem,";
159 $sql .= " s.nom as name, s.rowid as socid";
160 $sql .= ", s.client";
161 $sql .= ", s.code_client";
162 $sql .= ", s.canvas";
163 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c,";
164 $sql .= " ".MAIN_DB_PREFIX."societe as s";
165 if (empty($user->rights->societe->client->voir) && !$socid) {
166  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
167 }
168 $sql .= " WHERE c.fk_soc = s.rowid";
169 $sql .= " AND c.entity IN (".getEntity('commande').")";
170 //$sql.= " AND c.fk_statut > 2";
171 if ($socid) {
172  $sql .= " AND c.fk_soc = ".((int) $socid);
173 }
174 if (empty($user->rights->societe->client->voir) && !$socid) {
175  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
176 }
177 $sql .= " ORDER BY c.tms DESC";
178 $sql .= $db->plimit($max, 0);
179 
180 $resql = $db->query($sql);
181 if ($resql) {
182  print '<div class="div-table-responsive-no-min">';
183  print '<table class="noborder centpercent">';
184  print '<tr class="liste_titre">';
185  print '<th colspan="4">'.$langs->trans("LastModifiedOrders", $max).'</th></tr>';
186 
187  $num = $db->num_rows($resql);
188  if ($num) {
189  $i = 0;
190  while ($i < $num) {
191  $obj = $db->fetch_object($resql);
192 
193  print '<tr class="oddeven">';
194  print '<td width="20%" class="nowrap">';
195 
196  $commandestatic->id = $obj->rowid;
197  $commandestatic->ref = $obj->ref;
198 
199  $companystatic->id = $obj->socid;
200  $companystatic->name = $obj->name;
201  $companystatic->client = $obj->client;
202  $companystatic->code_client = $obj->code_client;
203  $companystatic->canvas = $obj->canvas;
204 
205  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
206  print '<td width="96" class="nobordernopadding nowrap">';
207  print $commandestatic->getNomUrl(1);
208  print '</td>';
209 
210  print '<td width="16" class="nobordernopadding nowrap">';
211  print '&nbsp;';
212  print '</td>';
213 
214  print '<td width="16" class="nobordernopadding hideonsmartphone right">';
215  $filename = dol_sanitizeFileName($obj->ref);
216  $filedir = $conf->commande->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
217  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
218  print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
219  print '</td></tr></table>';
220 
221  print '</td>';
222 
223  print '<td class="nowrap">';
224  print $companystatic->getNomUrl(1, 'company', 16);
225  print '</td>';
226  print '<td>'.dol_print_date($db->jdate($obj->datem), 'day').'</td>';
227  print '<td class="right">'.$commandestatic->LibStatut($obj->fk_statut, $obj->facture, 3).'</td>';
228  print '</tr>';
229  $i++;
230  }
231  }
232  print "</table></div><br>";
233 } else {
234  dol_print_error($db);
235 }
236 
237 $max = 10;
238 
239 /*
240  * Orders to process
241  */
242 if (!empty($conf->commande->enabled)) {
243  $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";
244  $sql .= ", s.client";
245  $sql .= ", s.code_client";
246  $sql .= ", s.canvas";
247  $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
248  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
249  if (empty($user->rights->societe->client->voir) && !$socid) {
250  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
251  }
252  $sql .= " WHERE c.fk_soc = s.rowid";
253  $sql .= " AND c.entity IN (".getEntity('commande').")";
254  $sql .= " AND c.fk_statut = ".Commande::STATUS_VALIDATED;
255  if ($socid) {
256  $sql .= " AND c.fk_soc = ".((int) $socid);
257  }
258  if (empty($user->rights->societe->client->voir) && !$socid) {
259  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
260  }
261  $sql .= " ORDER BY c.rowid DESC";
262 
263  $resql = $db->query($sql);
264  if ($resql) {
265  $num = $db->num_rows($resql);
266 
267  print '<div class="div-table-responsive-no-min">';
268  print '<table class="noborder centpercent">';
269  print '<tr class="liste_titre">';
270  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>';
271 
272  if ($num) {
273  $i = 0;
274  while ($i < $num && $i < $max) {
275  $obj = $db->fetch_object($resql);
276  print '<tr class="oddeven">';
277  print '<td class="nowrap" width="20%">';
278 
279  $commandestatic->id = $obj->rowid;
280  $commandestatic->ref = $obj->ref;
281 
282  $companystatic->id = $obj->socid;
283  $companystatic->name = $obj->name;
284  $companystatic->client = $obj->client;
285  $companystatic->code_client = $obj->code_client;
286  $companystatic->canvas = $obj->canvas;
287 
288  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
289  print '<td width="96" class="nobordernopadding nowrap">';
290  print $commandestatic->getNomUrl(1);
291  print '</td>';
292 
293  print '<td width="16" class="nobordernopadding nowrap">';
294  print '&nbsp;';
295  print '</td>';
296 
297  print '<td width="16" class="nobordernopadding hideonsmartphone right">';
298  $filename = dol_sanitizeFileName($obj->ref);
299  $filedir = $conf->commande->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
300  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
301  print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
302  print '</td></tr></table>';
303 
304  print '</td>';
305 
306  print '<td class="nowrap">';
307  print $companystatic->getNomUrl(1, 'company', 24);
308  print '</td>';
309 
310  print '<td class="right">'.dol_print_date($db->jdate($obj->date), 'day').'</td>'."\n";
311 
312  print '<td class="right">'.$commandestatic->LibStatut($obj->fk_statut, $obj->facture, 3).'</td>';
313 
314  print '</tr>';
315  $i++;
316  }
317  if ($i < $num) {
318  print '<tr><td><span class="opacitymedium">'.$langs->trans("More").'...</span></td><td></td><td></td><td></td></tr>';
319  }
320  }
321 
322  print "</table></div><br>";
323  } else {
324  dol_print_error($db);
325  }
326 }
327 
328 /*
329  * Orders that are in process
330  */
331 if (!empty($conf->commande->enabled)) {
332  $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";
333  $sql .= ", s.client";
334  $sql .= ", s.code_client";
335  $sql .= ", s.canvas";
336  $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
337  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
338  if (empty($user->rights->societe->client->voir) && !$socid) {
339  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
340  }
341  $sql .= " WHERE c.fk_soc = s.rowid";
342  $sql .= " AND c.entity IN (".getEntity('commande').")";
343  $sql .= " AND c.fk_statut = ".((int) Commande::STATUS_ACCEPTED);
344  if ($socid) {
345  $sql .= " AND c.fk_soc = ".((int) $socid);
346  }
347  if (empty($user->rights->societe->client->voir) && !$socid) {
348  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
349  }
350  $sql .= " ORDER BY c.rowid DESC";
351 
352  $resql = $db->query($sql);
353  if ($resql) {
354  $num = $db->num_rows($resql);
355 
356  print '<div class="div-table-responsive-no-min">';
357  print '<table class="noborder centpercent">';
358  print '<tr class="liste_titre">';
359  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>';
360 
361  if ($num) {
362  $i = 0;
363  while ($i < $num && $i < $max) {
364  $obj = $db->fetch_object($resql);
365  print '<tr class="oddeven">';
366  print '<td width="20%" class="nowrap">';
367 
368  $commandestatic->id = $obj->rowid;
369  $commandestatic->ref = $obj->ref;
370 
371  $companystatic->id = $obj->socid;
372  $companystatic->name = $obj->name;
373  $companystatic->client = $obj->client;
374  $companystatic->code_client = $obj->code_client;
375  $companystatic->canvas = $obj->canvas;
376 
377  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
378  print '<td width="96" class="nobordernopadding nowrap">';
379  print $commandestatic->getNomUrl(1);
380  print '</td>';
381 
382  print '<td width="16" class="nobordernopadding nowrap">';
383  print '&nbsp;';
384  print '</td>';
385 
386  print '<td width="16" class="nobordernopadding hideonsmartphone right">';
387  $filename = dol_sanitizeFileName($obj->ref);
388  $filedir = $conf->commande->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
389  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
390  print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
391  print '</td></tr></table>';
392 
393  print '</td>';
394 
395  print '<td>';
396  print $companystatic->getNomUrl(1, 'company');
397  print '</td>';
398 
399  print '<td class="right">'.dol_print_date($db->jdate($obj->date), 'day').'</td>'."\n";
400 
401  print '<td class="right">'.$commandestatic->LibStatut($obj->fk_statut, $obj->facture, 3).'</td>';
402 
403  print '</tr>';
404  $i++;
405  }
406  if ($i < $num) {
407  print '<tr><td><span class="opacitymedium">'.$langs->trans("More").'...</span></td><td></td><td></td><td></td></tr>';
408  }
409  }
410  print "</table></div><br>";
411  } else {
412  dol_print_error($db);
413  }
414 }
415 
416 
417 print '</div></div>';
418 
419 $parameters = array('user' => $user);
420 $reshook = $hookmanager->executeHooks('dashboardOrders', $parameters, $object); // Note that $action and $object may have been modified by hook
421 
422 // End of page
423 llxFooter();
424 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
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
$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
Commande\STATUS_VALIDATED
const STATUS_VALIDATED
Validated status.
Definition: commande.class.php:385
llxFooter
llxFooter()
Footer empty.
Definition: index.php:71
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
getCustomerOrderPieChart
getCustomerOrderPieChart($socid=0)
Return a HTML table that contains a pie chart of customer orders.
Definition: order.lib.php:183
Commande
Class to manage customers orders.
Definition: commande.class.php:46
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
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
$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