dolibarr  13.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 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) $socid = $user->socid;
36 $result = restrictedArea($user, 'deplacement', '', '');
37 
38 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
39 $sortfield = GETPOST("sortfield", 'alpha');
40 $sortorder = GETPOST("sortorder", 'alpha');
41 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
42 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
43 $offset = $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', 'int') ?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 centpercent">';
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(2);
120  $dolgraph->setShowPercent(1);
121  $dolgraph->SetType(array('pie'));
122  $dolgraph->setHeight('200');
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 class="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->socid) $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->socid) $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 centpercent">';
165  print '<tr class="liste_titre">';
166  print '<td colspan="2">'.$langs->trans("BoxTitleLastModifiedExpenses", min($max, $num)).'</td>';
167  print '<td class="right">'.$langs->trans("FeesKilometersOrAmout").'</td>';
168  print '<td class="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 class="right">'.$obj->km.'</td>';
189  print '<td class="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  } else {
196  print '<tr class="oddeven"><td colspan="2" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
197  }
198  print '</table><br>';
199 } else dol_print_error($db);
200 
201 
202 print '</div></div></div>';
203 
204 // End of page
205 llxFooter();
206 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage trips and working credit notes.
Class to manage Dolibarr users.
Definition: user.class.php:44
llxHeader()
Empty header.
Definition: wrapper.php:45
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
print
Draft customers invoices.
Definition: index.php:89
Class to build graphs.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
llxFooter()
Empty footer.
Definition: wrapper.php:59