dolibarr  9.0.0
index.php
Go to the documentation of this file.
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 
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
31 
32 // Load translation files required by the page
33 $langs->loadLangs(array("companies","members"));
34 
35 // Security check
36 $result=restrictedArea($user,'adherent');
37 
38 
39 /*
40  * View
41  */
42 
43 llxHeader('',$langs->trans("Members"),'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros');
44 
45 $staticmember=new Adherent($db);
46 $statictype=new AdherentType($db);
47 $subscriptionstatic=new Subscription($db);
48 
49 print load_fiche_titre($langs->trans("MembersArea"));
50 
51 $Adherents=array();
52 $AdherentsAValider=array();
53 $MemberUpToDate=array();
54 $AdherentsResilies=array();
55 
56 $AdherentType=array();
57 
58 // Members list
59 $sql = "SELECT t.rowid, t.libelle as label, t.subscription,";
60 $sql.= " d.statut, count(d.rowid) as somme";
61 $sql.= " FROM ".MAIN_DB_PREFIX."adherent_type as t";
62 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as d";
63 $sql.= " ON t.rowid = d.fk_adherent_type";
64 $sql.= " AND d.entity IN (".getEntity('adherent').")";
65 $sql.= " WHERE t.entity IN (".getEntity('member_type').")";
66 $sql.= " GROUP BY t.rowid, t.libelle, t.subscription, d.statut";
67 
68 dol_syslog("index.php::select nb of members by type", LOG_DEBUG);
69 $result = $db->query($sql);
70 if ($result)
71 {
72  $num = $db->num_rows($result);
73  $i = 0;
74  while ($i < $num)
75  {
76  $objp = $db->fetch_object($result);
77 
78  $adhtype=new AdherentType($db);
79  $adhtype->id=$objp->rowid;
80  $adhtype->subscription=$objp->subscription;
81  $adhtype->label=$objp->label;
82  $AdherentType[$objp->rowid]=$adhtype;
83 
84  if ($objp->statut == -1) { $MemberToValidate[$objp->rowid]=$objp->somme; }
85  if ($objp->statut == 1) { $MembersValidated[$objp->rowid]=$objp->somme; }
86  if ($objp->statut == 0) { $MembersResiliated[$objp->rowid]=$objp->somme; }
87 
88  $i++;
89  }
90  $db->free($result);
91 }
92 
93 $now=dol_now();
94 
95 // Members up to date list
96 // current rule: uptodate = the end date is in future whatever is type
97 // old rule: uptodate = if type does not need payment, that end date is null, if type need payment that end date is in future)
98 $sql = "SELECT count(*) as somme , d.fk_adherent_type";
99 $sql.= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."adherent_type as t";
100 $sql.= " WHERE d.entity IN (".getEntity('adherent').")";
101 //$sql.= " AND d.statut = 1 AND ((t.subscription = 0 AND d.datefin IS NULL) OR d.datefin >= '".$db->idate($now)."')";
102 $sql.= " AND d.statut = 1 AND d.datefin >= '".$db->idate($now)."'";
103 $sql.= " AND t.rowid = d.fk_adherent_type";
104 $sql.= " GROUP BY d.fk_adherent_type";
105 
106 dol_syslog("index.php::select nb of uptodate members by type", LOG_DEBUG);
107 $result = $db->query($sql);
108 if ($result)
109 {
110  $num = $db->num_rows($result);
111  $i = 0;
112  while ($i < $num)
113  {
114  $objp = $db->fetch_object($result);
115  $MemberUpToDate[$objp->fk_adherent_type]=$objp->somme;
116  $i++;
117  }
118  $db->free();
119 }
120 
121 
122 //print '<tr><td width="30%" class="notopnoleft" valign="top">';
123 print '<div class="fichecenter"><div class="fichethirdleft">';
124 
125 
126 if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
127 {
128  // Search contact/address
129  if (! empty($conf->adherent->enabled) && $user->rights->adherent->lire)
130  {
131  $listofsearchfields['search_member']=array('text'=>'Member');
132  }
133 
134  if (count($listofsearchfields))
135  {
136  print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
137  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
138  print '<table class="noborder nohover centpercent">';
139  $i=0;
140  foreach($listofsearchfields as $key => $value)
141  {
142  if ($i == 0) print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
143  print '<tr class="oddeven">';
144  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>';
145  if ($i == 0) print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
146  print '</tr>';
147  $i++;
148  }
149  print '</table>';
150  print '</form>';
151  print '<br>';
152  }
153 }
154 
155 
156 /*
157  * Statistics
158  */
159 
160 if ($conf->use_javascript_ajax)
161 {
162  print '<div class="div-table-responsive-no-min">';
163  print '<table class="noborder nohover" width="100%">';
164  print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
165  print '<tr><td align="center" colspan="2">';
166 
167  $SommeA=0;
168  $SommeB=0;
169  $SommeC=0;
170  $SommeD=0;
171  $total=0;
172  $dataval=array();
173  $datalabels=array();
174  $i=0;
175  foreach ($AdherentType as $key => $adhtype)
176  {
177  $datalabels[]=array($i,$adhtype->getNomUrl(0,dol_size(16)));
178  $dataval['draft'][]=array($i,isset($MemberToValidate[$key])?$MemberToValidate[$key]:0);
179  $dataval['notuptodate'][]=array($i,isset($MembersValidated[$key])?$MembersValidated[$key]-(isset($MemberUpToDate[$key])?$MemberUpToDate[$key]:0):0);
180  $dataval['uptodate'][]=array($i,isset($MemberUpToDate[$key])?$MemberUpToDate[$key]:0);
181  $dataval['resiliated'][]=array($i,isset($MembersResiliated[$key])?$MembersResiliated[$key]:0);
182  $SommeA+=isset($MemberToValidate[$key])?$MemberToValidate[$key]:0;
183  $SommeB+=isset($MembersValidated[$key])?$MembersValidated[$key]-(isset($MemberUpToDate[$key])?$MemberUpToDate[$key]:0):0;
184  $SommeC+=isset($MemberUpToDate[$key])?$MemberUpToDate[$key]:0;
185  $SommeD+=isset($MembersResiliated[$key])?$MembersResiliated[$key]:0;
186  $i++;
187  }
188  $total = $SommeA + $SommeB + $SommeC + $SommeD;
189  $dataseries=array();
190  $dataseries[]=array($langs->trans("MenuMembersNotUpToDate"), round($SommeB));
191  $dataseries[]=array($langs->trans("MenuMembersUpToDate"), round($SommeC));
192  $dataseries[]=array($langs->trans("MembersStatusResiliated"), round($SommeD));
193  $dataseries[]=array($langs->trans("MembersStatusToValid"), round($SommeA));
194 
195  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
196  $dolgraph = new DolGraph();
197  $dolgraph->SetData($dataseries);
198  $dolgraph->setShowLegend(1);
199  $dolgraph->setShowPercent(1);
200  $dolgraph->SetType(array('pie'));
201  $dolgraph->setWidth('100%');
202  $dolgraph->draw('idgraphstatus');
203  print $dolgraph->show($total?0:1);
204 
205  print '</td></tr>';
206  print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td align="right">';
207  print $SommeA+$SommeB+$SommeC+$SommeD;
208  print '</td></tr>';
209  print '</table>';
210  print '</div>';
211 }
212 
213 print '<br>';
214 
215 // List of subscription by year
216 $Total=array();
217 $Number=array();
218 $tot=0;
219 $numb=0;
220 
221 $sql = "SELECT c.subscription, c.dateadh as dateh";
222 $sql.= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."subscription as c";
223 $sql.= " WHERE d.entity IN (".getEntity('adherent').")";
224 $sql.= " AND d.rowid = c.fk_adherent";
225 if(isset($date_select) && $date_select != '')
226 {
227  $sql .= " AND c.dateadh LIKE '".$date_select."%'";
228 }
229 $result = $db->query($sql);
230 if ($result)
231 {
232  $num = $db->num_rows($result);
233  $i = 0;
234  while ($i < $num)
235  {
236  $objp = $db->fetch_object($result);
237  $year=dol_print_date($db->jdate($objp->dateh),"%Y");
238  $Total[$year]=(isset($Total[$year])?$Total[$year]:0)+$objp->subscription;
239  $Number[$year]=(isset($Number[$year])?$Number[$year]:0)+1;
240  $tot+=$objp->subscription;
241  $numb+=1;
242  $i++;
243  }
244 }
245 
246 print '<div class="div-table-responsive-no-min">';
247 print '<table class="noborder" width="100%">';
248 print '<tr class="liste_titre">';
249 print '<th>'.$langs->trans("Subscriptions").'</th>';
250 print '<th align="right">'.$langs->trans("Number").'</th>';
251 print '<th align="right">'.$langs->trans("AmountTotal").'</th>';
252 print '<th align="right">'.$langs->trans("AmountAverage").'</th>';
253 print "</tr>\n";
254 
255 krsort($Total);
256 foreach ($Total as $key=>$value)
257 {
258  print '<tr class="oddeven">';
259  print "<td><a href=\"./subscription/list.php?date_select=$key\">$key</a></td>";
260  print "<td align=\"right\">".$Number[$key]."</td>";
261  print "<td align=\"right\">".price($value)."</td>";
262  print "<td align=\"right\">".price(price2num($value/$Number[$key],'MT'))."</td>";
263  print "</tr>\n";
264 }
265 
266 // Total
267 print '<tr class="liste_total">';
268 print '<td>'.$langs->trans("Total").'</td>';
269 print "<td align=\"right\">".$numb."</td>";
270 print '<td align="right">'.price($tot)."</td>";
271 print "<td align=\"right\">".price(price2num($numb>0?($tot/$numb):0,'MT'))."</td>";
272 print "</tr>\n";
273 print "</table></div>";
274 print "<br>\n";
275 
276 
277 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
278 
279 /*
280  * Last modified members
281  */
282 $max=5;
283 
284 $sql = "SELECT a.rowid, a.statut, a.lastname, a.firstname, a.societe as company, a.fk_soc,";
285 $sql.= " a.tms as datem, datefin as date_end_subscription,";
286 $sql.= " ta.rowid as typeid, ta.libelle as label, ta.subscription";
287 $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a, ".MAIN_DB_PREFIX."adherent_type as ta";
288 $sql.= " WHERE a.entity IN (".getEntity('adherent').")";
289 $sql.= " AND a.fk_adherent_type = ta.rowid";
290 $sql.= $db->order("a.tms","DESC");
291 $sql.= $db->plimit($max, 0);
292 
293 $resql=$db->query($sql);
294 if ($resql)
295 {
296  print '<div class="div-table-responsive-no-min">';
297  print '<table class="noborder" width="100%">';
298  print '<tr class="liste_titre">';
299  print '<th colspan="4">'.$langs->trans("LastMembersModified",$max).'</th></tr>';
300 
301  $num = $db->num_rows($resql);
302  if ($num)
303  {
304  $i = 0;
305  while ($i < $num)
306  {
307  $obj = $db->fetch_object($resql);
308  print '<tr class="oddeven">';
309  $staticmember->id=$obj->rowid;
310  $staticmember->lastname=$obj->lastname;
311  $staticmember->firstname=$obj->firstname;
312  if (! empty($obj->fk_soc))
313  {
314  $staticmember->fk_soc = $obj->fk_soc;
315  $staticmember->fetch_thirdparty();
316  $staticmember->name=$staticmember->thirdparty->name;
317  }
318  else
319  {
320  $staticmember->name=$obj->company;
321  }
322  $staticmember->ref=$staticmember->getFullName($langs);
323  $statictype->id=$obj->typeid;
324  $statictype->label=$obj->label;
325  print '<td>'.$staticmember->getNomUrl(1,32).'</td>';
326  print '<td>'.$statictype->getNomUrl(1,32).'</td>';
327  print '<td>'.dol_print_date($db->jdate($obj->datem),'dayhour').'</td>';
328  print '<td align="right">'.$staticmember->LibStatut($obj->statut,($obj->subscription=='yes'?1:0),$db->jdate($obj->date_end_subscription),5).'</td>';
329  print '</tr>';
330  $i++;
331  }
332  }
333  print "</table></div>";
334  print "<br>";
335 }
336 else
337 {
338  dol_print_error($db);
339 }
340 
341 
342 /*
343  * Last modified subscriptions
344  */
345 $max=5;
346 
347 $sql = "SELECT a.rowid, a.statut, a.lastname, a.firstname, a.societe as company, a.fk_soc,";
348 $sql.= " datefin as date_end_subscription,";
349 $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";
350 $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a, ".MAIN_DB_PREFIX."subscription as c";
351 $sql.= " WHERE a.entity IN (".getEntity('adherent').")";
352 $sql.= " AND c.fk_adherent = a.rowid";
353 $sql.= $db->order("c.tms","DESC");
354 $sql.= $db->plimit($max, 0);
355 
356 $resql=$db->query($sql);
357 if ($resql)
358 {
359  print '<div class="div-table-responsive-no-min">';
360  print '<table class="noborder" width="100%">';
361  print '<tr class="liste_titre">';
362  print '<th colspan="5">'.$langs->trans("LastSubscriptionsModified",$max).'</th></tr>';
363 
364  $num = $db->num_rows($resql);
365  if ($num)
366  {
367  $i = 0;
368  while ($i < $num)
369  {
370  $obj = $db->fetch_object($resql);
371  print '<tr class="oddeven">';
372  $subscriptionstatic->id=$obj->cid;
373  $subscriptionstatic->ref=$obj->cid;
374  $staticmember->id=$obj->rowid;
375  $staticmember->lastname=$obj->lastname;
376  $staticmember->firstname=$obj->firstname;
377  if (! empty($obj->fk_soc)) {
378  $staticmember->socid = $obj->fk_soc;
379  $staticmember->fetch_thirdparty();
380  $staticmember->name=$staticmember->thirdparty->name;
381  } else {
382  $staticmember->name=$obj->company;
383  }
384  $staticmember->ref=$staticmember->getFullName($langs);
385  print '<td>'.$subscriptionstatic->getNomUrl(1).'</td>';
386  print '<td>'.$staticmember->getNomUrl(1,32,'subscription').'</td>';
387  print '<td>'.get_date_range($db->jdate($obj->date_start),$db->jdate($obj->date_end)).'</td>';
388  print '<td align="right">'.price($obj->subscription).'</td>';
389  //print '<td align="right">'.$staticmember->LibStatut($obj->statut,($obj->subscription=='yes'?1:0),$db->jdate($obj->date_end_subscription),5).'</td>';
390  print '<td align="right">'.dol_print_date($db->jdate($obj->datem?$obj->datem:$obj->datec),'dayhour').'</td>';
391  print '</tr>';
392  $i++;
393  }
394  }
395  print "</table></div>";
396  print "<br>";
397 }
398 else
399 {
400  dol_print_error($db);
401 }
402 
403 
404 // Summary of members by type
405 print '<div class="div-table-responsive-no-min">';
406 print '<table class="noborder" width="100%">';
407 print '<tr class="liste_titre">';
408 print '<th>'.$langs->trans("MembersTypes").'</th>';
409 print '<th align=right>'.$langs->trans("MembersStatusToValid").'</th>';
410 print '<th align=right>'.$langs->trans("MenuMembersNotUpToDate").'</th>';
411 print '<th align=right>'.$langs->trans("MenuMembersUpToDate").'</th>';
412 print '<th align=right>'.$langs->trans("MembersStatusResiliated").'</th>';
413 print "</tr>\n";
414 
415 foreach ($AdherentType as $key => $adhtype)
416 {
417  print '<tr class="oddeven">';
418  print '<td>'.$adhtype->getNomUrl(1, dol_size(32)).'</td>';
419  print '<td align="right">'.(isset($MemberToValidate[$key]) && $MemberToValidate[$key] > 0?$MemberToValidate[$key]:'').' '.$staticmember->LibStatut(-1,$adhtype->subscription,0,3).'</td>';
420  print '<td align="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>';
421  print '<td align="right">'.(isset($MemberUpToDate[$key]) && $MemberUpToDate[$key] > 0 ? $MemberUpToDate[$key]:'').' '.$staticmember->LibStatut(1,$adhtype->subscription,$now,3).'</td>';
422  print '<td align="right">'.(isset($MembersResiliated[$key]) && $MembersResiliated[$key]> 0 ?$MembersResiliated[$key]:'').' '.$staticmember->LibStatut(0,$adhtype->subscription,0,3).'</td>';
423  print "</tr>\n";
424 }
425 print '<tr class="liste_total">';
426 print '<td class="liste_total">'.$langs->trans("Total").'</td>';
427 print '<td class="liste_total" align="right">'.$SommeA.' '.$staticmember->LibStatut(-1,$adhtype->subscription,0,3).'</td>';
428 print '<td class="liste_total" align="right">'.$SommeB.' '.$staticmember->LibStatut(1,$adhtype->subscription,0,3).'</td>';
429 print '<td class="liste_total" align="right">'.$SommeC.' '.$staticmember->LibStatut(1,$adhtype->subscription,$now,3).'</td>';
430 print '<td class="liste_total" align="right">'.$SommeD.' '.$staticmember->LibStatut(0,$adhtype->subscription,0,3).'</td>';
431 print '</tr>';
432 
433 print "</table>\n";
434 print "</div>";
435 
436 print '</div></div></div>';
437 
438 // End of page
439 llxFooter();
440 $db->close();
llxFooter()
Footer empty.
Definition: index.php:44
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
print
Draft customers invoices.
Definition: index.php:91
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
dol_size($size, $type='')
Optimize a size for some browsers (phone, smarphone, ...)
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
llxHeader()
Header empty.
Definition: index.php:36
Class to manage members of a foundation.
dol_now($mode='gmt')
Return date for now.
Class to manage members type.
Class to manage subscriptions of foundation members.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Class to build graphs.
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...