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