dolibarr 23.0.3
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 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/projet/class/projectstats.class.php';
33
44
45$search_opp_status = GETPOST("search_opp_status", 'alpha');
46
47$userid = GETPOSTINT('userid');
48$socid = GETPOSTINT('socid');
49// Security check
50if ($user->socid > 0) {
51 $action = '';
52 $socid = $user->socid;
53}
54$nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
55$year = GETPOSTINT('year') > 0 ? GETPOSTINT('year') : $nowyear;
56$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
57$endyear = $year;
58
59// Load translation files required by the page
60$langs->loadLangs(array('companies', 'projects'));
61
62// Security check
63if (!$user->hasRight('projet', 'lire')) {
65}
66
67
68/*
69 * View
70 */
71
72$form = new Form($db);
73$formproject = new FormProjets($db);
74
75$includeuserlist = array();
76
77llxHeader('', $langs->trans('Projects'), '', '', 0, 0, '', '', '', 'mod-project page-stats');
78
79$title = $langs->trans("ProjectsStatistics");
80$dir = $conf->project->dir_output.'/temp';
81
82print load_fiche_titre($title, '', 'project');
83
84dol_mkdir($dir);
85
86
87$stats_project = new ProjectStats($db);
88if (!empty($userid) && $userid != -1) {
89 $stats_project->userid = $userid;
90}
91if (!empty($socid) && $socid != -1) {
92 $stats_project->socid = $socid;
93}
94if (!empty($year)) {
95 $stats_project->year = $year;
96}
97
98if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
99 if ($search_opp_status) {
100 $stats_project->opp_status = $search_opp_status;
101 }
102}
103
104
105// Build graphic number of object
106// $data = array(array('Lib',val1,val2,val3),...)
107$data = $stats_project->getNbByMonthWithPrevYear($endyear, $startyear);
108//var_dump($data);
109
110$filenamenb = $conf->project->dir_output."/stats/projectnbprevyear-".$year.".png";
111$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=projectstats&amp;file=projectnbprevyear-'.$year.'.png';
112
113$px1 = new DolGraph();
114$mesg = $px1->isGraphKo();
115if (!$mesg) {
116 $px1->SetData($data);
117 $i = $startyear;
118 $legend = array();
119 while ($i <= $endyear) {
120 $legend[] = $i;
121 $i++;
122 }
123 $px1->SetLegend($legend);
124 $px1->SetMaxValue($px1->GetCeilMaxValue());
125 $px1->SetWidth($WIDTH);
126 $px1->SetHeight($HEIGHT);
127 $px1->SetYLabel($langs->trans("ProjectNbProject"));
128 $px1->SetShading(3);
129 $px1->SetHorizTickIncrement(1);
130 $px1->mode = 'depth';
131 $px1->SetTitle($langs->trans("ProjectNbProjectByMonth"));
132
133 $px1->draw($filenamenb, $fileurlnb);
134}
135
136
137$px2 = null;
138if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
139 // Build graphic amount of object
140 $data = $stats_project->getAmountByMonthWithPrevYear($endyear, $startyear);
141 //var_dump($data);
142 // $data = array(array('Lib',val1,val2,val3),...)
143
144 $filenamenb = $conf->project->dir_output."/stats/projectamountprevyear-".$year.".png";
145 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=projectstats&amp;file=projectamountprevyear-'.$year.'.png';
146
147 $px2 = new DolGraph();
148 $mesg = $px2->isGraphKo();
149 if (!$mesg) {
150 $i = $startyear;
151 $legend = array();
152 while ($i <= $endyear) {
153 $legend[] = $i;
154 $i++;
155 }
156
157 $px2->SetData($data);
158 $px2->SetLegend($legend);
159 $px2->SetMaxValue($px2->GetCeilMaxValue());
160 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
161 $px2->SetWidth($WIDTH);
162 $px2->SetHeight($HEIGHT);
163 $px2->SetYLabel($langs->trans("ProjectOppAmountOfProjectsByMonth"));
164 $px2->SetShading(3);
165 $px2->SetHorizTickIncrement(1);
166 $px2->SetType(array('bars', 'bars'));
167 $px2->mode = 'depth';
168 $px2->SetTitle($langs->trans("ProjectOppAmountOfProjectsByMonth"));
169
170 $px2->draw($filenamenb, $fileurlnb);
171 }
172}
173
174$px3 = null;
175if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
176 // Build graphic with transformation rate
177 $data = $stats_project->getWeightedAmountByMonthWithPrevYear($endyear, $startyear, 0, 0);
178 //var_dump($data);
179 // $data = array(array('Lib',val1,val2,val3),...)
180
181 $filenamenb = $conf->project->dir_output."/stats/projecttransrateprevyear-".$year.".png";
182 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=projectstats&amp;file=projecttransrateprevyear-'.$year.'.png';
183
184 $px3 = new DolGraph();
185 $mesg = $px3->isGraphKo();
186 if (!$mesg) {
187 $px3->SetData($data);
188 $i = $startyear;
189 $legend = array();
190 while ($i <= $endyear) {
191 $legend[] = $i;
192 $i++;
193 }
194 $px3->SetLegend($legend);
195 $px3->SetMaxValue($px3->GetCeilMaxValue());
196 $px3->SetMinValue(min(0, $px3->GetFloorMinValue()));
197 $px3->SetWidth($WIDTH);
198 $px3->SetHeight($HEIGHT);
199 $px3->SetYLabel($langs->trans("ProjectWeightedOppAmountOfProjectsByMonth"));
200 $px3->SetShading(3);
201 $px3->SetHorizTickIncrement(1);
202 $px3->mode = 'depth';
203 $px3->SetTitle($langs->trans("ProjectWeightedOppAmountOfProjectsByMonth"));
204
205 $px3->draw($filenamenb, $fileurlnb);
206 }
207}
208
209
210// Show array
211$stats_project->year = 0;
212$data_all_year = $stats_project->getAllByYear();
213
214if (!empty($year)) {
215 $stats_project->year = $year;
216}
217$arrayyears = array();
218foreach ($data_all_year as $val) {
219 $arrayyears[$val['year']] = $val['year'];
220}
221if (!count($arrayyears)) {
222 $arrayyears[$nowyear] = $nowyear;
223}
224
225
226$h = 0;
227$head = array();
228$head[$h][0] = DOL_URL_ROOT.'/projet/stats/index.php';
229$head[$h][1] = $langs->trans("ByMonthYear");
230$head[$h][2] = 'byyear';
231$h++;
232
233complete_head_from_modules($conf, $langs, null, $head, $h, 'project_stats');
234
235print dol_get_fiche_head($head, 'byyear', '', -1, '');
236
237
238print '<div class="fichecenter"><div class="fichethirdleft">';
239
240print '<form name="stats" method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
241print '<input type="hidden" name="token" value="'.newToken().'">';
242
243print '<table class="noborder centpercent">';
244print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
245// Company
246print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
247print img_picto('', 'company', 'class="pictofixedwidth"');
248print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
249print '</td></tr>';
250// Opportunity status
251if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
252 print '<tr><td>'.$langs->trans("OpportunityStatusShort").'</td><td>';
253 print $formproject->selectOpportunityStatus('search_opp_status', $search_opp_status, 1, 0, 1, 0, 'maxwidth300', 1, 1);
254 print '</td></tr>';
255}
256
257// User
258/*print '<tr><td>'.$langs->trans("ProjectCommercial").'</td><td>';
259print $form->select_dolusers($userid, 'userid', 1, array(),0,$includeuserlist);
260print '</td></tr>';*/
261// Year
262print '<tr><td>'.$langs->trans("Year").' <span class="opacitymedium">('.$langs->trans("DateCreation").')</span></td><td>';
263if (!in_array($year, $arrayyears)) {
264 $arrayyears[$year] = $year;
265}
266if (!in_array($nowyear, $arrayyears)) {
267 $arrayyears[$nowyear] = $nowyear;
268}
269arsort($arrayyears);
270print img_picto('', 'calendar', 'class="pictofixedwidth"');
271print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
272print '</td></tr>';
273print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
274print '</table>';
275
276print '</form>';
277
278print '<br><br>';
279
280print '<div class="div-table-responsive-no-min">';
281print '<table class="noborder centpercent">';
282print '<tr class="liste_titre" height="24">';
283print '<td class="center">'.$langs->trans("Year").'</td>';
284print '<td class="right">'.$langs->trans("NbOfProjects").'</td>';
285if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
286 print '<td class="right">'.$langs->trans("OpportunityAmountShort").'</td>';
287 print '<td class="right">'.$langs->trans("OpportunityAmountAverageShort").'</td>';
288 print '<td class="right">'.$langs->trans("OpportunityAmountWeigthedShort").'</td>';
289}
290print '</tr>';
291
292$oldyear = 0;
293foreach ($data_all_year as $val) {
294 $year = $val['year'];
295 while ($year && $oldyear > (int) $year + 1) { // If we have empty year
296 $oldyear--;
297
298 print '<tr class="oddeven" height="24">';
299 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$oldyear.'</a></td>';
300 print '<td class="right">0</td>';
301 if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
302 print '<td class="right amount nowraponall">0</td>';
303 print '<td class="right amount nowraponall">0</td>';
304 print '<td class="right amount nowraponall">0</td>';
305 }
306 print '</tr>';
307 }
308
309 print '<tr class="oddeven" height="24">';
310 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$year.'</a></td>';
311 print '<td class="right">'.$val['nb'].'</td>';
312 if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
313 print '<td class="right amount nowraponall">'.($val['total'] ? price(price2num($val['total'], 'MT'), 1) : '0').'</td>';
314 print '<td class="right amount nowraponall">'.($val['avg'] ? price(price2num($val['avg'], 'MT'), 1) : '0').'</td>';
315 print '<td class="right amount nowraponall">'.(isset($val['weighted']) ? price(price2num($val['weighted'], 'MT'), 1) : '0').'</td>';
316 }
317 print '</tr>';
318 $oldyear = $year;
319}
320
321print '</table>';
322print '</div>';
323
324print '</div><div class="fichetwothirdright">';
325
326$stringtoshow = '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
327if ($mesg) {
328 print $mesg;
329} else {
330 $stringtoshow .= $px1->show();
331 $stringtoshow .= "<br>\n";
332 if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES') && $px2 !== null && $px3 !== null) {
333 //$stringtoshow .= $px->show();
334 //$stringtoshow .= "<br>\n";
335 $stringtoshow .= $px2->show();
336 $stringtoshow .= "<br>\n";
337 $stringtoshow .= $px3->show();
338 }
339}
340$stringtoshow .= '</td></tr></table>';
341
342print $stringtoshow;
343
344print '</div></div>';
345
346print '<div class="clearboth"></div>';
347
348print dol_get_fiche_end();
349
350// End of page
351llxFooter();
352$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
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.
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.