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