PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/compta/deplacement/stats/index.php

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