dolibarr 25.0.0-alpha
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-2026 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';
38require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
39require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
40require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
41require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
43
44
45// Load translation files required by the page
46$langs->loadLangs(array('orders', 'bills'));
47
48
49if (!$user->hasRight('commande', 'lire')) {
51}
52
53// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
54$hookmanager->initHooks(array('ordersindex'));
55
56
57// Security check
58$socid = GETPOSTINT('socid');
59if ($user->socid > 0) {
60 $action = '';
61 $socid = $user->socid;
62}
63
64// Maximum elements of the tables
65$max = getDolUserInt('MAIN_SIZE_SHORTLIST_LIMIT', getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5));
66
67$maxDraftCount = !getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
68$maxLatestEditCount = 5;
69$maxOpenCount = !getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
70
71
72/*
73 * View
74 */
75
76$commandestatic = new Commande($db);
77$companystatic = new Societe($db);
78$form = new Form($db);
79$formfile = new FormFile($db);
80$help_url = "EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes";
81
82llxHeader('', $langs->trans("Orders"), $help_url, '', 0, 0, '', '', '', 'mod-commande page-index');
83
84
85print load_fiche_titre($langs->trans("OrdersArea"), '', 'order');
86
87
88print '<div class="fichecenter"><div class="fichethirdleft">';
89
90$tmp = getCustomerOrderPieChart($socid);
91if ($tmp) {
92 print $tmp;
93 print '<br>';
94}
95
96
97/*
98 * Draft orders
99 */
100if (isModEnabled('order')) {
101 $sql = "SELECT c.rowid, c.ref, s.nom as name, s.rowid as socid";
102 $sql .= ", s.client";
103 $sql .= ", s.code_client";
104 $sql .= ", s.canvas";
105 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
106 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
107 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
108 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
109 }
110 $sql .= " WHERE c.fk_soc = s.rowid";
111 $sql .= " AND c.entity IN (".getEntity('commande').")";
112 $sql .= " AND c.fk_statut = 0";
113 if ($socid) {
114 $sql .= " AND c.fk_soc = ".((int) $socid);
115 }
116 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
117 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
118 }
119 // Add where from hooks
120 $parameters = array('socid' => $user->socid);
121 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $commandestatic); // Note that $action and $object may have been modified by hook
122 $sql .= $hookmanager->resPrint;
123 $resql = $db->query($sql);
124 if ($resql) {
125 print '<div class="div-table-responsive-no-min">';
126 print '<table class="noborder centpercent">';
127 print '<tr class="liste_titre">';
128 print '<th colspan="2">'.$langs->trans("DraftOrders").'</th></tr>';
129 $langs->load("orders");
130 $num = $db->num_rows($resql);
131 if ($num) {
132 $i = 0;
133 while ($i < $num) {
134 $obj = $db->fetch_object($resql);
135
136 $commandestatic->id = $obj->rowid;
137 $commandestatic->ref = $obj->ref;
138
139 $companystatic->id = $obj->socid;
140 $companystatic->name = $obj->name;
141 $companystatic->client = $obj->client;
142 $companystatic->code_client = $obj->code_client;
143 $companystatic->canvas = $obj->canvas;
144
145 print '<tr class="oddeven">';
146 print '<td class="nowrap">';
147 print $commandestatic->getNomUrl(1);
148 print "</td>";
149 print '<td class="nowrap">';
150 print $companystatic->getNomUrl(1, 'company', 16);
151 print '</td></tr>';
152 $i++;
153 }
154 } else {
155 print '<tr class="oddeven"><td colspan="3">'.$langs->trans("NoOrder").'</td></tr>';
156 }
157 print "</table></div><br>";
158 }
159}
160
161
162print '</div><div class="fichetwothirdright">';
163
164
165/*
166 * Latest modified orders
167 */
168
169$sql = "SELECT c.rowid, c.entity, c.ref, c.fk_statut as status, c.facture, c.date_cloture as datec, c.tms as datem,";
170$sql .= " s.nom as name, s.rowid as socid";
171$sql .= ", s.client";
172$sql .= ", s.code_client";
173$sql .= ", s.canvas";
174$sql .= " FROM ".MAIN_DB_PREFIX."commande as c,";
175$sql .= " ".MAIN_DB_PREFIX."societe as s";
176if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
177 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
178}
179$sql .= " WHERE c.fk_soc = s.rowid";
180$sql .= " AND c.entity IN (".getEntity('commande').")";
181//$sql.= " AND c.fk_statut > 2";
182if ($socid) {
183 $sql .= " AND c.fk_soc = ".((int) $socid);
184}
185if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
186 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
187}
188// Add where from hooks
189$parameters = array('socid' => $user->socid);
190$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $commandestatic); // Note that $action and $object may have been modified by hook
191$sql .= $hookmanager->resPrint;
192$sql .= " ORDER BY c.tms DESC";
193$sql .= $db->plimit($max, 0);
194
195$resql = $db->query($sql);
196if ($resql) {
197 $num = $db->num_rows($resql);
198
199 startSimpleTable($langs->trans("LastModifiedOrders", $max), "commande/list.php", "sortfield=c.tms&sortorder=DESC", 2, -1, 'order');
200
201 if ($num) {
202 $i = 0;
203 while ($i < $num) {
204 $obj = $db->fetch_object($resql);
205
206 print '<tr class="oddeven">';
207 print '<td width="20%" class="nowrap">';
208
209 $commandestatic->id = $obj->rowid;
210 $commandestatic->ref = $obj->ref;
211
212 $companystatic->id = $obj->socid;
213 $companystatic->name = $obj->name;
214 $companystatic->client = $obj->client;
215 $companystatic->code_client = $obj->code_client;
216 $companystatic->canvas = $obj->canvas;
217
218 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
219 print '<td width="96" class="nobordernopadding nowrap">';
220 print $commandestatic->getNomUrl(1);
221 print '</td>';
222
223 print '<td width="16" class="nobordernopadding nowrap">';
224 print '&nbsp;';
225 print '</td>';
226
227 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
228 $filename = dol_sanitizeFileName($obj->ref);
229 $filedir = $conf->commande->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
230 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
231 print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
232 print '</td></tr></table>';
233
234 print '</td>';
235
236 print '<td class="nowrap">';
237 print $companystatic->getNomUrl(1, 'company', 16);
238 print '</td>';
239
240 $datem = $db->jdate($obj->datem);
241 print '<td class="center" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
242 print dol_print_date($datem, 'day', 'tzuserrel');
243 print '</td>';
244
245 print '<td class="right">'.$commandestatic->LibStatut($obj->status, $obj->facture, 3).'</td>';
246 print '</tr>';
247 $i++;
248 }
249 }
250 finishSimpleTable(true);
251} else {
253}
254
255
256/*
257 * Orders to process
258 */
259if (isModEnabled('order')) {
260 $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";
261 $sql .= ", s.client";
262 $sql .= ", s.code_client";
263 $sql .= ", s.canvas";
264 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
265 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
266 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
267 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
268 }
269 $sql .= " WHERE c.fk_soc = s.rowid";
270 $sql .= " AND c.entity IN (".getEntity('commande').")";
271 $sql .= " AND c.fk_statut = ".Commande::STATUS_VALIDATED;
272 if ($socid) {
273 $sql .= " AND c.fk_soc = ".((int) $socid);
274 }
275 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
276 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
277 }
278 // Add where from hooks
279 $parameters = array('socid' => $user->socid);
280 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $commandestatic); // Note that $action and $object may have been modified by hook
281 $sql .= $hookmanager->resPrint;
282 $sql .= " ORDER BY c.rowid DESC";
283
284 $resql = $db->query($sql);
285 if ($resql) {
286 $num = $db->num_rows($resql);
287
288 print '<div class="div-table-responsive-no-min">';
289 print '<table class="noborder centpercent">';
290 print '<tr class="liste_titre">';
291 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>';
292
293 if ($num) {
294 $i = 0;
295 while ($i < $num && $i < $max) {
296 $obj = $db->fetch_object($resql);
297 print '<tr class="oddeven">';
298 print '<td class="nowrap" width="20%">';
299
300 $commandestatic->id = $obj->rowid;
301 $commandestatic->ref = $obj->ref;
302
303 $companystatic->id = $obj->socid;
304 $companystatic->name = $obj->name;
305 $companystatic->client = $obj->client;
306 $companystatic->code_client = $obj->code_client;
307 $companystatic->canvas = $obj->canvas;
308
309 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
310 print '<td width="96" class="nobordernopadding nowrap">';
311 print $commandestatic->getNomUrl(1);
312 print '</td>';
313
314 print '<td width="16" class="nobordernopadding nowrap">';
315 print '&nbsp;';
316 print '</td>';
317
318 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
319 $filename = dol_sanitizeFileName($obj->ref);
320 $filedir = $conf->commande->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
321 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
322 print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
323 print '</td></tr></table>';
324
325 print '</td>';
326
327 print '<td class="nowrap">';
328 print $companystatic->getNomUrl(1, 'company', 24);
329 print '</td>';
330
331 print '<td class="right">'.dol_print_date($db->jdate($obj->date), 'day').'</td>'."\n";
332
333 print '<td class="right">'.$commandestatic->LibStatut($obj->status, $obj->facture, 3).'</td>';
334
335 print '</tr>';
336 $i++;
337 }
338 if ($i < $num) {
339 print '<tr><td><span class="opacitymedium">'.$langs->trans("More").'...</span></td><td></td><td></td><td></td></tr>';
340 }
341 }
342
343 print "</table></div><br>";
344 } else {
346 }
347}
348
349/*
350 * Orders that are in process
351 */
352if (isModEnabled('order')) {
353 $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";
354 $sql .= ", s.client";
355 $sql .= ", s.code_client";
356 $sql .= ", s.canvas";
357 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
358 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
359 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
360 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
361 }
362 $sql .= " WHERE c.fk_soc = s.rowid";
363 $sql .= " AND c.entity IN (".getEntity('commande').")";
364 $sql .= " AND c.fk_statut = ".((int) Commande::STATUS_SHIPMENTONPROCESS);
365 if ($socid) {
366 $sql .= " AND c.fk_soc = ".((int) $socid);
367 }
368 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
369 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
370 }
371 // Add where from hooks
372 $parameters = array('socid' => $user->socid);
373 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $commandestatic); // Note that $action and $object may have been modified by hook
374 $sql .= $hookmanager->resPrint;
375 $sql .= " ORDER BY c.rowid DESC";
376
377 $resql = $db->query($sql);
378 if ($resql) {
379 $num = $db->num_rows($resql);
380
381 print '<div class="div-table-responsive-no-min">';
382 print '<table class="noborder centpercent">';
383 print '<tr class="liste_titre">';
384 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>';
385
386 if ($num) {
387 $i = 0;
388 while ($i < $num && $i < $max) {
389 $obj = $db->fetch_object($resql);
390 print '<tr class="oddeven">';
391 print '<td width="20%" class="nowrap">';
392
393 $commandestatic->id = $obj->rowid;
394 $commandestatic->ref = $obj->ref;
395
396 $companystatic->id = $obj->socid;
397 $companystatic->name = $obj->name;
398 $companystatic->client = $obj->client;
399 $companystatic->code_client = $obj->code_client;
400 $companystatic->canvas = $obj->canvas;
401
402 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
403 print '<td width="96" class="nobordernopadding nowrap">';
404 print $commandestatic->getNomUrl(1);
405 print '</td>';
406
407 print '<td width="16" class="nobordernopadding nowrap">';
408 print '&nbsp;';
409 print '</td>';
410
411 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
412 $filename = dol_sanitizeFileName($obj->ref);
413 $filedir = $conf->commande->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
414 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
415 print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
416 print '</td></tr></table>';
417
418 print '</td>';
419
420 print '<td>';
421 print $companystatic->getNomUrl(1, 'company');
422 print '</td>';
423
424 print '<td class="right">'.dol_print_date($db->jdate($obj->date), 'day').'</td>'."\n";
425
426 print '<td class="right">'.$commandestatic->LibStatut($obj->status, $obj->facture, 3).'</td>';
427
428 print '</tr>';
429 $i++;
430 }
431 if ($i < $num) {
432 print '<tr><td><span class="opacitymedium">'.$langs->trans("More").'...</span></td><td></td><td></td><td></td></tr>';
433 }
434 }
435 print "</table></div><br>";
436 } else {
438 }
439}
440
441
442print '</div></div>';
443
444$parameters = array('user' => $user);
445$reshook = $hookmanager->executeHooks('dashboardOrders', $parameters, $object); // Note that $action and $object may have been modified by hook
446
447// End of page
448llxFooter();
449$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 third parties objects (customers, suppliers, prospects...)
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.
finishSimpleTable($addLineBreak=false)
Add the correct HTML close tags for "startSimpleTable(...)" (use after the last table line)
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.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.