index.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <?php
  2. /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2018 Quentin Vial-Gouteyron <quentin.vial-gouteyron@atm-consulting.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/reception/stats/index.php
  22. * \ingroup reception
  23. * \brief Page with reception statistics
  24. */
  25. // Load Dolibarr environment
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/reception/class/receptionstats.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  30. $WIDTH = DolGraph::getDefaultGraphSizeForStats('width');
  31. $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
  32. $userid = GETPOST('userid', 'int');
  33. $socid = GETPOST('socid', 'int');
  34. $nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
  35. $year = GETPOST('year') > 0 ?GETPOST('year') : $nowyear;
  36. $startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
  37. $endyear = $year;
  38. $langs->loadLangs(array("receptions", "other", "companies"));
  39. // Security check
  40. if ($user->socid) {
  41. $socid = $user->socid;
  42. }
  43. $result = restrictedArea($user, 'reception', 0, '');
  44. /*
  45. * View
  46. */
  47. $form = new Form($db);
  48. llxHeader();
  49. print load_fiche_titre($langs->trans("StatisticsOfReceptions"), '', 'dollyrevert');
  50. $dir = (!empty($conf->reception->multidir_temp[$conf->entity]) ? $conf->reception->multidir_temp[$conf->entity] : $conf->service->multidir_temp[$conf->entity]);
  51. dol_mkdir($dir);
  52. $stats = new ReceptionStats($db, $socid, '', ($userid > 0 ? $userid : 0));
  53. // Build graphic number of object
  54. $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
  55. //var_dump($data);exit;
  56. // $data = array(array('Lib',val1,val2,val3),...)
  57. if (empty($user->rights->societe->client->voir) || $user->socid) {
  58. $filenamenb = $dir.'/receptionsnbinyear-'.$user->id.'-'.$year.'.png';
  59. } else {
  60. $filenamenb = $dir.'/receptionsnbinyear-'.$year.'.png';
  61. }
  62. $px1 = new DolGraph();
  63. $mesg = $px1->isGraphKo();
  64. $fileurlnb = '';
  65. if (!$mesg) {
  66. $px1->SetData($data);
  67. $i = $startyear; $legend = array();
  68. while ($i <= $endyear) {
  69. $legend[] = $i;
  70. $i++;
  71. }
  72. $px1->SetLegend($legend);
  73. $px1->SetMaxValue($px1->GetCeilMaxValue());
  74. $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
  75. $px1->SetWidth($WIDTH);
  76. $px1->SetHeight($HEIGHT);
  77. $px1->SetYLabel($langs->trans("NbOfReceptions"));
  78. $px1->SetShading(3);
  79. $px1->SetHorizTickIncrement(1);
  80. $px1->mode = 'depth';
  81. $px1->SetTitle($langs->trans("NumberOfReceptionsByMonth"));
  82. $px1->draw($filenamenb, $fileurlnb);
  83. }
  84. // Build graphic amount of object
  85. /*
  86. $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
  87. //var_dump($data);
  88. // $data = array(array('Lib',val1,val2,val3),...)
  89. if (empty($user->rights->societe->client->voir) || $user->socid)
  90. {
  91. $filenameamount = $dir.'/receptionsamountinyear-'.$user->id.'-'.$year.'.png';
  92. }
  93. else
  94. {
  95. $filenameamount = $dir.'/receptionsamountinyear-'.$year.'.png';
  96. }
  97. $px2 = new DolGraph();
  98. $mesg = $px2->isGraphKo();
  99. if (! $mesg)
  100. {
  101. $px2->SetData($data);
  102. $i=$startyear;$legend=array();
  103. while ($i <= $endyear)
  104. {
  105. $legend[]=$i;
  106. $i++;
  107. }
  108. $px2->SetLegend($legend);
  109. $px2->SetMaxValue($px2->GetCeilMaxValue());
  110. $px2->SetMinValue(min(0,$px2->GetFloorMinValue()));
  111. $px2->SetWidth($WIDTH);
  112. $px2->SetHeight($HEIGHT);
  113. $px2->SetYLabel($langs->trans("AmountOfReceptions"));
  114. $px2->SetShading(3);
  115. $px2->SetHorizTickIncrement(1);
  116. $px2->mode='depth';
  117. $px2->SetTitle($langs->trans("AmountOfReceptionsByMonthHT"));
  118. $px2->draw($filenameamount,$fileurlamount);
  119. }
  120. */
  121. /*
  122. $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
  123. if (empty($user->rights->societe->client->voir) || $user->socid)
  124. {
  125. $filename_avg = $dir.'/receptionsaverage-'.$user->id.'-'.$year.'.png';
  126. }
  127. else
  128. {
  129. $filename_avg = $dir.'/receptionsaverage-'.$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->mode='depth';
  151. $px3->SetTitle($langs->trans("AmountAverage"));
  152. $px3->draw($filename_avg,$fileurl_avg);
  153. }
  154. */
  155. // Show array
  156. $data = $stats->getAllByYear();
  157. $arrayyears = array();
  158. foreach ($data as $val) {
  159. if (!empty($val['year'])) {
  160. $arrayyears[$val['year']] = $val['year'];
  161. }
  162. }
  163. if (!count($arrayyears)) {
  164. $arrayyears[$nowyear] = $nowyear;
  165. }
  166. $h = 0;
  167. $head = array();
  168. $head[$h][0] = DOL_URL_ROOT.'/reception/stats/index.php';
  169. $head[$h][1] = $langs->trans("ByMonthYear");
  170. $head[$h][2] = 'byyear';
  171. $h++;
  172. $type = 'reception_stats';
  173. complete_head_from_modules($conf, $langs, null, $head, $h, $type);
  174. print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
  175. print '<div class="fichecenter"><div class="fichethirdleft">';
  176. // Show filter box
  177. print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  178. print '<input type="hidden" name="token" value="'.newToken().'">';
  179. print '<table class="noborder centpercent">';
  180. print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
  181. // Company
  182. print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
  183. print img_picto('', 'company', 'class="pictofixedwidth"');
  184. print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300', '');
  185. print '</td></tr>';
  186. // User
  187. print '<tr><td>'.$langs->trans("CreatedBy").'</td><td>';
  188. print img_picto('', 'user', 'class="pictofixedwidth"');
  189. print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
  190. print '</td></tr>';
  191. // Year
  192. print '<tr><td>'.$langs->trans("Year").'</td><td>';
  193. if (!in_array($year, $arrayyears)) {
  194. $arrayyears[$year] = $year;
  195. }
  196. if (!in_array($nowyear, $arrayyears)) {
  197. $arrayyears[$nowyear] = $nowyear;
  198. }
  199. arsort($arrayyears);
  200. print $form->selectarray('year', $arrayyears, $year, 0, 0, 0, '', 0, 0, 0, '', 'width75');
  201. print '</td></tr>';
  202. print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
  203. print '</table>';
  204. print '</form>';
  205. print '<br><br>';
  206. print '<table class="noborder centpercent">';
  207. print '<tr class="liste_titre" height="24">';
  208. print '<td class="center">'.$langs->trans("Year").'</td>';
  209. print '<td class="right">'.$langs->trans("NbOfReceptions").'</td>';
  210. /*print '<td class="center">'.$langs->trans("AmountTotal").'</td>';
  211. print '<td class="center">'.$langs->trans("AmountAverage").'</td>';*/
  212. print '</tr>';
  213. $oldyear = 0;
  214. foreach ($data as $val) {
  215. $year = $val['year'];
  216. while (!empty($year) && $oldyear > $year + 1) { // If we have empty year
  217. $oldyear--;
  218. print '<tr class="oddeven" height="24">';
  219. print '<td class="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'">'.$oldyear.'</a></td>';
  220. print '<td class="right">0</td>';
  221. /*print '<td class="right">0</td>';
  222. print '<td class="right">0</td>';*/
  223. print '</tr>';
  224. }
  225. print '<tr class="oddeven" height="24">';
  226. print '<td class="center">';
  227. if ($year) {
  228. print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'">'.$year.'</a>';
  229. } else {
  230. print $langs->trans("ValidationDateNotDefinedEvenIfReceptionValidated");
  231. }
  232. print '</td>';
  233. print '<td class="right">'.$val['nb'].'</td>';
  234. /*print '<td class="right">'.price(price2num($val['total'],'MT'),1).'</td>';
  235. print '<td class="right">'.price(price2num($val['avg'],'MT'),1).'</td>';*/
  236. print '</tr>';
  237. $oldyear = $year;
  238. }
  239. print '</table>';
  240. print '</div><div class="fichetwothirdright">';
  241. // Show graphs
  242. print '<table class="border centpercent"><tr valign="top"><td class="center">';
  243. if ($mesg) {
  244. print $mesg;
  245. } else {
  246. print $px1->show();
  247. print "<br>\n";
  248. /*print $px2->show();
  249. print "<br>\n";
  250. print $px3->show();*/
  251. }
  252. print '</td></tr></table>';
  253. print '</div></div>';
  254. print '<div style="clear:both"></div>';
  255. print dol_get_fiche_end();
  256. // TODO USe code similar to commande/stats/index.php instead of this one.
  257. /*
  258. print '<table class="border centpercent">';
  259. print '<tr><td class="center">'.$langs->trans("Year").'</td>';
  260. print '<td width="40%" class="center">'.$langs->trans("NbOfReceptions").'</td></tr>';
  261. $sql = "SELECT count(*) as nb, date_format(date_reception,'%Y') as dm";
  262. $sql.= " FROM ".MAIN_DB_PREFIX."reception";
  263. $sql.= " WHERE fk_statut > 0";
  264. $sql.= " AND entity = ".$conf->entity;
  265. $sql.= " GROUP BY dm DESC";
  266. $resql=$db->query($sql);
  267. if ($resql)
  268. {
  269. $num = $db->num_rows($resql);
  270. $i = 0;
  271. while ($i < $num)
  272. {
  273. $row = $db->fetch_row($resql);
  274. $nbproduct = $row[0];
  275. $year = $row[1];
  276. print "<tr>";
  277. print '<td class="center"><a href="month.php?year='.$year.'">'.$year.'</a></td><td class="center">'.$nbproduct.'</td></tr>';
  278. $i++;
  279. }
  280. }
  281. $db->free($resql);
  282. print '</table>';
  283. */
  284. print '<br>';
  285. print '<i class="opacitymedium">'.$langs->trans("StatsOnReceptionsOnlyValidated").'</i>';
  286. llxFooter();
  287. $db->close();