dolibarr 25.0.0-alpha
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-2026 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
135$theme_vars_file = dol_getThemeFilePath('theme_vars.inc.php');
136if ($theme_vars_file) {
137 include $theme_vars_file;
138}
146print '<table class="noborder nohover centpercent">';
147print '<tr class="liste_titre">';
148print '<th colspan="4">'.$langs->trans("Statistics").'</th>';
149print "</tr>\n";
150
151$listofstatus = array(0, 1, -1, 2);
152foreach ($listofstatus as $status) {
153 $dataseries[] = array($donstatic->LibStatut($status, 1), (isset($nb[$status]) ? (int) $nb[$status] : 0));
154 if ($status == Don::STATUS_DRAFT) {
155 $colorseries[$status] = '-'.$badgeStatus0;
156 }
157 if ($status == Don::STATUS_VALIDATED) {
158 $colorseries[$status] = $badgeStatus1;
159 }
160 if ($status == Don::STATUS_CANCELED) {
161 $colorseries[$status] = $badgeStatus9;
162 }
163 if ($status == Don::STATUS_PAID) {
164 $colorseries[$status] = $badgeStatus6;
165 }
166}
167
168if ($conf->use_javascript_ajax) {
169 print '<tr><td class="center" colspan="4">';
170
171 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
172 $dolgraph = new DolGraph();
173 $dolgraph->SetData($dataseries);
174 $dolgraph->SetDataColor(array_values($colorseries));
175 $dolgraph->setShowLegend(2);
176 $dolgraph->setShowPercent(1);
177 $dolgraph->SetType(array('pie'));
178 $dolgraph->setHeight('200');
179 $dolgraph->draw('idgraphstatus');
180 print $dolgraph->show($total ? 0 : 1);
181
182 print '</td></tr>';
183}
184
185print '<tr class="liste_titre">';
186print '<td>'.$langs->trans("Status").'</td>';
187print '<td class="right">'.$langs->trans("Number").'</td>';
188print '<td class="right">'.$langs->trans("Total").'</td>';
189print '<td class="right">'.$langs->trans("Average").'</td>';
190print '</tr>';
191
192$total = 0;
193$totalnb = 0;
194foreach ($listofstatus as $status) {
195 print '<tr class="oddeven">';
196 print '<td><a href="list.php?search_status='.$status.'">'.$donstatic->LibStatut($status, 4).'</a></td>';
197 print '<td class="right">'.(!empty($nb[$status]) ? $nb[$status] : '&nbsp;').'</td>';
198 print '<td class="right nowraponall amount">'.(!empty($nb[$status]) ? price($somme[$status], 1, '', 1, -1, 'MT') : '&nbsp;').'</td>';
199 print '<td class="right nowraponall">'.(!empty($nb[$status]) ? price(price2num($somme[$status] / $nb[$status], 'MT')) : '&nbsp;').'</td>';
200 $totalnb += (!empty($nb[$status]) ? $nb[$status] : 0);
201 $total += (!empty($somme[$status]) ? $somme[$status] : 0);
202 print "</tr>";
203}
204
205print '<tr class="liste_total">';
206print '<td>'.$langs->trans("Total").'</td>';
207print '<td class="right nowraponall">'.$totalnb.'</td>';
208print '<td class="right nowraponall">'.price($total, 1, "", 1, -1, 'MT').'</td>';
209print '<td class="right nowraponall">'.($totalnb ? price(price2num($total / $totalnb, 'MT')) : '&nbsp;').'</td>';
210print '</tr>';
211print "</table>";
212
213
214print '</div><div class="fichetwothirdright">';
215
216
217$max = getDolUserInt('MAIN_SIZE_SHORTLIST_LIMIT', getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5));
218
219
220/*
221 * Last modified donations
222 */
223
224$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";
225$sql .= " FROM ".MAIN_DB_PREFIX."don as c";
226$sql .= " WHERE c.entity IN (".getEntity("don").")";
227//$sql.= " AND c.fk_statut > 2";
228$sql .= " ORDER BY c.tms DESC";
229$sql .= $db->plimit($max, 0);
230
231$resql = $db->query($sql);
232if ($resql) {
233 print '<table class="noborder centpercent">';
234 print '<tr class="liste_titre">';
235 print '<th colspan="5">'.$langs->trans("LastModifiedDonations", $max).' ';
236 print '<a href="'.DOL_URL_ROOT.'/don/list.php?sortfield=d.datedon&sortorder=DESC">';
237 print '<span class="badge">...</span>';
238 print '</a>';
239 print '</th></tr>';
240
241 $num = $db->num_rows($resql);
242 if ($num) {
243 $i = 0;
244 while ($i < $num) {
245 $obj = $db->fetch_object($resql);
246
247 print '<tr class="oddeven">';
248
249 $donation_static->id = $obj->rowid;
250 $donation_static->ref = $obj->ref ? $obj->ref : $obj->rowid;
251
252 print '<td width="96" class="nobordernopadding nowrap">';
253 print $donation_static->getNomUrl(1);
254 print '</td>';
255
256 print '<td class="nobordernopadding">';
257 if (!empty($obj->socid)) {
258 $companystatic = new Societe($db);
259 $ret = $companystatic->fetch($obj->socid);
260 if ($ret > 0) {
261 print $companystatic->getNomUrl(1);
262 }
263 } else {
264 print $obj->societe;
265 print($obj->societe && ($obj->lastname || $obj->firstname) ? ' / ' : '');
266 print dolGetFirstLastname($obj->firstname, $obj->lastname);
267 }
268 print '</td>';
269
270 print '<td class="right nobordernopadding nowraponall amount">';
271 print price($obj->amount, 1);
272 print '</td>';
273
274 // Date
275 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>';
276
277 print '<td class="right">'.$donation_static->LibStatut($obj->fk_statut, 5).'</td>';
278
279 print '</tr>';
280 $i++;
281 }
282 }
283 print "</table><br>";
284} else {
285 dol_print_error($db);
286}
287
288
289print '</div></div>';
290
291$parameters = array('user' => $user);
292$reshook = $hookmanager->executeHooks('dashboardDonation', $parameters, $object); // Note that $action and $object may have been modified by hook
293
294llxFooter();
295
296$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...)
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
getDolUserInt($key, $default=0, $tmpuser=null)
Return Dolibarr user constant int value.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_getThemeFilePath($file, $theme='')
Return the full filesystem path of a file located in the currently selected theme directory.
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_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.