index.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /* Copyright (C) 2011-2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/compta/salaries/index.php
  19. * \ingroup salaries
  20. * \brief List of salaries payments
  21. */
  22. require '../../main.inc.php';
  23. require_once DOL_DOCUMENT_ROOT.'/compta/salaries/class/paymentsalary.class.php';
  24. $langs->load("compta");
  25. $langs->load("salaries");
  26. $langs->load("bills");
  27. // Security check
  28. $socid = GETPOST("socid","int");
  29. if ($user->societe_id) $socid=$user->societe_id;
  30. $result = restrictedArea($user, 'salaries', '', '', '');
  31. $sortfield = GETPOST("sortfield",'alpha');
  32. $sortorder = GETPOST("sortorder",'alpha');
  33. $page = GETPOST("page",'int');
  34. if ($page == -1) { $page = 0; }
  35. $offset = $conf->liste_limit * $page;
  36. $pageprev = $page - 1;
  37. $pagenext = $page + 1;
  38. $limit = $conf->liste_limit;
  39. if (! $sortfield) $sortfield="s.datev";
  40. if (! $sortorder) $sortorder="DESC";
  41. $filtre=$_GET["filtre"];
  42. if (empty($_REQUEST['typeid']))
  43. {
  44. $newfiltre=str_replace('filtre=','',$filtre);
  45. $filterarray=explode('-',$newfiltre);
  46. foreach($filterarray as $val)
  47. {
  48. $part=explode(':',$val);
  49. if ($part[0] == 's.fk_typepayment') $typeid=$part[1];
  50. }
  51. }
  52. else
  53. {
  54. $typeid=$_REQUEST['typeid'];
  55. }
  56. /*
  57. * View
  58. */
  59. llxHeader();
  60. $form = new Form($db);
  61. $salstatic = new PaymentSalary($db);
  62. $userstatic = new User($db);
  63. $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, s.rowid, s.fk_user, s.amount, s.label, s.datev as dm, s.fk_typepayment as type,";
  64. $sql.= " s.num_payment, pst.code as payment_code";
  65. $sql.= " FROM ".MAIN_DB_PREFIX."payment_salary as s";
  66. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON s.fk_typepayment = pst.id,";
  67. $sql.= " ".MAIN_DB_PREFIX."user as u";
  68. $sql.= " WHERE u.rowid = s.fk_user";
  69. $sql.= " AND s.entity = ".$conf->entity;
  70. if (GETPOST("search_label")) $sql.=" AND s.label LIKE '%".$db->escape(GETPOST("search_label"))."%'";
  71. if (GETPOST("search_amount")) $sql.=" AND s.amount = ".price2num(GETPOST("search_amount"));
  72. if ($filtre) {
  73. $filtre=str_replace(":","=",$filtre);
  74. $sql .= " AND ".$filtre;
  75. }
  76. if ($typeid) {
  77. $sql .= " AND s.fk_typepayment=".$typeid;
  78. }
  79. $sql.= " GROUP BY s.rowid, s.fk_typepayment, s.amount, s.datev, s.label";
  80. $sql.= $db->order($sortfield,$sortorder);
  81. $sql.= $db->plimit($limit+1,$offset);
  82. $result = $db->query($sql);
  83. if ($result)
  84. {
  85. $num = $db->num_rows($result);
  86. $i = 0;
  87. $total = 0 ;
  88. $var=true;
  89. $param='';
  90. if ($typeid) $param.='&amp;typeid='.$typeid;
  91. print_barre_liste($langs->trans("SalariesPayments"),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$totalnboflines);
  92. dol_htmloutput_mesg($mesg);
  93. print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
  94. print '<table class="noborder" width="100%">';
  95. print '<tr class="liste_titre">';
  96. print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"s.rowid","",$param,"",$sortfield,$sortorder);
  97. print_liste_field_titre($langs->trans("Person"),$_SERVER["PHP_SELF"],"u.rowid","",$param,"",$sortfield,$sortorder);
  98. print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"s.label","",$param,'align="left"',$sortfield,$sortorder);
  99. print_liste_field_titre($langs->trans("DatePayment"),$_SERVER["PHP_SELF"],"s.datev","",$param,'align="left"',$sortfield,$sortorder);
  100. print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"type","",$param,'align="left"',$sortfield,$sortorder);
  101. print_liste_field_titre($langs->trans("PayedByThisPayment"),$_SERVER["PHP_SELF"],"s.amount","",$param,'align="right"',$sortfield,$sortorder);
  102. print_liste_field_titre("");
  103. print "</tr>\n";
  104. print '<tr class="liste_titre">';
  105. print '<td class="liste_titre">&nbsp;</td>';
  106. print '<td class="liste_titre">&nbsp;</td>';
  107. print '<td class="liste_titre"><input type="text" class="flat" size="14" name="search_label" value="'.GETPOST("search_label").'"></td>';
  108. print '<td class="liste_titre">&nbsp;</td>';
  109. // Type
  110. print '<td class="liste_titre" align="left">';
  111. $form->select_types_paiements($typeid,'typeid','',0,0,1,16);
  112. print '</td>';
  113. print '<td class="liste_titre" align="right"><input name="search_amount" class="flat" type="text" size="8" value="'.GETPOST("search_amount").'"></td>';
  114. print '<td class="liste_titre" align="right">';
  115. print '<input type="image" class="liste_titre" src="'.img_picto($langs->trans("Search"),'search.png','','',1).'" name="button_search" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
  116. print '</td>';
  117. print "</tr>\n";
  118. while ($i < min($num,$limit))
  119. {
  120. $obj = $db->fetch_object($result);
  121. $var=!$var;
  122. print "<tr ".$bc[$var].">";
  123. $userstatic->id=$obj->uid;
  124. $userstatic->lastname=$obj->lastname;
  125. $userstatic->firstname=$obj->firstname;
  126. $salstatic->id=$obj->rowid;
  127. $salstatic->ref=$obj->rowid;
  128. print "<td>".$salstatic->getNomUrl(1)."</td>\n";
  129. print "<td>".$userstatic->getNomUrl(1)."</td>\n";
  130. print "<td>".dol_trunc($obj->label,40)."</td>\n";
  131. print '<td align="left">'.dol_print_date($db->jdate($obj->dm),'day')."</td>\n";
  132. // Type
  133. print '<td>'.$langs->trans("PaymentTypeShort".$obj->payment_code).' '.$obj->num_payment.'</td>';
  134. // Amount
  135. print "<td align=\"right\">".price($obj->amount,0,$outputlangs,1,-1,-1,$conf->currency)."</td>";
  136. print "<td>&nbsp;</td>";
  137. print "</tr>\n";
  138. $total = $total + $obj->amount;
  139. $i++;
  140. }
  141. print '<tr class="liste_total"><td colspan="5" class="liste_total">'.$langs->trans("Total").'</td>';
  142. print '<td class="liste_total" align="right">'.price($total,0,$outputlangs,1,-1,-1,$conf->currency)."</td>";
  143. print "<td>&nbsp;</td></tr>";
  144. print "</table>";
  145. print '</form>';
  146. $db->free($result);
  147. }
  148. else
  149. {
  150. dol_print_error($db);
  151. }
  152. $db->close();
  153. llxFooter();