PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/comm/propal/stats/index.php

https://github.com/asterix14/dolibarr
PHP | 227 lines | 157 code | 35 blank | 35 comment | 14 complexity | 3759fba6db06573c8e0b1e72b7914b9b MD5 | raw file
Possible License(s): LGPL-2.0
  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-2009 Regis Houssin <regis@dolibarr.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/comm/propal/stats/index.php
  21. * \ingroup propale
  22. * \brief Page des stats propositions commerciales
  23. */
  24. require("../../../main.inc.php");
  25. require_once(DOL_DOCUMENT_ROOT."/comm/propal/class/propalestats.class.php");
  26. require_once(DOL_DOCUMENT_ROOT."/core/class/dolgraph.class.php");
  27. $WIDTH=500;
  28. $HEIGHT=200;
  29. $userid=GETPOST('userid'); if ($userid < 0) $userid=0;
  30. $socid=GETPOST('socid'); if ($socid < 0) $socid=0;
  31. // Security check
  32. if ($user->societe_id > 0)
  33. {
  34. $action = '';
  35. $socid = $user->societe_id;
  36. }
  37. $year = strftime("%Y", time());
  38. $startyear=$year-2;
  39. $endyear=$year;
  40. /*
  41. * View
  42. */
  43. $form=new Form($db);
  44. $langs->load("propal");
  45. llxHeader();
  46. print_fiche_titre($langs->trans("ProposalsStatistics"), $mesg);
  47. $dir=$conf->propale->dir_temp;
  48. create_exdir($dir);
  49. $stats = new PropaleStats($db, $socid, $userid);
  50. // Build graphic number of object
  51. $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
  52. //var_dump($data);
  53. // $data = array(array('Lib',val1,val2,val3),...)
  54. if (!$user->rights->societe->client->voir || $user->societe_id)
  55. {
  56. $filenamenb = $dir.'/proposalsnbinyear-'.$user->id.'-'.$year.'.png';
  57. $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$user->id.'-'.$year.'.png';
  58. }
  59. else
  60. {
  61. $filenamenb = $dir.'/proposalsnbinyear-'.$year.'.png';
  62. $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$year.'.png';
  63. }
  64. $px = new DolGraph();
  65. $mesg = $px->isGraphKo();
  66. if (! $mesg)
  67. {
  68. $px->SetData($data);
  69. $px->SetPrecisionY(0);
  70. $i=$startyear;
  71. while ($i <= $endyear)
  72. {
  73. $legend[]=$i;
  74. $i++;
  75. }
  76. $px->SetLegend($legend);
  77. $px->SetMaxValue($px->GetCeilMaxValue());
  78. $px->SetMinValue(min(0,$px->GetFloorMinValue()));
  79. $px->SetWidth($WIDTH);
  80. $px->SetHeight($HEIGHT);
  81. $px->SetYLabel($langs->trans("NbOfProposals"));
  82. $px->SetShading(3);
  83. $px->SetHorizTickIncrement(1);
  84. $px->SetPrecisionY(0);
  85. $px->mode='depth';
  86. $px->SetTitle($langs->trans("NumberOfProposalsByMonth"));
  87. $px->draw($filenamenb);
  88. }
  89. // Build graphic amount of object
  90. $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
  91. //var_dump($data);
  92. // $data = array(array('Lib',val1,val2,val3),...)
  93. if (!$user->rights->societe->client->voir || $user->societe_id)
  94. {
  95. $filenameamount = $dir.'/proposalsamountinyear-'.$user->id.'-'.$year.'.png';
  96. $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsamountinyear-'.$user->id.'-'.$year.'.png';
  97. }
  98. else
  99. {
  100. $filenameamount = $dir.'/proposalsamountinyear-'.$year.'.png';
  101. $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsamountinyear-'.$year.'.png';
  102. }
  103. $px = new DolGraph();
  104. $mesg = $px->isGraphKo();
  105. if (! $mesg)
  106. {
  107. $px->SetData($data);
  108. $px->SetPrecisionY(0);
  109. $i=$startyear;
  110. while ($i <= $endyear)
  111. {
  112. $legend[]=$i;
  113. $i++;
  114. }
  115. $px->SetLegend($legend);
  116. $px->SetMaxValue($px->GetCeilMaxValue());
  117. $px->SetMinValue(min(0,$px->GetFloorMinValue()));
  118. $px->SetWidth($WIDTH);
  119. $px->SetHeight($HEIGHT);
  120. $px->SetYLabel($langs->trans("AmountOfProposals"));
  121. $px->SetShading(3);
  122. $px->SetHorizTickIncrement(1);
  123. $px->SetPrecisionY(0);
  124. $px->mode='depth';
  125. $px->SetTitle($langs->trans("AmountOfProposalsByMonthHT"));
  126. $px->draw($filenameamount);
  127. }
  128. print '<table class="notopnoleftnopadd" width="100%"><tr>';
  129. print '<td align="center" valign="top">';
  130. // Show filter box
  131. print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  132. print '<table class="border" width="100%">';
  133. print '<tr><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
  134. print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
  135. $filter='s.client in (1,2,3)';
  136. print $form->select_company($socid,'socid',$filter,1);
  137. print '</td></tr>';
  138. print '<tr><td>'.$langs->trans("User").'</td><td>';
  139. print $form->select_users($userid,'userid',1);
  140. print '</td></tr>';
  141. print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
  142. print '</table>';
  143. print '</form>';
  144. print '<br><br>';
  145. // Show array
  146. $data = $stats->getAllByYear();
  147. print '<table class="border" width="100%">';
  148. print '<tr height="24">';
  149. print '<td align="center">'.$langs->trans("Year").'</td>';
  150. print '<td align="center">'.$langs->trans("NbOfProposals").'</td>';
  151. print '<td align="center">'.$langs->trans("AmountTotal").'</td>';
  152. print '<td align="center">'.$langs->trans("AmountAverage").'</td>';
  153. print '</tr>';
  154. $oldyear=0;
  155. foreach ($data as $val)
  156. {
  157. $year = $val['year'];
  158. print $avg;
  159. while ($oldyear > $year+1)
  160. { // If we have empty year
  161. $oldyear--;
  162. print '<tr height="24">';
  163. print '<td align="center"><a href="month.php?year='.$oldyear.'&amp;mode='.$mode.'">'.$oldyear.'</a></td>';
  164. print '<td align="right">0</td>';
  165. print '<td align="right">0</td>';
  166. print '<td align="right">0</td>';
  167. print '</tr>';
  168. }
  169. print '<tr height="24">';
  170. print '<td align="center"><a href="month.php?year='.$year.'">'.$year.'</a></td>';
  171. print '<td align="right">'.$val['nb'].'</td>';
  172. print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
  173. print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>';
  174. print '</tr>';
  175. $oldyear=$year;
  176. }
  177. print '</table>';
  178. print '</td>';
  179. print '<td align="center" valign="top">';
  180. // Show graphs
  181. print '<table class="border" width="100%"><tr valign="top"><td align="center">';
  182. if ($mesg) { print $mesg; }
  183. else {
  184. print '<img src="'.$fileurlnb.'" title="'.$langs->trans("NbOfProposals").'" alt="'.$langs->trans("NbOfProposals").'">';
  185. print "<br>\n";
  186. print '<img src="'.$fileurlamount.'" title="'.$langs->trans("AmountTotal").'" alt="'.$langs->trans("AmountTotal").'">';
  187. }
  188. print '</td></tr></table>';
  189. print '</td></tr></table>';
  190. $db->close();
  191. llxFooter();
  192. ?>