dolibarr  17.0.4
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 // Load Dolibarr environment
26 require '../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/projet/class/projectstats.class.php';
31 
33 $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
34 
35 $search_opp_status = GETPOST("search_opp_status", 'alpha');
36 
37 $userid = GETPOST('userid', 'int');
38 $socid = GETPOST('socid', 'int');
39 // Security check
40 if ($user->socid > 0) {
41  $action = '';
42  $socid = $user->socid;
43 }
44 $nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
45 $year = GETPOST('year', 'int') > 0 ? GETPOST('year', 'int') : $nowyear;
46 $startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
47 $endyear = $year;
48 
49 // Load translation files required by the page
50 $langs->loadLangs(array('companies', 'projects'));
51 
52 // Security check
53 if (!$user->rights->projet->lire) {
55 }
56 
57 
58 /*
59  * View
60  */
61 
62 $form = new Form($db);
63 $formproject = new FormProjets($db);
64 
65 $includeuserlist = array();
66 
67 
68 llxHeader('', $langs->trans('Projects'));
69 
70 $title = $langs->trans("ProjectsStatistics");
71 $dir = $conf->project->dir_output.'/temp';
72 
73 print load_fiche_titre($title, '', 'project');
74 
75 dol_mkdir($dir);
76 
77 
78 $stats_project = new ProjectStats($db);
79 if (!empty($userid) && $userid != -1) {
80  $stats_project->userid = $userid;
81 }
82 if (!empty($socid) && $socid != -1) {
83  $stats_project->socid = $socid;
84 }
85 if (!empty($year)) {
86  $stats_project->year = $year;
87 }
88 
89 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
90  if ($search_opp_status) {
91  $stats_project->opp_status = $search_opp_status;
92  }
93 }
94 
95 
96 // Build graphic number of object
97 // $data = array(array('Lib',val1,val2,val3),...)
98 $data = $stats_project->getNbByMonthWithPrevYear($endyear, $startyear);
99 //var_dump($data);
100 
101 $filenamenb = $conf->project->dir_output."/stats/projectnbprevyear-".$year.".png";
102 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=projectstats&amp;file=projectnbprevyear-'.$year.'.png';
103 
104 $px1 = new DolGraph();
105 $mesg = $px1->isGraphKo();
106 if (!$mesg) {
107  $px1->SetData($data);
108  $i = $startyear; $legend = array();
109  while ($i <= $endyear) {
110  $legend[] = $i;
111  $i++;
112  }
113  $px1->SetLegend($legend);
114  $px1->SetMaxValue($px1->GetCeilMaxValue());
115  $px1->SetWidth($WIDTH);
116  $px1->SetHeight($HEIGHT);
117  $px1->SetYLabel($langs->trans("ProjectNbProject"));
118  $px1->SetShading(3);
119  $px1->SetHorizTickIncrement(1);
120  $px1->mode = 'depth';
121  $px1->SetTitle($langs->trans("ProjectNbProjectByMonth"));
122 
123  $px1->draw($filenamenb, $fileurlnb);
124 }
125 
126 
127 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
128  // Build graphic amount of object
129  $data = $stats_project->getAmountByMonthWithPrevYear($endyear, $startyear);
130  //var_dump($data);
131  // $data = array(array('Lib',val1,val2,val3),...)
132 
133  $filenamenb = $conf->project->dir_output."/stats/projectamountprevyear-".$year.".png";
134  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=projectstats&amp;file=projectamountprevyear-'.$year.'.png';
135 
136  $px2 = new DolGraph();
137  $mesg = $px2->isGraphKo();
138  if (!$mesg) {
139  $i = $startyear; $legend = array();
140  while ($i <= $endyear) {
141  $legend[] = $i;
142  $i++;
143  }
144 
145  $px2->SetData($data);
146  $px2->SetLegend($legend);
147  $px2->SetMaxValue($px2->GetCeilMaxValue());
148  $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
149  $px2->SetWidth($WIDTH);
150  $px2->SetHeight($HEIGHT);
151  $px2->SetYLabel($langs->trans("ProjectOppAmountOfProjectsByMonth"));
152  $px2->SetShading(3);
153  $px2->SetHorizTickIncrement(1);
154  $px2->SetType(array('bars', 'bars'));
155  $px2->mode = 'depth';
156  $px2->SetTitle($langs->trans("ProjectOppAmountOfProjectsByMonth"));
157 
158  $px2->draw($filenamenb, $fileurlnb);
159  }
160 }
161 
162 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
163  // Build graphic with transformation rate
164  $data = $stats_project->getWeightedAmountByMonthWithPrevYear($endyear, $startyear, 0, 0);
165  //var_dump($data);
166  // $data = array(array('Lib',val1,val2,val3),...)
167 
168  $filenamenb = $conf->project->dir_output."/stats/projecttransrateprevyear-".$year.".png";
169  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=projectstats&amp;file=projecttransrateprevyear-'.$year.'.png';
170 
171  $px3 = new DolGraph();
172  $mesg = $px3->isGraphKo();
173  if (!$mesg) {
174  $px3->SetData($data);
175  $i = $startyear;
176  $legend = array();
177  while ($i <= $endyear) {
178  $legend[] = $i;
179  $i++;
180  }
181  $px3->SetLegend($legend);
182  $px3->SetMaxValue($px3->GetCeilMaxValue());
183  $px3->SetMinValue(min(0, $px3->GetFloorMinValue()));
184  $px3->SetWidth($WIDTH);
185  $px3->SetHeight($HEIGHT);
186  $px3->SetYLabel($langs->trans("ProjectWeightedOppAmountOfProjectsByMonth"));
187  $px3->SetShading(3);
188  $px3->SetHorizTickIncrement(1);
189  $px3->mode = 'depth';
190  $px3->SetTitle($langs->trans("ProjectWeightedOppAmountOfProjectsByMonth"));
191 
192  $px3->draw($filenamenb, $fileurlnb);
193  }
194 }
195 
196 
197 // Show array
198 $stats_project->year = 0;
199 $data_all_year = $stats_project->getAllByYear();
200 
201 if (!empty($year)) {
202  $stats_project->year = $year;
203 }
204 $arrayyears = array();
205 foreach ($data_all_year as $val) {
206  $arrayyears[$val['year']] = $val['year'];
207 }
208 if (!count($arrayyears)) {
209  $arrayyears[$nowyear] = $nowyear;
210 }
211 
212 
213 $h = 0;
214 $head = array();
215 $head[$h][0] = DOL_URL_ROOT.'/projet/stats/index.php';
216 $head[$h][1] = $langs->trans("ByMonthYear");
217 $head[$h][2] = 'byyear';
218 $h++;
219 
220 complete_head_from_modules($conf, $langs, null, $head, $h, 'project_stats');
221 
222 print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1, '');
223 
224 
225 print '<div class="fichecenter"><div class="fichethirdleft">';
226 
227 print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
228 print '<input type="hidden" name="token" value="'.newToken().'">';
229 
230 print '<table class="noborder centpercent">';
231 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
232 // Company
233 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
234 print img_picto('', 'company', 'class="pictofixedwidth"');
235 print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
236 print '</td></tr>';
237 // Opportunity status
238 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
239  print '<tr><td>'.$langs->trans("OpportunityStatusShort").'</td><td>';
240  print $formproject->selectOpportunityStatus('search_opp_status', $search_opp_status, 1, 0, 1, 0, 'maxwidth300', 1, 1);
241  print '</td></tr>';
242 }
243 
244 // User
245 /*print '<tr><td>'.$langs->trans("ProjectCommercial").'</td><td>';
246 print $form->select_dolusers($userid, 'userid', 1, array(),0,$includeuserlist);
247 print '</td></tr>';*/
248 // Year
249 print '<tr><td>'.$langs->trans("Year").' <span class="opacitymedium">('.$langs->trans("DateCreation").')</span></td><td>';
250 if (!in_array($year, $arrayyears)) {
251  $arrayyears[$year] = $year;
252 }
253 if (!in_array($nowyear, $arrayyears)) {
254  $arrayyears[$nowyear] = $nowyear;
255 }
256 arsort($arrayyears);
257 print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
258 print '</td></tr>';
259 print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
260 print '</table>';
261 
262 print '</form>';
263 
264 print '<br><br>';
265 
266 print '<div class="div-table-responsive-no-min">';
267 print '<table class="noborder centpercent">';
268 print '<tr class="liste_titre" height="24">';
269 print '<td class="center">'.$langs->trans("Year").'</td>';
270 print '<td class="right">'.$langs->trans("NbOfProjects").'</td>';
271 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
272  print '<td class="right">'.$langs->trans("OpportunityAmountShort").'</td>';
273  print '<td class="right">'.$langs->trans("OpportunityAmountAverageShort").'</td>';
274  print '<td class="right">'.$langs->trans("OpportunityAmountWeigthedShort").'</td>';
275 }
276 print '</tr>';
277 
278 $oldyear = 0;
279 foreach ($data_all_year as $val) {
280  $year = $val['year'];
281  while ($year && $oldyear > $year + 1) { // If we have empty year
282  $oldyear--;
283 
284  print '<tr class="oddeven" height="24">';
285  print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$oldyear.'</a></td>';
286  print '<td class="right">0</td>';
287  if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
288  print '<td class="right amount nowraponall">0</td>';
289  print '<td class="right amount nowraponall">0</td>';
290  print '<td class="right amount nowraponall">0</td>';
291  }
292  print '</tr>';
293  }
294 
295  print '<tr class="oddeven" height="24">';
296  print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$year.'</a></td>';
297  print '<td class="right">'.$val['nb'].'</td>';
298  if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
299  print '<td class="right amount nowraponall">'.($val['total'] ? price(price2num($val['total'], 'MT'), 1) : '0').'</td>';
300  print '<td class="right amount nowraponall">'.($val['avg'] ? price(price2num($val['avg'], 'MT'), 1) : '0').'</td>';
301  print '<td class="right amount nowraponall">'.(isset($val['weighted']) ? price(price2num($val['weighted'], 'MT'), 1) : '0').'</td>';
302  }
303  print '</tr>';
304  $oldyear = $year;
305 }
306 
307 print '</table>';
308 print '</div>';
309 
310 print '</div><div class="fichetwothirdright">';
311 
312 $stringtoshow = '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
313 if ($mesg) {
314  print $mesg;
315 } else {
316  $stringtoshow .= $px1->show();
317  $stringtoshow .= "<br>\n";
318  if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
319  //$stringtoshow .= $px->show();
320  //$stringtoshow .= "<br>\n";
321  $stringtoshow .= $px2->show();
322  $stringtoshow .= "<br>\n";
323  $stringtoshow .= $px3->show();
324  }
325 }
326 $stringtoshow .= '</td></tr></table>';
327 
328 print $stringtoshow;
329 
330 print '</div></div>';
331 
332 print '<div style="clear:both"></div>';
333 
334 print dol_get_fiche_end();
335 
336 // End of page
337 llxFooter();
338 $db->close();
Class to build graphs.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Class to manage generation of HTML components Only common components must be here.
Class to manage building of HTML components.
Class to manage statistics on projects.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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.
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.
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)
llxFooter()
Footer empty.
Definition: index.php:71
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
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.