dolibarr 19.0.3
list.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2012 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) 2012 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2018 charlene Benke <charlie@patas-monkey.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
28// Load Dolibarr environment
29require '../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
31require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
34
35// Load translation files required by the page
36$langs->loadLangs(array('companies', 'users', 'trips'));
37
38// Security check
39$socid = GETPOST('socid', 'int');
40if ($user->socid) {
41 $socid = $user->socid;
42}
43$result = restrictedArea($user, 'deplacement', '', '');
44
45$search_ref = GETPOST('search_ref', 'int');
46$search_name = GETPOST('search_name', 'alpha');
47$search_company = GETPOST('search_company', 'alpha');
48// $search_amount=GETPOST('search_amount','alpha');
49$sortfield = GETPOST('sortfield', 'aZ09comma');
50$sortorder = GETPOST('sortorder', 'aZ09comma');
51$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
52$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
53if (empty($page) || $page == -1) {
54 $page = 0;
55} // If $page is not defined, or '' or -1
56$offset = $limit * $page;
57$pageprev = $page - 1;
58$pagenext = $page + 1;
59if (!$sortorder) {
60 $sortorder = "DESC";
61}
62if (!$sortfield) {
63 $sortfield = "d.dated";
64}
65
66$year = GETPOST("year");
67$month = GETPOST("month");
68$day = GETPOST("day");
69
70if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
71 $search_ref = "";
72 $search_name = "";
73 $search_company = "";
74 // $search_amount="";
75 $year = "";
76 $month = "";
77 $day = "";
78}
79
80/*
81 * View
82 */
83
84$formother = new FormOther($db);
85$tripandexpense_static = new Deplacement($db);
86$userstatic = new User($db);
87
88$childids = $user->getAllChildIds();
89$childids[] = $user->id;
90
91llxHeader();
92
93$sql = "SELECT s.nom, d.fk_user, s.rowid as socid,"; // Ou
94$sql .= " d.rowid, d.type, d.dated as dd, d.km,"; // Comment
95$sql .= " d.fk_statut,";
96$sql .= " u.lastname, u.firstname"; // Qui
97$sql .= " FROM ".MAIN_DB_PREFIX."user as u";
98$sql .= ", ".MAIN_DB_PREFIX."deplacement as d";
99$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON d.fk_soc = s.rowid";
100if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
101 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
102}
103$sql .= " WHERE d.fk_user = u.rowid";
104$sql .= " AND d.entity = ".$conf->entity;
105if (!$user->hasRight('deplacement', 'readall') && !$user->hasRight('deplacement', 'lire_tous')) {
106 $sql .= ' AND d.fk_user IN ('.$db->sanitize(join(',', $childids)).')';
107}
108if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
109 $sql .= " AND (sc.fk_user = ".((int) $user->id)." OR d.fk_soc IS NULL) ";
110}
111if ($socid) {
112 $sql .= " AND s.rowid = ".((int) $socid);
113}
114
115if ($search_ref) {
116 $sql .= " AND d.rowid = ".((int) $search_ref);
117}
118if ($search_name) {
119 $sql .= natural_search('u.lastname', $search_name);
120}
121if ($search_company) {
122 $sql .= natural_search('s.nom', $search_company);
123}
124$sql .= dolSqlDateFilter("d.dated", $day, $month, $year);
125
126$sql .= $db->order($sortfield, $sortorder);
127$sql .= $db->plimit($limit + 1, $offset);
128
129//print $sql;
130$resql = $db->query($sql);
131if ($resql) {
132 $num = $db->num_rows($resql);
133
134 print_barre_liste($langs->trans("TripsAndExpenses"), $page, $_SERVER["PHP_SELF"], "&socid=$socid", $sortfield, $sortorder, '', $num);
135
136 $i = 0;
137 print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">'."\n";
138 print '<table class="noborder centpercent">';
139 print "<tr class=\"liste_titre\">";
140 print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "d.rowid", "", "&socid=$socid", '', $sortfield, $sortorder);
141 print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "d.type", "", "&socid=$socid", '', $sortfield, $sortorder);
142 print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "d.dated", "", "&socid=$socid", 'align="center"', $sortfield, $sortorder);
143 print_liste_field_titre("Person", $_SERVER["PHP_SELF"], "u.lastname", "", "&socid=$socid", '', $sortfield, $sortorder);
144 print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "&socid=$socid", '', $sortfield, $sortorder);
145 print_liste_field_titre("FeesKilometersOrAmout", $_SERVER["PHP_SELF"], "d.km", "", "&socid=$socid", 'class="right"', $sortfield, $sortorder);
147 print "</tr>\n";
148
149 // Filters lines
150 print '<tr class="liste_titre">';
151 print '<td class="liste_titre">';
152 print '<input class="flat" size="4" type="text" name="search_ref" value="'.$search_ref.'">';
153 print '</td>';
154 print '<td class="liste_titre">';
155 print '&nbsp;';
156 print '</td>';
157 print '<td class="liste_titre" align="center">';
158 if (getDolGlobalString('MAIN_LIST_FILTER_ON_DAY')) {
159 print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
160 }
161 print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
162 print $formother->selectyear($year ? $year : -1, 'year', 1, 20, 5);
163 print '</td>';
164 print '<td class="liste_titre">';
165 print '<input class="flat" size="10" type="text" name="search_name" value="'.$search_name.'">';
166 print '</td>';
167 print '<td class="liste_titre">';
168 print '<input class="flat" size="10" type="text" name="search_company" value="'.$search_company.'">';
169 print '</td>';
170 print '<td class="liste_titre right">';
171 // print '<input class="flat" size="10" type="text" name="search_amount" value="'.$search_amount.'">';
172 print '</td>';
173 print '<td class="liste_titre maxwidthsearch">';
174 $searchpicto = $form->showFilterAndCheckAddButtons(0);
175 print $searchpicto;
176 print '</td>';
177 print "</tr>\n";
178
179 while ($i < min($num, $limit)) {
180 $obj = $db->fetch_object($resql);
181
182 $soc = new Societe($db);
183 if ($obj->socid) {
184 $soc->fetch($obj->socid);
185 }
186
187 print '<tr class="oddeven">';
188 // Id
189 print '<td><a href="card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowTrip"), "trip").' '.$obj->rowid.'</a></td>';
190 // Type
191 print '<td>'.$langs->trans($obj->type).'</td>';
192 // Date
193 print '<td class="center">'.dol_print_date($db->jdate($obj->dd), 'day').'</td>';
194 // User
195 print '<td>';
196 $userstatic->id = $obj->fk_user;
197 $userstatic->lastname = $obj->lastname;
198 $userstatic->firstname = $obj->firstname;
199 print $userstatic->getNomUrl(1);
200 print '</td>';
201
202 if ($obj->socid) {
203 print '<td>'.$soc->getNomUrl(1).'</td>';
204 } else {
205 print '<td>&nbsp;</td>';
206 }
207
208 print '<td class="right">'.$obj->km.'</td>';
209
210 $tripandexpense_static->statut = $obj->fk_statut;
211 print '<td class="right">'.$tripandexpense_static->getLibStatut(5).'</td>';
212 print "</tr>\n";
213
214 $i++;
215 }
216
217 print "</table>";
218 print "</form>\n";
219 $db->free($resql);
220} else {
221 dol_print_error($db);
222}
223
224// End of page
225llxFooter();
226$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.
Classe permettant la generation de composants html autre Only common components are here.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0, $gm=false)
Generate a SQL string to make a filter into a range (for second of date until last second of date).
Definition date.lib.php:376
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.