32require
'../../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/commande/class/commandestats.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formorder.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
52$mode = GETPOSTISSET(
"mode") ?
GETPOST(
"mode",
'aZ09') :
'customer';
54$hookmanager->initHooks(array(
'orderstats',
'globalcard'));
56$usercanreadcustumerstatistic = $user->hasRight(
'commande',
'lire');
57$usercanreadsupplierstatistic = $user->hasRight(
'fournisseur',
'commande',
'lire');
59 $usercanreadcustumerstatistic = $user->hasRight(
'commande',
'commande',
'export');
60 $usercanreadsupplierstatistic = $user->hasRight(
'fournisseur',
'commande',
'export');
62if ($mode ==
'customer' && !$usercanreadcustumerstatistic) {
65if ($mode ==
'supplier' && !$usercanreadsupplierstatistic) {
69if ($mode ==
'supplier') {
70 $object_status =
GETPOST(
'object_status',
'array:int');
71 $object_status = implode(
',', $object_status);
73 $object_status =
GETPOST(
'object_status',
'intcomma');
83if ($user->socid > 0) {
85 $socid = $user->socid;
89$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
100$langs->loadLangs(array(
'orders',
'companies',
'other',
'suppliers'));
107$form =
new Form($db);
113$title = $langs->trans(
"OrdersStatistics");
114$dir =
$conf->commande->dir_temp;
116if ($mode ==
'supplier') {
117 $picto =
'supplier_order';
118 $title = $langs->trans(
"OrdersStatisticsSuppliers");
119 $dir =
$conf->fournisseur->commande->dir_temp;
122llxHeader(
'', $title,
'',
'', 0, 0,
'',
'',
'',
'mod-order page-stats');
128$stats =
new CommandeStats($db, $socid, $mode, ($userid > 0 ? $userid : 0), ($typent_id > 0 ? $typent_id : 0), ($categ_id > 0 ? $categ_id : 0));
129if ($mode ==
'customer') {
130 if ($object_status !=
'' && $object_status >= -1) {
131 $stats->where .=
' AND c.fk_statut IN ('.$db->sanitize($object_status).
')';
134if ($mode ==
'supplier') {
135 if ($object_status !=
'' && $object_status >= 0) {
136 $stats->where .=
' AND c.fk_statut IN ('.$db->sanitize($object_status).
')';
142$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
149if (!$user->hasRight(
'societe',
'client',
'voir')) {
150 $filenamenb = $dir.
'/ordersnbinyear-'.$user->id.
'-'.$year.
'.png';
151 if ($mode ==
'customer') {
152 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$user->id.
'-'.$year.
'.png';
154 if ($mode ==
'supplier') {
155 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$user->id.
'-'.$year.
'.png';
158 $filenamenb = $dir.
'/ordersnbinyear-'.$year.
'.png';
159 if ($mode ==
'customer') {
160 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$year.
'.png';
162 if ($mode ==
'supplier') {
163 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$year.
'.png';
168$mesg = $px1->isGraphKo();
170 $px1->SetData($data);
173 while ($i <= $endyear) {
177 $px1->SetLegend($legend);
178 $px1->SetMaxValue($px1->GetCeilMaxValue());
179 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
180 $px1->SetWidth($WIDTH);
181 $px1->SetHeight($HEIGHT);
182 $px1->SetYLabel($langs->trans(
"NbOfOrder"));
184 $px1->SetHorizTickIncrement(1);
185 $px1->mode =
'depth';
186 $px1->SetTitle($langs->trans(
"NumberOfOrdersByMonth"));
188 $px1->draw($filenamenb, $fileurlnb);
192$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
197if (!$user->hasRight(
'societe',
'client',
'voir')) {
198 $filenameamount = $dir.
'/ordersamountinyear-'.$user->id.
'-'.$year.
'.png';
199 if ($mode ==
'customer') {
200 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$user->id.
'-'.$year.
'.png';
202 if ($mode ==
'supplier') {
203 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$user->id.
'-'.$year.
'.png';
206 $filenameamount = $dir.
'/ordersamountinyear-'.$year.
'.png';
207 if ($mode ==
'customer') {
208 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$year.
'.png';
210 if ($mode ==
'supplier') {
211 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$year.
'.png';
216$mesg = $px2->isGraphKo();
218 $px2->SetData($data);
221 while ($i <= $endyear) {
225 $px2->SetLegend($legend);
226 $px2->SetMaxValue($px2->GetCeilMaxValue());
227 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
228 $px2->SetWidth($WIDTH);
229 $px2->SetHeight($HEIGHT);
230 $px2->SetYLabel($langs->trans(
"AmountOfOrders"));
232 $px2->SetHorizTickIncrement(1);
233 $px2->mode =
'depth';
234 $px2->SetTitle($langs->trans(
"AmountOfOrdersByMonthHT"));
236 $px2->draw($filenameamount, $fileurlamount);
240$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
244if (!$user->hasRight(
'societe',
'client',
'voir')) {
245 $filename_avg = $dir.
'/ordersaverage-'.$user->id.
'-'.$year.
'.png';
246 if ($mode ==
'customer') {
247 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
249 if ($mode ==
'supplier') {
250 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
253 $filename_avg = $dir.
'/ordersaverage-'.$year.
'.png';
254 if ($mode ==
'customer') {
255 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.
'.png';
257 if ($mode ==
'supplier') {
258 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.
'.png';
263$mesg = $px3->isGraphKo();
265 $px3->SetData($data);
268 while ($i <= $endyear) {
272 $px3->SetLegend($legend);
273 $px3->SetYLabel($langs->trans(
"AmountAverage"));
274 $px3->SetMaxValue($px3->GetCeilMaxValue());
275 $px3->SetMinValue($px3->GetFloorMinValue());
276 $px3->SetWidth($WIDTH);
277 $px3->SetHeight($HEIGHT);
279 $px3->SetHorizTickIncrement(1);
280 $px3->mode =
'depth';
281 $px3->SetTitle($langs->trans(
"AmountAverage"));
283 $px3->draw($filename_avg, $fileurl_avg);
289$data = $stats->getAllByYear();
290$arrayyears = array();
291foreach ($data as $val) {
292 if (!empty($val[
'year'])) {
293 $arrayyears[$val[
'year']] = $val[
'year'];
296if (!count($arrayyears)) {
297 $arrayyears[$nowyear] = $nowyear;
302$head[$h][0] = DOL_URL_ROOT.
'/commande/stats/index.php?mode='.$mode;
303$head[$h][1] = $langs->trans(
"ByMonthYear");
304$head[$h][2] =
'byyear';
307$type =
'order_stats';
309if ($mode ==
'supplier') {
310 $type =
'supplier_order_stats';
318print
'<div class="fichecenter"><div class="fichethirdleft">';
322print
'<form name="stats" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
323print
'<input type="hidden" name="token" value="'.newToken().
'">';
324print
'<input type="hidden" name="mode" value="'.$mode.
'">';
326print
'<table class="noborder centpercent">';
327print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
329print
'<tr><td class="left">'.$langs->trans(
"ThirdParty").
'</td><td class="left">';
331if ($mode ==
'customer') {
332 $filter =
'(s.client:IN:1,2,3)';
334if ($mode ==
'supplier') {
335 $filter =
'(s.fournisseur:=:1)';
337print
img_picto(
'',
'company',
'class="pictofixedwidth"');
338print $form->select_company($socid,
'socid', $filter, 1, 0, 0, array(), 0,
'widthcentpercentminusx maxwidth300');
341print
'<tr><td>'.$langs->trans(
"ThirdPartyType").
'</td><td>';
342$sortparam_typent = (!
getDolGlobalString(
'SOCIETE_SORT_ON_TYPEENT') ?
'ASC' :
$conf->global->SOCIETE_SORT_ON_TYPEENT);
343print $form->selectarray(
"typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0,
'', 0, 0, 0, $sortparam_typent,
'', 1);
345 print
' '.info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
351if ($mode ==
'customer') {
352 $cat_type = Categorie::TYPE_CUSTOMER;
353 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Customer"));
355if ($mode ==
'supplier') {
356 $cat_type = Categorie::TYPE_SUPPLIER;
357 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Supplier"));
359print
'<tr><td>'.$cat_label.
'</td><td>';
360print
img_picto(
'',
'category',
'class="pictofixedwidth"');
361print $formother->select_categories($cat_type, $categ_id,
'categ_id', 0, 1,
'widthcentpercentminusx maxwidth300');
364print
'<tr><td>'.$langs->trans(
"CreatedBy").
'</td><td>';
365print
img_picto(
'',
'user',
'class="pictofixedwidth"');
366print $form->select_dolusers($userid,
'userid', 1,
'', 0,
'',
'', 0, 0, 0,
'', 0,
'',
'widthcentpercentminusx maxwidth300');
368print
'<tr><td>'.$langs->trans(
"Status").
'</td><td>';
369if ($mode ==
'customer') {
377 print $form->selectarray(
'object_status', $liststatus,
GETPOST(
'object_status',
'intcomma'), -4);
379if ($mode ==
'supplier') {
380 $formorder->selectSupplierOrderStatus((strstr($object_status,
',') ? -1 : $object_status), 0,
'object_status');
384print
'<tr><td class="left">'.$langs->trans(
"Year").
'</td><td class="left">';
385if (!in_array($year, $arrayyears)) {
386 $arrayyears[$year] = $year;
388if (!in_array($nowyear, $arrayyears)) {
389 $arrayyears[$nowyear] = $nowyear;
392print $form->selectarray(
'year', $arrayyears, $year, 0, 0, 0,
'', 0, 0, 0,
'',
'width75');
394print
'<tr><td align="center" colspan="2"><input type="submit" class="button small" name="submit" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
400print
'<div class="div-table-responsive-no-min">';
401print
'<table class="noborder centpercent">';
402print
'<tr class="liste_titre" height="24">';
403print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
404print
'<td class="right">'.$langs->trans(
"NbOfOrders").
'</td>';
405print
'<td class="right">%</td>';
406print
'<td class="right">'.$langs->trans(
"AmountTotal").
'</td>';
407print
'<td class="right">%</td>';
408print
'<td class="right">'.$langs->trans(
"AmountAverage").
'</td>';
409print
'<td class="right">%</td>';
413foreach ($data as $val) {
414 $year = $val[
'year'];
415 while (!empty($year) && $oldyear > (
int) $year + 1) {
418 print
'<tr class="oddeven" height="24">';
419 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$oldyear.
'</a></td>';
420 print
'<td class="right">0</td>';
421 print
'<td class="right"></td>';
422 print
'<td class="right">0</td>';
423 print
'<td class="right"></td>';
424 print
'<td class="right">0</td>';
425 print
'<td class="right"></td>';
430 print
'<tr class="oddeven" height="24">';
431 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$year.
'</a></td>';
432 print
'<td class="right">'.$val[
'nb'].
'</td>';
433 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>';
434 print
'<td class="right">'.price(
price2num($val[
'total'],
'MT'), 1).
'</td>';
435 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>';
436 print
'<td class="right">'.price(
price2num($val[
'avg'],
'MT'), 1).
'</td>';
437 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>';
446print
'</div><div class="fichetwothirdright">';
450print
'<table class="border centpercent"><tr class="pair nohover"><td align="center">';
460print
'</td></tr></table>';
464print
'<div class="clearboth"></div>';
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.
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($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_now($mode='auto')
Return date for now.
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).
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 a Dolibarr global constant string value.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.