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