32require
'../../main.inc.php';
40require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/commande/class/commandestats.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formorder.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
51$mode = GETPOSTISSET(
"mode") ?
GETPOST(
"mode",
'aZ09') :
'customer';
53$hookmanager->initHooks(array(
'orderstats',
'globalcard'));
55$usercanreadcustumerstatistic = $user->hasRight(
'commande',
'lire');
56$usercanreadsupplierstatistic = $user->hasRight(
'fournisseur',
'commande',
'lire');
58 $usercanreadcustumerstatistic = $user->hasRight(
'commande',
'commande',
'export');
59 $usercanreadsupplierstatistic = $user->hasRight(
'fournisseur',
'commande',
'export');
61if ($mode ==
'customer' && !$usercanreadcustumerstatistic) {
64if ($mode ==
'supplier' && !$usercanreadsupplierstatistic) {
68if ($mode ==
'supplier') {
69 $object_status =
GETPOST(
'object_status',
'array:int');
70 $object_status = implode(
',', $object_status);
72 $object_status =
GETPOST(
'object_status',
'intcomma');
78$select_categ_comande_id=
GETPOST(
'select_categ_comande_id',
'array');
82if ($user->socid > 0) {
84 $socid = $user->socid;
88$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
99$langs->loadLangs(array(
'orders',
'companies',
'other',
'suppliers'));
112$title = $langs->trans(
"Orders");
113$dir =
$conf->order->dir_temp;
115if ($mode ==
'supplier') {
116 $picto =
'supplier_order';
117 $title = $langs->trans(
"SuppliersOrders");
118 $dir =
$conf->fournisseur->commande->dir_temp;
121llxHeader(
'', $title,
'',
'', 0, 0,
'',
'',
'',
'mod-order page-stats');
127$massactionbutton =
'';
129$nbtotalofrecords = $langs->trans(
"Statistics");
133if ($mode ==
'supplier') {
134 $urlnew = DOL_URL_ROOT.
'/fourn/commande/card.php?action=create';
135 if (!empty($socid)) {
136 $urlnew .=
'&socid='.$socid;
138 $newcardbutton .=
dolGetButtonTitle($langs->trans(
'ViewList'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/fourn/commande/list.php?mode=common',
'', 1, array(
'morecss' =>
'reposition'));
139 $newcardbutton .=
dolGetButtonTitle($langs->trans(
'ViewKanban'),
'',
'fa fa-th-list imgforviewmode', DOL_URL_ROOT.
'/fourn/commande/list.php?mode=kanban',
'', 1, array(
'morecss' =>
'reposition'));
140 $newcardbutton .=
dolGetButtonTitle($langs->trans(
'Statistics'),
'',
'fa fa-chart-bar imgforviewmode', DOL_URL_ROOT.
'/commande/stats/index.php?mode=supplier',
'', 2, array(
'morecss' =>
'reposition'));
142 $newcardbutton .=
dolGetButtonTitle($langs->trans(
'NewSupplierOrderShort'),
'',
'fa fa-plus-circle', $urlnew,
'', (
int) ($user->hasRight(
'fournisseur',
'commande',
'creer') || $user->hasRight(
'supplier_order',
'creer')));
144 $urlnew = DOL_URL_ROOT.
'/commande/card.php?action=create';
145 if (!empty($socid)) {
146 $urlnew .=
'&socid='.$socid;
148 $newcardbutton .=
dolGetButtonTitle($langs->trans(
'ViewList'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/commande/list.php?mode=common',
'', 1, array(
'morecss' =>
'reposition'));
149 $newcardbutton .=
dolGetButtonTitle($langs->trans(
'ViewKanban'),
'',
'fa fa-th-list imgforviewmode', DOL_URL_ROOT.
'/commande/list.php?mode=kanban',
'', 1, array(
'morecss' =>
'reposition'));
150 $newcardbutton .=
dolGetButtonTitle($langs->trans(
'Statistics'),
'',
'fa fa-chart-bar imgforviewmode', DOL_URL_ROOT.
'/commande/stats/index.php',
'', 2, array(
'morecss' =>
'reposition'));
152 $newcardbutton .=
dolGetButtonTitle($langs->trans(
'NewOrder'),
'',
'fa fa-plus-circle', $urlnew,
'', $user->hasRight(
'commande',
'creer'));
155print_barre_liste($title, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $newcardbutton,
'', $limit, 0, 0, 1);
159$stats =
new CommandeStats(
$db, $socid, $mode, ($userid > 0 ? $userid : 0), ($typent_id > 0 ? $typent_id : 0), ($categ_id > 0 ? $categ_id : 0));
160if ($mode ==
'customer') {
161 if ($object_status !=
'' && $object_status >= -1) {
162 $stats->where .=
' AND c.fk_statut IN ('.$db->sanitize($object_status).
')';
164 if (is_array($select_categ_comande_id) && !empty($select_categ_comande_id)) {
165 $stats->from .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'categorie_order as cat ON (c.rowid = cat.fk_order)';
166 $stats->where .=
' AND cat.fk_categorie IN ('.$db->sanitize(implode(
',', $select_categ_comande_id)).
')';
169if ($mode ==
'supplier') {
170 if ($object_status !=
'' && $object_status >= 0) {
171 $stats->where .=
' AND c.fk_statut IN ('.$db->sanitize($object_status).
')';
173 if (is_array($select_categ_comande_id) && !empty($select_categ_comande_id)) {
174 $stats->from .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'categorie_supplier_order as cat ON (c.rowid = cat.fk_supplier_order)';
175 $stats->where .=
' AND cat.fk_categorie IN ('.$db->sanitize(implode(
',', $select_categ_comande_id)).
')';
181$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
187if (!$user->hasRight(
'societe',
'client',
'voir')) {
188 $filenamenb = $dir.
'/ordersnbinyear-'.$user->id.
'-'.$year.
'.png';
189 if ($mode ==
'customer') {
190 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$user->id.
'-'.$year.
'.png';
192 if ($mode ==
'supplier') {
193 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$user->id.
'-'.$year.
'.png';
196 $filenamenb = $dir.
'/ordersnbinyear-'.$year.
'.png';
197 if ($mode ==
'customer') {
198 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$year.
'.png';
200 if ($mode ==
'supplier') {
201 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$year.
'.png';
206$mesg = $px1->isGraphKo();
208 $px1->SetData($data);
211 while ($i <= $endyear) {
215 $px1->SetLegend($legend);
216 $px1->SetMaxValue($px1->GetCeilMaxValue());
217 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
218 $px1->SetWidth($WIDTH);
219 $px1->SetHeight($HEIGHT);
220 $px1->SetYLabel($langs->trans(
"NbOfOrder"));
222 $px1->SetHorizTickIncrement(1);
223 $px1->mode =
'depth';
224 $px1->SetTitle($langs->trans(
"NumberOfOrdersByMonth"));
226 $px1->draw($filenamenb, $fileurlnb);
230$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
234if (!$user->hasRight(
'societe',
'client',
'voir')) {
235 $filenameamount = $dir.
'/ordersamountinyear-'.$user->id.
'-'.$year.
'.png';
236 if ($mode ==
'customer') {
237 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$user->id.
'-'.$year.
'.png';
239 if ($mode ==
'supplier') {
240 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$user->id.
'-'.$year.
'.png';
243 $filenameamount = $dir.
'/ordersamountinyear-'.$year.
'.png';
244 if ($mode ==
'customer') {
245 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$year.
'.png';
247 if ($mode ==
'supplier') {
248 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$year.
'.png';
253$mesg = $px2->isGraphKo();
255 $px2->SetData($data);
258 while ($i <= $endyear) {
262 $px2->SetLegend($legend);
263 $px2->SetMaxValue($px2->GetCeilMaxValue());
264 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
265 $px2->SetWidth($WIDTH);
266 $px2->SetHeight($HEIGHT);
267 $px2->SetYLabel($langs->trans(
"AmountOfOrders"));
269 $px2->SetHorizTickIncrement(1);
270 $px2->mode =
'depth';
271 $px2->SetTitle($langs->trans(
"AmountOfOrdersByMonthHT"));
273 $px2->draw($filenameamount, $fileurlamount);
277$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
281if (!$user->hasRight(
'societe',
'client',
'voir')) {
282 $filename_avg = $dir.
'/ordersaverage-'.$user->id.
'-'.$year.
'.png';
283 if ($mode ==
'customer') {
284 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
286 if ($mode ==
'supplier') {
287 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
290 $filename_avg = $dir.
'/ordersaverage-'.$year.
'.png';
291 if ($mode ==
'customer') {
292 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.
'.png';
294 if ($mode ==
'supplier') {
295 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.
'.png';
300$mesg = $px3->isGraphKo();
302 $px3->SetData($data);
305 while ($i <= $endyear) {
309 $px3->SetLegend($legend);
310 $px3->SetYLabel($langs->trans(
"AmountAverage"));
311 $px3->SetMaxValue($px3->GetCeilMaxValue());
312 $px3->SetMinValue((
int) $px3->GetFloorMinValue());
313 $px3->SetWidth($WIDTH);
314 $px3->SetHeight($HEIGHT);
316 $px3->SetHorizTickIncrement(1);
317 $px3->mode =
'depth';
318 $px3->SetTitle($langs->trans(
"AmountAverage"));
320 $px3->draw($filename_avg, $fileurl_avg);
326$data = $stats->getAllByYear();
327$arrayyears = array();
328foreach ($data as $val) {
329 if (!empty($val[
'year'])) {
330 $arrayyears[$val[
'year']] = $val[
'year'];
333if (!count($arrayyears)) {
334 $arrayyears[$nowyear] = $nowyear;
339$head[$h][0] = DOL_URL_ROOT.
'/commande/stats/index.php?mode='.$mode;
340$head[$h][1] = $langs->trans(
"ByMonthYear");
341$head[$h][2] =
'byyear';
344$type =
'order_stats';
346if ($mode ==
'supplier') {
347 $type =
'supplier_order_stats';
355print
'<div class="fichecenter"><div class="fichethirdleft">';
359print
'<form name="stats" method="POST" action="'.dolBuildUrl($_SERVER[
"PHP_SELF"]).
'">';
360print
'<input type="hidden" name="token" value="'.newToken().
'">';
361print
'<input type="hidden" name="mode" value="'.$mode.
'">';
363print
'<table class="noborder centpercent">';
364print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
366print
'<tr><td class="left">'.$langs->trans(
"ThirdParty").
'</td><td class="left">';
368if ($mode ==
'customer') {
369 $filter =
'(s.client:IN:1,2,3)';
371if ($mode ==
'supplier') {
372 $filter =
'(s.fournisseur:=:1)';
374print
img_picto(
'',
'company',
'class="pictofixedwidth"');
375print $form->select_company($socid,
'socid', $filter, 1, 0, 0, array(), 0,
'widthcentpercentminusx maxwidth300');
378print
'<tr><td>'.$langs->trans(
"ThirdPartyType").
'</td><td>';
379$sortparam_typent = (!
getDolGlobalString(
'SOCIETE_SORT_ON_TYPEENT') ?
'ASC' :
$conf->global->SOCIETE_SORT_ON_TYPEENT);
380print $form->selectarray(
"typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0,
'', 0, 0, 0, $sortparam_typent,
'', 1);
382 print
' '.info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
388if ($mode ==
'customer') {
389 $cat_type = Categorie::TYPE_CUSTOMER;
390 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Customer"));
392if ($mode ==
'supplier') {
393 $cat_type = Categorie::TYPE_SUPPLIER;
394 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Supplier"));
396print
'<tr><td>'.$cat_label.
'</td><td>';
397print
img_picto(
'',
'category',
'class="pictofixedwidth"');
398print $formother->select_categories($cat_type, $categ_id,
'categ_id', 0, 1,
'widthcentpercentminusx maxwidth300');
404 if ($mode ==
'customer') {
405 $cat_type = Categorie::TYPE_ORDER;
406 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"CustomersOrders"));
408 if ($mode ==
'supplier') {
409 $cat_type = Categorie::TYPE_SUPPLIER_ORDER;
410 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"SuppliersOrders"));
412 print
'<tr><td>'.$cat_label.
'</td><td>';
413 $cate_arbo = $form->select_all_categories($cat_type,
'',
'parent', 0, 0, 1);
414 print
img_picto(
'',
'category',
'class="pictofixedwidth"');
415 print $form->multiselectarray(
'select_categ_comande_id', $cate_arbo,
GETPOST(
'select_categ_comande_id',
'array'), 0, 0,
'widthcentpercentminusx maxwidth300');
420print
'<tr><td>'.$langs->trans(
"CreatedBy").
'</td><td>';
421print
img_picto(
'',
'user',
'class="pictofixedwidth"');
425print $form->select_dolusers(($userid > 0 ? $userid : -1),
'userid', 1, null, 0,
'',
'',
'0', 0, 0,
'', 0,
'',
'widthcentpercentminusx maxwidth300');
427print
'<tr><td>'.$langs->trans(
"Status").
'</td><td>';
428if ($mode ==
'customer') {
436 print $form->selectarray(
'object_status', $liststatus,
GETPOST(
'object_status',
'intcomma'), -4);
438if ($mode ==
'supplier') {
439 $formorder->selectSupplierOrderStatus((strstr($object_status,
',') ? -1 : $object_status), 0,
'object_status');
443print
'<tr><td class="left">'.$langs->trans(
"Year").
'</td><td class="left">';
444if (!in_array($year, $arrayyears)) {
445 $arrayyears[$year] = $year;
447if (!in_array($nowyear, $arrayyears)) {
448 $arrayyears[$nowyear] = $nowyear;
451print
img_picto(
'',
'calendar',
'class="pictofixedwidth"');
452print $form->selectarray(
'year', $arrayyears, $year, 0, 0, 0,
'', 0, 0, 0,
'',
'width75');
454print
'<tr><td align="center" colspan="2"><input type="submit" class="button small" name="submit" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
460print
'<div class="div-table-responsive-no-min">';
461print
'<table class="noborder centpercent">';
462print
'<tr class="liste_titre" height="24">';
463print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
464print
'<td class="right">'.$langs->trans(
"NbOfOrders").
'</td>';
465print
'<td class="right">%</td>';
466print
'<td class="right">'.$langs->trans(
"AmountTotal").
'</td>';
467print
'<td class="right">%</td>';
468print
'<td class="right">'.$langs->trans(
"AmountAverage").
'</td>';
469print
'<td class="right">%</td>';
473foreach ($data as $val) {
474 $year = $val[
'year'];
475 while (!empty($year) && $oldyear > (
int) $year + 1) {
478 print
'<tr class="oddeven" height="24">';
479 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$oldyear.
'</a></td>';
480 print
'<td class="right">0</td>';
481 print
'<td class="right"></td>';
482 print
'<td class="right">0</td>';
483 print
'<td class="right"></td>';
484 print
'<td class="right">0</td>';
485 print
'<td class="right"></td>';
490 print
'<tr class="oddeven" height="24">';
491 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$year.
'</a></td>';
492 print
'<td class="right">'.$val[
'nb'].
'</td>';
493 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>';
494 print
'<td class="right">'.price(
price2num($val[
'total'],
'MT'), 1).
'</td>';
495 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>';
496 print
'<td class="right">'.price(
price2num($val[
'avg'],
'MT'), 1).
'</td>';
497 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>';
506print
'</div><div class="fichetwothirdright">';
510print
'<table class="border centpercent"><tr class="pair nohover"><td align="center">';
520print
'</td></tr></table>';
524print
'<div class="clearboth"></div>';
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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
dol_now($mode='gmt')
Return date for now.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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.
isModEnabled($module)
Is Dolibarr module enabled.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.