dolibarr 20.0.0
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 = GETPOSTINT('socid');
40if ($user->socid) {
41 $socid = $user->socid;
42}
43$result = restrictedArea($user, 'deplacement', '', '');
44
45$search_ref = GETPOST('search_ref', 'alpha');
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') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
52$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $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";
100$sql .= " WHERE d.fk_user = u.rowid";
101$sql .= " AND d.entity = ".$conf->entity;
102if (!$user->hasRight('deplacement', 'readall') && !$user->hasRight('deplacement', 'lire_tous')) {
103 $sql .= ' AND d.fk_user IN ('.$db->sanitize(implode(',', $childids)).')';
104}
105// If the internal user must only see his customers, force searching by him
106$search_sale = 0;
107if (!$user->hasRight('societe', 'client', 'voir')) {
108 $search_sale = $user->id;
109}
110// Search on sale representative
111if ($search_sale && $search_sale != '-1') {
112 if ($search_sale == -2) {
113 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = d.fk_soc)";
114 } elseif ($search_sale > 0) {
115 $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).")";
116 }
117}
118// Search on socid
119if ($socid) {
120 $sql .= " AND d.fk_soc = ".((int) $socid);
121}
122
123if ($search_ref) {
124 $sql .= " AND d.rowid = ".((int) $search_ref);
125}
126if ($search_name) {
127 $sql .= natural_search('u.lastname', $search_name);
128}
129if ($search_company) {
130 $sql .= natural_search('s.nom', $search_company);
131}
132$sql .= dolSqlDateFilter("d.dated", $day, $month, $year);
133
134$sql .= $db->order($sortfield, $sortorder);
135$sql .= $db->plimit($limit + 1, $offset);
136
137//print $sql;
138$resql = $db->query($sql);
139if ($resql) {
140 $num = $db->num_rows($resql);
141
142 print_barre_liste($langs->trans("TripsAndExpenses"), $page, $_SERVER["PHP_SELF"], "&socid=$socid", $sortfield, $sortorder, '', $num);
143
144 $i = 0;
145 print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">'."\n";
146 print '<table class="noborder centpercent">';
147 print "<tr class=\"liste_titre\">";
148 print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "d.rowid", "", "&socid=$socid", '', $sortfield, $sortorder);
149 print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "d.type", "", "&socid=$socid", '', $sortfield, $sortorder);
150 print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "d.dated", "", "&socid=$socid", 'align="center"', $sortfield, $sortorder);
151 print_liste_field_titre("Person", $_SERVER["PHP_SELF"], "u.lastname", "", "&socid=$socid", '', $sortfield, $sortorder);
152 print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "&socid=$socid", '', $sortfield, $sortorder);
153 print_liste_field_titre("FeesKilometersOrAmout", $_SERVER["PHP_SELF"], "d.km", "", "&socid=$socid", 'class="right"', $sortfield, $sortorder);
155 print "</tr>\n";
156
157 // Filters lines
158 print '<tr class="liste_titre">';
159 print '<td class="liste_titre">';
160 print '<input class="flat" size="4" type="text" name="search_ref" value="'.$search_ref.'">';
161 print '</td>';
162 print '<td class="liste_titre">';
163 print '&nbsp;';
164 print '</td>';
165 print '<td class="liste_titre" align="center">';
166 if (getDolGlobalString('MAIN_LIST_FILTER_ON_DAY')) {
167 print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
168 }
169 print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
170 print $formother->selectyear($year ? $year : -1, 'year', 1, 20, 5);
171 print '</td>';
172 print '<td class="liste_titre">';
173 print '<input class="flat" size="10" type="text" name="search_name" value="'.$search_name.'">';
174 print '</td>';
175 print '<td class="liste_titre">';
176 print '<input class="flat" size="10" type="text" name="search_company" value="'.$search_company.'">';
177 print '</td>';
178 print '<td class="liste_titre right">';
179 // print '<input class="flat" size="10" type="text" name="search_amount" value="'.$search_amount.'">';
180 print '</td>';
181 print '<td class="liste_titre maxwidthsearch">';
182 $searchpicto = $form->showFilterAndCheckAddButtons(0);
183 print $searchpicto;
184 print '</td>';
185 print "</tr>\n";
186
187 while ($i < min($num, $limit)) {
188 $obj = $db->fetch_object($resql);
189
190 $soc = new Societe($db);
191 if ($obj->socid) {
192 $soc->fetch($obj->socid);
193 }
194
195 print '<tr class="oddeven">';
196 // Id
197 print '<td><a href="card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowTrip"), "trip").' '.$obj->rowid.'</a></td>';
198 // Type
199 print '<td>'.$langs->trans($obj->type).'</td>';
200 // Date
201 print '<td class="center">'.dol_print_date($db->jdate($obj->dd), 'day').'</td>';
202 // User
203 print '<td>';
204 $userstatic->id = $obj->fk_user;
205 $userstatic->lastname = $obj->lastname;
206 $userstatic->firstname = $obj->firstname;
207 print $userstatic->getNomUrl(1);
208 print '</td>';
209
210 if ($obj->socid) {
211 print '<td>'.$soc->getNomUrl(1).'</td>';
212 } else {
213 print '<td>&nbsp;</td>';
214 }
215
216 print '<td class="right">'.$obj->km.'</td>';
217
218 $tripandexpense_static->statut = $obj->fk_statut;
219 print '<td class="right">'.$tripandexpense_static->getLibStatut(5).'</td>';
220 print "</tr>\n";
221
222 $i++;
223 }
224
225 print "</table>";
226 print "</form>\n";
227 $db->free($resql);
228} else {
229 dol_print_error($db);
230}
231
232// End of page
233llxFooter();
234$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.
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:377
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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.
print_barre_liste($title, $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.
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 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.