dolibarr  19.0.0-dev
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 // Load Dolibarr environment
30 require '../../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propalestats.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formpropal.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
37 
39 $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
40 
41 $mode = GETPOSTISSET("mode") ? GETPOST("mode", 'aZ09') : 'customer';
42 
43 $object_status = GETPOST('object_status', 'intcomma');
44 $typent_id = GETPOST('typent_id', 'int');
45 $categ_id = GETPOST('categ_id', 'categ_id');
46 
47 $userid = GETPOST('userid', 'int');
48 $socid = GETPOST('socid', 'int');
49 // Security check
50 if ($user->socid > 0) {
51  $action = '';
52  $socid = $user->socid;
53 }
54 
55 $nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
56 $year = GETPOST('year') > 0 ? GETPOST('year', 'int') : $nowyear;
57 $startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
58 $endyear = $year;
59 
60 // Load translation files required by the page
61 $langs->loadLangs(array('orders', 'companies', 'other', 'suppliers', 'supplier_proposal'));
62 
63 if ($mode == 'customer' && !$user->rights->propal->lire) {
65 }
66 if ($mode == 'supplier' && !$user->rights->supplier_proposal->lire) {
68 }
69 
70 
71 /*
72  * View
73  */
74 
75 $form = new Form($db);
76 $formpropal = new FormPropal($db);
77 $formcompany = new FormCompany($db);
78 $formother = new FormOther($db);
79 
80 $langs->loadLangs(array('propal', 'other', 'companies'));
81 
82 if ($mode == 'customer') {
83  $picto = 'propal';
84  $title = $langs->trans("ProposalsStatistics");
85  $dir = $conf->propal->dir_temp;
86  $cat_type = Categorie::TYPE_CUSTOMER;
87  $cat_label = $langs->trans("Category").' '.lcfirst($langs->trans("Customer"));
88 }
89 if ($mode == 'supplier') {
90  $picto = 'supplier_proposal';
91  $title = $langs->trans("ProposalsStatisticsSuppliers");
92  $dir = $conf->supplier_proposal->dir_temp;
93  $cat_type = Categorie::TYPE_SUPPLIER;
94  $cat_label = $langs->trans("Category").' '.lcfirst($langs->trans("Supplier"));
95 }
96 
97 llxHeader('', $title);
98 
99 print load_fiche_titre($title, '', $picto);
100 
101 
102 dol_mkdir($dir);
103 
104 
105 $stats = new PropaleStats($db, $socid, ($userid > 0 ? $userid : 0), $mode, ($typent_id > 0 ? $typent_id : 0), ($categ_id > 0 ? $categ_id : 0));
106 if ($object_status != '' && $object_status >= 0) {
107  $stats->where .= ' AND p.fk_statut IN ('.$db->sanitize($object_status).')';
108 }
109 
110 // Build graphic number of object
111 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
112 // $data = array(array('Lib',val1,val2,val3),...)
113 
114 
115 if (empty($user->rights->societe->client->voir) || $user->socid) {
116  $filenamenb = $dir.'/proposalsnbinyear-'.$user->id.'-'.$year.'.png';
117  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$user->id.'-'.$year.'.png';
118 } else {
119  $filenamenb = $dir.'/proposalsnbinyear-'.$year.'.png';
120  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$year.'.png';
121 }
122 
123 $px1 = new DolGraph();
124 $mesg = $px1->isGraphKo();
125 if (!$mesg) {
126  $px1->SetData($data);
127  $i = $startyear;
128  $legend = array();
129  while ($i <= $endyear) {
130  $legend[] = $i;
131  $i++;
132  }
133  $px1->SetLegend($legend);
134  $px1->SetMaxValue($px1->GetCeilMaxValue());
135  $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
136  $px1->SetWidth($WIDTH);
137  $px1->SetHeight($HEIGHT);
138  $px1->SetYLabel($langs->trans("NbOfProposals"));
139  $px1->SetShading(3);
140  $px1->SetHorizTickIncrement(1);
141  $px1->mode = 'depth';
142  $px1->SetTitle($langs->trans("NumberOfProposalsByMonth"));
143 
144  $px1->draw($filenamenb, $fileurlnb);
145 }
146 
147 // Build graphic amount of object
148 $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, 0);
149 // $data = array(array('Lib',val1,val2,val3),...)
150 
151 if (empty($user->rights->societe->client->voir) || $user->socid) {
152  $filenameamount = $dir.'/proposalsamountinyear-'.$user->id.'-'.$year.'.png';
153  $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsamountinyear-'.$user->id.'-'.$year.'.png';
154 } else {
155  $filenameamount = $dir.'/proposalsamountinyear-'.$year.'.png';
156  $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsamountinyear-'.$year.'.png';
157 }
158 
159 $px2 = new DolGraph();
160 $mesg = $px2->isGraphKo();
161 if (!$mesg) {
162  $px2->SetData($data);
163  $i = $startyear;
164  $legend = array();
165  while ($i <= $endyear) {
166  $legend[] = $i;
167  $i++;
168  }
169  $px2->SetLegend($legend);
170  $px2->SetMaxValue($px2->GetCeilMaxValue());
171  $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
172  $px2->SetWidth($WIDTH);
173  $px2->SetHeight($HEIGHT);
174  $px2->SetYLabel($langs->trans("AmountOfProposals"));
175  $px2->SetShading(3);
176  $px2->SetHorizTickIncrement(1);
177  $px2->mode = 'depth';
178  $px2->SetTitle($langs->trans("AmountOfProposalsByMonthHT"));
179 
180  $px2->draw($filenameamount, $fileurlamount);
181 }
182 
183 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
184 
185 $fileurl_avg = '';
186 if (empty($user->rights->societe->client->voir) || $user->socid) {
187  $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
188  if ($mode == 'customer') {
189  $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
190  }
191  if ($mode == 'supplier') {
192  $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
193  }
194 } else {
195  $filename_avg = $dir.'/ordersaverage-'.$year.'.png';
196  if ($mode == 'customer') {
197  $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
198  }
199  if ($mode == 'supplier') {
200  $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
201  }
202 }
203 
204 $px3 = new DolGraph();
205 $mesg = $px3->isGraphKo();
206 if (!$mesg) {
207  $px3->SetData($data);
208  $i = $startyear;
209  $legend = array();
210  while ($i <= $endyear) {
211  $legend[] = $i;
212  $i++;
213  }
214  $px3->SetLegend($legend);
215  $px3->SetYLabel($langs->trans("AmountAverage"));
216  $px3->SetMaxValue($px3->GetCeilMaxValue());
217  $px3->SetMinValue($px3->GetFloorMinValue());
218  $px3->SetWidth($WIDTH);
219  $px3->SetHeight($HEIGHT);
220  $px3->SetShading(3);
221  $px3->SetHorizTickIncrement(1);
222  $px3->mode = 'depth';
223  $px3->SetTitle($langs->trans("AmountAverage"));
224 
225  $px3->draw($filename_avg, $fileurl_avg);
226 }
227 
228 
229 // Show array
230 $data = $stats->getAllByYear();
231 $arrayyears = array();
232 foreach ($data as $val) {
233  if (!empty($val['year'])) {
234  $arrayyears[$val['year']] = $val['year'];
235  }
236 }
237 if (!count($arrayyears)) {
238  $arrayyears[$nowyear] = $nowyear;
239 }
240 
241 
242 $h = 0;
243 $head = array();
244 $head[$h][0] = DOL_URL_ROOT.'/comm/propal/stats/index.php';
245 $head[$h][1] = $langs->trans("ByMonthYear");
246 $head[$h][2] = 'byyear';
247 $h++;
248 
249 complete_head_from_modules($conf, $langs, null, $head, $h, 'propal_stats');
250 
251 print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
252 
253 
254 print '<div class="fichecenter"><div class="fichethirdleft">';
255 
256 
257 // Show filter box
258 print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
259 print '<input type="hidden" name="token" value="'.newToken().'">';
260 print '<input type="hidden" name="mode" value="'.$mode.'">';
261 
262 print '<table class="noborder centpercent">';
263 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
264 // Company
265 print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
266 print img_picto('', 'company', 'class="pictofixedwidth"');
267 $filter = '(s.client:IN:1,2,3)';
268 print $form->select_company($socid, 'socid', $filter, 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
269 print '</td></tr>';
270 // ThirdParty Type
271 print '<tr><td>'.$langs->trans("ThirdPartyType").'</td><td>';
272 $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.
273 print $form->selectarray("typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0, '', 0, 0, 0, $sortparam_typent, '', 1);
274 if ($user->admin) {
275  print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
276 }
277 print '</td></tr>';
278 // Category
279 print '<tr><td>'.$cat_label.'</td><td>';
280 print img_picto('', 'category', 'class="pictofixedwidth"');
281 print $formother->select_categories($cat_type, $categ_id, 'categ_id', 0, 1, 'widthcentpercentminusx maxwidth300');
282 print '</td></tr>';
283 // User
284 print '<tr><td>'.$langs->trans("CreatedBy").'</td><td>';
285 print img_picto('', 'user', 'class="pictofixedwidth"');
286 print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
287 print '</td></tr>';
288 // Status
289 print '<tr><td>'.$langs->trans("Status").'</td><td>';
290 $formpropal->selectProposalStatus(($object_status != '' ? $object_status : -1), 0, 0, 1, $mode, 'object_status');
291 print '</td></tr>';
292 // Year
293 print '<tr><td>'.$langs->trans("Year").'</td><td>';
294 if (!in_array($year, $arrayyears)) {
295  $arrayyears[$year] = $year;
296 }
297 if (!in_array($nowyear, $arrayyears)) {
298  $arrayyears[$nowyear] = $nowyear;
299 }
300 arsort($arrayyears);
301 print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
302 print '</td></tr>';
303 print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
304 print '</table>';
305 print '</form>';
306 print '<br><br>';
307 
308 print '<div class="div-table-responsive-no-min">';
309 print '<table class="noborder centpercent">';
310 print '<tr class="liste_titre" height="24">';
311 print '<td class="center">'.$langs->trans("Year").'</td>';
312 print '<td class="right">'.$langs->trans("NbOfProposals").'</td>';
313 print '<td class="right">%</td>';
314 print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
315 print '<td class="right">%</td>';
316 print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
317 print '<td class="right">%</td>';
318 print '</tr>';
319 
320 $oldyear = 0;
321 foreach ($data as $val) {
322  $year = $val['year'];
323  while (!empty($year) && $oldyear > $year + 1) { // If we have empty year
324  $oldyear--;
325 
326  print '<tr class="oddeven" height="24">';
327  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>';
328  print '<td class="right">0</td>';
329  print '<td class="right"></td>';
330  print '<td class="right">0</td>';
331  print '<td class="right"></td>';
332  print '<td class="right">0</td>';
333  print '<td class="right"></td>';
334  print '</tr>';
335  }
336  print '<tr class="oddeven" height="24">';
337  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$year.'</a></td>';
338  print '<td class="right">'.$val['nb'].'</td>';
339  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>';
340  print '<td class="right">'.price(price2num($val['total'], 'MT'), 1).'</td>';
341  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>';
342  print '<td class="right">'.price(price2num($val['avg'], 'MT'), 1).'</td>';
343  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>';
344  print '</tr>';
345  $oldyear = $year;
346 }
347 
348 print '</table>';
349 print '</div>';
350 
351 print '</div><div class="fichetwothirdright">';
352 
353 
354 // Show graphs
355 print '<table class="border centpercent"><tr class="pair nohover"><td align="center">';
356 if ($mesg) {
357  print $mesg;
358 } else {
359  print $px1->show();
360  print "<br>\n";
361  print $px2->show();
362  print "<br>\n";
363  print $px3->show();
364 }
365 print '</td></tr></table>';
366 
367 
368 print '</div></div>';
369 print '<div class="clearboth"></div>';
370 
371 
372 print dol_get_fiche_end();
373 
374 // End of page
375 llxFooter();
376 $db->close();
DolGraph\getDefaultGraphSizeForStats
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Definition: dolgraph.class.php:1552
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5477
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:609
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:143
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:29
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5955
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2675
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:4135
PropaleStats
Class to manage proposals statistics.
Definition: propalestats.class.php:37
llxFooter
llxFooter()
Footer empty.
Definition: index.php:71
complete_head_from_modules
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).
Definition: functions.lib.php:9602
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_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2177
dol_get_fiche_head
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.
Definition: functions.lib.php:1979
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:509
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:53
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:3056
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
Definition: security.lib.php:1169
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6936