dolibarr  16.0.5
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 - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
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, '', $memberstatic->picto);
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 <> ".Adherent::STATUS_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') {
86  $foundphy++;
87  }
88  if ($obj->code == 'mor') {
89  $foundmor++;
90  }
91 
92  $data[$obj->code] = array('label'=>$obj->code, 'nb'=>$obj->nb, 'nbsubscriptions'=>$obj->nbsubscriptions, 'lastdate'=>$db->jdate($obj->lastdate), 'lastsubscriptiondate'=>$db->jdate($obj->lastsubscriptiondate));
93 
94  $i++;
95  }
96  $db->free($resql);
97 } else {
98  dol_print_error($db);
99 }
100 
101 $sql = "SELECT COUNT(DISTINCT d.rowid) as nb, COUNT(s.rowid) as nbsubscriptions,";
102 $sql .= " MAX(d.datevalid) as lastdate, MAX(s.dateadh) as lastsubscriptiondate,";
103 $sql .= " d.morphy as code";
104 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
105 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."subscription as s ON s.fk_adherent = d.rowid";
106 $sql .= " WHERE d.entity IN (".getEntity('adherent').")";
107 $sql .= " AND d.statut >= 1"; // Active (not excluded=-2, not draft=-1, not resiliated=0)
108 $sql .= " GROUP BY d.morphy";
109 $foundphy = $foundmor = 0;
110 
111 // Define $data array
112 dol_syslog("Count member still active", LOG_DEBUG);
113 $resql = $db->query($sql);
114 if ($resql) {
115  $num = $db->num_rows($resql);
116  $i = 0;
117  while ($i < $num) {
118  $obj = $db->fetch_object($resql);
119 
120  if ($obj->code == 'phy') {
121  $foundphy++;
122  }
123  if ($obj->code == 'mor') {
124  $foundmor++;
125  }
126 
127  $data[$obj->code]['nbactive'] = $obj->nb;
128 
129  $i++;
130  }
131  $db->free($resql);
132 } else {
133  dol_print_error($db);
134 }
135 
136 
137 $head = member_stats_prepare_head($memberstatic);
138 
139 print dol_get_fiche_head($head, 'statsbyproperties', '', -1, '');
140 
141 
142 // Print title
143 if (!count($data)) {
144  print '<span class="opacitymedium">'.$langs->trans("NoValidatedMemberYet").'</span><br>';
145  print '<br>';
146 } else {
147  print '<span class="opacitymedium">'.$langs->trans("MembersByNature").'</span><br>';
148  print '<br>';
149 }
150 
151 // Print array
152 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
153 print '<table class="liste centpercent">';
154 print '<tr class="liste_titre">';
155 print '<td>'.$langs->trans("MemberNature").'</td>';
156 print '<td class="right">'.$langs->trans("NbOfMembers").' <span class="opacitymedium">('.$langs->trans("AllTime").')</span></td>';
157 print '<td class="right">'.$langs->trans("NbOfActiveMembers").'</td>';
158 print '<td class="center">'.$langs->trans("LastMemberDate").'</td>';
159 print '<td class="right">'.$langs->trans("NbOfSubscriptions").'</td>';
160 print '<td class="center">'.$langs->trans("LatestSubscriptionDate").'</td>';
161 print '</tr>';
162 
163 if (!$foundphy) {
164  $data[] = array('label'=>'phy', 'nb'=>'0', 'nbactive'=>'0', 'lastdate'=>'', 'lastsubscriptiondate'=>'');
165 }
166 if (!$foundmor) {
167  $data[] = array('label'=>'mor', 'nb'=>'0', 'nbactive'=>'0', 'lastdate'=>'', 'lastsubscriptiondate'=>'');
168 }
169 
170 foreach ($data as $val) {
171  $nb = $val['nb'];
172  $nbsubscriptions = isset($val['nbsubscriptions']) ? $val['nbsubscriptions'] : 0;
173  $nbactive = $val['nbactive'];
174 
175  print '<tr class="oddeven">';
176  print '<td>'.$memberstatic->getmorphylib($val['label']).'</td>';
177  print '<td class="right">'.$nb.'</td>';
178  print '<td class="right">'.$nbactive.'</td>';
179  print '<td class="center">'.dol_print_date($val['lastdate'], 'dayhour').'</td>';
180  print '<td class="right">'.$nbsubscriptions.'</td>';
181  print '<td class="center">'.dol_print_date($val['lastsubscriptiondate'], 'dayhour').'</td>';
182  print '</tr>';
183 }
184 
185 print '</table>';
186 print '</div>';
187 
188 print dol_get_fiche_end();
189 
190 // End of page
191 llxFooter();
192 $db->close();
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
member_stats_prepare_head
member_stats_prepare_head($object)
Return array head with list of tabs to view object stats informations.
Definition: member.lib.php:233
Adherent
Class to manage members of a foundation.
Definition: adherent.class.php:46
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59