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) {
39 $socid =
GETPOST(
'socid',
'int');
if ($socid < 0) {
45 if ($user->socid > 0) {
47 $socid = $user->socid;
50 $socid = $user->socid;
55 $childids = $user->getAllChildIds();
56 $childids[] = $user->id;
58 if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous) && !in_array($userid, $childids)) {
64 $nowyear = strftime(
"%Y",
dol_now());
66 $startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
81 $title = $langs->trans(
"TripsAndExpensesStatistics");
82 $dir = $conf->deplacement->dir_temp;
88 $useridtofilter = $userid;
89 if (empty($useridtofilter)) {
90 $useridtofilter = $childids;
91 if (!empty($user->rights->deplacement->readall) || !empty($user->rights->deplacement->lire_tous)) {
102 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
105 $filenamenb = $dir.
"/tripsexpensesnbinyear-".$year.
".png";
106 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=tripsexpensesstats&file=tripsexpensesnbinyear-'.$year.
'.png';
109 $mesg = $px1->isGraphKo();
111 $px1->SetData($data);
114 while ($i <= $endyear) {
118 $px1->SetLegend($legend);
119 $px1->SetMaxValue($px1->GetCeilMaxValue());
120 $px1->SetWidth($WIDTH);
121 $px1->SetHeight($HEIGHT);
122 $px1->SetYLabel($langs->trans(
"Number"));
124 $px1->SetHorizTickIncrement(1);
125 $px1->mode =
'depth';
126 $px1->SetTitle($langs->trans(
"NumberByMonth"));
128 $px1->draw($filenamenb, $fileurlnb);
132 $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
136 $filenameamount = $dir.
"/tripsexpensesamountinyear-".$year.
".png";
137 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=tripsexpensesstats&file=tripsexpensesamountinyear-'.$year.
'.png';
140 $mesg = $px2->isGraphKo();
142 $px2->SetData($data);
145 while ($i <= $endyear) {
149 $px2->SetLegend($legend);
150 $px2->SetMaxValue($px2->GetCeilMaxValue());
151 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
152 $px2->SetWidth($WIDTH);
153 $px2->SetHeight($HEIGHT);
154 $px2->SetYLabel($langs->trans(
"Amount"));
156 $px2->SetHorizTickIncrement(1);
157 $px2->mode =
'depth';
158 $px2->SetTitle($langs->trans(
"AmountTotal"));
160 $px2->draw($filenameamount, $fileurlamount);
164 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
166 if (empty($user->rights->societe->client->voir) || $user->socid) {
167 $filename_avg = $dir.
'/ordersaverage-'.$user->id.
'-'.$year.
'.png';
168 if ($mode ==
'customer') {
169 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
171 if ($mode ==
'supplier') {
172 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
175 $filename_avg = $dir.
'/ordersaverage-'.$year.
'.png';
176 if ($mode ==
'customer') {
177 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.
'.png';
179 if ($mode ==
'supplier') {
180 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.
'.png';
185 $mesg = $px3->isGraphKo();
187 $px3->SetData($data);
190 while ($i <= $endyear) {
194 $px3->SetLegend($legend);
195 $px3->SetYLabel($langs->trans(
"AmountAverage"));
196 $px3->SetMaxValue($px3->GetCeilMaxValue());
197 $px3->SetMinValue($px3->GetFloorMinValue());
198 $px3->SetWidth($WIDTH);
199 $px3->SetHeight($HEIGHT);
201 $px3->SetHorizTickIncrement(1);
202 $px3->mode =
'depth';
203 $px3->SetTitle($langs->trans(
"AmountAverage"));
205 $px3->draw($filename_avg, $fileurl_avg);
210 $data = $stats->getAllByYear();
211 $arrayyears = array();
212 foreach ($data as $val) {
213 $arrayyears[$val[
'year']] = $val[
'year'];
215 if (!count($arrayyears)) {
216 $arrayyears[$nowyear] = $nowyear;
222 $head[$h][0] = DOL_URL_ROOT.
'/compta/deplacement/stats/index.php';
223 $head[$h][1] = $langs->trans(
"ByMonthYear");
224 $head[$h][2] =
'byyear';
232 print
'<div class="fichecenter"><div class="fichethirdleft">';
236 print
'<form name="stats" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
237 print
'<input type="hidden" name="token" value="'.newToken().
'">';
238 print
'<input type="hidden" name="mode" value="'.$mode.
'">';
240 print
'<table class="border centpercent">';
241 print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
243 print
'<tr><td>'.$langs->trans(
"ThirdParty").
'</td><td>';
245 print
img_picto(
'',
'company',
'class="pictofixedwidth"');
246 print
$form->select_company($socid,
'socid', $filter, 1, 1, 0, array(), 0,
'widthcentpercentminusx maxwidth300',
'');
249 print
'<tr><td>'.$langs->trans(
"User").
'</td><td>';
251 if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) {
252 $include =
'hierarchy';
254 print
img_picto(
'',
'user',
'class="pictofixedwidth"');
255 print
$form->select_dolusers($userid,
'userid', 1,
'', 0, $include,
'', 0, 0, 0,
'', 0,
'',
'widthcentpercentminusx maxwidth300');
258 print
'<tr><td>'.$langs->trans(
"Year").
'</td><td>';
259 if (!in_array($year, $arrayyears)) {
260 $arrayyears[$year] = $year;
263 print
$form->selectarray(
'year', $arrayyears, $year, 0, 0, 0,
'', 0, 0, 0,
'',
'width75');
265 print
'<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
270 print
'<div class="div-table-responsive-no-min">';
271 print
'<table class="border centpercent">';
273 print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
274 print
'<td class="center">'.$langs->trans(
"Number").
'</td>';
275 print
'<td class="center">'.$langs->trans(
"AmountTotal").
'</td>';
276 print
'<td class="center">'.$langs->trans(
"AmountAverage").
'</td>';
280 foreach ($data as $val) {
281 $year = $val[
'year'];
282 while ($year && $oldyear > $year + 1) {
285 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.
'&mode='.$mode.
'">'.$oldyear.
'</a></td>';
286 print
'<td class="right">0</td>';
287 print
'<td class="right">0</td>';
288 print
'<td class="right">0</td>';
294 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&mode='.$mode.
'">'.$year.
'</a></td>';
295 print
'<td class="right">'.$val[
'nb'].
'</td>';
296 print
'<td class="right">'.price(
price2num($val[
'total'],
'MT'), 1).
'</td>';
297 print
'<td class="right">'.price(
price2num($val[
'avg'],
'MT'), 1).
'</td>';
305 print
'</div><div class="fichetwothirdright">';
309 print
'<table class="border centpercent"><tr class="pair nohover"><td align="center">';
319 print
'</td></tr></table>';
322 print
'</div></div>';
323 print
'<div style="clear:both"></div>';