dolibarr  17.0.4
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 // Load Dolibarr environment
25 require '../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
28 
29 $graphwidth = 700;
30 $mapratio = 0.5;
31 $graphheight = round($graphwidth * $mapratio);
32 
33 $mode = GETPOST('mode') ? GETPOST('mode') : '';
34 
35 
36 // Security check
37 if ($user->socid > 0) {
38  $action = '';
39  $socid = $user->socid;
40 }
41 $result = restrictedArea($user, 'adherent', '', '', 'cotisation');
42 
43 $year = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
44 $startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
45 $endyear = $year;
46 
47 // Load translation files required by the page
48 $langs->loadLangs(array("companies", "members"));
49 
50 
51 /*
52  * View
53  */
54 
55 $memberstatic = new Adherent($db);
56 
57 llxHeader('', $langs->trans("MembersStatisticsByProperties"), '', '', 0, 0, array('https://www.google.com/jsapi'));
58 
59 $title = $langs->trans("MembersStatisticsByProperties");
60 
61 print load_fiche_titre($title, '', $memberstatic->picto);
62 
63 //dol_mkdir($dir);
64 
65 $data = array();
66 
67 $sql = "SELECT COUNT(DISTINCT d.rowid) as nb, COUNT(s.rowid) as nbsubscriptions,";
68 $sql .= " MAX(d.datevalid) as lastdate, MAX(s.dateadh) as lastsubscriptiondate,";
69 $sql .= " d.morphy as code";
70 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
71 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."subscription as s ON s.fk_adherent = d.rowid";
72 $sql .= " WHERE d.entity IN (".getEntity('adherent').")";
73 $sql .= " AND d.statut <> ".Adherent::STATUS_DRAFT;
74 $sql .= " GROUP BY d.morphy";
75 $foundphy = $foundmor = 0;
76 
77 // Define $data array
78 dol_syslog("Count member", LOG_DEBUG);
79 $resql = $db->query($sql);
80 if ($resql) {
81  $num = $db->num_rows($resql);
82  $i = 0;
83  while ($i < $num) {
84  $obj = $db->fetch_object($resql);
85 
86  if ($obj->code == 'phy') {
87  $foundphy++;
88  }
89  if ($obj->code == 'mor') {
90  $foundmor++;
91  }
92 
93  $data[$obj->code] = array('label'=>$obj->code, 'nb'=>$obj->nb, 'nbsubscriptions'=>$obj->nbsubscriptions, 'lastdate'=>$db->jdate($obj->lastdate), 'lastsubscriptiondate'=>$db->jdate($obj->lastsubscriptiondate));
94 
95  $i++;
96  }
97  $db->free($resql);
98 } else {
99  dol_print_error($db);
100 }
101 
102 $sql = "SELECT COUNT(DISTINCT d.rowid) as nb, COUNT(s.rowid) as nbsubscriptions,";
103 $sql .= " MAX(d.datevalid) as lastdate, MAX(s.dateadh) as lastsubscriptiondate,";
104 $sql .= " d.morphy as code";
105 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
106 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."subscription as s ON s.fk_adherent = d.rowid";
107 $sql .= " WHERE d.entity IN (".getEntity('adherent').")";
108 $sql .= " AND d.statut >= 1"; // Active (not excluded=-2, not draft=-1, not resiliated=0)
109 $sql .= " GROUP BY d.morphy";
110 $foundphy = $foundmor = 0;
111 
112 // Define $data array
113 dol_syslog("Count member still active", LOG_DEBUG);
114 $resql = $db->query($sql);
115 if ($resql) {
116  $num = $db->num_rows($resql);
117  $i = 0;
118  while ($i < $num) {
119  $obj = $db->fetch_object($resql);
120 
121  if ($obj->code == 'phy') {
122  $foundphy++;
123  }
124  if ($obj->code == 'mor') {
125  $foundmor++;
126  }
127 
128  $data[$obj->code]['nbactive'] = $obj->nb;
129 
130  $i++;
131  }
132  $db->free($resql);
133 } else {
134  dol_print_error($db);
135 }
136 
137 
138 $head = member_stats_prepare_head($memberstatic);
139 
140 print dol_get_fiche_head($head, 'statsbyproperties', '', -1, '');
141 
142 
143 // Print title
144 if (!count($data)) {
145  print '<span class="opacitymedium">'.$langs->trans("NoValidatedMemberYet").'</span><br>';
146  print '<br>';
147 } else {
148  print '<span class="opacitymedium">'.$langs->trans("MembersByNature").'</span><br>';
149  print '<br>';
150 }
151 
152 // Print array
153 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
154 print '<table class="liste centpercent">';
155 print '<tr class="liste_titre">';
156 print '<td>'.$langs->trans("MemberNature").'</td>';
157 print '<td class="right">'.$langs->trans("NbOfMembers").' <span class="opacitymedium">('.$langs->trans("AllTime").')</span></td>';
158 print '<td class="right">'.$langs->trans("NbOfActiveMembers").'</td>';
159 print '<td class="center">'.$langs->trans("LastMemberDate").'</td>';
160 print '<td class="right">'.$langs->trans("NbOfSubscriptions").'</td>';
161 print '<td class="center">'.$langs->trans("LatestSubscriptionDate").'</td>';
162 print '</tr>';
163 
164 if (!$foundphy) {
165  $data[] = array('label'=>'phy', 'nb'=>'0', 'nbactive'=>'0', 'lastdate'=>'', 'lastsubscriptiondate'=>'');
166 }
167 if (!$foundmor) {
168  $data[] = array('label'=>'mor', 'nb'=>'0', 'nbactive'=>'0', 'lastdate'=>'', 'lastsubscriptiondate'=>'');
169 }
170 
171 foreach ($data as $val) {
172  $nb = $val['nb'];
173  $nbsubscriptions = isset($val['nbsubscriptions']) ? $val['nbsubscriptions'] : 0;
174  $nbactive = $val['nbactive'];
175 
176  print '<tr class="oddeven">';
177  print '<td>'.$memberstatic->getmorphylib($val['label']).'</td>';
178  print '<td class="right">'.$nb.'</td>';
179  print '<td class="right">'.$nbactive.'</td>';
180  print '<td class="center">'.dol_print_date($val['lastdate'], 'dayhour').'</td>';
181  print '<td class="right">'.$nbsubscriptions.'</td>';
182  print '<td class="center">'.dol_print_date($val['lastsubscriptiondate'], 'dayhour').'</td>';
183  print '</tr>';
184 }
185 
186 print '</table>';
187 print '</div>';
188 
189 print dol_get_fiche_end();
190 
191 // End of page
192 llxFooter();
193 $db->close();
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage members of a foundation.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
member_stats_prepare_head($object)
Return array head with list of tabs to view object stats informations.
Definition: member.lib.php:261
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.