index.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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"), '', 'members');
  45. $Adherents = array();
  46. $AdherentsAValider = array();
  47. $MemberUpToDate = array();
  48. $AdherentsResilies = array();
  49. $AdherentType = array();
  50. // Type of membership
  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 per 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 (d.datefin >= '".$db->idate($now)."' OR t.subscription = 0)";
  88. $sql .= " AND t.rowid = d.fk_adherent_type";
  89. $sql .= " GROUP BY d.fk_adherent_type";
  90. dol_syslog("index.php::select nb of uptodate members by type", LOG_DEBUG);
  91. $result = $db->query($sql);
  92. if ($result)
  93. {
  94. $num = $db->num_rows($result);
  95. $i = 0;
  96. while ($i < $num)
  97. {
  98. $objp = $db->fetch_object($result);
  99. $MemberUpToDate[$objp->fk_adherent_type] = $objp->somme;
  100. $i++;
  101. }
  102. $db->free();
  103. }
  104. print '<div class="fichecenter"><div class="fichethirdleft">';
  105. if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
  106. {
  107. // Search contact/address
  108. if (!empty($conf->adherent->enabled) && $user->rights->adherent->lire)
  109. {
  110. $listofsearchfields['search_member'] = array('text'=>'Member');
  111. }
  112. if (count($listofsearchfields))
  113. {
  114. print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
  115. print '<input type="hidden" name="token" value="'.newToken().'">';
  116. print '<div class="div-table-responsive-no-min">';
  117. print '<table class="noborder nohover centpercent">';
  118. $i = 0;
  119. foreach ($listofsearchfields as $key => $value)
  120. {
  121. if ($i == 0) print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
  122. print '<tr class="oddeven">';
  123. 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>';
  124. if ($i == 0) print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
  125. print '</tr>';
  126. $i++;
  127. }
  128. print '</table>';
  129. print '</div>';
  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 centpercent">';
  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. $i = 0;
  150. foreach ($AdherentType as $key => $adhtype)
  151. {
  152. $dataval['draft'][] = array($i, isset($MemberToValidate[$key]) ? $MemberToValidate[$key] : 0);
  153. $dataval['notuptodate'][] = array($i, isset($MembersValidated[$key]) ? $MembersValidated[$key] - (isset($MemberUpToDate[$key]) ? $MemberUpToDate[$key] : 0) : 0);
  154. $dataval['uptodate'][] = array($i, isset($MemberUpToDate[$key]) ? $MemberUpToDate[$key] : 0);
  155. $dataval['resiliated'][] = array($i, isset($MembersResiliated[$key]) ? $MembersResiliated[$key] : 0);
  156. $SommeA += isset($MemberToValidate[$key]) ? $MemberToValidate[$key] : 0;
  157. $SommeB += isset($MembersValidated[$key]) ? $MembersValidated[$key] - (isset($MemberUpToDate[$key]) ? $MemberUpToDate[$key] : 0) : 0;
  158. $SommeC += isset($MemberUpToDate[$key]) ? $MemberUpToDate[$key] : 0;
  159. $SommeD += isset($MembersResiliated[$key]) ? $MembersResiliated[$key] : 0;
  160. $i++;
  161. }
  162. $total = $SommeA + $SommeB + $SommeC + $SommeD;
  163. $dataseries = array();
  164. $dataseries[] = array($langs->transnoentitiesnoconv("MenuMembersNotUpToDate"), round($SommeB));
  165. $dataseries[] = array($langs->transnoentitiesnoconv("MenuMembersUpToDate"), round($SommeC));
  166. $dataseries[] = array($langs->transnoentitiesnoconv("MembersStatusResiliated"), round($SommeD));
  167. $dataseries[] = array($langs->transnoentitiesnoconv("MembersStatusToValid"), round($SommeA));
  168. include_once DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
  169. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  170. $dolgraph = new DolGraph();
  171. $dolgraph->SetData($dataseries);
  172. $dolgraph->SetDataColor(array($badgeStatus1, $badgeStatus4, $badgeStatus6, '-'.$badgeStatus0));
  173. $dolgraph->setShowLegend(2);
  174. $dolgraph->setShowPercent(1);
  175. $dolgraph->SetType(array('pie'));
  176. $dolgraph->setHeight('200');
  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. $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 centpercent">';
  214. print '<tr class="liste_titre">';
  215. print '<th>'.$langs->trans("Year").'</th>';
  216. print '<th class="right">'.$langs->trans("Subscriptions").'</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. $i = 0;
  222. foreach ($Total as $key=>$value)
  223. {
  224. if ($i >= 8)
  225. {
  226. print '<tr class="oddeven">';
  227. print "<td>...</td>";
  228. print "<td class=\"right\"></td>";
  229. print "<td class=\"right\"></td>";
  230. print "<td class=\"right\"></td>";
  231. print "</tr>\n";
  232. break;
  233. }
  234. print '<tr class="oddeven">';
  235. print "<td><a href=\"./subscription/list.php?date_select=$key\">$key</a></td>";
  236. print "<td class=\"right\">".$Number[$key]."</td>";
  237. print "<td class=\"right\">".price($value)."</td>";
  238. print "<td class=\"right\">".price(price2num($value / $Number[$key], 'MT'))."</td>";
  239. print "</tr>\n";
  240. $i++;
  241. }
  242. // Total
  243. print '<tr class="liste_total">';
  244. print '<td>'.$langs->trans("Total").'</td>';
  245. print "<td class=\"right\">".$numb."</td>";
  246. print '<td class="right">'.price($tot)."</td>";
  247. print "<td class=\"right\">".price(price2num($numb > 0 ? ($tot / $numb) : 0, 'MT'))."</td>";
  248. print "</tr>\n";
  249. print "</table></div>";
  250. print "<br>\n";
  251. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  252. /*
  253. * Latest modified members
  254. */
  255. $max = 5;
  256. $sql = "SELECT a.rowid, a.statut, a.lastname, a.firstname, a.societe as company, a.fk_soc,";
  257. $sql .= " a.tms as datem, datefin as date_end_subscription,";
  258. $sql .= " ta.rowid as typeid, ta.libelle as label, ta.subscription";
  259. $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a, ".MAIN_DB_PREFIX."adherent_type as ta";
  260. $sql .= " WHERE a.entity IN (".getEntity('adherent').")";
  261. $sql .= " AND a.fk_adherent_type = ta.rowid";
  262. $sql .= $db->order("a.tms", "DESC");
  263. $sql .= $db->plimit($max, 0);
  264. $resql = $db->query($sql);
  265. if ($resql)
  266. {
  267. print '<div class="div-table-responsive-no-min">';
  268. print '<table class="noborder centpercent">';
  269. print '<tr class="liste_titre">';
  270. print '<th colspan="4">'.$langs->trans("LastMembersModified", $max).'</th></tr>';
  271. $num = $db->num_rows($resql);
  272. if ($num)
  273. {
  274. $i = 0;
  275. while ($i < $num)
  276. {
  277. $obj = $db->fetch_object($resql);
  278. print '<tr class="oddeven">';
  279. $staticmember->id = $obj->rowid;
  280. $staticmember->lastname = $obj->lastname;
  281. $staticmember->firstname = $obj->firstname;
  282. if (!empty($obj->fk_soc))
  283. {
  284. $staticmember->fk_soc = $obj->fk_soc;
  285. $staticmember->fetch_thirdparty();
  286. $staticmember->name = $staticmember->thirdparty->name;
  287. }
  288. else
  289. {
  290. $staticmember->name = $obj->company;
  291. }
  292. $staticmember->ref = $staticmember->getFullName($langs);
  293. $statictype->id = $obj->typeid;
  294. $statictype->label = $obj->label;
  295. print '<td>'.$staticmember->getNomUrl(1, 32).'</td>';
  296. print '<td>'.$statictype->getNomUrl(1, 32).'</td>';
  297. print '<td>'.dol_print_date($db->jdate($obj->datem), 'dayhour').'</td>';
  298. print '<td class="right">'.$staticmember->LibStatut($obj->statut, ($obj->subscription == 'yes' ? 1 : 0), $db->jdate($obj->date_end_subscription), 3).'</td>';
  299. print '</tr>';
  300. $i++;
  301. }
  302. }
  303. print "</table></div>";
  304. print "<br>";
  305. }
  306. else
  307. {
  308. dol_print_error($db);
  309. }
  310. /*
  311. * Last modified subscriptions
  312. */
  313. $max = 5;
  314. $sql = "SELECT a.rowid, a.statut, a.lastname, a.firstname, a.societe as company, a.fk_soc,";
  315. $sql .= " datefin as date_end_subscription,";
  316. $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";
  317. $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a, ".MAIN_DB_PREFIX."subscription as c";
  318. $sql .= " WHERE a.entity IN (".getEntity('adherent').")";
  319. $sql .= " AND c.fk_adherent = a.rowid";
  320. $sql .= $db->order("c.tms", "DESC");
  321. $sql .= $db->plimit($max, 0);
  322. $resql = $db->query($sql);
  323. if ($resql)
  324. {
  325. print '<div class="div-table-responsive-no-min">';
  326. print '<table class="noborder centpercent">';
  327. print '<tr class="liste_titre">';
  328. print '<th colspan="5">'.$langs->trans("LastSubscriptionsModified", $max).'</th></tr>';
  329. $num = $db->num_rows($resql);
  330. if ($num)
  331. {
  332. $i = 0;
  333. while ($i < $num)
  334. {
  335. $obj = $db->fetch_object($resql);
  336. print '<tr class="oddeven">';
  337. $subscriptionstatic->id = $obj->cid;
  338. $subscriptionstatic->ref = $obj->cid;
  339. $staticmember->id = $obj->rowid;
  340. $staticmember->lastname = $obj->lastname;
  341. $staticmember->firstname = $obj->firstname;
  342. if (!empty($obj->fk_soc)) {
  343. $staticmember->fk_soc = $obj->fk_soc;
  344. $staticmember->fetch_thirdparty();
  345. $staticmember->name = $staticmember->thirdparty->name;
  346. } else {
  347. $staticmember->name = $obj->company;
  348. }
  349. $staticmember->ref = $staticmember->getFullName($langs);
  350. print '<td>'.$subscriptionstatic->getNomUrl(1).'</td>';
  351. print '<td>'.$staticmember->getNomUrl(1, 32, 'subscription').'</td>';
  352. print '<td>'.get_date_range($db->jdate($obj->date_start), $db->jdate($obj->date_end)).'</td>';
  353. print '<td class="right">'.price($obj->subscription).'</td>';
  354. //print '<td class="right">'.$staticmember->LibStatut($obj->statut,($obj->subscription=='yes'?1:0),$db->jdate($obj->date_end_subscription),5).'</td>';
  355. print '<td class="right">'.dol_print_date($db->jdate($obj->datem ? $obj->datem : $obj->datec), 'dayhour').'</td>';
  356. print '</tr>';
  357. $i++;
  358. }
  359. }
  360. print "</table></div>";
  361. print "<br>";
  362. }
  363. else
  364. {
  365. dol_print_error($db);
  366. }
  367. // Summary of members by type
  368. print '<div class="div-table-responsive-no-min">';
  369. print '<table class="noborder centpercent">';
  370. print '<tr class="liste_titre">';
  371. print '<th>'.$langs->trans("MembersTypes").'</th>';
  372. print '<th class=right>'.$langs->trans("MembersStatusToValid").'</th>';
  373. print '<th class=right>'.$langs->trans("MenuMembersNotUpToDate").'</th>';
  374. print '<th class=right>'.$langs->trans("MenuMembersUpToDate").'</th>';
  375. print '<th class=right>'.$langs->trans("MembersStatusResiliated").'</th>';
  376. print "</tr>\n";
  377. foreach ($AdherentType as $key => $adhtype)
  378. {
  379. print '<tr class="oddeven">';
  380. print '<td>'.$adhtype->getNomUrl(1, dol_size(32)).'</td>';
  381. print '<td class="right">'.(isset($MemberToValidate[$key]) && $MemberToValidate[$key] > 0 ? $MemberToValidate[$key] : '').' '.$staticmember->LibStatut(-1, $adhtype->subscription, 0, 3).'</td>';
  382. 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>';
  383. print '<td class="right">'.(isset($MemberUpToDate[$key]) && $MemberUpToDate[$key] > 0 ? $MemberUpToDate[$key] : '').' '.$staticmember->LibStatut(1, $adhtype->subscription, $now, 3).'</td>';
  384. print '<td class="right">'.(isset($MembersResiliated[$key]) && $MembersResiliated[$key] > 0 ? $MembersResiliated[$key] : '').' '.$staticmember->LibStatut(0, $adhtype->subscription, 0, 3).'</td>';
  385. print "</tr>\n";
  386. }
  387. print '<tr class="liste_total">';
  388. print '<td class="liste_total">'.$langs->trans("Total").'</td>';
  389. print '<td class="liste_total right">'.$SommeA.' '.$staticmember->LibStatut(-1, $adhtype->subscription, 0, 3).'</td>';
  390. print '<td class="liste_total right">'.$SommeB.' '.$staticmember->LibStatut(1, $adhtype->subscription, 0, 3).'</td>';
  391. print '<td class="liste_total right">'.$SommeC.' '.$staticmember->LibStatut(1, $adhtype->subscription, $now, 3).'</td>';
  392. print '<td class="liste_total right">'.$SommeD.' '.$staticmember->LibStatut(0, $adhtype->subscription, 0, 3).'</td>';
  393. print '</tr>';
  394. print "</table>\n";
  395. print "</div>";
  396. print '</div></div></div>';
  397. $parameters = array('user' => $user);
  398. $reshook = $hookmanager->executeHooks('dashboardMembers', $parameters, $object); // Note that $action and $object may have been modified by hook
  399. // End of page
  400. llxFooter();
  401. $db->close();