PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/propal/stats/index.php

https://bitbucket.org/speedealing/speedealing
PHP | 309 lines | 218 code | 46 blank | 45 comment | 31 complexity | 8682862f12efbfba03b126a87fb3548e MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/comm/propal/stats/index.php
  22. * \ingroup propale
  23. * \brief Page des stats propositions commerciales
  24. */
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/propal/class/propalestats.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  28. $WIDTH=500;
  29. $HEIGHT=200;
  30. $userid=GETPOST('userid','alpha'); if (empty($userid)) $userid=null;
  31. $socid=GETPOST('socid','alpha'); if (empty($socid)) $socid=null;
  32. // Security check
  33. if (!empty($user->societe_id))
  34. {
  35. $action = '';
  36. $socid = $user->societe_id;
  37. }
  38. $nowyear=strftime("%Y", dol_now());
  39. $year = GETPOST('year')>0?GETPOST('year'):$nowyear;
  40. //$startyear=$year-2;
  41. $startyear=$year-1;
  42. $endyear=$year;
  43. /*
  44. * View
  45. */
  46. $form=new Form($db);
  47. $langs->load("propal");
  48. llxHeader();
  49. print_fiche_titre($langs->trans("ProposalsStatistics"));
  50. $dir=$conf->propal->dir_temp;
  51. dol_mkdir($dir);
  52. $stats = new PropaleStats($db, $socid, $userid);
  53. // Build graphic number of object
  54. $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
  55. // $data = array(array('Lib',val1,val2,val3),...)
  56. if (!$user->rights->societe->client->voir || $user->societe_id)
  57. {
  58. $filenamenb = $dir.'/proposalsnbinyear-'.$user->id.'-'.$year.'.png';
  59. $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$user->id.'-'.$year.'.png';
  60. }
  61. else
  62. {
  63. $filenamenb = $dir.'/proposalsnbinyear-'.$year.'.png';
  64. $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$year.'.png';
  65. }
  66. $px1 = new DolGraph();
  67. $mesg = $px1->isGraphKo();
  68. if (! $mesg)
  69. {
  70. $px1->SetData($data);
  71. $px1->SetPrecisionY(0);
  72. $i=$startyear;$legend=array();
  73. while ($i <= $endyear)
  74. {
  75. $legend[]=$i;
  76. $i++;
  77. }
  78. $px1->SetLegend($legend);
  79. $px1->SetMaxValue($px1->GetCeilMaxValue());
  80. $px1->SetMinValue(min(0,$px1->GetFloorMinValue()));
  81. $px1->SetWidth($WIDTH);
  82. $px1->SetHeight($HEIGHT);
  83. $px1->SetYLabel($langs->trans("NbOfProposals"));
  84. $px1->SetShading(3);
  85. $px1->SetHorizTickIncrement(1);
  86. $px1->SetPrecisionY(0);
  87. $px1->mode='depth';
  88. $px1->SetTitle($langs->trans("NumberOfProposalsByMonth"));
  89. $px1->draw($filenamenb,$fileurlnb);
  90. }
  91. // Build graphic amount of object
  92. $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
  93. // $data = array(array('Lib',val1,val2,val3),...)
  94. if (!$user->rights->societe->client->voir || $user->societe_id)
  95. {
  96. $filenameamount = $dir.'/proposalsamountinyear-'.$user->id.'-'.$year.'.png';
  97. $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsamountinyear-'.$user->id.'-'.$year.'.png';
  98. }
  99. else
  100. {
  101. $filenameamount = $dir.'/proposalsamountinyear-'.$year.'.png';
  102. $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsamountinyear-'.$year.'.png';
  103. }
  104. $px2 = new DolGraph();
  105. $mesg = $px2->isGraphKo();
  106. if (! $mesg)
  107. {
  108. $px2->SetData($data);
  109. $px2->SetPrecisionY(0);
  110. $i=$startyear;$legend=array();
  111. while ($i <= $endyear)
  112. {
  113. $legend[]=$i;
  114. $i++;
  115. }
  116. $px2->SetLegend($legend);
  117. $px2->SetMaxValue($px2->GetCeilMaxValue());
  118. $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
  119. $px2->SetWidth($WIDTH);
  120. $px2->SetHeight($HEIGHT);
  121. $px2->SetYLabel($langs->trans("AmountOfProposals"));
  122. $px2->SetShading(3);
  123. $px2->SetHorizTickIncrement(1);
  124. $px2->SetPrecisionY(0);
  125. $px2->mode='depth';
  126. $px2->SetTitle($langs->trans("AmountOfProposalsByMonthHT"));
  127. $px2->draw($filenameamount,$fileurlamount);
  128. }
  129. $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
  130. $fileurl_avg='';
  131. if (! isset($mode)) $mode=''; // TODO $mode not defined ?
  132. if (!$user->rights->societe->client->voir || $user->societe_id)
  133. {
  134. $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
  135. if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
  136. if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
  137. }
  138. else
  139. {
  140. $filename_avg = $dir.'/ordersaverage-'.$year.'.png';
  141. if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
  142. if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
  143. }
  144. $px3 = new DolGraph();
  145. $mesg = $px3->isGraphKo();
  146. if (! $mesg)
  147. {
  148. $px3->SetData($data);
  149. $i=$startyear;$legend=array();
  150. while ($i <= $endyear)
  151. {
  152. $legend[]=$i;
  153. $i++;
  154. }
  155. $px3->SetLegend($legend);
  156. $px3->SetYLabel($langs->trans("AmountAverage"));
  157. $px3->SetMaxValue($px3->GetCeilMaxValue());
  158. $px3->SetMinValue($px3->GetFloorMinValue());
  159. $px3->SetWidth($WIDTH);
  160. $px3->SetHeight($HEIGHT);
  161. $px3->SetShading(3);
  162. $px3->SetHorizTickIncrement(1);
  163. $px3->SetPrecisionY(0);
  164. $px3->mode='depth';
  165. $px3->SetTitle($langs->trans("AmountAverage"));
  166. $px3->draw($filename_avg,$fileurl_avg);
  167. }
  168. // Show array
  169. $data = $stats->getAllByYear();
  170. $arrayyears=array();
  171. foreach($data as $val) {
  172. if (! empty($val['year'])) {
  173. $arrayyears[$val['year']]=$val['year'];
  174. }
  175. }
  176. if (! count($arrayyears)) $arrayyears[$nowyear]=$nowyear;
  177. $h=0;
  178. $head = array();
  179. $head[$h][0] = DOL_URL_ROOT . '/comm/propal/stats/index.php';
  180. $head[$h][1] = $langs->trans("ByMonthYear");
  181. $head[$h][2] = 'byyear';
  182. $h++;
  183. $object=new stdClass(); // TODO $object not defined ?
  184. complete_head_from_modules($conf,$langs,$object,$head,$h,'propal_stats');
  185. dol_fiche_head($head,'byyear',$langs->trans("Statistics"));
  186. print '<table class="notopnoleftnopadd" width="100%"><tr>';
  187. print '<td align="center" valign="top">';
  188. //if (empty($socid))
  189. //{
  190. // Show filter box
  191. print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  192. print '<input type="hidden" name="mode" value="'.$mode.'">';
  193. print '<table class="border" width="100%">';
  194. print '<tr><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
  195. // Company
  196. print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
  197. $filter='s.client in (1,2,3)';
  198. print $form->select_company($socid,'socid',$filter,1);
  199. print '</td></tr>';
  200. // User
  201. // print '<tr><td>'.$langs->trans("User").'/'.$langs->trans("SalesRepresentative").'</td><td>';
  202. // print $form->select_users($userid,'userid',1);
  203. // print '</td></tr>';
  204. // Year
  205. print '<tr><td>'.$langs->trans("Year").'</td><td>';
  206. if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
  207. arsort($arrayyears);
  208. print $form->selectarray('year',$arrayyears,$year,0);
  209. print '</td></tr>';
  210. print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
  211. print '</table>';
  212. print '</form>';
  213. print '<br><br>';
  214. //}
  215. print '<table class="border" width="100%">';
  216. print '<tr height="24">';
  217. print '<td align="center">'.$langs->trans("Year").'</td>';
  218. print '<td align="center">'.$langs->trans("NbOfProposals").'</td>';
  219. print '<td align="center">'.$langs->trans("AmountTotal").'</td>';
  220. print '<td align="center">'.$langs->trans("AmountAverage").'</td>';
  221. print '</tr>';
  222. $oldyear=0;
  223. foreach ($data as $val)
  224. {
  225. $year = $val['year'];
  226. //print $avg; // TODO $avg not defined ?
  227. while (! empty($year) && $oldyear > $year+1)
  228. { // If we have empty year
  229. $oldyear--;
  230. print '<tr height="24">';
  231. print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&amp;mode='.$mode.'">'.$oldyear.'</a></td>';
  232. print '<td align="right">0</td>';
  233. print '<td align="right">0</td>';
  234. print '<td align="right">0</td>';
  235. print '</tr>';
  236. }
  237. print '<tr height="24">';
  238. print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'">'.$year.'</a></td>';
  239. print '<td align="right">'.$val['nb'].'</td>';
  240. print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
  241. print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>';
  242. print '</tr>';
  243. $oldyear=$year;
  244. }
  245. print '</table>';
  246. print '</td>';
  247. print '<td align="center" valign="top">';
  248. // Show graphs
  249. print '<table class="border" width="100%"><tr valign="top"><td align="center">';
  250. if ($mesg) { print $mesg; }
  251. else {
  252. print $px1->show();
  253. print "<br>\n";
  254. print $px2->show();
  255. print "<br>\n";
  256. print $px3->show();
  257. }
  258. print '</td></tr></table>';
  259. print '</td></tr></table>';
  260. dol_fiche_end();
  261. llxFooter();
  262. $db->close();
  263. ?>