dolibarr 24.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-2026 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';
32
41require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
42require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
43require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
44
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->isExternalUser()) {
57 $socid = $user->isExternalUser();
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 {
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 to approve
239 */
240
241$sql = "SELECT";
242if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
243 $sql .= " DISTINCT";
244}
245$sql .= " u.rowid, u.login, u.lastname, u.firstname, u.email, u.photo, 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 approve
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 print '<tr class="oddeven">';
268 print '<td>';
269
270 while ($i < $num) {
271 $obj = $db->fetch_object($resql);
272
273 $userstatic = new User($db);
274 $userstatic->id = $obj->rowid;
275 $userstatic->loadRights('fournisseur');
276
277 if ($userstatic->hasRight('fournisseur', 'commande', 'approuver')) {
278 if ($i > 0) {
279 print ', ';
280 }
281
282 $userstatic->lastname = $obj->lastname;
283 $userstatic->firstname = $obj->firstname;
284 $userstatic->email = $obj->email;
285 $userstatic->login = $obj->login;
286 $userstatic->photo = $obj->photo;
287 $userstatic->status = $obj->statut;
288
289 print $userstatic->getNomUrl(-1);
290 }
291
292 $i++;
293 }
294 if ($i == 0) {
295 print '<span class="opacitymedium">'.$langs->trans("Nobody").'</span>';
296 }
297
298 print '</td>';
299 print "</tr>\n";
300
301 print "</table></div><br>";
302 $db->free($resql);
303} else {
305}
306
307
308print '</div><div class="fichetwothirdright">';
309
310
311/*
312 * Last modified orders
313*/
314
315$sql = "SELECT c.rowid, c.ref, c.fk_statut as status, c.tms, c.billed, s.nom as name, s.rowid as socid";
316$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
317$sql .= ", ".MAIN_DB_PREFIX."societe as s";
318if (!$user->hasRight("societe", "client", "voir") && !$socid) {
319 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
320}
321$sql .= " WHERE c.fk_soc = s.rowid";
322$sql .= " AND c.entity IN (".getEntity('supplier_order').")";
323//$sql.= " AND c.fk_statut > 2";
324if (!empty($socid)) {
325 $sql .= " AND c.fk_soc = ".((int) $socid);
326}
327if (!$user->hasRight("societe", "client", "voir") && !$socid) {
328 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
329}
330$sql .= " ORDER BY c.tms DESC";
331$sql .= $db->plimit($max, 0);
332
333$resql = $db->query($sql);
334if ($resql) {
335 print '<div class="div-table-responsive-no-min">';
336 print '<table class="noborder centpercent">';
337 print '<tr class="liste_titre">';
338 print '<th colspan="4">'.$langs->trans("LastModifiedOrders", $max).' ';
339 print '<a href="'.DOL_URL_ROOT.'/fourn/commande/list.php?sortfield=cf.tms&sortorder=DESC">';
340 print '<span class="badge">...</span>';
341 print '</a>';
342 print '</th></tr>';
343
344 $num = $db->num_rows($resql);
345 if ($num) {
346 $i = 0;
347 while ($i < $num) {
348 $obj = $db->fetch_object($resql);
349
350 print '<tr class="oddeven">';
351 print '<td width="20%" class="nowrap">';
352
353 $commandestatic->id = $obj->rowid;
354 $commandestatic->ref = $obj->ref;
355
356 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
357 print '<td width="96" class="nobordernopadding nowrap">';
358 print $commandestatic->getNomUrl(1);
359 print '</td>';
360
361 print '<td width="16" class="nobordernopadding nowrap">';
362 print '&nbsp;';
363 print '</td>';
364
365 print '<td width="16" class="right nobordernopadding hideonsmartphone">';
366 $filename = dol_sanitizeFileName($obj->ref);
367 $filedir = getMultidirOutput($commandestatic).'/'.dol_sanitizeFileName($obj->ref);
368 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
369 print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
370 print '</td></tr></table>';
371
372 print '</td>';
373
374 print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.'</a></td>';
375 print '<td>'.dol_print_date($db->jdate($obj->tms), 'day').'</td>';
376 print '<td class="right">'.$commandestatic->LibStatut($obj->status, 3, $obj->billed).'</td>';
377 print '</tr>';
378 $i++;
379 }
380 }
381 print "</table></div><br>";
382} else {
384}
385
386
387/*
388 * Orders to process
389 */
390/*
391 $sql = "SELECT c.rowid, c.ref, c.fk_statut, s.nom as name, s.rowid as socid";
392$sql.=" FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
393$sql.= ", ".MAIN_DB_PREFIX."societe as s";
394if (!$user->hasRight("societe", "client", "voir") && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
395$sql.= " WHERE c.fk_soc = s.rowid";
396$sql.= " AND c.entity IN (".getEntity("supplier_order").")";
397$sql.= " AND c.fk_statut = 1";
398if ($socid) $sql.= " AND c.fk_soc = ".((int) $socid);
399if (!$user->hasRight("societe", "client", "voir") && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .((int) $user->id);
400$sql.= " ORDER BY c.rowid DESC";
401
402$resql=$db->query($sql);
403if ($resql)
404{
405$num = $db->num_rows($resql);
406
407print '<div class="div-table-responsive-no-min">';
408print '<table class="noborder centpercent">';
409print '<tr class="liste_titre">';
410print '<th colspan="3">'.$langs->trans("OrdersToProcess").' <a href="'.DOL_URL_ROOT.'/commande/list.php?search_status=1">('.$num.')</a></th></tr>';
411
412if ($num)
413{
414$i = 0;
415while ($i < $num)
416{
417$obj = $db->fetch_object($resql);
418
419print '<tr class="oddeven">';
420print '<td class="nowrap">';
421
422$commandestatic->id=$obj->rowid;
423$commandestatic->ref=$obj->ref;
424
425print '<table class="nobordernopadding"><tr class="nocellnopadd">';
426print '<td width="96" class="nobordernopadding nowrap">';
427print $commandestatic->getNomUrl(1);
428print '</td>';
429
430print '<td width="16" class="nobordernopadding nowrap">';
431print '&nbsp;';
432print '</td>';
433
434print '<td width="16" class="right nobordernopadding hideonsmartphone">';
435$filename=dol_sanitizeFileName($obj->ref);
436$filedir=getMultidirOutput($commandestatic) . '/' . dol_sanitizeFileName($obj->ref);
437$urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
438print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
439print '</td></tr></table>';
440
441print '</td>';
442
443print '<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>';
444
445print '<td class="right">'.$commandestatic->LibStatut($obj->fk_statut,$obj->facture,5).'</td>';
446
447print '</tr>';
448$i++;
449}
450}
451
452print "</table></div><br>";
453}
454*/
455
456print '</div></div>';
457
458$parameters = array('user' => $user);
459$reshook = $hookmanager->executeHooks('dashboardOrdersSuppliers', $parameters, $object); // Note that $action and $object may have been modified by hook
460
461// End of page
462llxFooter();
463$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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.
isModEnabled($module)
Is Dolibarr module enabled.
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.