index.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?php
  2. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.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 <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/adherents/stats/index.php
  21. * \ingroup member
  22. * \brief Page of subscription members statistics
  23. */
  24. // Load Dolibarr environment
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherentstats.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
  30. $WIDTH = DolGraph::getDefaultGraphSizeForStats('width');
  31. $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
  32. $userid = GETPOST('userid', 'int'); if ($userid < 0) {
  33. $userid = 0;
  34. }
  35. $socid = GETPOST('socid', 'int'); if ($socid < 0) {
  36. $socid = 0;
  37. }
  38. // Security check
  39. if ($user->socid > 0) {
  40. $action = '';
  41. $socid = $user->socid;
  42. }
  43. $result = restrictedArea($user, 'adherent', '', '', 'cotisation');
  44. $year = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
  45. $startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
  46. $endyear = $year;
  47. // Load translation files required by the page
  48. $langs->loadLangs(array("companies", "members"));
  49. /*
  50. * View
  51. */
  52. $memberstatic = new Adherent($db);
  53. $form = new Form($db);
  54. $title = $langs->trans("SubscriptionsStatistics");
  55. llxHeader('', $title);
  56. print load_fiche_titre($title, '', $memberstatic->picto);
  57. $dir = $conf->adherent->dir_temp;
  58. dol_mkdir($dir);
  59. $stats = new AdherentStats($db, $socid, $userid);
  60. // Build graphic number of object
  61. $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
  62. //var_dump($data);
  63. // $data = array(array('Lib',val1,val2,val3),...)
  64. $filenamenb = $dir.'/subscriptionsnbinyear-'.$year.'.png';
  65. $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=memberstats&file=subscriptionsnbinyear-'.$year.'.png';
  66. $px1 = new DolGraph();
  67. $mesg = $px1->isGraphKo();
  68. if (!$mesg) {
  69. $px1->SetData($data);
  70. $i = $startyear;
  71. while ($i <= $endyear) {
  72. $legend[] = $i;
  73. $i++;
  74. }
  75. $px1->SetLegend($legend);
  76. $px1->SetMaxValue($px1->GetCeilMaxValue());
  77. $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
  78. $px1->SetWidth($WIDTH);
  79. $px1->SetHeight($HEIGHT);
  80. $px1->SetYLabel($langs->trans("NbOfSubscriptions"));
  81. $px1->SetShading(3);
  82. $px1->SetHorizTickIncrement(1);
  83. $px1->mode = 'depth';
  84. $px1->SetTitle($langs->trans("NbOfSubscriptions"));
  85. $px1->draw($filenamenb, $fileurlnb);
  86. }
  87. // Build graphic amount of object
  88. $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
  89. //var_dump($data);
  90. // $data = array(array('Lib',val1,val2,val3),...)
  91. $filenameamount = $dir.'/subscriptionsamountinyear-'.$year.'.png';
  92. $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=memberstats&file=subscriptionsamountinyear-'.$year.'.png';
  93. $px2 = new DolGraph();
  94. $mesg = $px2->isGraphKo();
  95. if (!$mesg) {
  96. $px2->SetData($data);
  97. $i = $startyear;
  98. while ($i <= $endyear) {
  99. $legend[] = $i;
  100. $i++;
  101. }
  102. $px2->SetLegend($legend);
  103. $px2->SetMaxValue($px2->GetCeilMaxValue());
  104. $px2->SetMinValue(min(0, $px2->GetFloorMinValue()));
  105. $px2->SetWidth($WIDTH);
  106. $px2->SetHeight($HEIGHT);
  107. $px2->SetYLabel($langs->trans("AmountOfSubscriptions"));
  108. $px2->SetShading(3);
  109. $px2->SetHorizTickIncrement(1);
  110. $px2->mode = 'depth';
  111. $px2->SetTitle($langs->trans("AmountOfSubscriptions"));
  112. $px2->draw($filenameamount, $fileurlamount);
  113. }
  114. $head = member_stats_prepare_head($memberstatic);
  115. print dol_get_fiche_head($head, 'statssubscription', '', -1, '');
  116. print '<div class="fichecenter"><div class="fichethirdleft">';
  117. // Show filter box
  118. /*print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  119. print '<input type="hidden" name="token" value="'.newToken().'">';
  120. print '<table class="border centpercent">';
  121. print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
  122. print '<tr><td>'.$langs->trans("Member").'</td><td>';
  123. print img_picto('', 'company', 'class="pictofixedwidth"');
  124. print $form->select_company($id,'memberid','',1);
  125. print '</td></tr>';
  126. print '<tr><td>'.$langs->trans("User").'</td><td>';
  127. print img_picto('', 'user', 'class="pictofixedwidth"');
  128. print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
  129. print '</td></tr>';
  130. print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
  131. print '</table>';
  132. print '</form>';
  133. print '<br><br>';
  134. */
  135. // Show array
  136. $data = $stats->getAllByYear();
  137. print '<div class="div-table-responsive-no-min">';
  138. print '<table class="noborder">';
  139. print '<tr class="liste_titre" height="24">';
  140. print '<td class="center">'.$langs->trans("Year").'</td>';
  141. print '<td class="right">'.$langs->trans("NbOfSubscriptions").'</td>';
  142. print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
  143. print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
  144. print '</tr>';
  145. $oldyear = 0;
  146. foreach ($data as $val) {
  147. $year = $val['year'];
  148. while ($oldyear > $year + 1) { // If we have empty year
  149. $oldyear--;
  150. print '<tr class="oddeven" height="24">';
  151. print '<td class="center">';
  152. //print '<a href="month.php?year='.$oldyear.'&amp;mode='.$mode.'">';
  153. print $oldyear;
  154. //print '</a>';
  155. print '</td>';
  156. print '<td class="right">0</td>';
  157. print '<td class="right amount nowraponall">0</td>';
  158. print '<td class="right amount nowraponall">0</td>';
  159. print '</tr>';
  160. }
  161. print '<tr class="oddeven" height="24">';
  162. print '<td class="center">';
  163. print '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php?date_select='.((int) $year).'">'.$year.'</a>';
  164. print '</td>';
  165. print '<td class="right">'.$val['nb'].'</td>';
  166. print '<td class="right amount nowraponall"><span class="amount">'.price(price2num($val['total'], 'MT'), 1).'</span></td>';
  167. print '<td class="right amount nowraponall"><span class="amount">'.price(price2num($val['avg'], 'MT'), 1).'</span></td>';
  168. print '</tr>';
  169. $oldyear = $year;
  170. }
  171. print '</table>';
  172. print '</div>';
  173. print '</div><div class="fichetwothirdright">';
  174. // Show graphs
  175. print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
  176. if ($mesg) {
  177. print $mesg;
  178. } else {
  179. print $px1->show();
  180. print "<br>\n";
  181. print $px2->show();
  182. }
  183. print '</td></tr></table>';
  184. print '</div></div>';
  185. print '<div style="clear:both"></div>';
  186. print dol_get_fiche_end();
  187. // End of page
  188. llxFooter();
  189. $db->close();