dolibarr 21.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@inodbox.com>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
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 <https://www.gnu.org/licenses/>.
20 */
21
27// Load Dolibarr environment
28require '../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
30require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
31
40// Load translation files required by the page
41$langs->loadLangs(array('companies', 'users', 'trips'));
42
43// Security check
44$socid = GETPOSTINT('socid');
45if ($user->socid) {
46 $socid = $user->socid;
47}
48$result = restrictedArea($user, 'deplacement', '', '');
49
50$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
51$sortfield = GETPOST('sortfield', 'aZ09comma');
52$sortorder = GETPOST('sortorder', 'aZ09comma');
53$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
54if (empty($page) || $page == -1) {
55 $page = 0;
56} // If $page is not defined, or '' or -1
57$offset = $limit * $page;
58$pageprev = $page - 1;
59$pagenext = $page + 1;
60if (!$sortorder) {
61 $sortorder = "DESC";
62}
63if (!$sortfield) {
64 $sortfield = "d.dated";
65}
66$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
67
68
69/*
70 * View
71 */
72
73$tripandexpense_static = new Deplacement($db);
74
75$childids = $user->getAllChildIds();
76$childids[] = $user->id;
77
78//$help_url='EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones';
79$help_url = '';
80llxHeader('', $langs->trans("TripsAndExpenses"), $help_url);
81
82
83
84$totalnb = 0;
85$sql = "SELECT count(d.rowid) as nb, sum(d.km) as km, d.type";
86$sql .= " FROM ".MAIN_DB_PREFIX."deplacement as d";
87$sql .= " WHERE d.entity = ".$conf->entity;
88if (!$user->hasRight('deplacement', 'readall') && !$user->hasRight('deplacement', 'lire_tous')) {
89 $sql .= ' AND d.fk_user IN ('.$db->sanitize(implode(',', $childids)).')';
90}
91$sql .= " GROUP BY d.type";
92$sql .= " ORDER BY d.type";
93
94$result = $db->query($sql);
95$somme = array();
96$nb = array();
97if ($result) {
98 $num = $db->num_rows($result);
99 $i = 0;
100 while ($i < $num) {
101 $objp = $db->fetch_object($result);
102
103 $somme[$objp->type] = $objp->km;
104 $nb[$objp->type] = $objp->nb;
105 $totalnb += $objp->nb;
106 $i++;
107 }
108 $db->free($result);
109} else {
110 dol_print_error($db);
111}
112
113
114print load_fiche_titre($langs->trans("ExpensesArea"));
115
116
117print '<div class="fichecenter"><div class="fichethirdleft">';
118
119
120// Statistics
121print '<table class="noborder nohover centpercent">';
122print '<tr class="liste_titre">';
123print '<td colspan="4">'.$langs->trans("Statistics").'</td>';
124print "</tr>\n";
125
126$listoftype = $tripandexpense_static->listOfTypes();
127$dataseries = array();
128foreach ($listoftype as $code => $label) {
129 $dataseries[] = array($label, (isset($nb[$code]) ? (int) $nb[$code] : 0));
130}
131
132if ($conf->use_javascript_ajax) {
133 print '<tr><td align="center" colspan="4">';
134
135 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
136 $dolgraph = new DolGraph();
137 $dolgraph->SetData($dataseries);
138 $dolgraph->setShowLegend(2);
139 $dolgraph->setShowPercent(1);
140 $dolgraph->SetType(array('pie'));
141 $dolgraph->setHeight('200');
142 $dolgraph->draw('idgraphstatus');
143 print $dolgraph->show($totalnb ? 0 : 1);
144
145 print '</td></tr>';
146}
147
148print '<tr class="liste_total">';
149print '<td>'.$langs->trans("Total").'</td>';
150print '<td class="right">'.$totalnb.'</td>';
151print '</tr>';
152
153print '</table>';
154
155
156
157print '</div><div class="fichetwothirdright">';
158
159
160$max = 10;
161
162$langs->load("boxes");
163
164$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";
165$sql .= " FROM ".MAIN_DB_PREFIX."deplacement as d, ".MAIN_DB_PREFIX."user as u";
166$sql .= " WHERE u.rowid = d.fk_user";
167$sql .= " AND d.entity = ".$conf->entity;
168if (!$user->hasRight('deplacement', 'readall') && !$user->hasRight('deplacement', 'lire_tous')) {
169 $sql .= ' AND d.fk_user IN ('.$db->sanitize(implode(',', $childids)).')';
170}
171// If the internal user must only see his customers, force searching by him
172$search_sale = 0;
173if (!$user->hasRight('societe', 'client', 'voir')) {
174 $search_sale = $user->id;
175}
176// Search on sale representative
177if ($search_sale && $search_sale != '-1') {
178 if ($search_sale == -2) {
179 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = d.fk_soc)";
180 } elseif ($search_sale > 0) {
181 $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).")";
182 }
183}
184// Search on socid
185if ($socid) {
186 $sql .= " AND d.fk_soc = ".((int) $socid);
187}
188$sql .= $db->order("d.tms", "DESC");
189$sql .= $db->plimit($max, 0);
190
191$result = $db->query($sql);
192if ($result) {
193 $var = false;
194 $num = $db->num_rows($result);
195
196 $i = 0;
197
198 print '<table class="noborder centpercent">';
199 print '<tr class="liste_titre">';
200 print '<td colspan="2">'.$langs->trans("BoxTitleLastModifiedExpenses", min($max, $num)).'</td>';
201 print '<td class="right">'.$langs->trans("FeesKilometersOrAmout").'</td>';
202 print '<td class="right">'.$langs->trans("DateModificationShort").'</td>';
203 print '<td width="16">&nbsp;</td>';
204 print '</tr>';
205 if ($num) {
206 $total_ttc = $totalam = $total = 0;
207
208 $deplacementstatic = new Deplacement($db);
209 $userstatic = new User($db);
210 while ($i < $num && $i < $max) {
211 $obj = $db->fetch_object($result);
212 $deplacementstatic->ref = $obj->rowid;
213 $deplacementstatic->id = $obj->rowid;
214 $userstatic->id = $obj->uid;
215 $userstatic->lastname = $obj->lastname;
216 $userstatic->firstname = $obj->firstname;
217 print '<tr class="oddeven">';
218 print '<td>'.$deplacementstatic->getNomUrl(1).'</td>';
219 print '<td>'.$userstatic->getNomUrl(1).'</td>';
220 print '<td class="right">'.$obj->km.'</td>';
221 print '<td class="right">'.dol_print_date($db->jdate($obj->dm), 'day').'</td>';
222 print '<td>'.$deplacementstatic->LibStatut($obj->fk_statut, 3).'</td>';
223 print '</tr>';
224
225 $i++;
226 }
227 } else {
228 print '<tr class="oddeven"><td colspan="2" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
229 }
230 print '</table><br>';
231} else {
232 dol_print_error($db);
233}
234
235
236print '</div></div>';
237
238// End of page
239llxFooter();
240$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage trips and working credit notes.
Class to build graphs.
Class to manage Dolibarr users.
llxFooter()
Footer empty.
Definition document.php:107
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.