dolibarr  13.0.2
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 if ($mode == 'customer' && !$user->rights->propale->lire) accessforbidden();
42 if ($mode == 'supplier' && !$user->rights->supplier_proposal->lire) accessforbidden();
43 
44 $object_status = GETPOST('object_status', 'intcomma');
45 $typent_id = GETPOST('typent_id', 'int');
46 $categ_id = GETPOST('categ_id', 'categ_id');
47 
48 $userid = GETPOST('userid', 'int');
49 $socid = GETPOST('socid', 'int');
50 // Security check
51 if ($user->socid > 0)
52 {
53  $action = '';
54  $socid = $user->socid;
55 }
56 
57 $nowyear = strftime("%Y", dol_now());
58 $year = GETPOST('year') > 0 ? GETPOST('year', 'int') : $nowyear;
59 //$startyear=$year-2;
60 $startyear = $year - 1;
61 $endyear = $year;
62 
63 // Load translation files required by the page
64 $langs->loadLangs(array('orders', 'companies', 'other', 'suppliers', 'supplier_proposal'));
65 
66 
67 /*
68  * View
69  */
70 
71 $form = new Form($db);
72 $formpropal = new FormPropal($db);
73 $formcompany = new FormCompany($db);
74 $formother = new FormOther($db);
75 
76 $langs->loadLangs(array('propal', 'other', 'companies'));
77 
78 if ($mode == 'customer')
79 {
80  $picto = 'propal';
81  $title = $langs->trans("ProposalsStatistics");
82  $dir = $conf->propale->dir_temp;
83  $cat_type = Categorie::TYPE_CUSTOMER;
84  $cat_label = $langs->trans("Category").' '.lcfirst($langs->trans("Customer"));
85 }
86 if ($mode == 'supplier')
87 {
88  $picto = 'supplier_proposal';
89  $title = $langs->trans("ProposalsStatisticsSuppliers");
90  $dir = $conf->supplier_proposal->dir_temp;
91  $cat_type = Categorie::TYPE_SUPPLIER;
92  $cat_label = $langs->trans("Category").' '.lcfirst($langs->trans("Supplier"));
93 }
94 
95 llxHeader('', $title);
96 
97 print load_fiche_titre($title, '', $picto);
98 
99 
100 dol_mkdir($dir);
101 
102 
103 $stats = new PropaleStats($db, $socid, ($userid > 0 ? $userid : 0), $mode, ($typent_id > 0 ? $typent_id : 0), ($categ_id > 0 ? $categ_id : 0));
104 if ($object_status != '' && $object_status >= 0) $stats->where .= ' AND p.fk_statut IN ('.$db->sanitize($db->escape($object_status)).')';
105 
106 // Build graphic number of object
107 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
108 // $data = array(array('Lib',val1,val2,val3),...)
109 
110 
111 if (!$user->rights->societe->client->voir || $user->socid)
112 {
113  $filenamenb = $dir.'/proposalsnbinyear-'.$user->id.'-'.$year.'.png';
114  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$user->id.'-'.$year.'.png';
115 } else {
116  $filenamenb = $dir.'/proposalsnbinyear-'.$year.'.png';
117  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$year.'.png';
118 }
119 
120 $px1 = new DolGraph();
121 $mesg = $px1->isGraphKo();
122 if (!$mesg)
123 {
124  $px1->SetData($data);
125  $i = $startyear; $legend = array();
126  while ($i <= $endyear)
127  {
128  $legend[] = $i;
129  $i++;
130  }
131  $px1->SetLegend($legend);
132  $px1->SetMaxValue($px1->GetCeilMaxValue());
133  $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
134  $px1->SetWidth($WIDTH);
135  $px1->SetHeight($HEIGHT);
136  $px1->SetYLabel($langs->trans("NbOfProposals"));
137  $px1->SetShading(3);
138  $px1->SetHorizTickIncrement(1);
139  $px1->mode = 'depth';
140  $px1->SetTitle($langs->trans("NumberOfProposalsByMonth"));
141 
142  $px1->draw($filenamenb, $fileurlnb);
143 }
144 
145 // Build graphic amount of object
146 $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, 0);
147 // $data = array(array('Lib',val1,val2,val3),...)
148 
149 if (!$user->rights->societe->client->voir || $user->socid)
150 {
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 {
162  $px2->SetData($data);
163  $i = $startyear; $legend = array();
164  while ($i <= $endyear)
165  {
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 (!$user->rights->societe->client->voir || $user->socid)
187 {
188  $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
189  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
190  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
191 } else {
192  $filename_avg = $dir.'/ordersaverage-'.$year.'.png';
193  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
194  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
195 }
196 
197 $px3 = new DolGraph();
198 $mesg = $px3->isGraphKo();
199 if (!$mesg)
200 {
201  $px3->SetData($data);
202  $i = $startyear; $legend = array();
203  while ($i <= $endyear)
204  {
205  $legend[] = $i;
206  $i++;
207  }
208  $px3->SetLegend($legend);
209  $px3->SetYLabel($langs->trans("AmountAverage"));
210  $px3->SetMaxValue($px3->GetCeilMaxValue());
211  $px3->SetMinValue($px3->GetFloorMinValue());
212  $px3->SetWidth($WIDTH);
213  $px3->SetHeight($HEIGHT);
214  $px3->SetShading(3);
215  $px3->SetHorizTickIncrement(1);
216  $px3->mode = 'depth';
217  $px3->SetTitle($langs->trans("AmountAverage"));
218 
219  $px3->draw($filename_avg, $fileurl_avg);
220 }
221 
222 
223 // Show array
224 $data = $stats->getAllByYear();
225 $arrayyears = array();
226 foreach ($data as $val) {
227  if (!empty($val['year'])) {
228  $arrayyears[$val['year']] = $val['year'];
229  }
230 }
231 if (!count($arrayyears)) $arrayyears[$nowyear] = $nowyear;
232 
233 
234 $h = 0;
235 $head = array();
236 $head[$h][0] = DOL_URL_ROOT.'/comm/propal/stats/index.php';
237 $head[$h][1] = $langs->trans("ByMonthYear");
238 $head[$h][2] = 'byyear';
239 $h++;
240 
241 complete_head_from_modules($conf, $langs, null, $head, $h, 'propal_stats');
242 
243 print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
244 
245 
246 print '<div class="fichecenter"><div class="fichethirdleft">';
247 
248 
249 //if (empty($socid))
250 //{
251  // Show filter box
252  print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
253  print '<input type="hidden" name="token" value="'.newToken().'">';
254  print '<input type="hidden" name="mode" value="'.$mode.'">';
255 
256  print '<table class="noborder centpercent">';
257  print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
258  // Company
259  print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
260  $filter = 's.client IN (1,2,3)';
261  print $form->select_company($socid, 'socid', $filter, 1, 0, 0, array(), 0, '', 'style="width: 95%"');
262  print '</td></tr>';
263  // ThirdParty Type
264  print '<tr><td>'.$langs->trans("ThirdPartyType").'</td><td>';
265  $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.
266  print $form->selectarray("typent_id", $formcompany->typent_array(0), $typent_id, 0, 0, 0, '', 0, 0, 0, $sortparam_typent);
267  if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
268  print '</td></tr>';
269  // Category
270  print '<tr><td>'.$cat_label.'</td><td>';
271  print $formother->select_categories($cat_type, $categ_id, 'categ_id', true);
272  print '</td></tr>';
273  // User
274  print '<tr><td class="left">'.$langs->trans("CreatedBy").'</td><td class="left">';
275  print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
276  print '</td></tr>';
277  // Status
278  print '<tr><td class="left">'.$langs->trans("Status").'</td><td class="left">';
279  $formpropal->selectProposalStatus(($object_status != '' ? $object_status : -1), 0, 0, 1, $mode, 'object_status');
280  print '</td></tr>';
281  // Year
282  print '<tr><td class="left">'.$langs->trans("Year").'</td><td class="left">';
283  if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year;
284  if (!in_array($nowyear, $arrayyears)) $arrayyears[$nowyear] = $nowyear;
285  arsort($arrayyears);
286  print $form->selectarray('year', $arrayyears, $year, 0);
287  print '</td></tr>';
288  print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
289  print '</table>';
290  print '</form>';
291  print '<br><br>';
292 //}
293 
294 print '<div class="div-table-responsive-no-min">';
295 print '<table class="noborder centpercent">';
296 print '<tr class="liste_titre" height="24">';
297 print '<td class="center">'.$langs->trans("Year").'</td>';
298 print '<td class="right">'.$langs->trans("NbOfProposals").'</td>';
299 print '<td class="right">%</td>';
300 print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
301 print '<td class="right">%</td>';
302 print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
303 print '<td class="right">%</td>';
304 print '</tr>';
305 
306 $oldyear = 0;
307 foreach ($data as $val)
308 {
309  $year = $val['year'];
310  while (!empty($year) && $oldyear > $year + 1)
311  { // If we have empty year
312  $oldyear--;
313 
314  print '<tr class="oddeven" height="24">';
315  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>';
316  print '<td class="right">0</td>';
317  print '<td class="right"></td>';
318  print '<td class="right">0</td>';
319  print '<td class="right"></td>';
320  print '<td class="right">0</td>';
321  print '<td class="right"></td>';
322  print '</tr>';
323  }
324  print '<tr class="oddeven" height="24">';
325  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.($socid > 0 ? '&socid='.$socid : '').($userid > 0 ? '&userid='.$userid : '').'">'.$year.'</a></td>';
326  print '<td class="right">'.$val['nb'].'</td>';
327  print '<td class="right" style="'.(($val['nb_diff'] >= 0) ? 'color: green;' : 'color: red;').'">'.round($val['nb_diff']).'</td>';
328  print '<td class="right">'.price(price2num($val['total'], 'MT'), 1).'</td>';
329  print '<td class="right" style="'.(($val['total_diff'] >= 0) ? 'color: green;' : 'color: red;').'">'.round($val['total_diff']).'</td>';
330  print '<td class="right">'.price(price2num($val['avg'], 'MT'), 1).'</td>';
331  print '<td class="right" style="'.(($val['avg_diff'] >= 0) ? 'color: green;' : 'color: red;').'">'.round($val['avg_diff']).'</td>';
332  print '</tr>';
333  $oldyear = $year;
334 }
335 
336 print '</table>';
337 print '</div>';
338 
339 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
340 
341 
342 // Show graphs
343 print '<table class="border centpercent"><tr class="pair nohover"><td align="center">';
344 if ($mesg) { print $mesg; } else {
345  print $px1->show();
346  print "<br>\n";
347  print $px2->show();
348  print "<br>\n";
349  print $px3->show();
350 }
351 print '</td></tr></table>';
352 
353 
354 print '</div></div></div>';
355 print '<div style="clear:both"></div>';
356 
357 
358 print dol_get_fiche_end();
359 
360 // End of page
361 llxFooter();
362 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_now($mode= 'auto')
Return date for now.
Class to manage generation of HTML components for proposal management.
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to build HTML component for third parties management Only common components are here...
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
Classe permettant la generation de composants html autre Only common components are here...
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 ...
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
Class to build graphs.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
static getDefaultGraphSizeForStats($direction, $defaultsize= '')
getDefaultGraphSizeForStats
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode= 'add')
Complete or removed entries into a head array (used to build tabs).
llxFooter()
Empty footer.
Definition: wrapper.php:59
Class to manage proposals statistics.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)