byproperties.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 <http://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->societe_id > 0)
  31. {
  32. $action = '';
  33. $socid = $user->societe_id;
  34. }
  35. $result=restrictedArea($user,'adherent','','','cotisation');
  36. $year = strftime("%Y", time());
  37. $startyear=$year-2;
  38. $endyear=$year;
  39. $langs->load("members");
  40. $langs->load("companies");
  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, $mesg);
  48. dol_mkdir($dir);
  49. $tab='byproperties';
  50. $data = array();
  51. $sql.="SELECT COUNT(d.rowid) as nb, MAX(d.datevalid) as lastdate, d.morphy as code";
  52. $sql.=" FROM ".MAIN_DB_PREFIX."adherent as d";
  53. $sql.=" WHERE d.entity IN (".getEntity().")";
  54. $sql.=" AND d.statut = 1";
  55. $sql.=" GROUP BY d.morphy";
  56. $foundphy=$foundmor=0;
  57. // Define $data array
  58. dol_syslog("Count member", LOG_DEBUG);
  59. $resql=$db->query($sql);
  60. if ($resql)
  61. {
  62. $num=$db->num_rows($resql);
  63. $i=0;
  64. while ($i < $num)
  65. {
  66. $obj=$db->fetch_object($resql);
  67. if ($obj->code == 'phy') $foundphy++;
  68. if ($obj->code == 'mor') $foundmor++;
  69. $data[]=array('label'=>$obj->code, 'nb'=>$obj->nb, 'lastdate'=>$db->jdate($obj->lastdate));
  70. $i++;
  71. }
  72. $db->free($resql);
  73. }
  74. else
  75. {
  76. dol_print_error($db);
  77. }
  78. $head = member_stats_prepare_head($adh);
  79. dol_fiche_head($head, 'statsbyproperties', $langs->trans("Statistics"), 0, 'user');
  80. // Print title
  81. if (! count($data))
  82. {
  83. print $langs->trans("NoValidatedMemberYet").'<br>';
  84. print '<br>';
  85. }
  86. else
  87. {
  88. print load_fiche_titre($langs->trans("MembersByNature"),'','');
  89. }
  90. // Print array
  91. print '<table class="liste" width="100%">';
  92. print '<tr class="liste_titre">';
  93. print '<td>'.$langs->trans("Nature").'</td>';
  94. print '<td align="right">'.$langs->trans("NbOfMembers").'</td>';
  95. print '<td align="center">'.$langs->trans("LastMemberDate").'</td>';
  96. print '</tr>';
  97. if (! $foundphy) $data[]=array('label'=>'phy','nb'=>'0','lastdate'=>'');
  98. if (! $foundmor) $data[]=array('label'=>'mor','nb'=>'0','lastdate'=>'');
  99. $oldyear=0;
  100. $var=true;
  101. foreach ($data as $val)
  102. {
  103. $year = $val['year'];
  104. $var=!$var;
  105. print '<tr '.$bc[$var].'>';
  106. print '<td>'.$memberstatic->getmorphylib($val['label']).'</td>';
  107. print '<td align="right">'.$val['nb'].'</td>';
  108. print '<td align="center">'.dol_print_date($val['lastdate'],'dayhour').'</td>';
  109. print '</tr>';
  110. $oldyear=$year;
  111. }
  112. print '</table>';
  113. dol_fiche_end();
  114. llxFooter();
  115. $db->close();