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