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 .
'/core/lib/functions.lib.php';
73require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
74require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
87$hookmanager->initHooks(array(
'mymodulestats',
'myobjectstats',
'globalcard'));
89$objecttype =
'myobject';
93$usercanreadstatistic = 1;
94$enablepermissioncheck =
getDolGlobalInt(
'MYMODULE_ENABLE_PERMISSION_CHECK');
95if ($enablepermissioncheck) {
96 $usercanreadstatistic = $user->hasRight($objecttype,
'read');
97 if (
getDolGlobalInt(
'MAIN_NEED_EXPORT_PERMISSION_TO_READ_STATISTICS')) {
98 $usercanreadstatistic = $user->hasRight($objecttype,
'export');
102if (!$usercanreadstatistic) {
108if ($user->socid > 0) {
110 $socid = $user->socid;
113$parameters = array();
114$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
116 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
121$startyear = $year - (!
getDolGlobalInt(
'MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10,
getDolGlobalInt(
'MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
125$langs->loadLangs(array(
'companies',
'other',
'mymodule@mymodule'));
132$form =
new Form($db);
134$title = $langs->trans(
"Statistics");
137llxHeader(
'', $title,
'',
'', 0, 0,
'',
'',
'',
'mod-order page-stats');
142$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'));
143$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'));
146$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'));
148$newcardbutton .=
dolGetButtonTitle($langs->trans(
'New'),
'',
'fa fa-plus-circle',
dol_buildpath(
'/mymodule/myobject_card.php', 1).
'?action=create&backtopage='.urlencode($_SERVER[
'PHP_SELF']),
'', $permissiontoadd);
154$massactionbutton =
'';
156$nbtotalofrecords = 0;
159print_barre_liste($title, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords,
$object->picto, 0, $newcardbutton,
'', $limit, 0, 0, 1);
166$stats =
new MyObjectStats($db, $socid, $mode, ($userid > 0 ? $userid : 0), ($categ_id > 0 ? $categ_id : 0));
170$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
173$filenamenb = $dir.
'/myobjectnbinyear-'.$user->id.
'-'.$year.
'.png';
174$fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$user->id.
'-'.$year.
'.png';
179$mesg = $px1->isGraphKo();
182 $px1->SetData($data);
185 while ($i <= $endyear) {
189 $px1->SetLegend($legend);
190 $px1->SetMaxValue($px1->GetCeilMaxValue());
191 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
192 $px1->SetWidth($WIDTH);
193 $px1->SetHeight($HEIGHT);
194 $px1->SetYLabel($langs->trans(
"Nb"));
196 $px1->SetHorizTickIncrement(1);
197 $px1->mode =
'depth';
198 $px1->SetTitle($langs->trans(
"ByMonth"));
200 $px1->draw($filenamenb, $fileurlnb);
310$data = $stats->getAllByYear();
311$arrayyears = array();
312foreach ($data as $val) {
313 if (!empty($val[
'year'])) {
314 $arrayyears[$val[
'year']] = $val[
'year'];
317if (!count($arrayyears)) {
318 $arrayyears[$nowyear] = $nowyear;
325$head[$h][0] = $_SERVER[
"PHP_SELF"].
'?mode='.$mode;
326$head[$h][1] = $langs->trans(
"ByMonthYear");
327$head[$h][2] =
'byyear';
330$type =
'myobject_stats';
336print
'<div class="fichecenter"><div class="fichethirdleft">';
340print
'<form name="stats" method="POST" action="'.dolBuildUrl($_SERVER[
"PHP_SELF"]).
'">';
341print
'<input type="hidden" name="token" value="'.newToken().
'">';
342print
'<input type="hidden" name="mode" value="'.$mode.
'">';
344print
'<table class="noborder centpercent">';
345print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
361if (array_key_exists(
'fk_user_creat',
$object->fields)) {
362 print
'<tr><td>'.$langs->trans(
"CreatedBy").
'</td><td>';
363 print img_picto(
'',
'user',
'class="pictofixedwidth"');
364 print $form->select_dolusers($userid,
'userid', 1,
null, 0,
'',
'',
'0', 0, 0,
'', 0,
'',
'widthcentpercentminusx maxwidth300');
367if (array_key_exists(
'status',
$object->fields)) {
368 print
'<tr><td>'.$langs->trans(
"Status").
'</td><td>';
369 $liststatus =
$object->fields[
'status'][
'arrayofkeyvalue'];
370 print $form->selectarray(
'object_status', $liststatus,
GETPOST(
'object_status',
'intcomma'), -4);
374print
'<tr><td class="left">'.$langs->trans(
"Year").
'</td><td class="left">';
375if (!in_array($year, $arrayyears)) {
376 $arrayyears[$year] = $year;
378if (!in_array($nowyear, $arrayyears)) {
379 $arrayyears[$nowyear] = $nowyear;
382print img_picto(
'',
'calendar',
'class="pictofixedwidth"');
383print $form->selectarray(
'year', $arrayyears, $year, 0, 0, 0,
'', 0, 0, 0,
'',
'width75');
385print
'<tr><td align="center" colspan="2"><input type="submit" class="button small" name="submit" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
391print
'<div class="div-table-responsive-no-min">';
392print
'<table class="noborder centpercent">';
393print
'<tr class="liste_titre" height="24">';
394print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
395print
'<td class="right">'.$langs->trans(
"NbOfOrders").
'</td>';
396print
'<td class="right">%</td>';
397print
'<td class="right">'.$langs->trans(
"AmountTotal").
'</td>';
398print
'<td class="right">%</td>';
399print
'<td class="right">'.$langs->trans(
"AmountAverage").
'</td>';
400print
'<td class="right">%</td>';
404foreach ($data as $val) {
405 $year = $val[
'year'];
406 while (!empty($year) && $oldyear > (
int) $year + 1) {
409 print
'<tr class="oddeven" height="24">';
410 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$oldyear.
'</a></td>';
411 print
'<td class="right">0</td>';
412 print
'<td class="right"></td>';
413 print
'<td class="right">0</td>';
414 print
'<td class="right"></td>';
415 print
'<td class="right">0</td>';
416 print
'<td class="right"></td>';
421 print
'<tr class="oddeven" height="24">';
422 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$year.
'</a></td>';
423 print
'<td class="right">'.$val[
'nb'].
'</td>';
424 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>';
425 print
'<td class="right">'.price(
price2num($val[
'total'],
'MT'), 1).
'</td>';
426 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>';
427 print
'<td class="right">'.price(
price2num($val[
'avg'],
'MT'), 1).
'</td>';
428 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>';
437print
'</div><div class="fichetwothirdright">';
441print
'<table class="border centpercent"><tr class="pair nohover"><td align="center">';
460print
'</td></tr></table>';
464print
'<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.
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 ...
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, $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_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).
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).
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.