dolibarr 22.0.5
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-2025 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
102$listofsearchfields = array();
103
104if (getDolGlobalString('MAIN_SEARCH_FORM_ON_HOME_AREAS')) { // TODO Add a search into global search combo so we can remove this
105 if (isModEnabled('don') && $user->hasRight('don', 'lire')) {
106 $listofsearchfields['search_donation'] = array('text' => 'Donation');
107 }
108
109 if (count($listofsearchfields)) {
110 print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
111 print '<input type="hidden" name="token" value="'.newToken().'">';
112 print '<table class="noborder nohover centpercent">';
113 $i = 0;
114 foreach ($listofsearchfields as $key => $value) {
115 if ($i == 0) {
116 print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
117 }
118 print '<tr>';
119 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>';
120 if ($i == 0) {
121 print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" class="button" value="'.$langs->trans("Search").'"></td>';
122 }
123 print '</tr>';
124 $i++;
125 }
126 print '</table>';
127 print '</form>';
128 print '<br>';
129 }
130}
131
132$dataseries = array();
133$colorseries = array();
134
135include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
136
137print '<table class="noborder nohover centpercent">';
138print '<tr class="liste_titre">';
139print '<th colspan="4">'.$langs->trans("Statistics").'</th>';
140print "</tr>\n";
141
142$listofstatus = array(0, 1, -1, 2);
143foreach ($listofstatus as $status) {
144 $dataseries[] = array($donstatic->LibStatut($status, 1), (isset($nb[$status]) ? (int) $nb[$status] : 0));
145 if ($status == Don::STATUS_DRAFT) {
146 $colorseries[$status] = '-'.$badgeStatus0;
147 }
148 if ($status == Don::STATUS_VALIDATED) {
149 $colorseries[$status] = $badgeStatus1;
150 }
151 if ($status == Don::STATUS_CANCELED) {
152 $colorseries[$status] = $badgeStatus9;
153 }
154 if ($status == Don::STATUS_PAID) {
155 $colorseries[$status] = $badgeStatus6;
156 }
157}
158
159if ($conf->use_javascript_ajax) {
160 print '<tr><td class="center" colspan="4">';
161
162 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
163 $dolgraph = new DolGraph();
164 $dolgraph->SetData($dataseries);
165 $dolgraph->SetDataColor(array_values($colorseries));
166 $dolgraph->setShowLegend(2);
167 $dolgraph->setShowPercent(1);
168 $dolgraph->SetType(array('pie'));
169 $dolgraph->setHeight('200');
170 $dolgraph->draw('idgraphstatus');
171 print $dolgraph->show($total ? 0 : 1);
172
173 print '</td></tr>';
174}
175
176print '<tr class="liste_titre">';
177print '<td>'.$langs->trans("Status").'</td>';
178print '<td class="right">'.$langs->trans("Number").'</td>';
179print '<td class="right">'.$langs->trans("Total").'</td>';
180print '<td class="right">'.$langs->trans("Average").'</td>';
181print '</tr>';
182
183$total = 0;
184$totalnb = 0;
185foreach ($listofstatus as $status) {
186 print '<tr class="oddeven">';
187 print '<td><a href="list.php?search_status='.$status.'">'.$donstatic->LibStatut($status, 4).'</a></td>';
188 print '<td class="right">'.(!empty($nb[$status]) ? $nb[$status] : '&nbsp;').'</td>';
189 print '<td class="right nowraponall amount">'.(!empty($nb[$status]) ? price($somme[$status], 1, '', 1, -1, 'MT') : '&nbsp;').'</td>';
190 print '<td class="right nowraponall">'.(!empty($nb[$status]) ? price(price2num($somme[$status] / $nb[$status], 'MT')) : '&nbsp;').'</td>';
191 $totalnb += (!empty($nb[$status]) ? $nb[$status] : 0);
192 $total += (!empty($somme[$status]) ? $somme[$status] : 0);
193 print "</tr>";
194}
195
196print '<tr class="liste_total">';
197print '<td>'.$langs->trans("Total").'</td>';
198print '<td class="right nowraponall">'.$totalnb.'</td>';
199print '<td class="right nowraponall">'.price($total, 1, "", 1, -1, 'MT').'</td>';
200print '<td class="right nowraponall">'.($totalnb ? price(price2num($total / $totalnb, 'MT')) : '&nbsp;').'</td>';
201print '</tr>';
202print "</table>";
203
204
205print '</div><div class="fichetwothirdright">';
206
207
208$max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
209
210
211/*
212 * Last modified donations
213 */
214
215$sql = "SELECT c.rowid, c.ref, c.fk_statut, c.societe, c.lastname, c.firstname, c.tms as datem, c.amount, c.fk_soc as socid";
216$sql .= " FROM ".MAIN_DB_PREFIX."don as c";
217$sql .= " WHERE c.entity IN (".getEntity("don").")";
218//$sql.= " AND c.fk_statut > 2";
219$sql .= " ORDER BY c.tms DESC";
220$sql .= $db->plimit($max, 0);
221
222$resql = $db->query($sql);
223if ($resql) {
224 print '<table class="noborder centpercent">';
225 print '<tr class="liste_titre">';
226 print '<th colspan="5">'.$langs->trans("LastModifiedDonations", $max).' ';
227 print '<a href="'.DOL_URL_ROOT.'/don/list.php?sortfield=d.datedon&sortorder=DESC">';
228 print '<span class="badge">...</span>';
229 print '</a>';
230 print '</th></tr>';
231
232 $num = $db->num_rows($resql);
233 if ($num) {
234 $i = 0;
235 while ($i < $num) {
236 $obj = $db->fetch_object($resql);
237
238 print '<tr class="oddeven">';
239
240 $donation_static->id = $obj->rowid;
241 $donation_static->ref = $obj->ref ? $obj->ref : $obj->rowid;
242
243 print '<td width="96" class="nobordernopadding nowrap">';
244 print $donation_static->getNomUrl(1);
245 print '</td>';
246
247 print '<td class="nobordernopadding">';
248 if (!empty($obj->socid)) {
249 $companystatic = new Societe($db);
250 $ret = $companystatic->fetch($obj->socid);
251 if ($ret > 0) {
252 print $companystatic->getNomUrl(1);
253 }
254 } else {
255 print $obj->societe;
256 print($obj->societe && ($obj->lastname || $obj->firstname) ? ' / ' : '');
257 print dolGetFirstLastname($obj->firstname, $obj->lastname);
258 }
259 print '</td>';
260
261 print '<td class="right nobordernopadding nowraponall amount">';
262 print price($obj->amount, 1);
263 print '</td>';
264
265 // Date
266 print '<td class="center" title="'.$langs->trans("DonationDate").': '.dol_print_date($db->jdate($obj->datem), 'day').'">'.dol_print_date($db->jdate($obj->datem), 'day').'</td>';
267
268 print '<td class="right">'.$donation_static->LibStatut($obj->fk_statut, 5).'</td>';
269
270 print '</tr>';
271 $i++;
272 }
273 }
274 print "</table><br>";
275} else {
276 dol_print_error($db);
277}
278
279
280print '</div></div>';
281
282$parameters = array('user' => $user);
283$reshook = $hookmanager->executeHooks('dashboardDonation', $parameters, $object); // Note that $action and $object may have been modified by hook
284
285llxFooter();
286
287$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
Class to build graphs.
Class to manage donations.
Definition don.class.php:41
Class to manage third parties objects (customers, suppliers, prospects...)
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.
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).
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.