25 require
'../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/project.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/projet/class/projectstats.class.php';
34 $search_opp_status =
GETPOST(
"search_opp_status",
'alpha');
36 $userid =
GETPOST(
'userid',
'int');
37 $socid =
GETPOST(
'socid',
'int');
39 if ($user->socid > 0) {
41 $socid = $user->socid;
43 $nowyear = strftime(
"%Y",
dol_now());
44 $year =
GETPOST(
'year',
'int') > 0 ?
GETPOST(
'year',
'int') : $nowyear;
45 $startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
49 $langs->loadLangs(array(
'companies',
'projects'));
52 if (!$user->rights->projet->lire) {
64 $includeuserlist = array();
69 $title = $langs->trans(
"ProjectsStatistics");
70 $dir = $conf->project->dir_output.
'/temp';
78 if (!empty($userid) && $userid != -1) {
79 $stats_project->userid = $userid;
81 if (!empty($socid) && $socid != -1) {
82 $stats_project->socid = $socid;
85 $stats_project->year = $year;
88 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
89 if ($search_opp_status) {
90 $stats_project->opp_status = $search_opp_status;
97 $data = $stats_project->getNbByMonthWithPrevYear($endyear, $startyear);
100 $filenamenb = $conf->project->dir_output.
"/stats/projectnbprevyear-".$year.
".png";
101 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=projectstats&file=projectnbprevyear-'.$year.
'.png';
104 $mesg = $px1->isGraphKo();
106 $px1->SetData($data);
107 $i = $startyear; $legend = array();
108 while ($i <= $endyear) {
112 $px1->SetLegend($legend);
113 $px1->SetMaxValue($px1->GetCeilMaxValue());
114 $px1->SetWidth($WIDTH);
115 $px1->SetHeight($HEIGHT);
116 $px1->SetYLabel($langs->trans(
"ProjectNbProject"));
118 $px1->SetHorizTickIncrement(1);
119 $px1->mode =
'depth';
120 $px1->SetTitle($langs->trans(
"ProjectNbProjectByMonth"));
122 $px1->draw($filenamenb, $fileurlnb);
126 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
128 $data = $stats_project->getAmountByMonthWithPrevYear($endyear, $startyear);
132 $filenamenb = $conf->project->dir_output.
"/stats/projectamountprevyear-".$year.
".png";
133 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=projectstats&file=projectamountprevyear-'.$year.
'.png';
136 $mesg = $px2->isGraphKo();
138 $i = $startyear; $legend = array();
139 while ($i <= $endyear) {
144 $px2->SetData($data);
145 $px2->SetLegend($legend);
146 $px2->SetMaxValue($px2->GetCeilMaxValue());
147 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
148 $px2->SetWidth($WIDTH);
149 $px2->SetHeight($HEIGHT);
150 $px2->SetYLabel($langs->trans(
"ProjectOppAmountOfProjectsByMonth"));
152 $px2->SetHorizTickIncrement(1);
153 $px2->SetType(array(
'bars',
'bars'));
154 $px2->mode =
'depth';
155 $px2->SetTitle($langs->trans(
"ProjectOppAmountOfProjectsByMonth"));
157 $px2->draw($filenamenb, $fileurlnb);
161 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
163 $data = $stats_project->getWeightedAmountByMonthWithPrevYear($endyear, $startyear, 0, 0);
167 $filenamenb = $conf->project->dir_output.
"/stats/projecttransrateprevyear-".$year.
".png";
168 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=projectstats&file=projecttransrateprevyear-'.$year.
'.png';
171 $mesg = $px3->isGraphKo();
173 $px3->SetData($data);
176 while ($i <= $endyear) {
180 $px3->SetLegend($legend);
181 $px3->SetMaxValue($px3->GetCeilMaxValue());
182 $px3->SetMinValue(min(0, $px3->GetFloorMinValue()));
183 $px3->SetWidth($WIDTH);
184 $px3->SetHeight($HEIGHT);
185 $px3->SetYLabel($langs->trans(
"ProjectWeightedOppAmountOfProjectsByMonth"));
187 $px3->SetHorizTickIncrement(1);
188 $px3->mode =
'depth';
189 $px3->SetTitle($langs->trans(
"ProjectWeightedOppAmountOfProjectsByMonth"));
191 $px3->draw($filenamenb, $fileurlnb);
197 $stats_project->year = 0;
198 $data_all_year = $stats_project->getAllByYear();
201 $stats_project->year = $year;
203 $arrayyears = array();
204 foreach ($data_all_year as $val) {
205 $arrayyears[$val[
'year']] = $val[
'year'];
207 if (!count($arrayyears)) {
208 $arrayyears[$nowyear] = $nowyear;
214 $head[$h][0] = DOL_URL_ROOT.
'/projet/stats/index.php';
215 $head[$h][1] = $langs->trans(
"ByMonthYear");
216 $head[$h][2] =
'byyear';
224 print
'<div class="fichecenter"><div class="fichethirdleft">';
226 print
'<form name="stats" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
227 print
'<input type="hidden" name="token" value="'.newToken().
'">';
229 print
'<table class="noborder centpercent">';
230 print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
232 print
'<tr><td>'.$langs->trans(
"ThirdParty").
'</td><td>';
233 print
img_picto(
'',
'company',
'class="pictofixedwidth"');
234 print
$form->select_company($socid,
'socid',
'', 1, 0, 0, array(), 0,
'widthcentpercentminusx maxwidth300',
'');
237 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
238 print
'<tr><td>'.$langs->trans(
"OpportunityStatusShort").
'</td><td>';
239 print $formproject->selectOpportunityStatus(
'search_opp_status', $search_opp_status, 1, 0, 1, 0,
'maxwidth300', 1, 1);
248 print
'<tr><td>'.$langs->trans(
"Year").
' <span class="opacitymedium">('.$langs->trans(
"DateCreation").
')</span></td><td>';
249 if (!in_array($year, $arrayyears)) {
250 $arrayyears[$year] = $year;
252 if (!in_array($nowyear, $arrayyears)) {
253 $arrayyears[$nowyear] = $nowyear;
256 print
$form->selectarray(
'year', $arrayyears, $year, 0, 0, 0,
'', 0, 0, 0,
'',
'width75');
258 print
'<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
265 print
'<div class="div-table-responsive-no-min">';
266 print
'<table class="noborder centpercent">';
267 print
'<tr class="liste_titre" height="24">';
268 print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
269 print
'<td class="right">'.$langs->trans(
"NbOfProjects").
'</td>';
270 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
271 print
'<td class="right">'.$langs->trans(
"OpportunityAmountShort").
'</td>';
272 print
'<td class="right">'.$langs->trans(
"OpportunityAmountAverageShort").
'</td>';
273 print
'<td class="right">'.$langs->trans(
"OpportunityAmountWeigthedShort").
'</td>';
278 foreach ($data_all_year as $val) {
279 $year = $val[
'year'];
280 while ($year && $oldyear > $year + 1) {
283 print
'<tr class="oddeven" height="24">';
284 print
'<td class="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$oldyear.
'</a></td>';
285 print
'<td class="right">0</td>';
286 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
287 print
'<td class="right amount nowraponall">0</td>';
288 print
'<td class="right amount nowraponall">0</td>';
289 print
'<td class="right amount nowraponall">0</td>';
294 print
'<tr class="oddeven" height="24">';
295 print
'<td class="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$year.
'</a></td>';
296 print
'<td class="right">'.$val[
'nb'].
'</td>';
297 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
298 print
'<td class="right amount nowraponall">'.($val[
'total'] ?
price(
price2num($val[
'total'],
'MT'), 1) :
'0').
'</td>';
299 print
'<td class="right amount nowraponall">'.($val[
'avg'] ?
price(
price2num($val[
'avg'],
'MT'), 1) :
'0').
'</td>';
300 print
'<td class="right amount nowraponall">'.(isset($val[
'weighted']) ?
price(
price2num($val[
'weighted'],
'MT'), 1) :
'0').
'</td>';
309 print
'</div><div class="fichetwothirdright">';
311 $stringtoshow =
'<table class="border centpercent"><tr class="pair nohover"><td class="center">';
315 $stringtoshow .= $px1->show();
316 $stringtoshow .=
"<br>\n";
317 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
320 $stringtoshow .= $px2->show();
321 $stringtoshow .=
"<br>\n";
322 $stringtoshow .= $px3->show();
325 $stringtoshow .=
'</td></tr></table>';
329 print
'</div></div>';
331 print
'<div style="clear:both"></div>';