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