PageRenderTime 45ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/don/stats/index.php

http://github.com/Dolibarr/dolibarr
PHP | 340 lines | 136 code | 50 blank | 154 comment | 14 complexity | f45f26068d9e1b64d6a700e8635e68c5 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-3.0, LGPL-2.0, CC-BY-SA-4.0, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, MIT
  1. <?php
  2. /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
  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 <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/don/stats/index.php
  22. * \ingroup donations
  23. * \brief Page with donations statistics
  24. */
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/don/class/donstats.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  29. $WIDTH = DolGraph::getDefaultGraphSizeForStats('width');
  30. $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
  31. $userid = GETPOST('userid', 'int');
  32. $socid = GETPOST('socid', 'int');
  33. // Security check
  34. if ($user->socid > 0) {
  35. $action = '';
  36. $socid = $user->socid;
  37. }
  38. $nowyear = strftime("%Y", dol_now());
  39. $year = GETPOST('year') > 0 ?GETPOST('year') : $nowyear;
  40. $startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
  41. $endyear = $year;
  42. // Load translation files required by the page
  43. $langs->loadLangs(array("companies", "other", "sendings"));
  44. /*
  45. * View
  46. */
  47. $form = new Form($db);
  48. llxHeader();
  49. print load_fiche_titre($langs->trans("StatisticsOfSendings"), $mesg);
  50. dol_mkdir($dir);
  51. $stats = new DonationStats($db, $socid, '', ($userid > 0 ? $userid : 0));
  52. // Build graphic number of object
  53. $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
  54. //var_dump($data);exit;
  55. // $data = array(array('Lib',val1,val2,val3),...)
  56. if (empty($user->rights->societe->client->voir) || $user->socid) {
  57. $filenamenb = $dir.'/shipmentsnbinyear-'.$user->id.'-'.$year.'.png';
  58. } else {
  59. $filenamenb = $dir.'/shipmentsnbinyear-'.$year.'.png';
  60. }
  61. $px1 = new DolGraph();
  62. $mesg = $px1->isGraphKo();
  63. if (!$mesg) {
  64. $px1->SetData($data);
  65. $i = $startyear; $legend = array();
  66. while ($i <= $endyear) {
  67. $legend[] = $i;
  68. $i++;
  69. }
  70. $px1->SetLegend($legend);
  71. $px1->SetMaxValue($px1->GetCeilMaxValue());
  72. $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
  73. $px1->SetWidth($WIDTH);
  74. $px1->SetHeight($HEIGHT);
  75. $px1->SetYLabel($langs->trans("NbOfSendings"));
  76. $px1->SetShading(3);
  77. $px1->SetHorizTickIncrement(1);
  78. $px1->mode = 'depth';
  79. $px1->SetTitle($langs->trans("NumberOfShipmentsByMonth"));
  80. $px1->draw($filenamenb, $fileurlnb);
  81. }
  82. // Build graphic amount of object
  83. /*
  84. $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
  85. //var_dump($data);
  86. // $data = array(array('Lib',val1,val2,val3),...)
  87. if (empty($user->rights->societe->client->voir) || $user->socid)
  88. {
  89. $filenameamount = $dir.'/shipmentsamountinyear-'.$user->id.'-'.$year.'.png';
  90. }
  91. else
  92. {
  93. $filenameamount = $dir.'/shipmentsamountinyear-'.$year.'.png';
  94. }
  95. $px2 = new DolGraph();
  96. $mesg = $px2->isGraphKo();
  97. if (! $mesg)
  98. {
  99. $px2->SetData($data);
  100. $i=$startyear;$legend=array();
  101. while ($i <= $endyear)
  102. {
  103. $legend[]=$i;
  104. $i++;
  105. }
  106. $px2->SetLegend($legend);
  107. $px2->SetMaxValue($px2->GetCeilMaxValue());
  108. $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
  109. $px2->SetWidth($WIDTH);
  110. $px2->SetHeight($HEIGHT);
  111. $px2->SetYLabel($langs->trans("AmountOfShipments"));
  112. $px2->SetShading(3);
  113. $px2->SetHorizTickIncrement(1);
  114. $px2->mode='depth';
  115. $px2->SetTitle($langs->trans("AmountOfShipmentsByMonthHT"));
  116. $px2->draw($filenameamount,$fileurlamount);
  117. }
  118. */
  119. /*
  120. $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
  121. if (empty($user->rights->societe->client->voir) || $user->socid)
  122. {
  123. $filename_avg = $dir.'/shipmentsaverage-'.$user->id.'-'.$year.'.png';
  124. }
  125. else
  126. {
  127. $filename_avg = $dir.'/shipmentsaverage-'.$year.'.png';
  128. }
  129. $px3 = new DolGraph();
  130. $mesg = $px3->isGraphKo();
  131. if (! $mesg)
  132. {
  133. $px3->SetData($data);
  134. $i=$startyear;$legend=array();
  135. while ($i <= $endyear)
  136. {
  137. $legend[]=$i;
  138. $i++;
  139. }
  140. $px3->SetLegend($legend);
  141. $px3->SetYLabel($langs->trans("AmountAverage"));
  142. $px3->SetMaxValue($px3->GetCeilMaxValue());
  143. $px3->SetMinValue($px3->GetFloorMinValue());
  144. $px3->SetWidth($WIDTH);
  145. $px3->SetHeight($HEIGHT);
  146. $px3->SetShading(3);
  147. $px3->SetHorizTickIncrement(1);
  148. $px3->mode='depth';
  149. $px3->SetTitle($langs->trans("AmountAverage"));
  150. $px3->draw($filename_avg,$fileurl_avg);
  151. }
  152. */
  153. // Show array
  154. $data = $stats->getAllByYear();
  155. $arrayyears = array();
  156. foreach ($data as $val) {
  157. if (!empty($val['year'])) {
  158. $arrayyears[$val['year']] = $val['year'];
  159. }
  160. }
  161. if (!count($arrayyears)) {
  162. $arrayyears[$nowyear] = $nowyear;
  163. }
  164. $h = 0;
  165. $head = array();
  166. $head[$h][0] = DOL_URL_ROOT.'/don/stats/index.php';
  167. $head[$h][1] = $langs->trans("ByMonthYear");
  168. $head[$h][2] = 'byyear';
  169. $h++;
  170. $type = 'donation_stats';
  171. complete_head_from_modules($conf, $langs, null, $head, $h, $type);
  172. print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
  173. print '<div class="fichecenter"><div class="fichethirdleft">';
  174. // Show filter box
  175. print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  176. print '<input type="hidden" name="token" value="'.newToken().'">';
  177. print '<table class="border centpercent">';
  178. print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
  179. // Company
  180. print '<tr><td class="left">'.$langs->trans("ThirdParty").'</td><td class="left">';
  181. print img_picto('', 'company', 'class="pictofixedwidth"');
  182. print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
  183. print '</td></tr>';
  184. // User
  185. print '<tr><td class="left">'.$langs->trans("CreatedBy").'</td><td class="left">';
  186. print img_picto('', 'user', 'class="pictofixedwidth"');
  187. print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
  188. print '</td></tr>';
  189. // Year
  190. print '<tr><td class="left">'.$langs->trans("Year").'</td><td class="left">';
  191. if (!in_array($year, $arrayyears)) {
  192. $arrayyears[$year] = $year;
  193. }
  194. if (!in_array($nowyear, $arrayyears)) {
  195. $arrayyears[$nowyear] = $nowyear;
  196. }
  197. arsort($arrayyears);
  198. print $form->selectarray('year', $arrayyears, $year, 0);
  199. print '</td></tr>';
  200. print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
  201. print '</table>';
  202. print '</form>';
  203. print '<br><br>';
  204. print '<div class="div-table-responsive-no-min">';
  205. print '<table class="border centpercent">';
  206. print '<tr height="24">';
  207. print '<td class="center">'.$langs->trans("Year").'</td>';
  208. print '<td class="center">'.$langs->trans("NbOfSendings").'</td>';
  209. /*print '<td class="center">'.$langs->trans("AmountTotal").'</td>';
  210. print '<td class="center">'.$langs->trans("AmountAverage").'</td>';*/
  211. print '</tr>';
  212. $oldyear = 0;
  213. foreach ($data as $val) {
  214. $year = $val['year'];
  215. while (!empty($year) && $oldyear > $year + 1) { // If we have empty year
  216. $oldyear--;
  217. print '<tr height="24">';
  218. print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'">'.$oldyear.'</a></td>';
  219. print '<td class="right">0</td>';
  220. /*print '<td class="right">0</td>';
  221. print '<td class="right">0</td>';*/
  222. print '</tr>';
  223. }
  224. print '<tr height="24">';
  225. print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'">'.$year.'</a></td>';
  226. print '<td class="right">'.$val['nb'].'</td>';
  227. /*print '<td class="right">'.price(price2num($val['total'],'MT'),1).'</td>';
  228. print '<td class="right">'.price(price2num($val['avg'],'MT'),1).'</td>';*/
  229. print '</tr>';
  230. $oldyear = $year;
  231. }
  232. print '</table>';
  233. print '</div>';
  234. print '</div><div class="fichetwothirdright">';
  235. // Show graphs
  236. print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
  237. if ($mesg) {
  238. print $mesg;
  239. } else {
  240. print $px1->show();
  241. print "<br>\n";
  242. /*print $px2->show();
  243. print "<br>\n";
  244. print $px3->show();*/
  245. }
  246. print '</td></tr></table>';
  247. print '</div></div>';
  248. print '<div style="clear:both"></div>';
  249. print dol_get_fiche_end();
  250. // TODO USe code similar to commande/stats/index.php instead of this one.
  251. /*
  252. print '<table class="border centpercent">';
  253. print '<tr><td class="center">'.$langs->trans("Year").'</td>';
  254. print '<td width="40%" class="center">'.$langs->trans("NbOfSendings").'</td></tr>';
  255. $sql = "SELECT count(*) as nb, date_format(date_expedition,'%Y') as dm";
  256. $sql.= " FROM ".MAIN_DB_PREFIX."expedition";
  257. $sql.= " WHERE fk_statut > 0";
  258. $sql.= " AND entity = ".$conf->entity;
  259. $sql.= " GROUP BY dm DESC";
  260. $resql=$db->query($sql);
  261. if ($resql)
  262. {
  263. $num = $db->num_rows($resql);
  264. $i = 0;
  265. while ($i < $num)
  266. {
  267. $row = $db->fetch_row($resql);
  268. $nbproduct = $row[0];
  269. $year = $row[1];
  270. print "<tr>";
  271. print '<td class="center"><a href="month.php?year='.$year.'">'.$year.'</a></td><td class="center">'.$nbproduct.'</td></tr>';
  272. $i++;
  273. }
  274. }
  275. $db->free($resql);
  276. print '</table>';
  277. */
  278. print '<br>';
  279. print '<i>'.$langs->trans("StatsOnShipmentsOnlyValidated").'</i>';
  280. llxFooter();
  281. $db->close();