dolibarr 21.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@inodbox.com>
5 * Copyright (C) 2012 Vinicius Nogueira <viniciusvgn@gmail.com>
6 * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
7 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
30// Load Dolibarr environment
31require '../../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
33require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
34require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
35
36
45// Load translation files required by the page
46$langs->loadLangs(array("suppliers", "orders"));
47
48// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
49$hookmanager->initHooks(array('orderssuppliersindex'));
50
51$max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
52
53// Security check
54$orderid = GETPOST('orderid');
55$socid = GETPOSTINT('socid');
56if ($user->socid) {
57 $socid = $user->socid;
58}
59$result = restrictedArea($user, 'fournisseur', $orderid, '', 'commande');
60
61
62/*
63 * View
64 */
65
66llxHeader('', $langs->trans("SuppliersOrdersArea"), '', '', 0, 0, '', '', '', 'mod-supplier-order page-stats');
67
68$commandestatic = new CommandeFournisseur($db);
69$userstatic = new User($db);
70$formfile = new FormFile($db);
71
72print load_fiche_titre($langs->trans("SuppliersOrdersArea"), '', 'supplier_order');
73
74print '<div class="fichecenter"><div class="fichethirdleft">';
75
76/*
77 * Statistics
78 */
79
80$sql = "SELECT count(cf.rowid) as nb, fk_statut as status";
81$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
82$sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf";
83if (!$user->hasRight("societe", "client", "voir") && !$socid) {
84 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
85}
86$sql .= " WHERE cf.fk_soc = s.rowid";
87$sql .= " AND cf.entity IN (".getEntity('supplier_order').")";
88if ($user->socid) {
89 $sql .= ' AND cf.fk_soc = '.((int) $user->socid);
90}
91if (!$user->hasRight("societe", "client", "voir") && !$socid) {
92 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
93}
94$sql .= " GROUP BY cf.fk_statut";
95
96$resql = $db->query($sql);
97if ($resql) {
98 $num = $db->num_rows($resql);
99 $i = 0;
100
101 $total = 0;
102 $dataseries = array();
103 $colorseries = array();
104 $vals = array();
105 // 0=Draft -> 1=Validated -> 2=Approved -> 3=Process running -> 4=Received partially -> 5=Received totally -> (reopen) 4=Received partially
106 // -> 7=Canceled/Never received -> (reopen) 3=Process running
107 // -> 6=Canceled -> (reopen) 2=Approved
108 while ($i < $num) {
109 $obj = $db->fetch_object($resql);
110 if ($obj) {
111 $vals[($obj->status == CommandeFournisseur::STATUS_CANCELED_AFTER_ORDER ? CommandeFournisseur::STATUS_CANCELED : $obj->status)] = $obj->nb;
112
113 $total += $obj->nb;
114 }
115 $i++;
116 }
117 $db->free($resql);
118
119 include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
127 print '<div class="div-table-responsive-no-min">';
128 print '<table class="noborder nohover centpercent">';
129 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("SuppliersOrders").'</th></tr>';
130 print "</tr>\n";
131 $listofstatus = array(0, 1, 2, 3, 4, 5, 6, 9);
132 foreach ($listofstatus as $status) {
133 $dataseries[] = array($commandestatic->LibStatut($status, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0));
134 if ($status == CommandeFournisseur::STATUS_DRAFT) {
135 $colorseries[$status] = '-'.$badgeStatus0;
136 }
138 $colorseries[$status] = '-'.$badgeStatus1;
139 }
141 $colorseries[$status] = $badgeStatus1;
142 }
144 $colorseries[$status] = $badgeStatus9;
145 }
147 $colorseries[$status] = $badgeStatus4;
148 }
150 $colorseries[$status] = '-'.$badgeStatus4;
151 }
153 $colorseries[$status] = $badgeStatus6;
154 }
156 $colorseries[$status] = $badgeStatus9;
157 }
158
159 if (!$conf->use_javascript_ajax) {
160 print '<tr class="oddeven">';
161 print '<td>'.$commandestatic->LibStatut($status, 0).'</td>';
162 print '<td class="right"><a href="list.php?statut='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).'</a></td>';
163 print "</tr>\n";
164 }
165 }
166 if ($conf->use_javascript_ajax) {
167 print '<tr class="impair"><td class="center" colspan="2">';
168
169 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
170 $dolgraph = new DolGraph();
171 $dolgraph->SetData($dataseries);
172 $dolgraph->SetDataColor(array_values($colorseries));
173 $dolgraph->setShowLegend(2);
174 $dolgraph->setShowPercent(1);
175 $dolgraph->SetType(array('pie'));
176 $dolgraph->setHeight('200');
177 $dolgraph->draw('idgraphstatus');
178 print $dolgraph->show($total ? 0 : 1);
179
180 print '</td></tr>';
181 }
182 //if ($totalinprocess != $total)
183 //print '<tr class="liste_total"><td>'.$langs->trans("Total").' ('.$langs->trans("SuppliersOrdersRunning").')</td><td class="right">'.$totalinprocess.'</td></tr>';
184 print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$total.'</td></tr>';
185
186 print "</table></div><br>";
187} else {
188 dol_print_error($db);
189}
190
191/*
192 * Draft orders
193 */
194
195if (isModEnabled("supplier_order")) {
196 $sql = "SELECT c.rowid, c.ref, s.nom as name, s.rowid as socid";
197 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
198 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
199 if (!$user->hasRight("societe", "client", "voir") && !$socid) {
200 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
201 }
202 $sql .= " WHERE c.fk_soc = s.rowid";
203 $sql .= " AND c.entity IN (".getEntity("supplier_order").")"; // Thirdparty sharing is mandatory with supplier order sharing
204 $sql .= " AND c.fk_statut = 0";
205 if (!empty($socid)) {
206 $sql .= " AND c.fk_soc = ".((int) $socid);
207 }
208 if (!$user->hasRight("societe", "client", "voir") && !$socid) {
209 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
210 }
211
212 $resql = $db->query($sql);
213 if ($resql) {
214 print '<div class="div-table-responsive-no-min">';
215 print '<table class="noborder centpercent">';
216 print '<tr class="liste_titre">';
217 print '<th colspan="2">'.$langs->trans("DraftOrders").'</th></tr>';
218 $langs->load("orders");
219 $num = $db->num_rows($resql);
220 if ($num) {
221 $i = 0;
222 while ($i < $num) {
223 $obj = $db->fetch_object($resql);
224
225 print '<tr class="oddeven">';
226 print '<td class="nowrap">';
227 print "<a href=\"card.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowOrder"), "order").' '.$obj->ref."</a></td>";
228 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>';
229 $i++;
230 }
231 }
232 print "</table></div><br>";
233 }
234}
235
236
237/*
238 * List of users allowed
239 */
240
241$sql = "SELECT";
242if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
243 $sql .= " DISTINCT";
244}
245$sql .= " u.rowid, u.lastname, u.firstname, u.email, u.statut";
246$sql .= " FROM ".MAIN_DB_PREFIX."user as u";
247if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
248 $sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug";
249 $sql .= " WHERE ((ug.fk_user = u.rowid";
250 $sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
251 $sql .= " OR u.entity = 0)"; // Show always superadmin
252} else {
253 $sql .= " WHERE (u.entity IN (".getEntity('user')."))";
254}
255$sql .= " AND u.fk_soc IS NULL"; // An external user can not approved
256
257$resql = $db->query($sql);
258if ($resql) {
259 $num = $db->num_rows($resql);
260 $i = 0;
261
262 print '<div class="div-table-responsive-no-min">';
263 print '<table class="liste centpercent">';
264 print '<tr class="liste_titre"><th>'.$langs->trans("UserWithApproveOrderGrant").'</th>';
265 print "</tr>\n";
266
267 while ($i < $num) {
268 $obj = $db->fetch_object($resql);
269
270 $userstatic = new User($db);
271 $userstatic->id = $obj->rowid;
272 $userstatic->loadRights('fournisseur');
273
274 if ($userstatic->hasRight('fournisseur', 'commande', 'approuver')) {
275 print '<tr class="oddeven">';
276 print '<td>';
277 $userstatic->lastname = $obj->lastname;
278 $userstatic->firstname = $obj->firstname;
279 $userstatic->email = $obj->email;
280 $userstatic->status = $obj->statut;
281 print $userstatic->getNomUrl(1);
282 print '</td>';
283 print "</tr>\n";
284 }
285
286 $i++;
287 }
288 print "</table></div><br>";
289 $db->free($resql);
290} else {
291 dol_print_error($db);
292}
293
294
295print '</div><div class="fichetwothirdright">';
296
297
298/*
299 * Last modified orders
300*/
301
302$sql = "SELECT c.rowid, c.ref, c.fk_statut as status, c.tms, c.billed, 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";
305if (!$user->hasRight("societe", "client", "voir") && !$socid) {
306 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
307}
308$sql .= " WHERE c.fk_soc = s.rowid";
309$sql .= " AND c.entity IN (".getEntity('supplier_order').")";
310//$sql.= " AND c.fk_statut > 2";
311if (!empty($socid)) {
312 $sql .= " AND c.fk_soc = ".((int) $socid);
313}
314if (!$user->hasRight("societe", "client", "voir") && !$socid) {
315 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
316}
317$sql .= " ORDER BY c.tms DESC";
318$sql .= $db->plimit($max, 0);
319
320$resql = $db->query($sql);
321if ($resql) {
322 print '<div class="div-table-responsive-no-min">';
323 print '<table class="noborder centpercent">';
324 print '<tr class="liste_titre">';
325 print '<th colspan="4">'.$langs->trans("LastModifiedOrders", $max).' ';
326 print '<a href="'.DOL_URL_ROOT.'/fourn/commande/list.php?sortfield=cf.tms&sortorder=DESC">';
327 print '<span class="badge">...</span>';
328 print '</a>';
329 print '</th></tr>';
330
331 $num = $db->num_rows($resql);
332 if ($num) {
333 $i = 0;
334 while ($i < $num) {
335 $obj = $db->fetch_object($resql);
336
337 print '<tr class="oddeven">';
338 print '<td width="20%" class="nowrap">';
339
340 $commandestatic->id = $obj->rowid;
341 $commandestatic->ref = $obj->ref;
342
343 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
344 print '<td width="96" class="nobordernopadding nowrap">';
345 print $commandestatic->getNomUrl(1);
346 print '</td>';
347
348 print '<td width="16" class="nobordernopadding nowrap">';
349 print '&nbsp;';
350 print '</td>';
351
352 print '<td width="16" class="right nobordernopadding hideonsmartphone">';
353 $filename = dol_sanitizeFileName($obj->ref);
354 $filedir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
355 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
356 print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
357 print '</td></tr></table>';
358
359 print '</td>';
360
361 print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.'</a></td>';
362 print '<td>'.dol_print_date($db->jdate($obj->tms), 'day').'</td>';
363 print '<td class="right">'.$commandestatic->LibStatut($obj->status, 3, $obj->billed).'</td>';
364 print '</tr>';
365 $i++;
366 }
367 }
368 print "</table></div><br>";
369} else {
370 dol_print_error($db);
371}
372
373
374/*
375 * Orders to process
376 */
377/*
378 $sql = "SELECT c.rowid, c.ref, c.fk_statut, s.nom as name, s.rowid as socid";
379$sql.=" FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
380$sql.= ", ".MAIN_DB_PREFIX."societe as s";
381if (!$user->hasRight("societe", "client", "voir") && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
382$sql.= " WHERE c.fk_soc = s.rowid";
383$sql.= " AND c.entity IN (".getEntity("supplier_order").")";
384$sql.= " AND c.fk_statut = 1";
385if ($socid) $sql.= " AND c.fk_soc = ".((int) $socid);
386if (!$user->hasRight("societe", "client", "voir") && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .((int) $user->id);
387$sql.= " ORDER BY c.rowid DESC";
388
389$resql=$db->query($sql);
390if ($resql)
391{
392$num = $db->num_rows($resql);
393
394print '<div class="div-table-responsive-no-min">';
395print '<table class="noborder centpercent">';
396print '<tr class="liste_titre">';
397print '<th colspan="3">'.$langs->trans("OrdersToProcess").' <a href="'.DOL_URL_ROOT.'/commande/list.php?search_status=1">('.$num.')</a></th></tr>';
398
399if ($num)
400{
401$i = 0;
402while ($i < $num)
403{
404$obj = $db->fetch_object($resql);
405
406print '<tr class="oddeven">';
407print '<td class="nowrap">';
408
409$commandestatic->id=$obj->rowid;
410$commandestatic->ref=$obj->ref;
411
412print '<table class="nobordernopadding"><tr class="nocellnopadd">';
413print '<td width="96" class="nobordernopadding nowrap">';
414print $commandestatic->getNomUrl(1);
415print '</td>';
416
417print '<td width="16" class="nobordernopadding nowrap">';
418print '&nbsp;';
419print '</td>';
420
421print '<td width="16" class="right nobordernopadding hideonsmartphone">';
422$filename=dol_sanitizeFileName($obj->ref);
423$filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
424$urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
425print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
426print '</td></tr></table>';
427
428print '</td>';
429
430print '<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>';
431
432print '<td class="right">'.$commandestatic->LibStatut($obj->fk_statut,$obj->facture,5).'</td>';
433
434print '</tr>';
435$i++;
436}
437}
438
439print "</table></div><br>";
440}
441*/
442
443print '</div></div>';
444
445$parameters = array('user' => $user);
446$reshook = $hookmanager->executeHooks('dashboardOrdersSuppliers', $parameters, $object); // Note that $action and $object may have been modified by hook
447
448// End of page
449llxFooter();
450$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
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 Dolibarr users.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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_print_error($db=null, $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 '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.