index.php 11 KB

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