dolibarr  7.0.0-beta
index.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 $langs->load("compta");
32 $langs->load("salaries");
33 $langs->load("bills");
34 $langs->load("hrm");
35 
36 // Security check
37 $socid = GETPOST("socid","int");
38 if ($user->societe_id) $socid=$user->societe_id;
39 $result = restrictedArea($user, 'salaries', '', '', '');
40 
41 $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
42 $search_ref = GETPOST('search_ref','int');
43 $search_user = GETPOST('search_user','alpha');
44 $search_label = GETPOST('search_label','alpha');
45 $search_amount = GETPOST('search_amount','alpha');
46 $search_account = GETPOST('search_account','int');
47 
48 $sortfield = GETPOST("sortfield",'alpha');
49 $sortorder = GETPOST("sortorder",'alpha');
50 $page = GETPOST("page",'int');
51 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
52 $offset = $conf->liste_limit * $page;
53 $pageprev = $page - 1;
54 $pagenext = $page + 1;
55 if (! $sortfield) $sortfield="s.datep";
56 if (! $sortorder) $sortorder="DESC";
57 $optioncss = GETPOST('optioncss','alpha');
58 
59 $filtre=$_GET["filtre"];
60 
61 if (empty($_REQUEST['typeid']))
62 {
63  $newfiltre=str_replace('filtre=','',$filtre);
64  $filterarray=explode('-',$newfiltre);
65  foreach($filterarray as $val)
66  {
67  $part=explode(':',$val);
68  if ($part[0] == 's.fk_typepayment') $typeid=$part[1];
69  }
70 }
71 else
72 {
73  $typeid=$_REQUEST['typeid'];
74 }
75 
76 
77 
78 /*
79  * Actions
80  */
81 
82 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
83 {
84  $search_ref="";
85  $search_label="";
86  $search_amount="";
87  $search_account='';
88  $typeid="";
89 }
90 
91 
92 /*
93  * View
94  */
95 
96 llxHeader('', $langs->trans("Salaries"));
97 
98 $form = new Form($db);
99 $salstatic = new PaymentSalary($db);
100 $userstatic = new User($db);
101 $accountstatic = new Account($db);
102 
103 $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,";
104 $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,";
105 $sql.= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.fk_accountancy_journal, ba.label as blabel,";
106 $sql.= " pst.code as payment_code";
107 $sql.= " FROM ".MAIN_DB_PREFIX."payment_salary as s";
108 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON s.fk_typepayment = pst.id AND pst.entity IN (".getEntity('c_paiement').")";
109 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid";
110 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid,";
111 $sql.= " ".MAIN_DB_PREFIX."user as u";
112 $sql.= " WHERE u.rowid = s.fk_user";
113 $sql.= " AND s.entity = ".$conf->entity;
114 
115 // Search criteria
116 if ($search_ref) $sql.=" AND s.rowid=".$search_ref;
117 if ($search_user) $sql.=natural_search(array('u.login', 'u.lastname', 'u.firstname', 'u.email'), $search_user);
118 if ($search_label) $sql.=natural_search(array('s.label'), $search_label);
119 if ($search_amount) $sql.=natural_search("s.amount", $search_amount, 1);
120 if ($search_account > 0) $sql .=" AND b.fk_account=".$search_account;
121 if ($filtre) {
122  $filtre=str_replace(":","=",$filtre);
123  $sql .= " AND ".$filtre;
124 }
125 if ($typeid) {
126  $sql .= " AND s.fk_typepayment=".$typeid;
127 }
128 $sql.= $db->order($sortfield,$sortorder);
129 
130 //$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";
131 $totalnboflines=0;
132 $result=$db->query($sql);
133 if ($result)
134 {
135  $totalnboflines = $db->num_rows($result);
136 }
137 $sql.= $db->plimit($limit+1,$offset);
138 
139 $result = $db->query($sql);
140 if ($result)
141 {
142  $num = $db->num_rows($result);
143  $i = 0;
144  $total = 0 ;
145  $var=true;
146 
147  $param='';
148  if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
149  if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
150  if ($typeid) $param.='&amp;typeid='.$typeid;
151  if ($optioncss != '') $param.='&amp;optioncss='.$optioncss;
152 
153  print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
154  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
155  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
156  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
157  print '<input type="hidden" name="action" value="list">';
158  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
159  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
160  print '<input type="hidden" name="page" value="'.$page.'">';
161 
162  print_barre_liste($langs->trans("SalariesPayments"),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num, $totalnboflines, 'title_accountancy.png', 0, '', '', $limit);
163 
164  print '<div class="div-table-responsive">';
165  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
166 
167  print '<tr class="liste_titre_filter">';
168  // Ref
169  print '<td class="liste_titre" align="left">';
170  print '<input class="flat" type="text" size="3" name="search_ref" value="'.$db->escape($search_ref).'">';
171  print '</td>';
172  // Employee
173  print '<td class="liste_titre">';
174  print '<input class="flat" type="text" size="6" name="search_user" value="'.$db->escape($search_user).'">';
175  print '</td>';
176  // Label
177  print '<td class="liste_titre"><input type="text" class="flat" size="10" name="search_label" value="'.$db->escape($search_label).'"></td>';
178  // Date
179  print '<td class="liste_titre">&nbsp;</td>';
180  // Type
181  print '<td class="liste_titre" align="left">';
182  $form->select_types_paiements($typeid,'typeid','',0,0,1,16);
183  print '</td>';
184  // Account
185  if (! empty($conf->banque->enabled))
186  {
187  print '<td class="liste_titre">';
188  $form->select_comptes($search_account,'search_account',0,'',1);
189  print '</td>';
190  }
191  // Amount
192  print '<td class="liste_titre" align="right"><input name="search_amount" class="flat" type="text" size="8" value="'.$db->escape($search_amount).'"></td>';
193 
194  print '<td class="liste_titre" align="right">';
195  $searchpicto=$form->showFilterAndCheckAddButtons(0);
196  print $searchpicto;
197  print '</td>';
198 
199  print '<tr class="liste_titre">';
200  print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"s.rowid","",$param,"",$sortfield,$sortorder);
201  print_liste_field_titre("Employee",$_SERVER["PHP_SELF"],"u.rowid","",$param,"",$sortfield,$sortorder);
202  print_liste_field_titre("Label",$_SERVER["PHP_SELF"],"s.label","",$param,'align="left"',$sortfield,$sortorder);
203  print_liste_field_titre("DatePayment",$_SERVER["PHP_SELF"],"s.datep","",$param,'align="center"',$sortfield,$sortorder);
204  print_liste_field_titre("PaymentMode",$_SERVER["PHP_SELF"],"type","",$param,'align="left"',$sortfield,$sortorder);
205  if (! empty($conf->banque->enabled)) print_liste_field_titre("BankAccount",$_SERVER["PHP_SELF"],"ba.label","",$param,"",$sortfield,$sortorder);
206  print_liste_field_titre("PayedByThisPayment",$_SERVER["PHP_SELF"],"s.amount","",$param,'align="right"',$sortfield,$sortorder);
207  print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
208  print "</tr>\n";
209 
210  print "</tr>\n";
211 
212  while ($i < min($num,$limit))
213  {
214  $obj = $db->fetch_object($result);
215 
216  print '<tr class="oddeven">';
217 
218  $userstatic->id=$obj->uid;
219  $userstatic->lastname=$obj->lastname;
220  $userstatic->firstname=$obj->firstname;
221  $userstatic->admin=$obj->admin;
222  $userstatic->login=$obj->login;
223  $userstatic->email=$obj->email;
224  $userstatic->societe_id=$obj->fk_soc;
225  $userstatic->statut=$obj->status;
226 
227  $salstatic->id=$obj->rowid;
228  $salstatic->ref=$obj->rowid;
229  // Ref
230  print "<td>".$salstatic->getNomUrl(1)."</td>\n";
231  // Employee
232  print "<td>".$userstatic->getNomUrl(1)."</td>\n";
233  // Label payment
234  print "<td>".dol_trunc($obj->label,40)."</td>\n";
235  // Date payment
236  print '<td align="center">'.dol_print_date($db->jdate($obj->datep),'day')."</td>\n";
237  // Type
238  print '<td>'.$langs->trans("PaymentTypeShort".$obj->payment_code).' '.$obj->num_payment.'</td>';
239  // Account
240  if (! empty($conf->banque->enabled))
241  {
242  print '<td>';
243  if ($obj->fk_bank > 0)
244  {
245  //$accountstatic->fetch($obj->fk_bank);
246  $accountstatic->id=$obj->bid;
247  $accountstatic->ref=$obj->bref;
248  $accountstatic->number=$obj->bnumber;
249 
250  if (! empty($conf->accounting->enabled))
251  {
252  $accountstatic->account_number=$obj->account_number;
253 
254  $accountingjournal = new AccountingJournal($db);
255  $accountingjournal->fetch($obj->fk_accountancy_journal);
256 
257  $accountstatic->accountancy_journal = $accountingjournal->getNomUrl(0,1,1,'',1);
258  }
259  $accountstatic->label=$obj->blabel;
260  print $accountstatic->getNomUrl(1);
261  }
262  else print '&nbsp;';
263  print '</td>';
264  }
265  // Amount
266  print "<td align=\"right\">".price($obj->amount)."</td>";
267  print "<td></td>";
268  print "</tr>\n";
269 
270  $total = $total + $obj->amount;
271 
272  $i++;
273  }
274 
275  $colspan=5;
276  if (! empty($conf->banque->enabled)) $colspan++;
277  print '<tr class="liste_total"><td colspan="'.$colspan.'" class="liste_total">'.$langs->trans("Total").'</td>';
278  print '<td class="liste_total" align="right">'.price($total)."</td>";
279  print "<td></td></tr>";
280 
281  print "</table>";
282  print '</div>';
283  print '</form>';
284 
285  $db->free($result);
286 }
287 else
288 {
289  dol_print_error($db);
290 }
291 
292 
293 llxFooter();
294 $db->close();
llxFooter()
Footer empty.
Definition: index.php:43
Class to manage salary payments.
Class to manage Dolibarr users.
Definition: user.class.php:39
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
Class to manage bank accounts.
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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()
Header empty.
Definition: index.php:37
getEntity($element, $shared=1, $forceentity=null)
Get list of entity id to use.
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...
print
Draft customers invoices.
Definition: index.php:91
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.
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.