dolibarr 24.0.0-beta
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-2026 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';
36require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
37require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/projet/class/projectstats.class.php';
40
43
44$mode = GETPOST('mode', 'alpha');
45
46$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'projectlist';
47
48$search_project_user = GETPOSTINT('search_project_user');
49$search_opp_status = GETPOST("search_opp_status", 'alpha');
50$search_usage_event_organization = GETPOST('search_usage_event_organization', 'intcomma');
51$search_usage_opportunity = GETPOST('search_usage_opportunity', 'intcomma');
52
53$userid = GETPOSTINT('userid');
54$socid = GETPOSTINT('socid');
55// Security check
56if ($user->socid > 0) {
57 $action = '';
58 $socid = $user->socid;
59}
60$nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
61$year = GETPOSTINT('year') > 0 ? GETPOSTINT('year') : $nowyear;
62$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
63$endyear = $year;
64
65// Load translation files required by the page
66$langs->loadLangs(array('companies', 'projects'));
67
68// Security check
69if (!$user->hasRight('projet', 'lire')) {
71}
72
73
74/*
75 * View
76 */
77
78$form = new Form($db);
79$formproject = new FormProjets($db);
80
81$includeuserlist = array();
82
83$help_url = "EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
84$title = $langs->trans("LeadsOrProjects");
85if (!getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
86 $title = $langs->trans("Projects");
87}
88if (getDolGlobalInt('PROJECT_USE_OPPORTUNITIES') == 2) { // 2 = leads only
89 $title = $langs->trans("Leads");
90}
91
92llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-project page-stats');
93
94$dir = $conf->project->dir_output.'/temp';
95
96$page = 0;
97$sortfield = '';
98$sortorder = '';
99$massactionbutton = '';
100$num = 0;
101$nbtotalofrecords = $langs->trans("Statistics");
102$param = '';
103$limit = 0;
104
105$url = DOL_URL_ROOT.'/projet/card.php?action=create';
106if (!empty($socid)) {
107 $url .= '&socid='.$socid;
108}
109if ($search_usage_event_organization == 1) {
110 $url .= '&usage_organize_event=1';
111 if (((int) $search_usage_opportunity) < 1) {
112 $url .= '&usage_opportunity=0';
113 }
114}
115
116$newcardbutton = '';
117$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/projet/list.php?mode=common'.preg_replace('/(&|\?)*(mode|groupby)=[^&]+/', '', $param), '', ($mode == 'common' ? 2 : 1), array('morecss' => 'reposition'));
118$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', DOL_URL_ROOT.'/projet/list.php?mode=kanban'.preg_replace('/(&|\?)*(mode|groupby)=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss' => 'reposition'));
119if ($contextpage == 'lead') {
120 $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanbanGroupBy'), '', 'fa fa-grip-vertical imgforviewmode', DOL_URL_ROOT.'/projet/list.php?mode=kanbangroupby&groupby=p.fk_opp_status'.preg_replace('/(&|\?)*(mode|groupby)=[^&]+/', '', $param), '', ($mode == 'kanbangroupby' ? 2 : 1), array('morecss' => 'reposition'));
121}
122$newcardbutton .= dolGetButtonTitle($langs->trans('Statistics'), '', 'fa fa-chart-bar imgforviewmode', DOL_URL_ROOT.'/projet/stats/index.php?mode=statistics'.preg_replace('/(&|\?)*(mode|groupby)=[^&]+/', '', $param), '', 2, array('morecss' => 'reposition'));
123$newcardbutton .= dolGetButtonTitleSeparator();
124$newcardbutton .= dolGetButtonTitle($langs->trans('NewProject'), '', 'fa fa-plus-circle', $url, '', $user->hasRight('projet', 'creer'));
125
126// Show description of content
127$htmltooltip = '';
128if ($search_project_user == $user->id) {
129 $htmltooltip .= $langs->trans("MyProjectsDesc");
130} else {
131 if ($user->hasRight('projet', 'all', 'lire') && !$socid) {
132 $htmltooltip .= $langs->trans("ProjectsDesc");
133 } else {
134 $htmltooltip .= $langs->trans("ProjectsPublicDesc");
135 }
136}
137
138print_barre_liste($form->textwithpicto($title, $htmltooltip), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'project', 0, $newcardbutton, '', $limit, 0, 0, 1);
139
140
141dol_mkdir($dir);
142
143
144$stats_project = new ProjectStats($db);
145if (!empty($userid) && $userid != -1) {
146 $stats_project->userid = $userid;
147}
148if (!empty($socid) && $socid != -1) {
149 $stats_project->socid = $socid;
150}
151if (!empty($year)) {
152 $stats_project->year = $year;
153}
154
155if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
156 if ($search_opp_status) {
157 $stats_project->opp_status = $search_opp_status;
158 }
159}
160
161
162// Build graphic number of object
163// $data = array(array('Lib',val1,val2,val3),...)
164$data = $stats_project->getNbByMonthWithPrevYear($endyear, $startyear);
165//var_dump($data);
166
167$filenamenb = $conf->project->dir_output."/stats/projectnbprevyear-".$year.".png";
168$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=projectstats&amp;file=projectnbprevyear-'.$year.'.png';
169
170$px1 = new DolGraph();
171$mesg = $px1->isGraphKo();
172if (!$mesg) {
173 $px1->SetData($data);
174 $i = $startyear;
175 $legend = array();
176 while ($i <= $endyear) {
177 $legend[] = $i;
178 $i++;
179 }
180 $px1->SetLegend($legend);
181 $px1->SetMaxValue($px1->GetCeilMaxValue());
182 $px1->SetWidth($WIDTH);
183 $px1->SetHeight($HEIGHT);
184 $px1->SetYLabel($langs->trans("ProjectNbProject"));
185 $px1->SetShading(3);
186 $px1->SetHorizTickIncrement(1);
187 $px1->mode = 'depth';
188 $px1->SetTitle($langs->trans("ProjectNbProjectByMonth"));
189
190 $px1->draw($filenamenb, $fileurlnb);
191}
192
193
194$px2 = null;
195if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
196 // Build graphic amount of object
197 $data = $stats_project->getAmountByMonthWithPrevYear($endyear, $startyear);
198 //var_dump($data);
199 // $data = array(array('Lib',val1,val2,val3),...)
200
201 $filenamenb = $conf->project->dir_output."/stats/projectamountprevyear-".$year.".png";
202 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=projectstats&amp;file=projectamountprevyear-'.$year.'.png';
203
204 $px2 = new DolGraph();
205 $mesg = $px2->isGraphKo();
206 if (!$mesg) {
207 $i = $startyear;
208 $legend = array();
209 while ($i <= $endyear) {
210 $legend[] = $i;
211 $i++;
212 }
213
214 $px2->SetData($data);
215 $px2->SetLegend($legend);
216 $px2->SetMaxValue($px2->GetCeilMaxValue());
217 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
218 $px2->SetWidth($WIDTH);
219 $px2->SetHeight($HEIGHT);
220 $px2->SetYLabel($langs->trans("ProjectOppAmountOfProjectsByMonth"));
221 $px2->SetShading(3);
222 $px2->SetHorizTickIncrement(1);
223 $px2->SetType(array('bars', 'bars'));
224 $px2->mode = 'depth';
225 $px2->SetTitle($langs->trans("ProjectOppAmountOfProjectsByMonth"));
226
227 $px2->draw($filenamenb, $fileurlnb);
228 }
229}
230
231$px3 = null;
232if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
233 // Build graphic with transformation rate
234 $data = $stats_project->getWeightedAmountByMonthWithPrevYear($endyear, $startyear, 0, 0);
235 //var_dump($data);
236 // $data = array(array('Lib',val1,val2,val3),...)
237
238 $filenamenb = $conf->project->dir_output."/stats/projecttransrateprevyear-".$year.".png";
239 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=projectstats&amp;file=projecttransrateprevyear-'.$year.'.png';
240
241 $px3 = new DolGraph();
242 $mesg = $px3->isGraphKo();
243 if (!$mesg) {
244 $px3->SetData($data);
245 $i = $startyear;
246 $legend = array();
247 while ($i <= $endyear) {
248 $legend[] = $i;
249 $i++;
250 }
251 $px3->SetLegend($legend);
252 $px3->SetMaxValue($px3->GetCeilMaxValue());
253 $px3->SetMinValue(min(0, $px3->GetFloorMinValue()));
254 $px3->SetWidth($WIDTH);
255 $px3->SetHeight($HEIGHT);
256 $px3->SetYLabel($langs->trans("ProjectWeightedOppAmountOfProjectsByMonth"));
257 $px3->SetShading(3);
258 $px3->SetHorizTickIncrement(1);
259 $px3->mode = 'depth';
260 $px3->SetTitle($langs->trans("ProjectWeightedOppAmountOfProjectsByMonth"));
261
262 $px3->draw($filenamenb, $fileurlnb);
263 }
264}
265
266
267// Show array
268$stats_project->year = 0;
269$data_all_year = $stats_project->getAllByYear();
270
271if (!empty($year)) {
272 $stats_project->year = $year;
273}
274$arrayyears = array();
275foreach ($data_all_year as $val) {
276 $arrayyears[$val['year']] = $val['year'];
277}
278if (!count($arrayyears)) {
279 $arrayyears[$nowyear] = $nowyear;
280}
281
282
283$h = 0;
284$head = array();
285$head[$h][0] = DOL_URL_ROOT.'/projet/stats/index.php';
286$head[$h][1] = $langs->trans("ByMonthYear");
287$head[$h][2] = 'byyear';
288$h++;
289
290complete_head_from_modules($conf, $langs, null, $head, $h, 'project_stats');
291
292print dol_get_fiche_head($head, 'byyear', '', -1, '');
293
294
295print '<div class="fichecenter"><div class="fichethirdleft">';
296
297print '<form name="stats" method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
298print '<input type="hidden" name="token" value="'.newToken().'">';
299
300print '<table class="noborder centpercent">';
301print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
302// Company
303print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
304print img_picto('', 'company', 'class="pictofixedwidth"');
305print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
306print '</td></tr>';
307// Opportunity status
308if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
309 print '<tr><td>'.$langs->trans("OpportunityStatusShort").'</td><td>';
310 print $formproject->selectOpportunityStatus('search_opp_status', $search_opp_status, 1, 0, 1, 0, 'maxwidth300', 1, 1);
311 print '</td></tr>';
312}
313
314// User
315/*print '<tr><td>'.$langs->trans("ProjectCommercial").'</td><td>';
316print $form->select_dolusers($userid, 'userid', 1, array(),0,$includeuserlist);
317print '</td></tr>';*/
318// Year
319print '<tr><td>'.$langs->trans("Year").' <span class="opacitymedium">('.$langs->trans("DateCreation").')</span></td><td>';
320if (!in_array($year, $arrayyears)) {
321 $arrayyears[$year] = $year;
322}
323if (!in_array($nowyear, $arrayyears)) {
324 $arrayyears[$nowyear] = $nowyear;
325}
326arsort($arrayyears);
327print img_picto('', 'calendar', 'class="pictofixedwidth"');
328print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
329print '</td></tr>';
330print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
331print '</table>';
332
333print '</form>';
334
335print '<br><br>';
336
337print '<div class="div-table-responsive-no-min">';
338print '<table class="noborder centpercent">';
339print '<tr class="liste_titre" height="24">';
340print '<td class="center">'.$langs->trans("Year").'</td>';
341print '<td class="right">'.$langs->trans("NbOfProjects").'</td>';
342if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
343 print '<td class="right">'.$langs->trans("OpportunityAmountShort").'</td>';
344 print '<td class="right">'.$langs->trans("OpportunityAmountAverageShort").'</td>';
345 print '<td class="right">'.$langs->trans("OpportunityAmountWeigthedShort").'</td>';
346}
347print '</tr>';
348
349$oldyear = 0;
350foreach ($data_all_year as $val) {
351 $year = $val['year'];
352 while ($year && $oldyear > (int) $year + 1) { // If we have empty year
353 $oldyear--;
354
355 print '<tr class="oddeven" height="24">';
356 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$oldyear.'</a></td>';
357 print '<td class="right">0</td>';
358 if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
359 print '<td class="right amount nowraponall">0</td>';
360 print '<td class="right amount nowraponall">0</td>';
361 print '<td class="right amount nowraponall">0</td>';
362 }
363 print '</tr>';
364 }
365
366 print '<tr class="oddeven" height="24">';
367 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$year.'</a></td>';
368 print '<td class="right">'.$val['nb'].'</td>';
369 if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
370 print '<td class="right amount nowraponall">'.($val['total'] ? price(price2num($val['total'], 'MT'), 1) : '0').'</td>';
371 print '<td class="right amount nowraponall">'.($val['avg'] ? price(price2num($val['avg'], 'MT'), 1) : '0').'</td>';
372 print '<td class="right amount nowraponall">'.(isset($val['weighted']) ? price(price2num($val['weighted'], 'MT'), 1) : '0').'</td>';
373 }
374 print '</tr>';
375 $oldyear = $year;
376}
377
378print '</table>';
379print '</div>';
380
381print '</div><div class="fichetwothirdright">';
382
383$stringtoshow = '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
384if ($mesg) {
385 print $mesg;
386} else {
387 $stringtoshow .= $px1->show();
388 $stringtoshow .= "<br>\n";
389 if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES') && $px2 !== null && $px3 !== null) {
390 //$stringtoshow .= $px->show();
391 //$stringtoshow .= "<br>\n";
392 $stringtoshow .= $px2->show();
393 $stringtoshow .= "<br>\n";
394 $stringtoshow .= $px3->show();
395 }
396}
397$stringtoshow .= '</td></tr></table>';
398
399print $stringtoshow;
400
401print '</div></div>';
402
403print '<div class="clearboth"></div>';
404
405print dol_get_fiche_end();
406
407// End of page
408llxFooter();
409$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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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).
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.