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  *
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 <http://www.gnu.org/licenses/>.
19  */
20 
26 require '../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
29 
30 // Load translation files required by the page
31 $langs->loadLangs(array('companies', 'users', 'trips'));
32 
33 // Security check
34 $socid = GETPOST('socid','int');
35 if ($user->societe_id) $socid=$user->societe_id;
36 $result = restrictedArea($user, 'deplacement','','');
37 
38 $sortfield = GETPOST("sortfield",'alpha');
39 $sortorder = GETPOST("sortorder",'alpha');
40 $page = GETPOST("page",'int');
41 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
42 $offset = $conf->liste_limit * $page;
43 $pageprev = $page - 1;
44 $pagenext = $page + 1;
45 if (! $sortorder) $sortorder="DESC";
46 if (! $sortfield) $sortfield="d.dated";
47 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
48 
49 
50 /*
51  * View
52  */
53 
54 $tripandexpense_static=new Deplacement($db);
55 
56 $childids = $user->getAllChildIds();
57 $childids[]=$user->id;
58 
59 //$help_url='EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones';
60 $help_url='';
61 llxHeader('',$langs->trans("ListOfFees"),$help_url);
62 
63 
64 
65 $totalnb=0;
66 $sql = "SELECT count(d.rowid) as nb, sum(d.km) as km, d.type";
67 $sql.= " FROM ".MAIN_DB_PREFIX."deplacement as d";
68 $sql.= " WHERE d.entity = ".$conf->entity;
69 if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) $sql.=' AND d.fk_user IN ('.join(',',$childids).')';
70 $sql.= " GROUP BY d.type";
71 $sql.= " ORDER BY d.type";
72 
73 $result = $db->query($sql);
74 if ($result)
75 {
76  $num = $db->num_rows($result);
77  $i = 0;
78  while ($i < $num)
79  {
80  $objp = $db->fetch_object($result);
81 
82  $somme[$objp->type] = $objp->km;
83  $nb[$objp->type] = $objp->nb;
84  $totalnb += $objp->nb;
85  $i++;
86  }
87  $db->free($result);
88 } else {
89  dol_print_error($db);
90 }
91 
92 
93 print load_fiche_titre($langs->trans("ExpensesArea"));
94 
95 
96 print '<div class="fichecenter"><div class="fichethirdleft">';
97 
98 
99 // Statistics
100 print '<table class="noborder nohover" width="100%">';
101 print '<tr class="liste_titre">';
102 print '<td colspan="4">'.$langs->trans("Statistics").'</td>';
103 print "</tr>\n";
104 
105 $listoftype=$tripandexpense_static->listOfTypes();
106 foreach ($listoftype as $code => $label)
107 {
108  $dataseries[]=array($label, (isset($nb[$code])?(int) $nb[$code]:0));
109 }
110 
111 if ($conf->use_javascript_ajax)
112 {
113  print '<tr><td align="center" colspan="4">';
114 
115  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
116  $dolgraph = new DolGraph();
117  $dolgraph->SetData($dataseries);
118  $dolgraph->setShowLegend(1);
119  $dolgraph->setShowPercent(1);
120  $dolgraph->SetType(array('pie'));
121  $dolgraph->setWidth('100%');
122  $dolgraph->draw('idgraphstatus');
123  print $dolgraph->show($totalnb?0:1);
124 
125  print '</td></tr>';
126 }
127 
128 print '<tr class="liste_total">';
129 print '<td>'.$langs->trans("Total").'</td>';
130 print '<td align="right">'.$totalnb.'</td>';
131 print '</tr>';
132 
133 print '</table>';
134 
135 
136 
137 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
138 
139 
140 $max=10;
141 
142 $langs->load("boxes");
143 
144 $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, d.rowid, d.dated as date, d.tms as dm, d.km, d.fk_statut";
145 $sql.= " FROM ".MAIN_DB_PREFIX."deplacement as d, ".MAIN_DB_PREFIX."user as u";
146 if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
147 $sql.= " WHERE u.rowid = d.fk_user";
148 $sql.= " AND d.entity = ".$conf->entity;
149 if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) $sql.=' AND d.fk_user IN ('.join(',',$childids).')';
150 if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND d.fk_soc = s. rowid AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
151 if ($socid) $sql.= " AND d.fk_soc = ".$socid;
152 $sql.= $db->order("d.tms","DESC");
153 $sql.= $db->plimit($max, 0);
154 
155 $result = $db->query($sql);
156 if ($result)
157 {
158  $var=false;
159  $num = $db->num_rows($result);
160 
161  $i = 0;
162 
163  print '<table class="noborder" width="100%">';
164  print '<tr class="liste_titre">';
165  print '<td colspan="2">'.$langs->trans("BoxTitleLastModifiedExpenses",min($max,$num)).'</td>';
166  print '<td align="right">'.$langs->trans("FeesKilometersOrAmout").'</td>';
167  print '<td align="right">'.$langs->trans("DateModificationShort").'</td>';
168  print '<td width="16">&nbsp;</td>';
169  print '</tr>';
170  if ($num)
171  {
172  $total_ttc = $totalam = $total = 0;
173 
174  $deplacementstatic=new Deplacement($db);
175  $userstatic=new User($db);
176  while ($i < $num && $i < $max)
177  {
178  $obj = $db->fetch_object($result);
179  $deplacementstatic->ref=$obj->rowid;
180  $deplacementstatic->id=$obj->rowid;
181  $userstatic->id=$obj->uid;
182  $userstatic->lastname=$obj->lastname;
183  $userstatic->firstname=$obj->firstname;
184  print '<tr class="oddeven">';
185  print '<td>'.$deplacementstatic->getNomUrl(1).'</td>';
186  print '<td>'.$userstatic->getNomUrl(1).'</td>';
187  print '<td align="right">'.$obj->km.'</td>';
188  print '<td align="right">'.dol_print_date($db->jdate($obj->dm),'day').'</td>';
189  print '<td>'.$deplacementstatic->LibStatut($obj->fk_statut,3).'</td>';
190  print '</tr>';
191 
192  $i++;
193  }
194  }
195  else
196  {
197  print '<tr class="oddeven"><td colspan="2" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
198  }
199  print '</table><br>';
200 }
201 else dol_print_error($db);
202 
203 
204 print '</div></div></div>';
205 
206 // End of page
207 llxFooter();
208 $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 trips and working credit notes.
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 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.