PageRenderTime 132ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/compta/facture/stats/index.php

https://github.com/asterix14/dolibarr
PHP | 223 lines | 151 code | 38 blank | 34 comment | 27 complexity | 4abbf978bf908c62a73103e0fce77a88 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-2010 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/facture/stats/index.php
  20. * \ingroup facture
  21. * \brief Page des stats factures
  22. */
  23. require("../../../main.inc.php");
  24. require_once(DOL_DOCUMENT_ROOT."/core/class/dolgraph.class.php");
  25. require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facturestats.class.php");
  26. $WIDTH=500;
  27. $HEIGHT=200;
  28. $userid=GETPOST('userid'); if ($userid < 0) $userid=0;
  29. $socid=GETPOST('socid'); if ($socid < 0) $socid=0;
  30. // Security check
  31. if ($user->societe_id > 0)
  32. {
  33. $action = '';
  34. $socid = $user->societe_id;
  35. }
  36. $year = strftime("%Y", time());
  37. $startyear=$year-2;
  38. $endyear=$year;
  39. $mode=GETPOST("mode")?GETPOST("mode"):'customer';
  40. /*
  41. * View
  42. */
  43. $langs->load("bills");
  44. $form=new Form($db);
  45. llxHeader();
  46. if ($mode == 'customer')
  47. {
  48. $title=$langs->trans("BillsStatistics");
  49. $dir=$conf->facture->dir_temp;
  50. }
  51. if ($mode == 'supplier')
  52. {
  53. $title=$langs->trans("BillsStatisticsSuppliers");
  54. $dir=$conf->fournisseur->dir_output.'/facture/temp';
  55. }
  56. print_fiche_titre($title, $mesg);
  57. create_exdir($dir);
  58. $stats = new FactureStats($db, $socid, $mode, ($userid>0?$userid:0));
  59. // Build graphic number of object
  60. // $data = array(array('Lib',val1,val2,val3),...)
  61. $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
  62. //var_dump($data);
  63. $filenamenb = $dir."/invoicesnbinyear-".$year.".png";
  64. if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;file=invoicesnbinyear-'.$year.'.png';
  65. if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&amp;file=invoicesnbinyear-'.$year.'.png';
  66. $px = new DolGraph();
  67. $mesg = $px->isGraphKo();
  68. if (! $mesg)
  69. {
  70. $px->SetData($data);
  71. $px->SetPrecisionY(0);
  72. $i=$startyear;
  73. while ($i <= $endyear)
  74. {
  75. $legend[]=$i;
  76. $i++;
  77. }
  78. $px->SetLegend($legend);
  79. $px->SetMaxValue($px->GetCeilMaxValue());
  80. $px->SetWidth($WIDTH);
  81. $px->SetHeight($HEIGHT);
  82. $px->SetYLabel($langs->trans("NumberOfBills"));
  83. $px->SetShading(3);
  84. $px->SetHorizTickIncrement(1);
  85. $px->SetPrecisionY(0);
  86. $px->mode='depth';
  87. $px->SetTitle($langs->trans("NumberOfBillsByMonth"));
  88. $px->draw($filenamenb);
  89. }
  90. // Build graphic amount of object
  91. $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
  92. //var_dump($data);
  93. // $data = array(array('Lib',val1,val2,val3),...)
  94. $filenameamount = $dir."/invoicesamountinyear-".$year.".png";
  95. if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;file=invoicesamountinyear-'.$year.'.png';
  96. if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&amp;file=invoicesamountinyear-'.$year.'.png';
  97. $px = new DolGraph();
  98. $mesg = $px->isGraphKo();
  99. if (! $mesg)
  100. {
  101. $px->SetData($data);
  102. $i=$startyear;
  103. while ($i <= $endyear)
  104. {
  105. $legend[]=$i;
  106. $i++;
  107. }
  108. $px->SetLegend($legend);
  109. $px->SetMaxValue($px->GetCeilMaxValue());
  110. $px->SetMinValue(min(0,$px->GetFloorMinValue()));
  111. $px->SetWidth($WIDTH);
  112. $px->SetHeight($HEIGHT);
  113. $px->SetYLabel($langs->trans("AmountOfBills"));
  114. $px->SetShading(3);
  115. $px->SetHorizTickIncrement(1);
  116. $px->SetPrecisionY(0);
  117. $px->mode='depth';
  118. $px->SetTitle($langs->trans("AmountOfBillsByMonthHT"));
  119. $px->draw($filenameamount);
  120. }
  121. print '<table class="notopnoleftnopadd" width="100%"><tr>';
  122. print '<td align="center" valign="top">';
  123. // Show filter box
  124. print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  125. print '<table class="border" width="100%">';
  126. print '<tr><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
  127. print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
  128. if ($mode == 'customer') $filter='s.client in (1,2,3)';
  129. if ($mode == 'supplier') $filter='s.fournisseur = 1';
  130. print $form->select_company($socid,'socid',$filter,1);
  131. print '</td></tr>';
  132. print '<tr><td>'.$langs->trans("User").'</td><td>';
  133. print $form->select_users($userid,'userid',1);
  134. print '</td></tr>';
  135. print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
  136. print '</table>';
  137. print '</form>';
  138. print '<br><br>';
  139. // Show array
  140. $data = $stats->getAllByYear();
  141. print '<table class="border" width="100%">';
  142. print '<tr height="24">';
  143. print '<td align="center">'.$langs->trans("Year").'</td>';
  144. print '<td align="center">'.$langs->trans("NumberOfBills").'</td>';
  145. print '<td align="center">'.$langs->trans("AmountTotal").'</td>';
  146. print '<td align="center">'.$langs->trans("AmountAverage").'</td>';
  147. print '</tr>';
  148. $oldyear=0;
  149. foreach ($data as $val)
  150. {
  151. $year = $val['year'];
  152. while ($year && $oldyear > $year+1)
  153. { // If we have empty year
  154. $oldyear--;
  155. print '<tr height="24">';
  156. print '<td align="center"><a href="month.php?year='.$oldyear.'&amp;mode='.$mode.'">'.$oldyear.'</a></td>';
  157. print '<td align="right">0</td>';
  158. print '<td align="right">0</td>';
  159. print '<td align="right">0</td>';
  160. print '</tr>';
  161. }
  162. print '<tr height="24">';
  163. print '<td align="center"><a href="month.php?year='.$year.'&amp;mode='.$mode.'">'.$year.'</a></td>';
  164. print '<td align="right">'.$val['nb'].'</td>';
  165. print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
  166. print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>';
  167. print '</tr>';
  168. $oldyear=$year;
  169. }
  170. print '</table>';
  171. $db->close();
  172. print '</td>';
  173. print '<td align="center" valign="top">';
  174. // Show graphs
  175. print '<table class="border" width="100%"><tr valign="top"><td align="center">';
  176. if ($mesg) { print $mesg; }
  177. else {
  178. print '<img src="'.$fileurlnb.'" title="'.$langs->trans("NumberOfBills").'" alt="'.$langs->trans("NumberOfBills").'">';
  179. print "<br>\n";
  180. print '<img src="'.$fileurlamount.'" title="'.$langs->trans("AmountOfBills").'" alt="'.$langs->trans("AmountOfBills").'">';
  181. }
  182. print '</td></tr></table>';
  183. print '</td></tr></table>';
  184. llxFooter();
  185. ?>