byproperties.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. /* Copyright (c) 2012 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/adherents/stats/byproperties.php
  19. * \ingroup member
  20. * \brief Page with statistics on members
  21. */
  22. // Load Dolibarr environment
  23. require '../../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  26. $graphwidth = 700;
  27. $mapratio = 0.5;
  28. $graphheight = round($graphwidth * $mapratio);
  29. $mode = GETPOST('mode') ? GETPOST('mode') : '';
  30. // Security check
  31. if ($user->socid > 0) {
  32. $action = '';
  33. $socid = $user->socid;
  34. }
  35. $result = restrictedArea($user, 'adherent', '', '', 'cotisation');
  36. $year = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
  37. $startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
  38. $endyear = $year;
  39. // Load translation files required by the page
  40. $langs->loadLangs(array("companies", "members"));
  41. /*
  42. * View
  43. */
  44. $memberstatic = new Adherent($db);
  45. llxHeader('', $langs->trans("MembersStatisticsByProperties"), '', '', 0, 0, array('https://www.google.com/jsapi'));
  46. $title = $langs->trans("MembersStatisticsByProperties");
  47. print load_fiche_titre($title, '', $memberstatic->picto);
  48. //dol_mkdir($dir);
  49. $data = array();
  50. $sql = "SELECT COUNT(DISTINCT d.rowid) as nb, COUNT(s.rowid) as nbsubscriptions,";
  51. $sql .= " MAX(d.datevalid) as lastdate, MAX(s.dateadh) as lastsubscriptiondate,";
  52. $sql .= " d.morphy as code";
  53. $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
  54. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."subscription as s ON s.fk_adherent = d.rowid";
  55. $sql .= " WHERE d.entity IN (".getEntity('adherent').")";
  56. $sql .= " AND d.statut <> ".Adherent::STATUS_DRAFT;
  57. $sql .= " GROUP BY d.morphy";
  58. $foundphy = $foundmor = 0;
  59. // Define $data array
  60. dol_syslog("Count member", LOG_DEBUG);
  61. $resql = $db->query($sql);
  62. if ($resql) {
  63. $num = $db->num_rows($resql);
  64. $i = 0;
  65. while ($i < $num) {
  66. $obj = $db->fetch_object($resql);
  67. if ($obj->code == 'phy') {
  68. $foundphy++;
  69. }
  70. if ($obj->code == 'mor') {
  71. $foundmor++;
  72. }
  73. $data[$obj->code] = array('label'=>$obj->code, 'nb'=>$obj->nb, 'nbsubscriptions'=>$obj->nbsubscriptions, 'lastdate'=>$db->jdate($obj->lastdate), 'lastsubscriptiondate'=>$db->jdate($obj->lastsubscriptiondate));
  74. $i++;
  75. }
  76. $db->free($resql);
  77. } else {
  78. dol_print_error($db);
  79. }
  80. $sql = "SELECT COUNT(DISTINCT d.rowid) as nb, COUNT(s.rowid) as nbsubscriptions,";
  81. $sql .= " MAX(d.datevalid) as lastdate, MAX(s.dateadh) as lastsubscriptiondate,";
  82. $sql .= " d.morphy as code";
  83. $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
  84. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."subscription as s ON s.fk_adherent = d.rowid";
  85. $sql .= " WHERE d.entity IN (".getEntity('adherent').")";
  86. $sql .= " AND d.statut >= 1"; // Active (not excluded=-2, not draft=-1, not resiliated=0)
  87. $sql .= " GROUP BY d.morphy";
  88. $foundphy = $foundmor = 0;
  89. // Define $data array
  90. dol_syslog("Count member still active", LOG_DEBUG);
  91. $resql = $db->query($sql);
  92. if ($resql) {
  93. $num = $db->num_rows($resql);
  94. $i = 0;
  95. while ($i < $num) {
  96. $obj = $db->fetch_object($resql);
  97. if ($obj->code == 'phy') {
  98. $foundphy++;
  99. }
  100. if ($obj->code == 'mor') {
  101. $foundmor++;
  102. }
  103. $data[$obj->code]['nbactive'] = $obj->nb;
  104. $i++;
  105. }
  106. $db->free($resql);
  107. } else {
  108. dol_print_error($db);
  109. }
  110. $head = member_stats_prepare_head($memberstatic);
  111. print dol_get_fiche_head($head, 'statsbyproperties', '', -1, '');
  112. // Print title
  113. if (!count($data)) {
  114. print '<span class="opacitymedium">'.$langs->trans("NoValidatedMemberYet").'</span><br>';
  115. print '<br>';
  116. } else {
  117. print '<span class="opacitymedium">'.$langs->trans("MembersByNature").'</span><br>';
  118. print '<br>';
  119. }
  120. // Print array
  121. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  122. print '<table class="liste centpercent">';
  123. print '<tr class="liste_titre">';
  124. print '<td>'.$langs->trans("MemberNature").'</td>';
  125. print '<td class="right">'.$langs->trans("NbOfMembers").' <span class="opacitymedium">('.$langs->trans("AllTime").')</span></td>';
  126. print '<td class="right">'.$langs->trans("NbOfActiveMembers").'</td>';
  127. print '<td class="center">'.$langs->trans("LastMemberDate").'</td>';
  128. print '<td class="right">'.$langs->trans("NbOfSubscriptions").'</td>';
  129. print '<td class="center">'.$langs->trans("LatestSubscriptionDate").'</td>';
  130. print '</tr>';
  131. if (!$foundphy) {
  132. $data[] = array('label'=>'phy', 'nb'=>'0', 'nbactive'=>'0', 'lastdate'=>'', 'lastsubscriptiondate'=>'');
  133. }
  134. if (!$foundmor) {
  135. $data[] = array('label'=>'mor', 'nb'=>'0', 'nbactive'=>'0', 'lastdate'=>'', 'lastsubscriptiondate'=>'');
  136. }
  137. foreach ($data as $val) {
  138. $nb = $val['nb'];
  139. $nbsubscriptions = isset($val['nbsubscriptions']) ? $val['nbsubscriptions'] : 0;
  140. $nbactive = $val['nbactive'];
  141. print '<tr class="oddeven">';
  142. print '<td>'.$memberstatic->getmorphylib($val['label']).'</td>';
  143. print '<td class="right">'.$nb.'</td>';
  144. print '<td class="right">'.$nbactive.'</td>';
  145. print '<td class="center">'.dol_print_date($val['lastdate'], 'dayhour').'</td>';
  146. print '<td class="right">'.$nbsubscriptions.'</td>';
  147. print '<td class="center">'.dol_print_date($val['lastsubscriptiondate'], 'dayhour').'</td>';
  148. print '</tr>';
  149. }
  150. print '</table>';
  151. print '</div>';
  152. print dol_get_fiche_end();
  153. // End of page
  154. llxFooter();
  155. $db->close();