dolibarr  16.0.5
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
6  * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
7  * Copyright (C) 2020 Maxime DEMAREST <maxime@indelog.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  */
22 
29 require '../../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propalestats.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formpropal.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
36 
38 $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
39 
40 $mode = GETPOSTISSET("mode") ? GETPOST("mode", 'aZ09') : 'customer';
41 
42 $object_status = GETPOST('object_status', 'intcomma');
43 $typent_id = GETPOST('typent_id', 'int');
44 $categ_id = GETPOST('categ_id', 'categ_id');
45 
46 $userid = GETPOST('userid', 'int');
47 $socid = GETPOST('socid', 'int');
48 // Security check
49 if ($user->socid > 0) {
50  $action = '';
51  $socid = $user->socid;
52 }
53 
54 $nowyear = strftime("%Y", dol_now());
55 $year = GETPOST('year') > 0 ? GETPOST('year', 'int') : $nowyear;
56 $startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
57 $endyear = $year;
58 
59 // Load translation files required by the page
60 $langs->loadLangs(array('orders', 'companies', 'other', 'suppliers', 'supplier_proposal'));
61 
62 if ($mode == 'customer' && !$user->rights->propale->lire) {
64 }
65 if ($mode == 'supplier' && !$user->rights->supplier_proposal->lire) {
67 }
68 
69 
70 /*
71  * View
72  */
73 
74 $form = new Form($db);
75 $formpropal = new FormPropal($db);
76 $formcompany = new FormCompany($db);
77 $formother = new FormOther($db);
78 
79 $langs->loadLangs(array('propal', 'other', 'companies'));
80 
81 if ($mode == 'customer') {
82  $picto = 'propal';
83  $title = $langs->trans("ProposalsStatistics");
84  $dir = $conf->propal->dir_temp;
85  $cat_type = Categorie::TYPE_CUSTOMER;
86  $cat_label = $langs->trans("Category").' '.lcfirst($langs->trans("Customer"));
87 }
88 if ($mode == 'supplier') {
89  $picto = 'supplier_proposal';
90  $title = $langs->trans("ProposalsStatisticsSuppliers");
91  $dir = $conf->supplier_proposal->dir_temp;
92  $cat_type = Categorie::TYPE_SUPPLIER;
93  $cat_label = $langs->trans("Category").' '.lcfirst($langs->trans("Supplier"));
94 }
95 
96 llxHeader('', $title);
97 
98 print load_fiche_titre($title, '', $picto);
99 
100 
101 dol_mkdir($dir);
102 
103 
104 $stats = new PropaleStats($db, $socid, ($userid > 0 ? $userid : 0), $mode, ($typent_id > 0 ? $typent_id : 0), ($categ_id > 0 ? $categ_id : 0));
105 if ($object_status != '' && $object_status >= 0) {
106  $stats->where .= ' AND p.fk_statut IN ('.$db->sanitize($object_status).')';
107 }
108 
109 // Build graphic number of object
110 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
111 // $data = array(array('Lib',val1,val2,val3),...)
112 
113 
114 if (empty($user->rights->societe->client->voir) || $user->socid) {
115  $filenamenb = $dir.'/proposalsnbinyear-'.$user->id.'-'.$year.'.png';
116  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$user->id.'-'.$year.'.png';
117 } else {
118  $filenamenb = $dir.'/proposalsnbinyear-'.$year.'.png';
119  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$year.'.png';
120 }
121 
122 $px1 = new DolGraph();
123 $mesg = $px1->isGraphKo();
124 if (!$mesg) {
125  $px1->SetData($data);
126  $i = $startyear;
127  $legend = array();
128  while ($i <= $endyear) {
129  $legend[] = $i;
130  $i++;
131  }
132  $px1->SetLegend($legend);
133  $px1->SetMaxValue($px1->GetCeilMaxValue());
134  $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
135  $px1->SetWidth($WIDTH);
136  $px1->SetHeight($HEIGHT);
137  $px1->SetYLabel($langs->trans("NbOfProposals"));
138  $px1->SetShading(3);
139  $px1->SetHorizTickIncrement(1);
140  $px1->mode = 'depth';
141  $px1->SetTitle($langs->trans("NumberOfProposalsByMonth"));
142 
143  $px1->draw($filenamenb, $fileurlnb);
144 }
145 
146 // Build graphic amount of object
147 $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, 0);
148 // $data = array(array('Lib',val1,val2,val3),...)
149 
150 if (empty($user->rights->societe->client->voir) || $user->socid) {
151  $filenameamount = $dir.'/proposalsamountinyear-'.$user->id.'-'.$year.'.png';
152  $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsamountinyear-'.$user->id.'-'.$year.'.png';
153 } else {
154  $filenameamount = $dir.'/proposalsamountinyear-'.$year.'.png';
155  $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsamountinyear-'.$year.'.png';
156 }
157 
158 $px2 = new DolGraph();
159 $mesg = $px2->isGraphKo();
160 if (!$mesg) {
161  $px2->SetData($data);
162  $i = $startyear;
163  $legend = array();
164  while ($i <= $endyear) {
165  $legend[] = $i;
166  $i++;
167  }
168  $px2->SetLegend($legend);
169  $px2->SetMaxValue($px2->GetCeilMaxValue());
170  $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
171  $px2->SetWidth($WIDTH);
172  $px2->SetHeight($HEIGHT);
173  $px2->SetYLabel($langs->trans("AmountOfProposals"));
174  $px2->SetShading(3);
175  $px2->SetHorizTickIncrement(1);
176  $px2->mode = 'depth';
177  $px2->SetTitle($langs->trans("AmountOfProposalsByMonthHT"));
178 
179  $px2->draw($filenameamount, $fileurlamount);
180 }
181 
182 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
183 
184 $fileurl_avg = '';
185 if (empty($user->rights->societe->client->voir) || $user->socid) {
186  $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
187  if ($mode == 'customer') {
188  $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
189  }
190  if ($mode == 'supplier') {
191  $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
192  }
193 } else {
194  $filename_avg = $dir.'/ordersaverage-'.$year.'.png';
195  if ($mode == 'customer') {
196  $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
197  }
198  if ($mode == 'supplier') {
199  $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
200  }
201 }
202 
203 $px3 = new DolGraph();
204 $mesg = $px3->isGraphKo();
205 if (!$mesg) {
206  $px3->SetData($data);
207  $i = $startyear;
208  $legend = array();
209  while ($i <= $endyear) {
210  $legend[] = $i;
211  $i++;
212  }
213  $px3->SetLegend($legend);
214  $px3->SetYLabel($langs->trans("AmountAverage"));
215  $px3->SetMaxValue($px3->GetCeilMaxValue());
216  $px3->SetMinValue($px3->GetFloorMinValue());
217  $px3->SetWidth($WIDTH);
218  $px3->SetHeight($HEIGHT);
219  $px3->SetShading(3);
220  $px3->SetHorizTickIncrement(1);
221  $px3->mode = 'depth';
222  $px3->SetTitle($langs->trans("AmountAverage"));
223 
224  $px3->draw($filename_avg, $fileurl_avg);
225 }
226 
227 
228 // Show array
229 $data = $stats->getAllByYear();
230 $arrayyears = array();
231 foreach ($data as $val) {
232  if (!empty($val['year'])) {
233  $arrayyears[$val['year']] = $val['year'];
234  }
235 }
236 if (!count($arrayyears)) {
237  $arrayyears[$nowyear] = $nowyear;
238 }
239 
240 
241 $h = 0;
242 $head = array();
243 $head[$h][0] = DOL_URL_ROOT.'/comm/propal/stats/index.php';
244 $head[$h][1] = $langs->trans("ByMonthYear");
245 $head[$h][2] = 'byyear';
246 $h++;
247 
248 complete_head_from_modules($conf, $langs, null, $head, $h, 'propal_stats');
249 
250 print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
251 
252 
253 print '<div class="fichecenter"><div class="fichethirdleft">';
254 
255 
256 // Show filter box
257 print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
258 print '<input type="hidden" name="token" value="'.newToken().'">';
259 print '<input type="hidden" name="mode" value="'.$mode.'">';
260 
261 print '<table class="noborder centpercent">';
262 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
263 // Company
264 print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
265 $filter = 's.client IN (1,2,3)';
266 print img_picto('', 'company', 'class="pictofixedwidth"');
267 print $form->select_company($socid, 'socid', $filter, 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
268 print '</td></tr>';
269 // ThirdParty Type
270 print '<tr><td>'.$langs->trans("ThirdPartyType").'</td><td>';
271 $sortparam_typent = (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT); // NONE means we keep sort of original array, so we sort on position. ASC, means next function will sort on label.
272 print $form->selectarray("typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0, '', 0, 0, 0, $sortparam_typent, '', 1);
273 if ($user->admin) {
274  print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
275 }
276 print '</td></tr>';
277 // Category
278 print '<tr><td>'.$cat_label.'</td><td>';
279 print img_picto('', 'category', 'class="pictofixedwidth"');
280 print $formother->select_categories($cat_type, $categ_id, 'categ_id', 0, 1, 'widthcentpercentminusx maxwidth300');
281 print '</td></tr>';
282 // User
283 print '<tr><td>'.$langs->trans("CreatedBy").'</td><td>';
284 print img_picto('', 'user', 'class="pictofixedwidth"');
285 print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
286 print '</td></tr>';
287 // Status
288 print '<tr><td>'.$langs->trans("Status").'</td><td>';
289 $formpropal->selectProposalStatus(($object_status != '' ? $object_status : -1), 0, 0, 1, $mode, 'object_status');
290 print '</td></tr>';
291 // Year
292 print '<tr><td>'.$langs->trans("Year").'</td><td>';
293 if (!in_array($year, $arrayyears)) {
294  $arrayyears[$year] = $year;
295 }
296 if (!in_array($nowyear, $arrayyears)) {
297  $arrayyears[$nowyear] = $nowyear;
298 }
299 arsort($arrayyears);
300 print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
301 print '</td></tr>';
302 print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
303 print '</table>';
304 print '</form>';
305 print '<br><br>';
306 
307 print '<div class="div-table-responsive-no-min">';
308 print '<table class="noborder centpercent">';
309 print '<tr class="liste_titre" height="24">';
310 print '<td class="center">'.$langs->trans("Year").'</td>';
311 print '<td class="right">'.$langs->trans("NbOfProposals").'</td>';
312 print '<td class="right">%</td>';
313 print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
314 print '<td class="right">%</td>';
315 print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
316 print '<td class="right">%</td>';
317 print '</tr>';
318 
319 $oldyear = 0;
320 foreach ($data as $val) {
321  $year = $val['year'];
322  while (!empty($year) && $oldyear > $year + 1) { // If we have empty year
323  $oldyear--;
324 
325  print '<tr class="oddeven" height="24">';
326  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&amp;mode='.$mode.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$oldyear.'</a></td>';
327  print '<td class="right">0</td>';
328  print '<td class="right"></td>';
329  print '<td class="right">0</td>';
330  print '<td class="right"></td>';
331  print '<td class="right">0</td>';
332  print '<td class="right"></td>';
333  print '</tr>';
334  }
335  print '<tr class="oddeven" height="24">';
336  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$year.'</a></td>';
337  print '<td class="right">'.$val['nb'].'</td>';
338  print '<td class="right opacitylow" style="'.((!isset($val['nb_diff']) || $val['nb_diff'] >= 0) ? 'color: green;' : 'color: red;').'">'.(isset($val['nb_diff']) ? round($val['nb_diff']): "0").'%</td>';
339  print '<td class="right">'.price(price2num($val['total'], 'MT'), 1).'</td>';
340  print '<td class="right opacitylow" style="'.((!isset($val['total_diff']) || $val['total_diff'] >= 0) ? 'color: green;' : 'color: red;').'">'.(isset($val['total_diff']) ? round($val['total_diff']) : "0").'%</td>';
341  print '<td class="right">'.price(price2num($val['avg'], 'MT'), 1).'</td>';
342  print '<td class="right opacitylow" style="'.((!isset($val['avg_diff']) || $val['avg_diff'] >= 0) ? 'color: green;' : 'color: red;').'">'.(isset($val['avg_diff']) ? round($val['avg_diff']) : "0").'%</td>';
343  print '</tr>';
344  $oldyear = $year;
345 }
346 
347 print '</table>';
348 print '</div>';
349 
350 print '</div><div class="fichetwothirdright">';
351 
352 
353 // Show graphs
354 print '<table class="border centpercent"><tr class="pair nohover"><td align="center">';
355 if ($mesg) {
356  print $mesg;
357 } else {
358  print $px1->show();
359  print "<br>\n";
360  print $px2->show();
361  print "<br>\n";
362  print $px3->show();
363 }
364 print '</td></tr></table>';
365 
366 
367 print '</div></div>';
368 print '<div style="clear:both"></div>';
369 
370 
371 print dol_get_fiche_end();
372 
373 // End of page
374 llxFooter();
375 $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
DolGraph
Class to build graphs.
Definition: dolgraph.class.php:40
$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
FormOther
Classe permettant la generation de composants html autre Only common components are here.
Definition: html.formother.class.php:39
FormPropal
Class to manage generation of HTML components for proposal management.
Definition: html.formpropal.class.php:28
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
FormCompany
Class to build HTML component for third parties management Only common components are here.
Definition: html.formcompany.class.php:40
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
PropaleStats
Class to manage proposals statistics.
Definition: propalestats.class.php:37
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
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
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
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