dolibarr  9.0.0
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2012 Vinicius Nogueira <viniciusvgn@gmail.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
27 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
31 
32 // Security check
33 $orderid = GETPOST('orderid');
34 if ($user->societe_id) $socid=$user->societe_id;
35 $result = restrictedArea($user, 'fournisseur', $orderid, '', 'commande');
36 
37 // Load translation files required by the page
38 $langs->loadLangs(array("suppliers", "orders"));
39 
40 
41 /*
42  * View
43  */
44 
45 llxHeader('',$langs->trans("SuppliersOrdersArea"));
46 
47 $commandestatic = new CommandeFournisseur($db);
48 $userstatic=new User($db);
49 $formfile = new FormFile($db);
50 
51 print load_fiche_titre($langs->trans("SuppliersOrdersArea"));
52 
53 print '<div class="fichecenter"><div class="fichethirdleft">';
54 
55 
56 if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
57 {
58  print '<form method="post" action="list.php">';
59  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
60  print '<table class="noborder nohover" width="100%">';
61  print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
62  print '<tr class="oddeven"><td>';
63  print $langs->trans("SupplierOrder").':</td><td><input type="text" class="flat" name="search_all" size="18"></td><td><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
64  print "</table></form><br>\n";
65 }
66 
67 
68 /*
69  * Statistics
70  */
71 
72 $sql = "SELECT count(cf.rowid), fk_statut";
73 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
74 $sql.= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf";
75 if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
76 $sql.= " WHERE cf.fk_soc = s.rowid";
77 $sql.= " AND cf.entity = ".$conf->entity;
78 if ($user->societe_id) $sql.=' AND cf.fk_soc = '.$user->societe_id;
79 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
80 $sql.= " GROUP BY cf.fk_statut";
81 
82 $resql = $db->query($sql);
83 if ($resql)
84 {
85  $num = $db->num_rows($resql);
86  $i = 0;
87 
88  $total=0;
89  $totalinprocess=0;
90  $dataseries=array();
91  $vals=array();
92  // 0=Draft -> 1=Validated -> 2=Approved -> 3=Process runing -> 4=Received partially -> 5=Received totally -> (reopen) 4=Received partially
93  // -> 7=Canceled/Never received -> (reopen) 3=Process runing
94  // -> 6=Canceled -> (reopen) 2=Approved
95  while ($i < $num)
96  {
97  $row = $db->fetch_row($resql);
98  if ($row)
99  {
100  if ($row[1]!=7 && $row[1]!=6 && $row[1]!=5)
101  {
102  $vals[$row[1]]=$row[0];
103  $totalinprocess+=$row[0];
104  }
105  $total+=$row[0];
106  }
107  $i++;
108  }
109  $db->free($resql);
110 
111  print '<table class="noborder nohover" width="100%">';
112  print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("SuppliersOrders").'</th></tr>';
113  print "</tr>\n";
114  foreach (array(0,1,2,3,4,5,6) as $statut)
115  {
116  $dataseries[]=array($commandestatic->LibStatut($statut,1), (isset($vals[$statut])?(int) $vals[$statut]:0));
117  if (! $conf->use_javascript_ajax)
118  {
119 
120  print '<tr class="oddeven">';
121  print '<td>'.$commandestatic->LibStatut($statut,0).'</td>';
122  print '<td align="right"><a href="list.php?statut='.$statut.'">'.(isset($vals[$statut])?$vals[$statut]:0).'</a></td>';
123  print "</tr>\n";
124  }
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  //if ($totalinprocess != $total)
143  //print '<tr class="liste_total"><td>'.$langs->trans("Total").' ('.$langs->trans("SuppliersOrdersRunning").')</td><td align="right">'.$totalinprocess.'</td></tr>';
144  print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td align="right">'.$total.'</td></tr>';
145 
146  print "</table><br>";
147 }
148 else
149 {
150  dol_print_error($db);
151 }
152 
153 /*
154  * Legends / Status
155  *
156  * Motivo: Mostrar todos os Status e dar a possibilidade de filtrar apenas um deles
157  * Reason: Show all Status and give the possibility to filter only one
158  */
159 
160 $sql = "SELECT count(cf.rowid), fk_statut";
161 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
162 $sql.= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf";
163 if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
164 $sql.= " WHERE cf.fk_soc = s.rowid";
165 $sql.= " AND s.entity = ".$conf->entity;
166 if ($user->societe_id) $sql.=' AND cf.fk_soc = '.$user->societe_id;
167 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
168 $sql.= " GROUP BY cf.fk_statut";
169 
170 $resql = $db->query($sql);
171 if ($resql)
172 {
173  $num = $db->num_rows($resql);
174  $i = 0;
175 
176  print '<table class="liste" width="100%">';
177 
178  print '<tr class="liste_titre"><th>'.$langs->trans("Status").'</th>';
179  print '<th align="right">'.$langs->trans("Nb").'</th>';
180  print "</tr>\n";
181 
182  while ($i < $num)
183  {
184  $row = $db->fetch_row($resql);
185 
186  print '<tr class="oddeven">';
187  print '<td>'.$commandestatic->LibStatut($row[1]).'</td>';
188  print '<td align="right"><a href="list.php?statut='.$row[1].'">'.$row[0].' '.$commandestatic->LibStatut($row[1],3).'</a></td>';
189 
190  print "</tr>\n";
191  $i++;
192  }
193  print "</table><br>";
194  $db->free($resql);
195 }
196 else
197 {
198  dol_print_error($db);
199 }
200 
201 
202 /*
203  * Draft orders
204  */
205 
206 if (! empty($conf->fournisseur->enabled))
207 {
208  $sql = "SELECT c.rowid, c.ref, s.nom as name, s.rowid as socid";
209  $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
210  $sql.= ", ".MAIN_DB_PREFIX."societe as s";
211  if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
212  $sql.= " WHERE c.fk_soc = s.rowid";
213  $sql.= " AND c.entity = ".$conf->entity;
214  $sql.= " AND c.fk_statut = 0";
215  if (! empty($socid)) $sql.= " AND c.fk_soc = ".$socid;
216  if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
217 
218  $resql=$db->query($sql);
219  if ($resql)
220  {
221  print '<table class="noborder" width="100%">';
222  print '<tr class="liste_titre">';
223  print '<th colspan="2">'.$langs->trans("DraftOrders").'</th></tr>';
224  $langs->load("orders");
225  $num = $db->num_rows($resql);
226  if ($num)
227  {
228  $i = 0;
229  while ($i < $num)
230  {
231  $obj = $db->fetch_object($resql);
232 
233  print '<tr class="oddeven">';
234  print '<td class="nowrap">';
235  print "<a href=\"card.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowOrder"),"order").' '.$obj->ref."</a></td>";
236  print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($obj->name,24).'</a></td></tr>';
237  $i++;
238  }
239  }
240  print "</table><br>";
241  }
242 }
243 
244 
245 /*
246  * List of users allowed
247  */
248 $sql = "SELECT u.rowid, u.lastname, u.firstname, u.email";
249 $sql.= " FROM ".MAIN_DB_PREFIX."user as u,";
250 $sql.= " ".MAIN_DB_PREFIX."user_rights as ur";
251 $sql.= ", ".MAIN_DB_PREFIX."rights_def as rd";
252 $sql.= " WHERE u.rowid = ur.fk_user";
253 $sql.= " AND (u.entity IN (0,".$conf->entity.")";
254 $sql.= " AND rd.entity = ".$conf->entity.")";
255 $sql.= " AND ur.fk_id = rd.id";
256 $sql.= " AND module = 'fournisseur'";
257 $sql.= " AND perms = 'commande'";
258 $sql.= " AND subperms = 'approuver'";
259 
260 $resql = $db->query($sql);
261 if ($resql)
262 {
263  $num = $db->num_rows($resql);
264  $i = 0;
265 
266  print '<table class="liste" width="100%">';
267  print '<tr class="liste_titre"><th>'.$langs->trans("UserWithApproveOrderGrant").'</th>';
268  print "</tr>\n";
269 
270  while ($i < $num)
271  {
272  $obj = $db->fetch_object($resql);
273 
274  print '<tr class="oddeven">';
275  print '<td>';
276  $userstatic->id=$obj->rowid;
277  $userstatic->lastname=$obj->lastname;
278  $userstatic->firstname=$obj->firstname;
279  $userstatic->email=$obj->email;
280  print $userstatic->getNomUrl(1);
281  print '</td>';
282  print "</tr>\n";
283  $i++;
284  }
285  print "</table><br>";
286  $db->free($resql);
287 }
288 else
289 {
290  dol_print_error($db);
291 }
292 
293 
294 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
295 
296 
297 /*
298  * Last modified orders
299 */
300 $max=5;
301 
302 $sql = "SELECT c.rowid, c.ref, c.fk_statut, c.tms, s.nom as name, s.rowid as socid";
303 $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
304 $sql.= ", ".MAIN_DB_PREFIX."societe as s";
305 if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
306 $sql.= " WHERE c.fk_soc = s.rowid";
307 $sql.= " AND c.entity = ".$conf->entity;
308 //$sql.= " AND c.fk_statut > 2";
309 if (! empty($socid)) $sql .= " AND c.fk_soc = ".$socid;
310 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
311 $sql.= " ORDER BY c.tms DESC";
312 $sql.= $db->plimit($max, 0);
313 
314 $resql=$db->query($sql);
315 if ($resql)
316 {
317  print '<table class="noborder" width="100%">';
318  print '<tr class="liste_titre">';
319  print '<th colspan="4">'.$langs->trans("LastModifiedOrders",$max).'</th></tr>';
320 
321  $num = $db->num_rows($resql);
322  if ($num)
323  {
324  $i = 0;
325  while ($i < $num)
326  {
327  $obj = $db->fetch_object($resql);
328 
329  print '<tr class="oddeven">';
330  print '<td width="20%" class="nowrap">';
331 
332  $commandestatic->id=$obj->rowid;
333  $commandestatic->ref=$obj->ref;
334 
335  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
336  print '<td width="96" class="nobordernopadding nowrap">';
337  print $commandestatic->getNomUrl(1);
338  print '</td>';
339 
340  print '<td width="16" class="nobordernopadding nowrap">';
341  print '&nbsp;';
342  print '</td>';
343 
344  print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">';
345  $filename=dol_sanitizeFileName($obj->ref);
346  $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
347  $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
348  print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
349  print '</td></tr></table>';
350 
351  print '</td>';
352 
353  print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->name.'</a></td>';
354  print '<td>'.dol_print_date($db->jdate($obj->tms),'day').'</td>';
355  print '<td align="right">'.$commandestatic->LibStatut($obj->fk_statut,5).'</td>';
356  print '</tr>';
357  $i++;
358  }
359  }
360  print "</table><br>";
361 }
362 else dol_print_error($db);
363 
364 
365 /*
366  * Orders to process
367 */
368 /*
369  $sql = "SELECT c.rowid, c.ref, c.fk_statut, s.nom as name, s.rowid as socid";
370 $sql.=" FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
371 $sql.= ", ".MAIN_DB_PREFIX."societe as s";
372 if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
373 $sql.= " WHERE c.fk_soc = s.rowid";
374 $sql.= " AND c.entity = ".$conf->entity;
375 $sql.= " AND c.fk_statut = 1";
376 if ($socid) $sql.= " AND c.fk_soc = ".$socid;
377 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
378 $sql.= " ORDER BY c.rowid DESC";
379 
380 $resql=$db->query($sql);
381 if ($resql)
382 {
383 $num = $db->num_rows($resql);
384 
385 print '<table class="noborder" width="100%">';
386 print '<tr class="liste_titre">';
387 print '<th colspan="3">'.$langs->trans("OrdersToProcess").' <a href="'.DOL_URL_ROOT.'/commande/list.php?viewstatut=1">('.$num.')</a></th></tr>';
388 
389 if ($num)
390 {
391 $i = 0;
392 while ($i < $num)
393 {
394 $obj = $db->fetch_object($resql);
395 
396 print '<tr class="oddeven">';
397 print '<td class="nowrap">';
398 
399 $commandestatic->id=$obj->rowid;
400 $commandestatic->ref=$obj->ref;
401 
402 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
403 print '<td width="96" class="nobordernopadding nowrap">';
404 print $commandestatic->getNomUrl(1);
405 print '</td>';
406 
407 print '<td width="16" class="nobordernopadding nowrap">';
408 print '&nbsp;';
409 print '</td>';
410 
411 print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">';
412 $filename=dol_sanitizeFileName($obj->ref);
413 $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
414 $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
415 print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
416 print '</td></tr></table>';
417 
418 print '</td>';
419 
420 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>';
421 
422 print '<td align="right">'.$commandestatic->LibStatut($obj->fk_statut,$obj->facture,5).'</td>';
423 
424 print '</tr>';
425 $i++;
426 }
427 }
428 
429 print "</table><br>";
430 }
431 */
432 
433 print '</div></div></div>';
434 
435 // End of page
436 llxFooter();
437 $db->close();
llxFooter()
Footer empty.
Definition: index.php:44
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
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.
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:1053
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Class to manage Dolibarr users.
Definition: user.class.php:41
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
llxHeader()
Header empty.
Definition: index.php:36
Class to manage predefined suppliers products.
Class to offer components to list and upload files.
Class to build graphs.
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)