index.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <?php
  2. /* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (c) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
  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 3 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/compta/deplacement/stats/index.php
  21. * \ingroup deplacement
  22. * \brief Page des stats deplacement et notes de frais
  23. */
  24. require '../../../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacementstats.class.php';
  27. $langs->load("trips");
  28. $WIDTH=DolGraph::getDefaultGraphSizeForStats('width');
  29. $HEIGHT=DolGraph::getDefaultGraphSizeForStats('height');
  30. $userid=GETPOST('userid','int'); if ($userid < 0) $userid=0;
  31. $socid=GETPOST('socid','int'); if ($socid < 0) $socid=0;
  32. $id = GETPOST('id','int');
  33. // Security check
  34. if ($user->societe_id > 0)
  35. {
  36. $action = '';
  37. $socid = $user->societe_id;
  38. }
  39. if ($user->societe_id) $socid=$user->societe_id;
  40. $result = restrictedArea($user, 'deplacement', $id,'');
  41. $nowyear=strftime("%Y", dol_now());
  42. $year = GETPOST('year')>0?GETPOST('year'):$nowyear;
  43. //$startyear=$year-2;
  44. $startyear=$year-1;
  45. $endyear=$year;
  46. $mode=GETPOST("mode")?GETPOST("mode"):'customer';
  47. /*
  48. * View
  49. */
  50. $form=new Form($db);
  51. llxHeader();
  52. $title=$langs->trans("TripsAndExpensesStatistics");
  53. $dir=$conf->deplacement->dir_temp;
  54. print_fiche_titre($title, $mesg);
  55. dol_mkdir($dir);
  56. $stats = new DeplacementStats($db, $socid, $userid);
  57. // Build graphic number of object
  58. // $data = array(array('Lib',val1,val2,val3),...)
  59. //print "$endyear, $startyear";
  60. $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
  61. //var_dump($data);
  62. $filenamenb = $dir."/tripsexpensesnbinyear-".$year.".png";
  63. $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=tripsexpensesstats&amp;file=tripsexpensesnbinyear-'.$year.'.png';
  64. $px1 = new DolGraph();
  65. $mesg = $px1->isGraphKo();
  66. if (! $mesg)
  67. {
  68. $px1->SetData($data);
  69. $px1->SetPrecisionY(0);
  70. $i=$startyear;$legend=array();
  71. while ($i <= $endyear)
  72. {
  73. $legend[]=$i;
  74. $i++;
  75. }
  76. $px1->SetLegend($legend);
  77. $px1->SetMaxValue($px1->GetCeilMaxValue());
  78. $px1->SetWidth($WIDTH);
  79. $px1->SetHeight($HEIGHT);
  80. $px1->SetYLabel($langs->trans("Number"));
  81. $px1->SetShading(3);
  82. $px1->SetHorizTickIncrement(1);
  83. $px1->SetPrecisionY(0);
  84. $px1->mode='depth';
  85. $px1->SetTitle($langs->trans("NumberByMonth"));
  86. $px1->draw($filenamenb,$fileurlnb);
  87. }
  88. // Build graphic amount of object
  89. $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
  90. //var_dump($data);
  91. // $data = array(array('Lib',val1,val2,val3),...)
  92. $filenameamount = $dir."/tripsexpensesamountinyear-".$year.".png";
  93. $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=tripsexpensesstats&amp;file=tripsexpensesamountinyear-'.$year.'.png';
  94. $px2 = new DolGraph();
  95. $mesg = $px2->isGraphKo();
  96. if (! $mesg)
  97. {
  98. $px2->SetData($data);
  99. $i=$startyear;$legend=array();
  100. while ($i <= $endyear)
  101. {
  102. $legend[]=$i;
  103. $i++;
  104. }
  105. $px2->SetLegend($legend);
  106. $px2->SetMaxValue($px2->GetCeilMaxValue());
  107. $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
  108. $px2->SetWidth($WIDTH);
  109. $px2->SetHeight($HEIGHT);
  110. $px2->SetYLabel($langs->trans("Amount"));
  111. $px2->SetShading(3);
  112. $px2->SetHorizTickIncrement(1);
  113. $px2->SetPrecisionY(0);
  114. $px2->mode='depth';
  115. $px2->SetTitle($langs->trans("AmountTotal"));
  116. $px2->draw($filenameamount,$fileurlamount);
  117. }
  118. $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
  119. if (!$user->rights->societe->client->voir || $user->societe_id)
  120. {
  121. $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
  122. if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
  123. if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
  124. }
  125. else
  126. {
  127. $filename_avg = $dir.'/ordersaverage-'.$year.'.png';
  128. if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
  129. if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
  130. }
  131. $px3 = new DolGraph();
  132. $mesg = $px3->isGraphKo();
  133. if (! $mesg)
  134. {
  135. $px3->SetData($data);
  136. $i = $startyear;$legend=array();
  137. while ($i <= $endyear)
  138. {
  139. $legend[]=$i;
  140. $i++;
  141. }
  142. $px3->SetLegend($legend);
  143. $px3->SetYLabel($langs->trans("AmountAverage"));
  144. $px3->SetMaxValue($px3->GetCeilMaxValue());
  145. $px3->SetMinValue($px3->GetFloorMinValue());
  146. $px3->SetWidth($WIDTH);
  147. $px3->SetHeight($HEIGHT);
  148. $px3->SetShading(3);
  149. $px3->SetHorizTickIncrement(1);
  150. $px3->SetPrecisionY(0);
  151. $px3->mode='depth';
  152. $px3->SetTitle($langs->trans("AmountAverage"));
  153. $px3->draw($filename_avg,$fileurl_avg);
  154. }
  155. // Show array
  156. $data = $stats->getAllByYear();
  157. $arrayyears=array();
  158. foreach($data as $val) {
  159. $arrayyears[$val['year']]=$val['year'];
  160. }
  161. if (! count($arrayyears)) $arrayyears[$nowyear]=$nowyear;
  162. $h=0;
  163. $head = array();
  164. $head[$h][0] = DOL_URL_ROOT . '/compta/deplacement/stats/index.php';
  165. $head[$h][1] = $langs->trans("ByMonthYear");
  166. $head[$h][2] = 'byyear';
  167. $h++;
  168. complete_head_from_modules($conf,$langs,null,$head,$h,'trip_stats');
  169. dol_fiche_head($head,'byyear',$langs->trans("Statistics"));
  170. print '<div class="fichecenter"><div class="fichethirdleft">';
  171. // Show filter box
  172. print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  173. print '<input type="hidden" name="mode" value="'.$mode.'">';
  174. print '<table class="border" width="100%">';
  175. print '<tr><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
  176. // Company
  177. print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
  178. $filter='';
  179. print $form->select_company($socid,'socid',$filter,1,1);
  180. print '</td></tr>';
  181. // User
  182. print '<tr><td>'.$langs->trans("User").'/'.$langs->trans("SalesRepresentative").'</td><td>';
  183. print $form->select_dolusers($userid,'userid',1);
  184. print '</td></tr>';
  185. // Year
  186. print '<tr><td>'.$langs->trans("Year").'</td><td>';
  187. if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
  188. arsort($arrayyears);
  189. print $form->selectarray('year',$arrayyears,$year,0);
  190. print '</td></tr>';
  191. print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
  192. print '</table>';
  193. print '</form>';
  194. print '<br><br>';
  195. print '<table class="border" width="100%">';
  196. print '<tr height="24">';
  197. print '<td align="center">'.$langs->trans("Year").'</td>';
  198. print '<td align="center">'.$langs->trans("Number").'</td>';
  199. print '<td align="center">'.$langs->trans("AmountTotal").'</td>';
  200. print '<td align="center">'.$langs->trans("AmountAverage").'</td>';
  201. print '</tr>';
  202. $oldyear=0;
  203. foreach ($data as $val)
  204. {
  205. $year = $val['year'];
  206. while ($year && $oldyear > $year+1)
  207. { // If we have empty year
  208. $oldyear--;
  209. print '<tr height="24">';
  210. print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&amp;mode='.$mode.'">'.$oldyear.'</a></td>';
  211. print '<td align="right">0</td>';
  212. print '<td align="right">0</td>';
  213. print '<td align="right">0</td>';
  214. print '</tr>';
  215. }
  216. print '<tr height="24">';
  217. print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&amp;mode='.$mode.'">'.$year.'</a></td>';
  218. print '<td align="right">'.$val['nb'].'</td>';
  219. print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
  220. print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>';
  221. print '</tr>';
  222. $oldyear=$year;
  223. }
  224. print '</table>';
  225. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  226. // Show graphs
  227. print '<table class="border" width="100%"><tr valign="top"><td align="center">';
  228. if ($mesg) { print $mesg; }
  229. else {
  230. print $px1->show();
  231. print "<br>\n";
  232. print $px2->show();
  233. print "<br>\n";
  234. print $px3->show();
  235. }
  236. print '</td></tr></table>';
  237. print '</div></div></div>';
  238. print '<div style="clear:both"></div>';
  239. dol_fiche_end();
  240. llxFooter();
  241. $db->close();
  242. ?>