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';
42$mode = GETPOSTISSET(
"mode") ?
GETPOST(
"mode",
'aZ09') :
'customer';
44$usercanreadcustumerstatistic = $user->hasRight(
'commande',
'lire');
45$usercanreadsupplierstatistic = $user->hasRight(
'fournisseur',
'commande',
'lire');
47 $usercanreadcustumerstatistic = $user->hasRight(
'commande',
'commande',
'export');
48 $usercanreadsupplierstatistic = $user->hasRight(
'fournisseur',
'commande',
'export');
50if ($mode ==
'customer' && !$usercanreadcustumerstatistic) {
53if ($mode ==
'supplier' && !$usercanreadsupplierstatistic) {
57if ($mode ==
'supplier') {
58 $object_status =
GETPOST(
'object_status',
'array:int');
59 $object_status = implode(
',', $object_status);
61 $object_status =
GETPOST(
'object_status',
'intcomma');
65$typent_id =
GETPOST(
'typent_id',
'int');
66$categ_id =
GETPOST(
'categ_id',
'categ_id');
68$userid =
GETPOST(
'userid',
'int');
69$socid =
GETPOST(
'socid',
'int');
71if ($user->socid > 0) {
73 $socid = $user->socid;
82$langs->loadLangs(array(
'orders',
'companies',
'other',
'suppliers'));
95$title = $langs->trans(
"OrdersStatistics");
96$dir = $conf->commande->dir_temp;
98if ($mode ==
'supplier') {
99 $picto =
'supplier_order';
100 $title = $langs->trans(
"OrdersStatisticsSuppliers");
101 $dir = $conf->fournisseur->commande->dir_temp;
110$stats =
new CommandeStats($db, $socid, $mode, ($userid > 0 ? $userid : 0), ($typent_id > 0 ? $typent_id : 0), ($categ_id > 0 ? $categ_id : 0));
111if ($mode ==
'customer') {
112 if ($object_status !=
'' && $object_status >= -1) {
113 $stats->where .=
' AND c.fk_statut IN ('.$db->sanitize($object_status).
')';
116if ($mode ==
'supplier') {
117 if ($object_status !=
'' && $object_status >= 0) {
118 $stats->where .=
' AND c.fk_statut IN ('.$db->sanitize($object_status).
')';
124$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
130if (!$user->hasRight(
'societe',
'client',
'voir') || $user->socid) {
131 $filenamenb = $dir.
'/ordersnbinyear-'.$user->id.
'-'.$year.
'.png';
132 if ($mode ==
'customer') {
133 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$user->id.
'-'.$year.
'.png';
135 if ($mode ==
'supplier') {
136 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$user->id.
'-'.$year.
'.png';
139 $filenamenb = $dir.
'/ordersnbinyear-'.$year.
'.png';
140 if ($mode ==
'customer') {
141 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$year.
'.png';
143 if ($mode ==
'supplier') {
144 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$year.
'.png';
149$mesg = $px1->isGraphKo();
151 $px1->SetData($data);
154 while ($i <= $endyear) {
158 $px1->SetLegend($legend);
159 $px1->SetMaxValue($px1->GetCeilMaxValue());
160 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
161 $px1->SetWidth($WIDTH);
162 $px1->SetHeight($HEIGHT);
163 $px1->SetYLabel($langs->trans(
"NbOfOrder"));
165 $px1->SetHorizTickIncrement(1);
166 $px1->mode =
'depth';
167 $px1->SetTitle($langs->trans(
"NumberOfOrdersByMonth"));
169 $px1->draw($filenamenb, $fileurlnb);
173$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
177if (!$user->hasRight(
'societe',
'client',
'voir') || $user->socid) {
178 $filenameamount = $dir.
'/ordersamountinyear-'.$user->id.
'-'.$year.
'.png';
179 if ($mode ==
'customer') {
180 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$user->id.
'-'.$year.
'.png';
182 if ($mode ==
'supplier') {
183 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$user->id.
'-'.$year.
'.png';
186 $filenameamount = $dir.
'/ordersamountinyear-'.$year.
'.png';
187 if ($mode ==
'customer') {
188 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$year.
'.png';
190 if ($mode ==
'supplier') {
191 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$year.
'.png';
196$mesg = $px2->isGraphKo();
198 $px2->SetData($data);
201 while ($i <= $endyear) {
205 $px2->SetLegend($legend);
206 $px2->SetMaxValue($px2->GetCeilMaxValue());
207 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
208 $px2->SetWidth($WIDTH);
209 $px2->SetHeight($HEIGHT);
210 $px2->SetYLabel($langs->trans(
"AmountOfOrders"));
212 $px2->SetHorizTickIncrement(1);
213 $px2->mode =
'depth';
214 $px2->SetTitle($langs->trans(
"AmountOfOrdersByMonthHT"));
216 $px2->draw($filenameamount, $fileurlamount);
220$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
222if (!$user->hasRight(
'societe',
'client',
'voir') || $user->socid) {
223 $filename_avg = $dir.
'/ordersaverage-'.$user->id.
'-'.$year.
'.png';
224 if ($mode ==
'customer') {
225 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
227 if ($mode ==
'supplier') {
228 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
231 $filename_avg = $dir.
'/ordersaverage-'.$year.
'.png';
232 if ($mode ==
'customer') {
233 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.
'.png';
235 if ($mode ==
'supplier') {
236 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.
'.png';
241$mesg = $px3->isGraphKo();
243 $px3->SetData($data);
246 while ($i <= $endyear) {
250 $px3->SetLegend($legend);
251 $px3->SetYLabel($langs->trans(
"AmountAverage"));
252 $px3->SetMaxValue($px3->GetCeilMaxValue());
253 $px3->SetMinValue($px3->GetFloorMinValue());
254 $px3->SetWidth($WIDTH);
255 $px3->SetHeight($HEIGHT);
257 $px3->SetHorizTickIncrement(1);
258 $px3->mode =
'depth';
259 $px3->SetTitle($langs->trans(
"AmountAverage"));
261 $px3->draw($filename_avg, $fileurl_avg);
267$data = $stats->getAllByYear();
268$arrayyears = array();
269foreach ($data as $val) {
270 if (!empty($val[
'year'])) {
271 $arrayyears[$val[
'year']] = $val[
'year'];
274if (!count($arrayyears)) {
275 $arrayyears[$nowyear] = $nowyear;
280$head[$h][0] = DOL_URL_ROOT.
'/commande/stats/index.php?mode='.$mode;
281$head[$h][1] = $langs->trans(
"ByMonthYear");
282$head[$h][2] =
'byyear';
285if ($mode ==
'customer') {
286 $type =
'order_stats';
288if ($mode ==
'supplier') {
289 $type =
'supplier_order_stats';
297print
'<div class="fichecenter"><div class="fichethirdleft">';
301print
'<form name="stats" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
302print
'<input type="hidden" name="token" value="'.newToken().
'">';
303print
'<input type="hidden" name="mode" value="'.$mode.
'">';
305print
'<table class="noborder centpercent">';
306print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
308print
'<tr><td class="left">'.$langs->trans(
"ThirdParty").
'</td><td class="left">';
310if ($mode ==
'customer') {
311 $filter =
'(s.client:IN:1,2,3)';
313if ($mode ==
'supplier') {
314 $filter =
'(s.fournisseur:=:1)';
316print
img_picto(
'',
'company',
'class="pictofixedwidth"');
317print $form->select_company($socid,
'socid', $filter, 1, 0, 0, array(), 0,
'widthcentpercentminusx maxwidth300');
320print
'<tr><td>'.$langs->trans(
"ThirdPartyType").
'</td><td>';
321$sortparam_typent = (!
getDolGlobalString(
'SOCIETE_SORT_ON_TYPEENT') ?
'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT);
322print $form->selectarray(
"typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0,
'', 0, 0, 0, $sortparam_typent,
'', 1);
324 print
' '.info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
328if ($mode ==
'customer') {
329 $cat_type = Categorie::TYPE_CUSTOMER;
330 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Customer"));
332if ($mode ==
'supplier') {
333 $cat_type = Categorie::TYPE_SUPPLIER;
334 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Supplier"));
336print
'<tr><td>'.$cat_label.
'</td><td>';
337print
img_picto(
'',
'category',
'class="pictofixedwidth"');
338print $formother->select_categories($cat_type, $categ_id,
'categ_id', 0, 1,
'widthcentpercentminusx maxwidth300');
341print
'<tr><td>'.$langs->trans(
"CreatedBy").
'</td><td>';
342print
img_picto(
'',
'user',
'class="pictofixedwidth"');
343print $form->select_dolusers($userid,
'userid', 1,
'', 0,
'',
'', 0, 0, 0,
'', 0,
'',
'widthcentpercentminusx maxwidth300');
345print
'<tr><td>'.$langs->trans(
"Status").
'</td><td>';
346if ($mode ==
'customer') {
354 print $form->selectarray(
'object_status', $liststatus,
GETPOST(
'object_status',
'intcomma'), -4);
356if ($mode ==
'supplier') {
357 $formorder->selectSupplierOrderStatus((strstr($object_status,
',') ? -1 : $object_status), 0,
'object_status');
361print
'<tr><td class="left">'.$langs->trans(
"Year").
'</td><td class="left">';
362if (!in_array($year, $arrayyears)) {
363 $arrayyears[$year] = $year;
365if (!in_array($nowyear, $arrayyears)) {
366 $arrayyears[$nowyear] = $nowyear;
369print $form->selectarray(
'year', $arrayyears, $year, 0, 0, 0,
'', 0, 0, 0,
'',
'width75');
371print
'<tr><td align="center" colspan="2"><input type="submit" class="button small" name="submit" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
377print
'<div class="div-table-responsive-no-min">';
378print
'<table class="noborder centpercent">';
379print
'<tr class="liste_titre" height="24">';
380print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
381print
'<td class="right">'.$langs->trans(
"NbOfOrders").
'</td>';
382print
'<td class="right">%</td>';
383print
'<td class="right">'.$langs->trans(
"AmountTotal").
'</td>';
384print
'<td class="right">%</td>';
385print
'<td class="right">'.$langs->trans(
"AmountAverage").
'</td>';
386print
'<td class="right">%</td>';
390foreach ($data as $val) {
391 $year = $val[
'year'];
392 while (!empty($year) && $oldyear > $year + 1) {
395 print
'<tr class="oddeven" height="24">';
396 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$oldyear.
'</a></td>';
397 print
'<td class="right">0</td>';
398 print
'<td class="right"></td>';
399 print
'<td class="right">0</td>';
400 print
'<td class="right"></td>';
401 print
'<td class="right">0</td>';
402 print
'<td class="right"></td>';
407 print
'<tr class="oddeven" height="24">';
408 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$year.
'</a></td>';
409 print
'<td class="right">'.$val[
'nb'].
'</td>';
410 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>';
411 print
'<td class="right">'.price(
price2num($val[
'total'],
'MT'), 1).
'</td>';
412 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>';
413 print
'<td class="right">'.price(
price2num($val[
'avg'],
'MT'), 1).
'</td>';
414 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>';
423print
'</div><div class="fichetwothirdright">';
427print
'<table class="border centpercent"><tr class="pair nohover"><td align="center">';
437print
'</td></tr></table>';
441print
'<div class="clearboth"></div>';
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
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)
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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).
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.