dolibarr 21.0.0-beta
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
29// Load Dolibarr environment
30require '../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
32require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
35
45// Load translation files required by the page
46$langs->loadLangs(array('companies', 'users', 'trips'));
47
48// Security check
49$socid = GETPOSTINT('socid');
50if ($user->socid) {
51 $socid = $user->socid;
52}
53$result = restrictedArea($user, 'deplacement', '', '');
54
55$search_ref = GETPOST('search_ref', 'alpha');
56$search_name = GETPOST('search_name', 'alpha');
57$search_company = GETPOST('search_company', 'alpha');
58// $search_amount=GETPOST('search_amount','alpha');
59$sortfield = GETPOST('sortfield', 'aZ09comma');
60$sortorder = GETPOST('sortorder', 'aZ09comma');
61$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
62$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
63if (empty($page) || $page == -1) {
64 $page = 0;
65} // If $page is not defined, or '' or -1
66$offset = $limit * $page;
67$pageprev = $page - 1;
68$pagenext = $page + 1;
69if (!$sortorder) {
70 $sortorder = "DESC";
71}
72if (!$sortfield) {
73 $sortfield = "d.dated";
74}
75
76$year = GETPOST("year");
77$month = GETPOST("month");
78$day = GETPOST("day");
79
80if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
81 $search_ref = "";
82 $search_name = "";
83 $search_company = "";
84 // $search_amount="";
85 $year = "";
86 $month = "";
87 $day = "";
88}
89
90/*
91 * View
92 */
93
94$formother = new FormOther($db);
95$tripandexpense_static = new Deplacement($db);
96$userstatic = new User($db);
97
98$childids = $user->getAllChildIds();
99$childids[] = $user->id;
100
101llxHeader();
102
103$sql = "SELECT s.nom, d.fk_user, s.rowid as socid,"; // Ou
104$sql .= " d.rowid, d.type, d.dated as dd, d.km,"; // Comment
105$sql .= " d.fk_statut,";
106$sql .= " u.lastname, u.firstname"; // Qui
107$sql .= " FROM ".MAIN_DB_PREFIX."user as u";
108$sql .= ", ".MAIN_DB_PREFIX."deplacement as d";
109$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON d.fk_soc = s.rowid";
110$sql .= " WHERE d.fk_user = u.rowid";
111$sql .= " AND d.entity = ".$conf->entity;
112if (!$user->hasRight('deplacement', 'readall') && !$user->hasRight('deplacement', 'lire_tous')) {
113 $sql .= ' AND d.fk_user IN ('.$db->sanitize(implode(',', $childids)).')';
114}
115// If the internal user must only see his customers, force searching by him
116$search_sale = 0;
117if (!$user->hasRight('societe', 'client', 'voir')) {
118 $search_sale = $user->id;
119}
120// Search on sale representative
121if ($search_sale && $search_sale != '-1') {
122 if ($search_sale == -2) {
123 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = d.fk_soc)";
124 } elseif ($search_sale > 0) {
125 $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).")";
126 }
127}
128// Search on socid
129if ($socid) {
130 $sql .= " AND d.fk_soc = ".((int) $socid);
131}
132
133if ($search_ref) {
134 $sql .= " AND d.rowid = ".((int) $search_ref);
135}
136if ($search_name) {
137 $sql .= natural_search('u.lastname', $search_name);
138}
139if ($search_company) {
140 $sql .= natural_search('s.nom', $search_company);
141}
142$sql .= dolSqlDateFilter("d.dated", $day, $month, $year);
143
144$sql .= $db->order($sortfield, $sortorder);
145$sql .= $db->plimit($limit + 1, $offset);
146
147//print $sql;
148$resql = $db->query($sql);
149if ($resql) {
150 $num = $db->num_rows($resql);
151
152 print_barre_liste($langs->trans("TripsAndExpenses"), $page, $_SERVER["PHP_SELF"], "&socid=$socid", $sortfield, $sortorder, '', $num);
153
154 $i = 0;
155 print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">'."\n";
156 print '<table class="noborder centpercent">';
157 print "<tr class=\"liste_titre\">";
158 print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "d.rowid", "", "&socid=$socid", '', $sortfield, $sortorder);
159 print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "d.type", "", "&socid=$socid", '', $sortfield, $sortorder);
160 print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "d.dated", "", "&socid=$socid", 'align="center"', $sortfield, $sortorder);
161 print_liste_field_titre("Person", $_SERVER["PHP_SELF"], "u.lastname", "", "&socid=$socid", '', $sortfield, $sortorder);
162 print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "&socid=$socid", '', $sortfield, $sortorder);
163 print_liste_field_titre("FeesKilometersOrAmout", $_SERVER["PHP_SELF"], "d.km", "", "&socid=$socid", 'class="right"', $sortfield, $sortorder);
165 print "</tr>\n";
166
167 // Filters lines
168 print '<tr class="liste_titre">';
169 print '<td class="liste_titre">';
170 print '<input class="flat" size="4" type="text" name="search_ref" value="'.$search_ref.'">';
171 print '</td>';
172 print '<td class="liste_titre">';
173 print '&nbsp;';
174 print '</td>';
175 print '<td class="liste_titre" align="center">';
176 if (getDolGlobalString('MAIN_LIST_FILTER_ON_DAY')) {
177 print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
178 }
179 print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
180 print $formother->selectyear($year ? $year : -1, 'year', 1, 20, 5);
181 print '</td>';
182 print '<td class="liste_titre">';
183 print '<input class="flat" size="10" type="text" name="search_name" value="'.$search_name.'">';
184 print '</td>';
185 print '<td class="liste_titre">';
186 print '<input class="flat" size="10" type="text" name="search_company" value="'.$search_company.'">';
187 print '</td>';
188 print '<td class="liste_titre right">';
189 // print '<input class="flat" size="10" type="text" name="search_amount" value="'.$search_amount.'">';
190 print '</td>';
191 print '<td class="liste_titre maxwidthsearch">';
192 $searchpicto = $form->showFilterAndCheckAddButtons(0);
193 print $searchpicto;
194 print '</td>';
195 print "</tr>\n";
196
197 while ($i < min($num, $limit)) {
198 $obj = $db->fetch_object($resql);
199
200 $soc = new Societe($db);
201 if ($obj->socid) {
202 $soc->fetch($obj->socid);
203 }
204
205 print '<tr class="oddeven">';
206 // Id
207 print '<td><a href="card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowTrip"), "trip").' '.$obj->rowid.'</a></td>';
208 // Type
209 print '<td>'.$langs->trans($obj->type).'</td>';
210 // Date
211 print '<td class="center">'.dol_print_date($db->jdate($obj->dd), 'day').'</td>';
212 // User
213 print '<td>';
214 $userstatic->id = $obj->fk_user;
215 $userstatic->lastname = $obj->lastname;
216 $userstatic->firstname = $obj->firstname;
217 print $userstatic->getNomUrl(1);
218 print '</td>';
219
220 if ($obj->socid) {
221 print '<td>'.$soc->getNomUrl(1).'</td>';
222 } else {
223 print '<td>&nbsp;</td>';
224 }
225
226 print '<td class="right">'.$obj->km.'</td>';
227
228 $tripandexpense_static->statut = $obj->fk_statut;
229 print '<td class="right">'.$tripandexpense_static->getLibStatut(5).'</td>';
230 print "</tr>\n";
231
232 $i++;
233 }
234
235 print "</table>";
236 print "</form>\n";
237 $db->free($resql);
238} else {
239 dol_print_error($db);
240}
241
242// End of page
243llxFooter();
244$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 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:382
llxFooter()
Footer empty.
Definition document.php:107
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.