dolibarr  13.0.2
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';
57 llxHeader('', $langs->trans("Donations"), $help_url);
58 
59 $nb = array();
60 $somme = array();
61 $total = 0;
62 
63 $sql = "SELECT count(d.rowid) as nb, sum(d.amount) as somme , d.fk_statut";
64 $sql .= " FROM ".MAIN_DB_PREFIX."don as d WHERE d.entity IN (".getEntity('donation').")";
65 $sql .= " GROUP BY d.fk_statut";
66 $sql .= " ORDER BY d.fk_statut";
67 
68 $result = $db->query($sql);
69 if ($result)
70 {
71  $i = 0;
72  $num = $db->num_rows($result);
73  while ($i < $num)
74  {
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 
88 print load_fiche_titre($langs->trans("DonationsArea"), '', 'object_donation');
89 
90 
91 print '<div class="fichecenter"><div class="fichethirdleft">';
92 
93 if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
94 {
95  if (!empty($conf->don->enabled) && $user->rights->don->lire)
96  {
97  $listofsearchfields['search_donation'] = array('text'=>'Donation');
98  }
99 
100  if (count($listofsearchfields))
101  {
102  print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
103  print '<input type="hidden" name="token" value="'.newToken().'">';
104  print '<table class="noborder nohover centpercent">';
105  $i = 0;
106  foreach ($listofsearchfields as $key => $value)
107  {
108  if ($i == 0) print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
109  print '<tr '.$bc[false].'>';
110  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>';
111  if ($i == 0) print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
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 
124 include_once DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
125 
126 print '<table class="noborder nohover centpercent">';
127 print '<tr class="liste_titre">';
128 print '<th colspan="4">'.$langs->trans("Statistics").'</th>';
129 print "</tr>\n";
130 
131 $listofstatus = array(0, 1, -1, 2);
132 foreach ($listofstatus as $status)
133 {
134  $dataseries[] = array($donstatic->LibStatut($status, 1), (isset($nb[$status]) ? (int) $nb[$status] : 0));
135  if ($status == Don::STATUS_DRAFT) $colorseries[$status] = '-'.$badgeStatus0;
136  if ($status == Don::STATUS_VALIDATED) $colorseries[$status] = $badgeStatus1;
137  if ($status == Don::STATUS_CANCELED) $colorseries[$status] = $badgeStatus9;
138  if ($status == Don::STATUS_PAID) $colorseries[$status] = $badgeStatus6;
139 }
140 
141 if ($conf->use_javascript_ajax)
142 {
143  print '<tr><td class="center" colspan="4">';
144 
145  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
146  $dolgraph = new DolGraph();
147  $dolgraph->SetData($dataseries);
148  $dolgraph->SetDataColor(array_values($colorseries));
149  $dolgraph->setShowLegend(2);
150  $dolgraph->setShowPercent(1);
151  $dolgraph->SetType(array('pie'));
152  $dolgraph->setHeight('200');
153  $dolgraph->draw('idgraphstatus');
154  print $dolgraph->show($total ? 0 : 1);
155 
156  print '</td></tr>';
157 }
158 
159 print '<tr class="liste_titre">';
160 print '<td>'.$langs->trans("Status").'</td>';
161 print '<td class="right">'.$langs->trans("Number").'</td>';
162 print '<td class="right">'.$langs->trans("Total").'</td>';
163 print '<td class="right">'.$langs->trans("Average").'</td>';
164 print '</tr>';
165 
166 $total = 0;
167 $totalnb = 0;
168 foreach ($listofstatus as $status)
169 {
170  print '<tr class="oddeven">';
171  print '<td><a href="list.php?search_status='.$status.'">'.$donstatic->LibStatut($status, 4).'</a></td>';
172  print '<td class="right">'.(!empty($nb[$status]) ? $nb[$status] : '&nbsp;').'</td>';
173  print '<td class="right">'.(!empty($nb[$status]) ?price($somme[$status], 'MT') : '&nbsp;').'</td>';
174  print '<td class="right">'.(!empty($nb[$status]) ?price(price2num($somme[$status] / $nb[$status], 'MT')) : '&nbsp;').'</td>';
175  $totalnb += (!empty($nb[$status]) ? $nb[$status] : 0);
176  $total += (!empty($somme[$status]) ? $somme[$status] : 0);
177  print "</tr>";
178 }
179 
180 print '<tr class="liste_total">';
181 print '<td>'.$langs->trans("Total").'</td>';
182 print '<td class="right">'.$totalnb.'</td>';
183 print '<td class="right">'.price($total, 'MT').'</td>';
184 print '<td class="right">'.($totalnb ?price(price2num($total / $totalnb, 'MT')) : '&nbsp;').'</td>';
185 print '</tr>';
186 print "</table>";
187 
188 
189 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
190 
191 
192 $max = 10;
193 
194 /*
195  * Last modified donations
196  */
197 
198 $sql = "SELECT c.rowid, c.ref, c.fk_statut, c.societe, c.lastname, c.firstname, c.tms as datem, c.amount";
199 $sql .= " FROM ".MAIN_DB_PREFIX."don as c";
200 $sql .= " WHERE c.entity = ".$conf->entity;
201 //$sql.= " AND c.fk_statut > 2";
202 $sql .= " ORDER BY c.tms DESC";
203 $sql .= $db->plimit($max, 0);
204 
205 $resql = $db->query($sql);
206 if ($resql)
207 {
208  print '<table class="noborder centpercent">';
209  print '<tr class="liste_titre">';
210  print '<th colspan="5">'.$langs->trans("LastModifiedDonations", $max).'</th></tr>';
211 
212  $num = $db->num_rows($resql);
213  if ($num)
214  {
215  $i = 0;
216  while ($i < $num)
217  {
218  $obj = $db->fetch_object($resql);
219 
220  print '<tr class="oddeven">';
221 
222  $donation_static->id = $obj->rowid;
223  $donation_static->ref = $obj->ref ? $obj->ref : $obj->rowid;
224 
225  print '<td width="96" class="nobordernopadding nowrap">';
226  print $donation_static->getNomUrl(1);
227  print '</td>';
228 
229  print '<td class="nobordernopadding">';
230  print $obj->societe;
231  print ($obj->societe && ($obj->lastname || $obj->firstname) ? ' / ' : '');
232  print dolGetFirstLastname($obj->lastname, $obj->firstname);
233  print '</td>';
234 
235  print '<td class="right nobordernopadding">';
236  print price($obj->amount, 1);
237  print '</td>';
238 
239  // Date
240  print '<td class="center">'.dol_print_date($db->jdate($obj->datem), 'day').'</td>';
241 
242  print '<td class="right">'.$donation_static->LibStatut($obj->fk_statut, 5).'</td>';
243 
244  print '</tr>';
245  $i++;
246  }
247  }
248  print "</table><br>";
249 } else dol_print_error($db);
250 
251 
252 print '</div></div></div>';
253 
254 $parameters = array('user' => $user);
255 $reshook = $hookmanager->executeHooks('dashboardDonation', $parameters, $object); // Note that $action and $object may have been modified by hook
256 
257 llxFooter();
258 
259 $db->close();
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...
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage hooks.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
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 &#39;...
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
print
Draft customers invoices.
Definition: index.php:89
Class to manage donations.
Definition: don.class.php:37
Class to build graphs.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
llxFooter()
Empty footer.
Definition: wrapper.php:59
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.