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