dolibarr 18.0.6
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
6 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
7 * Copyright (C) 2020 Maxime DEMAREST <maxime@indelog.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
32require_once DOL_DOCUMENT_ROOT.'/commande/class/commandestats.class.php';
33require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formorder.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
36require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
37require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
38
41
42$mode = GETPOSTISSET("mode") ? GETPOST("mode", 'aZ09') : 'customer';
43if ($mode == 'customer' && !$user->rights->commande->lire) {
45}
46if ($mode == 'supplier' && empty($user->rights->fournisseur->commande->lire)) {
48}
49if ($mode == 'supplier') {
50 $object_status = GETPOST('object_status', 'array:int');
51 $object_status = implode(',', $object_status);
52} else {
53 $object_status = GETPOST('object_status', 'intcomma');
54}
55
56
57$typent_id = GETPOST('typent_id', 'int');
58$categ_id = GETPOST('categ_id', 'categ_id');
59
60$userid = GETPOST('userid', 'int');
61$socid = GETPOST('socid', 'int');
62// Security check
63if ($user->socid > 0) {
64 $action = '';
65 $socid = $user->socid;
66}
67
68$nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
69$year = GETPOST('year') > 0 ?GETPOST('year') : $nowyear;
70$startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
71$endyear = $year;
72
73// Load translation files required by the page
74$langs->loadLangs(array('orders', 'companies', 'other', 'suppliers'));
75
76
77/*
78 * View
79 */
80
81$form = new Form($db);
82$formorder = new FormOrder($db);
83$formcompany = new FormCompany($db);
84$formother = new FormOther($db);
85
86$picto = 'order';
87$title = $langs->trans("OrdersStatistics");
88$dir = $conf->commande->dir_temp;
89
90if ($mode == 'supplier') {
91 $picto = 'supplier_order';
92 $title = $langs->trans("OrdersStatisticsSuppliers");
93 $dir = $conf->fournisseur->commande->dir_temp;
94}
95
96llxHeader('', $title);
97
98print load_fiche_titre($title, '', $picto);
99
100dol_mkdir($dir);
101
102$stats = new CommandeStats($db, $socid, $mode, ($userid > 0 ? $userid : 0), ($typent_id > 0 ? $typent_id : 0), ($categ_id > 0 ? $categ_id : 0));
103if ($mode == 'customer') {
104 if ($object_status != '' && $object_status >= -1) {
105 $stats->where .= ' AND c.fk_statut IN ('.$db->sanitize($object_status).')';
106 }
107}
108if ($mode == 'supplier') {
109 if ($object_status != '' && $object_status >= 0) {
110 $stats->where .= ' AND c.fk_statut IN ('.$db->sanitize($object_status).')';
111 }
112}
113
114
115// Build graphic number of object
116$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
117
118//var_dump($data);
119// $data = array(array('Lib',val1,val2,val3),...)
120
121
122if (empty($user->rights->societe->client->voir) || $user->socid) {
123 $filenamenb = $dir.'/ordersnbinyear-'.$user->id.'-'.$year.'.png';
124 if ($mode == 'customer') {
125 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$user->id.'-'.$year.'.png';
126 }
127 if ($mode == 'supplier') {
128 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$user->id.'-'.$year.'.png';
129 }
130} else {
131 $filenamenb = $dir.'/ordersnbinyear-'.$year.'.png';
132 if ($mode == 'customer') {
133 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$year.'.png';
134 }
135 if ($mode == 'supplier') {
136 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$year.'.png';
137 }
138}
139
140$px1 = new DolGraph();
141$mesg = $px1->isGraphKo();
142if (!$mesg) {
143 $px1->SetData($data);
144 $i = $startyear; $legend = array();
145 while ($i <= $endyear) {
146 $legend[] = $i;
147 $i++;
148 }
149 $px1->SetLegend($legend);
150 $px1->SetMaxValue($px1->GetCeilMaxValue());
151 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
152 $px1->SetWidth($WIDTH);
153 $px1->SetHeight($HEIGHT);
154 $px1->SetYLabel($langs->trans("NbOfOrder"));
155 $px1->SetShading(3);
156 $px1->SetHorizTickIncrement(1);
157 $px1->mode = 'depth';
158 $px1->SetTitle($langs->trans("NumberOfOrdersByMonth"));
159
160 $px1->draw($filenamenb, $fileurlnb);
161}
162
163// Build graphic amount of object
164$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
165//var_dump($data);
166// $data = array(array('Lib',val1,val2,val3),...)
167
168if (empty($user->rights->societe->client->voir) || $user->socid) {
169 $filenameamount = $dir.'/ordersamountinyear-'.$user->id.'-'.$year.'.png';
170 if ($mode == 'customer') {
171 $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$user->id.'-'.$year.'.png';
172 }
173 if ($mode == 'supplier') {
174 $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$user->id.'-'.$year.'.png';
175 }
176} else {
177 $filenameamount = $dir.'/ordersamountinyear-'.$year.'.png';
178 if ($mode == 'customer') {
179 $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$year.'.png';
180 }
181 if ($mode == 'supplier') {
182 $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$year.'.png';
183 }
184}
185
186$px2 = new DolGraph();
187$mesg = $px2->isGraphKo();
188if (!$mesg) {
189 $px2->SetData($data);
190 $i = $startyear; $legend = array();
191 while ($i <= $endyear) {
192 $legend[] = $i;
193 $i++;
194 }
195 $px2->SetLegend($legend);
196 $px2->SetMaxValue($px2->GetCeilMaxValue());
197 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
198 $px2->SetWidth($WIDTH);
199 $px2->SetHeight($HEIGHT);
200 $px2->SetYLabel($langs->trans("AmountOfOrders"));
201 $px2->SetShading(3);
202 $px2->SetHorizTickIncrement(1);
203 $px2->mode = 'depth';
204 $px2->SetTitle($langs->trans("AmountOfOrdersByMonthHT"));
205
206 $px2->draw($filenameamount, $fileurlamount);
207}
208
209
210$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
211
212if (empty($user->rights->societe->client->voir) || $user->socid) {
213 $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
214 if ($mode == 'customer') {
215 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
216 }
217 if ($mode == 'supplier') {
218 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
219 }
220} else {
221 $filename_avg = $dir.'/ordersaverage-'.$year.'.png';
222 if ($mode == 'customer') {
223 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
224 }
225 if ($mode == 'supplier') {
226 $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
227 }
228}
229
230$px3 = new DolGraph();
231$mesg = $px3->isGraphKo();
232if (!$mesg) {
233 $px3->SetData($data);
234 $i = $startyear; $legend = array();
235 while ($i <= $endyear) {
236 $legend[] = $i;
237 $i++;
238 }
239 $px3->SetLegend($legend);
240 $px3->SetYLabel($langs->trans("AmountAverage"));
241 $px3->SetMaxValue($px3->GetCeilMaxValue());
242 $px3->SetMinValue($px3->GetFloorMinValue());
243 $px3->SetWidth($WIDTH);
244 $px3->SetHeight($HEIGHT);
245 $px3->SetShading(3);
246 $px3->SetHorizTickIncrement(1);
247 $px3->mode = 'depth';
248 $px3->SetTitle($langs->trans("AmountAverage"));
249
250 $px3->draw($filename_avg, $fileurl_avg);
251}
252
253
254
255// Show array
256$data = $stats->getAllByYear();
257$arrayyears = array();
258foreach ($data as $val) {
259 if (!empty($val['year'])) {
260 $arrayyears[$val['year']] = $val['year'];
261 }
262}
263if (!count($arrayyears)) {
264 $arrayyears[$nowyear] = $nowyear;
265}
266
267$h = 0;
268$head = array();
269$head[$h][0] = DOL_URL_ROOT.'/commande/stats/index.php?mode='.$mode;
270$head[$h][1] = $langs->trans("ByMonthYear");
271$head[$h][2] = 'byyear';
272$h++;
273
274if ($mode == 'customer') {
275 $type = 'order_stats';
276}
277if ($mode == 'supplier') {
278 $type = 'supplier_order_stats';
279}
280
281complete_head_from_modules($conf, $langs, null, $head, $h, $type);
282
283print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
284
285
286print '<div class="fichecenter"><div class="fichethirdleft">';
287
288
289// Show filter box
290print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
291print '<input type="hidden" name="token" value="'.newToken().'">';
292print '<input type="hidden" name="mode" value="'.$mode.'">';
293
294print '<table class="noborder centpercent">';
295print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
296// Company
297print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
298$filter = '';
299if ($mode == 'customer') {
300 $filter = '(s.client:IN:1,2,3)';
301}
302if ($mode == 'supplier') {
303 $filter = '(s.fournisseur:=:1)';
304}
305print img_picto('', 'company', 'class="pictofixedwidth"');
306print $form->select_company($socid, 'socid', $filter, 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300');
307print '</td></tr>';
308// ThirdParty Type
309print '<tr><td>'.$langs->trans("ThirdPartyType").'</td><td>';
310$sortparam_typent = (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT); // NONE means we keep sort of original array, so we sort on position. ASC, means next function will sort on label.
311print $form->selectarray("typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0, '', 0, 0, 0, $sortparam_typent, '', 1);
312if ($user->admin) {
313 print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
314}
315print '</td></tr>';
316// Category
317if ($mode == 'customer') {
318 $cat_type = Categorie::TYPE_CUSTOMER;
319 $cat_label = $langs->trans("Category").' '.lcfirst($langs->trans("Customer"));
320}
321if ($mode == 'supplier') {
322 $cat_type = Categorie::TYPE_SUPPLIER;
323 $cat_label = $langs->trans("Category").' '.lcfirst($langs->trans("Supplier"));
324}
325print '<tr><td>'.$cat_label.'</td><td>';
326print img_picto('', 'category', 'class="pictofixedwidth"');
327print $formother->select_categories($cat_type, $categ_id, 'categ_id', 0, 1, 'widthcentpercentminusx maxwidth300');
328print '</td></tr>';
329// User
330print '<tr><td>'.$langs->trans("CreatedBy").'</td><td>';
331print img_picto('', 'user', 'class="pictofixedwidth"');
332print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
333// Status
334print '<tr><td>'.$langs->trans("Status").'</td><td>';
335if ($mode == 'customer') {
336 $liststatus = array(
337 Commande::STATUS_DRAFT=>$langs->trans("StatusOrderDraft"),
338 Commande::STATUS_VALIDATED=>$langs->trans("StatusOrderValidated"),
339 Commande::STATUS_SHIPMENTONPROCESS=>$langs->trans("StatusOrderSent"),
340 Commande::STATUS_CLOSED=>$langs->trans("StatusOrderDelivered"),
341 Commande::STATUS_CANCELED=>$langs->trans("StatusOrderCanceled")
342 );
343 print $form->selectarray('object_status', $liststatus, GETPOST('object_status', 'intcomma'), -4);
344}
345if ($mode == 'supplier') {
346 $formorder->selectSupplierOrderStatus((strstr($object_status, ',') ? -1 : $object_status), 0, 'object_status');
347}
348print '</td></tr>';
349// Year
350print '<tr><td class="left">'.$langs->trans("Year").'</td><td class="left">';
351if (!in_array($year, $arrayyears)) {
352 $arrayyears[$year] = $year;
353}
354if (!in_array($nowyear, $arrayyears)) {
355 $arrayyears[$nowyear] = $nowyear;
356}
357arsort($arrayyears);
358print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
359print '</td></tr>';
360print '<tr><td align="center" colspan="2"><input type="submit" class="button small" name="submit" value="'.$langs->trans("Refresh").'"></td></tr>';
361print '</table>';
362print '</form>';
363print '<br><br>';
364
365
366print '<div class="div-table-responsive-no-min">';
367print '<table class="noborder centpercent">';
368print '<tr class="liste_titre" height="24">';
369print '<td class="center">'.$langs->trans("Year").'</td>';
370print '<td class="right">'.$langs->trans("NbOfOrders").'</td>';
371print '<td class="right">%</td>';
372print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
373print '<td class="right">%</td>';
374print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
375print '<td class="right">%</td>';
376print '</tr>';
377
378$oldyear = 0;
379foreach ($data as $val) {
380 $year = $val['year'];
381 while (!empty($year) && $oldyear > $year + 1) { // If we have empty year
382 $oldyear--;
383
384 print '<tr class="oddeven" height="24">';
385 print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&amp;mode='.$mode.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$oldyear.'</a></td>';
386 print '<td class="right">0</td>';
387 print '<td class="right"></td>';
388 print '<td class="right">0</td>';
389 print '<td class="right"></td>';
390 print '<td class="right">0</td>';
391 print '<td class="right"></td>';
392 print '</tr>';
393 }
394
395
396 print '<tr class="oddeven" height="24">';
397 print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&amp;mode='.$mode.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$year.'</a></td>';
398 print '<td class="right">'.$val['nb'].'</td>';
399 print '<td class="right opacitylow" style="'.((!isset($val['nb_diff']) || $val['nb_diff'] >= 0) ? 'color: green;' : 'color: red;').'">'.(isset($val['nb_diff']) ? round($val['nb_diff']): "0").'%</td>';
400 print '<td class="right">'.price(price2num($val['total'], 'MT'), 1).'</td>';
401 print '<td class="right opacitylow" style="'.((!isset($val['total_diff']) || $val['total_diff'] >= 0) ? 'color: green;' : 'color: red;').'">'.(isset($val['total_diff']) ? round($val['total_diff']) : "0").'%</td>';
402 print '<td class="right">'.price(price2num($val['avg'], 'MT'), 1).'</td>';
403 print '<td class="right opacitylow" style="'.((!isset($val['avg_diff']) || $val['avg_diff'] >= 0) ? 'color: green;' : 'color: red;').'">'.(isset($val['avg_diff']) ? round($val['avg_diff']) : "0").'%</td>';
404 print '</tr>';
405 $oldyear = $year;
406}
407
408print '</table>';
409print '</div>';
410
411
412print '</div><div class="fichetwothirdright">';
413
414
415// Show graphs
416print '<table class="border centpercent"><tr class="pair nohover"><td align="center">';
417if ($mesg) {
418 print $mesg;
419} else {
420 print $px1->show();
421 print "<br>\n";
422 print $px2->show();
423 print "<br>\n";
424 print $px3->show();
425}
426print '</td></tr></table>';
427
428
429print '</div></div>';
430print '<div class="clearboth"></div>';
431
432print dol_get_fiche_end();
433
434// End of page
435llxFooter();
436$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:56
llxFooter()
Empty footer.
Definition wrapper.php:70
const STATUS_SHIPMENTONPROCESS
Shipment on process.
const STATUS_CLOSED
Closed (Sent, billed or not)
const STATUS_CANCELED
Canceled status.
const STATUS_DRAFT
Draft status.
const STATUS_VALIDATED
Validated status.
Class to manage order statistics (customer and supplier)
Class to build graphs.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Class to manage HTML output components for orders Before adding component here, check they are not in...
Classe permettant la generation de composants html autre Only common components are here.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.