dolibarr 21.0.0-alpha
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28include_once DOL_DOCUMENT_ROOT . '/core/boxes/modules_boxes.php';
29
30
35{
36 public $boxcode = "box_members_subscriptions_by_year";
37 public $boximg = "object_user";
38 public $boxlabel = "BoxTitleMembersSubscriptionsByYear";
39 public $depends = array("adherent");
40
41 public $enabled = 1;
42
49 public function __construct($db, $param = '')
50 {
51 global $conf, $user;
52
53 $this->db = $db;
54
55 // disable module for such cases
56 $listofmodulesforexternal = explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL'));
57 if (!in_array('adherent', $listofmodulesforexternal) && !empty($user->socid)) {
58 $this->enabled = 0; // disabled for external users
59 }
60
61 $this->hidden = !(isModEnabled('member') && $user->hasRight('adherent', 'lire'));
62 }
63
70 public function loadBox($max = 5)
71 {
72 global $user, $langs, $conf;
73 $langs->loadLangs(array("boxes", "members"));
74
75 $this->max = $max;
76
77 include_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
78 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent_type.class.php';
79 $memberstatic = new Adherent($this->db);
80 $statictype = new AdherentType($this->db);
81
82 $this->info_box_head = array('text' => $langs->trans("BoxTitleMembersSubscriptionsByYear", $max));
83
84 if ($user->hasRight('adherent', 'lire')) {
85 $num = 0;
86 $line = 0;
87 // List of subscription by year
88 $Total = array();
89 $Number = array();
90 $tot = 0;
91 $numb = 0;
92
93 $sql = "SELECT c.subscription, c.dateadh as dateh";
94 $sql .= " FROM " . MAIN_DB_PREFIX . "adherent as d, " . MAIN_DB_PREFIX . "subscription as c";
95 $sql .= " WHERE d.entity IN (" . getEntity('adherent') . ")";
96 $sql .= " AND d.rowid = c.fk_adherent";
97
98
99 $result = $this->db->query($sql);
100 if ($result) {
101 $num = $this->db->num_rows($result);
102 $i = 0;
103 while ($i < $num) {
104 $objp = $this->db->fetch_object($result);
105 $year = dol_print_date($this->db->jdate($objp->dateh), "%Y");
106 $Total[$year] = (isset($Total[$year]) ? $Total[$year] : 0) + $objp->subscription;
107 $Number[$year] = (isset($Number[$year]) ? $Number[$year] : 0) + 1;
108 $tot += $objp->subscription;
109 $numb += 1;
110 $i++;
111 }
112
113
114 $line = 0;
115 $this->info_box_contents[$line][] = array(
116 'td' => 'class=""',
117 'text' => $langs->trans("Year"),
118 );
119 $this->info_box_contents[$line][] = array(
120 'td' => 'class="right"',
121 'text' => $langs->trans("Subscriptions"),
122 );
123 $this->info_box_contents[$line][] = array(
124 'td' => 'class="right"',
125 'text' => $langs->trans("AmountTotal"),
126 );
127 $this->info_box_contents[$line][] = array(
128 'td' => 'class="right"',
129 'text' => $langs->trans("AmountAverage"),
130 );
131
132 $line++;
133
134 krsort($Total);
135 $i = 0;
136 foreach ($Total as $key => $value) {
137 if ($i >= 8) {
138 // print '<tr class="oddeven">';
139 // print "<td>...</td>";
140 // print "<td class=\"right\"></td>";
141 // print "<td class=\"right\"></td>";
142 // print "<td class=\"right\"></td>";
143 // print "</tr>\n";
144 $this->info_box_contents[$line][] = array(
145 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
146 'text' => '...',
147 );
148 $this->info_box_contents[$line][] = array(
149 'td' => 'class="right"',
150 'text' => '',
151 );
152 $this->info_box_contents[$line][] = array(
153 'td' => 'class="right"',
154 'text' => '',
155 );
156 $this->info_box_contents[$line][] = array(
157 'td' => 'class="right"',
158 'text' => '',
159 );
160 $line++;
161 break;
162 }
163 $this->info_box_contents[$line][] = array(
164 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
165 'text' => '<a href="./subscription/list.php?date_select='.$key.'">'.$key.'</a>',
166 'asis' => 1,
167 );
168 $this->info_box_contents[$line][] = array(
169 'td' => 'class="right"',
170 'text' => $Number[$key],
171 );
172 $this->info_box_contents[$line][] = array(
173 'td' => 'class="nowraponall right amount"',
174 'text' => price($value),
175 );
176 $this->info_box_contents[$line][] = array(
177 'td' => 'class="nowraponall right amount"',
178 'text' => price(price2num($value / $Number[$key], 'MT')),
179 );
180 $line++;
181 }
182
183 if ($num == 0) {
184 $this->info_box_contents[$line][0] = array(
185 'td' => 'colspan="4" class="center"',
186 'text' => '<span class="opacitymedium">'.$langs->trans("NoRecordedMembers").'</span>',
187 );
188 } else {
189 $this->info_box_contents[$line][] = array(
190 'tr' => 'class="liste_total"',
191 'td' => 'class="liste_total"',
192 'text' => $langs->trans("Total"),
193 );
194 $this->info_box_contents[$line][] = array(
195 'td' => 'class="liste_total right"',
196 'text' => $numb,
197 );
198 $this->info_box_contents[$line][] = array(
199 'td' => 'class="liste_total nowraponall right amount"',
200 'text' => price($tot),
201 );
202 $this->info_box_contents[$line][] = array(
203 'td' => 'class="liste_total nowraponall right amount"',
204 'text' => price(price2num($numb > 0 ? ($tot / $numb) : 0, 'MT')),
205 );
206 }
207 } else {
208 $this->info_box_contents[0][0] = array(
209 'td' => '',
210 'maxlength' => 500,
211 'text' => ($this->db->error() . ' sql=' . $sql),
212 );
213 }
214 } else {
215 $this->info_box_contents[0][0] = array(
216 'td' => 'class="nohover left"',
217 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
218 );
219 }
220 }
221
230 public function showBox($head = null, $contents = null, $nooutput = 0)
231 {
232 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
233 }
234}
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=null, $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.