dolibarr 20.0.0
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 *
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
28// Load Dolibarr environment
29require '../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
31
32$hookmanager = new HookManager($db);
33
34// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
35$hookmanager->initHooks(array('donationindex'));
36
37$langs->load("donations");
38
39$donation_static = new Don($db);
40
41// Security check
42$result = restrictedArea($user, 'don');
43
44
45/*
46 * Actions
47 */
48
49// None
50
51
52/*
53 * View
54 */
55
56$donstatic = new Don($db);
57
58$help_url = 'EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones|DE:Modul_Spenden';
59
60llxHeader('', $langs->trans("Donations"), $help_url, '', 0, 0, '', '', '', 'mod-donation page-index');
61
62$nb = array();
63$somme = array();
64$total = 0;
65
66$sql = "SELECT count(d.rowid) as nb, sum(d.amount) as somme , d.fk_statut";
67$sql .= " FROM ".MAIN_DB_PREFIX."don as d WHERE d.entity IN (".getEntity('donation').")";
68$sql .= " GROUP BY d.fk_statut";
69$sql .= " ORDER BY d.fk_statut";
70
71$result = $db->query($sql);
72if ($result) {
73 $i = 0;
74 $num = $db->num_rows($result);
75 while ($i < $num) {
76 $objp = $db->fetch_object($result);
77
78 $somme[$objp->fk_statut] = $objp->somme;
79 $nb[$objp->fk_statut] = $objp->nb;
80 $total += $objp->somme;
81
82 $i++;
83 }
84 $db->free($result);
85} else {
86 dol_print_error($db);
87}
88
89print load_fiche_titre($langs->trans("DonationsArea"), '', 'object_donation');
90
91
92print '<div class="fichecenter"><div class="fichethirdleft">';
93
94if (!isset($listofsearchfields) || !is_array($listofsearchfields)) {
95 // Ensure $listofsearchfields is an array
96 $listofsearchfields = array();
97}
98if (getDolGlobalString('MAIN_SEARCH_FORM_ON_HOME_AREAS')) { // TODO Add a search into global search combo so we can remove this
99 if (isModEnabled('don') && $user->hasRight('don', 'lire')) {
100 $listofsearchfields['search_donation'] = array('text' => 'Donation');
101 }
102
103 if (count($listofsearchfields)) {
104 print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
105 print '<input type="hidden" name="token" value="'.newToken().'">';
106 print '<table class="noborder nohover centpercent">';
107 $i = 0;
108 foreach ($listofsearchfields as $key => $value) {
109 if ($i == 0) {
110 print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
111 }
112 print '<tr>';
113 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>';
114 if ($i == 0) {
115 print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" class="button" value="'.$langs->trans("Search").'"></td>';
116 }
117 print '</tr>';
118 $i++;
119 }
120 print '</table>';
121 print '</form>';
122 print '<br>';
123 }
124}
125
126$dataseries = array();
127$colorseries = array();
128
129include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
130
131print '<table class="noborder nohover centpercent">';
132print '<tr class="liste_titre">';
133print '<th colspan="4">'.$langs->trans("Statistics").'</th>';
134print "</tr>\n";
135
136$listofstatus = array(0, 1, -1, 2);
137foreach ($listofstatus as $status) {
138 $dataseries[] = array($donstatic->LibStatut($status, 1), (isset($nb[$status]) ? (int) $nb[$status] : 0));
139 if ($status == Don::STATUS_DRAFT) {
140 $colorseries[$status] = '-'.$badgeStatus0;
141 }
142 if ($status == Don::STATUS_VALIDATED) {
143 $colorseries[$status] = $badgeStatus1;
144 }
145 if ($status == Don::STATUS_CANCELED) {
146 $colorseries[$status] = $badgeStatus9;
147 }
148 if ($status == Don::STATUS_PAID) {
149 $colorseries[$status] = $badgeStatus6;
150 }
151}
152
153if ($conf->use_javascript_ajax) {
154 print '<tr><td class="center" colspan="4">';
155
156 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
157 $dolgraph = new DolGraph();
158 $dolgraph->SetData($dataseries);
159 $dolgraph->SetDataColor(array_values($colorseries));
160 $dolgraph->setShowLegend(2);
161 $dolgraph->setShowPercent(1);
162 $dolgraph->SetType(array('pie'));
163 $dolgraph->setHeight('200');
164 $dolgraph->draw('idgraphstatus');
165 print $dolgraph->show($total ? 0 : 1);
166
167 print '</td></tr>';
168}
169
170print '<tr class="liste_titre">';
171print '<td>'.$langs->trans("Status").'</td>';
172print '<td class="right">'.$langs->trans("Number").'</td>';
173print '<td class="right">'.$langs->trans("Total").'</td>';
174print '<td class="right">'.$langs->trans("Average").'</td>';
175print '</tr>';
176
177$total = 0;
178$totalnb = 0;
179foreach ($listofstatus as $status) {
180 print '<tr class="oddeven">';
181 print '<td><a href="list.php?search_status='.$status.'">'.$donstatic->LibStatut($status, 4).'</a></td>';
182 print '<td class="right">'.(!empty($nb[$status]) ? $nb[$status] : '&nbsp;').'</td>';
183 print '<td class="right nowraponall amount">'.(!empty($nb[$status]) ? price($somme[$status], 1, '', 1, -1, 'MT') : '&nbsp;').'</td>';
184 print '<td class="right nowraponall">'.(!empty($nb[$status]) ? price(price2num($somme[$status] / $nb[$status], 'MT')) : '&nbsp;').'</td>';
185 $totalnb += (!empty($nb[$status]) ? $nb[$status] : 0);
186 $total += (!empty($somme[$status]) ? $somme[$status] : 0);
187 print "</tr>";
188}
189
190print '<tr class="liste_total">';
191print '<td>'.$langs->trans("Total").'</td>';
192print '<td class="right nowraponall">'.$totalnb.'</td>';
193print '<td class="right nowraponall">'.price($total, 1, "", 1, -1, 'MT').'</td>';
194print '<td class="right nowraponall">'.($totalnb ? price(price2num($total / $totalnb, 'MT')) : '&nbsp;').'</td>';
195print '</tr>';
196print "</table>";
197
198
199print '</div><div class="fichetwothirdright">';
200
201
202$max = 10;
203
204/*
205 * Last modified donations
206 */
207
208$sql = "SELECT c.rowid, c.ref, c.fk_statut, c.societe, c.lastname, c.firstname, c.tms as datem, c.amount";
209$sql .= " FROM ".MAIN_DB_PREFIX."don as c";
210$sql .= " WHERE c.entity = ".$conf->entity;
211//$sql.= " AND c.fk_statut > 2";
212$sql .= " ORDER BY c.tms DESC";
213$sql .= $db->plimit($max, 0);
214
215$resql = $db->query($sql);
216if ($resql) {
217 print '<table class="noborder centpercent">';
218 print '<tr class="liste_titre">';
219 print '<th colspan="5">'.$langs->trans("LastModifiedDonations", $max).'</th></tr>';
220
221 $num = $db->num_rows($resql);
222 if ($num) {
223 $i = 0;
224 while ($i < $num) {
225 $obj = $db->fetch_object($resql);
226
227 print '<tr class="oddeven">';
228
229 $donation_static->id = $obj->rowid;
230 $donation_static->ref = $obj->ref ? $obj->ref : $obj->rowid;
231
232 print '<td width="96" class="nobordernopadding nowrap">';
233 print $donation_static->getNomUrl(1);
234 print '</td>';
235
236 print '<td class="nobordernopadding">';
237 print $obj->societe;
238 print($obj->societe && ($obj->lastname || $obj->firstname) ? ' / ' : '');
239 print dolGetFirstLastname($obj->firstname, $obj->lastname);
240 print '</td>';
241
242 print '<td class="right nobordernopadding nowraponall amount">';
243 print price($obj->amount, 1);
244 print '</td>';
245
246 // Date
247 print '<td class="center">'.dol_print_date($db->jdate($obj->datem), 'day').'</td>';
248
249 print '<td class="right">'.$donation_static->LibStatut($obj->fk_statut, 5).'</td>';
250
251 print '</tr>';
252 $i++;
253 }
254 }
255 print "</table><br>";
256} else {
257 dol_print_error($db);
258}
259
260
261print '</div></div>';
262
263$parameters = array('user' => $user);
264$reshook = $hookmanager->executeHooks('dashboardDonation', $parameters, $object); // Note that $action and $object may have been modified by hook
265
266llxFooter();
267
268$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:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to build graphs.
Class to manage donations.
Definition don.class.php:41
Class to manage hooks.
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.
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 dolibarr global constant string value.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
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.