dolibarr 21.0.0-alpha
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
26require '../../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
28require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/projet/class/projectstats.class.php';
31
34
35$search_opp_status = GETPOST("search_opp_status", 'alpha');
36
37$userid = GETPOSTINT('userid');
38$socid = GETPOSTINT('socid');
39// Security check
40if ($user->socid > 0) {
41 $action = '';
42 $socid = $user->socid;
43}
44$nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
45$year = GETPOSTINT('year') > 0 ? GETPOSTINT('year') : $nowyear;
46$startyear = $year - (!getDolGlobalString('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalString('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
53if (!$user->hasRight('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
67llxHeader('', $langs->trans('Projects'), '', '', 0, 0, '', '', '', 'mod-project page-stats');
68
69$title = $langs->trans("ProjectsStatistics");
70$dir = $conf->project->dir_output.'/temp';
71
72print load_fiche_titre($title, '', 'project');
73
74dol_mkdir($dir);
75
76
77$stats_project = new ProjectStats($db);
78if (!empty($userid) && $userid != -1) {
79 $stats_project->userid = $userid;
80}
81if (!empty($socid) && $socid != -1) {
82 $stats_project->socid = $socid;
83}
84if (!empty($year)) {
85 $stats_project->year = $year;
86}
87
88if (getDolGlobalString('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();
105if (!$mesg) {
106 $px1->SetData($data);
107 $i = $startyear;
108 $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
127if (getDolGlobalString('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;
140 $legend = array();
141 while ($i <= $endyear) {
142 $legend[] = $i;
143 $i++;
144 }
145
146 $px2->SetData($data);
147 $px2->SetLegend($legend);
148 $px2->SetMaxValue($px2->GetCeilMaxValue());
149 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
150 $px2->SetWidth($WIDTH);
151 $px2->SetHeight($HEIGHT);
152 $px2->SetYLabel($langs->trans("ProjectOppAmountOfProjectsByMonth"));
153 $px2->SetShading(3);
154 $px2->SetHorizTickIncrement(1);
155 $px2->SetType(array('bars', 'bars'));
156 $px2->mode = 'depth';
157 $px2->SetTitle($langs->trans("ProjectOppAmountOfProjectsByMonth"));
158
159 $px2->draw($filenamenb, $fileurlnb);
160 }
161}
162
163if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
164 // Build graphic with transformation rate
165 $data = $stats_project->getWeightedAmountByMonthWithPrevYear($endyear, $startyear, 0, 0);
166 //var_dump($data);
167 // $data = array(array('Lib',val1,val2,val3),...)
168
169 $filenamenb = $conf->project->dir_output."/stats/projecttransrateprevyear-".$year.".png";
170 $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=projectstats&amp;file=projecttransrateprevyear-'.$year.'.png';
171
172 $px3 = new DolGraph();
173 $mesg = $px3->isGraphKo();
174 if (!$mesg) {
175 $px3->SetData($data);
176 $i = $startyear;
177 $legend = array();
178 while ($i <= $endyear) {
179 $legend[] = $i;
180 $i++;
181 }
182 $px3->SetLegend($legend);
183 $px3->SetMaxValue($px3->GetCeilMaxValue());
184 $px3->SetMinValue(min(0, $px3->GetFloorMinValue()));
185 $px3->SetWidth($WIDTH);
186 $px3->SetHeight($HEIGHT);
187 $px3->SetYLabel($langs->trans("ProjectWeightedOppAmountOfProjectsByMonth"));
188 $px3->SetShading(3);
189 $px3->SetHorizTickIncrement(1);
190 $px3->mode = 'depth';
191 $px3->SetTitle($langs->trans("ProjectWeightedOppAmountOfProjectsByMonth"));
192
193 $px3->draw($filenamenb, $fileurlnb);
194 }
195}
196
197
198// Show array
199$stats_project->year = 0;
200$data_all_year = $stats_project->getAllByYear();
201
202if (!empty($year)) {
203 $stats_project->year = $year;
204}
205$arrayyears = array();
206foreach ($data_all_year as $val) {
207 $arrayyears[$val['year']] = $val['year'];
208}
209if (!count($arrayyears)) {
210 $arrayyears[$nowyear] = $nowyear;
211}
212
213
214$h = 0;
215$head = array();
216$head[$h][0] = DOL_URL_ROOT.'/projet/stats/index.php';
217$head[$h][1] = $langs->trans("ByMonthYear");
218$head[$h][2] = 'byyear';
219$h++;
220
221complete_head_from_modules($conf, $langs, null, $head, $h, 'project_stats');
222
223print dol_get_fiche_head($head, 'byyear', '', -1, '');
224
225
226print '<div class="fichecenter"><div class="fichethirdleft">';
227
228print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
229print '<input type="hidden" name="token" value="'.newToken().'">';
230
231print '<table class="noborder centpercent">';
232print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
233// Company
234print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
235print img_picto('', 'company', 'class="pictofixedwidth"');
236print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
237print '</td></tr>';
238// Opportunity status
239if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
240 print '<tr><td>'.$langs->trans("OpportunityStatusShort").'</td><td>';
241 print $formproject->selectOpportunityStatus('search_opp_status', $search_opp_status, 1, 0, 1, 0, 'maxwidth300', 1, 1);
242 print '</td></tr>';
243}
244
245// User
246/*print '<tr><td>'.$langs->trans("ProjectCommercial").'</td><td>';
247print $form->select_dolusers($userid, 'userid', 1, array(),0,$includeuserlist);
248print '</td></tr>';*/
249// Year
250print '<tr><td>'.$langs->trans("Year").' <span class="opacitymedium">('.$langs->trans("DateCreation").')</span></td><td>';
251if (!in_array($year, $arrayyears)) {
252 $arrayyears[$year] = $year;
253}
254if (!in_array($nowyear, $arrayyears)) {
255 $arrayyears[$nowyear] = $nowyear;
256}
257arsort($arrayyears);
258print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
259print '</td></tr>';
260print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
261print '</table>';
262
263print '</form>';
264
265print '<br><br>';
266
267print '<div class="div-table-responsive-no-min">';
268print '<table class="noborder centpercent">';
269print '<tr class="liste_titre" height="24">';
270print '<td class="center">'.$langs->trans("Year").'</td>';
271print '<td class="right">'.$langs->trans("NbOfProjects").'</td>';
272if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
273 print '<td class="right">'.$langs->trans("OpportunityAmountShort").'</td>';
274 print '<td class="right">'.$langs->trans("OpportunityAmountAverageShort").'</td>';
275 print '<td class="right">'.$langs->trans("OpportunityAmountWeigthedShort").'</td>';
276}
277print '</tr>';
278
279$oldyear = 0;
280foreach ($data_all_year as $val) {
281 $year = $val['year'];
282 while ($year && $oldyear > $year + 1) { // If we have empty year
283 $oldyear--;
284
285 print '<tr class="oddeven" height="24">';
286 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$oldyear.'</a></td>';
287 print '<td class="right">0</td>';
288 if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
289 print '<td class="right amount nowraponall">0</td>';
290 print '<td class="right amount nowraponall">0</td>';
291 print '<td class="right amount nowraponall">0</td>';
292 }
293 print '</tr>';
294 }
295
296 print '<tr class="oddeven" height="24">';
297 print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$year.'</a></td>';
298 print '<td class="right">'.$val['nb'].'</td>';
299 if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
300 print '<td class="right amount nowraponall">'.($val['total'] ? price(price2num($val['total'], 'MT'), 1) : '0').'</td>';
301 print '<td class="right amount nowraponall">'.($val['avg'] ? price(price2num($val['avg'], 'MT'), 1) : '0').'</td>';
302 print '<td class="right amount nowraponall">'.(isset($val['weighted']) ? price(price2num($val['weighted'], 'MT'), 1) : '0').'</td>';
303 }
304 print '</tr>';
305 $oldyear = $year;
306}
307
308print '</table>';
309print '</div>';
310
311print '</div><div class="fichetwothirdright">';
312
313$stringtoshow = '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
314if ($mesg) {
315 print $mesg;
316} else {
317 $stringtoshow .= $px1->show();
318 $stringtoshow .= "<br>\n";
319 if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
320 //$stringtoshow .= $px->show();
321 //$stringtoshow .= "<br>\n";
322 $stringtoshow .= $px2->show();
323 $stringtoshow .= "<br>\n";
324 $stringtoshow .= $px3->show();
325 }
326}
327$stringtoshow .= '</td></tr></table>';
328
329print $stringtoshow;
330
331print '</div></div>';
332
333print '<div class="clearboth"></div>';
334
335print dol_get_fiche_end();
336
337// End of page
338llxFooter();
339$db->close();
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:70
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.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
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)
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_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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).
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.