dolibarr  9.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  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
27 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array('companies', 'users', 'trips'));
35 
36 // Security check
37 $socid = GETPOST('socid','int');
38 if ($user->societe_id) $socid=$user->societe_id;
39 $result = restrictedArea($user, 'deplacement','','');
40 
41 $search_ref=GETPOST('search_ref','int');
42 $search_name=GETPOST('search_name','alpha');
43 $search_company=GETPOST('search_company','alpha');
44 // $search_amount=GETPOST('search_amount','alpha');
45 $sortfield = GETPOST("sortfield",'alpha');
46 $sortorder = GETPOST("sortorder",'alpha');
47 $page = GETPOST("page",'int');
48 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
49 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
50 $offset = $limit * $page;
51 $pageprev = $page - 1;
52 $pagenext = $page + 1;
53 if (! $sortorder) $sortorder="DESC";
54 if (! $sortfield) $sortfield="d.dated";
55 
56 $year=GETPOST("year");
57 $month=GETPOST("month");
58 
59 if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter','alpha')) // Both test are required to be compatible with all browsers
60 {
61  $search_ref="";
62  $search_name="";
63  $search_company="";
64  // $search_amount="";
65  $year="";
66  $month="";
67 }
68 
69 /*
70  * View
71  */
72 
73 $formother = new FormOther($db);
74 $tripandexpense_static=new Deplacement($db);
75 $userstatic = new User($db);
76 
77 $childids = $user->getAllChildIds();
78 $childids[]=$user->id;
79 
80 llxHeader();
81 
82 $sql = "SELECT s.nom, d.fk_user, s.rowid as socid,"; // Ou
83 $sql.= " d.rowid, d.type, d.dated as dd, d.km,"; // Comment
84 $sql.= " d.fk_statut,";
85 $sql.= " u.lastname, u.firstname"; // Qui
86 $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
87 $sql.= ", ".MAIN_DB_PREFIX."deplacement as d";
88 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON d.fk_soc = s.rowid";
89 if (!$user->rights->societe->client->voir && !$socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
90 $sql.= " WHERE d.fk_user = u.rowid";
91 $sql.= " AND d.entity = ".$conf->entity;
92 if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) $sql.=' AND d.fk_user IN ('.join(',',$childids).')';
93 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id." OR d.fk_soc IS NULL) ";
94 if ($socid) $sql.= " AND s.rowid = ".$socid;
95 
96 if ($search_ref) $sql.=" AND d.rowid=".$search_ref;
97 if ($search_name)
98 {
99  $sql .= natural_search('u.lastname', $search_name);
100 }
101 if ($search_company)
102 {
103  $sql .= natural_search('s.nom', $search_company);
104 }
105 // if ($search_amount) $sql.=" AND d.km='".$db->escape(price2num(trim($search_amount)))."'";
106 if ($month > 0)
107 {
108  if ($year > 0 && empty($day))
109  $sql.= " AND d.dated BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
110  else if ($year > 0 && ! empty($day))
111  $sql.= " AND d.dated BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'";
112  else
113  $sql.= " AND date_format(d.dated, '%m') = '".$month."'";
114 }
115 else if ($year > 0)
116 {
117  $sql.= " AND d.dated BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
118 }
119 
120 $sql.= $db->order($sortfield,$sortorder);
121 $sql.= $db->plimit($limit + 1, $offset);
122 
123 //print $sql;
124 $resql=$db->query($sql);
125 if ($resql)
126 {
127  $num = $db->num_rows($resql);
128 
129  print_barre_liste($langs->trans("ListOfFees"), $page, $_SERVER["PHP_SELF"],"&socid=$socid",$sortfield,$sortorder,'',$num);
130 
131  $i = 0;
132  print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">'."\n";
133  print '<table class="noborder" width="100%">';
134  print "<tr class=\"liste_titre\">";
135  print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"d.rowid","","&socid=$socid",'',$sortfield,$sortorder);
136  print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"d.type","","&socid=$socid",'',$sortfield,$sortorder);
137  print_liste_field_titre("Date",$_SERVER["PHP_SELF"],"d.dated","","&socid=$socid",'align="center"',$sortfield,$sortorder);
138  print_liste_field_titre("Person",$_SERVER["PHP_SELF"],"u.lastname","","&socid=$socid",'',$sortfield,$sortorder);
139  print_liste_field_titre("Company",$_SERVER["PHP_SELF"],"s.nom","","&socid=$socid",'',$sortfield,$sortorder);
140  print_liste_field_titre("FeesKilometersOrAmout",$_SERVER["PHP_SELF"],"d.km","","&socid=$socid",'align="right"',$sortfield,$sortorder);
142  print "</tr>\n";
143 
144  // Filters lines
145  print '<tr class="liste_titre">';
146  print '<td class="liste_titre">';
147  print '<input class="flat" size="4" type="text" name="search_ref" value="'.$search_ref.'">';
148  print '</td>';
149  print '<td class="liste_titre">';
150  print '&nbsp;';
151  print '</td>';
152  print '<td class="liste_titre" align="center">';
153  if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
154  print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
155  $formother->select_year($year?$year:-1,'year',1, 20, 5);
156  print '</td>';
157  print '<td class="liste_titre">';
158  print '<input class="flat" size="10" type="text" name="search_name" value="'.$search_name.'">';
159  print '</td>';
160  print '<td class="liste_titre">';
161  print '<input class="flat" size="10" type="text" name="search_company" value="'.$search_company.'">';
162  print '</td>';
163  print '<td class="liste_titre" align="right">';
164  // print '<input class="flat" size="10" type="text" name="search_amount" value="'.$search_amount.'">';
165  print '</td>';
166  print '<td class="liste_titre" align="right">';
167  $searchpicto=$form->showFilterAndCheckAddButtons(0);
168  print $searchpicto;
169  print '</td>';
170  print "</tr>\n";
171 
172  while ($i < min($num,$limit))
173  {
174  $obj = $db->fetch_object($resql);
175 
176  $soc = new Societe($db);
177  if ($obj->socid) $soc->fetch($obj->socid);
178 
179  print '<tr class="oddeven">';
180  // Id
181  print '<td><a href="card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowTrip"),"trip").' '.$obj->rowid.'</a></td>';
182  // Type
183  print '<td>'.$langs->trans($obj->type).'</td>';
184  // Date
185  print '<td align="center">'.dol_print_date($db->jdate($obj->dd),'day').'</td>';
186  // User
187  print '<td>';
188  $userstatic->id = $obj->fk_user;
189  $userstatic->lastname = $obj->lastname;
190  $userstatic->firstname = $obj->firstname;
191  print $userstatic->getNomUrl(1);
192  print '</td>';
193 
194  if ($obj->socid) print '<td>'.$soc->getNomUrl(1).'</td>';
195  else print '<td>&nbsp;</td>';
196 
197  print '<td align="right">'.$obj->km.'</td>';
198 
199  $tripandexpense_static->statut=$obj->fk_statut;
200  print '<td align="right">'.$tripandexpense_static->getLibStatut(5).'</td>';
201  print "</tr>\n";
202 
203  $i++;
204  }
205 
206  print "</table>";
207  print "</form>\n";
208  $db->free($resql);
209 }
210 else
211 {
212  dol_print_error($db);
213 }
214 
215 // End of page
216 llxFooter();
217 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
Class to manage trips and working credit notes.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->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) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Class to manage Dolibarr users.
Definition: user.class.php:41
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:453
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
Print a title with navigation controls for pagination.
Class to manage third parties objects (customers, suppliers, prospects...)
Classe permettant la generation de composants html autre Only common components are here...
llxHeader()
Empty header.
Definition: wrapper.php:44
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...
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:467
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.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)