dolibarr 25.0.0-alpha
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 * Copyright (C) 2026 Joachim Kueter <git-jk@bloxera.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
31// Load Dolibarr environment
32require '../../main.inc.php';
33
42require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
43require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
44require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
45require_once DOL_DOCUMENT_ROOT.'/core/lib/dashboard.lib.php';
46
47// Load translation files required by the page
48$langs->loadLangs(array("suppliers", "orders"));
49
50// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
51$hookmanager->initHooks(array('orderssuppliersindex'));
52
53$max = getDolUserInt('MAIN_SIZE_SHORTLIST_LIMIT', getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5));
54
55// Security check
56$orderid = GETPOST('orderid');
57$socid = GETPOSTINT('socid');
58if ($user->isExternalUser()) {
59 $socid = $user->isExternalUser();
60}
61$result = restrictedArea($user, 'fournisseur', $orderid, '', 'commande');
62
63
64/*
65 * View
66 */
67
68llxHeader('', $langs->trans("SuppliersOrdersArea"), '', '', 0, 0, '', '', '', 'mod-supplier-order page-stats');
69
70$commandestatic = new CommandeFournisseur($db);
71$userstatic = new User($db);
72$formfile = new FormFile($db);
73
74print load_fiche_titre($langs->trans("SuppliersOrdersArea"), '', 'supplier_order');
75
76print '<div class="fichecenter"><div class="fichethirdleft">';
77
78/*
79 * Statistics
80 */
81
82$sql = "SELECT count(cf.rowid) as nb, fk_statut as status";
83$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
84$sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf";
85if (!$user->hasRight("societe", "client", "voir") && !$socid) {
86 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
87}
88$sql .= " WHERE cf.fk_soc = s.rowid";
89$sql .= " AND cf.entity IN (".getEntity('supplier_order').")";
90if ($user->socid) {
91 $sql .= ' AND cf.fk_soc = '.((int) $user->socid);
92}
93if (!$user->hasRight("societe", "client", "voir") && !$socid) {
94 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
95}
96$sql .= " GROUP BY cf.fk_statut";
97
98$resql = $db->query($sql);
99if ($resql) {
100 $vals = array();
101 // 0=Draft -> 1=Validated -> 2=Approved -> 3=Process running -> 4=Received partially -> 5=Received totally -> (reopen) 4=Received partially
102 // -> 7=Canceled/Never received -> (reopen) 3=Process running
103 // -> 6=Canceled -> (reopen) 2=Approved
104 while ($obj = $db->fetch_object($resql)) {
105 $vals[($obj->status == CommandeFournisseur::STATUS_CANCELED_AFTER_ORDER ? CommandeFournisseur::STATUS_CANCELED : $obj->status)] = $obj->nb;
106 }
107 $db->free($resql);
108
109 $colors = getThemeBadgeStatusColors();
110 $colorofstatus = array(
111 CommandeFournisseur::STATUS_DRAFT => '-'.$colors[0],
120 );
121 $series = array();
122 foreach (array(0, 1, 2, 3, 4, 5, 6, 9) as $status) {
123 $series[] = array(
124 'label' => $commandestatic->LibStatut($status, 1),
125 'labelnojs' => $commandestatic->LibStatut($status, 0),
126 'nb' => (isset($vals[$status]) ? (int) $vals[$status] : 0),
127 'color' => $colorofstatus[$status],
128 'url' => 'list.php?search_status='.$status,
129 );
130 }
131 print getStatusPieChart($langs->trans("Statistics").' - '.$langs->trans("SuppliersOrders"), $series);
132} else {
133 dol_print_error($db);
134}
135
136/*
137 * Draft orders
138 */
139
140if (isModEnabled("supplier_order")) {
141 $sql = "SELECT c.rowid, c.ref, s.nom as name, s.rowid as socid";
142 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
143 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
144 if (!$user->hasRight("societe", "client", "voir") && !$socid) {
145 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
146 }
147 $sql .= " WHERE c.fk_soc = s.rowid";
148 $sql .= " AND c.entity IN (".getEntity("supplier_order").")"; // Thirdparty sharing is mandatory with supplier order sharing
149 $sql .= " AND c.fk_statut = 0";
150 if (!empty($socid)) {
151 $sql .= " AND c.fk_soc = ".((int) $socid);
152 }
153 if (!$user->hasRight("societe", "client", "voir") && !$socid) {
154 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
155 }
156
157 $resql = $db->query($sql);
158 if ($resql) {
159 print '<div class="div-table-responsive-no-min">';
160 print '<table class="noborder centpercent">';
161 print '<tr class="liste_titre">';
162 print '<th colspan="2">'.$langs->trans("DraftOrders").'</th></tr>';
163 $langs->load("orders");
164 $num = $db->num_rows($resql);
165 if ($num) {
166 $i = 0;
167 while ($i < $num) {
168 $obj = $db->fetch_object($resql);
169
170 print '<tr class="oddeven">';
171 print '<td class="nowrap">';
172 print "<a href=\"card.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowOrder"), "order").' '.$obj->ref."</a></td>";
173 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>';
174 $i++;
175 }
176 }
177 print "</table></div><br>";
178 }
179}
180
181
182/*
183 * List of users allowed to approve
184 */
185
186$sql = "SELECT";
187if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
188 $sql .= " DISTINCT";
189}
190$sql .= " u.rowid, u.login, u.lastname, u.firstname, u.email, u.photo, u.statut";
191$sql .= " FROM ".MAIN_DB_PREFIX."user as u";
192if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
193 $sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug";
194 $sql .= " WHERE ((ug.fk_user = u.rowid";
195 $sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
196 $sql .= " OR u.entity = 0)"; // Show always superadmin
197} else {
198 $sql .= " WHERE (u.entity IN (".getEntity('user')."))";
199}
200$sql .= " AND u.fk_soc IS NULL"; // An external user can not approve
201
202$resql = $db->query($sql);
203if ($resql) {
204 $num = $db->num_rows($resql);
205 $i = 0;
206
207 print '<div class="div-table-responsive-no-min">';
208 print '<table class="liste centpercent">';
209 print '<tr class="liste_titre"><th>'.$langs->trans("UserWithApproveOrderGrant").'</th>';
210 print "</tr>\n";
211
212 print '<tr class="oddeven">';
213 print '<td>';
214
215 while ($i < $num) {
216 $obj = $db->fetch_object($resql);
217
218 $userstatic = new User($db);
219 $userstatic->id = $obj->rowid;
220 $userstatic->loadRights('fournisseur');
221
222 if ($userstatic->hasRight('fournisseur', 'commande', 'approuver')) {
223 if ($i > 0) {
224 print ', ';
225 }
226
227 $userstatic->lastname = $obj->lastname;
228 $userstatic->firstname = $obj->firstname;
229 $userstatic->email = $obj->email;
230 $userstatic->login = $obj->login;
231 $userstatic->photo = $obj->photo;
232 $userstatic->status = $obj->statut;
233
234 print $userstatic->getNomUrl(-1);
235 }
236
237 $i++;
238 }
239 if ($i == 0) {
240 print '<span class="opacitymedium">'.$langs->trans("Nobody").'</span>';
241 }
242
243 print '</td>';
244 print "</tr>\n";
245
246 print "</table></div><br>";
247 $db->free($resql);
248} else {
249 dol_print_error($db);
250}
251
252
253print '</div><div class="fichetwothirdright">';
254
255
256/*
257 * Last modified orders
258*/
259
260$sql = "SELECT c.rowid, c.ref, c.fk_statut as status, c.tms, c.billed, s.nom as name, s.rowid as socid";
261$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
262$sql .= ", ".MAIN_DB_PREFIX."societe as s";
263if (!$user->hasRight("societe", "client", "voir") && !$socid) {
264 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
265}
266$sql .= " WHERE c.fk_soc = s.rowid";
267$sql .= " AND c.entity IN (".getEntity('supplier_order').")";
268//$sql.= " AND c.fk_statut > 2";
269if (!empty($socid)) {
270 $sql .= " AND c.fk_soc = ".((int) $socid);
271}
272if (!$user->hasRight("societe", "client", "voir") && !$socid) {
273 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
274}
275$sql .= " ORDER BY c.tms DESC";
276$sql .= $db->plimit($max, 0);
277
278$resql = $db->query($sql);
279if ($resql) {
280 print '<div class="div-table-responsive-no-min">';
281 print '<table class="noborder centpercent">';
282 print '<tr class="liste_titre">';
283 print '<th colspan="4">'.$langs->trans("LastModifiedSupplierOrders", $max).' ';
284 print '<a href="'.DOL_URL_ROOT.'/fourn/commande/list.php?sortfield=cf.tms&sortorder=DESC">';
285 print '<span class="badge">...</span>';
286 print '</a>';
287 print '</th></tr>';
288
289 $num = $db->num_rows($resql);
290 if ($num) {
291 $i = 0;
292 while ($i < $num) {
293 $obj = $db->fetch_object($resql);
294
295 print '<tr class="oddeven">';
296 print '<td width="20%" class="nowrap">';
297
298 $commandestatic->id = $obj->rowid;
299 $commandestatic->ref = $obj->ref;
300
301 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
302 print '<td width="96" class="nobordernopadding nowrap">';
303 print $commandestatic->getNomUrl(1);
304 print '</td>';
305
306 print '<td width="16" class="nobordernopadding nowrap">';
307 print '&nbsp;';
308 print '</td>';
309
310 print '<td width="16" class="right nobordernopadding hideonsmartphone">';
311 $filename = dol_sanitizeFileName($obj->ref);
312 $filedir = getMultidirOutput($commandestatic).'/'.dol_sanitizeFileName($obj->ref);
313 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
314 print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
315 print '</td></tr></table>';
316
317 print '</td>';
318
319 print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.'</a></td>';
320 print '<td>'.dol_print_date($db->jdate($obj->tms), 'day').'</td>';
321 print '<td class="right">'.$commandestatic->LibStatut($obj->status, 3, $obj->billed).'</td>';
322 print '</tr>';
323 $i++;
324 }
325 }
326 print "</table></div><br>";
327} else {
328 dol_print_error($db);
329}
330
331
332/*
333 * Orders to process
334 */
335/*
336 $sql = "SELECT c.rowid, c.ref, c.fk_statut, s.nom as name, s.rowid as socid";
337$sql.=" FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
338$sql.= ", ".MAIN_DB_PREFIX."societe as s";
339if (!$user->hasRight("societe", "client", "voir") && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
340$sql.= " WHERE c.fk_soc = s.rowid";
341$sql.= " AND c.entity IN (".getEntity("supplier_order").")";
342$sql.= " AND c.fk_statut = 1";
343if ($socid) $sql.= " AND c.fk_soc = ".((int) $socid);
344if (!$user->hasRight("societe", "client", "voir") && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .((int) $user->id);
345$sql.= " ORDER BY c.rowid DESC";
346
347$resql=$db->query($sql);
348if ($resql)
349{
350$num = $db->num_rows($resql);
351
352print '<div class="div-table-responsive-no-min">';
353print '<table class="noborder centpercent">';
354print '<tr class="liste_titre">';
355print '<th colspan="3">'.$langs->trans("OrdersToProcess").' <a href="'.DOL_URL_ROOT.'/commande/list.php?search_status=1">('.$num.')</a></th></tr>';
356
357if ($num)
358{
359$i = 0;
360while ($i < $num)
361{
362$obj = $db->fetch_object($resql);
363
364print '<tr class="oddeven">';
365print '<td class="nowrap">';
366
367$commandestatic->id=$obj->rowid;
368$commandestatic->ref=$obj->ref;
369
370print '<table class="nobordernopadding"><tr class="nocellnopadd">';
371print '<td width="96" class="nobordernopadding nowrap">';
372print $commandestatic->getNomUrl(1);
373print '</td>';
374
375print '<td width="16" class="nobordernopadding nowrap">';
376print '&nbsp;';
377print '</td>';
378
379print '<td width="16" class="right nobordernopadding hideonsmartphone">';
380$filename=dol_sanitizeFileName($obj->ref);
381$filedir=getMultidirOutput($commandestatic) . '/' . dol_sanitizeFileName($obj->ref);
382$urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
383print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
384print '</td></tr></table>';
385
386print '</td>';
387
388print '<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>';
389
390print '<td class="right">'.$commandestatic->LibStatut($obj->fk_statut,$obj->facture,5).'</td>';
391
392print '</tr>';
393$i++;
394}
395}
396
397print "</table></div><br>";
398}
399*/
400
401print '</div></div>';
402
403$parameters = array('user' => $user);
404$reshook = $hookmanager->executeHooks('dashboardOrdersSuppliers', $parameters, $object); // Note that $action and $object may have been modified by hook
405
406// End of page
407llxFooter();
408$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 offer components to list and upload files.
Class to manage Dolibarr users.
getThemeBadgeStatusColors()
Return the colors of status badges defined by the current theme (theme_vars.inc.php)
getStatusPieChart($title, $series, $options=array())
Return the HTML table with a pie chart of values by status, as shown on the home page of a module.
getDolUserInt($key, $default=0, $tmpuser=null)
Return Dolibarr user constant int value.
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.