dolibarr  19.0.0-dev
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
27 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
29 require_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');
36 if ($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');
45 if (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;
51 if (!$sortorder) {
52  $sortorder = "DESC";
53 }
54 if (!$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 = '';
71 llxHeader('', $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;
79 if (empty($user->rights->deplacement->readall) && empty($user->rights->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);
86 if ($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 
103 print load_fiche_titre($langs->trans("ExpensesArea"));
104 
105 
106 print '<div class="fichecenter"><div class="fichethirdleft">';
107 
108 
109 // Statistics
110 print '<table class="noborder nohover centpercent">';
111 print '<tr class="liste_titre">';
112 print '<td colspan="4">'.$langs->trans("Statistics").'</td>';
113 print "</tr>\n";
114 
115 $listoftype = $tripandexpense_static->listOfTypes();
116 foreach ($listoftype as $code => $label) {
117  $dataseries[] = array($label, (isset($nb[$code]) ? (int) $nb[$code] : 0));
118 }
119 
120 if ($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 
136 print '<tr class="liste_total">';
137 print '<td>'.$langs->trans("Total").'</td>';
138 print '<td class="right">'.$totalnb.'</td>';
139 print '</tr>';
140 
141 print '</table>';
142 
143 
144 
145 print '</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";
154 if (empty($user->rights->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;
159 if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) {
160  $sql .= ' AND d.fk_user IN ('.$db->sanitize(join(',', $childids)).')';
161 }
162 if (empty($user->rights->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 }
165 if ($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);
172 if ($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 
216 print '</div></div>';
217 
218 // End of page
219 llxFooter();
220 $db->close();
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:118
Class to manage trips and working credit notes.
Class to build graphs.
Class to manage Dolibarr users.
Definition: user.class.php:48
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
llxFooter()
Footer empty.
Definition: index.php:71
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
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.