list.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <?php
  2. /* Copyright (C) 2011-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
  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. /**
  20. * \file htdocs/compta/salaries/list.php
  21. * \ingroup salaries
  22. * \brief List of salaries payments
  23. */
  24. require '../../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/compta/salaries/class/paymentsalary.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  27. if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
  28. // Load translation files required by the page
  29. $langs->loadLangs(array("compta","salaries","bills","hrm"));
  30. // Security check
  31. $socid = GETPOST("socid","int");
  32. if ($user->societe_id) $socid=$user->societe_id;
  33. $result = restrictedArea($user, 'salaries', '', '', '');
  34. $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
  35. $search_ref = GETPOST('search_ref','int');
  36. $search_user = GETPOST('search_user','alpha');
  37. $search_label = GETPOST('search_label','alpha');
  38. $search_amount = GETPOST('search_amount','alpha');
  39. $search_account = GETPOST('search_account','int');
  40. $sortfield = GETPOST("sortfield",'alpha');
  41. $sortorder = GETPOST("sortorder",'alpha');
  42. $page = GETPOST("page",'int');
  43. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  44. $offset = $conf->liste_limit * $page;
  45. $pageprev = $page - 1;
  46. $pagenext = $page + 1;
  47. if (! $sortfield) $sortfield="s.datep,s.rowid";
  48. if (! $sortorder) $sortorder="DESC,DESC";
  49. $optioncss = GETPOST('optioncss','alpha');
  50. $filtre=$_GET["filtre"];
  51. if (empty($_REQUEST['typeid']))
  52. {
  53. $newfiltre=str_replace('filtre=','',$filtre);
  54. $filterarray=explode('-',$newfiltre);
  55. foreach($filterarray as $val)
  56. {
  57. $part=explode(':',$val);
  58. if ($part[0] == 's.fk_typepayment') $typeid=$part[1];
  59. }
  60. }
  61. else
  62. {
  63. $typeid=$_REQUEST['typeid'];
  64. }
  65. /*
  66. * Actions
  67. */
  68. 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
  69. {
  70. $search_ref="";
  71. $search_label="";
  72. $search_amount="";
  73. $search_account='';
  74. $typeid="";
  75. }
  76. /*
  77. * View
  78. */
  79. llxHeader('', $langs->trans("Salaries"));
  80. $form = new Form($db);
  81. $salstatic = new PaymentSalary($db);
  82. $userstatic = new User($db);
  83. $accountstatic = new Account($db);
  84. $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,";
  85. $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,";
  86. $sql.= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.fk_accountancy_journal, ba.label as blabel,";
  87. $sql.= " pst.code as payment_code";
  88. $sql.= " FROM ".MAIN_DB_PREFIX."payment_salary as s";
  89. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON s.fk_typepayment = pst.id";
  90. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid";
  91. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid,";
  92. $sql.= " ".MAIN_DB_PREFIX."user as u";
  93. $sql.= " WHERE u.rowid = s.fk_user";
  94. $sql.= " AND s.entity = ".$conf->entity;
  95. // Search criteria
  96. if ($search_ref) $sql.=" AND s.rowid=".$search_ref;
  97. if ($search_user) $sql.=natural_search(array('u.login', 'u.lastname', 'u.firstname', 'u.email'), $search_user);
  98. if ($search_label) $sql.=natural_search(array('s.label'), $search_label);
  99. if ($search_amount) $sql.=natural_search("s.amount", $search_amount, 1);
  100. if ($search_account > 0) $sql .=" AND b.fk_account=".$search_account;
  101. if ($filtre) {
  102. $filtre=str_replace(":","=",$filtre);
  103. $sql .= " AND ".$filtre;
  104. }
  105. if ($typeid) {
  106. $sql .= " AND s.fk_typepayment=".$typeid;
  107. }
  108. $sql.= $db->order($sortfield,$sortorder);
  109. //$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";
  110. $totalnboflines=0;
  111. $result=$db->query($sql);
  112. if ($result)
  113. {
  114. $totalnboflines = $db->num_rows($result);
  115. }
  116. $sql.= $db->plimit($limit+1,$offset);
  117. $result = $db->query($sql);
  118. if ($result)
  119. {
  120. $num = $db->num_rows($result);
  121. $i = 0;
  122. $total = 0 ;
  123. $param='';
  124. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  125. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  126. if ($typeid) $param.='&amp;typeid='.$typeid;
  127. if ($optioncss != '') $param.='&amp;optioncss='.$optioncss;
  128. $newcardbutton='';
  129. if (! empty($user->rights->salaries->write))
  130. {
  131. $newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/compta/salaries/card.php?action=create"><span class="valignmiddle">'.$langs->trans('NewSalaryPayment').'</span>';
  132. $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
  133. $newcardbutton.= '</a>';
  134. }
  135. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  136. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  137. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  138. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  139. print '<input type="hidden" name="action" value="list">';
  140. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  141. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  142. print '<input type="hidden" name="page" value="'.$page.'">';
  143. print_barre_liste($langs->trans("SalariesPayments"),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num, $totalnboflines, 'title_accountancy.png', 0, $newcardbutton, '', $limit);
  144. print '<div class="div-table-responsive">';
  145. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  146. print '<tr class="liste_titre_filter">';
  147. // Ref
  148. print '<td class="liste_titre" align="left">';
  149. print '<input class="flat" type="text" size="3" name="search_ref" value="'.$db->escape($search_ref).'">';
  150. print '</td>';
  151. // Employee
  152. print '<td class="liste_titre">';
  153. print '<input class="flat" type="text" size="6" name="search_user" value="'.$db->escape($search_user).'">';
  154. print '</td>';
  155. // Label
  156. print '<td class="liste_titre"><input type="text" class="flat" size="10" name="search_label" value="'.$db->escape($search_label).'"></td>';
  157. // Date
  158. print '<td class="liste_titre">&nbsp;</td>';
  159. // Type
  160. print '<td class="liste_titre" align="left">';
  161. $form->select_types_paiements($typeid,'typeid','',0,1,1,16);
  162. print '</td>';
  163. // Account
  164. if (! empty($conf->banque->enabled))
  165. {
  166. print '<td class="liste_titre">';
  167. $form->select_comptes($search_account,'search_account',0,'',1);
  168. print '</td>';
  169. }
  170. // Amount
  171. print '<td class="liste_titre" align="right"><input name="search_amount" class="flat" type="text" size="8" value="'.$db->escape($search_amount).'"></td>';
  172. print '<td class="liste_titre" align="right">';
  173. $searchpicto=$form->showFilterAndCheckAddButtons(0);
  174. print $searchpicto;
  175. print '</td>';
  176. print '<tr class="liste_titre">';
  177. print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"s.rowid","",$param,"",$sortfield,$sortorder);
  178. print_liste_field_titre("Employee",$_SERVER["PHP_SELF"],"u.rowid","",$param,"",$sortfield,$sortorder);
  179. print_liste_field_titre("Label",$_SERVER["PHP_SELF"],"s.label","",$param,'align="left"',$sortfield,$sortorder);
  180. print_liste_field_titre("DatePayment",$_SERVER["PHP_SELF"],"s.datep,s.rowid","",$param,'align="center"',$sortfield,$sortorder);
  181. print_liste_field_titre("PaymentMode",$_SERVER["PHP_SELF"],"type","",$param,'align="left"',$sortfield,$sortorder);
  182. if (! empty($conf->banque->enabled)) print_liste_field_titre("BankAccount",$_SERVER["PHP_SELF"],"ba.label","",$param,"",$sortfield,$sortorder);
  183. print_liste_field_titre("PayedByThisPayment",$_SERVER["PHP_SELF"],"s.amount","",$param,'align="right"',$sortfield,$sortorder);
  184. print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
  185. print "</tr>\n";
  186. print "</tr>\n";
  187. while ($i < min($num,$limit))
  188. {
  189. $obj = $db->fetch_object($result);
  190. print '<tr class="oddeven">';
  191. $userstatic->id=$obj->uid;
  192. $userstatic->lastname=$obj->lastname;
  193. $userstatic->firstname=$obj->firstname;
  194. $userstatic->admin=$obj->admin;
  195. $userstatic->login=$obj->login;
  196. $userstatic->email=$obj->email;
  197. $userstatic->societe_id=$obj->fk_soc;
  198. $userstatic->statut=$obj->status;
  199. $salstatic->id=$obj->rowid;
  200. $salstatic->ref=$obj->rowid;
  201. // Ref
  202. print "<td>".$salstatic->getNomUrl(1)."</td>\n";
  203. // Employee
  204. print "<td>".$userstatic->getNomUrl(1)."</td>\n";
  205. // Label payment
  206. print "<td>".dol_trunc($obj->label,40)."</td>\n";
  207. // Date payment
  208. print '<td align="center">'.dol_print_date($db->jdate($obj->datep),'day')."</td>\n";
  209. // Type
  210. print '<td>'.$langs->trans("PaymentTypeShort".$obj->payment_code).' '.$obj->num_payment.'</td>';
  211. // Account
  212. if (! empty($conf->banque->enabled))
  213. {
  214. print '<td>';
  215. if ($obj->fk_bank > 0)
  216. {
  217. //$accountstatic->fetch($obj->fk_bank);
  218. $accountstatic->id=$obj->bid;
  219. $accountstatic->ref=$obj->bref;
  220. $accountstatic->number=$obj->bnumber;
  221. if (! empty($conf->accounting->enabled))
  222. {
  223. $accountstatic->account_number=$obj->account_number;
  224. $accountingjournal = new AccountingJournal($db);
  225. $accountingjournal->fetch($obj->fk_accountancy_journal);
  226. $accountstatic->accountancy_journal = $accountingjournal->getNomUrl(0,1,1,'',1);
  227. }
  228. $accountstatic->label=$obj->blabel;
  229. print $accountstatic->getNomUrl(1);
  230. }
  231. else print '&nbsp;';
  232. print '</td>';
  233. }
  234. // Amount
  235. print "<td align=\"right\">".price($obj->amount)."</td>";
  236. print "<td></td>";
  237. print "</tr>\n";
  238. $total = $total + $obj->amount;
  239. $i++;
  240. }
  241. $colspan=5;
  242. if (! empty($conf->banque->enabled)) $colspan++;
  243. print '<tr class="liste_total"><td colspan="'.$colspan.'" class="liste_total">'.$langs->trans("Total").'</td>';
  244. print '<td class="liste_total" align="right">'.price($total)."</td>";
  245. print "<td></td></tr>";
  246. print "</table>";
  247. print '</div>';
  248. print '</form>';
  249. $db->free($result);
  250. }
  251. else
  252. {
  253. dol_print_error($db);
  254. }
  255. // End of page
  256. llxFooter();
  257. $db->close();