32require
'../../../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propalestats.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formpropal.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
51$mode = GETPOSTISSET(
"mode") ?
GETPOST(
"mode",
'aZ09') :
'customer';
53$hookmanager->initHooks(array(
'propalstats',
'globalcard'));
55$object_status =
GETPOST(
'object_status',
'intcomma');
58$select_categ_propal_id=
GETPOST(
'select_categ_propal_id',
'array');
63if ($user->socid > 0) {
65 $socid = $user->socid;
69$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
80$langs->loadLangs(array(
'orders',
'companies',
'other',
'suppliers',
'supplier_proposal'));
82if ($mode ==
'customer' && !$user->hasRight(
'propal',
'lire')) {
85if ($mode ==
'supplier' && !$user->hasRight(
'supplier_proposal',
'lire')) {
99$langs->loadLangs(array(
'propal',
'other',
'companies'));
102$title = $langs->trans(
"ProposalsStatistics");
103$dir = $conf->propal->dir_temp;
104$cat_type = Categorie::TYPE_CUSTOMER;
105$cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Customer"));
107if ($mode ==
'supplier') {
108 $picto =
'supplier_proposal';
109 $title = $langs->trans(
"ProposalsStatisticsSuppliers");
110 $dir = $conf->supplier_proposal->dir_temp;
111 $cat_type = Categorie::TYPE_SUPPLIER;
112 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Supplier"));
123$stats =
new PropaleStats($db, $socid, ($userid > 0 ? $userid : 0), $mode, ($typent_id > 0 ? $typent_id : 0), ($categ_id > 0 ? $categ_id : 0));
124if ($object_status !=
'' && $object_status >= 0) {
125 $stats->where .=
' AND p.fk_statut IN ('.$db->sanitize($object_status).
')';
129$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
131if ($mode ==
'customer') {
132 if (is_array($select_categ_propal_id) && !empty($select_categ_propal_id)) {
133 $stats->from .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'categorie_propal as cat ON (p.rowid = cat.fk_propal)';
134 $stats->where .=
' AND cat.fk_categorie IN ('.$db->sanitize(implode(
',', $select_categ_propal_id)).
')';
137if ($mode ==
'supplier') {
138 if (is_array($select_categ_propal_id) && !empty($select_categ_propal_id)) {
139 $stats->from .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'categorie_supplier_proposal as cat ON (p.rowid = cat.fk_supplier_proposal)';
140 $stats->where .=
' AND cat.fk_categorie IN ('.$db->sanitize(implode(
',', $select_categ_propal_id)).
')';
144if (!$user->hasRight(
'societe',
'client',
'voir')) {
145 $filenamenb = $dir.
'/proposalsnbinyear-'.$user->id.
'-'.$year.
'.png';
146 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$user->id.
'-'.$year.
'.png';
148 $filenamenb = $dir.
'/proposalsnbinyear-'.$year.
'.png';
149 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$year.
'.png';
153$mesg = $px1->isGraphKo();
155 $px1->SetData($data);
158 while ($i <= $endyear) {
162 $px1->SetLegend($legend);
163 $px1->SetMaxValue($px1->GetCeilMaxValue());
164 $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
165 $px1->SetWidth($WIDTH);
166 $px1->SetHeight($HEIGHT);
167 $px1->SetYLabel($langs->trans(
"NbOfProposals"));
169 $px1->SetHorizTickIncrement(1);
170 $px1->mode =
'depth';
171 $px1->SetTitle($langs->trans(
"NumberOfProposalsByMonth"));
173 $px1->draw($filenamenb, $fileurlnb);
177$data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, 0);
180if (!$user->hasRight(
'societe',
'client',
'voir')) {
181 $filenameamount = $dir.
'/proposalsamountinyear-'.$user->id.
'-'.$year.
'.png';
182 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=propalstats&file=proposalsamountinyear-'.$user->id.
'-'.$year.
'.png';
184 $filenameamount = $dir.
'/proposalsamountinyear-'.$year.
'.png';
185 $fileurlamount = DOL_URL_ROOT.
'/viewimage.php?modulepart=propalstats&file=proposalsamountinyear-'.$year.
'.png';
189$mesg = $px2->isGraphKo();
191 $px2->SetData($data);
194 while ($i <= $endyear) {
198 $px2->SetLegend($legend);
199 $px2->SetMaxValue($px2->GetCeilMaxValue());
200 $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
201 $px2->SetWidth($WIDTH);
202 $px2->SetHeight($HEIGHT);
203 $px2->SetYLabel($langs->trans(
"AmountOfProposals"));
205 $px2->SetHorizTickIncrement(1);
206 $px2->mode =
'depth';
207 $px2->SetTitle($langs->trans(
"AmountOfProposalsByMonthHT"));
209 $px2->draw($filenameamount, $fileurlamount);
212$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
215if (!$user->hasRight(
'societe',
'client',
'voir')) {
216 $filename_avg = $dir.
'/ordersaverage-'.$user->id.
'-'.$year.
'.png';
217 if ($mode ==
'customer') {
218 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
220 if ($mode ==
'supplier') {
221 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.
'-'.$year.
'.png';
224 $filename_avg = $dir.
'/ordersaverage-'.$year.
'.png';
225 if ($mode ==
'customer') {
226 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.
'.png';
228 if ($mode ==
'supplier') {
229 $fileurl_avg = DOL_URL_ROOT.
'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.
'.png';
234$mesg = $px3->isGraphKo();
236 $px3->SetData($data);
239 while ($i <= $endyear) {
243 $px3->SetLegend($legend);
244 $px3->SetYLabel($langs->trans(
"AmountAverage"));
245 $px3->SetMaxValue($px3->GetCeilMaxValue());
246 $px3->SetMinValue((
int) $px3->GetFloorMinValue());
247 $px3->SetWidth($WIDTH);
248 $px3->SetHeight($HEIGHT);
250 $px3->SetHorizTickIncrement(1);
251 $px3->mode =
'depth';
252 $px3->SetTitle($langs->trans(
"AmountAverage"));
254 $px3->draw($filename_avg, $fileurl_avg);
259$data = $stats->getAllByYear();
260$arrayyears = array();
261foreach ($data as $val) {
262 if (!empty($val[
'year'])) {
263 $arrayyears[$val[
'year']] = $val[
'year'];
266if (!count($arrayyears)) {
267 $arrayyears[$nowyear] = $nowyear;
273$head[$h][0] = DOL_URL_ROOT.
'/comm/propal/stats/index.php';
274$head[$h][1] = $langs->trans(
"ByMonthYear");
275$head[$h][2] =
'byyear';
283print
'<div class="fichecenter"><div class="fichethirdleft">';
287print
'<form name="stats" method="POST" action="'.dolBuildUrl($_SERVER[
"PHP_SELF"]).
'">';
288print
'<input type="hidden" name="token" value="'.newToken().
'">';
289print
'<input type="hidden" name="mode" value="'.$mode.
'">';
291print
'<table class="noborder centpercent">';
292print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
294print
'<tr><td class="left">'.$langs->trans(
"ThirdParty").
'</td><td class="left">';
295print
img_picto(
'',
'company',
'class="pictofixedwidth"');
296$filter =
'(s.client:IN:1,2,3)';
297print $form->select_company($socid,
'socid', $filter, 1, 0, 0, array(), 0,
'widthcentpercentminusx maxwidth300',
'');
300print
'<tr><td>'.$langs->trans(
"ThirdPartyType").
'</td><td>';
301$sortparam_typent = (!
getDolGlobalString(
'SOCIETE_SORT_ON_TYPEENT') ?
'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT);
302print $form->selectarray(
"typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0,
'', 0, 0, 0, $sortparam_typent,
'', 1);
304 print
' '.info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
308print
'<tr><td>'.$cat_label.
'</td><td>';
309print
img_picto(
'',
'category',
'class="pictofixedwidth"');
310print $formother->select_categories($cat_type, $categ_id,
'categ_id', 0, 1,
'widthcentpercentminusx maxwidth300');
316 if ($mode ==
'customer') {
317 $cat_type = Categorie::TYPE_PROPOSAL;
318 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"Proposals"));
320 if ($mode ==
'supplier') {
321 $cat_type = Categorie::TYPE_SUPPLIER_PROPOSAL;
322 $cat_label = $langs->trans(
"Category").
' '.lcfirst($langs->trans(
"SupplierProposals"));
324 print
'<tr><td>'.$cat_label.
'</td><td>';
325 $cate_arbo = $form->select_all_categories($cat_type,
'',
'parent', 0, 0, 1);
326 print
img_picto(
'',
'category',
'class="pictofixedwidth"');
327 print $form->multiselectarray(
'select_categ_propal_id', $cate_arbo,
GETPOST(
'select_categ_propal_id',
'array'), 0, 0,
'widthcentpercentminusx maxwidth300');
332print
'<tr><td>'.$langs->trans(
"CreatedBy").
'</td><td>';
333print
img_picto(
'',
'user',
'class="pictofixedwidth"');
334print $form->select_dolusers($userid,
'userid', 1,
null, 0,
'',
'',
'0', 0, 0,
'', 0,
'',
'widthcentpercentminusx maxwidth300');
337print
'<tr><td>'.$langs->trans(
"Status").
'</td><td>';
338$formpropal->selectProposalStatus(($object_status !=
'' ? $object_status : -1), 0, 0, 1, $mode,
'object_status');
341print
'<tr><td>'.$langs->trans(
"Year").
'</td><td>';
342if (!in_array($year, $arrayyears)) {
343 $arrayyears[$year] = $year;
345if (!in_array($nowyear, $arrayyears)) {
346 $arrayyears[$nowyear] = $nowyear;
349print
img_picto(
'',
'calendar',
'class="pictofixedwidth"');
350print $form->selectarray(
'year', $arrayyears, $year, 0, 0, 0,
'', 0, 0, 0,
'',
'width75');
352print
'<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans(
"Refresh").
'"></td></tr>';
357print
'<div class="div-table-responsive-no-min">';
358print
'<table class="noborder centpercent">';
359print
'<tr class="liste_titre" height="24">';
360print
'<td class="center">'.$langs->trans(
"Year").
'</td>';
361print
'<td class="right">'.$langs->trans(
"NbOfProposals").
'</td>';
362print
'<td class="right">%</td>';
363print
'<td class="right">'.$langs->trans(
"AmountTotal").
'</td>';
364print
'<td class="right">%</td>';
365print
'<td class="right">'.$langs->trans(
"AmountAverage").
'</td>';
366print
'<td class="right">%</td>';
370foreach ($data as $val) {
371 $year = $val[
'year'];
372 while (!empty($year) && $oldyear > (
int) $year + 1) {
375 print
'<tr class="oddeven" height="24">';
376 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$oldyear.
'&mode='.$mode.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$oldyear.
'</a></td>';
377 print
'<td class="right">0</td>';
378 print
'<td class="right"></td>';
379 print
'<td class="right">0</td>';
380 print
'<td class="right"></td>';
381 print
'<td class="right">0</td>';
382 print
'<td class="right"></td>';
385 print
'<tr class="oddeven" height="24">';
386 print
'<td align="center"><a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.($socid > 0 ?
'&socid='.$socid :
'').($userid > 0 ?
'&userid='.$userid :
'').
'">'.$year.
'</a></td>';
387 print
'<td class="right">'.$val[
'nb'].
'</td>';
388 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>';
389 print
'<td class="right">'.price(
price2num($val[
'total'],
'MT'), 1).
'</td>';
390 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>';
391 print
'<td class="right">'.price(
price2num($val[
'avg'],
'MT'), 1).
'</td>';
392 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>';
400print
'</div><div class="fichetwothirdright">';
404print
'<table class="border centpercent"><tr class="pair nohover"><td align="center">';
414print
'</td></tr></table>';
418print
'<div class="clearboth"></div>';
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Class to manage proposals statistics.
dol_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.