index.php 6.7 KB

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