27 require
'../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereportstats.class.php';
32 $langs->loadLangs(array(
'trips',
'companies'));
38 $object_status =
GETPOST(
'object_status',
'intcomma');
40 $userid =
GETPOST(
'userid',
'int');
41 $socid =
GETPOST(
'socid',
'int');
if ($socid < 0) $socid = 0;
48 $socid = $user->socid;
50 if ($user->socid) $socid = $user->socid;
53 $nowyear = strftime(
"%Y",
dol_now());
56 $startyear = $year - 1;
65 $form =
new Form($db);
68 $title = $langs->trans(
"TripsAndExpensesStatistics");
69 $dir = $conf->expensereport->dir_temp;
78 if ($object_status !=
'' && $object_status >= -1) $stats->where .=
' AND e.fk_statut IN ('.$db->sanitize($db->escape($object_status)).
')';
83 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
86 $filenamenb = $dir.
"/tripsexpensesnbinyear-".$year.
".png";
87 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=tripsexpensesstats&file=tripsexpensesnbinyear-'.$year.
'.png';
90 $mesg = $px1->isGraphKo();
94 $i = $startyear; $legend = array();
95 while ($i <= $endyear)
100 $px1->SetLegend($legend);
101 $px1->SetMaxValue($px1->GetCeilMaxValue());
102 $px1->SetWidth($WIDTH);
103 $px1->SetHeight($HEIGHT);
104 $px1->SetYLabel($langs->trans(
"Number"));
106 $px1->SetHorizTickIncrement(1);
107 $px1->mode =
'depth';
108 $px1->SetTitle($langs->trans(
"NumberByMonth"));
110 $px1->draw($filenamenb, $fileurlnb);
114 $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
118 $filenameamount = $dir.
"/tripsexpensesamountinyear-".$year.
".png";
119 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=tripsexpensesstats&file=tripsexpensesamountinyear-'.$year.
'.png';
122 $mesg = $px2->isGraphKo();
125 $px2->SetData($data);
126 $i = $startyear; $legend = array();
127 while ($i <= $endyear)
132 $px2->SetLegend($legend);
133 $px2->SetMaxValue($px2->GetCeilMaxValue());
134 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
135 $px2->SetWidth($WIDTH);
136 $px2->SetHeight($HEIGHT);
137 $px2->SetYLabel($langs->trans(
"Amount"));
139 $px2->SetHorizTickIncrement(1);
140 $px2->mode =
'depth';
141 $px2->SetTitle($langs->trans(
"AmountTotal"));
143 $px2->draw($filenameamount, $fileurlamount);
147 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
149 if (!$user->rights->societe->client->voir || $user->socid)
151 $filename_avg = $dir.
'/ordersaverage-'.$user->id.
'-'.$year.
'.png';
152 if ($mode ==
'customer') $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
153 if ($mode ==
'supplier') $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
155 $filename_avg = $dir.
'/ordersaverage-'.$year.
'.png';
156 if ($mode ==
'customer') $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.
'.png';
157 if ($mode ==
'supplier') $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.
'.png';
161 $mesg = $px3->isGraphKo();
164 $px3->SetData($data);
165 $i = $startyear; $legend = array();
166 while ($i <= $endyear)
171 $px3->SetLegend($legend);
172 $px3->SetYLabel($langs->trans(
"AmountAverage"));
173 $px3->SetMaxValue($px3->GetCeilMaxValue());
174 $px3->SetMinValue($px3->GetFloorMinValue());
175 $px3->SetWidth($WIDTH);
176 $px3->SetHeight($HEIGHT);
178 $px3->SetHorizTickIncrement(1);
179 $px3->mode =
'depth';
180 $px3->SetTitle($langs->trans(
"AmountAverage"));
182 $px3->draw($filename_avg, $fileurl_avg);
187 $data = $stats->getAllByYear();
188 $arrayyears = array();
189 foreach ($data as $val) {
190 $arrayyears[$val[
'year']] = $val[
'year'];
192 if (!count($arrayyears)) $arrayyears[$nowyear] = $nowyear;
197 $head[$h][0] = DOL_URL_ROOT.
'/expensereport/stats/index.php';
198 $head[$h][1] = $langs->trans(
"ByMonthYear");
199 $head[$h][2] =
'byyear';
207 print '<div class="fichecenter"><div class="fichethirdleft">';
211 print
'<form name="stats" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
212 print
'<input type="hidden" name="token" value="'.newToken().
'">';
213 print
'<input type="hidden" name="mode" value="'.$mode.
'">';
215 print
'<table class="noborder centpercent">';
216 print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
224 print
'<tr><td>'.$langs->trans(
"User").
'</td><td>';
226 if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) $include =
'hierarchy';
227 print $form->select_dolusers($userid,
'userid', 1,
'', 0, $include,
'', 0, 0, 0,
'', 0,
'',
'maxwidth300');
230 print
'<tr><td class="left">'.$langs->trans(
"Status").
'</td><td class="left">';
231 $liststatus = $tmpexpensereport->statuts;
232 print $form->selectarray(
'object_status', $liststatus,
GETPOST(
'object_status',
'intcomma'), -4, 0, 0,
'', 1);
236 print $form->textwithpicto($langs->trans(
"Year"), $langs->trans(
"DateValidation"));
238 if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year;
240 print $form->selectarray(
'year', $arrayyears, $year, 0);
242 print
'<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
247 print
'<div class="div-table-responsive-no-min">';
248 print
'<table class="noborder centpercent">';
249 print
'<tr class="liste_titre" height="24">';
250 print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
251 print
'<td class="right">'.$langs->trans(
"Number").
'</td>';
252 print
'<td class="right">'.$langs->trans(
"AmountTotal").
'</td>';
253 print
'<td class="right">'.$langs->trans(
"AmountAverage").
'</td>';
257 foreach ($data as $val)
259 $year = $val[
'year'];
260 while ($year && $oldyear > $year + 1)
264 print
'<tr class="oddeven" height="24">';
265 print
'<td class="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.
'&mode='.$mode.
'">'.$oldyear.
'</a></td>';
266 print
'<td class="right">0</td>';
267 print
'<td class="right">0</td>';
268 print
'<td class="right">0</td>';
273 print
'<tr class="oddeven" height="24">';
274 print
'<td class="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&mode='.$mode.
'">'.$year.
'</a></td>';
275 print
'<td class="right">'.$val[
'nb'].
'</td>';
276 print
'<td class="right">'.price(
price2num($val[
'total'],
'MT'), 1).
'</td>';
277 print
'<td class="right">'.price(
price2num($val[
'avg'],
'MT'), 1).
'</td>';
285 print
'</div><div class="fichetwothirdright"><div class="ficheaddleft">';
289 print
'<table class="border centpercent"><tr class="pair nohover"><td class="center">';
290 if ($mesg) { print $mesg; }
else {
297 print
'</td></tr></table>';
300 print
'</div></div></div>';
301 print
'<div style="clear:both"></div>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Classe permettant la gestion des stats des expensereports et notes de frais.
dol_now($mode= 'auto')
Return date for now.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
Class to manage Trips and Expenses.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
static getDefaultGraphSizeForStats($direction, $defaultsize= '')
getDefaultGraphSizeForStats
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode= 'add')
Complete or removed entries into a head array (used to build tabs).
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)