dolibarr  13.0.2
byproperties.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 2012 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
24 require '../../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
26 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
27 
28 $graphwidth = 700;
29 $mapratio = 0.5;
30 $graphheight = round($graphwidth * $mapratio);
31 
32 $mode = GETPOST('mode') ?GETPOST('mode') : '';
33 
34 
35 // Security check
36 if ($user->socid > 0) {
37  $action = '';
38  $socid = $user->socid;
39 }
40 $result = restrictedArea($user, 'adherent', '', '', 'cotisation');
41 
42 $year = strftime("%Y", time());
43 $startyear = $year - 2;
44 $endyear = $year;
45 
46 // Load translation files required by the page
47 $langs->loadLangs(array("companies", "members"));
48 
49 
50 /*
51  * View
52  */
53 
54 $memberstatic = new Adherent($db);
55 
56 llxHeader('', $langs->trans("MembersStatisticsByProperties"), '', '', 0, 0, array('https://www.google.com/jsapi'));
57 
58 $title = $langs->trans("MembersStatisticsByProperties");
59 
60 print load_fiche_titre($title, '', 'object_group');
61 
62 dol_mkdir($dir);
63 
64 $data = array();
65 
66 $sql = "SELECT COUNT(DISTINCT d.rowid) as nb, COUNT(s.rowid) as nbsubscriptions,";
67 $sql .= " MAX(d.datevalid) as lastdate, MAX(s.dateadh) as lastsubscriptiondate,";
68 $sql .= " d.morphy as code";
69 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
70 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."subscription as s ON s.fk_adherent = d.rowid";
71 $sql .= " WHERE d.entity IN (".getEntity('adherent').")";
72 $sql .= " AND d.statut != -1"; // Not draft
73 $sql .= " GROUP BY d.morphy";
74 $foundphy = $foundmor = 0;
75 
76 // Define $data array
77 dol_syslog("Count member", LOG_DEBUG);
78 $resql = $db->query($sql);
79 if ($resql) {
80  $num = $db->num_rows($resql);
81  $i = 0;
82  while ($i < $num) {
83  $obj = $db->fetch_object($resql);
84 
85  if ($obj->code == 'phy') $foundphy++;
86  if ($obj->code == 'mor') $foundmor++;
87 
88  $data[$obj->code] = array('label'=>$obj->code, 'nb'=>$obj->nb, 'nbsubscriptions'=>$obj->nbsubscriptions, 'lastdate'=>$db->jdate($obj->lastdate), 'lastsubscriptiondate'=>$db->jdate($obj->lastsubscriptiondate));
89 
90  $i++;
91  }
92  $db->free($resql);
93 } else {
94  dol_print_error($db);
95 }
96 
97 $sql = "SELECT COUNT(DISTINCT d.rowid) as nb, COUNT(s.rowid) as nbsubscriptions,";
98 $sql .= " MAX(d.datevalid) as lastdate, MAX(s.dateadh) as lastsubscriptiondate,";
99 $sql .= " d.morphy as code";
100 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
101 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."subscription as s ON s.fk_adherent = d.rowid";
102 $sql .= " WHERE d.entity IN (".getEntity('adherent').")";
103 $sql .= " AND d.statut >= 1"; // Active (not draft=-1, not resiliated=0)
104 $sql .= " GROUP BY d.morphy";
105 $foundphy = $foundmor = 0;
106 
107 // Define $data array
108 dol_syslog("Count member still active", LOG_DEBUG);
109 $resql = $db->query($sql);
110 if ($resql) {
111  $num = $db->num_rows($resql);
112  $i = 0;
113  while ($i < $num) {
114  $obj = $db->fetch_object($resql);
115 
116  if ($obj->code == 'phy') $foundphy++;
117  if ($obj->code == 'mor') $foundmor++;
118 
119  $data[$obj->code]['nbactive'] = $obj->nb;
120 
121  $i++;
122  }
123  $db->free($resql);
124 } else {
125  dol_print_error($db);
126 }
127 
128 
129 $head = member_stats_prepare_head($adh);
130 
131 print dol_get_fiche_head($head, 'statsbyproperties', $langs->trans("Statistics"), -1, 'user');
132 
133 
134 // Print title
135 if (!count($data)) {
136  print '<span class="opacitymedium">'.$langs->trans("NoValidatedMemberYet").'</span><br>';
137  print '<br>';
138 } else {
139  print '<span class="opacitymedium">'.$langs->trans("MembersByNature").'</span><br>';
140  print '<br>';
141 }
142 
143 // Print array
144 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
145 print '<table class="liste centpercent">';
146 print '<tr class="liste_titre">';
147 print '<td>'.$langs->trans("MemberNature").'</td>';
148 print '<td class="right">'.$langs->trans("NbOfMembers").' <span class="opacitymedium">('.$langs->trans("AllTime").')</span></td>';
149 print '<td class="right">'.$langs->trans("NbOfActiveMembers").'</td>';
150 print '<td class="center">'.$langs->trans("LastMemberDate").'</td>';
151 print '<td class="right">'.$langs->trans("NbOfSubscriptions").'</td>';
152 print '<td class="center">'.$langs->trans("LatestSubscriptionDate").'</td>';
153 print '</tr>';
154 
155 if (!$foundphy) $data[] = array('label'=>'phy', 'nb'=>'0', 'nbactive'=>'0', 'lastdate'=>'', 'lastsubscriptiondate'=>'');
156 if (!$foundmor) $data[] = array('label'=>'mor', 'nb'=>'0', 'nbactive'=>'0', 'lastdate'=>'', 'lastsubscriptiondate'=>'');
157 
158 foreach ($data as $val) {
159  $nb = $val['nb'];
160  $nbsubscriptions = $val['nbsubscriptions'];
161  $nbactive = $val['nbactive'];
162 
163  print '<tr class="oddeven">';
164  print '<td>'.$memberstatic->getmorphylib($val['label']).'</td>';
165  print '<td class="right">'.$nb.'</td>';
166  print '<td class="right">'.$nbactive.'</td>';
167  print '<td class="center">'.dol_print_date($val['lastdate'], 'dayhour').'</td>';
168  print '<td class="right">'.$nbsubscriptions.'</td>';
169  print '<td class="center">'.dol_print_date($val['lastsubscriptiondate'], 'dayhour').'</td>';
170  print '</tr>';
171 }
172 
173 print '</table>';
174 print '</div>';
175 
177 
178 // End of page
179 llxFooter();
180 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
llxHeader()
Empty header.
Definition: wrapper.php:45
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Class to manage members of a foundation.
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.
member_stats_prepare_head($object)
Return array head with list of tabs to view object stats informations.
Definition: member.lib.php:217
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->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)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:59
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)