dolibarr  7.0.0-beta
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@capnetworks.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 $langs->load("suppliers");
38 $langs->load("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  $var=false;
59  print '<form method="post" action="list.php">';
60  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
61  print '<table class="noborder nohover" width="100%">';
62  print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
63  print '<tr class="oddeven"><td>';
64  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>';
65  print "</table></form><br>\n";
66 }
67 
68 
69 /*
70  * Statistics
71  */
72 
73 $sql = "SELECT count(cf.rowid), fk_statut";
74 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
75 $sql.= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf";
76 if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
77 $sql.= " WHERE cf.fk_soc = s.rowid";
78 $sql.= " AND cf.entity = ".$conf->entity;
79 if ($user->societe_id) $sql.=' AND cf.fk_soc = '.$user->societe_id;
80 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
81 $sql.= " GROUP BY cf.fk_statut";
82 
83 $resql = $db->query($sql);
84 if ($resql)
85 {
86  $num = $db->num_rows($resql);
87  $i = 0;
88 
89  $var=True;
90 
91  $total=0;
92  $totalinprocess=0;
93  $dataseries=array();
94  $vals=array();
95  // 0=Draft -> 1=Validated -> 2=Approved -> 3=Process runing -> 4=Received partially -> 5=Received totally -> (reopen) 4=Received partially
96  // -> 7=Canceled/Never received -> (reopen) 3=Process runing
97  // -> 6=Canceled -> (reopen) 2=Approved
98  while ($i < $num)
99  {
100  $row = $db->fetch_row($resql);
101  if ($row)
102  {
103  if ($row[1]!=7 && $row[1]!=6 && $row[1]!=5)
104  {
105  $vals[$row[1]]=$row[0];
106  $totalinprocess+=$row[0];
107  }
108  $total+=$row[0];
109  }
110  $i++;
111  }
112  $db->free($resql);
113 
114  print '<table class="noborder nohover" width="100%">';
115  print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("SuppliersOrders").'</th></tr>';
116  print "</tr>\n";
117  foreach (array(0,1,2,3,4,5,6) as $statut)
118  {
119  $dataseries[]=array($commandestatic->LibStatut($statut,1), (isset($vals[$statut])?(int) $vals[$statut]:0));
120  if (! $conf->use_javascript_ajax)
121  {
122 
123  print '<tr class="oddeven">';
124  print '<td>'.$commandestatic->LibStatut($statut,0).'</td>';
125  print '<td align="right"><a href="list.php?statut='.$statut.'">'.(isset($vals[$statut])?$vals[$statut]:0).'</a></td>';
126  print "</tr>\n";
127  }
128  }
129  if ($conf->use_javascript_ajax)
130  {
131  print '<tr class="impair"><td align="center" colspan="2">';
132 
133  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
134  $dolgraph = new DolGraph();
135  $dolgraph->SetData($dataseries);
136  $dolgraph->setShowLegend(1);
137  $dolgraph->setShowPercent(1);
138  $dolgraph->SetType(array('pie'));
139  $dolgraph->setWidth('100%');
140  $dolgraph->draw('idgraphstatus');
141  print $dolgraph->show($total?0:1);
142 
143  print '</td></tr>';
144  }
145  //if ($totalinprocess != $total)
146  //print '<tr class="liste_total"><td>'.$langs->trans("Total").' ('.$langs->trans("SuppliersOrdersRunning").')</td><td align="right">'.$totalinprocess.'</td></tr>';
147  print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td align="right">'.$total.'</td></tr>';
148 
149  print "</table><br>";
150 }
151 else
152 {
153  dol_print_error($db);
154 }
155 
156 /*
157  * Legends / Status
158  *
159  * Motivo: Mostrar todos os Status e dar a possibilidade de filtrar apenas um deles
160  * Reason: Show all Status and give the possibility to filter only one
161  */
162 
163 $sql = "SELECT count(cf.rowid), fk_statut";
164 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
165 $sql.= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf";
166 if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
167 $sql.= " WHERE cf.fk_soc = s.rowid";
168 $sql.= " AND s.entity = ".$conf->entity;
169 if ($user->societe_id) $sql.=' AND cf.fk_soc = '.$user->societe_id;
170 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
171 $sql.= " GROUP BY cf.fk_statut";
172 
173 $resql = $db->query($sql);
174 if ($resql)
175 {
176  $num = $db->num_rows($resql);
177  $i = 0;
178 
179  print '<table class="liste" width="100%">';
180 
181  print '<tr class="liste_titre"><th>'.$langs->trans("Status").'</th>';
182  print '<th align="right">'.$langs->trans("Nb").'</th>';
183  print "</tr>\n";
184  $var=True;
185 
186  while ($i < $num)
187  {
188  $row = $db->fetch_row($resql);
189 
190 
191  print '<tr class="oddeven">';
192  print '<td>'.$langs->trans($commandestatic->statuts[$row[1]]).'</td>';
193  print '<td align="right"><a href="list.php?statut='.$row[1].'">'.$row[0].' '.$commandestatic->LibStatut($row[1],3).'</a></td>';
194 
195  print "</tr>\n";
196  $i++;
197  }
198  print "</table><br>";
199  $db->free($resql);
200 }
201 else
202 {
203  dol_print_error($db);
204 }
205 
206 
207 /*
208  * Draft orders
209  */
210 
211 if (! empty($conf->fournisseur->enabled))
212 {
213  $sql = "SELECT c.rowid, c.ref, s.nom as name, s.rowid as socid";
214  $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
215  $sql.= ", ".MAIN_DB_PREFIX."societe as s";
216  if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
217  $sql.= " WHERE c.fk_soc = s.rowid";
218  $sql.= " AND c.entity = ".$conf->entity;
219  $sql.= " AND c.fk_statut = 0";
220  if (! empty($socid)) $sql.= " AND c.fk_soc = ".$socid;
221  if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
222 
223  $resql=$db->query($sql);
224  if ($resql)
225  {
226  print '<table class="noborder" width="100%">';
227  print '<tr class="liste_titre">';
228  print '<th colspan="2">'.$langs->trans("DraftOrders").'</th></tr>';
229  $langs->load("orders");
230  $num = $db->num_rows($resql);
231  if ($num)
232  {
233  $i = 0;
234  $var = True;
235  while ($i < $num)
236  {
237 
238  $obj = $db->fetch_object($resql);
239  print '<tr class="oddeven">';
240  print '<td class="nowrap">';
241  print "<a href=\"card.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowOrder"),"order").' '.$obj->ref."</a></td>";
242  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>';
243  $i++;
244  }
245  }
246  print "</table><br>";
247  }
248 }
249 
250 
251 /*
252  * List of users allowed
253  */
254 $sql = "SELECT u.rowid, u.lastname, u.firstname, u.email";
255 $sql.= " FROM ".MAIN_DB_PREFIX."user as u,";
256 $sql.= " ".MAIN_DB_PREFIX."user_rights as ur";
257 $sql.= ", ".MAIN_DB_PREFIX."rights_def as rd";
258 $sql.= " WHERE u.rowid = ur.fk_user";
259 $sql.= " AND (u.entity IN (0,".$conf->entity.")";
260 $sql.= " AND rd.entity = ".$conf->entity.")";
261 $sql.= " AND ur.fk_id = rd.id";
262 $sql.= " AND module = 'fournisseur'";
263 $sql.= " AND perms = 'commande'";
264 $sql.= " AND subperms = 'approuver'";
265 
266 $resql = $db->query($sql);
267 if ($resql)
268 {
269  $num = $db->num_rows($resql);
270  $i = 0;
271 
272  print '<table class="liste" width="100%">';
273  print '<tr class="liste_titre"><th>'.$langs->trans("UserWithApproveOrderGrant").'</th>';
274  print "</tr>\n";
275  $var=True;
276 
277  while ($i < $num)
278  {
279  $obj = $db->fetch_object($resql);
280 
281 
282  print '<tr class="oddeven">';
283  print '<td>';
284  $userstatic->id=$obj->rowid;
285  $userstatic->lastname=$obj->lastname;
286  $userstatic->firstname=$obj->firstname;
287  $userstatic->email=$obj->email;
288  print $userstatic->getNomUrl(1);
289  print '</td>';
290  print "</tr>\n";
291  $i++;
292  }
293  print "</table><br>";
294  $db->free($resql);
295 }
296 else
297 {
298  dol_print_error($db);
299 }
300 
301 
302 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
303 
304 
305 /*
306  * Last modified orders
307 */
308 $max=5;
309 
310 $sql = "SELECT c.rowid, c.ref, c.fk_statut, c.tms, s.nom as name, s.rowid as socid";
311 $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
312 $sql.= ", ".MAIN_DB_PREFIX."societe as s";
313 if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
314 $sql.= " WHERE c.fk_soc = s.rowid";
315 $sql.= " AND c.entity = ".$conf->entity;
316 //$sql.= " AND c.fk_statut > 2";
317 if (! empty($socid)) $sql .= " AND c.fk_soc = ".$socid;
318 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
319 $sql.= " ORDER BY c.tms DESC";
320 $sql.= $db->plimit($max, 0);
321 
322 $resql=$db->query($sql);
323 if ($resql)
324 {
325  print '<table class="noborder" width="100%">';
326  print '<tr class="liste_titre">';
327  print '<th colspan="4">'.$langs->trans("LastModifiedOrders",$max).'</th></tr>';
328 
329  $num = $db->num_rows($resql);
330  if ($num)
331  {
332  $i = 0;
333  $var = True;
334  while ($i < $num)
335  {
336 
337  $obj = $db->fetch_object($resql);
338 
339  print '<tr class="oddeven">';
340  print '<td width="20%" class="nowrap">';
341 
342  $commandestatic->id=$obj->rowid;
343  $commandestatic->ref=$obj->ref;
344 
345  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
346  print '<td width="96" class="nobordernopadding nowrap">';
347  print $commandestatic->getNomUrl(1);
348  print '</td>';
349 
350  print '<td width="16" class="nobordernopadding nowrap">';
351  print '&nbsp;';
352  print '</td>';
353 
354  print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">';
355  $filename=dol_sanitizeFileName($obj->ref);
356  $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
357  $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
358  print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
359  print '</td></tr></table>';
360 
361  print '</td>';
362 
363  print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->name.'</a></td>';
364  print '<td>'.dol_print_date($db->jdate($obj->tms),'day').'</td>';
365  print '<td align="right">'.$commandestatic->LibStatut($obj->fk_statut,5).'</td>';
366  print '</tr>';
367  $i++;
368  }
369  }
370  print "</table><br>";
371 }
372 else dol_print_error($db);
373 
374 
375 /*
376  * Orders to process
377 */
378 /*
379  $sql = "SELECT c.rowid, c.ref, c.fk_statut, s.nom as name, s.rowid as socid";
380 $sql.=" FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
381 $sql.= ", ".MAIN_DB_PREFIX."societe as s";
382 if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
383 $sql.= " WHERE c.fk_soc = s.rowid";
384 $sql.= " AND c.entity = ".$conf->entity;
385 $sql.= " AND c.fk_statut = 1";
386 if ($socid) $sql.= " AND c.fk_soc = ".$socid;
387 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
388 $sql.= " ORDER BY c.rowid DESC";
389 
390 $resql=$db->query($sql);
391 if ($resql)
392 {
393 $num = $db->num_rows($resql);
394 
395 print '<table class="noborder" width="100%">';
396 print '<tr class="liste_titre">';
397 print '<th colspan="3">'.$langs->trans("OrdersToProcess").' <a href="'.DOL_URL_ROOT.'/commande/list.php?viewstatut=1">('.$num.')</a></th></tr>';
398 
399 if ($num)
400 {
401 $i = 0;
402 $var = True;
403 while ($i < $num)
404 {
405 
406 $obj = $db->fetch_object($resql);
407 print '<tr class="oddeven">';
408 print '<td class="nowrap">';
409 
410 $commandestatic->id=$obj->rowid;
411 $commandestatic->ref=$obj->ref;
412 
413 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
414 print '<td width="96" class="nobordernopadding nowrap">';
415 print $commandestatic->getNomUrl(1);
416 print '</td>';
417 
418 print '<td width="16" class="nobordernopadding nowrap">';
419 print '&nbsp;';
420 print '</td>';
421 
422 print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">';
423 $filename=dol_sanitizeFileName($obj->ref);
424 $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
425 $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
426 print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
427 print '</td></tr></table>';
428 
429 print '</td>';
430 
431 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>';
432 
433 print '<td align="right">'.$commandestatic->LibStatut($obj->fk_statut,$obj->facture,5).'</td>';
434 
435 print '</tr>';
436 $i++;
437 }
438 }
439 
440 print "</table><br>";
441 }
442 */
443 
444 print '</div></div></div>';
445 
446 llxFooter();
447 
448 $db->close();
llxFooter()
Footer empty.
Definition: index.php:43
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.
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:39
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
llxHeader()
Header empty.
Definition: index.php:37
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Class to manage predefined suppliers products.
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
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.