dolibarr 19.0.4
box_members_subscriptions_by_year.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2015-2021 Frederic France <frederic.france@netlogic.fr>
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 <https://www.gnu.org/licenses/>.
19 */
20
27include_once DOL_DOCUMENT_ROOT . '/core/boxes/modules_boxes.php';
28
29
34{
35 public $boxcode = "box_members_subscriptions_by_year";
36 public $boximg = "object_user";
37 public $boxlabel = "BoxTitleMembersSubscriptionsByYear";
38 public $depends = array("adherent");
39
43 public $db;
44
45 public $param;
46 public $enabled = 1;
47
48 public $info_box_head = array();
49 public $info_box_contents = array();
50
51
58 public function __construct($db, $param = '')
59 {
60 global $conf, $user;
61
62 $this->db = $db;
63
64 // disable module for such cases
65 $listofmodulesforexternal = explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL'));
66 if (!in_array('adherent', $listofmodulesforexternal) && !empty($user->socid)) {
67 $this->enabled = 0; // disabled for external users
68 }
69
70 $this->hidden = !(isModEnabled('adherent') && $user->hasRight('adherent', 'lire'));
71 }
72
79 public function loadBox($max = 5)
80 {
81 global $user, $langs, $conf;
82 $langs->loadLangs(array("boxes", "members"));
83
84 $this->max = $max;
85
86 include_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
87 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent_type.class.php';
88 $memberstatic = new Adherent($this->db);
89 $statictype = new AdherentType($this->db);
90
91 $this->info_box_head = array('text' => $langs->trans("BoxTitleMembersSubscriptionsByYear", $max));
92
93 if ($user->hasRight('adherent', 'lire')) {
94 $num = 0;
95 $line = 0;
96 // List of subscription by year
97 $Total = array();
98 $Number = array();
99 $tot = 0;
100 $numb = 0;
101
102 $sql = "SELECT c.subscription, c.dateadh as dateh";
103 $sql .= " FROM " . MAIN_DB_PREFIX . "adherent as d, " . MAIN_DB_PREFIX . "subscription as c";
104 $sql .= " WHERE d.entity IN (" . getEntity('adherent') . ")";
105 $sql .= " AND d.rowid = c.fk_adherent";
106
107
108 $result = $this->db->query($sql);
109 if ($result) {
110 $num = $this->db->num_rows($result);
111 $i = 0;
112 while ($i < $num) {
113 $objp = $this->db->fetch_object($result);
114 $year = dol_print_date($this->db->jdate($objp->dateh), "%Y");
115 $Total[$year] = (isset($Total[$year]) ? $Total[$year] : 0) + $objp->subscription;
116 $Number[$year] = (isset($Number[$year]) ? $Number[$year] : 0) + 1;
117 $tot += $objp->subscription;
118 $numb += 1;
119 $i++;
120 }
121
122
123 $line = 0;
124 $this->info_box_contents[$line][] = array(
125 'td' => 'class=""',
126 'text' => $langs->trans("Year"),
127 );
128 $this->info_box_contents[$line][] = array(
129 'td' => 'class="right"',
130 'text' => $langs->trans("Subscriptions"),
131 );
132 $this->info_box_contents[$line][] = array(
133 'td' => 'class="right"',
134 'text' => $langs->trans("AmountTotal"),
135 );
136 $this->info_box_contents[$line][] = array(
137 'td' => 'class="right"',
138 'text' => $langs->trans("AmountAverage"),
139 );
140
141 $line++;
142
143 krsort($Total);
144 $i = 0;
145 foreach ($Total as $key => $value) {
146 if ($i >= 8) {
147 // print '<tr class="oddeven">';
148 // print "<td>...</td>";
149 // print "<td class=\"right\"></td>";
150 // print "<td class=\"right\"></td>";
151 // print "<td class=\"right\"></td>";
152 // print "</tr>\n";
153 $this->info_box_contents[$line][] = array(
154 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
155 'text' => '...',
156 );
157 $this->info_box_contents[$line][] = array(
158 'td' => 'class="right"',
159 'text' => '',
160 );
161 $this->info_box_contents[$line][] = array(
162 'td' => 'class="right"',
163 'text' => '',
164 );
165 $this->info_box_contents[$line][] = array(
166 'td' => 'class="right"',
167 'text' => '',
168 );
169 $line++;
170 break;
171 }
172 $this->info_box_contents[$line][] = array(
173 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
174 'text' => '<a href="./subscription/list.php?date_select='.$key.'">'.$key.'</a>',
175 'asis' => 1,
176 );
177 $this->info_box_contents[$line][] = array(
178 'td' => 'class="right"',
179 'text' => $Number[$key],
180 );
181 $this->info_box_contents[$line][] = array(
182 'td' => 'class="nowraponall right amount"',
183 'text' => price($value),
184 );
185 $this->info_box_contents[$line][] = array(
186 'td' => 'class="nowraponall right amount"',
187 'text' => price(price2num($value / $Number[$key], 'MT')),
188 );
189 $line++;
190 }
191
192 if ($num == 0) {
193 $this->info_box_contents[$line][0] = array(
194 'td' => 'colspan="4" class="center"',
195 'text' => '<span class="opacitymedium">'.$langs->trans("NoRecordedMembers").'</span>',
196 );
197 } else {
198 $this->info_box_contents[$line][] = array(
199 'tr' => 'class="liste_total"',
200 'td' => 'class="liste_total"',
201 'text' => $langs->trans("Total"),
202 );
203 $this->info_box_contents[$line][] = array(
204 'td' => 'class="liste_total right"',
205 'text' => $numb,
206 );
207 $this->info_box_contents[$line][] = array(
208 'td' => 'class="liste_total nowraponall right amount"',
209 'text' => price($tot),
210 );
211 $this->info_box_contents[$line][] = array(
212 'td' => 'class="liste_total nowraponall right amount"',
213 'text' => price(price2num($numb > 0 ? ($tot / $numb) : 0, 'MT')),
214 );
215 }
216 } else {
217 $this->info_box_contents[0][0] = array(
218 'td' => '',
219 'maxlength' => 500,
220 'text' => ($this->db->error() . ' sql=' . $sql),
221 );
222 }
223 } else {
224 $this->info_box_contents[0][0] = array(
225 'td' => 'class="nohover left"',
226 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
227 );
228 }
229 }
230
239 public function showBox($head = null, $contents = null, $nooutput = 0)
240 {
241 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
242 }
243}
Class to manage members of a foundation.
Class to manage members type.
Class ModeleBoxes.
Class to manage the box to show last modofied members.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
loadBox($max=5)
Load data into info_box_contents array to show array later.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.