dolibarr  7.0.0-beta
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@capnetworks.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
28 
29 $langs->load("donations");
30 
31 // Security check
32 $result = restrictedArea($user, 'don');
33 
34 $donation_static=new Don($db);
35 
36 
37 /*
38  * Actions
39  */
40 
41 // None
42 
43 
44 /*
45  * View
46  */
47 
48 $donstatic=new Don($db);
49 
50 $help_url='EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones';
51 llxHeader('',$langs->trans("Donations"),$help_url);
52 
53 $nb=array();
54 $somme=array();
55 $total = 0;
56 
57 $sql = "SELECT count(d.rowid) as nb, sum(d.amount) as somme , d.fk_statut";
58 $sql.= " FROM ".MAIN_DB_PREFIX."don as d WHERE d.entity IN (".getEntity('donation').")";
59 $sql.= " GROUP BY d.fk_statut";
60 $sql.= " ORDER BY d.fk_statut";
61 
62 $result = $db->query($sql);
63 if ($result)
64 {
65  $i = 0;
66  $num = $db->num_rows($result);
67  while ($i < $num)
68  {
69  $objp = $db->fetch_object($result);
70 
71  $somme[$objp->fk_statut] = $objp->somme;
72  $nb[$objp->fk_statut] = $objp->nb;
73  $total += $objp->somme;
74 
75  $i++;
76  }
77  $db->free($result);
78 } else {
79  dol_print_error($db);
80 }
81 
82 print load_fiche_titre($langs->trans("DonationsArea"));
83 
84 
85 print '<div class="fichecenter"><div class="fichethirdleft">';
86 
87 if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
88 {
89  if (! empty($conf->don->enabled) && $user->rights->don->lire)
90  {
91  $listofsearchfields['search_donation']=array('text'=>'Donation');
92  }
93 
94  if (count($listofsearchfields))
95  {
96  print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
97  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
98  print '<table class="noborder nohover centpercent">';
99  $i=0;
100  foreach($listofsearchfields as $key => $value)
101  {
102  if ($i == 0) print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
103  print '<tr '.$bc[false].'>';
104  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>';
105  if ($i == 0) print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
106  print '</tr>';
107  $i++;
108  }
109  print '</table>';
110  print '</form>';
111  print '<br>';
112  }
113 }
114 
115 
116 print '<table class="noborder nohover" width="100%">';
117 print '<tr class="liste_titre">';
118 print '<th colspan="4">'.$langs->trans("Statistics").'</th>';
119 print "</tr>\n";
120 
121 $listofstatus=array(0,1,-1,2);
122 foreach ($listofstatus as $status)
123 {
124  $dataseries[]=array($donstatic->LibStatut($status,1), (isset($nb[$status])?(int) $nb[$status]:0));
125 }
126 
127 if ($conf->use_javascript_ajax)
128 {
129  print '<tr><td align="center" colspan="4">';
130 
131  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
132  $dolgraph = new DolGraph();
133  $dolgraph->SetData($dataseries);
134  $dolgraph->setShowLegend(1);
135  $dolgraph->setShowPercent(1);
136  $dolgraph->SetType(array('pie'));
137  $dolgraph->setWidth('100%');
138  $dolgraph->draw('idgraphstatus');
139  print $dolgraph->show($total?0:1);
140 
141  print '</td></tr>';
142 }
143 
144 print '<tr class="liste_titre">';
145 print '<td>'.$langs->trans("Status").'</td>';
146 print '<td align="right">'.$langs->trans("Number").'</td>';
147 print '<td align="right">'.$langs->trans("Total").'</td>';
148 print '<td align="right">'.$langs->trans("Average").'</td>';
149 print '</tr>';
150 
151 $total=0;
152 $totalnb=0;
153 $var=true;
154 foreach ($listofstatus as $status)
155 {
156 
157  print '<tr class="oddeven">';
158  print '<td><a href="list.php?statut='.$status.'">'.$donstatic->LibStatut($status,4).'</a></td>';
159  print '<td align="right">'.(! empty($nb[$status])?$nb[$status]:'&nbsp;').'</td>';
160  print '<td align="right">'.(! empty($nb[$status])?price($somme[$status],'MT'):'&nbsp;').'</td>';
161  print '<td align="right">'.(! empty($nb[$status])?price(price2num($somme[$status]/$nb[$status],'MT')):'&nbsp;').'</td>';
162  $totalnb += (! empty($nb[$status])?$nb[$status]:0);
163  $total += (! empty($somme[$status])?$somme[$status]:0);
164  print "</tr>";
165 }
166 
167 print '<tr class="liste_total">';
168 print '<td>'.$langs->trans("Total").'</td>';
169 print '<td align="right">'.$totalnb.'</td>';
170 print '<td align="right">'.price($total,'MT').'</td>';
171 print '<td align="right">'.($totalnb?price(price2num($total/$totalnb,'MT')):'&nbsp;').'</td>';
172 print '</tr>';
173 print "</table>";
174 
175 
176 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
177 
178 
179 $max=10;
180 
181 /*
182  * Last modified donations
183  */
184 
185 $sql = "SELECT c.rowid, c.ref, c.fk_statut, c.societe, c.lastname, c.firstname, c.tms as datem, c.amount";
186 $sql.= " FROM ".MAIN_DB_PREFIX."don as c";
187 $sql.= " WHERE c.entity = ".$conf->entity;
188 //$sql.= " AND c.fk_statut > 2";
189 $sql.= " ORDER BY c.tms DESC";
190 $sql.= $db->plimit($max, 0);
191 
192 $resql=$db->query($sql);
193 if ($resql)
194 {
195  print '<table class="noborder" width="100%">';
196  print '<tr class="liste_titre">';
197  print '<th colspan="5">'.$langs->trans("LastModifiedDonations",$max).'</th></tr>';
198 
199  $num = $db->num_rows($resql);
200  if ($num)
201  {
202  $i = 0;
203  $var = True;
204  while ($i < $num)
205  {
206 
207  $obj = $db->fetch_object($resql);
208 
209  print '<tr class="oddeven">';
210 
211  $donation_static->id=$obj->rowid;
212  $donation_static->ref=$obj->ref?$obj->ref:$obj->rowid;
213 
214  print '<td width="96" class="nobordernopadding nowrap">';
215  print $donation_static->getNomUrl(1);
216  print '</td>';
217 
218  print '<td class="nobordernopadding">';
219  print $obj->societe;
220  print ($obj->societe && ($obj->lastname || $obj->firstname)?' / ':'');
221  print dolGetFirstLastname($obj->lastname,$obj->firstname);
222  print '</td>';
223 
224  print '<td align="right" class="nobordernopadding">';
225  print price($obj->amount,1);
226  print '</td>';
227 
228  // Date
229  print '<td align="center">'.dol_print_date($db->jdate($obj->datem),'day').'</td>';
230 
231  print '<td align="right">'.$donation_static->LibStatut($obj->fk_statut,5).'</td>';
232 
233  print '</tr>';
234  $i++;
235  }
236  }
237  print "</table><br>";
238 }
239 else dol_print_error($db);
240 
241 
242 print '</div></div></div>';
243 
244 
245 llxFooter();
246 
247 $db->close();
llxFooter()
Footer empty.
Definition: index.php:43
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
llxHeader()
Header empty.
Definition: index.php:37
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
getEntity($element, $shared=1, $forceentity=null)
Get list of entity id to use.
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...
print
Draft customers invoices.
Definition: index.php:91
Class to manage donations.
Definition: don.class.php:35
Class to build graphs.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->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)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.