dolibarr  9.0.0
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2011-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
3  * Copyright (C) 2015-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2015 Jean-Fran├žois Ferry <jfefe@aternatik.fr>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
26 require '../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/compta/salaries/class/paymentsalary.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
29 if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array("compta","salaries","bills","hrm"));
33 
34 // Security check
35 $socid = GETPOST("socid","int");
36 if ($user->societe_id) $socid=$user->societe_id;
37 $result = restrictedArea($user, 'salaries', '', '', '');
38 
39 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
40 $search_ref = GETPOST('search_ref','int');
41 $search_user = GETPOST('search_user','alpha');
42 $search_label = GETPOST('search_label','alpha');
43 $search_amount = GETPOST('search_amount','alpha');
44 $search_account = GETPOST('search_account','int');
45 
46 $sortfield = GETPOST("sortfield",'alpha');
47 $sortorder = GETPOST("sortorder",'alpha');
48 $page = GETPOST("page",'int');
49 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
50 $offset = $conf->liste_limit * $page;
51 $pageprev = $page - 1;
52 $pagenext = $page + 1;
53 if (! $sortfield) $sortfield="s.datep,s.rowid";
54 if (! $sortorder) $sortorder="DESC,DESC";
55 $optioncss = GETPOST('optioncss','alpha');
56 
57 $filtre=$_GET["filtre"];
58 
59 if (empty($_REQUEST['typeid']))
60 {
61  $newfiltre=str_replace('filtre=','',$filtre);
62  $filterarray=explode('-',$newfiltre);
63  foreach($filterarray as $val)
64  {
65  $part=explode(':',$val);
66  if ($part[0] == 's.fk_typepayment') $typeid=$part[1];
67  }
68 }
69 else
70 {
71  $typeid=$_REQUEST['typeid'];
72 }
73 
74 
75 
76 /*
77  * Actions
78  */
79 
80 if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All test are required to be compatible with all browsers
81 {
82  $search_ref="";
83  $search_label="";
84  $search_amount="";
85  $search_account='';
86  $typeid="";
87 }
88 
89 
90 /*
91  * View
92  */
93 
94 llxHeader('', $langs->trans("Salaries"));
95 
96 $form = new Form($db);
97 $salstatic = new PaymentSalary($db);
98 $userstatic = new User($db);
99 $accountstatic = new Account($db);
100 
101 $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.email, u.admin, u.salary as current_salary, u.fk_soc as fk_soc, u.statut as status,";
102 $sql.= " s.rowid, s.fk_user, s.amount, s.salary, s.label, s.datep as datep, s.datev as datev, s.fk_typepayment as type, s.num_payment, s.fk_bank,";
103 $sql.= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.fk_accountancy_journal, ba.label as blabel,";
104 $sql.= " pst.code as payment_code";
105 $sql.= " FROM ".MAIN_DB_PREFIX."payment_salary as s";
106 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON s.fk_typepayment = pst.id";
107 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid";
108 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid,";
109 $sql.= " ".MAIN_DB_PREFIX."user as u";
110 $sql.= " WHERE u.rowid = s.fk_user";
111 $sql.= " AND s.entity = ".$conf->entity;
112 
113 // Search criteria
114 if ($search_ref) $sql.=" AND s.rowid=".$search_ref;
115 if ($search_user) $sql.=natural_search(array('u.login', 'u.lastname', 'u.firstname', 'u.email'), $search_user);
116 if ($search_label) $sql.=natural_search(array('s.label'), $search_label);
117 if ($search_amount) $sql.=natural_search("s.amount", $search_amount, 1);
118 if ($search_account > 0) $sql .=" AND b.fk_account=".$search_account;
119 if ($filtre) {
120  $filtre=str_replace(":","=",$filtre);
121  $sql .= " AND ".$filtre;
122 }
123 if ($typeid) {
124  $sql .= " AND s.fk_typepayment=".$typeid;
125 }
126 $sql.= $db->order($sortfield,$sortorder);
127 
128 //$sql.= " GROUP BY u.rowid, u.lastname, u.firstname, s.rowid, s.fk_user, s.amount, s.label, s.datev, s.fk_typepayment, s.num_payment, pst.code";
129 $totalnboflines=0;
130 $result=$db->query($sql);
131 if ($result)
132 {
133  $totalnboflines = $db->num_rows($result);
134 }
135 $sql.= $db->plimit($limit+1,$offset);
136 
137 $result = $db->query($sql);
138 if ($result)
139 {
140  $num = $db->num_rows($result);
141  $i = 0;
142  $total = 0 ;
143 
144  $param='';
145  if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
146  if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
147  if ($typeid) $param.='&amp;typeid='.$typeid;
148  if ($optioncss != '') $param.='&amp;optioncss='.$optioncss;
149 
150  $newcardbutton='';
151  if (! empty($user->rights->salaries->write))
152  {
153  $newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/compta/salaries/card.php?action=create"><span class="valignmiddle">'.$langs->trans('NewSalaryPayment').'</span>';
154  $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
155  $newcardbutton.= '</a>';
156  }
157 
158  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
159  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
160  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
161  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
162  print '<input type="hidden" name="action" value="list">';
163  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
164  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
165  print '<input type="hidden" name="page" value="'.$page.'">';
166 
167  print_barre_liste($langs->trans("SalariesPayments"),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num, $totalnboflines, 'title_accountancy.png', 0, $newcardbutton, '', $limit);
168 
169  print '<div class="div-table-responsive">';
170  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
171 
172  print '<tr class="liste_titre_filter">';
173  // Ref
174  print '<td class="liste_titre" align="left">';
175  print '<input class="flat" type="text" size="3" name="search_ref" value="'.$db->escape($search_ref).'">';
176  print '</td>';
177  // Employee
178  print '<td class="liste_titre">';
179  print '<input class="flat" type="text" size="6" name="search_user" value="'.$db->escape($search_user).'">';
180  print '</td>';
181  // Label
182  print '<td class="liste_titre"><input type="text" class="flat" size="10" name="search_label" value="'.$db->escape($search_label).'"></td>';
183  // Date
184  print '<td class="liste_titre">&nbsp;</td>';
185  // Type
186  print '<td class="liste_titre" align="left">';
187  $form->select_types_paiements($typeid,'typeid','',0,1,1,16);
188  print '</td>';
189  // Account
190  if (! empty($conf->banque->enabled))
191  {
192  print '<td class="liste_titre">';
193  $form->select_comptes($search_account,'search_account',0,'',1);
194  print '</td>';
195  }
196  // Amount
197  print '<td class="liste_titre" align="right"><input name="search_amount" class="flat" type="text" size="8" value="'.$db->escape($search_amount).'"></td>';
198 
199  print '<td class="liste_titre" align="right">';
200  $searchpicto=$form->showFilterAndCheckAddButtons(0);
201  print $searchpicto;
202  print '</td>';
203 
204  print '<tr class="liste_titre">';
205  print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"s.rowid","",$param,"",$sortfield,$sortorder);
206  print_liste_field_titre("Employee",$_SERVER["PHP_SELF"],"u.rowid","",$param,"",$sortfield,$sortorder);
207  print_liste_field_titre("Label",$_SERVER["PHP_SELF"],"s.label","",$param,'align="left"',$sortfield,$sortorder);
208  print_liste_field_titre("DatePayment",$_SERVER["PHP_SELF"],"s.datep,s.rowid","",$param,'align="center"',$sortfield,$sortorder);
209  print_liste_field_titre("PaymentMode",$_SERVER["PHP_SELF"],"type","",$param,'align="left"',$sortfield,$sortorder);
210  if (! empty($conf->banque->enabled)) print_liste_field_titre("BankAccount",$_SERVER["PHP_SELF"],"ba.label","",$param,"",$sortfield,$sortorder);
211  print_liste_field_titre("PayedByThisPayment",$_SERVER["PHP_SELF"],"s.amount","",$param,'align="right"',$sortfield,$sortorder);
212  print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
213  print "</tr>\n";
214 
215  print "</tr>\n";
216 
217  while ($i < min($num,$limit))
218  {
219  $obj = $db->fetch_object($result);
220 
221  print '<tr class="oddeven">';
222 
223  $userstatic->id=$obj->uid;
224  $userstatic->lastname=$obj->lastname;
225  $userstatic->firstname=$obj->firstname;
226  $userstatic->admin=$obj->admin;
227  $userstatic->login=$obj->login;
228  $userstatic->email=$obj->email;
229  $userstatic->societe_id=$obj->fk_soc;
230  $userstatic->statut=$obj->status;
231 
232  $salstatic->id=$obj->rowid;
233  $salstatic->ref=$obj->rowid;
234 
235  // Ref
236  print "<td>".$salstatic->getNomUrl(1)."</td>\n";
237  // Employee
238  print "<td>".$userstatic->getNomUrl(1)."</td>\n";
239  // Label payment
240  print "<td>".dol_trunc($obj->label,40)."</td>\n";
241  // Date payment
242  print '<td align="center">'.dol_print_date($db->jdate($obj->datep),'day')."</td>\n";
243  // Type
244  print '<td>'.$langs->trans("PaymentTypeShort".$obj->payment_code).' '.$obj->num_payment.'</td>';
245  // Account
246  if (! empty($conf->banque->enabled))
247  {
248  print '<td>';
249  if ($obj->fk_bank > 0)
250  {
251  //$accountstatic->fetch($obj->fk_bank);
252  $accountstatic->id=$obj->bid;
253  $accountstatic->ref=$obj->bref;
254  $accountstatic->number=$obj->bnumber;
255 
256  if (! empty($conf->accounting->enabled))
257  {
258  $accountstatic->account_number=$obj->account_number;
259 
260  $accountingjournal = new AccountingJournal($db);
261  $accountingjournal->fetch($obj->fk_accountancy_journal);
262 
263  $accountstatic->accountancy_journal = $accountingjournal->getNomUrl(0,1,1,'',1);
264  }
265  $accountstatic->label=$obj->blabel;
266  print $accountstatic->getNomUrl(1);
267  }
268  else print '&nbsp;';
269  print '</td>';
270  }
271  // Amount
272  print "<td align=\"right\">".price($obj->amount)."</td>";
273  print "<td></td>";
274  print "</tr>\n";
275 
276  $total = $total + $obj->amount;
277 
278  $i++;
279  }
280 
281  $colspan=5;
282  if (! empty($conf->banque->enabled)) $colspan++;
283  print '<tr class="liste_total"><td colspan="'.$colspan.'" class="liste_total">'.$langs->trans("Total").'</td>';
284  print '<td class="liste_total" align="right">'.price($total)."</td>";
285  print "<td></td></tr>";
286 
287  print "</table>";
288  print '</div>';
289  print '</form>';
290 
291  $db->free($result);
292 }
293 else
294 {
295  dol_print_error($db);
296 }
297 
298 // End of page
299 llxFooter();
300 $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 salary payments.
Class to manage Dolibarr users.
Definition: user.class.php:41
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class to manage bank accounts.
Class to manage generation of HTML components Only common components must be here.
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.
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...
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.
Class to manage accounting accounts.