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