dolibarr 21.0.0-beta
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
6 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
32
41$langs->load("donations");
42
43
44// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
45$hookmanager->initHooks(array('donationindex'));
46
47$donation_static = new Don($db);
48
49// Security check
50$result = restrictedArea($user, 'don');
51
52
53/*
54 * Actions
55 */
56
57// None
58
59
60/*
61 * View
62 */
63
64$donstatic = new Don($db);
65
66$help_url = 'EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones|DE:Modul_Spenden';
67
68llxHeader('', $langs->trans("Donations"), $help_url, '', 0, 0, '', '', '', 'mod-donation page-index');
69
70$nb = array();
71$somme = array();
72$total = 0;
73
74$sql = "SELECT count(d.rowid) as nb, sum(d.amount) as somme , d.fk_statut";
75$sql .= " FROM ".MAIN_DB_PREFIX."don as d WHERE d.entity IN (".getEntity('donation').")";
76$sql .= " GROUP BY d.fk_statut";
77$sql .= " ORDER BY d.fk_statut";
78
79$result = $db->query($sql);
80if ($result) {
81 $i = 0;
82 $num = $db->num_rows($result);
83 while ($i < $num) {
84 $objp = $db->fetch_object($result);
85
86 $somme[$objp->fk_statut] = $objp->somme;
87 $nb[$objp->fk_statut] = $objp->nb;
88 $total += $objp->somme;
89
90 $i++;
91 }
92 $db->free($result);
93} else {
94 dol_print_error($db);
95}
96
97print load_fiche_titre($langs->trans("DonationsArea"), '', 'object_donation');
98
99
100print '<div class="fichecenter"><div class="fichethirdleft">';
101
102if (!isset($listofsearchfields) || !is_array($listofsearchfields)) {
103 // Ensure $listofsearchfields is an array
104 $listofsearchfields = array();
105}
106if (getDolGlobalString('MAIN_SEARCH_FORM_ON_HOME_AREAS')) { // TODO Add a search into global search combo so we can remove this
107 if (isModEnabled('don') && $user->hasRight('don', 'lire')) {
108 $listofsearchfields['search_donation'] = array('text' => 'Donation');
109 }
110
111 if (count($listofsearchfields)) {
112 print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
113 print '<input type="hidden" name="token" value="'.newToken().'">';
114 print '<table class="noborder nohover centpercent">';
115 $i = 0;
116 foreach ($listofsearchfields as $key => $value) {
117 if ($i == 0) {
118 print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
119 }
120 print '<tr>';
121 print '<td class="nowrap"><label for="'.$key.'">'.$langs->trans($value["text"]).'</label></td><td><input type="text" class="flat inputsearch" name="'.$key.'" id="'.$key.'"></td>';
122 if ($i == 0) {
123 print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" class="button" value="'.$langs->trans("Search").'"></td>';
124 }
125 print '</tr>';
126 $i++;
127 }
128 print '</table>';
129 print '</form>';
130 print '<br>';
131 }
132}
133
134$dataseries = array();
135$colorseries = array();
136
137include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
138
139print '<table class="noborder nohover centpercent">';
140print '<tr class="liste_titre">';
141print '<th colspan="4">'.$langs->trans("Statistics").'</th>';
142print "</tr>\n";
143
144$listofstatus = array(0, 1, -1, 2);
145foreach ($listofstatus as $status) {
146 $dataseries[] = array($donstatic->LibStatut($status, 1), (isset($nb[$status]) ? (int) $nb[$status] : 0));
147 if ($status == Don::STATUS_DRAFT) {
148 $colorseries[$status] = '-'.$badgeStatus0;
149 }
150 if ($status == Don::STATUS_VALIDATED) {
151 $colorseries[$status] = $badgeStatus1;
152 }
153 if ($status == Don::STATUS_CANCELED) {
154 $colorseries[$status] = $badgeStatus9;
155 }
156 if ($status == Don::STATUS_PAID) {
157 $colorseries[$status] = $badgeStatus6;
158 }
159}
160
161if ($conf->use_javascript_ajax) {
162 print '<tr><td class="center" colspan="4">';
163
164 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
165 $dolgraph = new DolGraph();
166 $dolgraph->SetData($dataseries);
167 $dolgraph->SetDataColor(array_values($colorseries));
168 $dolgraph->setShowLegend(2);
169 $dolgraph->setShowPercent(1);
170 $dolgraph->SetType(array('pie'));
171 $dolgraph->setHeight('200');
172 $dolgraph->draw('idgraphstatus');
173 print $dolgraph->show($total ? 0 : 1);
174
175 print '</td></tr>';
176}
177
178print '<tr class="liste_titre">';
179print '<td>'.$langs->trans("Status").'</td>';
180print '<td class="right">'.$langs->trans("Number").'</td>';
181print '<td class="right">'.$langs->trans("Total").'</td>';
182print '<td class="right">'.$langs->trans("Average").'</td>';
183print '</tr>';
184
185$total = 0;
186$totalnb = 0;
187foreach ($listofstatus as $status) {
188 print '<tr class="oddeven">';
189 print '<td><a href="list.php?search_status='.$status.'">'.$donstatic->LibStatut($status, 4).'</a></td>';
190 print '<td class="right">'.(!empty($nb[$status]) ? $nb[$status] : '&nbsp;').'</td>';
191 print '<td class="right nowraponall amount">'.(!empty($nb[$status]) ? price($somme[$status], 1, '', 1, -1, 'MT') : '&nbsp;').'</td>';
192 print '<td class="right nowraponall">'.(!empty($nb[$status]) ? price(price2num($somme[$status] / $nb[$status], 'MT')) : '&nbsp;').'</td>';
193 $totalnb += (!empty($nb[$status]) ? $nb[$status] : 0);
194 $total += (!empty($somme[$status]) ? $somme[$status] : 0);
195 print "</tr>";
196}
197
198print '<tr class="liste_total">';
199print '<td>'.$langs->trans("Total").'</td>';
200print '<td class="right nowraponall">'.$totalnb.'</td>';
201print '<td class="right nowraponall">'.price($total, 1, "", 1, -1, 'MT').'</td>';
202print '<td class="right nowraponall">'.($totalnb ? price(price2num($total / $totalnb, 'MT')) : '&nbsp;').'</td>';
203print '</tr>';
204print "</table>";
205
206
207print '</div><div class="fichetwothirdright">';
208
209
210$max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
211
212
213/*
214 * Last modified donations
215 */
216
217$sql = "SELECT c.rowid, c.ref, c.fk_statut, c.societe, c.lastname, c.firstname, c.tms as datem, c.amount";
218$sql .= " FROM ".MAIN_DB_PREFIX."don as c";
219$sql .= " WHERE c.entity IN (".getEntity("don").")";
220//$sql.= " AND c.fk_statut > 2";
221$sql .= " ORDER BY c.tms DESC";
222$sql .= $db->plimit($max, 0);
223
224$resql = $db->query($sql);
225if ($resql) {
226 print '<table class="noborder centpercent">';
227 print '<tr class="liste_titre">';
228 print '<th colspan="5">'.$langs->trans("LastModifiedDonations", $max).' ';
229 print '<a href="'.DOL_URL_ROOT.'/don/list.php?sortfield=d.datem&sortorder=DESC">';
230 print '<span class="badge">...</span>';
231 print '</a>';
232 print '</th></tr>';
233
234 $num = $db->num_rows($resql);
235 if ($num) {
236 $i = 0;
237 while ($i < $num) {
238 $obj = $db->fetch_object($resql);
239
240 print '<tr class="oddeven">';
241
242 $donation_static->id = $obj->rowid;
243 $donation_static->ref = $obj->ref ? $obj->ref : $obj->rowid;
244
245 print '<td width="96" class="nobordernopadding nowrap">';
246 print $donation_static->getNomUrl(1);
247 print '</td>';
248
249 print '<td class="nobordernopadding">';
250 print $obj->societe;
251 print($obj->societe && ($obj->lastname || $obj->firstname) ? ' / ' : '');
252 print dolGetFirstLastname($obj->firstname, $obj->lastname);
253 print '</td>';
254
255 print '<td class="right nobordernopadding nowraponall amount">';
256 print price($obj->amount, 1);
257 print '</td>';
258
259 // Date
260 print '<td class="center">'.dol_print_date($db->jdate($obj->datem), 'day').'</td>';
261
262 print '<td class="right">'.$donation_static->LibStatut($obj->fk_statut, 5).'</td>';
263
264 print '</tr>';
265 $i++;
266 }
267 }
268 print "</table><br>";
269} else {
270 dol_print_error($db);
271}
272
273
274print '</div></div>';
275
276$parameters = array('user' => $user);
277$reshook = $hookmanager->executeHooks('dashboardDonation', $parameters, $object); // Note that $action and $object may have been modified by hook
278
279llxFooter();
280
281$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to build graphs.
Class to manage donations.
Definition don.class.php:41
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.