index.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <?php
  2. /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2016 Frédéric France <frederic.france@free.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/compta/sociales/index.php
  22. * \ingroup tax
  23. * \brief Page to list all social contributions
  24. */
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsocialcontrib.class.php';
  28. $langs->load("compta");
  29. $langs->load("banks");
  30. $langs->load("bills");
  31. // Security check
  32. $socid = isset($_GET["socid"])?$_GET["socid"]:'';
  33. if ($user->societe_id) $socid=$user->societe_id;
  34. $result = restrictedArea($user, 'tax', '', '', 'charges');
  35. $search_ref = GETPOST('search_ref','int');
  36. $search_label = GETPOST('search_label','alpha');
  37. $search_amount = GETPOST('search_amount','alpha');
  38. $search_status = GETPOST('search_status','int');
  39. $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
  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 = $limit * $page;
  45. $pageprev = $page - 1;
  46. $pagenext = $page + 1;
  47. if (! $sortfield) $sortfield="cs.date_ech";
  48. if (! $sortorder) $sortorder="DESC";
  49. $year=GETPOST("year",'int');
  50. $filtre=GETPOST("filtre",'int');
  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] == 'cs.fk_type') $typeid=$part[1];
  59. }
  60. }
  61. else
  62. {
  63. $typeid=$_REQUEST['typeid'];
  64. }
  65. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All test are required to be compatible with all browsers
  66. {
  67. $search_ref="";
  68. $search_label="";
  69. $search_amount="";
  70. $search_status='';
  71. $typeid="";
  72. $year="";
  73. $month="";
  74. }
  75. /*
  76. * View
  77. */
  78. $form = new Form($db);
  79. $formsocialcontrib = new FormSocialContrib($db);
  80. $chargesociale_static=new ChargeSociales($db);
  81. llxHeader('', $langs->trans("SocialContributions"));
  82. $sql = "SELECT cs.rowid as id, cs.fk_type as type, ";
  83. $sql.= " cs.amount, cs.date_ech, cs.libelle, cs.paye, cs.periode,";
  84. $sql.= " c.libelle as type_lib,";
  85. $sql.= " SUM(pc.amount) as alreadypayed";
  86. $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,";
  87. $sql.= " ".MAIN_DB_PREFIX."chargesociales as cs";
  88. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = cs.rowid";
  89. $sql.= " WHERE cs.fk_type = c.id";
  90. $sql.= " AND cs.entity = ".$conf->entity;
  91. // Search criteria
  92. if ($search_ref) $sql.=" AND cs.rowid=".$db->escape($search_ref);
  93. if ($search_label) $sql.=natural_search("cs.libelle", $search_label);
  94. if ($search_amount) $sql.=natural_search("cs.amount", price2num(trim($search_amount)), 1);
  95. if ($search_status != '' && $search_status >= 0) $sql.=" AND cs.paye = ".$db->escape($search_status);
  96. if ($year > 0)
  97. {
  98. $sql .= " AND (";
  99. // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance,
  100. // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire
  101. $sql .= " (cs.periode IS NOT NULL AND date_format(cs.periode, '%Y') = '".$year."') ";
  102. $sql .= "OR (cs.periode IS NULL AND date_format(cs.date_ech, '%Y') = '".$year."')";
  103. $sql .= ")";
  104. }
  105. if ($filtre) {
  106. $filtre=str_replace(":","=",$filtre);
  107. $sql .= " AND ".$filtre;
  108. }
  109. if ($typeid) {
  110. $sql .= " AND cs.fk_type=".$db->escape($typeid);
  111. }
  112. $sql.= " GROUP BY cs.rowid, cs.fk_type, cs.amount, cs.date_ech, cs.libelle, cs.paye, cs.periode, c.libelle";
  113. $sql.= $db->order($sortfield,$sortorder);
  114. $totalnboflines=0;
  115. $result=$db->query($sql);
  116. if ($result)
  117. {
  118. $totalnboflines = $db->num_rows($result);
  119. }
  120. $sql.= $db->plimit($limit+1,$offset);
  121. $resql=$db->query($sql);
  122. if ($resql)
  123. {
  124. $num = $db->num_rows($resql);
  125. $i = 0;
  126. $var=true;
  127. $param='';
  128. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  129. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  130. if ($year) $param.='&amp;year='.$year;
  131. if ($typeid) $param.='&amp;typeid='.$typeid;
  132. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  133. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  134. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  135. print '<input type="hidden" name="action" value="list">';
  136. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  137. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  138. print '<input type="hidden" name="page" value="'.$page.'">';
  139. print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
  140. if ($year)
  141. {
  142. $center=($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>":"");
  143. print_barre_liste($langs->trans("SocialContributions"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $center, $num, $totalnboflines, 'title_accountancy.png', 0, '', '', $limit);
  144. }
  145. else
  146. {
  147. print_barre_liste($langs->trans("SocialContributions"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, 'title_accountancy.png', 0, '', '', $limit);
  148. }
  149. if (empty($mysoc->country_id) && empty($mysoc->country_code))
  150. {
  151. print '<div class="error">';
  152. $langs->load("errors");
  153. $countrynotdefined=$langs->trans("ErrorSetACountryFirst");
  154. print $countrynotdefined;
  155. print '</div>';
  156. }
  157. else
  158. {
  159. print '<div class="div-table-responsive">';
  160. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  161. print '<tr class="liste_titre_filter">';
  162. // Ref
  163. print '<td class="liste_titre" align="left">';
  164. print '<input class="flat" type="text" size="3" name="search_ref" value="'.$search_ref.'">';
  165. print '</td>';
  166. // Label
  167. print '<td class="liste_titre"><input type="text" class="flat" size="8" name="search_label" value="'.$search_label.'"></td>';
  168. // Type
  169. print '<td class="liste_titre" align="left">';
  170. $formsocialcontrib->select_type_socialcontrib($typeid,'typeid',1,16,0);
  171. print '</td>';
  172. // Period end date
  173. print '<td class="liste_titre">&nbsp;</td>';
  174. // Amount
  175. print '<td class="liste_titre" align="right">';
  176. print '<input class="flat" type="text" size="6" name="search_amount" value="'.$search_amount.'">';
  177. print '</td>';
  178. print '<td class="liste_titre">&nbsp;</td>';
  179. // Status
  180. print '<td class="liste_titre maxwidthonsmartphone" align="right">';
  181. $liststatus=array('0'=>$langs->trans("Unpaid"), '1'=>$langs->trans("Paid"));
  182. print $form->selectarray('search_status', $liststatus, $search_status, 1);
  183. print '</td>';
  184. print '<td class="liste_titre" align="right">';
  185. $searchpicto=$form->showFilterAndCheckAddButtons(0);
  186. print $searchpicto;
  187. print '</td>';
  188. print "</tr>\n";
  189. print '<tr class="liste_titre">';
  190. print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"id","",$param,"",$sortfield,$sortorder);
  191. print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"cs.libelle","",$param,'align="left"',$sortfield,$sortorder);
  192. print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"type","",$param,'align="left"',$sortfield,$sortorder);
  193. print_liste_field_titre($langs->trans("PeriodEndDate"),$_SERVER["PHP_SELF"],"periode","",$param,'align="center"',$sortfield,$sortorder);
  194. print_liste_field_titre($langs->trans("Amount"),$_SERVER["PHP_SELF"],"cs.amount","",$param,'align="right"',$sortfield,$sortorder);
  195. print_liste_field_titre($langs->trans("DateDue"),$_SERVER["PHP_SELF"],"cs.date_ech","",$param,'align="center"',$sortfield,$sortorder);
  196. print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"cs.paye","",$param,'align="right"',$sortfield,$sortorder);
  197. print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
  198. print "</tr>\n";
  199. $i=0;
  200. $totalarray=array();
  201. while ($i < min($num,$limit))
  202. {
  203. $obj = $db->fetch_object($resql);
  204. print '<tr class="oddeven">';
  205. // Ref
  206. print '<td width="60">';
  207. $chargesociale_static->id=$obj->id;
  208. $chargesociale_static->lib=$obj->id;
  209. $chargesociale_static->ref=$obj->id;
  210. print $chargesociale_static->getNomUrl(1,'20');
  211. print '</td>';
  212. // Label
  213. print '<td>'.dol_trunc($obj->libelle,42).'</td>';
  214. // Type
  215. print '<td>'.$obj->type_lib.'</td>';
  216. // Date end period
  217. print '<td align="center">';
  218. if ($obj->periode)
  219. {
  220. print '<a href="index.php?year='.strftime("%Y",$db->jdate($obj->periode)).'">'.dol_print_date($db->jdate($obj->periode),'day').'</a>';
  221. }
  222. else
  223. {
  224. print '&nbsp;';
  225. }
  226. print '</td>';
  227. // Amount
  228. print '<td align="right" width="100">'.price($obj->amount).'</td>';
  229. if (! $i) $totalarray['nbfield']++;
  230. if (! $i) $totalarray['totalttcfield']=$totalarray['nbfield'];
  231. $totalarray['totalttc'] += $obj->amount;
  232. // Due date
  233. print '<td width="110" align="center">'.dol_print_date($db->jdate($obj->date_ech), 'day').'</td>';
  234. print '<td align="right" class="nowrap">'.$chargesociale_static->LibStatut($obj->paye,5,$obj->alreadypayed).'</td>';
  235. print '<td></td>';
  236. print '</tr>';
  237. $i++;
  238. }
  239. // Show total line
  240. if (isset($totalarray['totalttcfield']))
  241. {
  242. print '<tr class="liste_total">';
  243. if ($num < $limit && empty($offset)) print '<td align="left">'.$langs->trans("Total").'</td>';
  244. else print '<td align="left">'.$langs->trans("Totalforthispage").'</td>';
  245. print '<td></td>';
  246. print '<td></td>';
  247. print '<td></td>';
  248. print '<td align="right">'.price($totalarray['totalttc']).'</td>';
  249. print '<td></td>';
  250. print '<td></td>';
  251. print '<td></td>';
  252. print '</tr>';
  253. }
  254. print '</table>';
  255. print '</div>';
  256. }
  257. print '</form>';
  258. }
  259. else
  260. {
  261. dol_print_error($db);
  262. }
  263. llxFooter();
  264. $db->close();