PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/compta/sociales/index.php

https://github.com/asterix14/dolibarr
PHP | 229 lines | 151 code | 43 blank | 35 comment | 20 complexity | b3fceb823d2d007418a07155ed6a6f76 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.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 2 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/sociales/index.php
  21. * \ingroup tax
  22. * \brief Page to list all social contributions
  23. */
  24. require('../../main.inc.php');
  25. require(DOL_DOCUMENT_ROOT."/compta/sociales/class/chargesociales.class.php");
  26. // Security check
  27. $socid = isset($_GET["socid"])?$_GET["socid"]:'';
  28. if ($user->societe_id) $socid=$user->societe_id;
  29. $result = restrictedArea($user, 'tax', '', '', 'charges');
  30. $sortfield = GETPOST("sortfield",'alpha');
  31. $sortorder = GETPOST("sortorder",'alpha');
  32. $page = GETPOST("page",'int');
  33. if ($page == -1) { $page = 0; }
  34. $offset = $conf->liste_limit * $page;
  35. $pageprev = $page - 1;
  36. $pagenext = $page + 1;
  37. $limit = $conf->liste_limit;
  38. if (! $sortfield) $sortfield="s.date_ech";
  39. if (! $sortorder) $sortorder="DESC";
  40. $year=$_GET["year"];
  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_type') $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. $sql = "SELECT s.rowid as id, s.fk_type as type, ";
  62. $sql.= " s.amount, s.date_ech, s.libelle, s.paye, s.periode,";
  63. $sql.= " c.libelle as type_lib";
  64. $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
  65. $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s";
  66. $sql.= " WHERE s.fk_type = c.id";
  67. $sql.= " AND s.entity = ".$conf->entity;
  68. if (GETPOST("search_label")) $sql.=" AND s.libelle like '%".GETPOST("search_label")."%'";
  69. if ($year > 0)
  70. {
  71. $sql .= " AND (";
  72. // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance,
  73. // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire
  74. $sql .= " (s.periode is not null and date_format(s.periode, '%Y') = '".$year."') ";
  75. $sql .= "or (s.periode is null and date_format(s.date_ech, '%Y') = '".$year."')";
  76. $sql .= ")";
  77. }
  78. if ($filtre) {
  79. $filtre=str_replace(":","=",$filtre);
  80. $sql .= " AND ".$filtre;
  81. }
  82. if ($typeid) {
  83. $sql .= " AND s.fk_type=".$typeid;
  84. }
  85. $sql.= $db->order($sortfield,$sortorder);
  86. $sql.= $db->plimit($limit+1,$offset);
  87. $chargesociale_static=new ChargeSociales($db);
  88. $resql=$db->query($sql);
  89. if ($resql)
  90. {
  91. $num = $db->num_rows($resql);
  92. $i = 0;
  93. $var=true;
  94. $param='';
  95. if ($year) $param.='&amp;year='.$year;
  96. if ($typeid) $param.='&amp;typeid='.$typeid;
  97. if ($year)
  98. {
  99. print_fiche_titre($langs->trans("SocialContributions"),($year?"<a href='index.php?year=".($year-1)."'>".img_previous()."</a> ".$langs->trans("Year")." $year <a href='index.php?year=".($year+1)."'>".img_next()."</a>":""));
  100. }
  101. else
  102. {
  103. print_barre_liste($langs->trans("SocialContributions"),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$totalnboflines);
  104. }
  105. dol_htmloutput_mesg($mesg);
  106. if (empty($mysoc->country_id) && empty($mysoc->country_code))
  107. {
  108. print '<div class="error">';
  109. $langs->load("errors");
  110. $countrynotdefined=$langs->trans("ErrorSetACountryFirst");
  111. print $countrynotdefined;
  112. print '</div>';
  113. }
  114. else
  115. {
  116. print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
  117. print "<table class=\"noborder\" width=\"100%\">";
  118. print "<tr class=\"liste_titre\">";
  119. print_liste_field_titre($langs->trans("Ref"),"index.php","id","",$param,"",$sortfield,$sortorder);
  120. print_liste_field_titre($langs->trans("Label"),"index.php","s.libelle","",$param,'align="left"',$sortfield,$sortorder);
  121. print_liste_field_titre($langs->trans("Type"),"index.php","type","",$param,'align="left"',$sortfield,$sortorder);
  122. print_liste_field_titre($langs->trans("PeriodEndDate"),"index.php","periode","",$param,'align="center"',$sortfield,$sortorder);
  123. print_liste_field_titre($langs->trans("Amount"),"index.php","s.amount","",$param,'align="right"',$sortfield,$sortorder);
  124. print_liste_field_titre($langs->trans("DateDue"),"index.php","s.date_ech","",$param,'align="center"',$sortfield,$sortorder);
  125. print_liste_field_titre($langs->trans("Status"),"index.php","s.paye","",$param,'align="right"',$sortfield,$sortorder);
  126. print "</tr>\n";
  127. print '<tr class="liste_titre">';
  128. print '<td class="liste_titre">&nbsp;</td>';
  129. print '<td class="liste_titre"><input type="text" class="flat" size="8" name="search_label" value="'.GETPOST("search_label").'"></td>';
  130. // Type
  131. print '<td class="liste_titre" align="left">';
  132. $form->select_type_socialcontrib($typeid,'typeid',1,16,0);
  133. print '</td>';
  134. // Period end date
  135. print '<td class="liste_titre">&nbsp;</td>';
  136. print '<td class="liste_titre">&nbsp;</td>';
  137. print '<td class="liste_titre">&nbsp;</td>';
  138. print '<td class="liste_titre" align="right">';
  139. print '<input type="image" class="liste_titre" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" name="button_search" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
  140. print '</td>';
  141. print "</tr>\n";
  142. while ($i < min($num,$limit))
  143. {
  144. $obj = $db->fetch_object($resql);
  145. $var = !$var;
  146. print "<tr $bc[$var]>";
  147. // Ref
  148. print '<td width="60">';
  149. $chargesociale_static->id=$obj->id;
  150. $chargesociale_static->lib=$obj->id;
  151. $chargesociale_static->ref=$obj->id;
  152. print $chargesociale_static->getNomUrl(1,'20');
  153. print '</td>';
  154. // Label
  155. print '<td>'.dol_trunc($obj->libelle,42).'</td>';
  156. // Type
  157. print '<td>'.dol_trunc($obj->type_lib,16).'</td>';
  158. // Date end period
  159. print '<td align="center">';
  160. if ($obj->periode)
  161. {
  162. print '<a href="index.php?year='.strftime("%Y",$db->jdate($obj->periode)).'">'.dol_print_date($db->jdate($obj->periode),'day').'</a>';
  163. }
  164. else
  165. {
  166. print '&nbsp;';
  167. }
  168. print '</td>';
  169. print '<td align="right" width="100">'.price($obj->amount).'</td>';
  170. // Due date
  171. print '<td width="110" align="center">'.dol_print_date($db->jdate($obj->date_ech), 'day').'</td>';
  172. print '<td align="right" nowrap="nowrap">'.$chargesociale_static->LibStatut($obj->paye,5).'</a></td>';
  173. print '</tr>';
  174. $i++;
  175. }
  176. print '</table>';
  177. print '</form>';
  178. }
  179. }
  180. else
  181. {
  182. dol_print_error($db);
  183. }
  184. $db->close();
  185. llxFooter();
  186. ?>