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';
42 $object_status =
GETPOST(
'object_status',
'intcomma');
43 $typent_id =
GETPOST(
'typent_id',
'int');
44 $categ_id =
GETPOST(
'categ_id',
'categ_id');
46 $userid =
GETPOST(
'userid',
'int');
47 $socid =
GETPOST(
'socid',
'int');
49 if ($user->socid > 0) {
51 $socid = $user->socid;
54 $nowyear = strftime(
"%Y",
dol_now());
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)));
60 $langs->loadLangs(array(
'orders',
'companies',
'other',
'suppliers',
'supplier_proposal'));
62 if ($mode ==
'customer' && !$user->rights->propale->lire) {
65 if ($mode ==
'supplier' && !$user->rights->supplier_proposal->lire) {
79 $langs->loadLangs(array(
'propal',
'other',
'companies'));
81 if ($mode ==
'customer') {
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"));
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"));
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).
')';
110 $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
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';
118 $filenamenb = $dir.
'/proposalsnbinyear-'.$year.
'.png';
119 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$year.
'.png';
123 $mesg = $px1->isGraphKo();
125 $px1->SetData($data);
128 while ($i <= $endyear) {
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"));
139 $px1->SetHorizTickIncrement(1);
140 $px1->mode =
'depth';
141 $px1->SetTitle($langs->trans(
"NumberOfProposalsByMonth"));
143 $px1->draw($filenamenb, $fileurlnb);
147 $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, 0);
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';
154 $filenameamount = $dir.
'/proposalsamountinyear-'.$year.
'.png';
155 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=propalstats&file=proposalsamountinyear-'.$year.
'.png';
159 $mesg = $px2->isGraphKo();
161 $px2->SetData($data);
164 while ($i <= $endyear) {
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"));
175 $px2->SetHorizTickIncrement(1);
176 $px2->mode =
'depth';
177 $px2->SetTitle($langs->trans(
"AmountOfProposalsByMonthHT"));
179 $px2->draw($filenameamount, $fileurlamount);
182 $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
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';
190 if ($mode ==
'supplier') {
191 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
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';
198 if ($mode ==
'supplier') {
199 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.
'.png';
204 $mesg = $px3->isGraphKo();
206 $px3->SetData($data);
209 while ($i <= $endyear) {
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);
220 $px3->SetHorizTickIncrement(1);
221 $px3->mode =
'depth';
222 $px3->SetTitle($langs->trans(
"AmountAverage"));
224 $px3->draw($filename_avg, $fileurl_avg);
229 $data = $stats->getAllByYear();
230 $arrayyears = array();
231 foreach ($data as $val) {
232 if (!empty($val[
'year'])) {
233 $arrayyears[$val[
'year']] = $val[
'year'];
236 if (!count($arrayyears)) {
237 $arrayyears[$nowyear] = $nowyear;
243 $head[$h][0] = DOL_URL_ROOT.
'/comm/propal/stats/index.php';
244 $head[$h][1] = $langs->trans(
"ByMonthYear");
245 $head[$h][2] =
'byyear';
253 print
'<div class="fichecenter"><div class="fichethirdleft">';
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.
'">';
261 print
'<table class="noborder centpercent">';
262 print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
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',
'');
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);
272 print
$form->selectarray(
"typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0,
'', 0, 0, 0, $sortparam_typent,
'', 1);
274 print
' '.info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
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');
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');
288 print
'<tr><td>'.$langs->trans(
"Status").
'</td><td>';
289 $formpropal->selectProposalStatus(($object_status !=
'' ? $object_status : -1), 0, 0, 1, $mode,
'object_status');
292 print
'<tr><td>'.$langs->trans(
"Year").
'</td><td>';
293 if (!in_array($year, $arrayyears)) {
294 $arrayyears[$year] = $year;
296 if (!in_array($nowyear, $arrayyears)) {
297 $arrayyears[$nowyear] = $nowyear;
300 print
$form->selectarray(
'year', $arrayyears, $year, 0, 0, 0,
'', 0, 0, 0,
'',
'width75');
302 print
'<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
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>';
320 foreach ($data as $val) {
321 $year = $val[
'year'];
322 while (!empty($year) && $oldyear > $year + 1) {
325 print
'<tr class="oddeven" height="24">';
326 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.
'&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>';
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>';
350 print
'</div><div class="fichetwothirdright">';
354 print
'<table class="border centpercent"><tr class="pair nohover"><td align="center">';
364 print
'</td></tr></table>';
367 print
'</div></div>';
368 print
'<div style="clear:both"></div>';