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