dolibarr  7.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@capnetworks.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 $langs->load("companies");
34 $langs->load("users");
35 $langs->load("trips");
36 
37 // Security check
38 $socid = GETPOST('socid','int');
39 if ($user->societe_id) $socid=$user->societe_id;
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 = GETPOST("page",'int');
49 $limit = GETPOST('limit')?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 
60 if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter','alpha')) // Both test are required to be compatible with all browsers
61 {
62  $search_ref="";
63  $search_name="";
64  $search_company="";
65  // $search_amount="";
66  $year="";
67  $month="";
68 }
69 
70 /*
71  * View
72  */
73 
74 $formother = new FormOther($db);
75 $tripandexpense_static=new Deplacement($db);
76 $userstatic = new User($db);
77 
78 $childids = $user->getAllChildIds();
79 $childids[]=$user->id;
80 
81 llxHeader();
82 
83 $sql = "SELECT s.nom, d.fk_user, s.rowid as socid,"; // Ou
84 $sql.= " d.rowid, d.type, d.dated as dd, d.km,"; // Comment
85 $sql.= " d.fk_statut,";
86 $sql.= " u.lastname, u.firstname"; // Qui
87 $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
88 $sql.= ", ".MAIN_DB_PREFIX."deplacement as d";
89 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON d.fk_soc = s.rowid";
90 if (!$user->rights->societe->client->voir && !$socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
91 $sql.= " WHERE d.fk_user = u.rowid";
92 $sql.= " AND d.entity = ".$conf->entity;
93 if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) $sql.=' AND d.fk_user IN ('.join(',',$childids).')';
94 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id." OR d.fk_soc IS NULL) ";
95 if ($socid) $sql.= " AND s.rowid = ".$socid;
96 
97 if ($search_ref) $sql.=" AND d.rowid=".$search_ref;
98 if ($search_name)
99 {
100  $sql .= natural_search('u.lastname', $search_name);
101 }
102 if ($search_company)
103 {
104  $sql .= natural_search('s.nom', $search_company);
105 }
106 // if ($search_amount) $sql.=" AND d.km='".$db->escape(price2num(trim($search_amount)))."'";
107 if ($month > 0)
108 {
109  if ($year > 0 && empty($day))
110  $sql.= " AND d.dated BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
111  else if ($year > 0 && ! empty($day))
112  $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))."'";
113  else
114  $sql.= " AND date_format(d.dated, '%m') = '".$month."'";
115 }
116 else if ($year > 0)
117 {
118  $sql.= " AND d.dated BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
119 }
120 
121 $sql.= $db->order($sortfield,$sortorder);
122 $sql.= $db->plimit($limit + 1, $offset);
123 
124 //print $sql;
125 $resql=$db->query($sql);
126 if ($resql)
127 {
128  $num = $db->num_rows($resql);
129 
130  print_barre_liste($langs->trans("ListOfFees"), $page, $_SERVER["PHP_SELF"],"&socid=$socid",$sortfield,$sortorder,'',$num);
131 
132  $i = 0;
133  print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">'."\n";
134  print '<table class="noborder" width="100%">';
135  print "<tr class=\"liste_titre\">";
136  print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"d.rowid","","&socid=$socid",'',$sortfield,$sortorder);
137  print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"d.type","","&socid=$socid",'',$sortfield,$sortorder);
138  print_liste_field_titre("Date",$_SERVER["PHP_SELF"],"d.dated","","&socid=$socid",'align="center"',$sortfield,$sortorder);
139  print_liste_field_titre("Person",$_SERVER["PHP_SELF"],"u.lastname","","&socid=$socid",'',$sortfield,$sortorder);
140  print_liste_field_titre("Company",$_SERVER["PHP_SELF"],"s.nom","","&socid=$socid",'',$sortfield,$sortorder);
141  print_liste_field_titre("FeesKilometersOrAmout",$_SERVER["PHP_SELF"],"d.km","","&socid=$socid",'align="right"',$sortfield,$sortorder);
143  print "</tr>\n";
144 
145  // Filters lines
146  print '<tr class="liste_titre">';
147  print '<td class="liste_titre">';
148  print '<input class="flat" size="4" type="text" name="search_ref" value="'.$search_ref.'">';
149  print '</td>';
150  print '<td class="liste_titre">';
151  print '&nbsp;';
152  print '</td>';
153  print '<td class="liste_titre" align="center">';
154  if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
155  print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
156  $formother->select_year($year?$year:-1,'year',1, 20, 5);
157  print '</td>';
158  print '<td class="liste_titre">';
159  print '<input class="flat" size="10" type="text" name="search_name" value="'.$search_name.'">';
160  print '</td>';
161  print '<td class="liste_titre">';
162  print '<input class="flat" size="10" type="text" name="search_company" value="'.$search_company.'">';
163  print '</td>';
164  print '<td class="liste_titre" align="right">';
165  // print '<input class="flat" size="10" type="text" name="search_amount" value="'.$search_amount.'">';
166  print '</td>';
167  print '<td class="liste_titre" align="right">';
168  $searchpicto=$form->showFilterAndCheckAddButtons(0);
169  print $searchpicto;
170  print '</td>';
171  print "</tr>\n";
172 
173  $var=true;
174  while ($i < min($num,$limit))
175  {
176  $obj = $db->fetch_object($resql);
177 
178  $soc = new Societe($db);
179  if ($obj->socid) $soc->fetch($obj->socid);
180 
181 
182  print '<tr class="oddeven">';
183  // Id
184  print '<td><a href="card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowTrip"),"trip").' '.$obj->rowid.'</a></td>';
185  // Type
186  print '<td>'.$langs->trans($obj->type).'</td>';
187  // Date
188  print '<td align="center">'.dol_print_date($db->jdate($obj->dd),'day').'</td>';
189  // User
190  print '<td>';
191  $userstatic->id = $obj->fk_user;
192  $userstatic->lastname = $obj->lastname;
193  $userstatic->firstname = $obj->firstname;
194  print $userstatic->getNomUrl(1);
195  print '</td>';
196 
197  if ($obj->socid) print '<td>'.$soc->getNomUrl(1).'</td>';
198  else print '<td>&nbsp;</td>';
199 
200  print '<td align="right">'.$obj->km.'</td>';
201 
202  $tripandexpense_static->statut=$obj->fk_statut;
203  print '<td align="right">'.$tripandexpense_static->getLibStatut(5).'</td>';
204  print "</tr>\n";
205 
206  $i++;
207  }
208 
209  print "</table>";
210  print "</form>\n";
211  $db->free($resql);
212 }
213 else
214 {
215  dol_print_error($db);
216 }
217 
218 llxFooter();
219 
220 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
Class to manage trips and working credit notes.
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:39
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:445
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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:46
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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:459
print
Draft customers invoices.
Definition: index.php:91
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:1013
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.