PageRenderTime 26ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/compta/tva/index.php

https://bitbucket.org/speedealing/speedealing
PHP | 239 lines | 151 code | 47 blank | 41 comment | 16 complexity | c2fc7cacc9986a34ab4fc95b2ec5a1c2 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  4. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
  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/tva/index.php
  22. * \ingroup tax
  23. * \brief Index page of VAT reports
  24. */
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  29. $langs->load("other");
  30. $year=$_GET["year"];
  31. if ($year == 0 )
  32. {
  33. $year_current = strftime("%Y",time());
  34. $year_start = $year_current;
  35. } else {
  36. $year_current = $year;
  37. $year_start = $year;
  38. }
  39. // Security check
  40. $socid = isset($_GET["socid"])?$_GET["socid"]:'';
  41. if ($user->societe_id) $socid=$user->societe_id;
  42. $result = restrictedArea($user, 'tax', '', '', 'charges');
  43. // Define modetax (0 or 1)
  44. // 0=normal, 1=option vat for services is on debit
  45. $modetax = $conf->global->TAX_MODE;
  46. if (isset($_GET["modetax"])) $modetax=$_GET["modetax"];
  47. function pt ($db, $sql, $date)
  48. {
  49. global $conf, $bc,$langs;
  50. $result = $db->query($sql);
  51. if ($result)
  52. {
  53. $num = $db->num_rows($result);
  54. $i = 0;
  55. $total = 0;
  56. print '<table class="noborder" width="100%">';
  57. print '<tr class="liste_titre">';
  58. print '<td nowrap="nowrap" width="60%">'.$date.'</td>';
  59. print '<td align="right">'.$langs->trans("Amount").'</td>';
  60. print '<td>&nbsp;</td>'."\n";
  61. print "</tr>\n";
  62. $var=True;
  63. while ($i < $num)
  64. {
  65. $obj = $db->fetch_object($result);
  66. $var=!$var;
  67. print '<tr '.$bc[$var].'>';
  68. print '<td nowrap="nowrap">'.$obj->dm."</td>\n";
  69. $total = $total + $obj->mm;
  70. print '<td nowrap="nowrap" align="right">'.price($obj->mm)."</td><td >&nbsp;</td>\n";
  71. print "</tr>\n";
  72. $i++;
  73. }
  74. print '<tr class="liste_total"><td align="right">'.$langs->trans("Total")." :</td><td nowrap=\"nowrap\" align=\"right\"><b>".price($total)."</b></td><td>&nbsp;</td></tr>";
  75. print "</table>";
  76. $db->free($result);
  77. }
  78. else {
  79. dolibar_print_error($db);
  80. }
  81. }
  82. /*
  83. * View
  84. */
  85. llxHeader();
  86. $tva = new Tva($db);
  87. $textprevyear="<a href=\"index.php?year=" . ($year_current-1) . "\">".img_previous()."</a>";
  88. $textnextyear=" <a href=\"index.php?year=" . ($year_current+1) . "\">".img_next()."</a>";
  89. print_fiche_titre($langs->trans("VAT"),"$textprevyear ".$langs->trans("Year")." $year_start $textnextyear");
  90. print $langs->trans("VATReportBuildWithOptionDefinedInModule").'<br>';
  91. print '('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')<br>';
  92. print '<br>';
  93. echo '<table width="100%" class="notopnoleftnoright">';
  94. echo '<tr><td class="notopnoleft" width="50%">';
  95. print_titre($langs->trans("VATSummary"));
  96. // The report mode is the one defined by defaut in tax module setup
  97. //print $modetax;
  98. //print '('.$langs->trans("SeeVATReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modetax=0">','</a>').')';
  99. echo '</td><td>';
  100. print_titre($langs->trans("VATPaid"));
  101. echo '</td></tr>';
  102. echo '<tr><td class="notopnoleft" width="50%" valign="top">';
  103. print '<table class="noborder" width="100%">';
  104. print '<tr class="liste_titre">';
  105. print '<td width="30%">'.$langs->trans("Year")." ".$y.'</td>';
  106. print '<td align="right">'.$langs->trans("VATToPay").'</td>';
  107. print '<td align="right">'.$langs->trans("VATToCollect").'</td>';
  108. print '<td align="right">'.$langs->trans("TotalToPay").'</td>';
  109. print '<td>&nbsp;</td>'."\n";
  110. print '</tr>'."\n";
  111. $y = $year_current ;
  112. $var=True;
  113. $total=0; $subtotalcoll=0; $subtotalpaye=0; $subtotal=0;
  114. $i=0;
  115. for ($m = 1 ; $m < 13 ; $m++ )
  116. {
  117. $coll_listsell = vat_by_date($db, $y, 0, 0, 0, $modetax, 'sell', $m);
  118. $coll_listbuy = vat_by_date($db, $y, 0, 0, 0, $modetax, 'buy', $m);
  119. if (! is_array($coll_listbuy) && $coll_listbuy == -1)
  120. {
  121. $langs->load("errors");
  122. print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
  123. break;
  124. }
  125. if (! is_array($coll_listbuy) && $coll_listbuy == -2)
  126. {
  127. print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
  128. break;
  129. }
  130. $var=!$var;
  131. print "<tr $bc[$var]>";
  132. print '<td nowrap><a href="quadri_detail.php?leftmenu=tax_vat&month='.$m.'&year='.$y.'">'.dol_print_date(dol_mktime(0,0,0,$m,1,$y),"%b %Y").'</a></td>';
  133. $x_coll = 0;
  134. foreach($coll_listsell as $vatrate=>$val)
  135. {
  136. $x_coll+=$val['vat'];
  137. }
  138. $subtotalcoll = $subtotalcoll + $x_coll;
  139. print "<td nowrap align=\"right\">".price($x_coll)."</td>";
  140. $x_paye = 0;
  141. foreach($coll_listbuy as $vatrate=>$val)
  142. {
  143. $x_paye+=$val['vat'];
  144. }
  145. $subtotalpaye = $subtotalpaye + $x_paye;
  146. print "<td nowrap align=\"right\">".price($x_paye)."</td>";
  147. $diff = $x_coll - $x_paye;
  148. $total = $total + $diff;
  149. $subtotal = $subtotal + $diff;
  150. print "<td nowrap align=\"right\">".price($diff)."</td>\n";
  151. print "<td>&nbsp;</td>\n";
  152. print "</tr>\n";
  153. $i++;
  154. if ($i > 2) {
  155. print '<tr class="liste_total">';
  156. print '<td align="right"><a href="quadri_detail.php?leftmenu=tax_vat&q='.($m/3).'&year='.$y.'">'.$langs->trans("SubTotal").'</a>:</td>';
  157. print '<td nowrap="nowrap" align="right">'.price($subtotalcoll).'</td>';
  158. print '<td nowrap="nowrap" align="right">'.price($subtotalpaye).'</td>';
  159. print '<td nowrap="nowrap" align="right">'.price($subtotal).'</td>';
  160. print '<td>&nbsp;</td></tr>';
  161. $i = 0;
  162. $subtotalcoll=0; $subtotalpaye=0; $subtotal=0;
  163. }
  164. }
  165. print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("TotalToPay").':</td><td nowrap align="right">'.price($total).'</td>';
  166. print "<td>&nbsp;</td>\n";
  167. print '</tr>';
  168. /*}
  169. else
  170. {
  171. print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
  172. print '<tr><td colspan="5">'.$langs->trans("FeatureIsSupportedInInOutModeOnly").'</td></tr>';
  173. }*/
  174. print '</table>';
  175. echo '</td>';
  176. print '<td class="notopnoleftnoright" valign="top" width="50%">';
  177. /*
  178. * Payed
  179. */
  180. $sql = "SELECT SUM(amount) as mm, date_format(f.datev,'%Y-%m') as dm";
  181. $sql.= " FROM ".MAIN_DB_PREFIX."tva as f";
  182. $sql.= " WHERE f.entity = ".$conf->entity;
  183. $sql.= " AND f.datev >= '".$db->idate(dol_get_first_day($y,1,false))."'";
  184. $sql.= " AND f.datev <= '".$db->idate(dol_get_last_day($y,12,false))."'";
  185. $sql.= " GROUP BY dm ASC";
  186. pt($db, $sql,$langs->trans("Year")." $y");
  187. print "</td></tr></table>";
  188. echo '</td></tr>';
  189. echo '</table>';
  190. $db->close();
  191. llxFooter();
  192. ?>