index.php 16 KB

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