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