26 require
'../../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/compta/deplacement/class/deplacementstats.class.php';
31 $langs->loadLangs(array(
'trips',
'companies'));
36 $userid =
GETPOST(
'userid',
'int');
if ($userid < 0) $userid = 0;
37 $socid =
GETPOST(
'socid',
'int');
if ($socid < 0) $socid = 0;
44 $socid = $user->socid;
46 if ($user->socid) $socid = $user->socid;
50 $childids = $user->getAllChildIds();
51 $childids[] = $user->id;
54 if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous) && !in_array($userid, $childids))
61 $nowyear = strftime(
"%Y",
dol_now());
64 $startyear = $year - 1;
74 $form =
new Form($db);
79 $title = $langs->trans(
"TripsAndExpensesStatistics");
80 $dir = $conf->deplacement->dir_temp;
86 $useridtofilter = $userid;
87 if (empty($useridtofilter))
89 $useridtofilter = $childids;
90 if (!empty($user->rights->deplacement->readall) || !empty($user->rights->deplacement->lire_tous)) $useridtofilter = 0;
99 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
102 $filenamenb = $dir.
"/tripsexpensesnbinyear-".$year.
".png";
103 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=tripsexpensesstats&file=tripsexpensesnbinyear-'.$year.
'.png';
106 $mesg = $px1->isGraphKo();
109 $px1->SetData($data);
110 $i = $startyear; $legend = array();
111 while ($i <= $endyear)
116 $px1->SetLegend($legend);
117 $px1->SetMaxValue($px1->GetCeilMaxValue());
118 $px1->SetWidth($WIDTH);
119 $px1->SetHeight($HEIGHT);
120 $px1->SetYLabel($langs->trans(
"Number"));
122 $px1->SetHorizTickIncrement(1);
123 $px1->mode =
'depth';
124 $px1->SetTitle($langs->trans(
"NumberByMonth"));
126 $px1->draw($filenamenb, $fileurlnb);
130 $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
134 $filenameamount = $dir.
"/tripsexpensesamountinyear-".$year.
".png";
135 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=tripsexpensesstats&file=tripsexpensesamountinyear-'.$year.
'.png';
138 $mesg = $px2->isGraphKo();
141 $px2->SetData($data);
142 $i = $startyear; $legend = array();
143 while ($i <= $endyear)
148 $px2->SetLegend($legend);
149 $px2->SetMaxValue($px2->GetCeilMaxValue());
150 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
151 $px2->SetWidth($WIDTH);
152 $px2->SetHeight($HEIGHT);
153 $px2->SetYLabel($langs->trans(
"Amount"));
155 $px2->SetHorizTickIncrement(1);
156 $px2->mode =
'depth';
157 $px2->SetTitle($langs->trans(
"AmountTotal"));
159 $px2->draw($filenameamount, $fileurlamount);
163 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
165 if (!$user->rights->societe->client->voir || $user->socid)
167 $filename_avg = $dir.
'/ordersaverage-'.$user->id.
'-'.$year.
'.png';
168 if ($mode ==
'customer') $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
169 if ($mode ==
'supplier') $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
171 $filename_avg = $dir.
'/ordersaverage-'.$year.
'.png';
172 if ($mode ==
'customer') $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.
'.png';
173 if ($mode ==
'supplier') $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.
'.png';
177 $mesg = $px3->isGraphKo();
180 $px3->SetData($data);
181 $i = $startyear; $legend = array();
182 while ($i <= $endyear)
187 $px3->SetLegend($legend);
188 $px3->SetYLabel($langs->trans(
"AmountAverage"));
189 $px3->SetMaxValue($px3->GetCeilMaxValue());
190 $px3->SetMinValue($px3->GetFloorMinValue());
191 $px3->SetWidth($WIDTH);
192 $px3->SetHeight($HEIGHT);
194 $px3->SetHorizTickIncrement(1);
195 $px3->mode =
'depth';
196 $px3->SetTitle($langs->trans(
"AmountAverage"));
198 $px3->draw($filename_avg, $fileurl_avg);
203 $data = $stats->getAllByYear();
204 $arrayyears = array();
205 foreach ($data as $val) {
206 $arrayyears[$val[
'year']] = $val[
'year'];
208 if (!count($arrayyears)) $arrayyears[$nowyear] = $nowyear;
213 $head[$h][0] = DOL_URL_ROOT.
'/compta/deplacement/stats/index.php';
214 $head[$h][1] = $langs->trans(
"ByMonthYear");
215 $head[$h][2] =
'byyear';
223 print '<div class="fichecenter"><div class="fichethirdleft">';
227 print
'<form name="stats" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
228 print
'<input type="hidden" name="token" value="'.newToken().
'">';
229 print
'<input type="hidden" name="mode" value="'.$mode.
'">';
231 print
'<table class="border centpercent">';
232 print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
234 print
'<tr><td>'.$langs->trans(
"ThirdParty").
'</td><td>';
236 print $form->select_company($socid,
'socid', $filter, 1, 1, 0, array(), 0,
'',
'style="width: 95%"');
239 print
'<tr><td>'.$langs->trans(
"User").
'</td><td>';
241 if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) $include =
'hierarchy';
242 print $form->select_dolusers($userid,
'userid', 1,
'', 0, $include,
'', 0, 0, 0,
'', 0,
'',
'maxwidth300');
245 print
'<tr><td>'.$langs->trans(
"Year").
'</td><td>';
246 if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year;
248 print $form->selectarray(
'year', $arrayyears, $year, 0);
250 print
'<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
255 print
'<div class="div-table-responsive-no-min">';
256 print
'<table class="border centpercent">';
257 print
'<tr height="24">';
258 print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
259 print
'<td class="center">'.$langs->trans(
"Number").
'</td>';
260 print
'<td class="center">'.$langs->trans(
"AmountTotal").
'</td>';
261 print
'<td class="center">'.$langs->trans(
"AmountAverage").
'</td>';
265 foreach ($data as $val)
267 $year = $val[
'year'];
268 while ($year && $oldyear > $year + 1)
271 print
'<tr height="24">';
272 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.
'&mode='.$mode.
'">'.$oldyear.
'</a></td>';
273 print
'<td class="right">0</td>';
274 print
'<td class="right">0</td>';
275 print
'<td class="right">0</td>';
278 print
'<tr height="24">';
279 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&mode='.$mode.
'">'.$year.
'</a></td>';
280 print
'<td class="right">'.$val[
'nb'].
'</td>';
281 print
'<td class="right">'.price(
price2num($val[
'total'],
'MT'), 1).
'</td>';
282 print
'<td class="right">'.price(
price2num($val[
'avg'],
'MT'), 1).
'</td>';
290 print
'</div><div class="fichetwothirdright"><div class="ficheaddleft">';
294 print
'<table class="border centpercent"><tr class="pair nohover"><td align="center">';
295 if ($mesg) { print $mesg; }
else {
302 print
'</td></tr></table>';
305 print
'</div></div></div>';
306 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 deplacements et notes de frais.
dol_now($mode= 'auto')
Return date for now.
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.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
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)