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) {
47 if ($user->socid > 0) {
49 $socid = $user->socid;
52 $socid = $user->socid;
56 $nowyear = strftime(
"%Y",
dol_now());
58 $startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
70 $title = $langs->trans(
"TripsAndExpensesStatistics");
71 $dir = $conf->expensereport->dir_temp;
80 if ($object_status !=
'' && $object_status >= -1) {
81 $stats->where .=
' AND e.fk_statut IN ('.$db->sanitize($db->escape($object_status)).
')';
87 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
90 $filenamenb = $dir.
"/tripsexpensesnbinyear-".$year.
".png";
91 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=tripsexpensesstats&file=tripsexpensesnbinyear-'.$year.
'.png';
94 $mesg = $px1->isGraphKo();
97 $i = $startyear; $legend = array();
98 while ($i <= $endyear) {
102 $px1->SetLegend($legend);
103 $px1->SetMaxValue($px1->GetCeilMaxValue());
104 $px1->SetWidth($WIDTH);
105 $px1->SetHeight($HEIGHT);
106 $px1->SetYLabel($langs->trans(
"Number"));
108 $px1->SetHorizTickIncrement(1);
109 $px1->mode =
'depth';
110 $px1->SetTitle($langs->trans(
"NumberByMonth"));
112 $px1->draw($filenamenb, $fileurlnb);
116 $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
120 $filenameamount = $dir.
"/tripsexpensesamountinyear-".$year.
".png";
121 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=tripsexpensesstats&file=tripsexpensesamountinyear-'.$year.
'.png';
124 $mesg = $px2->isGraphKo();
126 $px2->SetData($data);
127 $i = $startyear; $legend = array();
128 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 (empty($user->rights->societe->client->voir) || $user->socid) {
150 $filename_avg = $dir.
'/ordersaverage-'.$user->id.
'-'.$year.
'.png';
151 if ($mode ==
'customer') {
152 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
154 if ($mode ==
'supplier') {
155 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
158 $filename_avg = $dir.
'/ordersaverage-'.$year.
'.png';
159 if ($mode ==
'customer') {
160 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.
'.png';
162 if ($mode ==
'supplier') {
163 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.
'.png';
168 $mesg = $px3->isGraphKo();
170 $px3->SetData($data);
171 $i = $startyear; $legend = array();
172 while ($i <= $endyear) {
176 $px3->SetLegend($legend);
177 $px3->SetYLabel($langs->trans(
"AmountAverage"));
178 $px3->SetMaxValue($px3->GetCeilMaxValue());
179 $px3->SetMinValue($px3->GetFloorMinValue());
180 $px3->SetWidth($WIDTH);
181 $px3->SetHeight($HEIGHT);
183 $px3->SetHorizTickIncrement(1);
184 $px3->mode =
'depth';
185 $px3->SetTitle($langs->trans(
"AmountAverage"));
187 $px3->draw($filename_avg, $fileurl_avg);
192 $data = $stats->getAllByYear();
193 $arrayyears = array();
194 foreach ($data as $val) {
195 $arrayyears[$val[
'year']] = $val[
'year'];
197 if (!count($arrayyears)) {
198 $arrayyears[$nowyear] = $nowyear;
204 $head[$h][0] = DOL_URL_ROOT.
'/expensereport/stats/index.php';
205 $head[$h][1] = $langs->trans(
"ByMonthYear");
206 $head[$h][2] =
'byyear';
214 print
'<div class="fichecenter"><div class="fichethirdleft">';
218 print
'<form name="stats" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
219 print
'<input type="hidden" name="token" value="'.newToken().
'">';
220 print
'<input type="hidden" name="mode" value="'.$mode.
'">';
222 print
'<table class="noborder centpercent">';
223 print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
231 print
'<tr><td>'.$langs->trans(
"User").
'</td><td>';
233 if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) {
234 $include =
'hierarchy';
236 print
img_picto(
'',
'user',
'class="pictofixedwidth"');
237 print
$form->select_dolusers($userid,
'userid', 1,
'', 0, $include,
'', 0, 0, 0,
'', 0,
'',
'widthcentpercentminusx maxwidth300');
240 print
'<tr><td class="left">'.$langs->trans(
"Status").
'</td><td class="left">';
241 $liststatus = $tmpexpensereport->statuts;
242 print
$form->selectarray(
'object_status', $liststatus,
GETPOST(
'object_status',
'intcomma'), -4, 0, 0,
'', 1);
246 print
$form->textwithpicto($langs->trans(
"Year"), $langs->trans(
"DateValidation"));
248 if (!in_array($year, $arrayyears)) {
249 $arrayyears[$year] = $year;
252 print
$form->selectarray(
'year', $arrayyears, $year, 0, 0, 0,
'', 0, 0, 0,
'',
'width75');
254 print
'<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
259 print
'<div class="div-table-responsive-no-min">';
260 print
'<table class="noborder centpercent">';
261 print
'<tr class="liste_titre" height="24">';
262 print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
263 print
'<td class="right">'.$langs->trans(
"Number").
'</td>';
264 print
'<td class="right">'.$langs->trans(
"AmountTotal").
'</td>';
265 print
'<td class="right">'.$langs->trans(
"AmountAverage").
'</td>';
269 foreach ($data as $val) {
270 $year = $val[
'year'];
271 while ($year && $oldyear > $year + 1) {
274 print
'<tr class="oddeven" height="24">';
275 print
'<td class="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.
'&mode='.$mode.
'">'.$oldyear.
'</a></td>';
276 print
'<td class="right">0</td>';
277 print
'<td class="right amount nowraponall">0</td>';
278 print
'<td class="right amount nowraponall">0</td>';
283 print
'<tr class="oddeven" height="24">';
284 print
'<td class="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&mode='.$mode.
'">'.$year.
'</a></td>';
285 print
'<td class="right">'.$val[
'nb'].
'</td>';
286 print
'<td class="right amount nowraponall">'.price(
price2num($val[
'total'],
'MT'), 1).
'</td>';
287 print
'<td class="right amount nowraponall">'.price(
price2num($val[
'avg'],
'MT'), 1).
'</td>';
295 print
'</div><div class="fichetwothirdright">';
299 print
'<table class="border centpercent"><tr class="pair nohover"><td class="center">';
309 print
'</td></tr></table>';
312 print
'</div></div>';
313 print
'<div style="clear:both"></div>';