dolibarr 20.0.2
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 = GETPOSTINT('socid');
36if ($user->socid) {
37 $socid = $user->socid;
38}
39$result = restrictedArea($user, 'deplacement', '', '');
40
41$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
42$sortfield = GETPOST('sortfield', 'aZ09comma');
43$sortorder = GETPOST('sortorder', 'aZ09comma');
44$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
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 = GETPOSTINT('limit') ? GETPOSTINT('limit') : $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(implode(',', $childids)).')';
81}
82$sql .= " GROUP BY d.type";
83$sql .= " ORDER BY d.type";
84
85$result = $db->query($sql);
86$somme = array();
87$nb = array();
88if ($result) {
89 $num = $db->num_rows($result);
90 $i = 0;
91 while ($i < $num) {
92 $objp = $db->fetch_object($result);
93
94 $somme[$objp->type] = $objp->km;
95 $nb[$objp->type] = $objp->nb;
96 $totalnb += $objp->nb;
97 $i++;
98 }
99 $db->free($result);
100} else {
101 dol_print_error($db);
102}
103
104
105print load_fiche_titre($langs->trans("ExpensesArea"));
106
107
108print '<div class="fichecenter"><div class="fichethirdleft">';
109
110
111// Statistics
112print '<table class="noborder nohover centpercent">';
113print '<tr class="liste_titre">';
114print '<td colspan="4">'.$langs->trans("Statistics").'</td>';
115print "</tr>\n";
116
117$listoftype = $tripandexpense_static->listOfTypes();
118$dataseries = array();
119foreach ($listoftype as $code => $label) {
120 $dataseries[] = array($label, (isset($nb[$code]) ? (int) $nb[$code] : 0));
121}
122
123if ($conf->use_javascript_ajax) {
124 print '<tr><td align="center" colspan="4">';
125
126 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
127 $dolgraph = new DolGraph();
128 $dolgraph->SetData($dataseries);
129 $dolgraph->setShowLegend(2);
130 $dolgraph->setShowPercent(1);
131 $dolgraph->SetType(array('pie'));
132 $dolgraph->setHeight('200');
133 $dolgraph->draw('idgraphstatus');
134 print $dolgraph->show($totalnb ? 0 : 1);
135
136 print '</td></tr>';
137}
138
139print '<tr class="liste_total">';
140print '<td>'.$langs->trans("Total").'</td>';
141print '<td class="right">'.$totalnb.'</td>';
142print '</tr>';
143
144print '</table>';
145
146
147
148print '</div><div class="fichetwothirdright">';
149
150
151$max = 10;
152
153$langs->load("boxes");
154
155$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";
156$sql .= " FROM ".MAIN_DB_PREFIX."deplacement as d, ".MAIN_DB_PREFIX."user as u";
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(implode(',', $childids)).')';
161}
162// If the internal user must only see his customers, force searching by him
163$search_sale = 0;
164if (!$user->hasRight('societe', 'client', 'voir')) {
165 $search_sale = $user->id;
166}
167// Search on sale representative
168if ($search_sale && $search_sale != '-1') {
169 if ($search_sale == -2) {
170 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = d.fk_soc)";
171 } elseif ($search_sale > 0) {
172 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = d.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
173 }
174}
175// Search on socid
176if ($socid) {
177 $sql .= " AND d.fk_soc = ".((int) $socid);
178}
179$sql .= $db->order("d.tms", "DESC");
180$sql .= $db->plimit($max, 0);
181
182$result = $db->query($sql);
183if ($result) {
184 $var = false;
185 $num = $db->num_rows($result);
186
187 $i = 0;
188
189 print '<table class="noborder centpercent">';
190 print '<tr class="liste_titre">';
191 print '<td colspan="2">'.$langs->trans("BoxTitleLastModifiedExpenses", min($max, $num)).'</td>';
192 print '<td class="right">'.$langs->trans("FeesKilometersOrAmout").'</td>';
193 print '<td class="right">'.$langs->trans("DateModificationShort").'</td>';
194 print '<td width="16">&nbsp;</td>';
195 print '</tr>';
196 if ($num) {
197 $total_ttc = $totalam = $total = 0;
198
199 $deplacementstatic = new Deplacement($db);
200 $userstatic = new User($db);
201 while ($i < $num && $i < $max) {
202 $obj = $db->fetch_object($result);
203 $deplacementstatic->ref = $obj->rowid;
204 $deplacementstatic->id = $obj->rowid;
205 $userstatic->id = $obj->uid;
206 $userstatic->lastname = $obj->lastname;
207 $userstatic->firstname = $obj->firstname;
208 print '<tr class="oddeven">';
209 print '<td>'.$deplacementstatic->getNomUrl(1).'</td>';
210 print '<td>'.$userstatic->getNomUrl(1).'</td>';
211 print '<td class="right">'.$obj->km.'</td>';
212 print '<td class="right">'.dol_print_date($db->jdate($obj->dm), 'day').'</td>';
213 print '<td>'.$deplacementstatic->LibStatut($obj->fk_statut, 3).'</td>';
214 print '</tr>';
215
216 $i++;
217 }
218 } else {
219 print '<tr class="oddeven"><td colspan="2" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
220 }
221 print '</table><br>';
222} else {
223 dol_print_error($db);
224}
225
226
227print '</div></div>';
228
229// End of page
230llxFooter();
231$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($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.