byproperties.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. require '../../main.inc.php';
  23. require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
  24. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  25. $graphwidth = 700;
  26. $mapratio = 0.5;
  27. $graphheight = round($graphwidth * $mapratio);
  28. $mode = GETPOST('mode') ?GETPOST('mode') : '';
  29. // Security check
  30. if ($user->socid > 0)
  31. {
  32. $action = '';
  33. $socid = $user->socid;
  34. }
  35. $result = restrictedArea($user, 'adherent', '', '', 'cotisation');
  36. $year = strftime("%Y", time());
  37. $startyear = $year - 2;
  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, '');
  48. dol_mkdir($dir);
  49. $tab = 'byproperties';
  50. $data = array();
  51. $sql .= "SELECT COUNT(d.rowid) as nb, MAX(d.datevalid) as lastdate, MAX(s.dateadh) as lastsubscriptiondate, d.morphy as code";
  52. $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
  53. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."subscription as s ON s.fk_adherent = d.rowid";
  54. $sql .= " WHERE d.entity IN (".getEntity('adherent').")";
  55. $sql .= " AND d.statut = 1";
  56. $sql .= " GROUP BY d.morphy";
  57. $foundphy = $foundmor = 0;
  58. // Define $data array
  59. dol_syslog("Count member", LOG_DEBUG);
  60. $resql = $db->query($sql);
  61. if ($resql)
  62. {
  63. $num = $db->num_rows($resql);
  64. $i = 0;
  65. while ($i < $num)
  66. {
  67. $obj = $db->fetch_object($resql);
  68. if ($obj->code == 'phy') $foundphy++;
  69. if ($obj->code == 'mor') $foundmor++;
  70. $data[] = array('label'=>$obj->code, 'nb'=>$obj->nb, 'lastdate'=>$db->jdate($obj->lastdate), 'lastsubscriptiondate'=>$db->jdate($obj->lastsubscriptiondate));
  71. $i++;
  72. }
  73. $db->free($resql);
  74. }
  75. else
  76. {
  77. dol_print_error($db);
  78. }
  79. $head = member_stats_prepare_head($adh);
  80. dol_fiche_head($head, 'statsbyproperties', $langs->trans("Statistics"), -1, 'user');
  81. // Print title
  82. if (!count($data))
  83. {
  84. print $langs->trans("NoValidatedMemberYet").'<br>';
  85. print '<br>';
  86. }
  87. else
  88. {
  89. print load_fiche_titre($langs->trans("MembersByNature"), '', '');
  90. }
  91. // Print array
  92. print '<table class="liste centpercent">';
  93. print '<tr class="liste_titre">';
  94. print '<td>'.$langs->trans("Nature").'</td>';
  95. print '<td class="right">'.$langs->trans("NbOfMembers").'</td>';
  96. print '<td class="center">'.$langs->trans("LastMemberDate").'</td>';
  97. print '<td class="center">'.$langs->trans("LatestSubscriptionDate").'</td>';
  98. print '</tr>';
  99. if (!$foundphy) $data[] = array('label'=>'phy', 'nb'=>'0', 'lastdate'=>'', 'lastsubscriptiondate'=>'');
  100. if (!$foundmor) $data[] = array('label'=>'mor', 'nb'=>'0', 'lastdate'=>'', 'lastsubscriptiondate'=>'');
  101. foreach ($data as $val)
  102. {
  103. print '<tr class="oddeven">';
  104. print '<td>'.$memberstatic->getmorphylib($val['label']).'</td>';
  105. print '<td class="right">'.$val['nb'].'</td>';
  106. print '<td class="center">'.dol_print_date($val['lastdate'], 'dayhour').'</td>';
  107. print '<td class="center">'.dol_print_date($val['lastsubscriptiondate'], 'dayhour').'</td>';
  108. print '</tr>';
  109. }
  110. print '</table>';
  111. dol_fiche_end();
  112. // End of page
  113. llxFooter();
  114. $db->close();