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';
41 if ($mode ==
'customer' && !$user->rights->propale->lire)
accessforbidden();
42 if ($mode ==
'supplier' && !$user->rights->supplier_proposal->lire)
accessforbidden();
44 $object_status =
GETPOST(
'object_status',
'intcomma');
45 $typent_id =
GETPOST(
'typent_id',
'int');
46 $categ_id =
GETPOST(
'categ_id',
'categ_id');
48 $userid =
GETPOST(
'userid',
'int');
49 $socid =
GETPOST(
'socid',
'int');
54 $socid = $user->socid;
57 $nowyear = strftime(
"%Y",
dol_now());
60 $startyear = $year - 1;
64 $langs->loadLangs(array(
'orders',
'companies',
'other',
'suppliers',
'supplier_proposal'));
71 $form =
new Form($db);
76 $langs->loadLangs(array(
'propal',
'other',
'companies'));
78 if ($mode ==
'customer')
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"));
86 if ($mode ==
'supplier')
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"));
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)).
')';
107 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
111 if (!$user->rights->societe->client->voir || $user->socid)
113 $filenamenb = $dir.
'/proposalsnbinyear-'.$user->id.
'-'.$year.
'.png';
114 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$user->id.
'-'.$year.
'.png';
116 $filenamenb = $dir.
'/proposalsnbinyear-'.$year.
'.png';
117 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$year.
'.png';
121 $mesg = $px1->isGraphKo();
124 $px1->SetData($data);
125 $i = $startyear; $legend = array();
126 while ($i <= $endyear)
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"));
138 $px1->SetHorizTickIncrement(1);
139 $px1->mode =
'depth';
140 $px1->SetTitle($langs->trans(
"NumberOfProposalsByMonth"));
142 $px1->draw($filenamenb, $fileurlnb);
146 $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, 0);
149 if (!$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';
154 $filenameamount = $dir.
'/proposalsamountinyear-'.$year.
'.png';
155 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=propalstats&file=proposalsamountinyear-'.$year.
'.png';
159 $mesg = $px2->isGraphKo();
162 $px2->SetData($data);
163 $i = $startyear; $legend = array();
164 while ($i <= $endyear)
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"));
176 $px2->SetHorizTickIncrement(1);
177 $px2->mode =
'depth';
178 $px2->SetTitle($langs->trans(
"AmountOfProposalsByMonthHT"));
180 $px2->draw($filenameamount, $fileurlamount);
183 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
186 if (!$user->rights->societe->client->voir || $user->socid)
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';
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';
198 $mesg = $px3->isGraphKo();
201 $px3->SetData($data);
202 $i = $startyear; $legend = array();
203 while ($i <= $endyear)
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);
215 $px3->SetHorizTickIncrement(1);
216 $px3->mode =
'depth';
217 $px3->SetTitle($langs->trans(
"AmountAverage"));
219 $px3->draw($filename_avg, $fileurl_avg);
224 $data = $stats->getAllByYear();
225 $arrayyears = array();
226 foreach ($data as $val) {
227 if (!empty($val[
'year'])) {
228 $arrayyears[$val[
'year']] = $val[
'year'];
231 if (!count($arrayyears)) $arrayyears[$nowyear] = $nowyear;
236 $head[$h][0] = DOL_URL_ROOT.
'/comm/propal/stats/index.php';
237 $head[$h][1] = $langs->trans(
"ByMonthYear");
238 $head[$h][2] =
'byyear';
246 print '<div class="fichecenter"><div class="fichethirdleft">';
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.
'">';
256 print
'<table class="noborder centpercent">';
257 print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
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%"');
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);
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);
270 print
'<tr><td>'.$cat_label.
'</td><td>';
271 print $formother->select_categories($cat_type, $categ_id,
'categ_id',
true);
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');
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');
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;
286 print $form->selectarray(
'year', $arrayyears, $year, 0);
288 print
'<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
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>';
307 foreach ($data as $val)
309 $year = $val[
'year'];
310 while (!empty($year) && $oldyear > $year + 1)
314 print
'<tr class="oddeven" height="24">';
315 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.
'&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>';
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>';
339 print
'</div><div class="fichetwothirdright"><div class="ficheaddleft">';
343 print
'<table class="border centpercent"><tr class="pair nohover"><td align="center">';
344 if ($mesg) { print $mesg; }
else {
351 print
'</td></tr></table>';
354 print
'</div></div></div>';
355 print
'<div style="clear:both"></div>';
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.
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 '...
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.
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).
Class to manage proposals statistics.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)