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