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