index.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <?php
  2. /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
  4. * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  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 2 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 <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/adherents/index.php
  21. * \ingroup member
  22. * \brief Page accueil module adherents
  23. */
  24. require("../main.inc.php");
  25. require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php");
  26. require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php");
  27. $langs->load("companies");
  28. $langs->load("members");
  29. /*
  30. * View
  31. */
  32. llxHeader('',$langs->trans("Members"),'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros');
  33. $staticmember=new Adherent($db);
  34. $statictype=new AdherentType($db);
  35. print_fiche_titre($langs->trans("MembersArea"));
  36. print '<table border="0" width="100%" class="notopnoleftnoright">';
  37. $var=True;
  38. $Adherents=array();
  39. $AdherentsAValider=array();
  40. $MemberUpToDate=array();
  41. $AdherentsResilies=array();
  42. $AdherentType=array();
  43. # Liste les adherents
  44. $sql = "SELECT t.rowid, t.libelle, t.cotisation,";
  45. $sql.= " d.statut, count(d.rowid) as somme";
  46. $sql.= " FROM ".MAIN_DB_PREFIX."adherent_type as t";
  47. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as d ON t.rowid = d.fk_adherent_type";
  48. $sql.= " GROUP BY t.rowid, t.libelle, t.cotisation, d.statut";
  49. dol_syslog("index.php::select nb of members by type sql=".$sql, LOG_DEBUG);
  50. $result = $db->query($sql);
  51. if ($result)
  52. {
  53. $num = $db->num_rows($result);
  54. $i = 0;
  55. while ($i < $num)
  56. {
  57. $objp = $db->fetch_object($result);
  58. $adhtype=new AdherentType($db);
  59. $adhtype->id=$objp->rowid;
  60. $adhtype->cotisation=$objp->cotisation;
  61. $adhtype->libelle=$objp->libelle;
  62. $AdherentType[$objp->rowid]=$adhtype;
  63. if ($objp->statut == -1) { $MemberToValidate[$objp->rowid]=$objp->somme; }
  64. if ($objp->statut == 1) { $MembersValidated[$objp->rowid]=$objp->somme; }
  65. if ($objp->statut == 0) { $MembersResiliated[$objp->rowid]=$objp->somme; }
  66. $i++;
  67. }
  68. $db->free($result);
  69. }
  70. // List members up to date
  71. // current rule: uptodate = the end date is in future whatever is type
  72. // old rule: uptodate = if type does not need payment, that end date is null, if type need payment that end date is in future)
  73. $sql = "SELECT count(*) as somme , d.fk_adherent_type";
  74. $sql.= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."adherent_type as t";
  75. //$sql.= " WHERE d.statut = 1 AND ((t.cotisation = 0 AND d.datefin IS NULL) OR d.datefin >= ".$db->idate(gmmktime()).')';
  76. $sql.= " WHERE d.statut = 1 AND d.datefin >= ".$db->idate(gmmktime());
  77. $sql.= " AND t.rowid = d.fk_adherent_type";
  78. $sql.= " GROUP BY d.fk_adherent_type";
  79. dol_syslog("index.php::select nb of uptodate members by type sql=".$sql, LOG_DEBUG);
  80. $result = $db->query($sql);
  81. if ($result)
  82. {
  83. $num = $db->num_rows($result);
  84. $i = 0;
  85. while ($i < $num)
  86. {
  87. $objp = $db->fetch_object($result);
  88. $MemberUpToDate[$objp->fk_adherent_type]=$objp->somme;
  89. $i++;
  90. }
  91. $db->free();
  92. }
  93. print '<tr><td width="30%" class="notopnoleft" valign="top">';
  94. // Formulaire recherche adherent
  95. print '<form action="liste.php" method="post">';
  96. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  97. print '<input type="hidden" name="action" value="search">';
  98. print '<table class="noborder" width="100%">';
  99. print '<tr class="liste_titre">';
  100. print '<td colspan="3">'.$langs->trans("SearchAMember").'</td>';
  101. print "</tr>\n";
  102. $var=false;
  103. print "<tr $bc[$var]>";
  104. print '<td>';
  105. print $langs->trans("Name").':</td><td><input type="text" name="search" class="flat" size="16">';
  106. print '</td><td rowspan="2"><input class="button" type="submit" value="'.$langs->trans("Search").'"></td></tr>';
  107. print "<tr $bc[$var]>";
  108. print '<td>';
  109. print $langs->trans("Other").':</td><td><input type="text" name="sall" class="flat" size="16">';
  110. print '</td></tr>';
  111. print "</table></form>";
  112. /*
  113. * Statistics
  114. */
  115. if ($conf->use_javascript_ajax)
  116. {
  117. print '<br>';
  118. print '<table class="noborder" width="100%">';
  119. print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Statistics").'</td></tr>';
  120. print '<tr><td align="center">';
  121. $SommeA=0;
  122. $SommeB=0;
  123. $SommeC=0;
  124. $SommeD=0;
  125. $dataval=array();
  126. $datalabels=array();
  127. foreach ($AdherentType as $key => $adhtype)
  128. {
  129. $datalabels[]=$adhtype->getNomUrl(0,dol_size(16));
  130. $dataval['draft'][]=isset($MemberToValidate[$key])?$MemberToValidate[$key]:0;
  131. $dataval['notuptodate'][]=isset($MembersValidated[$key])?$MembersValidated[$key]-$MemberUpToDate[$key]:0;
  132. $dataval['uptodate'][]=isset($MemberUpToDate[$key])?$MemberUpToDate[$key]:0;
  133. $dataval['resiliated'][]=isset($MembersResiliated[$key])?$MembersResiliated[$key]:0;
  134. $SommeA+=isset($MemberToValidate[$key])?$MemberToValidate[$key]:0;
  135. $SommeB+=isset($MembersValidated[$key])?$MembersValidated[$key]-$MemberUpToDate[$key]:0;
  136. $SommeC+=isset($MemberUpToDate[$key])?$MemberUpToDate[$key]:0;
  137. $SommeD+=isset($MembersResiliated[$key])?$MembersResiliated[$key]:0;
  138. }
  139. /*
  140. $dataseries=array();
  141. $dataseries[]=array('label'=>$langs->trans("MembersStatusToValid"),'values'=> $dataval['draft']);
  142. $dataseries[]=array('label'=>$langs->trans("MenuMembersNotUpToDate"),'values'=> $dataval['notuptodate']);
  143. $dataseries[]=array('label'=>$langs->trans("MenuMembersUpToDate"),'values'=> $dataval['uptodate']);
  144. $dataseries[]=array('label'=>$langs->trans("MembersStatusResiliated"),'values'=> $dataval['resiliated']);
  145. $data=array('series'=>$dataseries,'seriestype'=>array('bar','bar','bar','bar'),'xlabel'=>$datalabels);
  146. dol_print_graph('stats2',300,180,$data,1,'barline');
  147. */
  148. $dataseries=array();
  149. $dataseries[]=array('label'=>$langs->trans("MenuMembersNotUpToDate"),'values'=>array(round($SommeB)));
  150. $dataseries[]=array('label'=>$langs->trans("MenuMembersUpToDate"),'values'=>array(round($SommeC)));
  151. $dataseries[]=array('label'=>$langs->trans("MembersStatusResiliated"),'values'=>array(round($SommeD)));
  152. $dataseries[]=array('label'=>$langs->trans("MembersStatusToValid"),'values'=>array(round($SommeA)));
  153. $data=array('series'=>$dataseries);
  154. dol_print_graph('stats',300,180,$data,1,'pie',1);
  155. print '</td></tr>';
  156. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td align="right">';
  157. print $SommeA+$SommeB+$SommeC+$SommeD;
  158. print '</td></tr>';
  159. print '</table>';
  160. }
  161. print '</td><td class="notopnoleftnoright" valign="top">';
  162. $var=true;
  163. // Summary of members by type
  164. print '<table class="noborder" width="100%">';
  165. print '<tr class="liste_titre">';
  166. print '<td>'.$langs->trans("MembersTypes").'</td>';
  167. print '<td align=right>'.$langs->trans("MembersStatusToValid").'</td>';
  168. print '<td align=right>'.$langs->trans("MenuMembersNotUpToDate").'</td>';
  169. print '<td align=right>'.$langs->trans("MenuMembersUpToDate").'</td>';
  170. print '<td align=right>'.$langs->trans("MembersStatusResiliated").'</td>';
  171. print "</tr>\n";
  172. foreach ($AdherentType as $key => $adhtype)
  173. {
  174. $var=!$var;
  175. print "<tr $bc[$var]>";
  176. print '<td><a href="type.php?rowid='.$adhtype->id.'">'.img_object($langs->trans("ShowType"),"group").' '.$adhtype->getNomUrl(0,dol_size(16)).'</a></td>';
  177. print '<td align="right">'.(isset($MemberToValidate[$key]) && $MemberToValidate[$key] > 0?$MemberToValidate[$key]:'').' '.$staticmember->LibStatut(-1,$adhtype->cotisation,0,3).'</td>';
  178. print '<td align="right">'.(isset($MembersValidated[$key]) && ($MembersValidated[$key]-$MemberUpToDate[$key] > 0) ? $MembersValidated[$key]-$MemberUpToDate[$key]:'').' '.$staticmember->LibStatut(1,$adhtype->cotisation,0,3).'</td>';
  179. print '<td align="right">'.(isset($MemberUpToDate[$key]) && $MemberUpToDate[$key] > 0 ? $MemberUpToDate[$key]:'').' '.$staticmember->LibStatut(1,$adhtype->cotisation,gmmktime(),3).'</td>';
  180. print '<td align="right">'.(isset($MembersResiliated[$key]) && $MembersResiliated[$key]> 0 ?$MembersResiliated[$key]:'').' '.$staticmember->LibStatut(0,$adhtype->cotisation,0,3).'</td>';
  181. print "</tr>\n";
  182. }
  183. print '<tr class="liste_total">';
  184. print '<td class="liste_total">'.$langs->trans("Total").'</td>';
  185. print '<td class="liste_total" align="right">'.$SommeA.' '.$staticmember->LibStatut(-1,$adhtype->cotisation,0,3).'</td>';
  186. print '<td class="liste_total" align="right">'.$SommeB.' '.$staticmember->LibStatut(1,$adhtype->cotisation,0,3).'</td>';
  187. print '<td class="liste_total" align="right">'.$SommeC.' '.$staticmember->LibStatut(1,$adhtype->cotisation,gmmktime(),3).'</td>';
  188. print '<td class="liste_total" align="right">'.$SommeD.' '.$staticmember->LibStatut(0,$adhtype->cotisation,0,3).'</td>';
  189. print '</tr>';
  190. print "</table>\n";
  191. print "<br>\n";
  192. /*
  193. * Last modified members
  194. */
  195. $max=5;
  196. $sql = "SELECT a.rowid, a.statut, a.nom, a.prenom,";
  197. $sql.= " a.tms as datem, datefin as date_end_subscription,";
  198. $sql.= " ta.rowid as typeid, ta.libelle, ta.cotisation";
  199. $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a, ".MAIN_DB_PREFIX."adherent_type as ta";
  200. $sql.= " WHERE a.fk_adherent_type = ta.rowid";
  201. $sql.= $db->order("a.tms","DESC");
  202. $sql.= $db->plimit($max, 0);
  203. $resql=$db->query($sql);
  204. if ($resql)
  205. {
  206. print '<table class="noborder" width="100%">';
  207. print '<tr class="liste_titre">';
  208. print '<td colspan="4">'.$langs->trans("LastMembersModified",$max).'</td></tr>';
  209. $num = $db->num_rows($resql);
  210. if ($num)
  211. {
  212. $i = 0;
  213. $var = True;
  214. while ($i < $num)
  215. {
  216. $var=!$var;
  217. $obj = $db->fetch_object($resql);
  218. print "<tr $bc[$var]>";
  219. $staticmember->id=$obj->rowid;
  220. $staticmember->ref=trim($obj->prenom.' '.$obj->nom);
  221. $statictype->id=$obj->typeid;
  222. $statictype->libelle=$obj->libelle;
  223. print '<td>'.$staticmember->getNomUrl(1,24).'</td>';
  224. print '<td>'.$statictype->getNomUrl(1,16).'</td>';
  225. print '<td>'.dol_print_date($db->jdate($obj->datem),'dayhour').'</td>';
  226. print '<td align="right">'.$staticmember->LibStatut($obj->statut,($obj->cotisation=='yes'?1:0),$db->jdate($obj->date_end_subscription),5).'</td>';
  227. print '</tr>';
  228. $i++;
  229. }
  230. }
  231. print "</table><br>";
  232. }
  233. else
  234. {
  235. dol_print_error($db);
  236. }
  237. // List of subscription by year
  238. $Total=array();
  239. $Number=array();
  240. $tot=0;
  241. $numb=0;
  242. $sql = "SELECT c.cotisation, c.dateadh";
  243. $sql.= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."cotisation as c";
  244. $sql.= " WHERE d.rowid = c.fk_adherent";
  245. if(isset($date_select) && $date_select != '')
  246. {
  247. $sql .= " AND dateadh LIKE '$date_select%'";
  248. }
  249. $result = $db->query($sql);
  250. if ($result)
  251. {
  252. $num = $db->num_rows($result);
  253. $i = 0;
  254. while ($i < $num)
  255. {
  256. $objp = $db->fetch_object($result);
  257. $year=dol_print_date($db->jdate($objp->dateadh),"%Y");
  258. $Total[$year]=(isset($Total[$year])?$Total[$year]:0)+$objp->cotisation;
  259. $Number[$year]=(isset($Number[$year])?$Number[$year]:0)+1;
  260. $tot+=$objp->cotisation;
  261. $numb+=1;
  262. $i++;
  263. }
  264. }
  265. print '<table class="noborder" width="100%">';
  266. print '<tr class="liste_titre">';
  267. print '<td>'.$langs->trans("Subscriptions").'</td>';
  268. print '<td align="right">'.$langs->trans("Number").'</td>';
  269. print '<td align="right">'.$langs->trans("AmountTotal").'</td>';
  270. print '<td align="right">'.$langs->trans("AmountAverage").'</td>';
  271. print "</tr>\n";
  272. $var=true;
  273. krsort($Total);
  274. foreach ($Total as $key=>$value)
  275. {
  276. $var=!$var;
  277. print "<tr $bc[$var]>";
  278. print "<td><a href=\"cotisations.php?date_select=$key\">$key</a></td>";
  279. print "<td align=\"right\">".$Number[$key]."</td>";
  280. print "<td align=\"right\">".price($value)."</td>";
  281. print "<td align=\"right\">".price(price2num($value/$Number[$key],'MT'))."</td>";
  282. print "</tr>\n";
  283. }
  284. // Total
  285. print '<tr class="liste_total">';
  286. print '<td>'.$langs->trans("Total").'</td>';
  287. print "<td align=\"right\">".$numb."</td>";
  288. print '<td align="right">'.price($tot)."</td>";
  289. print "<td align=\"right\">".price(price2num($numb>0?($tot/$numb):0,'MT'))."</td>";
  290. print "</tr>\n";
  291. print "</table><br>\n";
  292. print '</td></tr>';
  293. print '</table>';
  294. $db->close();
  295. llxFooter();
  296. ?>