dolibarr  16.0.5
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2014-2015 Florian HENRY <florian.henry@open-concept.pro>
3  * Copyright (C) 2015-2021 Laurent Destailleur <ldestailleur@users.sourceforge.net>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
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';
30 
32 $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
33 
34 $search_opp_status = GETPOST("search_opp_status", 'alpha');
35 
36 $userid = GETPOST('userid', 'int');
37 $socid = GETPOST('socid', 'int');
38 // Security check
39 if ($user->socid > 0) {
40  $action = '';
41  $socid = $user->socid;
42 }
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)));
46 $endyear = $year;
47 
48 // Load translation files required by the page
49 $langs->loadLangs(array('companies', 'projects'));
50 
51 // Security check
52 if (!$user->rights->projet->lire) {
54 }
55 
56 
57 /*
58  * View
59  */
60 
61 $form = new Form($db);
62 $formproject = new FormProjets($db);
63 
64 $includeuserlist = array();
65 
66 
67 llxHeader('', $langs->trans('Projects'));
68 
69 $title = $langs->trans("ProjectsStatistics");
70 $dir = $conf->project->dir_output.'/temp';
71 
72 print load_fiche_titre($title, '', 'project');
73 
74 dol_mkdir($dir);
75 
76 
77 $stats_project = new ProjectStats($db);
78 if (!empty($userid) && $userid != -1) {
79  $stats_project->userid = $userid;
80 }
81 if (!empty($socid) && $socid != -1) {
82  $stats_project->socid = $socid;
83 }
84 if (!empty($year)) {
85  $stats_project->year = $year;
86 }
87 
88 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
89  if ($search_opp_status) {
90  $stats_project->opp_status = $search_opp_status;
91  }
92 }
93 
94 
95 // Build graphic number of object
96 // $data = array(array('Lib',val1,val2,val3),...)
97 $data = $stats_project->getNbByMonthWithPrevYear($endyear, $startyear);
98 //var_dump($data);
99 
100 $filenamenb = $conf->project->dir_output."/stats/projectnbprevyear-".$year.".png";
101 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=projectstats&amp;file=projectnbprevyear-'.$year.'.png';
102 
103 $px1 = new DolGraph();
104 $mesg = $px1->isGraphKo();
105 if (!$mesg) {
106  $px1->SetData($data);
107  $i = $startyear; $legend = array();
108  while ($i <= $endyear) {
109  $legend[] = $i;
110  $i++;
111  }
112  $px1->SetLegend($legend);
113  $px1->SetMaxValue($px1->GetCeilMaxValue());
114  $px1->SetWidth($WIDTH);
115  $px1->SetHeight($HEIGHT);
116  $px1->SetYLabel($langs->trans("ProjectNbProject"));
117  $px1->SetShading(3);
118  $px1->SetHorizTickIncrement(1);
119  $px1->mode = 'depth';
120  $px1->SetTitle($langs->trans("ProjectNbProjectByMonth"));
121 
122  $px1->draw($filenamenb, $fileurlnb);
123 }
124 
125 
126 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
127  // Build graphic amount of object
128  $data = $stats_project->getAmountByMonthWithPrevYear($endyear, $startyear);
129  //var_dump($data);
130  // $data = array(array('Lib',val1,val2,val3),...)
131 
132  $filenamenb = $conf->project->dir_output."/stats/projectamountprevyear-".$year.".png";
133  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=projectstats&amp;file=projectamountprevyear-'.$year.'.png';
134 
135  $px2 = new DolGraph();
136  $mesg = $px2->isGraphKo();
137  if (!$mesg) {
138  $i = $startyear; $legend = array();
139  while ($i <= $endyear) {
140  $legend[] = $i;
141  $i++;
142  }
143 
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"));
151  $px2->SetShading(3);
152  $px2->SetHorizTickIncrement(1);
153  $px2->SetType(array('bars', 'bars'));
154  $px2->mode = 'depth';
155  $px2->SetTitle($langs->trans("ProjectOppAmountOfProjectsByMonth"));
156 
157  $px2->draw($filenamenb, $fileurlnb);
158  }
159 }
160 
161 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
162  // Build graphic with transformation rate
163  $data = $stats_project->getWeightedAmountByMonthWithPrevYear($endyear, $startyear, 0, 0);
164  //var_dump($data);
165  // $data = array(array('Lib',val1,val2,val3),...)
166 
167  $filenamenb = $conf->project->dir_output."/stats/projecttransrateprevyear-".$year.".png";
168  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=projectstats&amp;file=projecttransrateprevyear-'.$year.'.png';
169 
170  $px3 = new DolGraph();
171  $mesg = $px3->isGraphKo();
172  if (!$mesg) {
173  $px3->SetData($data);
174  $i = $startyear;
175  $legend = array();
176  while ($i <= $endyear) {
177  $legend[] = $i;
178  $i++;
179  }
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"));
186  $px3->SetShading(3);
187  $px3->SetHorizTickIncrement(1);
188  $px3->mode = 'depth';
189  $px3->SetTitle($langs->trans("ProjectWeightedOppAmountOfProjectsByMonth"));
190 
191  $px3->draw($filenamenb, $fileurlnb);
192  }
193 }
194 
195 
196 // Show array
197 $stats_project->year = 0;
198 $data_all_year = $stats_project->getAllByYear();
199 
200 if (!empty($year)) {
201  $stats_project->year = $year;
202 }
203 $arrayyears = array();
204 foreach ($data_all_year as $val) {
205  $arrayyears[$val['year']] = $val['year'];
206 }
207 if (!count($arrayyears)) {
208  $arrayyears[$nowyear] = $nowyear;
209 }
210 
211 
212 $h = 0;
213 $head = array();
214 $head[$h][0] = DOL_URL_ROOT.'/projet/stats/index.php';
215 $head[$h][1] = $langs->trans("ByMonthYear");
216 $head[$h][2] = 'byyear';
217 $h++;
218 
219 complete_head_from_modules($conf, $langs, null, $head, $h, 'project_stats');
220 
221 print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1, '');
222 
223 
224 print '<div class="fichecenter"><div class="fichethirdleft">';
225 
226 print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
227 print '<input type="hidden" name="token" value="'.newToken().'">';
228 
229 print '<table class="noborder centpercent">';
230 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
231 // Company
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', '');
235 print '</td></tr>';
236 // Opportunity status
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);
240  print '</td></tr>';
241 }
242 
243 // User
244 /*print '<tr><td>'.$langs->trans("ProjectCommercial").'</td><td>';
245 print $form->select_dolusers($userid, 'userid', 1, array(),0,$includeuserlist);
246 print '</td></tr>';*/
247 // Year
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;
251 }
252 if (!in_array($nowyear, $arrayyears)) {
253  $arrayyears[$nowyear] = $nowyear;
254 }
255 arsort($arrayyears);
256 print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
257 print '</td></tr>';
258 print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
259 print '</table>';
260 
261 print '</form>';
262 
263 print '<br><br>';
264 
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>';
274 }
275 print '</tr>';
276 
277 $oldyear = 0;
278 foreach ($data_all_year as $val) {
279  $year = $val['year'];
280  while ($year && $oldyear > $year + 1) { // If we have empty year
281  $oldyear--;
282 
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>';
290  }
291  print '</tr>';
292  }
293 
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>';
301  }
302  print '</tr>';
303  $oldyear = $year;
304 }
305 
306 print '</table>';
307 print '</div>';
308 
309 print '</div><div class="fichetwothirdright">';
310 
311 $stringtoshow = '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
312 if ($mesg) {
313  print $mesg;
314 } else {
315  $stringtoshow .= $px1->show();
316  $stringtoshow .= "<br>\n";
317  if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
318  //$stringtoshow .= $px->show();
319  //$stringtoshow .= "<br>\n";
320  $stringtoshow .= $px2->show();
321  $stringtoshow .= "<br>\n";
322  $stringtoshow .= $px3->show();
323  }
324 }
325 $stringtoshow .= '</td></tr></table>';
326 
327 print $stringtoshow;
328 
329 print '</div></div>';
330 
331 print '<div style="clear:both"></div>';
332 
333 print dol_get_fiche_end();
334 
335 // End of page
336 llxFooter();
337 $db->close();
DolGraph\getDefaultGraphSizeForStats
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Definition: dolgraph.class.php:1539
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
ProjectStats
Class to manage statistics on projects.
Definition: projectstats.class.php:25
DolGraph
Class to build graphs.
Definition: dolgraph.class.php:40
FormProjets
Class to manage building of HTML components.
Definition: html.formprojet.class.php:30
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
complete_head_from_modules
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
Definition: functions.lib.php:9038
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
llxFooter
llxFooter()
Footer empty.
Definition: index.php:71
llxHeader
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.
Definition: index.php:63
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
price
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.
Definition: functions.lib.php:5541
accessforbidden
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 ...
Definition: security.lib.php:933
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6603