index.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. * Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/compta/tva/index.php
  23. * \ingroup tax
  24. * \brief Index page of VAT reports
  25. */
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  30. $langs->load("other");
  31. $langs->load("compta");
  32. $langs->load("banks");
  33. $langs->load("bills");
  34. $year=GETPOST("year","int");
  35. if ($year == 0)
  36. {
  37. $year_current = strftime("%Y",time());
  38. $year_start = $year_current;
  39. } else {
  40. $year_current = $year;
  41. $year_start = $year;
  42. }
  43. // Security check
  44. $socid = isset($_GET["socid"])?$_GET["socid"]:'';
  45. if ($user->societe_id) $socid=$user->societe_id;
  46. $result = restrictedArea($user, 'tax', '', '', 'charges');
  47. // Define modetax (0 or 1)
  48. // 0=normal, 1=option vat for services is on debit
  49. $modetax = $conf->global->TAX_MODE;
  50. if (isset($_GET["modetax"])) $modetax=$_GET["modetax"];
  51. /**
  52. * print function
  53. *
  54. * @param DoliDB $db Database handler
  55. * @param string $sql SQL Request
  56. * @param string $date Date
  57. * @return void
  58. */
  59. function pt ($db, $sql, $date)
  60. {
  61. global $conf, $bc,$langs;
  62. $result = $db->query($sql);
  63. if ($result)
  64. {
  65. $num = $db->num_rows($result);
  66. $i = 0;
  67. $total = 0;
  68. print '<table class="noborder" width="100%">';
  69. print '<tr class="liste_titre">';
  70. print '<td class="nowrap" width="60%">'.$date.'</td>';
  71. print '<td align="right">'.$langs->trans("Amount").'</td>';
  72. print '<td>&nbsp;</td>'."\n";
  73. print "</tr>\n";
  74. $var=True;
  75. while ($i < $num)
  76. {
  77. $obj = $db->fetch_object($result);
  78. print '<tr class="oddeven">';
  79. print '<td class="nowrap">'.$obj->dm."</td>\n";
  80. $total = $total + $obj->mm;
  81. print '<td class="nowrap" align="right">'.price($obj->mm)."</td><td >&nbsp;</td>\n";
  82. print "</tr>\n";
  83. $i++;
  84. }
  85. print '<tr class="liste_total"><td align="right">'.$langs->trans("Total")." :</td><td class=\"nowrap\" align=\"right\"><b>".price($total)."</b></td><td>&nbsp;</td></tr>";
  86. print "</table>";
  87. $db->free($result);
  88. }
  89. else {
  90. dol_print_error($db);
  91. }
  92. }
  93. /*
  94. * View
  95. */
  96. llxHeader();
  97. $tva = new Tva($db);
  98. $textprevyear="<a href=\"index.php?year=" . ($year_current-1) . "\">".img_previous($langs->trans("Previous"), 'class="valignbottom"')."</a>";
  99. $textnextyear=" <a href=\"index.php?year=" . ($year_current+1) . "\">".img_next($langs->trans("Next"), 'class="valignbottom"')."</a>";
  100. print $conf->dol_optimize_smallscreen;
  101. print load_fiche_titre($langs->transcountry("VAT", $mysoc->country_code), $textprevyear." ".$langs->trans("Year")." ".$year_start." ".$textnextyear, 'title_accountancy.png');
  102. print $langs->trans("VATReportBuildWithOptionDefinedInModule").'<br>';
  103. print '('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')<br>';
  104. print '<br>';
  105. print '<div class="fichecenter"><div class="fichethirdleft">';
  106. print load_fiche_titre($langs->trans("VATSummary"), '', '');
  107. print '<table class="noborder" width="100%">';
  108. print '<tr class="liste_titre">';
  109. print '<td width="30%">'.$langs->trans("Year")." ".$y.'</td>';
  110. print '<td align="right">'.$langs->trans("VATToPay").'</td>';
  111. print '<td align="right">'.$langs->trans("VATToCollect").'</td>';
  112. print '<td align="right">'.$langs->trans("TotalToPay").'</td>';
  113. print '<td>&nbsp;</td>'."\n";
  114. print '</tr>'."\n";
  115. $y = $year_current ;
  116. $var=True;
  117. $total=0; $subtotalcoll=0; $subtotalpaye=0; $subtotal=0;
  118. $i=0;
  119. for ($m = 1 ; $m < 13 ; $m++ )
  120. {
  121. $coll_listsell = vat_by_date($db, $y, 0, 0, 0, $modetax, 'sell', $m);
  122. $coll_listbuy = vat_by_date($db, $y, 0, 0, 0, $modetax, 'buy', $m);
  123. $action = "tva";
  124. $object = array(&$coll_listsell, &$coll_listbuy);
  125. $parameters["mode"] = $modetax;
  126. $parameters["year"] = $y;
  127. $parameters["month"] = $m;
  128. $parameters["type"] = 'vat';
  129. // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
  130. $hookmanager->initHooks(array('externalbalance'));
  131. $reshook=$hookmanager->executeHooks('addVatLine',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  132. if (! is_array($coll_listbuy) && $coll_listbuy == -1)
  133. {
  134. $langs->load("errors");
  135. print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
  136. break;
  137. }
  138. if (! is_array($coll_listbuy) && $coll_listbuy == -2)
  139. {
  140. print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
  141. break;
  142. }
  143. print '<tr class="oddeven">';
  144. print '<td class="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>';
  145. $x_coll = 0;
  146. foreach($coll_listsell as $vatrate=>$val)
  147. {
  148. $x_coll+=$val['vat'];
  149. }
  150. $subtotalcoll = $subtotalcoll + $x_coll;
  151. print "<td class=\"nowrap\" align=\"right\">".price($x_coll)."</td>";
  152. $x_paye = 0;
  153. foreach($coll_listbuy as $vatrate=>$val)
  154. {
  155. $x_paye+=$val['vat'];
  156. }
  157. $subtotalpaye = $subtotalpaye + $x_paye;
  158. print "<td class=\"nowrap\" align=\"right\">".price($x_paye)."</td>";
  159. $diff = $x_coll - $x_paye;
  160. $total = $total + $diff;
  161. $subtotal = $subtotal + $diff;
  162. print "<td class=\"nowrap\" align=\"right\">".price($diff)."</td>\n";
  163. print "<td>&nbsp;</td>\n";
  164. print "</tr>\n";
  165. $i++;
  166. if ($i > 2) {
  167. print '<tr class="liste_total">';
  168. print '<td align="right"><a href="quadri_detail.php?leftmenu=tax_vat&q='.($m/3).'&year='.$y.'">'.$langs->trans("SubTotal").'</a>:</td>';
  169. print '<td class="nowrap" align="right">'.price($subtotalcoll).'</td>';
  170. print '<td class="nowrap" align="right">'.price($subtotalpaye).'</td>';
  171. print '<td class="nowrap" align="right">'.price($subtotal).'</td>';
  172. print '<td>&nbsp;</td></tr>';
  173. $i = 0;
  174. $subtotalcoll=0; $subtotalpaye=0; $subtotal=0;
  175. }
  176. }
  177. print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("TotalToPay").':</td><td class="nowrap" align="right">'.price($total).'</td>';
  178. print "<td>&nbsp;</td>\n";
  179. print '</tr>';
  180. print '</table>';
  181. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  182. print load_fiche_titre($langs->trans("VATPaid"), '', '');
  183. /*
  184. * Payed
  185. */
  186. $sql = "SELECT SUM(amount) as mm, date_format(f.datep,'%Y-%m') as dm";
  187. $sql.= " FROM ".MAIN_DB_PREFIX."tva as f";
  188. $sql.= " WHERE f.entity = ".$conf->entity;
  189. $sql.= " AND f.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
  190. $sql.= " AND f.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
  191. $sql.= " GROUP BY dm ORDER BY dm ASC";
  192. pt($db, $sql,$langs->trans("Year")." $y");
  193. print '<br>';
  194. if (! empty($conf->global->MAIN_FEATURES_LEVEL))
  195. {
  196. /*
  197. * Recap
  198. */
  199. print load_fiche_titre($langs->trans("VATRecap"), '', ''); // need to add translation
  200. $sql1 = "SELECT SUM(amount) as mm, date_format(f.datev,'%Y') as dm";
  201. $sql1 .= " FROM " . MAIN_DB_PREFIX . "tva as f";
  202. $sql1 .= " WHERE f.entity = " . $conf->entity;
  203. $sql1 .= " AND f.datev >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'";
  204. $sql1 .= " AND f.datev <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'";
  205. $sql1 .= " GROUP BY dm ORDER BY dm ASC";
  206. $result = $db->query($sql1);
  207. if ($result) {
  208. $obj = $db->fetch_object($result);
  209. print '<table class="noborder" width="100%">';
  210. print "<tr>";
  211. print '<td align="right">' . $langs->trans("VATDue") . '</td>'; // need to add translation
  212. print '<td class="nowrap" align="right">' . price(price2num($total, 'MT')) . '</td>';
  213. print "</tr>\n";
  214. print "<tr>";
  215. print '<td align="right">' . $langs->trans("VATPaid") . '</td>';
  216. print '<td class="nowrap" align="right">' . price(price2num($obj->mm, 'MT')) . "</td>\n";
  217. print "</tr>\n";
  218. $restopay = $total - $obj->mm;
  219. print "<tr>";
  220. print '<td align="right">' . $langs->trans("VATRestopay") . '</td>'; // need to add translation
  221. print '<td class="nowrap" align="right">' . price(price2num($restopay, 'MT')) . '</td>';
  222. print "</tr>\n";
  223. print '</table>';
  224. }
  225. }
  226. print '</div></div>';
  227. llxFooter();
  228. $db->close();