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