index.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/adherents/index.php
  22. * \ingroup member
  23. * \brief Page accueil module adherents
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
  29. // Load translation files required by the page
  30. $langs->loadLangs(array("companies","members"));
  31. // Security check
  32. $result=restrictedArea($user,'adherent');
  33. /*
  34. * View
  35. */
  36. llxHeader('',$langs->trans("Members"),'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros');
  37. $staticmember=new Adherent($db);
  38. $statictype=new AdherentType($db);
  39. $subscriptionstatic=new Subscription($db);
  40. print load_fiche_titre($langs->trans("MembersArea"));
  41. $Adherents=array();
  42. $AdherentsAValider=array();
  43. $MemberUpToDate=array();
  44. $AdherentsResilies=array();
  45. $AdherentType=array();
  46. // Members list
  47. $sql = "SELECT t.rowid, t.libelle as label, t.subscription,";
  48. $sql.= " d.statut, count(d.rowid) as somme";
  49. $sql.= " FROM ".MAIN_DB_PREFIX."adherent_type as t";
  50. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as d";
  51. $sql.= " ON t.rowid = d.fk_adherent_type";
  52. $sql.= " AND d.entity IN (".getEntity('adherent').")";
  53. $sql.= " WHERE t.entity IN (".getEntity('member_type').")";
  54. $sql.= " GROUP BY t.rowid, t.libelle, t.subscription, d.statut";
  55. dol_syslog("index.php::select nb of members by type", LOG_DEBUG);
  56. $result = $db->query($sql);
  57. if ($result)
  58. {
  59. $num = $db->num_rows($result);
  60. $i = 0;
  61. while ($i < $num)
  62. {
  63. $objp = $db->fetch_object($result);
  64. $adhtype=new AdherentType($db);
  65. $adhtype->id=$objp->rowid;
  66. $adhtype->subscription=$objp->subscription;
  67. $adhtype->label=$objp->label;
  68. $AdherentType[$objp->rowid]=$adhtype;
  69. if ($objp->statut == -1) { $MemberToValidate[$objp->rowid]=$objp->somme; }
  70. if ($objp->statut == 1) { $MembersValidated[$objp->rowid]=$objp->somme; }
  71. if ($objp->statut == 0) { $MembersResiliated[$objp->rowid]=$objp->somme; }
  72. $i++;
  73. }
  74. $db->free($result);
  75. }
  76. $now=dol_now();
  77. // Members up to date list
  78. // current rule: uptodate = the end date is in future whatever is type
  79. // old rule: uptodate = if type does not need payment, that end date is null, if type need payment that end date is in future)
  80. $sql = "SELECT count(*) as somme , d.fk_adherent_type";
  81. $sql.= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."adherent_type as t";
  82. $sql.= " WHERE d.entity IN (".getEntity('adherent').")";
  83. //$sql.= " AND d.statut = 1 AND ((t.subscription = 0 AND d.datefin IS NULL) OR d.datefin >= '".$db->idate($now)."')";
  84. $sql.= " AND d.statut = 1 AND d.datefin >= '".$db->idate($now)."'";
  85. $sql.= " AND t.rowid = d.fk_adherent_type";
  86. $sql.= " GROUP BY d.fk_adherent_type";
  87. dol_syslog("index.php::select nb of uptodate members by type", LOG_DEBUG);
  88. $result = $db->query($sql);
  89. if ($result)
  90. {
  91. $num = $db->num_rows($result);
  92. $i = 0;
  93. while ($i < $num)
  94. {
  95. $objp = $db->fetch_object($result);
  96. $MemberUpToDate[$objp->fk_adherent_type]=$objp->somme;
  97. $i++;
  98. }
  99. $db->free();
  100. }
  101. //print '<tr><td width="30%" class="notopnoleft" valign="top">';
  102. print '<div class="fichecenter"><div class="fichethirdleft">';
  103. if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
  104. {
  105. // Search contact/address
  106. if (! empty($conf->adherent->enabled) && $user->rights->adherent->lire)
  107. {
  108. $listofsearchfields['search_member']=array('text'=>'Member');
  109. }
  110. if (count($listofsearchfields))
  111. {
  112. print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
  113. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  114. print '<table class="noborder nohover centpercent">';
  115. $i=0;
  116. foreach($listofsearchfields as $key => $value)
  117. {
  118. if ($i == 0) print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
  119. print '<tr class="oddeven">';
  120. print '<td class="nowrap"><label for="'.$key.'">'.$langs->trans($value["text"]).'</label>:</td><td><input type="text" class="flat inputsearch" name="'.$key.'" id="'.$key.'" size="18"></td>';
  121. if ($i == 0) print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
  122. print '</tr>';
  123. $i++;
  124. }
  125. print '</table>';
  126. print '</form>';
  127. print '<br>';
  128. }
  129. }
  130. /*
  131. * Statistics
  132. */
  133. if ($conf->use_javascript_ajax)
  134. {
  135. print '<div class="div-table-responsive-no-min">';
  136. print '<table class="noborder nohover" width="100%">';
  137. print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
  138. print '<tr><td align="center" colspan="2">';
  139. $SommeA=0;
  140. $SommeB=0;
  141. $SommeC=0;
  142. $SommeD=0;
  143. $total=0;
  144. $dataval=array();
  145. $datalabels=array();
  146. $i=0;
  147. foreach ($AdherentType as $key => $adhtype)
  148. {
  149. $datalabels[]=array($i,$adhtype->getNomUrl(0,dol_size(16)));
  150. $dataval['draft'][]=array($i,isset($MemberToValidate[$key])?$MemberToValidate[$key]:0);
  151. $dataval['notuptodate'][]=array($i,isset($MembersValidated[$key])?$MembersValidated[$key]-(isset($MemberUpToDate[$key])?$MemberUpToDate[$key]:0):0);
  152. $dataval['uptodate'][]=array($i,isset($MemberUpToDate[$key])?$MemberUpToDate[$key]:0);
  153. $dataval['resiliated'][]=array($i,isset($MembersResiliated[$key])?$MembersResiliated[$key]:0);
  154. $SommeA+=isset($MemberToValidate[$key])?$MemberToValidate[$key]:0;
  155. $SommeB+=isset($MembersValidated[$key])?$MembersValidated[$key]-(isset($MemberUpToDate[$key])?$MemberUpToDate[$key]:0):0;
  156. $SommeC+=isset($MemberUpToDate[$key])?$MemberUpToDate[$key]:0;
  157. $SommeD+=isset($MembersResiliated[$key])?$MembersResiliated[$key]:0;
  158. $i++;
  159. }
  160. $total = $SommeA + $SommeB + $SommeC + $SommeD;
  161. $dataseries=array();
  162. $dataseries[]=array($langs->trans("MenuMembersNotUpToDate"), round($SommeB));
  163. $dataseries[]=array($langs->trans("MenuMembersUpToDate"), round($SommeC));
  164. $dataseries[]=array($langs->trans("MembersStatusResiliated"), round($SommeD));
  165. $dataseries[]=array($langs->trans("MembersStatusToValid"), round($SommeA));
  166. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  167. $dolgraph = new DolGraph();
  168. $dolgraph->SetData($dataseries);
  169. $dolgraph->setShowLegend(1);
  170. $dolgraph->setShowPercent(1);
  171. $dolgraph->SetType(array('pie'));
  172. $dolgraph->setWidth('100%');
  173. $dolgraph->draw('idgraphstatus');
  174. print $dolgraph->show($total?0:1);
  175. print '</td></tr>';
  176. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">';
  177. print $SommeA+$SommeB+$SommeC+$SommeD;
  178. print '</td></tr>';
  179. print '</table>';
  180. print '</div>';
  181. }
  182. print '<br>';
  183. // List of subscription by year
  184. $Total=array();
  185. $Number=array();
  186. $tot=0;
  187. $numb=0;
  188. $sql = "SELECT c.subscription, c.dateadh as dateh";
  189. $sql.= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."subscription as c";
  190. $sql.= " WHERE d.entity IN (".getEntity('adherent').")";
  191. $sql.= " AND d.rowid = c.fk_adherent";
  192. if(isset($date_select) && $date_select != '')
  193. {
  194. $sql .= " AND c.dateadh LIKE '".$date_select."%'";
  195. }
  196. $result = $db->query($sql);
  197. if ($result)
  198. {
  199. $num = $db->num_rows($result);
  200. $i = 0;
  201. while ($i < $num)
  202. {
  203. $objp = $db->fetch_object($result);
  204. $year=dol_print_date($db->jdate($objp->dateh),"%Y");
  205. $Total[$year]=(isset($Total[$year])?$Total[$year]:0)+$objp->subscription;
  206. $Number[$year]=(isset($Number[$year])?$Number[$year]:0)+1;
  207. $tot+=$objp->subscription;
  208. $numb+=1;
  209. $i++;
  210. }
  211. }
  212. print '<div class="div-table-responsive-no-min">';
  213. print '<table class="noborder" width="100%">';
  214. print '<tr class="liste_titre">';
  215. print '<th>'.$langs->trans("Subscriptions").'</th>';
  216. print '<th class="right">'.$langs->trans("Number").'</th>';
  217. print '<th class="right">'.$langs->trans("AmountTotal").'</th>';
  218. print '<th class="right">'.$langs->trans("AmountAverage").'</th>';
  219. print "</tr>\n";
  220. krsort($Total);
  221. foreach ($Total as $key=>$value)
  222. {
  223. print '<tr class="oddeven">';
  224. print "<td><a href=\"./subscription/list.php?date_select=$key\">$key</a></td>";
  225. print "<td class=\"right\">".$Number[$key]."</td>";
  226. print "<td class=\"right\">".price($value)."</td>";
  227. print "<td class=\"right\">".price(price2num($value/$Number[$key],'MT'))."</td>";
  228. print "</tr>\n";
  229. }
  230. // Total
  231. print '<tr class="liste_total">';
  232. print '<td>'.$langs->trans("Total").'</td>';
  233. print "<td class=\"right\">".$numb."</td>";
  234. print '<td class="right">'.price($tot)."</td>";
  235. print "<td class=\"right\">".price(price2num($numb>0?($tot/$numb):0,'MT'))."</td>";
  236. print "</tr>\n";
  237. print "</table></div>";
  238. print "<br>\n";
  239. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  240. /*
  241. * Last modified members
  242. */
  243. $max=5;
  244. $sql = "SELECT a.rowid, a.statut, a.lastname, a.firstname, a.societe as company, a.fk_soc,";
  245. $sql.= " a.tms as datem, datefin as date_end_subscription,";
  246. $sql.= " ta.rowid as typeid, ta.libelle as label, ta.subscription";
  247. $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a, ".MAIN_DB_PREFIX."adherent_type as ta";
  248. $sql.= " WHERE a.entity IN (".getEntity('adherent').")";
  249. $sql.= " AND a.fk_adherent_type = ta.rowid";
  250. $sql.= $db->order("a.tms","DESC");
  251. $sql.= $db->plimit($max, 0);
  252. $resql=$db->query($sql);
  253. if ($resql)
  254. {
  255. print '<div class="div-table-responsive-no-min">';
  256. print '<table class="noborder" width="100%">';
  257. print '<tr class="liste_titre">';
  258. print '<th colspan="4">'.$langs->trans("LastMembersModified",$max).'</th></tr>';
  259. $num = $db->num_rows($resql);
  260. if ($num)
  261. {
  262. $i = 0;
  263. while ($i < $num)
  264. {
  265. $obj = $db->fetch_object($resql);
  266. print '<tr class="oddeven">';
  267. $staticmember->id=$obj->rowid;
  268. $staticmember->lastname=$obj->lastname;
  269. $staticmember->firstname=$obj->firstname;
  270. if (! empty($obj->fk_soc))
  271. {
  272. $staticmember->fk_soc = $obj->fk_soc;
  273. $staticmember->fetch_thirdparty();
  274. $staticmember->name=$staticmember->thirdparty->name;
  275. }
  276. else
  277. {
  278. $staticmember->name=$obj->company;
  279. }
  280. $staticmember->ref=$staticmember->getFullName($langs);
  281. $statictype->id=$obj->typeid;
  282. $statictype->label=$obj->label;
  283. print '<td>'.$staticmember->getNomUrl(1,32).'</td>';
  284. print '<td>'.$statictype->getNomUrl(1,32).'</td>';
  285. print '<td>'.dol_print_date($db->jdate($obj->datem),'dayhour').'</td>';
  286. print '<td class="right">'.$staticmember->LibStatut($obj->statut,($obj->subscription=='yes'?1:0),$db->jdate($obj->date_end_subscription),5).'</td>';
  287. print '</tr>';
  288. $i++;
  289. }
  290. }
  291. print "</table></div>";
  292. print "<br>";
  293. }
  294. else
  295. {
  296. dol_print_error($db);
  297. }
  298. /*
  299. * Last modified subscriptions
  300. */
  301. $max=5;
  302. $sql = "SELECT a.rowid, a.statut, a.lastname, a.firstname, a.societe as company, a.fk_soc,";
  303. $sql.= " datefin as date_end_subscription,";
  304. $sql.= " c.rowid as cid, c.tms as datem, c.datec as datec, c.dateadh as date_start, c.datef as date_end, c.subscription";
  305. $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a, ".MAIN_DB_PREFIX."subscription as c";
  306. $sql.= " WHERE a.entity IN (".getEntity('adherent').")";
  307. $sql.= " AND c.fk_adherent = a.rowid";
  308. $sql.= $db->order("c.tms","DESC");
  309. $sql.= $db->plimit($max, 0);
  310. $resql=$db->query($sql);
  311. if ($resql)
  312. {
  313. print '<div class="div-table-responsive-no-min">';
  314. print '<table class="noborder" width="100%">';
  315. print '<tr class="liste_titre">';
  316. print '<th colspan="5">'.$langs->trans("LastSubscriptionsModified",$max).'</th></tr>';
  317. $num = $db->num_rows($resql);
  318. if ($num)
  319. {
  320. $i = 0;
  321. while ($i < $num)
  322. {
  323. $obj = $db->fetch_object($resql);
  324. print '<tr class="oddeven">';
  325. $subscriptionstatic->id=$obj->cid;
  326. $subscriptionstatic->ref=$obj->cid;
  327. $staticmember->id=$obj->rowid;
  328. $staticmember->lastname=$obj->lastname;
  329. $staticmember->firstname=$obj->firstname;
  330. if (! empty($obj->fk_soc)) {
  331. $staticmember->fk_soc = $obj->fk_soc;
  332. $staticmember->fetch_thirdparty();
  333. $staticmember->name=$staticmember->thirdparty->name;
  334. } else {
  335. $staticmember->name=$obj->company;
  336. }
  337. $staticmember->ref=$staticmember->getFullName($langs);
  338. print '<td>'.$subscriptionstatic->getNomUrl(1).'</td>';
  339. print '<td>'.$staticmember->getNomUrl(1,32,'subscription').'</td>';
  340. print '<td>'.get_date_range($db->jdate($obj->date_start),$db->jdate($obj->date_end)).'</td>';
  341. print '<td class="right">'.price($obj->subscription).'</td>';
  342. //print '<td class="right">'.$staticmember->LibStatut($obj->statut,($obj->subscription=='yes'?1:0),$db->jdate($obj->date_end_subscription),5).'</td>';
  343. print '<td class="right">'.dol_print_date($db->jdate($obj->datem?$obj->datem:$obj->datec),'dayhour').'</td>';
  344. print '</tr>';
  345. $i++;
  346. }
  347. }
  348. print "</table></div>";
  349. print "<br>";
  350. }
  351. else
  352. {
  353. dol_print_error($db);
  354. }
  355. // Summary of members by type
  356. print '<div class="div-table-responsive-no-min">';
  357. print '<table class="noborder" width="100%">';
  358. print '<tr class="liste_titre">';
  359. print '<th>'.$langs->trans("MembersTypes").'</th>';
  360. print '<th class=right>'.$langs->trans("MembersStatusToValid").'</th>';
  361. print '<th class=right>'.$langs->trans("MenuMembersNotUpToDate").'</th>';
  362. print '<th class=right>'.$langs->trans("MenuMembersUpToDate").'</th>';
  363. print '<th class=right>'.$langs->trans("MembersStatusResiliated").'</th>';
  364. print "</tr>\n";
  365. foreach ($AdherentType as $key => $adhtype)
  366. {
  367. print '<tr class="oddeven">';
  368. print '<td>'.$adhtype->getNomUrl(1, dol_size(32)).'</td>';
  369. print '<td class="right">'.(isset($MemberToValidate[$key]) && $MemberToValidate[$key] > 0?$MemberToValidate[$key]:'').' '.$staticmember->LibStatut(-1,$adhtype->subscription,0,3).'</td>';
  370. print '<td class="right">'.(isset($MembersValidated[$key]) && ($MembersValidated[$key]-(isset($MemberUpToDate[$key])?$MemberUpToDate[$key]:0) > 0) ? $MembersValidated[$key]-(isset($MemberUpToDate[$key])?$MemberUpToDate[$key]:0):'').' '.$staticmember->LibStatut(1,$adhtype->subscription,0,3).'</td>';
  371. print '<td class="right">'.(isset($MemberUpToDate[$key]) && $MemberUpToDate[$key] > 0 ? $MemberUpToDate[$key]:'').' '.$staticmember->LibStatut(1,$adhtype->subscription,$now,3).'</td>';
  372. print '<td class="right">'.(isset($MembersResiliated[$key]) && $MembersResiliated[$key]> 0 ?$MembersResiliated[$key]:'').' '.$staticmember->LibStatut(0,$adhtype->subscription,0,3).'</td>';
  373. print "</tr>\n";
  374. }
  375. print '<tr class="liste_total">';
  376. print '<td class="liste_total">'.$langs->trans("Total").'</td>';
  377. print '<td class="liste_total" class="right">'.$SommeA.' '.$staticmember->LibStatut(-1,$adhtype->subscription,0,3).'</td>';
  378. print '<td class="liste_total" class="right">'.$SommeB.' '.$staticmember->LibStatut(1,$adhtype->subscription,0,3).'</td>';
  379. print '<td class="liste_total" class="right">'.$SommeC.' '.$staticmember->LibStatut(1,$adhtype->subscription,$now,3).'</td>';
  380. print '<td class="liste_total" class="right">'.$SommeD.' '.$staticmember->LibStatut(0,$adhtype->subscription,0,3).'</td>';
  381. print '</tr>';
  382. print "</table>\n";
  383. print "</div>";
  384. print '</div></div></div>';
  385. // End of page
  386. llxFooter();
  387. $db->close();