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

/htdocs/compta/charges/index.php

https://github.com/asterix14/dolibarr
PHP | 259 lines | 176 code | 40 blank | 43 comment | 25 complexity | bf8b6e1f7e41c02d249cd45209c6acc7 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-2010 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/charges/index.php
  21. * \ingroup compta
  22. * \brief Page to list payments of social contributions and vat
  23. */
  24. require("../../main.inc.php");
  25. require_once(DOL_DOCUMENT_ROOT."/compta/tva/class/tva.class.php");
  26. require_once(DOL_DOCUMENT_ROOT."/compta/sociales/class/chargesociales.class.php");
  27. require_once(DOL_DOCUMENT_ROOT."/compta/sociales/class/paymentsocialcontribution.class.php");
  28. require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php");
  29. $langs->load("compta");
  30. // Security check
  31. if ($user->societe_id) $socid=$user->societe_id;
  32. $result = restrictedArea($user, 'tax', '', '', 'charges');
  33. $year=$_GET["year"];
  34. $filtre=$_GET["filtre"];
  35. if (! $year && $_GET["mode"] != 'sconly') { $year=date("Y", time()); }
  36. $sortfield = isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"];
  37. $sortorder = isset($_GET["sortorder"])?$_GET["sortorder"]:$_POST["sortorder"];
  38. $page = $_GET["page"];
  39. if ($page < 0) $page = 0;
  40. //$limit = $conf->liste_limit;
  41. //$offset = $limit * $page ;
  42. if (! $sortfield) $sortfield="s.date_ech";
  43. if (! $sortorder) $sortorder="DESC";
  44. /*
  45. * View
  46. */
  47. $tva_static = new Tva($db);
  48. $socialcontrib=new ChargeSociales($db);
  49. $payment_sc_static=new PaymentSocialContribution($db);
  50. llxHeader('',$langs->trans("TaxAndDividendsArea"));
  51. $title=$langs->trans("TaxAndDividendsArea");
  52. if ($_GET["mode"] == 'sconly') $title=$langs->trans("SocialContributionsPayments");
  53. print_fiche_titre($title,($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>":""));
  54. if ($_GET["mode"] != 'sconly')
  55. {
  56. print $langs->trans("DescTaxAndDividendsArea").'<br>';
  57. print "<br>";
  58. }
  59. // Social contributions
  60. if ($_GET["mode"] != 'sconly')
  61. {
  62. print_titre($langs->trans("SocialContributionsPayments"));
  63. }
  64. if ($_GET["mode"] == 'sconly')
  65. {
  66. $param='&mode=sconly';
  67. }
  68. print '<table class="noborder" width="100%">';
  69. print "<tr class=\"liste_titre\">";
  70. print_liste_field_titre($langs->trans("PeriodEndDate"),$_SERVER["PHP_SELF"],"s.date_ech","",$param,'width="120"',$sortfield,$sortorder);
  71. print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"c.libelle","",$param,'',$sortfield,$sortorder);
  72. print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"s.fk_type","",$param,'',$sortfield,$sortorder);
  73. print_liste_field_titre($langs->trans("ExpectedToPay"),$_SERVER["PHP_SELF"],"s.amount","",$param,'align="right"',$sortfield,$sortorder);
  74. print_liste_field_titre($langs->trans("RefPayment"),$_SERVER["PHP_SELF"],"pid","",$param,'',$sortfield,$sortorder);
  75. print_liste_field_titre($langs->trans("DatePayment"),$_SERVER["PHP_SELF"],"datep","",$param,'align="center"',$sortfield,$sortorder);
  76. print_liste_field_titre($langs->trans("PayedByThisPayment"),$_SERVER["PHP_SELF"],"pc.amount","",$param,'align="right"',$sortfield,$sortorder);
  77. print "</tr>\n";
  78. $sql = "SELECT c.id, c.libelle as lib,";
  79. $sql.= " s.rowid, s.libelle, s.fk_type as type, s.periode, s.date_ech, s.amount as total,";
  80. $sql.= " pc.rowid as pid, pc.datep, pc.amount as totalpaye";
  81. $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,";
  82. $sql.= " ".MAIN_DB_PREFIX."chargesociales as s";
  83. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = s.rowid";
  84. $sql.= " WHERE s.fk_type = c.id";
  85. $sql.= " AND s.entity = ".$conf->entity;
  86. if ($year > 0)
  87. {
  88. $sql .= " AND (";
  89. // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance,
  90. // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire
  91. $sql .= " (s.periode is not null and s.periode between '".$db->idate(dol_get_first_day($year))."' AND '".$db->idate(dol_get_last_day($year))."')";
  92. $sql .= "or (s.periode is null and s.date_ech between '".$db->idate(dol_get_first_day($year))."' AND '".$db->idate(dol_get_last_day($year))."')";
  93. $sql .= ")";
  94. }
  95. $sql.= $db->order($sortfield,$sortorder);
  96. //$sql.= $db->plimit($limit+1,$offset);
  97. //print $sql;
  98. dol_syslog("compta/charges/index.php: select payment sql=".$sql);
  99. $resql=$db->query($sql);
  100. if ($resql)
  101. {
  102. $num = $db->num_rows($resql);
  103. $i = 0;
  104. $total = 0;
  105. $totalnb = 0;
  106. $totalpaye = 0;
  107. $var=true;
  108. while ($i < $num)
  109. {
  110. $obj = $db->fetch_object($resql);
  111. $var = !$var;
  112. print "<tr $bc[$var]>";
  113. // Date
  114. $date=$obj->periode;
  115. if (empty($date)) $date=$obj->date_ech;
  116. print '<td>'.dol_print_date($date,'day').'</td>';
  117. // Label
  118. print '<td>';
  119. $socialcontrib->id=$obj->rowid;
  120. $socialcontrib->ref=$obj->libelle;
  121. $socialcontrib->lib=$obj->libelle;
  122. print $socialcontrib->getNomUrl(1,'20');
  123. print '</td>';
  124. // Type
  125. print '<td><a href="../sociales/index.php?filtre=s.fk_type:'.$obj->type.'">'.$obj->lib.'</a></td>';
  126. // Expected to pay
  127. print '<td align="right">'.price($obj->total).'</td>';
  128. // Ref payment
  129. $payment_sc_static->id=$obj->pid;
  130. $payment_sc_static->ref=$obj->pid;
  131. print '<td>'.$payment_sc_static->getNomUrl(1)."</td>\n";
  132. // Date payment
  133. print '<td align="center">'.dol_print_date($db->jdate($obj->datep),'day').'</td>';
  134. // Paid
  135. print '<td align="right">'.price($obj->totalpaye).'</td>';
  136. print '</tr>';
  137. $total = $total + $obj->total;
  138. $totalnb = $totalnb + $obj->nb;
  139. $totalpaye = $totalpaye + $obj->totalpaye;
  140. $i++;
  141. }
  142. print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("Total").'</td>';
  143. print '<td align="right">'.price($total)."</td>";
  144. print '<td align="center">&nbsp;</td>';
  145. print '<td align="center">&nbsp;</td>';
  146. print '<td align="right">'.price($totalpaye)."</td>";
  147. print "</tr>";
  148. }
  149. else
  150. {
  151. dol_print_error($db);
  152. }
  153. print '</table>';
  154. // VAT
  155. if (empty($_GET["mode"]) || $_GET["mode"] != 'sconly')
  156. {
  157. print "<br>";
  158. $tva = new Tva($db);
  159. print_titre($langs->trans("VATPayments"));
  160. $sql = "SELECT f.rowid, f.amount, f.label, f.datev as dm";
  161. $sql.= " FROM ".MAIN_DB_PREFIX."tva as f ";
  162. $sql.= " WHERE f.entity = ".$conf->entity;
  163. if ($year > 0)
  164. {
  165. // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance,
  166. // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire
  167. $sql.= " AND f.datev between '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
  168. }
  169. $sql.= " ORDER BY dm DESC";
  170. $result = $db->query($sql);
  171. if ($result)
  172. {
  173. $num = $db->num_rows($result);
  174. $i = 0;
  175. $total = 0 ;
  176. print '<table class="noborder" width="100%">';
  177. print '<tr class="liste_titre">';
  178. print '<td width="120" nowrap="nowrap">'.$langs->trans("PeriodEndDate").'</td>';
  179. print "<td>".$langs->trans("Label")."</td>";
  180. print '<td align="right" width="10%">'.$langs->trans("ExpectedToPay")."</td>";
  181. print '<td align="right" width="10%">'.$langs->trans("RefPayment")."</td>";
  182. print '<td align="center" width="15%">'.$langs->trans("DatePayment")."</td>";
  183. print '<td align="right" width="10%">'.$langs->trans("PayedByThisPayment")."</td>";
  184. print "</tr>\n";
  185. $var=1;
  186. while ($i < $num)
  187. {
  188. $obj = $db->fetch_object($result);
  189. $total = $total + $obj->amount;
  190. $var=!$var;
  191. print "<tr $bc[$var]>";
  192. print '<td align="left">'.dol_print_date($db->jdate($obj->dm),'day').' ? </td>'."\n";
  193. print "<td>".$obj->label."</td>\n";
  194. print '<td align="right">'.price($obj->amount)."</td>";
  195. $tva_static->id=$obj->rowid;
  196. $tva_static->ref=$obj->rowid;
  197. print '<td align="right">'.$tva_static->getNomUrl(1)."</td>\n";
  198. print '<td align="center">'.dol_print_date($db->jdate($obj->dm),'day')."</td>\n";
  199. print "<td align=\"right\">".price($obj->amount)."</td>";
  200. print "</tr>\n";
  201. $i++;
  202. }
  203. print '<tr class="liste_total"><td align="right" colspan="2">'.$langs->trans("Total").'</td>';
  204. print '<td align="right">'.price($total)."</td>";
  205. print '<td align="center">&nbsp;</td>';
  206. print '<td align="center">&nbsp;</td>';
  207. print '<td align="right">'.price($total)."</td>";
  208. print "</tr>";
  209. print "</table>";
  210. $db->free($result);
  211. }
  212. else
  213. {
  214. dol_print_error($db);
  215. }
  216. }
  217. $db->close();
  218. llxFooter();
  219. ?>