dolibarr  13.0.2
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  * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
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.'/fourn/class/fournisseur.commande.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
32 
33 // Security check
34 $orderid = GETPOST('orderid');
35 if ($user->socid) $socid = $user->socid;
36 $result = restrictedArea($user, 'fournisseur', $orderid, '', 'commande');
37 
38 $hookmanager = new HookManager($db);
39 
40 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
41 $hookmanager->initHooks(array('orderssuppliersindex'));
42 
43 // Load translation files required by the page
44 $langs->loadLangs(array("suppliers", "orders"));
45 
46 
47 /*
48  * View
49  */
50 
51 llxHeader('', $langs->trans("SuppliersOrdersArea"));
52 
53 $commandestatic = new CommandeFournisseur($db);
54 $userstatic = new User($db);
55 $formfile = new FormFile($db);
56 
57 print load_fiche_titre($langs->trans("SuppliersOrdersArea"), '', 'supplier_order');
58 
59 print '<div class="fichecenter"><div class="fichethirdleft">';
60 
61 
62 if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
63 {
64  print '<form method="post" action="list.php">';
65  print '<input type="hidden" name="token" value="'.newToken().'">';
66  print '<div class="div-table-responsive-no-min">';
67  print '<table class="noborder nohover centpercent">';
68  print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
69  print '<tr class="oddeven"><td>';
70  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>';
71  print "</table></div></form><br>\n";
72 }
73 
74 
75 /*
76  * Statistics
77  */
78 
79 $sql = "SELECT count(cf.rowid) as nb, fk_statut as status";
80 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
81 $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf";
82 if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
83 $sql .= " WHERE cf.fk_soc = s.rowid";
84 $sql .= " AND cf.entity IN (".getEntity('supplier_order').")";
85 if ($user->socid) $sql .= ' AND cf.fk_soc = '.$user->socid;
86 if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
87 $sql .= " GROUP BY cf.fk_statut";
88 
89 $resql = $db->query($sql);
90 if ($resql)
91 {
92  $num = $db->num_rows($resql);
93  $i = 0;
94 
95  $total = 0;
96  $dataseries = array();
97  $vals = array();
98  // 0=Draft -> 1=Validated -> 2=Approved -> 3=Process runing -> 4=Received partially -> 5=Received totally -> (reopen) 4=Received partially
99  // -> 7=Canceled/Never received -> (reopen) 3=Process runing
100  // -> 6=Canceled -> (reopen) 2=Approved
101  while ($i < $num)
102  {
103  $obj = $db->fetch_object($resql);
104  if ($obj)
105  {
106  $vals[($obj->status == CommandeFournisseur::STATUS_CANCELED_AFTER_ORDER ? CommandeFournisseur::STATUS_CANCELED : $obj->status)] = $obj->nb;
107 
108  $total += $obj->nb;
109  }
110  $i++;
111  }
112  $db->free($resql);
113 
114  include_once DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
115 
116  print '<div class="div-table-responsive-no-min">';
117  print '<table class="noborder nohover centpercent">';
118  print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("SuppliersOrders").'</th></tr>';
119  print "</tr>\n";
120  $listofstatus = array(0, 1, 2, 3, 4, 5, 6, 9);
121  foreach ($listofstatus as $status)
122  {
123  $dataseries[] = array($commandestatic->LibStatut($status, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0));
124  if ($status == CommandeFournisseur::STATUS_DRAFT) $colorseries[$status] = '-'.$badgeStatus0;
125  if ($status == CommandeFournisseur::STATUS_VALIDATED) $colorseries[$status] = '-'.$badgeStatus1;
126  if ($status == CommandeFournisseur::STATUS_ACCEPTED) $colorseries[$status] = $badgeStatus1;
127  if ($status == CommandeFournisseur::STATUS_REFUSED) $colorseries[$status] = $badgeStatus9;
128  if ($status == CommandeFournisseur::STATUS_ORDERSENT) $colorseries[$status] = $badgeStatus4;
129  if ($status == CommandeFournisseur::STATUS_RECEIVED_PARTIALLY) $colorseries[$status] = '-'.$badgeStatus4;
130  if ($status == CommandeFournisseur::STATUS_RECEIVED_COMPLETELY) $colorseries[$status] = $badgeStatus6;
131  if ($status == CommandeFournisseur::STATUS_CANCELED || $status == CommandeFournisseur::STATUS_CANCELED_AFTER_ORDER) $colorseries[$status] = $badgeStatus9;
132 
133  if (!$conf->use_javascript_ajax)
134  {
135  print '<tr class="oddeven">';
136  print '<td>'.$commandestatic->LibStatut($status, 0).'</td>';
137  print '<td class="right"><a href="list.php?statut='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).'</a></td>';
138  print "</tr>\n";
139  }
140  }
141  if ($conf->use_javascript_ajax)
142  {
143  print '<tr class="impair"><td class="center" colspan="2">';
144 
145  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
146  $dolgraph = new DolGraph();
147  $dolgraph->SetData($dataseries);
148  $dolgraph->SetDataColor(array_values($colorseries));
149  $dolgraph->setShowLegend(2);
150  $dolgraph->setShowPercent(1);
151  $dolgraph->SetType(array('pie'));
152  $dolgraph->setHeight('200');
153  $dolgraph->draw('idgraphstatus');
154  print $dolgraph->show($total ? 0 : 1);
155 
156  print '</td></tr>';
157  }
158  //if ($totalinprocess != $total)
159  //print '<tr class="liste_total"><td>'.$langs->trans("Total").' ('.$langs->trans("SuppliersOrdersRunning").')</td><td class="right">'.$totalinprocess.'</td></tr>';
160  print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$total.'</td></tr>';
161 
162  print "</table></div><br>";
163 } else {
164  dol_print_error($db);
165 }
166 
167 /*
168  * Draft orders
169  */
170 
171 if (!empty($conf->fournisseur->enabled))
172 {
173  $sql = "SELECT c.rowid, c.ref, s.nom as name, s.rowid as socid";
174  $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur 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("supplier_order").")"; // Thirdparty sharing is mandatory with supplier order sharing
179  $sql .= " AND c.fk_statut = 0";
180  if (!empty($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 '<div class="div-table-responsive-no-min">';
187  print '<table class="noborder centpercent">';
188  print '<tr class="liste_titre">';
189  print '<th colspan="2">'.$langs->trans("DraftOrders").'</th></tr>';
190  $langs->load("orders");
191  $num = $db->num_rows($resql);
192  if ($num)
193  {
194  $i = 0;
195  while ($i < $num)
196  {
197  $obj = $db->fetch_object($resql);
198 
199  print '<tr class="oddeven">';
200  print '<td class="nowrap">';
201  print "<a href=\"card.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowOrder"), "order").' '.$obj->ref."</a></td>";
202  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>';
203  $i++;
204  }
205  }
206  print "</table></div><br>";
207  }
208 }
209 
210 
211 /*
212  * List of users allowed
213  */
214 
215 $sql = "SELECT";
216 if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
217  $sql .= " DISTINCT";
218 }
219 $sql .= " u.rowid, u.lastname, u.firstname, u.email, u.statut";
220 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
221 if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
222 {
223  $sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug";
224  $sql .= " WHERE ((ug.fk_user = u.rowid";
225  $sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
226  $sql .= " OR u.entity = 0)"; // Show always superadmin
227 } else {
228  $sql .= " WHERE (u.entity IN (".getEntity('user')."))";
229 }
230 $sql .= " AND u.fk_soc IS NULL"; // An external user can not approved
231 
232 $resql = $db->query($sql);
233 if ($resql)
234 {
235  $num = $db->num_rows($resql);
236  $i = 0;
237 
238  print '<div class="div-table-responsive-no-min">';
239  print '<table class="liste centpercent">';
240  print '<tr class="liste_titre"><th>'.$langs->trans("UserWithApproveOrderGrant").'</th>';
241  print "</tr>\n";
242 
243  while ($i < $num)
244  {
245  $obj = $db->fetch_object($resql);
246 
247  $userstatic = new User($db);
248  $userstatic->id = $obj->rowid;
249  $userstatic->getrights('fournisseur');
250 
251  if (!empty($userstatic->rights->fournisseur->commande->approuver))
252  {
253  print '<tr class="oddeven">';
254  print '<td>';
255  $userstatic->lastname = $obj->lastname;
256  $userstatic->firstname = $obj->firstname;
257  $userstatic->email = $obj->email;
258  $userstatic->statut = $obj->statut;
259  print $userstatic->getNomUrl(1);
260  print '</td>';
261  print "</tr>\n";
262  }
263 
264  $i++;
265  }
266  print "</table></div><br>";
267  $db->free($resql);
268 } else {
269  dol_print_error($db);
270 }
271 
272 
273 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
274 
275 
276 /*
277  * Last modified orders
278 */
279 $max = 5;
280 
281 $sql = "SELECT c.rowid, c.ref, c.fk_statut as status, c.tms, c.billed, s.nom as name, s.rowid as socid";
282 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
283 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
284 if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
285 $sql .= " WHERE c.fk_soc = s.rowid";
286 $sql .= " AND c.entity = ".$conf->entity;
287 //$sql.= " AND c.fk_statut > 2";
288 if (!empty($socid)) $sql .= " AND c.fk_soc = ".$socid;
289 if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
290 $sql .= " ORDER BY c.tms DESC";
291 $sql .= $db->plimit($max, 0);
292 
293 $resql = $db->query($sql);
294 if ($resql)
295 {
296  print '<div class="div-table-responsive-no-min">';
297  print '<table class="noborder centpercent">';
298  print '<tr class="liste_titre">';
299  print '<th colspan="4">'.$langs->trans("LastModifiedOrders", $max).'</th></tr>';
300 
301  $num = $db->num_rows($resql);
302  if ($num)
303  {
304  $i = 0;
305  while ($i < $num)
306  {
307  $obj = $db->fetch_object($resql);
308 
309  print '<tr class="oddeven">';
310  print '<td width="20%" class="nowrap">';
311 
312  $commandestatic->id = $obj->rowid;
313  $commandestatic->ref = $obj->ref;
314 
315  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
316  print '<td width="96" class="nobordernopadding nowrap">';
317  print $commandestatic->getNomUrl(1);
318  print '</td>';
319 
320  print '<td width="16" class="nobordernopadding nowrap">';
321  print '&nbsp;';
322  print '</td>';
323 
324  print '<td width="16" class="right nobordernopadding hideonsmartphone">';
325  $filename = dol_sanitizeFileName($obj->ref);
326  $filedir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
327  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
328  print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
329  print '</td></tr></table>';
330 
331  print '</td>';
332 
333  print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.'</a></td>';
334  print '<td>'.dol_print_date($db->jdate($obj->tms), 'day').'</td>';
335  print '<td class="right">'.$commandestatic->LibStatut($obj->status, 3, $obj->billed).'</td>';
336  print '</tr>';
337  $i++;
338  }
339  }
340  print "</table></div><br>";
341 } else dol_print_error($db);
342 
343 
344 /*
345  * Orders to process
346 */
347 /*
348  $sql = "SELECT c.rowid, c.ref, c.fk_statut, s.nom as name, s.rowid as socid";
349 $sql.=" FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
350 $sql.= ", ".MAIN_DB_PREFIX."societe as s";
351 if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
352 $sql.= " WHERE c.fk_soc = s.rowid";
353 $sql.= " AND c.entity = ".$conf->entity;
354 $sql.= " AND c.fk_statut = 1";
355 if ($socid) $sql.= " AND c.fk_soc = ".$socid;
356 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
357 $sql.= " ORDER BY c.rowid DESC";
358 
359 $resql=$db->query($sql);
360 if ($resql)
361 {
362 $num = $db->num_rows($resql);
363 
364 print '<div class="div-table-responsive-no-min">';
365 print '<table class="noborder centpercent">';
366 print '<tr class="liste_titre">';
367 print '<th colspan="3">'.$langs->trans("OrdersToProcess").' <a href="'.DOL_URL_ROOT.'/commande/list.php?search_status=1">('.$num.')</a></th></tr>';
368 
369 if ($num)
370 {
371 $i = 0;
372 while ($i < $num)
373 {
374 $obj = $db->fetch_object($resql);
375 
376 print '<tr class="oddeven">';
377 print '<td class="nowrap">';
378 
379 $commandestatic->id=$obj->rowid;
380 $commandestatic->ref=$obj->ref;
381 
382 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
383 print '<td width="96" class="nobordernopadding nowrap">';
384 print $commandestatic->getNomUrl(1);
385 print '</td>';
386 
387 print '<td width="16" class="nobordernopadding nowrap">';
388 print '&nbsp;';
389 print '</td>';
390 
391 print '<td width="16" class="right nobordernopadding hideonsmartphone">';
392 $filename=dol_sanitizeFileName($obj->ref);
393 $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
394 $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
395 print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
396 print '</td></tr></table>';
397 
398 print '</td>';
399 
400 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>';
401 
402 print '<td class="right">'.$commandestatic->LibStatut($obj->fk_statut,$obj->facture,5).'</td>';
403 
404 print '</tr>';
405 $i++;
406 }
407 }
408 
409 print "</table></div><br>";
410 }
411 */
412 
413 print '</div></div></div>';
414 
415 $parameters = array('user' => $user);
416 $reshook = $hookmanager->executeHooks('dashboardOrdersSuppliers', $parameters, $object); // Note that $action and $object may have been modified by hook
417 
418 // End of page
419 llxFooter();
420 $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_DRAFT
Draft status.
const STATUS_RECEIVED_COMPLETELY
Received completely.
const STATUS_CANCELED_AFTER_ORDER
Order canceled/never received.
Class to manage Dolibarr users.
Definition: user.class.php:44
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage hooks.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
const STATUS_RECEIVED_PARTIALLY
Received partially.
const STATUS_VALIDATED
Validated status.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
Class to manage predefined suppliers products.
Class to offer components to list and upload files.
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
const STATUS_ORDERSENT
Order sent, shipment on process.
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...
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.
const STATUS_CANCELED
Order canceled.
llxFooter()
Empty footer.
Definition: wrapper.php:59