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