dolibarr  7.0.0-beta
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@capnetworks.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 $langs->load("companies");
34 $langs->load("users");
35 $langs->load("trips");
36 
37 // Security check
38 $socid = GETPOST('socid','int');
39 if ($user->societe_id) $socid=$user->societe_id;
40 $result = restrictedArea($user, 'expensereport','','');
41 
42 $sortfield = GETPOST("sortfield",'alpha');
43 $sortorder = GETPOST("sortorder",'alpha');
44 $page = GETPOST("page",'int');
45 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
46 $offset = $conf->liste_limit * $page;
47 $pageprev = $page - 1;
48 $pagenext = $page + 1;
49 if (! $sortorder) $sortorder="DESC";
50 if (! $sortfield) $sortfield="d.date_create";
51 $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
52 
53 
54 /*
55  * View
56  */
57 
58 $tripandexpense_static=new ExpenseReport($db);
59 
60 $childids = $user->getAllChildIds();
61 $childids[]=$user->id;
62 
63 //$help_url='EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones';
64 $help_url='';
65 llxHeader('',$langs->trans("ListOfFees"),$help_url);
66 
67 
68 $label=$somme=$nb=array();
69 
70 $totalnb=$totalsum=0;
71 $sql = "SELECT tf.code, tf.label, count(de.rowid) as nb, sum(de.total_ht) as km";
72 $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as d, ".MAIN_DB_PREFIX."expensereport_det as de, ".MAIN_DB_PREFIX."c_type_fees as tf";
73 $sql.= " WHERE de.fk_expensereport = d.rowid AND d.entity IN (".getEntity('expensereport').") AND de.fk_c_type_fees = tf.id";
74 // RESTRICT RIGHTS
75 if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)
76  && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance)))
77 {
78  $childids = $user->getAllChildIds();
79  $childids[]=$user->id;
80  $sql.= " AND d.fk_user_author IN (".join(',',$childids).")\n";
81 }
82 
83 $sql.= " GROUP BY tf.code, tf.label";
84 
85 $result = $db->query($sql);
86 if ($result)
87 {
88  $num = $db->num_rows($result);
89  $i = 0;
90  while ($i < $num)
91  {
92  $objp = $db->fetch_object($result);
93 
94  $somme[$objp->code] = $objp->km;
95  $nb[$objp->code] = $objp->nb;
96  $label[$objp->code] = $objp->label;
97  $totalnb += $objp->nb;
98  $totalsum += $objp->km;
99  $i++;
100  }
101  $db->free($result);
102 } else {
103  dol_print_error($db);
104 }
105 
106 
107 print load_fiche_titre($langs->trans("ExpensesArea"));
108 
109 
110 print '<div class="fichecenter"><div class="fichethirdleft">';
111 
112 
113 print '<table class="noborder nohover" width="100%">';
114 print '<tr class="liste_titre">';
115 print '<th colspan="4">'.$langs->trans("Statistics").'</th>';
116 print "</tr>\n";
117 
118 $listoftype=$tripandexpense_static->listOfTypes();
119 foreach ($listoftype as $code => $label)
120 {
121  $dataseries[]=array($label, (isset($somme[$code])?(int) $somme[$code]:0));
122 }
123 
124 if ($conf->use_javascript_ajax)
125 {
126  print '<tr><td align="center" colspan="4">';
127 
128  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
129  $dolgraph = new DolGraph();
130  $dolgraph->SetData($dataseries);
131  $dolgraph->setShowLegend(1);
132  $dolgraph->setShowPercent(1);
133  $dolgraph->SetType(array('pie'));
134  $dolgraph->setWidth('100%');
135  $dolgraph->draw('idgraphstatus');
136  print $dolgraph->show($totalnb?0:1);
137 
138  print '</td></tr>';
139 }
140 
141 print '<tr class="liste_total">';
142 print '<td>'.$langs->trans("Total").'</td>';
143 print '<td align="right" colspan="3">'.price($totalsum,1,$langs,0,0,0,$conf->currency).'</td>';
144 print '</tr>';
145 
146 print '</table>';
147 
148 
149 
150 // Right area
151 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
152 
153 
154 $max=10;
155 
156 $langs->load("boxes");
157 
158 $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";
159 $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as d, ".MAIN_DB_PREFIX."user as u";
160 if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
161 $sql.= " WHERE u.rowid = d.fk_user_author";
162 // RESTRICT RIGHTS
163 if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)
164  && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance)))
165 {
166  $childids = $user->getAllChildIds();
167  $childids[]=$user->id;
168  $sql.= " AND d.fk_user_author IN (".join(',',$childids).")\n";
169 }
170 $sql.= ' AND d.entity IN ('.getEntity('expensereport').')';
171 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;
172 if ($socid) $sql.= " AND d.fk_user_author = ".$socid;
173 $sql.= $db->order($sortfield,$sortorder);
174 $sql.= $db->plimit($max, 0);
175 
176 $result = $db->query($sql);
177 if ($result)
178 {
179  $var=false;
180  $num = $db->num_rows($result);
181 
182  $i = 0;
183 
184  print '<table class="noborder" width="100%">';
185  print '<tr class="liste_titre">';
186  print '<th colspan="2">'.$langs->trans("BoxTitleLastModifiedExpenses",min($max,$num)).'</th>';
187  print '<th align="right">'.$langs->trans("AmountHT").'</th>';
188  print '<th align="right">'.$langs->trans("AmountTTC").'</th>';
189  print '<th align="right">'.$langs->trans("DateModificationShort").'</th>';
190  print '<th>&nbsp;</th>';
191  print '</tr>';
192  if ($num)
193  {
194  $total_ttc = $totalam = $total = 0;
195 
196  $expensereportstatic=new ExpenseReport($db);
197  $userstatic=new User($db);
198  while ($i < $num && $i < $max)
199  {
200  $obj = $db->fetch_object($result);
201  $expensereportstatic->id=$obj->rowid;
202  $expensereportstatic->ref=$obj->ref;
203  $userstatic->id=$obj->uid;
204  $userstatic->lastname=$obj->lastname;
205  $userstatic->firstname=$obj->firstname;
206  $userstatic->login=$obj->login;
207  $userstatic->statut=$obj->statut;
208  $userstatic->photo=$obj->photo;
209  print '<tr class="oddeven">';
210  print '<td>'.$expensereportstatic->getNomUrl(1).'</td>';
211  print '<td>'.$userstatic->getNomUrl(-1).'</td>';
212  print '<td align="right">'.price($obj->total_ht).'</td>';
213  print '<td align="right">'.price($obj->total_ttc).'</td>';
214  print '<td align="right">'.dol_print_date($db->jdate($obj->dm),'day').'</td>';
215  print '<td align="right">';
216  //print $obj->libelle;
217  print $expensereportstatic->LibStatut($obj->fk_status,3);
218  print '</td>';
219  print '</tr>';
220 
221  $i++;
222  }
223 
224  }
225  else
226  {
227  print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
228  }
229  print '</table><br>';
230 }
231 else dol_print_error($db);
232 
233 print '</div></div></div>';
234 
235 llxFooter();
236 
237 $db->close();
llxFooter()
Footer empty.
Definition: index.php:43
Class to manage Dolibarr users.
Definition: user.class.php:39
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
Class to manage Trips and Expenses.
print
Draft customers invoices.
Definition: index.php:91
Class to build graphs.
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.