dolibarr 21.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-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 (!$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 (!$user->hasRight('societe', 'client', 'voir')) {
118 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
119 }
120
121 $resql = $db->query($sql);
122 if ($resql) {
123 print '<div class="div-table-responsive-no-min">';
124 print '<table class="noborder centpercent">';
125 print '<tr class="liste_titre">';
126 print '<th colspan="2">'.$langs->trans("DraftOrders").'</th></tr>';
127 $langs->load("orders");
128 $num = $db->num_rows($resql);
129 if ($num) {
130 $i = 0;
131 while ($i < $num) {
132 $obj = $db->fetch_object($resql);
133
134 $commandestatic->id = $obj->rowid;
135 $commandestatic->ref = $obj->ref;
136
137 $companystatic->id = $obj->socid;
138 $companystatic->name = $obj->name;
139 $companystatic->client = $obj->client;
140 $companystatic->code_client = $obj->code_client;
141 $companystatic->canvas = $obj->canvas;
142
143 print '<tr class="oddeven">';
144 print '<td class="nowrap">';
145 print $commandestatic->getNomUrl(1);
146 print "</td>";
147 print '<td class="nowrap">';
148 print $companystatic->getNomUrl(1, 'company', 16);
149 print '</td></tr>';
150 $i++;
151 }
152 } else {
153 print '<tr class="oddeven"><td colspan="3">'.$langs->trans("NoOrder").'</td></tr>';
154 }
155 print "</table></div><br>";
156 }
157}
158
159
160print '</div><div class="fichetwothirdright">';
161
162
163/*
164 * Latest modified orders
165 */
166
167$sql = "SELECT c.rowid, c.entity, c.ref, c.fk_statut as status, c.facture, c.date_cloture as datec, c.tms as datem,";
168$sql .= " s.nom as name, s.rowid as socid";
169$sql .= ", s.client";
170$sql .= ", s.code_client";
171$sql .= ", s.canvas";
172$sql .= " FROM ".MAIN_DB_PREFIX."commande as c,";
173$sql .= " ".MAIN_DB_PREFIX."societe as s";
174if (!$user->hasRight('societe', 'client', 'voir')) {
175 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
176}
177$sql .= " WHERE c.fk_soc = s.rowid";
178$sql .= " AND c.entity IN (".getEntity('commande').")";
179//$sql.= " AND c.fk_statut > 2";
180if ($socid) {
181 $sql .= " AND c.fk_soc = ".((int) $socid);
182}
183if (!$user->hasRight('societe', 'client', 'voir')) {
184 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
185}
186$sql .= " ORDER BY c.tms DESC";
187$sql .= $db->plimit($max, 0);
188
189$resql = $db->query($sql);
190if ($resql) {
191 $num = $db->num_rows($resql);
192
193 startSimpleTable($langs->trans("LastModifiedOrders", $max), "commande/list.php", "sortfield=c.tms&sortorder=DESC", 2, -1, 'order');
194
195 if ($num) {
196 $i = 0;
197 while ($i < $num) {
198 $obj = $db->fetch_object($resql);
199
200 print '<tr class="oddeven">';
201 print '<td width="20%" class="nowrap">';
202
203 $commandestatic->id = $obj->rowid;
204 $commandestatic->ref = $obj->ref;
205
206 $companystatic->id = $obj->socid;
207 $companystatic->name = $obj->name;
208 $companystatic->client = $obj->client;
209 $companystatic->code_client = $obj->code_client;
210 $companystatic->canvas = $obj->canvas;
211
212 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
213 print '<td width="96" class="nobordernopadding nowrap">';
214 print $commandestatic->getNomUrl(1);
215 print '</td>';
216
217 print '<td width="16" class="nobordernopadding nowrap">';
218 print '&nbsp;';
219 print '</td>';
220
221 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
222 $filename = dol_sanitizeFileName($obj->ref);
223 $filedir = $conf->commande->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
224 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
225 print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
226 print '</td></tr></table>';
227
228 print '</td>';
229
230 print '<td class="nowrap">';
231 print $companystatic->getNomUrl(1, 'company', 16);
232 print '</td>';
233
234 $datem = $db->jdate($obj->datem);
235 print '<td class="center" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
236 print dol_print_date($datem, 'day', 'tzuserrel');
237 print '</td>';
238
239 print '<td class="right">'.$commandestatic->LibStatut($obj->status, $obj->facture, 3).'</td>';
240 print '</tr>';
241 $i++;
242 }
243 }
244 finishSimpleTable(true);
245} else {
246 dol_print_error($db);
247}
248
249
250/*
251 * Orders to process
252 */
253if (isModEnabled('order')) {
254 $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";
255 $sql .= ", s.client";
256 $sql .= ", s.code_client";
257 $sql .= ", s.canvas";
258 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
259 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
260 if (!$user->hasRight('societe', 'client', 'voir')) {
261 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
262 }
263 $sql .= " WHERE c.fk_soc = s.rowid";
264 $sql .= " AND c.entity IN (".getEntity('commande').")";
265 $sql .= " AND c.fk_statut = ".Commande::STATUS_VALIDATED;
266 if ($socid) {
267 $sql .= " AND c.fk_soc = ".((int) $socid);
268 }
269 if (!$user->hasRight('societe', 'client', 'voir')) {
270 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
271 }
272 $sql .= " ORDER BY c.rowid DESC";
273
274 $resql = $db->query($sql);
275 if ($resql) {
276 $num = $db->num_rows($resql);
277
278 print '<div class="div-table-responsive-no-min">';
279 print '<table class="noborder centpercent">';
280 print '<tr class="liste_titre">';
281 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>';
282
283 if ($num) {
284 $i = 0;
285 while ($i < $num && $i < $max) {
286 $obj = $db->fetch_object($resql);
287 print '<tr class="oddeven">';
288 print '<td class="nowrap" width="20%">';
289
290 $commandestatic->id = $obj->rowid;
291 $commandestatic->ref = $obj->ref;
292
293 $companystatic->id = $obj->socid;
294 $companystatic->name = $obj->name;
295 $companystatic->client = $obj->client;
296 $companystatic->code_client = $obj->code_client;
297 $companystatic->canvas = $obj->canvas;
298
299 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
300 print '<td width="96" class="nobordernopadding nowrap">';
301 print $commandestatic->getNomUrl(1);
302 print '</td>';
303
304 print '<td width="16" class="nobordernopadding nowrap">';
305 print '&nbsp;';
306 print '</td>';
307
308 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
309 $filename = dol_sanitizeFileName($obj->ref);
310 $filedir = $conf->commande->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
311 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
312 print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
313 print '</td></tr></table>';
314
315 print '</td>';
316
317 print '<td class="nowrap">';
318 print $companystatic->getNomUrl(1, 'company', 24);
319 print '</td>';
320
321 print '<td class="right">'.dol_print_date($db->jdate($obj->date), 'day').'</td>'."\n";
322
323 print '<td class="right">'.$commandestatic->LibStatut($obj->status, $obj->facture, 3).'</td>';
324
325 print '</tr>';
326 $i++;
327 }
328 if ($i < $num) {
329 print '<tr><td><span class="opacitymedium">'.$langs->trans("More").'...</span></td><td></td><td></td><td></td></tr>';
330 }
331 }
332
333 print "</table></div><br>";
334 } else {
335 dol_print_error($db);
336 }
337}
338
339/*
340 * Orders that are in process
341 */
342if (isModEnabled('order')) {
343 $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";
344 $sql .= ", s.client";
345 $sql .= ", s.code_client";
346 $sql .= ", s.canvas";
347 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
348 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
349 if (!$user->hasRight('societe', 'client', 'voir')) {
350 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
351 }
352 $sql .= " WHERE c.fk_soc = s.rowid";
353 $sql .= " AND c.entity IN (".getEntity('commande').")";
354 $sql .= " AND c.fk_statut = ".((int) Commande::STATUS_SHIPMENTONPROCESS);
355 if ($socid) {
356 $sql .= " AND c.fk_soc = ".((int) $socid);
357 }
358 if (!$user->hasRight('societe', 'client', 'voir')) {
359 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
360 }
361 $sql .= " ORDER BY c.rowid DESC";
362
363 $resql = $db->query($sql);
364 if ($resql) {
365 $num = $db->num_rows($resql);
366
367 print '<div class="div-table-responsive-no-min">';
368 print '<table class="noborder centpercent">';
369 print '<tr class="liste_titre">';
370 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>';
371
372 if ($num) {
373 $i = 0;
374 while ($i < $num && $i < $max) {
375 $obj = $db->fetch_object($resql);
376 print '<tr class="oddeven">';
377 print '<td width="20%" class="nowrap">';
378
379 $commandestatic->id = $obj->rowid;
380 $commandestatic->ref = $obj->ref;
381
382 $companystatic->id = $obj->socid;
383 $companystatic->name = $obj->name;
384 $companystatic->client = $obj->client;
385 $companystatic->code_client = $obj->code_client;
386 $companystatic->canvas = $obj->canvas;
387
388 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
389 print '<td width="96" class="nobordernopadding nowrap">';
390 print $commandestatic->getNomUrl(1);
391 print '</td>';
392
393 print '<td width="16" class="nobordernopadding nowrap">';
394 print '&nbsp;';
395 print '</td>';
396
397 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
398 $filename = dol_sanitizeFileName($obj->ref);
399 $filedir = $conf->commande->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
400 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
401 print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
402 print '</td></tr></table>';
403
404 print '</td>';
405
406 print '<td>';
407 print $companystatic->getNomUrl(1, 'company');
408 print '</td>';
409
410 print '<td class="right">'.dol_print_date($db->jdate($obj->date), 'day').'</td>'."\n";
411
412 print '<td class="right">'.$commandestatic->LibStatut($obj->status, $obj->facture, 3).'</td>';
413
414 print '</tr>';
415 $i++;
416 }
417 if ($i < $num) {
418 print '<tr><td><span class="opacitymedium">'.$langs->trans("More").'...</span></td><td></td><td></td><td></td></tr>';
419 }
420 }
421 print "</table></div><br>";
422 } else {
423 dol_print_error($db);
424 }
425}
426
427
428print '</div></div>';
429
430$parameters = array('user' => $user);
431$reshook = $hookmanager->executeHooks('dashboardOrders', $parameters, $object); // Note that $action and $object may have been modified by hook
432
433// End of page
434llxFooter();
435$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 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...)
llxFooter()
Footer empty.
Definition document.php:107
finishSimpleTable($addLineBreak=false)
Add the correct HTML close tags for "startSimpleTable(...)" (use after the last table line)
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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()"...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.