25 require
'../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.
'/fichinter/class/fichinter.class.php';
27 require_once DOL_DOCUMENT_ROOT.
'/fichinter/class/fichinterstats.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
34 if (!$user->rights->ficheinter->lire) {
38 $userid =
GETPOST(
'userid',
'int');
39 $socid =
GETPOST(
'socid',
'int');
41 if ($user->socid > 0) {
43 $socid = $user->socid;
48 $startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
51 $object_status =
GETPOST(
'object_status',
'intcomma');
54 $langs->loadLangs(array(
'interventions',
'companies',
'other',
'suppliers'));
62 $objectstatic =
new FichInter($db);
64 $title = $langs->trans(
"InterventionStatistics");
65 $dir = $conf->ficheinter->dir_temp;
73 $stats =
new FichinterStats($db, $socid, $mode, ($userid > 0 ? $userid : 0));
74 if ($object_status !=
'' && $object_status > -1) {
75 $stats->where .=
' AND c.fk_statut IN ('.$db->sanitize($db->escape($object_status)).
')';
79 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
83 if (empty($user->rights->societe->client->voir) || $user->socid) {
84 $filenamenb = $dir.
'/interventionsnbinyear-'.$user->id.
'-'.$year.
'.png';
85 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=interventionstats&file=interventionsnbinyear-'.$user->id.
'-'.$year.
'.png';
87 $filenamenb = $dir.
'/interventionsnbinyear-'.$year.
'.png';
88 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=interventionstats&file=interventionsnbinyear-'.$year.
'.png';
92 $mesg = $px1->isGraphKo();
95 $i = $startyear; $legend = array();
96 while ($i <= $endyear) {
100 $px1->SetLegend($legend);
101 $px1->SetMaxValue($px1->GetCeilMaxValue());
102 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
103 $px1->SetWidth($WIDTH);
104 $px1->SetHeight($HEIGHT);
105 $px1->SetYLabel($langs->trans(
"NbOfIntervention"));
107 $px1->SetHorizTickIncrement(1);
108 $px1->mode =
'depth';
109 $px1->SetTitle($langs->trans(
"NumberOfInterventionsByMonth"));
111 $px1->draw($filenamenb, $fileurlnb);
115 $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
118 if (empty($user->rights->societe->client->voir) || $user->socid) {
119 $filenameamount = $dir.
'/interventionsamountinyear-'.$user->id.
'-'.$year.
'.png';
120 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=interventionstats&file=interventionsamountinyear-'.$user->id.
'-'.$year.
'.png';
122 $filenameamount = $dir.
'/interventionsamountinyear-'.$year.
'.png';
123 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=interventionstats&file=interventionsamountinyear-'.$year.
'.png';
127 $mesg = $px2->isGraphKo();
129 $px2->SetData($data);
130 $i = $startyear; $legend = array();
131 while ($i <= $endyear) {
135 $px2->SetLegend($legend);
136 $px2->SetMaxValue($px2->GetCeilMaxValue());
137 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
138 $px2->SetWidth($WIDTH);
139 $px2->SetHeight($HEIGHT);
140 $px2->SetYLabel($langs->trans(
"AmountOfinterventions"));
142 $px2->SetHorizTickIncrement(1);
143 $px2->mode =
'depth';
144 $px2->SetTitle($langs->trans(
"AmountOfinterventionsByMonthHT"));
146 $px2->draw($filenameamount, $fileurlamount);
150 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
152 if (empty($user->rights->societe->client->voir) || $user->socid) {
153 $filename_avg = $dir.
'/interventionsaverage-'.$user->id.
'-'.$year.
'.png';
154 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=interventionstats&file=interventionsaverage-'.$user->id.
'-'.$year.
'.png';
156 $filename_avg = $dir.
'/interventionsaverage-'.$year.
'.png';
157 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=interventionstats&file=interventionsaverage-'.$year.
'.png';
161 $mesg = $px3->isGraphKo();
163 $px3->SetData($data);
164 $i = $startyear; $legend = array();
165 while ($i <= $endyear) {
169 $px3->SetLegend($legend);
170 $px3->SetYLabel($langs->trans(
"AmountAverage"));
171 $px3->SetMaxValue($px3->GetCeilMaxValue());
172 $px3->SetMinValue($px3->GetFloorMinValue());
173 $px3->SetWidth($WIDTH);
174 $px3->SetHeight($HEIGHT);
176 $px3->SetHorizTickIncrement(1);
177 $px3->mode =
'depth';
178 $px3->SetTitle($langs->trans(
"AmountAverage"));
180 $px3->draw($filename_avg, $fileurl_avg);
186 $data = $stats->getAllByYear();
187 $arrayyears = array();
188 foreach ($data as $val) {
189 if (!empty($val[
'year'])) {
190 $arrayyears[$val[
'year']] = $val[
'year'];
193 if (!count($arrayyears)) {
194 $arrayyears[$nowyear] = $nowyear;
199 $head[$h][0] = DOL_URL_ROOT.
'/fichinter/stats/index.php';
200 $head[$h][1] = $langs->trans(
"ByMonthYear");
201 $head[$h][2] =
'byyear';
204 $type =
'fichinter_stats';
211 print
'<div class="fichecenter"><div class="fichethirdleft">';
215 print
'<form name="stats" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
216 print
'<input type="hidden" name="token" value="'.newToken().
'">';
217 print
'<input type="hidden" name="mode" value="'.$mode.
'">';
219 print
'<table class="noborder centpercent">';
220 print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
222 print
'<tr><td class="left">'.$langs->trans(
"ThirdParty").
'</td><td class="left">';
223 $filter =
's.client IN (1,2,3)';
224 print
img_picto(
'',
'company',
'class="pictofixedwidth"');
225 print
$form->select_company($socid,
'socid', $filter, 1, 0, 0, array(), 0,
'widthcentpercentminusx maxwidth300',
'');
228 print
'<tr><td class="left">'.$langs->trans(
"CreatedBy").
'</td><td class="left">';
229 print
img_picto(
'',
'user',
'class="pictofixedwidth"');
230 print
$form->select_dolusers($userid,
'userid', 1,
'', 0,
'',
'', 0, 0, 0,
'', 0,
'',
'widthcentpercentminusx maxwidth300');
232 print
'<tr><td class="left">'.$langs->trans(
"Status").
'</td><td class="left">';
233 $tmp = $objectstatic->LibStatut(0);
234 $liststatus = $objectstatic->statuts_short;
235 if (empty($conf->global->FICHINTER_CLASSIFY_BILLED)) {
236 unset($liststatus[2]);
238 print
$form->selectarray(
'object_status', $liststatus, $object_status, 1, 0, 0,
'', 1);
241 print
'<tr><td class="left">'.$langs->trans(
"Year").
'</td><td class="left">';
242 if (!in_array($year, $arrayyears)) {
243 $arrayyears[$year] = $year;
245 if (!in_array($nowyear, $arrayyears)) {
246 $arrayyears[$nowyear] = $nowyear;
249 print
$form->selectarray(
'year', $arrayyears, $year, 0, 0, 0,
'', 0, 0, 0,
'',
'width75');
251 print
'<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
256 print
'<div class="div-table-responsive-no-min">';
257 print
'<table class="noborder centpercent">';
258 print
'<tr class="liste_titre" height="24">';
259 print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
260 print
'<td class="right">'.$langs->trans(
"NbOfinterventions").
'</td>';
261 print
'<td class="right">%</td>';
262 print
'<td class="right">'.$langs->trans(
"AmountTotal").
'</td>';
263 print
'<td class="right">%</td>';
264 print
'<td class="right">'.$langs->trans(
"AmountAverage").
'</td>';
265 print
'<td class="right">%</td>';
269 foreach ($data as $val) {
270 $year = $val[
'year'];
271 while (!empty($year) && $oldyear > $year + 1) {
275 print
'<tr class="oddeven" height="24">';
276 print
'<td class="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$oldyear.
'</a></td>';
278 print
'<td class="right">0</td>';
279 print
'<td class="right"></td>';
280 print
'<td class="right">0</td>';
281 print
'<td class="right"></td>';
282 print
'<td class="right">0</td>';
283 print
'<td class="right"></td>';
288 print
'<tr class="oddeven" height="24">';
289 print
'<td class="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$year.
'</a></td>';
290 print
'<td class="right">'.$val[
'nb'].
'</td>';
291 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>';
292 print
'<td class="right">'.price(
price2num($val[
'total'],
'MT'), 1).
'</td>';
293 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>';
294 print
'<td class="right">'.price(
price2num($val[
'avg'],
'MT'), 1).
'</td>';
295 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>';
304 print
'</div><div class="fichetwothirdright">';
308 print
'<table class="border centpercent"><tr class="pair nohover"><td class="center">';
318 print
'</td></tr></table>';
321 print
'</div></div>';
322 print
'<div style="clear:both"></div>';
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Class to manage intervention statistics.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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)
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.