dolibarr  7.0.0-beta
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@capnetworks.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
28 require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
30 require_once DOL_DOCUMENT_ROOT .'/commande/class/commande.class.php';
31 
32 if (!$user->rights->commande->lire) accessforbidden();
33 
34 $langs->load("orders");
35 $langs->load("bills");
36 
37 // Security check
38 $socid=GETPOST('socid','int');
39 if ($user->societe_id > 0)
40 {
41  $action = '';
42  $socid = $user->societe_id;
43 }
44 
45 
46 
47 /*
48  * View
49  */
50 
51 $commandestatic=new Commande($db);
52 $companystatic=new Societe($db);
53 $form = new Form($db);
54 $formfile = new FormFile($db);
55 $help_url="EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes";
56 
57 llxHeader("",$langs->trans("Orders"),$help_url);
58 
59 print load_fiche_titre($langs->trans("OrdersArea"));
60 
61 
62 print '<div class="fichecenter"><div class="fichethirdleft">';
63 
64 if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
65 {
66  // Search customer orders
67  $var=false;
68  print '<form method="post" action="'.DOL_URL_ROOT.'/commande/list.php">';
69  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
70  print '<table class="noborder nohover" width="100%">';
71  print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
72  print '<tr class="oddeven"><td>';
73  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>';
74  print "</table></form><br>\n";
75 }
76 
77 
78 /*
79  * Statistics
80  */
81 
82 $sql = "SELECT count(c.rowid), c.fk_statut";
83 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
84 $sql.= ", ".MAIN_DB_PREFIX."commande as c";
85 if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
86 $sql.= " WHERE c.fk_soc = s.rowid";
87 $sql.= " AND c.entity IN (".getEntity('societe').")";
88 if ($user->societe_id) $sql.=' AND c.fk_soc = '.$user->societe_id;
89 if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
90 $sql.= " GROUP BY c.fk_statut";
91 
92 $resql = $db->query($sql);
93 if ($resql)
94 {
95  $num = $db->num_rows($resql);
96  $i = 0;
97 
98  $total=0;
99  $totalinprocess=0;
100  $dataseries=array();
101  $vals=array();
102  // -1=Canceled, 0=Draft, 1=Validated, 2=Accepted/On process, 3=Closed (Sent/Received, billed or not)
103  while ($i < $num)
104  {
105  $row = $db->fetch_row($resql);
106  if ($row)
107  {
108  //if ($row[1]!=-1 && ($row[1]!=3 || $row[2]!=1))
109  {
110  if (! isset($vals[$row[1]])) $vals[$row[1]]=0;
111  $vals[$row[1].$bool]+=$row[0];
112  $totalinprocess+=$row[0];
113  }
114  $total+=$row[0];
115  }
116  $i++;
117  }
118  $db->free($resql);
119  print '<table class="noborder nohover" width="100%">';
120  print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("CustomersOrders").'</th></tr>'."\n";
121  $listofstatus=array(0,1,2,3,-1);
122  foreach ($listofstatus as $status)
123  {
124  $dataseries[]=array($commandestatic->LibStatut($status,$bool,1), (isset($vals[$status.$bool])?(int) $vals[$status.$bool]:0));
125  }
126  if ($conf->use_javascript_ajax)
127  {
128  print '<tr class="impair"><td align="center" colspan="2">';
129 
130  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
131  $dolgraph = new DolGraph();
132  $dolgraph->SetData($dataseries);
133  $dolgraph->setShowLegend(1);
134  $dolgraph->setShowPercent(1);
135  $dolgraph->SetType(array('pie'));
136  $dolgraph->setWidth('100%');
137  $dolgraph->draw('idgraphstatus');
138  print $dolgraph->show($total?0:1);
139 
140  print '</td></tr>';
141  }
142  else
143  {
144  foreach ($listofstatus as $status)
145  {
146  print '<tr class="oddeven">';
147  print '<td>'.$commandestatic->LibStatut($status,$bool,0).'</td>';
148  print '<td align="right"><a href="list.php?viewstatut='.$status.'">'.(isset($vals[$status.$bool])?$vals[$status.$bool]:0).' ';
149  print $commandestatic->LibStatut($status,$bool,3);
150  print '</a>';
151  print '</td>';
152  print "</tr>\n";
153  }
154  }
155  //if ($totalinprocess != $total)
156  print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td align="right">'.$total.'</td></tr>';
157  print "</table><br>";
158 }
159 else
160 {
161  dol_print_error($db);
162 }
163 
164 
165 /*
166  * Draft orders
167  */
168 if (! empty($conf->commande->enabled))
169 {
170  $sql = "SELECT c.rowid, c.ref, s.nom as name, s.rowid as socid";
171  $sql.= ", s.client";
172  $sql.= ", s.code_client";
173  $sql.= ", s.canvas";
174  $sql.= " FROM ".MAIN_DB_PREFIX."commande as c";
175  $sql.= ", ".MAIN_DB_PREFIX."societe as s";
176  if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
177  $sql.= " WHERE c.fk_soc = s.rowid";
178  $sql.= " AND c.entity IN (".getEntity('commande').")";
179  $sql.= " AND c.fk_statut = 0";
180  if ($socid) $sql.= " AND c.fk_soc = ".$socid;
181  if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
182 
183  $resql=$db->query($sql);
184  if ($resql)
185  {
186  print '<table class="noborder" width="100%">';
187  print '<tr class="liste_titre">';
188  print '<th colspan="2">'.$langs->trans("DraftOrders").'</th></tr>';
189  $langs->load("orders");
190  $num = $db->num_rows($resql);
191  if ($num)
192  {
193  $i = 0;
194  $var = true;
195  while ($i < $num)
196  {
197 
198  $obj = $db->fetch_object($resql);
199 
200  $commandestatic->id=$obj->rowid;
201  $commandestatic->ref=$obj->ref;
202 
203  $companystatic->id=$obj->socid;
204  $companystatic->name=$obj->name;
205  $companystatic->client=$obj->client;
206  $companystatic->code_client=$obj->code_client;
207  $companystatic->canvas=$obj->canvas;
208 
209  print '<tr class="oddeven">';
210  print '<td class="nowrap">';
211  print $commandestatic->getNomUrl(1);
212  print "</td>";
213  print '<td class="nowrap">';
214  print $companystatic->getNomUrl(1,'company',16);
215  print '</td></tr>';
216  $i++;
217  }
218  }
219  else
220  {
221 
222  print '<tr class="oddeven"><td colspan="3">'.$langs->trans("NoOrder").'</td></tr>';
223  }
224  print "</table><br>";
225  }
226 }
227 
228 
229 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
230 
231 
232 $max=5;
233 
234 /*
235  * Last modified orders
236  */
237 
238 $sql = "SELECT c.rowid, c.ref, c.fk_statut, c.facture, c.date_cloture as datec, c.tms as datem,";
239 $sql.= " s.nom as name, s.rowid as socid";
240 $sql.= ", s.client";
241 $sql.= ", s.code_client";
242 $sql.= ", s.canvas";
243 $sql.= " FROM ".MAIN_DB_PREFIX."commande as c,";
244 $sql.= " ".MAIN_DB_PREFIX."societe as s";
245 if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
246 $sql.= " WHERE c.fk_soc = s.rowid";
247 $sql.= " AND c.entity IN (".getEntity('commande').")";
248 //$sql.= " AND c.fk_statut > 2";
249 if ($socid) $sql .= " AND c.fk_soc = ".$socid;
250 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
251 $sql.= " ORDER BY c.tms DESC";
252 $sql.= $db->plimit($max, 0);
253 
254 $resql=$db->query($sql);
255 if ($resql)
256 {
257  print '<table class="noborder" width="100%">';
258  print '<tr class="liste_titre">';
259  print '<th colspan="4">'.$langs->trans("LastModifiedOrders",$max).'</th></tr>';
260 
261  $num = $db->num_rows($resql);
262  if ($num)
263  {
264  $i = 0;
265  $var = true;
266  while ($i < $num)
267  {
268 
269  $obj = $db->fetch_object($resql);
270 
271  print '<tr class="oddeven">';
272  print '<td width="20%" class="nowrap">';
273 
274  $commandestatic->id=$obj->rowid;
275  $commandestatic->ref=$obj->ref;
276 
277  $companystatic->id=$obj->socid;
278  $companystatic->name=$obj->name;
279  $companystatic->client=$obj->client;
280  $companystatic->code_client=$obj->code_client;
281  $companystatic->canvas=$obj->canvas;
282 
283  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
284  print '<td width="96" class="nobordernopadding nowrap">';
285  print $commandestatic->getNomUrl(1);
286  print '</td>';
287 
288  print '<td width="16" class="nobordernopadding nowrap">';
289  print '&nbsp;';
290  print '</td>';
291 
292  print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">';
293  $filename=dol_sanitizeFileName($obj->ref);
294  $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
295  $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
296  print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
297  print '</td></tr></table>';
298 
299  print '</td>';
300 
301  print '<td class="nowrap">';
302  print $companystatic->getNomUrl(1,'company',16);
303  print '</td>';
304  print '<td>'.dol_print_date($db->jdate($obj->datem),'day').'</td>';
305  print '<td align="right">'.$commandestatic->LibStatut($obj->fk_statut,$obj->facture,5).'</td>';
306  print '</tr>';
307  $i++;
308  }
309  }
310  print "</table><br>";
311 }
312 else dol_print_error($db);
313 
314 
315 /*
316  * Orders to process
317  */
318 if (! empty($conf->commande->enabled))
319 {
320  $sql = "SELECT c.rowid, c.ref, c.fk_statut, c.facture, s.nom as name, s.rowid as socid";
321  $sql.= ", s.client";
322  $sql.= ", s.code_client";
323  $sql.= ", s.canvas";
324  $sql.=" FROM ".MAIN_DB_PREFIX."commande as c";
325  $sql.= ", ".MAIN_DB_PREFIX."societe as s";
326  if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
327  $sql.= " WHERE c.fk_soc = s.rowid";
328  $sql.= " AND c.entity IN (".getEntity('commande').")";
329  $sql.= " AND c.fk_statut = 1";
330  if ($socid) $sql.= " AND c.fk_soc = ".$socid;
331  if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
332  $sql.= " ORDER BY c.rowid DESC";
333 
334  $resql=$db->query($sql);
335  if ($resql)
336  {
337  $num = $db->num_rows($resql);
338 
339  print '<table class="noborder" width="100%">';
340  print '<tr class="liste_titre">';
341  print '<th colspan="3">'.$langs->trans("OrdersToProcess").' <a href="'.DOL_URL_ROOT.'/commande/list.php?viewstatut=1"><span class="badge">'.$num.'</span></a></th></tr>';
342 
343  if ($num)
344  {
345  $i = 0;
346  $var = true;
347  while ($i < $num)
348  {
349 
350  $obj = $db->fetch_object($resql);
351  print '<tr class="oddeven">';
352  print '<td class="nowrap" width="20%">';
353 
354  $commandestatic->id=$obj->rowid;
355  $commandestatic->ref=$obj->ref;
356 
357  $companystatic->id=$obj->socid;
358  $companystatic->name=$obj->name;
359  $companystatic->client=$obj->client;
360  $companystatic->code_client=$obj->code_client;
361  $companystatic->canvas=$obj->canvas;
362 
363  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
364  print '<td width="96" class="nobordernopadding nowrap">';
365  print $commandestatic->getNomUrl(1);
366  print '</td>';
367 
368  print '<td width="16" class="nobordernopadding nowrap">';
369  print '&nbsp;';
370  print '</td>';
371 
372  print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">';
373  $filename=dol_sanitizeFileName($obj->ref);
374  $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
375  $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
376  print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
377  print '</td></tr></table>';
378 
379  print '</td>';
380 
381  print '<td class="nowrap">';
382  print $companystatic->getNomUrl(1,'company',24);
383  print '</td>';
384 
385  print '<td align="right">'.$commandestatic->LibStatut($obj->fk_statut,$obj->facture,5).'</td>';
386 
387  print '</tr>';
388  $i++;
389  }
390  }
391 
392  print "</table><br>";
393  }
394  else dol_print_error($db);
395 }
396 
397 /*
398  * Orders thar are in a shipping process
399  */
400 if (! empty($conf->commande->enabled))
401 {
402  $sql = "SELECT c.rowid, c.ref, c.fk_statut, c.facture, s.nom as name, s.rowid as socid";
403  $sql.= ", s.client";
404  $sql.= ", s.code_client";
405  $sql.= ", s.canvas";
406  $sql.= " FROM ".MAIN_DB_PREFIX."commande as c";
407  $sql.= ", ".MAIN_DB_PREFIX."societe as s";
408  if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
409  $sql.= " WHERE c.fk_soc = s.rowid";
410  $sql.= " AND c.entity IN (".getEntity('commande').")";
411  $sql.= " AND c.fk_statut = 2 ";
412  if ($socid) $sql.= " AND c.fk_soc = ".$socid;
413  if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
414  $sql.= " ORDER BY c.rowid DESC";
415 
416  $resql=$db->query($sql);
417  if ($resql)
418  {
419  $num = $db->num_rows($resql);
420 
421  print '<table class="noborder" width="100%">';
422  print '<tr class="liste_titre">';
423  print '<th colspan="3">'.$langs->trans("OnProcessOrders").' <a href="'.DOL_URL_ROOT.'/commande/list.php?viewstatut=2"><span class="badge">'.$num.'</span></a></th></tr>';
424 
425  if ($num)
426  {
427  $i = 0;
428  $var = true;
429  while ($i < $num)
430  {
431 
432  $obj = $db->fetch_object($resql);
433  print '<tr class="oddeven">';
434  print '<td width="20%" class="nowrap">';
435 
436  $commandestatic->id=$obj->rowid;
437  $commandestatic->ref=$obj->ref;
438 
439  $companystatic->id=$obj->socid;
440  $companystatic->name=$obj->name;
441  $companystatic->client=$obj->client;
442  $companystatic->code_client=$obj->code_client;
443  $companystatic->canvas=$obj->canvas;
444 
445  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
446  print '<td width="96" class="nobordernopadding nowrap">';
447  print $commandestatic->getNomUrl(1);
448  print '</td>';
449 
450  print '<td width="16" class="nobordernopadding nowrap">';
451  print '&nbsp;';
452  print '</td>';
453 
454  print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">';
455  $filename=dol_sanitizeFileName($obj->ref);
456  $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
457  $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
458  print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
459  print '</td></tr></table>';
460 
461  print '</td>';
462 
463  print '<td>';
464  print $companystatic->getNomUrl(1,'company');
465  print '</td>';
466 
467  print '<td align="right">'.$commandestatic->LibStatut($obj->fk_statut,$obj->facture,5).'</td>';
468 
469  print '</tr>';
470  $i++;
471  }
472  }
473  print "</table><br>";
474  }
475  else dol_print_error($db);
476 }
477 
478 
479 print '</div></div></div>';
480 
481 
482 llxFooter();
483 
484 $db->close();
llxFooter()
Footer empty.
Definition: index.php:43
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
llxHeader()
Header empty.
Definition: index.php:37
Class to manage customers orders.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Class to offer components to list and upload files.
print
Draft customers invoices.
Definition: index.php:91
Class to build graphs.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->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)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013