33require
'../../main.inc.php';
41require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/commande/class/commandestats.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formorder.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
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) {
69$object_status =
GETPOST(
'object_status',
'intcomma');
70if (!empty($object_status)) {
71 $object_status = explode(
',', $object_status);
73 $object_status =
GETPOST(
'object_status',
'array:int');
79$select_categ_comande_id=
GETPOST(
'select_categ_comande_id',
'array');
83if ($user->socid > 0) {
85 $socid = $user->socid;
89$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
91 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
100$langs->loadLangs(array(
'orders',
'companies',
'other',
'suppliers'));
107$form =
new Form($db);
113$title = $langs->trans(
"Orders");
114$dir =
$conf->order->dir_temp;
116if ($mode ==
'supplier') {
117 $picto =
'supplier_order';
118 $title = $langs->trans(
"SuppliersOrders");
119 $dir =
$conf->fournisseur->commande->dir_temp;
122llxHeader(
'', $title,
'',
'', 0, 0,
'',
'',
'',
'mod-order page-stats');
128$massactionbutton =
'';
130$nbtotalofrecords = $langs->trans(
"Statistics");
134if ($mode ==
'supplier') {
135 $urlnew = DOL_URL_ROOT.
'/fourn/commande/card.php?action=create';
136 if (!empty($socid)) {
137 $urlnew .=
'&socid='.$socid;
139 $newcardbutton .=
dolGetButtonTitle($langs->trans(
'ViewList'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/fourn/commande/list.php?mode=common',
'', 1, array(
'morecss' =>
'reposition'));
140 $newcardbutton .=
dolGetButtonTitle($langs->trans(
'ViewKanban'),
'',
'fa fa-th-list imgforviewmode', DOL_URL_ROOT.
'/fourn/commande/list.php?mode=kanban',
'', 1, array(
'morecss' =>
'reposition'));
141 $newcardbutton .=
dolGetButtonTitle($langs->trans(
'Statistics'),
'',
'fa fa-chart-bar imgforviewmode', DOL_URL_ROOT.
'/commande/stats/index.php?mode=supplier',
'', 2, array(
'morecss' =>
'reposition'));
143 $newcardbutton .=
dolGetButtonTitle($langs->trans(
'NewSupplierOrderShort'),
'',
'fa fa-plus-circle', $urlnew,
'', (
int) ($user->hasRight(
'fournisseur',
'commande',
'creer') || $user->hasRight(
'supplier_order',
'creer')));
145 $urlnew = DOL_URL_ROOT.
'/commande/card.php?action=create';
146 if (!empty($socid)) {
147 $urlnew .=
'&socid='.$socid;
149 $newcardbutton .=
dolGetButtonTitle($langs->trans(
'ViewList'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/commande/list.php?mode=common',
'', 1, array(
'morecss' =>
'reposition'));
150 $newcardbutton .=
dolGetButtonTitle($langs->trans(
'ViewKanban'),
'',
'fa fa-th-list imgforviewmode', DOL_URL_ROOT.
'/commande/list.php?mode=kanban',
'', 1, array(
'morecss' =>
'reposition'));
151 $newcardbutton .=
dolGetButtonTitle($langs->trans(
'Statistics'),
'',
'fa fa-chart-bar imgforviewmode', DOL_URL_ROOT.
'/commande/stats/index.php',
'', 2, array(
'morecss' =>
'reposition'));
153 $newcardbutton .=
dolGetButtonTitle($langs->trans(
'NewOrder'),
'',
'fa fa-plus-circle', $urlnew,
'', $user->hasRight(
'commande',
'creer'));
156print_barre_liste($title, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $newcardbutton,
'', $limit, 0, 0, 1);
160$stats =
new CommandeStats($db, $socid, $mode, ($userid > 0 ? $userid : 0), ($typent_id > 0 ? $typent_id : 0), ($categ_id > 0 ? $categ_id : 0));
161if (!empty($object_status)) {
162 $stats->where .=
' AND c.fk_statut IN ('.$db->sanitize(implode(
",", $object_status)).
')';
164if ($mode ==
'customer') {
165 if (is_array($select_categ_comande_id) && !empty($select_categ_comande_id)) {
166 $stats->from .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'categorie_order as cat ON (c.rowid = cat.fk_order)';
167 $stats->where .=
' AND cat.fk_categorie IN ('.$db->sanitize(implode(
',', $select_categ_comande_id)).
')';
170if ($mode ==
'supplier') {
171 if (is_array($select_categ_comande_id) && !empty($select_categ_comande_id)) {
172 $stats->from .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'categorie_supplier_order as cat ON (c.rowid = cat.fk_supplier_order)';
173 $stats->where .=
' AND cat.fk_categorie IN ('.$db->sanitize(implode(
',', $select_categ_comande_id)).
')';
179$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
185if (!$user->hasRight(
'societe',
'client',
'voir')) {
186 $filenamenb = $dir.
'/ordersnbinyear-'.$user->id.
'-'.$year.
'.png';
187 if ($mode ==
'customer') {
188 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$user->id.
'-'.$year.
'.png';
190 if ($mode ==
'supplier') {
191 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$user->id.
'-'.$year.
'.png';
194 $filenamenb = $dir.
'/ordersnbinyear-'.$year.
'.png';
195 if ($mode ==
'customer') {
196 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$year.
'.png';
198 if ($mode ==
'supplier') {
199 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$year.
'.png';
204$mesg = $px1->isGraphKo();
206 $px1->SetData($data);
209 while ($i <= $endyear) {
213 $px1->SetLegend($legend);
214 $px1->SetMaxValue($px1->GetCeilMaxValue());
215 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
216 $px1->SetWidth($WIDTH);
217 $px1->SetHeight($HEIGHT);
218 $px1->SetYLabel($langs->trans($mode ==
'supplier' ?
"NumberOfSupplierOrders" :
"NumberOfOrders"));
220 $px1->SetHorizTickIncrement(1);
221 $px1->mode =
'depth';
222 $px1->SetTitle($langs->trans($mode ==
'supplier' ?
"NumberOfSupplierOrdersByMonth" :
"NumberOfOrdersByMonth"));
224 $px1->draw($filenamenb, $fileurlnb);
228$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
232if (!$user->hasRight(
'societe',
'client',
'voir')) {
233 $filenameamount = $dir.
'/ordersamountinyear-'.$user->id.
'-'.$year.
'.png';
234 if ($mode ==
'customer') {
235 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$user->id.
'-'.$year.
'.png';
237 if ($mode ==
'supplier') {
238 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$user->id.
'-'.$year.
'.png';
241 $filenameamount = $dir.
'/ordersamountinyear-'.$year.
'.png';
242 if ($mode ==
'customer') {
243 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$year.
'.png';
245 if ($mode ==
'supplier') {
246 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$year.
'.png';
251$mesg = $px2->isGraphKo();
253 $px2->SetData($data);
256 while ($i <= $endyear) {
260 $px2->SetLegend($legend);
261 $px2->SetMaxValue($px2->GetCeilMaxValue());
262 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
263 $px2->SetWidth($WIDTH);
264 $px2->SetHeight($HEIGHT);
265 $px2->SetYLabel($langs->trans($mode ==
'supplier' ?
"AmountOfSupplierOrders" :
"AmountOfOrders"));
267 $px2->SetHorizTickIncrement(1);
268 $px2->mode =
'depth';
269 $px2->SetTitle($langs->trans($mode ==
'supplier' ?
"AmountOfSupplierOrdersByMonthHT" :
"AmountOfOrdersByMonthHT"));
271 $px2->draw($filenameamount, $fileurlamount);
275$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
279if (!$user->hasRight(
'societe',
'client',
'voir')) {
280 $filename_avg = $dir.
'/ordersaverage-'.$user->id.
'-'.$year.
'.png';
281 if ($mode ==
'customer') {
282 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
284 if ($mode ==
'supplier') {
285 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
288 $filename_avg = $dir.
'/ordersaverage-'.$year.
'.png';
289 if ($mode ==
'customer') {
290 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.
'.png';
292 if ($mode ==
'supplier') {
293 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.
'.png';
298$mesg = $px3->isGraphKo();
300 $px3->SetData($data);
303 while ($i <= $endyear) {
307 $px3->SetLegend($legend);
308 $px3->SetYLabel($langs->trans(
"AmountAverage"));
309 $px3->SetMaxValue($px3->GetCeilMaxValue());
310 $px3->SetMinValue((
int) $px3->GetFloorMinValue());
311 $px3->SetWidth($WIDTH);
312 $px3->SetHeight($HEIGHT);
314 $px3->SetHorizTickIncrement(1);
315 $px3->mode =
'depth';
316 $px3->SetTitle($langs->trans(
"AmountAverage"));
318 $px3->draw($filename_avg, $fileurl_avg);
324$data = $stats->getAllByYear();
325$arrayyears = array();
326foreach ($data as $val) {
327 if (!empty($val[
'year'])) {
328 $arrayyears[$val[
'year']] = $val[
'year'];
331if (!count($arrayyears)) {
332 $arrayyears[$nowyear] = $nowyear;
337$head[$h][0] = DOL_URL_ROOT.
'/commande/stats/index.php?mode='.$mode;
338$head[$h][1] = $langs->trans(
"ByMonthYear");
339$head[$h][2] =
'byyear';
342$type =
'order_stats';
344if ($mode ==
'supplier') {
345 $type =
'supplier_order_stats';
353print
'<div class="fichecenter"><div class="fichethirdleft">';
357print
'<form name="stats" method="POST" action="'.dolBuildUrl($_SERVER[
"PHP_SELF"]).
'">';
358print
'<input type="hidden" name="token" value="'.newToken().
'">';
359print
'<input type="hidden" name="mode" value="'.$mode.
'">';
361print
'<table class="noborder centpercent">';
362print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
364print
'<tr><td class="left">'.$langs->trans(
"ThirdParty").
'</td><td class="left">';
366if ($mode ==
'customer') {
367 $filter =
'(s.client:IN:1,2,3)';
369if ($mode ==
'supplier') {
370 $filter =
'(s.fournisseur:=:1)';
372print img_picto(
'',
'company',
'class="pictofixedwidth"');
373print $form->select_company($socid,
'socid', $filter, 1, 0, 0, array(), 0,
'widthcentpercentminusx maxwidth300');
376print
'<tr><td>'.$langs->trans(
"ThirdPartyType").
'</td><td>';
377$sortparam_typent = (!
getDolGlobalString(
'SOCIETE_SORT_ON_TYPEENT') ?
'ASC' :
$conf->global->SOCIETE_SORT_ON_TYPEENT);
378print $form->selectarray(
"typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0,
'', 0, 0, 0, $sortparam_typent,
'', 1);
380 print
' '.info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
386if ($mode ==
'customer') {
387 $cat_type = Categorie::TYPE_CUSTOMER;
388 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Customer"));
390if ($mode ==
'supplier') {
391 $cat_type = Categorie::TYPE_SUPPLIER;
392 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Supplier"));
394print
'<tr><td>'.$cat_label.
'</td><td>';
395print img_picto(
'',
'category',
'class="pictofixedwidth"');
396print $formother->select_categories($cat_type, $categ_id,
'categ_id', 0, 1,
'widthcentpercentminusx maxwidth300');
402 if ($mode ==
'customer') {
403 $cat_type = Categorie::TYPE_ORDER;
404 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"CustomersOrders"));
406 if ($mode ==
'supplier') {
407 $cat_type = Categorie::TYPE_SUPPLIER_ORDER;
408 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"SuppliersOrders"));
410 print
'<tr><td>'.$cat_label.
'</td><td>';
411 $cate_arbo = $form->select_all_categories($cat_type,
'',
'parent', 0, 0, 1);
412 print img_picto(
'',
'category',
'class="pictofixedwidth"');
413 print $form->multiselectarray(
'select_categ_comande_id', $cate_arbo,
GETPOST(
'select_categ_comande_id',
'array'), 0, 0,
'widthcentpercentminusx maxwidth300');
418print
'<tr><td>'.$langs->trans(
"CreatedBy").
'</td><td>';
419print img_picto(
'',
'user',
'class="pictofixedwidth"');
423print $form->select_dolusers(($userid > 0 ? $userid : -1),
'userid', 1, null, 0,
'',
'',
'0', 0, 0,
'', 0,
'',
'widthcentpercentminusx maxwidth300');
425print
'<tr><td>'.$langs->trans(
"Status").
'</td><td>';
426if ($mode ==
'customer') {
434 print $form->multiselectarray(
'object_status', $liststatus, $object_status, 0, 0,
'minwidth300');
436if ($mode ==
'supplier') {
437 $formorder->selectSupplierOrderStatus($object_status, 0,
'object_status',
'minwidth300', 1);
441print
'<tr><td class="left">'.$langs->trans(
"Year").
'</td><td class="left">';
442if (!in_array($year, $arrayyears)) {
443 $arrayyears[$year] = $year;
445if (!in_array($nowyear, $arrayyears)) {
446 $arrayyears[$nowyear] = $nowyear;
449print img_picto(
'',
'calendar',
'class="pictofixedwidth"');
450print $form->selectarray(
'year', $arrayyears, $year, 0, 0, 0,
'', 0, 0, 0,
'',
'width75');
452print
'<tr><td align="center" colspan="2"><input type="submit" class="button small" name="submit" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
458print
'<div class="div-table-responsive-no-min">';
459print
'<table class="noborder centpercent">';
460print
'<tr class="liste_titre" height="24">';
461print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
462print
'<td class="right">'.$langs->trans($mode ==
'supplier' ?
"NumberOfSupplierOrders" :
"NbOfOrders").
'</td>';
463print
'<td class="right">%</td>';
464print
'<td class="right">'.$langs->trans(
"AmountTotal").
'</td>';
465print
'<td class="right">%</td>';
466print
'<td class="right">'.$langs->trans(
"AmountAverage").
'</td>';
467print
'<td class="right">%</td>';
471foreach ($data as $val) {
472 $year = $val[
'year'];
473 while (!empty($year) && $oldyear > (
int) $year + 1) {
476 print
'<tr class="oddeven" height="24">';
477 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 $isyearbeforeval = ($oldyear == (int) $year + 1);
480 print
'<td class="right">0</td>';
481 print
'<td class="right opacitylow" style="color: red;">'.(($isyearbeforeval && $val[
'nb'] > 0) ?
'-100%' :
'').
'</td>';
482 print
'<td class="right">0</td>';
483 print
'<td class="right opacitylow" style="color: red;">'.(($isyearbeforeval && $val[
'total'] > 0) ?
'-100%' :
'').
'</td>';
484 print
'<td class="right">0</td>';
485 print
'<td class="right opacitylow" style="color: red;">'.(($isyearbeforeval && $val[
'avg'] > 0) ?
'-100%' :
'').
'</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']) ? ($val[
'nb_diff'] < 0 ?
'' :
'+').round($val[
'nb_diff']).
'%' :
'').
'</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']) ? ($val[
'total_diff'] < 0 ?
'' :
'+').round($val[
'total_diff']).
'%' :
'').
'</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']) ? ($val[
'avg_diff'] < 0 ?
'' :
'+').round($val[
'avg_diff']).
'%' :
'').
'</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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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, $currencycode='')
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).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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)
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.