dolibarr  9.0.0
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
5  * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  * or see http://www.gnu.org/
21  */
22 
29 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT . '/compta/tva/class/tva.class.php';
31 require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php';
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array('companies', 'users', 'trips'));
35 
36 // Security check
37 $socid = GETPOST('socid','int');
38 if ($user->societe_id) $socid=$user->societe_id;
39 $result = restrictedArea($user, 'expensereport','','');
40 
41 $sortfield = GETPOST("sortfield",'alpha');
42 $sortorder = GETPOST("sortorder",'alpha');
43 $page = GETPOST("page",'int');
44 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
45 $offset = $conf->liste_limit * $page;
46 $pageprev = $page - 1;
47 $pagenext = $page + 1;
48 if (! $sortorder) $sortorder="DESC";
49 if (! $sortfield) $sortfield="d.date_create";
50 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
51 
52 
53 /*
54  * View
55  */
56 
57 $tripandexpense_static=new ExpenseReport($db);
58 
59 $childids = $user->getAllChildIds();
60 $childids[]=$user->id;
61 
62 //$help_url='EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones';
63 $help_url='';
64 llxHeader('',$langs->trans("ListOfFees"),$help_url);
65 
66 
67 $label=$somme=$nb=array();
68 
69 $totalnb=$totalsum=0;
70 $sql = "SELECT tf.code, tf.label, count(de.rowid) as nb, sum(de.total_ht) as km";
71 $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as d, ".MAIN_DB_PREFIX."expensereport_det as de, ".MAIN_DB_PREFIX."c_type_fees as tf";
72 $sql.= " WHERE de.fk_expensereport = d.rowid AND d.entity IN (".getEntity('expensereport').") AND de.fk_c_type_fees = tf.id";
73 // RESTRICT RIGHTS
74 if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)
75  && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance)))
76 {
77  $childids = $user->getAllChildIds();
78  $childids[]=$user->id;
79  $sql.= " AND d.fk_user_author IN (".join(',',$childids).")\n";
80 }
81 
82 $sql.= " GROUP BY tf.code, tf.label";
83 
84 $result = $db->query($sql);
85 if ($result)
86 {
87  $num = $db->num_rows($result);
88  $i = 0;
89  while ($i < $num)
90  {
91  $objp = $db->fetch_object($result);
92 
93  $somme[$objp->code] = $objp->km;
94  $nb[$objp->code] = $objp->nb;
95  $label[$objp->code] = $objp->label;
96  $totalnb += $objp->nb;
97  $totalsum += $objp->km;
98  $i++;
99  }
100  $db->free($result);
101 } else {
102  dol_print_error($db);
103 }
104 
105 
106 print load_fiche_titre($langs->trans("ExpensesArea"));
107 
108 
109 print '<div class="fichecenter"><div class="fichethirdleft">';
110 
111 
112 print '<table class="noborder nohover" width="100%">';
113 print '<tr class="liste_titre">';
114 print '<th colspan="4">'.$langs->trans("Statistics").'</th>';
115 print "</tr>\n";
116 
117 $listoftype=$tripandexpense_static->listOfTypes();
118 foreach ($listoftype as $code => $label)
119 {
120  $dataseries[]=array($label, (isset($somme[$code])?(int) $somme[$code]:0));
121 }
122 
123 if ($conf->use_javascript_ajax)
124 {
125  print '<tr><td align="center" colspan="4">';
126 
127  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
128  $dolgraph = new DolGraph();
129  $dolgraph->SetData($dataseries);
130  $dolgraph->setShowLegend(1);
131  $dolgraph->setShowPercent(1);
132  $dolgraph->SetType(array('pie'));
133  $dolgraph->setWidth('100%');
134  $dolgraph->draw('idgraphstatus');
135  print $dolgraph->show($totalnb?0:1);
136 
137  print '</td></tr>';
138 }
139 
140 print '<tr class="liste_total">';
141 print '<td>'.$langs->trans("Total").'</td>';
142 print '<td align="right" colspan="3">'.price($totalsum,1,$langs,0,0,0,$conf->currency).'</td>';
143 print '</tr>';
144 
145 print '</table>';
146 
147 
148 
149 // Right area
150 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
151 
152 
153 $max=10;
154 
155 $langs->load("boxes");
156 
157 $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.statut, u.photo, d.rowid, d.ref, d.date_debut as dated, d.date_fin as datef, d.date_create as dm, d.total_ht, d.total_ttc, d.fk_statut as fk_status";
158 $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as d, ".MAIN_DB_PREFIX."user as u";
159 if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
160 $sql.= " WHERE u.rowid = d.fk_user_author";
161 // RESTRICT RIGHTS
162 if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)
163  && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance)))
164 {
165  $childids = $user->getAllChildIds();
166  $childids[]=$user->id;
167  $sql.= " AND d.fk_user_author IN (".join(',',$childids).")\n";
168 }
169 $sql.= ' AND d.entity IN ('.getEntity('expensereport').')';
170 if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND d.fk_user_author = s.rowid AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
171 if ($socid) $sql.= " AND d.fk_user_author = ".$socid;
172 $sql.= $db->order($sortfield,$sortorder);
173 $sql.= $db->plimit($max, 0);
174 
175 $result = $db->query($sql);
176 if ($result)
177 {
178  $var=false;
179  $num = $db->num_rows($result);
180 
181  $i = 0;
182 
183  print '<table class="noborder" width="100%">';
184  print '<tr class="liste_titre">';
185  print '<th colspan="2">'.$langs->trans("BoxTitleLastModifiedExpenses",min($max,$num)).'</th>';
186  print '<th align="right">'.$langs->trans("AmountHT").'</th>';
187  print '<th align="right">'.$langs->trans("AmountTTC").'</th>';
188  print '<th align="right">'.$langs->trans("DateModificationShort").'</th>';
189  print '<th>&nbsp;</th>';
190  print '</tr>';
191  if ($num)
192  {
193  $total_ttc = $totalam = $total = 0;
194 
195  $expensereportstatic=new ExpenseReport($db);
196  $userstatic=new User($db);
197  while ($i < $num && $i < $max)
198  {
199  $obj = $db->fetch_object($result);
200  $expensereportstatic->id=$obj->rowid;
201  $expensereportstatic->ref=$obj->ref;
202  $userstatic->id=$obj->uid;
203  $userstatic->lastname=$obj->lastname;
204  $userstatic->firstname=$obj->firstname;
205  $userstatic->login=$obj->login;
206  $userstatic->statut=$obj->statut;
207  $userstatic->photo=$obj->photo;
208  print '<tr class="oddeven">';
209  print '<td>'.$expensereportstatic->getNomUrl(1).'</td>';
210  print '<td>'.$userstatic->getNomUrl(-1).'</td>';
211  print '<td align="right">'.price($obj->total_ht).'</td>';
212  print '<td align="right">'.price($obj->total_ttc).'</td>';
213  print '<td align="right">'.dol_print_date($db->jdate($obj->dm),'day').'</td>';
214  print '<td align="right">';
215  //print $obj->libelle;
216  print $expensereportstatic->LibStatut($obj->fk_status,3);
217  print '</td>';
218  print '</tr>';
219 
220  $i++;
221  }
222  }
223  else
224  {
225  print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
226  }
227  print '</table><br>';
228 }
229 else dol_print_error($db);
230 
231 print '</div></div></div>';
232 
233 // End of page
234 llxFooter();
235 $db->close();
llxFooter()
Footer empty.
Definition: index.php:44
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
Class to manage Dolibarr users.
Definition: user.class.php:41
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:36
Class to manage Trips and Expenses.
Class to build graphs.
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.