25 require
'../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/project.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/projet/class/projectstats.class.php';
31 if (!$user->rights->projet->lire)
38 $userid =
GETPOST(
'userid',
'int');
39 $socid =
GETPOST(
'socid',
'int');
44 $socid = $user->socid;
46 $nowyear = strftime(
"%Y",
dol_now());
49 $startyear = $year - 1;
53 $langs->loadLangs(array(
'companies',
'projects'));
60 $form =
new Form($db);
62 $includeuserlist = array();
67 $title = $langs->trans(
"ProjectsStatistics");
68 $dir = $conf->projet->dir_output.
'/temp';
76 if (!empty($userid) && $userid != -1) $stats_project->userid = $userid;
77 if (!empty($socid) && $socid != -1) $stats_project->socid = $socid;
78 if (!empty($year)) $stats_project->year = $year;
144 $data = $stats_project->getNbByMonthWithPrevYear($endyear, $startyear);
147 $filenamenb = $conf->project->dir_output.
"/stats/projectnbprevyear-".$year.
".png";
148 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=projectstats&file=projectnbprevyear-'.$year.
'.png';
151 $mesg = $px1->isGraphKo();
154 $px1->SetData($data);
155 $i = $startyear; $legend = array();
156 while ($i <= $endyear)
161 $px1->SetLegend($legend);
162 $px1->SetMaxValue($px1->GetCeilMaxValue());
163 $px1->SetWidth($WIDTH);
164 $px1->SetHeight($HEIGHT);
165 $px1->SetYLabel($langs->trans(
"ProjectNbProject"));
167 $px1->SetHorizTickIncrement(1);
168 $px1->mode =
'depth';
169 $px1->SetTitle($langs->trans(
"ProjectNbProjectByMonth"));
171 $px1->draw($filenamenb, $fileurlnb);
175 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES))
178 $data = $stats_project->getAmountByMonthWithPrevYear($endyear, $startyear);
182 $filenamenb = $conf->project->dir_output.
"/stats/projectamountprevyear-".$year.
".png";
183 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=projectstats&file=projectamountprevyear-'.$year.
'.png';
186 $mesg = $px2->isGraphKo();
189 $i = $startyear; $legend = array();
190 while ($i <= $endyear)
196 $px2->SetData($data);
197 $px2->SetLegend($legend);
198 $px2->SetMaxValue($px2->GetCeilMaxValue());
199 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
200 $px2->SetWidth($WIDTH);
201 $px2->SetHeight($HEIGHT);
202 $px2->SetYLabel($langs->trans(
"ProjectOppAmountOfProjectsByMonth"));
204 $px2->SetHorizTickIncrement(1);
205 $px2->SetType(array(
'bars',
'bars'));
206 $px2->mode =
'depth';
207 $px2->SetTitle($langs->trans(
"ProjectOppAmountOfProjectsByMonth"));
209 $px2->draw($filenamenb, $fileurlnb);
213 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES))
216 $data = $stats_project->getWeightedAmountByMonthWithPrevYear($endyear, $startyear, 0, 0);
220 $filenamenb = $conf->project->dir_output.
"/stats/projecttransrateprevyear-".$year.
".png";
221 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=projectstats&file=projecttransrateprevyear-'.$year.
'.png';
224 $mesg = $px3->isGraphKo();
227 $px3->SetData($data);
228 $i = $startyear; $legend = array();
229 while ($i <= $endyear)
234 $px3->SetLegend($legend);
235 $px3->SetMaxValue($px3->GetCeilMaxValue());
236 $px3->SetMinValue(min(0, $px3->GetFloorMinValue()));
237 $px3->SetWidth($WIDTH);
238 $px3->SetHeight($HEIGHT);
239 $px3->SetYLabel($langs->trans(
"ProjectWeightedOppAmountOfProjectsByMonth"));
241 $px3->SetHorizTickIncrement(1);
242 $px3->mode =
'depth';
243 $px3->SetTitle($langs->trans(
"ProjectWeightedOppAmountOfProjectsByMonth"));
245 $px3->draw($filenamenb, $fileurlnb);
251 $stats_project->year = 0;
252 $data_all_year = $stats_project->getAllByYear();
254 if (!empty($year)) $stats_project->year = $year;
255 $arrayyears = array();
256 foreach ($data_all_year as $val) {
257 $arrayyears[$val[
'year']] = $val[
'year'];
259 if (!count($arrayyears)) $arrayyears[$nowyear] = $nowyear;
264 $head[$h][0] = DOL_URL_ROOT.
'/projet/stats/index.php';
265 $head[$h][1] = $langs->trans(
"ByMonthYear");
266 $head[$h][2] =
'byyear';
274 print '<div class="fichecenter"><div class="fichethirdleft">';
276 print
'<form name="stats" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
277 print
'<input type="hidden" name="token" value="'.newToken().
'">';
279 print
'<table class="noborder centpercent">';
280 print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
282 print
'<tr><td>'.$langs->trans(
"ThirdParty").
'</td><td>';
283 print $form->select_company($socid,
'socid',
'', 1, 0, 0, array(), 0,
'',
'style="width: 95%"');
290 print
'<tr><td>'.$langs->trans(
"Year").
'</td><td>';
291 if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year;
292 if (!in_array($nowyear, $arrayyears)) $arrayyears[$nowyear] = $nowyear;
294 print $form->selectarray(
'year', $arrayyears, $year, 0);
296 print
'<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
301 print
'<div class="div-table-responsive-no-min">';
302 print
'<table class="noborder centpercent">';
303 print
'<tr class="liste_titre" height="24">';
304 print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
305 print
'<td class="right">'.$langs->trans(
"NbOfProjects").
'</td>';
306 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES))
308 print
'<td class="right">'.$langs->trans(
"OpportunityAmountShort").
'</td>';
309 print
'<td class="right">'.$langs->trans(
"OpportunityAmountAverageShort").
'</td>';
310 print
'<td class="right">'.$langs->trans(
"OpportunityAmountWeigthedShort").
'</td>';
315 foreach ($data_all_year as $val)
317 $year = $val[
'year'];
318 while ($year && $oldyear > $year + 1)
322 print
'<tr class="oddeven" height="24">';
323 print
'<td class="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$oldyear.
'</a></td>';
324 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES))
326 print
'<td class="right">0</td>';
327 print
'<td class="right">0</td>';
328 print
'<td class="right">0</td>';
330 print
'<td class="right">0</td>';
334 print
'<tr class="oddeven" height="24">';
335 print
'<td class="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$year.
'</a></td>';
336 print
'<td class="right">'.$val[
'nb'].
'</td>';
337 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES))
339 print
'<td class="right">'.($val[
'total'] ?
price(
price2num($val[
'total'],
'MT'), 1) :
'0').
'</td>';
340 print
'<td class="right">'.($val[
'avg'] ?
price(
price2num($val[
'avg'],
'MT'), 1) :
'0').
'</td>';
341 print
'<td class="right">'.($val[
'weighted'] ?
price(
price2num($val[
'weighted'],
'MT'), 1) :
'0').
'</td>';
350 print
'</div><div class="fichetwothirdright"><div class="ficheaddleft">';
352 $stringtoshow .=
'<table class="border centpercent"><tr class="pair nohover"><td class="center">';
353 if ($mesg) { print $mesg; }
else {
354 $stringtoshow .= $px1->show();
355 $stringtoshow .=
"<br>\n";
356 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES))
360 $stringtoshow .= $px2->show();
361 $stringtoshow .=
"<br>\n";
362 $stringtoshow .= $px3->show();
365 $stringtoshow .=
'</td></tr></table>';
370 print
'</div></div></div>';
371 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.
dol_now($mode= 'auto')
Return date for now.
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
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 '...
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 ...
Class to manage statistics on projects.
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.
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)