index.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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 - (!getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS') ? 2 : max(1, min(10, getDolGlobalInt('MAIN_STATS_GRAPHS_SHOW_N_YEARS'))));
  46. $endyear = $year;
  47. if (getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER')) {
  48. $endyear = dol_print_date(dol_time_plus_duree(dol_now('gmt'), (int) substr(getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER'), 0, -1), substr(getDolGlobalString('MEMBER_SUBSCRIPTION_START_AFTER'), -1)), "%Y", 'gmt');
  49. }
  50. // Load translation files required by the page
  51. $langs->loadLangs(array("companies", "members"));
  52. /*
  53. * View
  54. */
  55. $memberstatic = new Adherent($db);
  56. $form = new Form($db);
  57. $title = $langs->trans("SubscriptionsStatistics");
  58. llxHeader('', $title);
  59. print load_fiche_titre($title, '', $memberstatic->picto);
  60. $dir = $conf->adherent->dir_temp;
  61. dol_mkdir($dir);
  62. $stats = new AdherentStats($db, $socid, $userid);
  63. // Build graphic number of object
  64. $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
  65. //var_dump($data);
  66. // $data = array(array('Lib',val1,val2,val3),...)
  67. $filenamenb = $dir.'/subscriptionsnbinyear-'.$year.'.png';
  68. $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=memberstats&file=subscriptionsnbinyear-'.$year.'.png';
  69. $px1 = new DolGraph();
  70. $mesg = $px1->isGraphKo();
  71. if (!$mesg) {
  72. $px1->SetData($data);
  73. $i = $startyear;
  74. while ($i <= $endyear) {
  75. $legend[] = $i;
  76. $i++;
  77. }
  78. $px1->SetLegend($legend);
  79. $px1->SetMaxValue($px1->GetCeilMaxValue());
  80. $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
  81. $px1->SetWidth($WIDTH);
  82. $px1->SetHeight($HEIGHT);
  83. $px1->SetYLabel($langs->trans("NbOfSubscriptions"));
  84. $px1->SetShading(3);
  85. $px1->SetHorizTickIncrement(1);
  86. $px1->mode = 'depth';
  87. $px1->SetTitle($langs->trans("NbOfSubscriptions"));
  88. $px1->draw($filenamenb, $fileurlnb);
  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.'/subscriptionsamountinyear-'.$year.'.png';
  95. $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=memberstats&file=subscriptionsamountinyear-'.$year.'.png';
  96. $px2 = new DolGraph();
  97. $mesg = $px2->isGraphKo();
  98. if (!$mesg) {
  99. $px2->SetData($data);
  100. $i = $startyear;
  101. while ($i <= $endyear) {
  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("AmountOfSubscriptions"));
  111. $px2->SetShading(3);
  112. $px2->SetHorizTickIncrement(1);
  113. $px2->mode = 'depth';
  114. $px2->SetTitle($langs->trans("AmountOfSubscriptions"));
  115. $px2->draw($filenameamount, $fileurlamount);
  116. }
  117. $head = member_stats_prepare_head($memberstatic);
  118. print dol_get_fiche_head($head, 'statssubscription', '', -1, '');
  119. print '<div class="fichecenter"><div class="fichethirdleft">';
  120. // Show filter box
  121. /*print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  122. print '<input type="hidden" name="token" value="'.newToken().'">';
  123. print '<table class="border centpercent">';
  124. print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
  125. print '<tr><td>'.$langs->trans("Member").'</td><td>';
  126. print img_picto('', 'company', 'class="pictofixedwidth"');
  127. print $form->select_company($id,'memberid','',1);
  128. print '</td></tr>';
  129. print '<tr><td>'.$langs->trans("User").'</td><td>';
  130. print img_picto('', 'user', 'class="pictofixedwidth"');
  131. print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
  132. print '</td></tr>';
  133. print '<tr><td class="center" colspan="2"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></td></tr>';
  134. print '</table>';
  135. print '</form>';
  136. print '<br><br>';
  137. */
  138. // Show array
  139. $data = $stats->getAllByYear();
  140. print '<div class="div-table-responsive-no-min">';
  141. print '<table class="noborder">';
  142. print '<tr class="liste_titre" height="24">';
  143. print '<td class="center">'.$langs->trans("Year").'</td>';
  144. print '<td class="right">'.$langs->trans("NbOfSubscriptions").'</td>';
  145. print '<td class="right">'.$langs->trans("AmountTotal").'</td>';
  146. print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
  147. print '</tr>';
  148. $oldyear = 0;
  149. foreach ($data as $val) {
  150. $year = $val['year'];
  151. while ($oldyear > $year + 1) { // If we have empty year
  152. $oldyear--;
  153. print '<tr class="oddeven" height="24">';
  154. print '<td class="center">';
  155. //print '<a href="month.php?year='.$oldyear.'&amp;mode='.$mode.'">';
  156. print $oldyear;
  157. //print '</a>';
  158. print '</td>';
  159. print '<td class="right">0</td>';
  160. print '<td class="right amount nowraponall">0</td>';
  161. print '<td class="right amount nowraponall">0</td>';
  162. print '</tr>';
  163. }
  164. print '<tr class="oddeven" height="24">';
  165. print '<td class="center">';
  166. print '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php?date_select='.((int) $year).'">'.$year.'</a>';
  167. print '</td>';
  168. print '<td class="right">'.$val['nb'].'</td>';
  169. print '<td class="right amount nowraponall"><span class="amount">'.price(price2num($val['total'], 'MT'), 1).'</span></td>';
  170. print '<td class="right amount nowraponall"><span class="amount">'.price(price2num($val['avg'], 'MT'), 1).'</span></td>';
  171. print '</tr>';
  172. $oldyear = $year;
  173. }
  174. print '</table>';
  175. print '</div>';
  176. print '</div><div class="fichetwothirdright">';
  177. // Show graphs
  178. print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
  179. if ($mesg) {
  180. print $mesg;
  181. } else {
  182. print $px1->show();
  183. print "<br>\n";
  184. print $px2->show();
  185. }
  186. print '</td></tr></table>';
  187. print '</div></div>';
  188. print '<div class="clearboth"></div>';
  189. print dol_get_fiche_end();
  190. // End of page
  191. llxFooter();
  192. $db->close();