dolibarr  16.0.5
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 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
33 
34 // Load translation files required by the page
35 $langs->loadLangs(array('companies', 'users', 'trips'));
36 
37 // Security check
38 $socid = GETPOST('socid', 'int');
39 if ($user->socid) {
40  $socid = $user->socid;
41 }
42 $result = restrictedArea($user, 'deplacement', '', '');
43 
44 $search_ref = GETPOST('search_ref', 'int');
45 $search_name = GETPOST('search_name', 'alpha');
46 $search_company = GETPOST('search_company', 'alpha');
47 // $search_amount=GETPOST('search_amount','alpha');
48 $sortfield = GETPOST('sortfield', 'aZ09comma');
49 $sortorder = GETPOST('sortorder', 'aZ09comma');
50 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
51 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
52 if (empty($page) || $page == -1) {
53  $page = 0;
54 } // If $page is not defined, or '' or -1
55 $offset = $limit * $page;
56 $pageprev = $page - 1;
57 $pagenext = $page + 1;
58 if (!$sortorder) {
59  $sortorder = "DESC";
60 }
61 if (!$sortfield) {
62  $sortfield = "d.dated";
63 }
64 
65 $year = GETPOST("year");
66 $month = GETPOST("month");
67 $day = GETPOST("day");
68 
69 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
70  $search_ref = "";
71  $search_name = "";
72  $search_company = "";
73  // $search_amount="";
74  $year = "";
75  $month = "";
76  $day = "";
77 }
78 
79 /*
80  * View
81  */
82 
83 $formother = new FormOther($db);
84 $tripandexpense_static = new Deplacement($db);
85 $userstatic = new User($db);
86 
87 $childids = $user->getAllChildIds();
88 $childids[] = $user->id;
89 
90 llxHeader();
91 
92 $sql = "SELECT s.nom, d.fk_user, s.rowid as socid,"; // Ou
93 $sql .= " d.rowid, d.type, d.dated as dd, d.km,"; // Comment
94 $sql .= " d.fk_statut,";
95 $sql .= " u.lastname, u.firstname"; // Qui
96 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
97 $sql .= ", ".MAIN_DB_PREFIX."deplacement as d";
98 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON d.fk_soc = s.rowid";
99 if (empty($user->rights->societe->client->voir) && !$socid) {
100  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
101 }
102 $sql .= " WHERE d.fk_user = u.rowid";
103 $sql .= " AND d.entity = ".$conf->entity;
104 if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) {
105  $sql .= ' AND d.fk_user IN ('.$db->sanitize(join(',', $childids)).')';
106 }
107 if (empty($user->rights->societe->client->voir) && !$socid) {
108  $sql .= " AND (sc.fk_user = ".((int) $user->id)." OR d.fk_soc IS NULL) ";
109 }
110 if ($socid) {
111  $sql .= " AND s.rowid = ".((int) $socid);
112 }
113 
114 if ($search_ref) {
115  $sql .= " AND d.rowid = ".((int) $search_ref);
116 }
117 if ($search_name) {
118  $sql .= natural_search('u.lastname', $search_name);
119 }
120 if ($search_company) {
121  $sql .= natural_search('s.nom', $search_company);
122 }
123 $sql .= dolSqlDateFilter("d.dated", $day, $month, $year);
124 
125 $sql .= $db->order($sortfield, $sortorder);
126 $sql .= $db->plimit($limit + 1, $offset);
127 
128 //print $sql;
129 $resql = $db->query($sql);
130 if ($resql) {
131  $num = $db->num_rows($resql);
132 
133  print_barre_liste($langs->trans("ListOfFees"), $page, $_SERVER["PHP_SELF"], "&socid=$socid", $sortfield, $sortorder, '', $num);
134 
135  $i = 0;
136  print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">'."\n";
137  print '<table class="noborder centpercent">';
138  print "<tr class=\"liste_titre\">";
139  print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "d.rowid", "", "&socid=$socid", '', $sortfield, $sortorder);
140  print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "d.type", "", "&socid=$socid", '', $sortfield, $sortorder);
141  print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "d.dated", "", "&socid=$socid", 'align="center"', $sortfield, $sortorder);
142  print_liste_field_titre("Person", $_SERVER["PHP_SELF"], "u.lastname", "", "&socid=$socid", '', $sortfield, $sortorder);
143  print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "&socid=$socid", '', $sortfield, $sortorder);
144  print_liste_field_titre("FeesKilometersOrAmout", $_SERVER["PHP_SELF"], "d.km", "", "&socid=$socid", 'class="right"', $sortfield, $sortorder);
146  print "</tr>\n";
147 
148  // Filters lines
149  print '<tr class="liste_titre">';
150  print '<td class="liste_titre">';
151  print '<input class="flat" size="4" type="text" name="search_ref" value="'.$search_ref.'">';
152  print '</td>';
153  print '<td class="liste_titre">';
154  print '&nbsp;';
155  print '</td>';
156  print '<td class="liste_titre" align="center">';
157  if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) {
158  print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
159  }
160  print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
161  print $formother->selectyear($year ? $year : -1, 'year', 1, 20, 5);
162  print '</td>';
163  print '<td class="liste_titre">';
164  print '<input class="flat" size="10" type="text" name="search_name" value="'.$search_name.'">';
165  print '</td>';
166  print '<td class="liste_titre">';
167  print '<input class="flat" size="10" type="text" name="search_company" value="'.$search_company.'">';
168  print '</td>';
169  print '<td class="liste_titre right">';
170  // print '<input class="flat" size="10" type="text" name="search_amount" value="'.$search_amount.'">';
171  print '</td>';
172  print '<td class="liste_titre maxwidthsearch">';
173  $searchpicto = $form->showFilterAndCheckAddButtons(0);
174  print $searchpicto;
175  print '</td>';
176  print "</tr>\n";
177 
178  while ($i < min($num, $limit)) {
179  $obj = $db->fetch_object($resql);
180 
181  $soc = new Societe($db);
182  if ($obj->socid) {
183  $soc->fetch($obj->socid);
184  }
185 
186  print '<tr class="oddeven">';
187  // Id
188  print '<td><a href="card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowTrip"), "trip").' '.$obj->rowid.'</a></td>';
189  // Type
190  print '<td>'.$langs->trans($obj->type).'</td>';
191  // Date
192  print '<td class="center">'.dol_print_date($db->jdate($obj->dd), 'day').'</td>';
193  // User
194  print '<td>';
195  $userstatic->id = $obj->fk_user;
196  $userstatic->lastname = $obj->lastname;
197  $userstatic->firstname = $obj->firstname;
198  print $userstatic->getNomUrl(1);
199  print '</td>';
200 
201  if ($obj->socid) {
202  print '<td>'.$soc->getNomUrl(1).'</td>';
203  } else {
204  print '<td>&nbsp;</td>';
205  }
206 
207  print '<td class="right">'.$obj->km.'</td>';
208 
209  $tripandexpense_static->statut = $obj->fk_statut;
210  print '<td class="right">'.$tripandexpense_static->getLibStatut(5).'</td>';
211  print "</tr>\n";
212 
213  $i++;
214  }
215 
216  print "</table>";
217  print "</form>\n";
218  $db->free($resql);
219 } else {
220  dol_print_error($db);
221 }
222 
223 // End of page
224 llxFooter();
225 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
FormOther
Classe permettant la generation de composants html autre Only common components are here.
Definition: html.formother.class.php:39
print_barre_liste
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.
Definition: functions.lib.php:5257
User
Class to manage Dolibarr users.
Definition: user.class.php:44
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5026
natural_search
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...
Definition: functions.lib.php:9420
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
Deplacement
Class to manage trips and working credit notes.
Definition: deplacement.class.php:33
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
dolSqlDateFilter
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:334
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59