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