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