dolibarr  7.0.0-beta
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@capnetworks.com>
5  * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
6  * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
28 require '../../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propalestats.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formpropal.class.php';
32 
35 
36 $mode=GETPOST("mode")?GETPOST("mode"):'customer';
37 if ($mode == 'customer' && ! $user->rights->propale->lire) accessforbidden();
38 if ($mode == 'supplier' && ! $user->rights->supplier_proposal->lire) accessforbidden();
39 
40 $object_status=GETPOST('object_status');
41 
42 $userid=GETPOST('userid','int');
43 $socid=GETPOST('socid','int');
44 // Security check
45 if ($user->societe_id > 0)
46 {
47  $action = '';
48  $socid = $user->societe_id;
49 }
50 
51 $nowyear=strftime("%Y", dol_now());
52 $year = GETPOST('year')>0?GETPOST('year'):$nowyear;
53 //$startyear=$year-2;
54 $startyear=$year-1;
55 $endyear=$year;
56 
57 $langs->load('orders');
58 $langs->load('companies');
59 $langs->load('other');
60 $langs->load('suppliers');
61 $langs->load('supplier_proposal');
62 
63 
64 /*
65  * View
66  */
67 
68 $form=new Form($db);
69 $formpropal=new FormPropal($db);
70 
71 $langs->load('propal');
72 $langs->load('other');
73 $langs->load("companies");
74 
75 if ($mode == 'customer')
76 {
77  $title=$langs->trans("ProposalsStatistics");
78  $dir=$conf->propale->dir_temp;
79 }
80 if ($mode == 'supplier')
81 {
82  $title=$langs->trans("ProposalsStatisticsSuppliers").' ('.$langs->trans("SentToSuppliers").")";
83  $dir=$conf->supplier_proposal->dir_temp;
84 }
85 
86 llxHeader('', $title);
87 
88 print load_fiche_titre($title,'','title_commercial.png');
89 
90 
91 dol_mkdir($dir);
92 
93 
94 $stats = new PropaleStats($db, $socid, ($userid>0?$userid:0), $mode);
95 if ($object_status != '' && $object_status >= 0) $stats->where .= ' AND p.fk_statut IN ('.$db->escape($object_status).')';
96 
97 // Build graphic number of object
98 $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
99 // $data = array(array('Lib',val1,val2,val3),...)
100 
101 
102 if (!$user->rights->societe->client->voir || $user->societe_id)
103 {
104  $filenamenb = $dir.'/proposalsnbinyear-'.$user->id.'-'.$year.'.png';
105  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$user->id.'-'.$year.'.png';
106 }
107 else
108 {
109  $filenamenb = $dir.'/proposalsnbinyear-'.$year.'.png';
110  $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$year.'.png';
111 }
112 
113 $px1 = new DolGraph();
114 $mesg = $px1->isGraphKo();
115 if (! $mesg)
116 {
117  $px1->SetData($data);
118  $px1->SetPrecisionY(0);
119  $i=$startyear;$legend=array();
120  while ($i <= $endyear)
121  {
122  $legend[]=$i;
123  $i++;
124  }
125  $px1->SetLegend($legend);
126  $px1->SetMaxValue($px1->GetCeilMaxValue());
127  $px1->SetMinValue(min(0,$px1->GetFloorMinValue()));
128  $px1->SetWidth($WIDTH);
129  $px1->SetHeight($HEIGHT);
130  $px1->SetYLabel($langs->trans("NbOfProposals"));
131  $px1->SetShading(3);
132  $px1->SetHorizTickIncrement(1);
133  $px1->SetPrecisionY(0);
134  $px1->mode='depth';
135  $px1->SetTitle($langs->trans("NumberOfProposalsByMonth"));
136 
137  $px1->draw($filenamenb,$fileurlnb);
138 }
139 
140 // Build graphic amount of object
141 $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear,0);
142 // $data = array(array('Lib',val1,val2,val3),...)
143 
144 if (!$user->rights->societe->client->voir || $user->societe_id)
145 {
146  $filenameamount = $dir.'/proposalsamountinyear-'.$user->id.'-'.$year.'.png';
147  $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsamountinyear-'.$user->id.'-'.$year.'.png';
148 }
149 else
150 {
151  $filenameamount = $dir.'/proposalsamountinyear-'.$year.'.png';
152  $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsamountinyear-'.$year.'.png';
153 }
154 
155 $px2 = new DolGraph();
156 $mesg = $px2->isGraphKo();
157 if (! $mesg)
158 {
159  $px2->SetData($data);
160  $px2->SetPrecisionY(0);
161  $i=$startyear;$legend=array();
162  while ($i <= $endyear)
163  {
164  $legend[]=$i;
165  $i++;
166  }
167  $px2->SetLegend($legend);
168  $px2->SetMaxValue($px2->GetCeilMaxValue());
169  $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
170  $px2->SetWidth($WIDTH);
171  $px2->SetHeight($HEIGHT);
172  $px2->SetYLabel($langs->trans("AmountOfProposals"));
173  $px2->SetShading(3);
174  $px2->SetHorizTickIncrement(1);
175  $px2->SetPrecisionY(0);
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 (!$user->rights->societe->client->voir || $user->societe_id)
186 {
187  $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
188  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
189  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
190 }
191 else
192 {
193  $filename_avg = $dir.'/ordersaverage-'.$year.'.png';
194  if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
195  if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
196 }
197 
198 $px3 = new DolGraph();
199 $mesg = $px3->isGraphKo();
200 if (! $mesg)
201 {
202  $px3->SetData($data);
203  $i=$startyear;$legend=array();
204  while ($i <= $endyear)
205  {
206  $legend[]=$i;
207  $i++;
208  }
209  $px3->SetLegend($legend);
210  $px3->SetYLabel($langs->trans("AmountAverage"));
211  $px3->SetMaxValue($px3->GetCeilMaxValue());
212  $px3->SetMinValue($px3->GetFloorMinValue());
213  $px3->SetWidth($WIDTH);
214  $px3->SetHeight($HEIGHT);
215  $px3->SetShading(3);
216  $px3->SetHorizTickIncrement(1);
217  $px3->SetPrecisionY(0);
218  $px3->mode='depth';
219  $px3->SetTitle($langs->trans("AmountAverage"));
220 
221  $px3->draw($filename_avg,$fileurl_avg);
222 }
223 
224 
225 // Show array
226 $data = $stats->getAllByYear();
227 $arrayyears=array();
228 foreach($data as $val) {
229  if (! empty($val['year'])) {
230  $arrayyears[$val['year']]=$val['year'];
231  }
232 }
233 if (! count($arrayyears)) $arrayyears[$nowyear]=$nowyear;
234 
235 
236 $h=0;
237 $head = array();
238 $head[$h][0] = DOL_URL_ROOT . '/comm/propal/stats/index.php';
239 $head[$h][1] = $langs->trans("ByMonthYear");
240 $head[$h][2] = 'byyear';
241 $h++;
242 
243 complete_head_from_modules($conf,$langs,null,$head,$h,'propal_stats');
244 
245 dol_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
246 
247 
248 print '<div class="fichecenter"><div class="fichethirdleft">';
249 
250 
251 //if (empty($socid))
252 //{
253  // Show filter box
254  print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
255  print '<input type="hidden" name="mode" value="'.$mode.'">';
256  print '<table class="noborder" width="100%">';
257  print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
258  // Company
259  print '<tr><td align="left">'.$langs->trans("ThirdParty").'</td><td align="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  // User
264  print '<tr><td align="left">'.$langs->trans("CreatedBy").'</td><td align="left">';
265  print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
266  print '</td></tr>';
267  // Status
268  print '<tr><td align="left">'.$langs->trans("Status").'</td><td align="left">';
269  $formpropal->selectProposalStatus(($object_status!=''?$object_status:-1),0,0,1,$mode,'object_status');
270  print '</td></tr>';
271  // Year
272  print '<tr><td align="left">'.$langs->trans("Year").'</td><td align="left">';
273  if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
274  if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear;
275  arsort($arrayyears);
276  print $form->selectarray('year',$arrayyears,$year,0);
277  print '</td></tr>';
278  print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
279  print '</table>';
280  print '</form>';
281  print '<br><br>';
282 //}
283 
284 print '<table class="noborder" width="100%">';
285 print '<tr class="liste_titre" height="24">';
286 print '<td align="center">'.$langs->trans("Year").'</td>';
287 print '<td align="right">'.$langs->trans("NbOfProposals").'</td>';
288 print '<td align="right">%</td>';
289 print '<td align="right">'.$langs->trans("AmountTotal").'</td>';
290 print '<td align="right">%</td>';
291 print '<td align="right">'.$langs->trans("AmountAverage").'</td>';
292 print '<td align="right">%</td>';
293 print '</tr>';
294 
295 $oldyear=0;
296 foreach ($data as $val)
297 {
298  $year = $val['year'];
299  while (! empty($year) && $oldyear > $year+1)
300  { // If we have empty year
301  $oldyear--;
302 
303  print '<tr class="oddeven" height="24">';
304  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>';
305  print '<td align="right">0</td>';
306  print '<td align="right"></td>';
307  print '<td align="right">0</td>';
308  print '<td align="right"></td>';
309  print '<td align="right">0</td>';
310  print '<td align="right"></td>';
311  print '</tr>';
312  }
313  print '<tr class="oddeven" height="24">';
314  print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.($socid>0?'&socid='.$socid:'').($userid>0?'&userid='.$userid:'').'">'.$year.'</a></td>';
315  print '<td align="right">'.$val['nb'].'</td>';
316  print '<td align="right" style="'.(($val['nb_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['nb_diff']).'</td>';
317  print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
318  print '<td align="right" style="'.(($val['total_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['total_diff']).'</td>';
319  print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>';
320  print '<td align="right" style="'.(($val['avg_diff'] >= 0) ? 'color: green;':'color: red;').'">'.round($val['avg_diff']).'</td>';
321  print '</tr>';
322  $oldyear=$year;
323 }
324 
325 print '</table>';
326 
327 
328 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
329 
330 
331 // Show graphs
332 print '<table class="border" width="100%"><tr valign="top"><td align="center">';
333 if ($mesg) { print $mesg; }
334 else {
335  print $px1->show();
336  print "<br>\n";
337  print $px2->show();
338  print "<br>\n";
339  print $px3->show();
340 }
341 print '</td></tr></table>';
342 
343 
344 print '</div></div></div>';
345 print '<div style="clear:both"></div>';
346 
347 
348 dol_fiche_end();
349 
350 
351 llxFooter();
352 
353 $db->close();
llxFooter()
Footer empty.
Definition: index.php:43
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
Class to manage generation of HTML components for proposal management.
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
llxHeader()
Header empty.
Definition: index.php:37
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
dol_fiche_end($notab=0)
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_now($mode='gmt')
Return date for now.
print
Draft customers invoices.
Definition: index.php:91
Class to build graphs.
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...
Class to manage proposals statistics.