index.php 6.8 KB

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