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(
"OrdersStatistics");
113$dir =
$conf->commande->dir_temp;
115if ($mode ==
'supplier') {
116 $picto =
'supplier_order';
117 $title = $langs->trans(
"OrdersStatisticsSuppliers");
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'));
141 $newcardbutton .= dolGetButtonTitleSeparator();
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'));
151 $newcardbutton .= dolGetButtonTitleSeparator();
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);
188if (!$user->hasRight(
'societe',
'client',
'voir')) {
189 $filenamenb = $dir.
'/ordersnbinyear-'.$user->id.
'-'.$year.
'.png';
190 if ($mode ==
'customer') {
191 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$user->id.
'-'.$year.
'.png';
193 if ($mode ==
'supplier') {
194 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$user->id.
'-'.$year.
'.png';
197 $filenamenb = $dir.
'/ordersnbinyear-'.$year.
'.png';
198 if ($mode ==
'customer') {
199 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$year.
'.png';
201 if ($mode ==
'supplier') {
202 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$year.
'.png';
207$mesg = $px1->isGraphKo();
209 $px1->SetData($data);
212 while ($i <= $endyear) {
216 $px1->SetLegend($legend);
217 $px1->SetMaxValue($px1->GetCeilMaxValue());
218 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
219 $px1->SetWidth($WIDTH);
220 $px1->SetHeight($HEIGHT);
221 $px1->SetYLabel($langs->trans(
"NbOfOrder"));
223 $px1->SetHorizTickIncrement(1);
224 $px1->mode =
'depth';
225 $px1->SetTitle($langs->trans(
"NumberOfOrdersByMonth"));
227 $px1->draw($filenamenb, $fileurlnb);
231$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
236if (!$user->hasRight(
'societe',
'client',
'voir')) {
237 $filenameamount = $dir.
'/ordersamountinyear-'.$user->id.
'-'.$year.
'.png';
238 if ($mode ==
'customer') {
239 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$user->id.
'-'.$year.
'.png';
241 if ($mode ==
'supplier') {
242 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$user->id.
'-'.$year.
'.png';
245 $filenameamount = $dir.
'/ordersamountinyear-'.$year.
'.png';
246 if ($mode ==
'customer') {
247 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$year.
'.png';
249 if ($mode ==
'supplier') {
250 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$year.
'.png';
255$mesg = $px2->isGraphKo();
257 $px2->SetData($data);
260 while ($i <= $endyear) {
264 $px2->SetLegend($legend);
265 $px2->SetMaxValue($px2->GetCeilMaxValue());
266 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
267 $px2->SetWidth($WIDTH);
268 $px2->SetHeight($HEIGHT);
269 $px2->SetYLabel($langs->trans(
"AmountOfOrders"));
271 $px2->SetHorizTickIncrement(1);
272 $px2->mode =
'depth';
273 $px2->SetTitle($langs->trans(
"AmountOfOrdersByMonthHT"));
275 $px2->draw($filenameamount, $fileurlamount);
279$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
283if (!$user->hasRight(
'societe',
'client',
'voir')) {
284 $filename_avg = $dir.
'/ordersaverage-'.$user->id.
'-'.$year.
'.png';
285 if ($mode ==
'customer') {
286 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
288 if ($mode ==
'supplier') {
289 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
292 $filename_avg = $dir.
'/ordersaverage-'.$year.
'.png';
293 if ($mode ==
'customer') {
294 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.
'.png';
296 if ($mode ==
'supplier') {
297 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.
'.png';
302$mesg = $px3->isGraphKo();
304 $px3->SetData($data);
307 while ($i <= $endyear) {
311 $px3->SetLegend($legend);
312 $px3->SetYLabel($langs->trans(
"AmountAverage"));
313 $px3->SetMaxValue($px3->GetCeilMaxValue());
314 $px3->SetMinValue((
int) $px3->GetFloorMinValue());
315 $px3->SetWidth($WIDTH);
316 $px3->SetHeight($HEIGHT);
318 $px3->SetHorizTickIncrement(1);
319 $px3->mode =
'depth';
320 $px3->SetTitle($langs->trans(
"AmountAverage"));
322 $px3->draw($filename_avg, $fileurl_avg);
328$data = $stats->getAllByYear();
329$arrayyears = array();
330foreach ($data as $val) {
331 if (!empty($val[
'year'])) {
332 $arrayyears[$val[
'year']] = $val[
'year'];
335if (!count($arrayyears)) {
336 $arrayyears[$nowyear] = $nowyear;
341$head[$h][0] = DOL_URL_ROOT.
'/commande/stats/index.php?mode='.$mode;
342$head[$h][1] = $langs->trans(
"ByMonthYear");
343$head[$h][2] =
'byyear';
346$type =
'order_stats';
348if ($mode ==
'supplier') {
349 $type =
'supplier_order_stats';
357print
'<div class="fichecenter"><div class="fichethirdleft">';
361print
'<form name="stats" method="POST" action="'.dolBuildUrl($_SERVER[
"PHP_SELF"]).
'">';
362print
'<input type="hidden" name="token" value="'.newToken().
'">';
363print
'<input type="hidden" name="mode" value="'.$mode.
'">';
365print
'<table class="noborder centpercent">';
366print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
368print
'<tr><td class="left">'.$langs->trans(
"ThirdParty").
'</td><td class="left">';
370if ($mode ==
'customer') {
371 $filter =
'(s.client:IN:1,2,3)';
373if ($mode ==
'supplier') {
374 $filter =
'(s.fournisseur:=:1)';
376print
img_picto(
'',
'company',
'class="pictofixedwidth"');
377print $form->select_company($socid,
'socid', $filter, 1, 0, 0, array(), 0,
'widthcentpercentminusx maxwidth300');
380print
'<tr><td>'.$langs->trans(
"ThirdPartyType").
'</td><td>';
381$sortparam_typent = (!
getDolGlobalString(
'SOCIETE_SORT_ON_TYPEENT') ?
'ASC' :
$conf->global->SOCIETE_SORT_ON_TYPEENT);
382print $form->selectarray(
"typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0,
'', 0, 0, 0, $sortparam_typent,
'', 1);
384 print
' '.info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
390if ($mode ==
'customer') {
391 $cat_type = Categorie::TYPE_CUSTOMER;
392 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Customer"));
394if ($mode ==
'supplier') {
395 $cat_type = Categorie::TYPE_SUPPLIER;
396 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Supplier"));
398print
'<tr><td>'.$cat_label.
'</td><td>';
399print
img_picto(
'',
'category',
'class="pictofixedwidth"');
400print $formother->select_categories($cat_type, $categ_id,
'categ_id', 0, 1,
'widthcentpercentminusx maxwidth300');
406 if ($mode ==
'customer') {
407 $cat_type = Categorie::TYPE_ORDER;
408 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"CustomersOrders"));
410 if ($mode ==
'supplier') {
411 $cat_type = Categorie::TYPE_SUPPLIER_ORDER;
412 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"SuppliersOrders"));
414 print
'<tr><td>'.$cat_label.
'</td><td>';
415 $cate_arbo = $form->select_all_categories($cat_type,
'',
'parent', 0, 0, 1);
416 print
img_picto(
'',
'category',
'class="pictofixedwidth"');
417 print $form->multiselectarray(
'select_categ_comande_id', $cate_arbo,
GETPOST(
'select_categ_comande_id',
'array'), 0, 0,
'widthcentpercentminusx maxwidth300');
422print
'<tr><td>'.$langs->trans(
"CreatedBy").
'</td><td>';
423print
img_picto(
'',
'user',
'class="pictofixedwidth"');
424print $form->select_dolusers($userid,
'userid', 1,
null, 0,
'',
'',
'0', 0, 0,
'', 0,
'',
'widthcentpercentminusx maxwidth300');
426print
'<tr><td>'.$langs->trans(
"Status").
'</td><td>';
427if ($mode ==
'customer') {
435 print $form->selectarray(
'object_status', $liststatus,
GETPOST(
'object_status',
'intcomma'), -4);
437if ($mode ==
'supplier') {
438 $formorder->selectSupplierOrderStatus((strstr($object_status,
',') ? -1 : $object_status), 0,
'object_status');
442print
'<tr><td class="left">'.$langs->trans(
"Year").
'</td><td class="left">';
443if (!in_array($year, $arrayyears)) {
444 $arrayyears[$year] = $year;
446if (!in_array($nowyear, $arrayyears)) {
447 $arrayyears[$nowyear] = $nowyear;
450print
img_picto(
'',
'calendar',
'class="pictofixedwidth"');
451print $form->selectarray(
'year', $arrayyears, $year, 0, 0, 0,
'', 0, 0, 0,
'',
'width75');
453print
'<tr><td align="center" colspan="2"><input type="submit" class="button small" name="submit" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
459print
'<div class="div-table-responsive-no-min">';
460print
'<table class="noborder centpercent">';
461print
'<tr class="liste_titre" height="24">';
462print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
463print
'<td class="right">'.$langs->trans(
"NbOfOrders").
'</td>';
464print
'<td class="right">%</td>';
465print
'<td class="right">'.$langs->trans(
"AmountTotal").
'</td>';
466print
'<td class="right">%</td>';
467print
'<td class="right">'.$langs->trans(
"AmountAverage").
'</td>';
468print
'<td class="right">%</td>';
472foreach ($data as $val) {
473 $year = $val[
'year'];
474 while (!empty($year) && $oldyear > (
int) $year + 1) {
477 print
'<tr class="oddeven" height="24">';
478 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$oldyear.
'</a></td>';
479 print
'<td class="right">0</td>';
480 print
'<td class="right"></td>';
481 print
'<td class="right">0</td>';
482 print
'<td class="right"></td>';
483 print
'<td class="right">0</td>';
484 print
'<td class="right"></td>';
489 print
'<tr class="oddeven" height="24">';
490 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$year.
'</a></td>';
491 print
'<td class="right">'.$val[
'nb'].
'</td>';
492 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>';
493 print
'<td class="right">'.price(
price2num($val[
'total'],
'MT'), 1).
'</td>';
494 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>';
495 print
'<td class="right">'.price(
price2num($val[
'avg'],
'MT'), 1).
'</td>';
496 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>';
505print
'</div><div class="fichetwothirdright">';
509print
'<table class="border centpercent"><tr class="pair nohover"><td align="center">';
519print
'</td></tr></table>';
523print
'<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.
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)
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, $morecssdiv='')
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.
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_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)
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.