34if (!$res && !empty($_SERVER[
"CONTEXT_DOCUMENT_ROOT"])) {
35 $res = @include str_replace(
"..",
"", $_SERVER[
"CONTEXT_DOCUMENT_ROOT"]).
"/main.inc.php";
38$tmp = empty($_SERVER[
'SCRIPT_FILENAME']) ?
'' : $_SERVER[
'SCRIPT_FILENAME'];
39$tmp2 = realpath(__FILE__);
41$j = strlen($tmp2) - 1;
42while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
46if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)).
"/main.inc.php")) {
47 $res = @include substr($tmp, 0, ($i + 1)).
"/main.inc.php";
49if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))).
"/main.inc.php")) {
50 $res = @include dirname(substr($tmp, 0, ($i + 1))).
"/main.inc.php";
53if (!$res && file_exists(
"../main.inc.php")) {
54 $res = @include
"../main.inc.php";
56if (!$res && file_exists(
"../../main.inc.php")) {
57 $res = @include
"../../main.inc.php";
59if (!$res && file_exists(
"../../../main.inc.php")) {
60 $res = @include
"../../../main.inc.php";
63 die(
"Include of main fails");
72require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
73require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
81$mode = GETPOSTISSET(
"mode") ?
GETPOST(
"mode",
'aZ09') :
'statistics';
86$hookmanager->initHooks(array(
'mymodulestats',
'myobjectstats',
'globalcard'));
88$objecttype =
'myobject';
92$usercanreadstatistic = 1;
93$enablepermissioncheck =
getDolGlobalInt(
'MYMODULE_ENABLE_PERMISSION_CHECK');
94if ($enablepermissioncheck) {
95 $usercanreadstatistic = $user->hasRight($objecttype,
'read');
96 if (
getDolGlobalInt(
'MAIN_NEED_EXPORT_PERMISSION_TO_READ_STATISTICS')) {
97 $usercanreadstatistic = $user->hasRight($objecttype,
'export');
101if (!$usercanreadstatistic) {
107if ($user->socid > 0) {
109 $socid = $user->socid;
112$parameters = array();
113$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
120$startyear = $year - (!
getDolGlobalInt(
'MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10,
getDolGlobalInt(
'MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
124$langs->loadLangs(array(
'companies',
'other',
'mymodule@mymodule'));
133$title = $langs->trans(
"Statistics");
136llxHeader(
'', $title,
'',
'', 0, 0,
'',
'',
'',
'mod-order page-stats');
141$newcardbutton .= dolGetButtonTitle($langs->trans(
'ViewList'),
'',
'fa fa-bars imgforviewmode',
dol_buildpath(
'/mymodule/myobject_list.php', 1).
'?mode=common'.preg_replace(
'/(&|\?)*(mode|groupby)=[^&]+/',
'', $param),
'', ((empty($mode) || $mode ==
'common') ? 2 : 1), array(
'morecss' =>
'reposition'));
142$newcardbutton .= dolGetButtonTitle($langs->trans(
'ViewKanban'),
'',
'fa fa-th-list imgforviewmode',
dol_buildpath(
'/mymodule/myobject_list.php', 1).
'?mode=kanban'.preg_replace(
'/(&|\?)*(mode|groupby)=[^&]+/',
'', $param),
'', ($mode ==
'kanban' ? 2 : 1), array(
'morecss' =>
'reposition'));
145$newcardbutton .= dolGetButtonTitle($langs->trans(
'Statistics'),
'',
'fa fa-chart-bar imgforviewmode',
dol_buildpath(
'/mymodule/stats/mymodule_index.php', 1).
'?mode=statistics&objecttype=myobject@mymodule'.preg_replace(
'/(&|\?)*(mode|groupby)=[^&]+/',
'', $param),
'', ($mode ==
'statistics' ? 2 : 1), array(
'morecss' =>
'reposition'));
146$newcardbutton .= dolGetButtonTitleSeparator();
147$newcardbutton .= dolGetButtonTitle($langs->trans(
'New'),
'',
'fa fa-plus-circle',
dol_buildpath(
'/mymodule/myobject_card.php', 1).
'?action=create&backtopage='.urlencode($_SERVER[
'PHP_SELF']),
'', $permissiontoadd);
153$massactionbutton =
'';
155$nbtotalofrecords = 0;
158print_barre_liste($title, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords,
$object->picto, 0, $newcardbutton,
'', $limit, 0, 0, 1);
165$stats =
new MyObjectStats(
$db, $socid, $mode, ($userid > 0 ? $userid : 0), ($categ_id > 0 ? $categ_id : 0));
169$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
172$filenamenb = $dir.
'/myobjectnbinyear-'.$user->id.
'-'.$year.
'.png';
173$fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$user->id.
'-'.$year.
'.png';
178$mesg = $px1->isGraphKo();
181 $px1->SetData($data);
184 while ($i <= $endyear) {
188 $px1->SetLegend($legend);
189 $px1->SetMaxValue($px1->GetCeilMaxValue());
190 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
191 $px1->SetWidth($WIDTH);
192 $px1->SetHeight($HEIGHT);
193 $px1->SetYLabel($langs->trans(
"Nb"));
195 $px1->SetHorizTickIncrement(1);
196 $px1->mode =
'depth';
197 $px1->SetTitle($langs->trans(
"ByMonth"));
199 $px1->draw($filenamenb, $fileurlnb);
309$data = $stats->getAllByYear();
310$arrayyears = array();
311foreach ($data as $val) {
312 if (!empty($val[
'year'])) {
313 $arrayyears[$val[
'year']] = $val[
'year'];
316if (!count($arrayyears)) {
317 $arrayyears[$nowyear] = $nowyear;
324$head[$h][0] = $_SERVER[
"PHP_SELF"].
'?mode='.$mode;
325$head[$h][1] = $langs->trans(
"ByMonthYear");
326$head[$h][2] =
'byyear';
329$type =
'myobject_stats';
335print
'<div class="fichecenter"><div class="fichethirdleft">';
339print
'<form name="stats" method="POST" action="'.dolBuildUrl($_SERVER[
"PHP_SELF"]).
'">';
340print
'<input type="hidden" name="token" value="'.newToken().
'">';
341print
'<input type="hidden" name="mode" value="'.$mode.
'">';
343print
'<table class="noborder centpercent">';
344print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
360if (array_key_exists(
'fk_user_creat',
$object->fields)) {
361 print
'<tr><td>'.$langs->trans(
"CreatedBy").
'</td><td>';
362 print
img_picto(
'',
'user',
'class="pictofixedwidth"');
363 print $form->select_dolusers($userid,
'userid', 1,
null, 0,
'',
'',
'0', 0, 0,
'', 0,
'',
'widthcentpercentminusx maxwidth300');
366if (array_key_exists(
'status',
$object->fields)) {
367 print
'<tr><td>'.$langs->trans(
"Status").
'</td><td>';
368 $liststatus =
$object->fields[
'status'][
'arrayofkeyvalue'];
369 print $form->selectarray(
'object_status', $liststatus,
GETPOST(
'object_status',
'intcomma'), -4);
373print
'<tr><td class="left">'.$langs->trans(
"Year").
'</td><td class="left">';
374if (!in_array($year, $arrayyears)) {
375 $arrayyears[$year] = $year;
377if (!in_array($nowyear, $arrayyears)) {
378 $arrayyears[$nowyear] = $nowyear;
381print
img_picto(
'',
'calendar',
'class="pictofixedwidth"');
382print $form->selectarray(
'year', $arrayyears, $year, 0, 0, 0,
'', 0, 0, 0,
'',
'width75');
384print
'<tr><td align="center" colspan="2"><input type="submit" class="button small" name="submit" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
390print
'<div class="div-table-responsive-no-min">';
391print
'<table class="noborder centpercent">';
392print
'<tr class="liste_titre" height="24">';
393print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
394print
'<td class="right">'.$langs->trans(
"NbOfOrders").
'</td>';
395print
'<td class="right">%</td>';
396print
'<td class="right">'.$langs->trans(
"AmountTotal").
'</td>';
397print
'<td class="right">%</td>';
398print
'<td class="right">'.$langs->trans(
"AmountAverage").
'</td>';
399print
'<td class="right">%</td>';
403foreach ($data as $val) {
404 $year = $val[
'year'];
405 while (!empty($year) && $oldyear > (
int) $year + 1) {
408 print
'<tr class="oddeven" height="24">';
409 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$oldyear.
'</a></td>';
410 print
'<td class="right">0</td>';
411 print
'<td class="right"></td>';
412 print
'<td class="right">0</td>';
413 print
'<td class="right"></td>';
414 print
'<td class="right">0</td>';
415 print
'<td class="right"></td>';
420 print
'<tr class="oddeven" height="24">';
421 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$year.
'</a></td>';
422 print
'<td class="right">'.$val[
'nb'].
'</td>';
423 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>';
424 print
'<td class="right">'.price(
price2num($val[
'total'],
'MT'), 1).
'</td>';
425 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>';
426 print
'<td class="right">'.price(
price2num($val[
'avg'],
'MT'), 1).
'</td>';
427 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>';
436print
'</div><div class="fichetwothirdright">';
440print
'<table class="border centpercent"><tr class="pair nohover"><td align="center">';
459print
'</td></tr></table>';
463print
'<div class="clearboth"></div>';
if(! $sortfield) if(! $sortorder) $object
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.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Class to manage order statistics (customer and supplier)
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 '.
getMultidirTemp($object, $module='', $forobject=0)
Return the full path of the directory where a module (or an object of a module) stores its temporary ...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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).
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.