dolibarr 23.0.3
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
6 * Copyright (C) 2019-2024 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
29// Load Dolibarr environment
30require '../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
33require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
34require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
36
45// Load translation files required by the page
46$langs->loadLangs(array('orders', 'bills'));
47
48
49if (!$user->hasRight('commande', 'lire')) {
51}
52
53$hookmanager = new HookManager($db);
54
55// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
56$hookmanager->initHooks(array('ordersindex'));
57
58
59// Security check
60$socid = GETPOSTINT('socid');
61if ($user->socid > 0) {
62 $action = '';
63 $socid = $user->socid;
64}
65
66// Maximum elements of the tables
67$max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
68$maxDraftCount = !getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
69$maxLatestEditCount = 5;
70$maxOpenCount = !getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
71
72
73/*
74 * View
75 */
76
77$commandestatic = new Commande($db);
78$companystatic = new Societe($db);
79$form = new Form($db);
80$formfile = new FormFile($db);
81$help_url = "EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes";
82
83llxHeader('', $langs->trans("Orders"), $help_url, '', 0, 0, '', '', '', 'mod-commande page-index');
84
85
86print load_fiche_titre($langs->trans("OrdersArea"), '', 'order');
87
88
89print '<div class="fichecenter"><div class="fichethirdleft">';
90
91$tmp = getCustomerOrderPieChart($socid);
92if ($tmp) {
93 print $tmp;
94 print '<br>';
95}
96
97
98/*
99 * Draft orders
100 */
101if (isModEnabled('order')) {
102 $sql = "SELECT c.rowid, c.ref, s.nom as name, s.rowid as socid";
103 $sql .= ", s.client";
104 $sql .= ", s.code_client";
105 $sql .= ", s.canvas";
106 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
107 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
108 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
109 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
110 }
111 $sql .= " WHERE c.fk_soc = s.rowid";
112 $sql .= " AND c.entity IN (".getEntity('commande').")";
113 $sql .= " AND c.fk_statut = 0";
114 if ($socid) {
115 $sql .= " AND c.fk_soc = ".((int) $socid);
116 }
117 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
118 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
119 }
120 // Add where from hooks
121 $parameters = array('socid' => $user->socid);
122 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $commandestatic); // Note that $action and $object may have been modified by hook
123 $sql .= $hookmanager->resPrint;
124 $resql = $db->query($sql);
125 if ($resql) {
126 print '<div class="div-table-responsive-no-min">';
127 print '<table class="noborder centpercent">';
128 print '<tr class="liste_titre">';
129 print '<th colspan="2">'.$langs->trans("DraftOrders").'</th></tr>';
130 $langs->load("orders");
131 $num = $db->num_rows($resql);
132 if ($num) {
133 $i = 0;
134 while ($i < $num) {
135 $obj = $db->fetch_object($resql);
136
137 $commandestatic->id = $obj->rowid;
138 $commandestatic->ref = $obj->ref;
139
140 $companystatic->id = $obj->socid;
141 $companystatic->name = $obj->name;
142 $companystatic->client = $obj->client;
143 $companystatic->code_client = $obj->code_client;
144 $companystatic->canvas = $obj->canvas;
145
146 print '<tr class="oddeven">';
147 print '<td class="nowrap">';
148 print $commandestatic->getNomUrl(1);
149 print "</td>";
150 print '<td class="nowrap">';
151 print $companystatic->getNomUrl(1, 'company', 16);
152 print '</td></tr>';
153 $i++;
154 }
155 } else {
156 print '<tr class="oddeven"><td colspan="3">'.$langs->trans("NoOrder").'</td></tr>';
157 }
158 print "</table></div><br>";
159 }
160}
161
162
163print '</div><div class="fichetwothirdright">';
164
165
166/*
167 * Latest modified orders
168 */
169
170$sql = "SELECT c.rowid, c.entity, c.ref, c.fk_statut as status, c.facture, c.date_cloture as datec, c.tms as datem,";
171$sql .= " s.nom as name, s.rowid as socid";
172$sql .= ", s.client";
173$sql .= ", s.code_client";
174$sql .= ", s.canvas";
175$sql .= " FROM ".MAIN_DB_PREFIX."commande as c,";
176$sql .= " ".MAIN_DB_PREFIX."societe as s";
177if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
178 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
179}
180$sql .= " WHERE c.fk_soc = s.rowid";
181$sql .= " AND c.entity IN (".getEntity('commande').")";
182//$sql.= " AND c.fk_statut > 2";
183if ($socid) {
184 $sql .= " AND c.fk_soc = ".((int) $socid);
185}
186if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
187 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
188}
189// Add where from hooks
190$parameters = array('socid' => $user->socid);
191$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $commandestatic); // Note that $action and $object may have been modified by hook
192$sql .= $hookmanager->resPrint;
193$sql .= " ORDER BY c.tms DESC";
194$sql .= $db->plimit($max, 0);
195
196$resql = $db->query($sql);
197if ($resql) {
198 $num = $db->num_rows($resql);
199
200 startSimpleTable($langs->trans("LastModifiedOrders", $max), "commande/list.php", "sortfield=c.tms&sortorder=DESC", 2, -1, 'order');
201
202 if ($num) {
203 $i = 0;
204 while ($i < $num) {
205 $obj = $db->fetch_object($resql);
206
207 print '<tr class="oddeven">';
208 print '<td width="20%" class="nowrap">';
209
210 $commandestatic->id = $obj->rowid;
211 $commandestatic->ref = $obj->ref;
212
213 $companystatic->id = $obj->socid;
214 $companystatic->name = $obj->name;
215 $companystatic->client = $obj->client;
216 $companystatic->code_client = $obj->code_client;
217 $companystatic->canvas = $obj->canvas;
218
219 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
220 print '<td width="96" class="nobordernopadding nowrap">';
221 print $commandestatic->getNomUrl(1);
222 print '</td>';
223
224 print '<td width="16" class="nobordernopadding nowrap">';
225 print '&nbsp;';
226 print '</td>';
227
228 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
229 $filename = dol_sanitizeFileName($obj->ref);
230 $filedir = $conf->commande->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
231 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
232 print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
233 print '</td></tr></table>';
234
235 print '</td>';
236
237 print '<td class="nowrap">';
238 print $companystatic->getNomUrl(1, 'company', 16);
239 print '</td>';
240
241 $datem = $db->jdate($obj->datem);
242 print '<td class="center" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
243 print dol_print_date($datem, 'day', 'tzuserrel');
244 print '</td>';
245
246 print '<td class="right">'.$commandestatic->LibStatut($obj->status, $obj->facture, 3).'</td>';
247 print '</tr>';
248 $i++;
249 }
250 }
251 finishSimpleTable(true);
252} else {
253 dol_print_error($db);
254}
255
256
257/*
258 * Orders to process
259 */
260if (isModEnabled('order')) {
261 $sql = "SELECT c.rowid, c.entity, c.ref, c.fk_statut as status, c.facture, c.date_commande as date, s.nom as name, s.rowid as socid";
262 $sql .= ", s.client";
263 $sql .= ", s.code_client";
264 $sql .= ", s.canvas";
265 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
266 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
267 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
268 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
269 }
270 $sql .= " WHERE c.fk_soc = s.rowid";
271 $sql .= " AND c.entity IN (".getEntity('commande').")";
272 $sql .= " AND c.fk_statut = ".Commande::STATUS_VALIDATED;
273 if ($socid) {
274 $sql .= " AND c.fk_soc = ".((int) $socid);
275 }
276 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
277 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
278 }
279 // Add where from hooks
280 $parameters = array('socid' => $user->socid);
281 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $commandestatic); // Note that $action and $object may have been modified by hook
282 $sql .= $hookmanager->resPrint;
283 $sql .= " ORDER BY c.rowid DESC";
284
285 $resql = $db->query($sql);
286 if ($resql) {
287 $num = $db->num_rows($resql);
288
289 print '<div class="div-table-responsive-no-min">';
290 print '<table class="noborder centpercent">';
291 print '<tr class="liste_titre">';
292 print '<th colspan="4">'.$langs->trans("OrdersToProcess").' <a href="'.DOL_URL_ROOT.'/commande/list.php?search_status='.Commande::STATUS_VALIDATED.'"><span class="badge">'.$num.'</span></a></th></tr>';
293
294 if ($num) {
295 $i = 0;
296 while ($i < $num && $i < $max) {
297 $obj = $db->fetch_object($resql);
298 print '<tr class="oddeven">';
299 print '<td class="nowrap" width="20%">';
300
301 $commandestatic->id = $obj->rowid;
302 $commandestatic->ref = $obj->ref;
303
304 $companystatic->id = $obj->socid;
305 $companystatic->name = $obj->name;
306 $companystatic->client = $obj->client;
307 $companystatic->code_client = $obj->code_client;
308 $companystatic->canvas = $obj->canvas;
309
310 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
311 print '<td width="96" class="nobordernopadding nowrap">';
312 print $commandestatic->getNomUrl(1);
313 print '</td>';
314
315 print '<td width="16" class="nobordernopadding nowrap">';
316 print '&nbsp;';
317 print '</td>';
318
319 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
320 $filename = dol_sanitizeFileName($obj->ref);
321 $filedir = $conf->commande->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
322 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
323 print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
324 print '</td></tr></table>';
325
326 print '</td>';
327
328 print '<td class="nowrap">';
329 print $companystatic->getNomUrl(1, 'company', 24);
330 print '</td>';
331
332 print '<td class="right">'.dol_print_date($db->jdate($obj->date), 'day').'</td>'."\n";
333
334 print '<td class="right">'.$commandestatic->LibStatut($obj->status, $obj->facture, 3).'</td>';
335
336 print '</tr>';
337 $i++;
338 }
339 if ($i < $num) {
340 print '<tr><td><span class="opacitymedium">'.$langs->trans("More").'...</span></td><td></td><td></td><td></td></tr>';
341 }
342 }
343
344 print "</table></div><br>";
345 } else {
346 dol_print_error($db);
347 }
348}
349
350/*
351 * Orders that are in process
352 */
353if (isModEnabled('order')) {
354 $sql = "SELECT c.rowid, c.entity, c.ref, c.fk_statut as status, c.facture, c.date_commande as date, s.nom as name, s.rowid as socid";
355 $sql .= ", s.client";
356 $sql .= ", s.code_client";
357 $sql .= ", s.canvas";
358 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
359 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
360 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
361 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
362 }
363 $sql .= " WHERE c.fk_soc = s.rowid";
364 $sql .= " AND c.entity IN (".getEntity('commande').")";
365 $sql .= " AND c.fk_statut = ".((int) Commande::STATUS_SHIPMENTONPROCESS);
366 if ($socid) {
367 $sql .= " AND c.fk_soc = ".((int) $socid);
368 }
369 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
370 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
371 }
372 // Add where from hooks
373 $parameters = array('socid' => $user->socid);
374 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $commandestatic); // Note that $action and $object may have been modified by hook
375 $sql .= $hookmanager->resPrint;
376 $sql .= " ORDER BY c.rowid DESC";
377
378 $resql = $db->query($sql);
379 if ($resql) {
380 $num = $db->num_rows($resql);
381
382 print '<div class="div-table-responsive-no-min">';
383 print '<table class="noborder centpercent">';
384 print '<tr class="liste_titre">';
385 print '<th colspan="4">'.$langs->trans("OnProcessOrders").' <a href="'.DOL_URL_ROOT.'/commande/list.php?search_status='.Commande::STATUS_SHIPMENTONPROCESS.'"><span class="badge">'.$num.'</span></a></th></tr>';
386
387 if ($num) {
388 $i = 0;
389 while ($i < $num && $i < $max) {
390 $obj = $db->fetch_object($resql);
391 print '<tr class="oddeven">';
392 print '<td width="20%" class="nowrap">';
393
394 $commandestatic->id = $obj->rowid;
395 $commandestatic->ref = $obj->ref;
396
397 $companystatic->id = $obj->socid;
398 $companystatic->name = $obj->name;
399 $companystatic->client = $obj->client;
400 $companystatic->code_client = $obj->code_client;
401 $companystatic->canvas = $obj->canvas;
402
403 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
404 print '<td width="96" class="nobordernopadding nowrap">';
405 print $commandestatic->getNomUrl(1);
406 print '</td>';
407
408 print '<td width="16" class="nobordernopadding nowrap">';
409 print '&nbsp;';
410 print '</td>';
411
412 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
413 $filename = dol_sanitizeFileName($obj->ref);
414 $filedir = $conf->commande->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
415 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
416 print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
417 print '</td></tr></table>';
418
419 print '</td>';
420
421 print '<td>';
422 print $companystatic->getNomUrl(1, 'company');
423 print '</td>';
424
425 print '<td class="right">'.dol_print_date($db->jdate($obj->date), 'day').'</td>'."\n";
426
427 print '<td class="right">'.$commandestatic->LibStatut($obj->status, $obj->facture, 3).'</td>';
428
429 print '</tr>';
430 $i++;
431 }
432 if ($i < $num) {
433 print '<tr><td><span class="opacitymedium">'.$langs->trans("More").'...</span></td><td></td><td></td><td></td></tr>';
434 }
435 }
436 print "</table></div><br>";
437 } else {
438 dol_print_error($db);
439 }
440}
441
442
443print '</div></div>';
444
445$parameters = array('user' => $user);
446$reshook = $hookmanager->executeHooks('dashboardOrders', $parameters, $object); // Note that $action and $object may have been modified by hook
447
448// End of page
449llxFooter();
450$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 customers orders.
const STATUS_SHIPMENTONPROCESS
Shipment on process.
const STATUS_VALIDATED
Validated status.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage hooks.
Class to manage third parties objects (customers, suppliers, prospects...)
finishSimpleTable($addLineBreak=false)
Add the correct HTML close tags for "startSimpleTable(...)" (use after the last table line)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
startSimpleTable($header, $link="", $arguments="", $emptyColumns=0, $number=-1, $pictofulllist='')
Start a table with headers and a optional clickable number (don't forget to use "finishSimpleTable()"...
getCustomerOrderPieChart($socid=0)
Return a HTML table that contains a pie chart of sales orders.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.