dolibarr  7.0.0-beta
index.php
Go to the documentation of this file.
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 
27 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
31 
32 $langs->load("other");
33 $langs->load("compta");
34 $langs->load("banks");
35 $langs->load("bills");
36 
37 $year=GETPOST("year","int");
38 if ($year == 0)
39 {
40  $year_current = strftime("%Y",time());
41  $year_start = $year_current;
42 } else {
43  $year_current = $year;
44  $year_start = $year;
45 }
46 
47 // Security check
48 $socid = isset($_GET["socid"])?$_GET["socid"]:'';
49 if ($user->societe_id) $socid=$user->societe_id;
50 $result = restrictedArea($user, 'tax', '', '', 'charges');
51 
52 // Define modetax (0 or 1)
53 // 0=normal, 1=option vat for services is on debit
54 $modetax = $conf->global->TAX_MODE;
55 if (isset($_GET["modetax"])) $modetax=$_GET["modetax"];
56 
57 
66 function pt ($db, $sql, $date)
67 {
68  global $conf, $bc,$langs;
69 
70  $result = $db->query($sql);
71  if ($result)
72  {
73  $num = $db->num_rows($result);
74  $i = 0;
75  $total = 0;
76  print '<table class="noborder" width="100%">';
77  print '<tr class="liste_titre">';
78  print '<td class="nowrap" width="60%">'.$date.'</td>';
79  print '<td align="right">'.$langs->trans("Amount").'</td>';
80  print '<td>&nbsp;</td>'."\n";
81  print "</tr>\n";
82  $var=True;
83  while ($i < $num)
84  {
85  $obj = $db->fetch_object($result);
86 
87  print '<tr class="oddeven">';
88  print '<td class="nowrap">'.$obj->dm."</td>\n";
89  $total = $total + $obj->mm;
90 
91  print '<td class="nowrap" align="right">'.price($obj->mm)."</td><td >&nbsp;</td>\n";
92  print "</tr>\n";
93 
94  $i++;
95  }
96  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>";
97 
98  print "</table>";
99  $db->free($result);
100  }
101  else {
102  dol_print_error($db);
103  }
104 }
105 
106 
107 /*
108  * View
109  */
110 
111 llxHeader();
112 
113 $tva = new Tva($db);
114 
115 
116 $textprevyear="<a href=\"index.php?year=" . ($year_current-1) . "\">".img_previous($langs->trans("Previous"), 'class="valignbottom"')."</a>";
117 $textnextyear=" <a href=\"index.php?year=" . ($year_current+1) . "\">".img_next($langs->trans("Next"), 'class="valignbottom"')."</a>";
118 
119 print $conf->dol_optimize_smallscreen;
120 print load_fiche_titre($langs->transcountry("VAT", $mysoc->country_code), $textprevyear." ".$langs->trans("Year")." ".$year_start." ".$textnextyear, 'title_accountancy.png');
121 
122 print $langs->trans("VATReportBuildWithOptionDefinedInModule").'<br>';
123 print '('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')<br>';
124 print '<br>';
125 
126 print '<div class="fichecenter"><div class="fichethirdleft">';
127 
128 print load_fiche_titre($langs->trans("VATSummary"), '', '');
129 
130 print '<table class="noborder" width="100%">';
131 print '<tr class="liste_titre">';
132 print '<td width="30%">'.$langs->trans("Year")." ".$y.'</td>';
133 print '<td align="right">'.$langs->trans("VATToPay").'</td>';
134 print '<td align="right">'.$langs->trans("VATToCollect").'</td>';
135 print '<td align="right">'.$langs->trans("TotalToPay").'</td>';
136 print '<td>&nbsp;</td>'."\n";
137 print '</tr>'."\n";
138 
139 
140 $y = $year_current ;
141 
142 
143 $var=True;
144 $total=0; $subtotalcoll=0; $subtotalpaye=0; $subtotal=0;
145 $i=0;
146 for ($m = 1 ; $m < 13 ; $m++ )
147 {
148  $coll_listsell = vat_by_date($db, $y, 0, 0, 0, $modetax, 'sell', $m);
149  $coll_listbuy = vat_by_date($db, $y, 0, 0, 0, $modetax, 'buy', $m);
150 
151  $action = "tva";
152  $object = array(&$coll_listsell, &$coll_listbuy);
153  $parameters["mode"] = $modetax;
154  $parameters["year"] = $y;
155  $parameters["month"] = $m;
156  $parameters["type"] = 'vat';
157 
158  // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
159  $hookmanager->initHooks(array('externalbalance'));
160  $reshook=$hookmanager->executeHooks('addVatLine',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
161 
162  if (! is_array($coll_listbuy) && $coll_listbuy == -1)
163  {
164  $langs->load("errors");
165  print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
166  break;
167  }
168  if (! is_array($coll_listbuy) && $coll_listbuy == -2)
169  {
170  print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
171  break;
172  }
173 
174 
175  print '<tr class="oddeven">';
176  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>';
177 
178  $x_coll = 0;
179  foreach($coll_listsell as $vatrate=>$val)
180  {
181  $x_coll+=$val['vat'];
182  }
183  $subtotalcoll = $subtotalcoll + $x_coll;
184  print "<td class=\"nowrap\" align=\"right\">".price($x_coll)."</td>";
185 
186  $x_paye = 0;
187  foreach($coll_listbuy as $vatrate=>$val)
188  {
189  $x_paye+=$val['vat'];
190  }
191  $subtotalpaye = $subtotalpaye + $x_paye;
192  print "<td class=\"nowrap\" align=\"right\">".price($x_paye)."</td>";
193 
194  $diff = $x_coll - $x_paye;
195  $total = $total + $diff;
196  $subtotal = $subtotal + $diff;
197 
198  print "<td class=\"nowrap\" align=\"right\">".price($diff)."</td>\n";
199  print "<td>&nbsp;</td>\n";
200  print "</tr>\n";
201 
202  $i++;
203  if ($i > 2) {
204  print '<tr class="liste_total">';
205  print '<td align="right"><a href="quadri_detail.php?leftmenu=tax_vat&q='.($m/3).'&year='.$y.'">'.$langs->trans("SubTotal").'</a>:</td>';
206  print '<td class="nowrap" align="right">'.price($subtotalcoll).'</td>';
207  print '<td class="nowrap" align="right">'.price($subtotalpaye).'</td>';
208  print '<td class="nowrap" align="right">'.price($subtotal).'</td>';
209  print '<td>&nbsp;</td></tr>';
210  $i = 0;
211  $subtotalcoll=0; $subtotalpaye=0; $subtotal=0;
212  }
213 }
214 print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("TotalToPay").':</td><td class="nowrap" align="right">'.price($total).'</td>';
215 print "<td>&nbsp;</td>\n";
216 print '</tr>';
217 
218 print '</table>';
219 
220 
221 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
222 
223 
224 print load_fiche_titre($langs->trans("VATPaid"), '', '');
225 
226 /*
227  * Payed
228  */
229 
230 $sql = "SELECT SUM(amount) as mm, date_format(f.datep,'%Y-%m') as dm";
231 $sql.= " FROM ".MAIN_DB_PREFIX."tva as f";
232 $sql.= " WHERE f.entity = ".$conf->entity;
233 $sql.= " AND f.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
234 $sql.= " AND f.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
235 $sql.= " GROUP BY dm ORDER BY dm ASC";
236 
237 pt($db, $sql,$langs->trans("Year")." $y");
238 
239 
240 print '<br>';
241 
242 
243 
244 if (! empty($conf->global->MAIN_FEATURES_LEVEL))
245 {
246  /*
247  * Recap
248  */
249 
250  print load_fiche_titre($langs->trans("VATRecap"), '', ''); // need to add translation
251 
252  $sql1 = "SELECT SUM(amount) as mm, date_format(f.datev,'%Y') as dm";
253  $sql1 .= " FROM " . MAIN_DB_PREFIX . "tva as f";
254  $sql1 .= " WHERE f.entity = " . $conf->entity;
255  $sql1 .= " AND f.datev >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'";
256  $sql1 .= " AND f.datev <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'";
257  $sql1 .= " GROUP BY dm ORDER BY dm ASC";
258 
259  $result = $db->query($sql1);
260  if ($result) {
261  $obj = $db->fetch_object($result);
262  print '<table class="noborder" width="100%">';
263 
264  print "<tr>";
265  print '<td align="right">' . $langs->trans("VATDue") . '</td>'; // need to add translation
266  print '<td class="nowrap" align="right">' . price(price2num($total, 'MT')) . '</td>';
267  print "</tr>\n";
268 
269  print "<tr>";
270  print '<td align="right">' . $langs->trans("VATPaid") . '</td>';
271  print '<td class="nowrap" align="right">' . price(price2num($obj->mm, 'MT')) . "</td>\n";
272  print "</tr>\n";
273 
274  $restopay = $total - $obj->mm;
275  print "<tr>";
276  print '<td align="right">' . $langs->trans("VATRestopay") . '</td>'; // need to add translation
277  print '<td class="nowrap" align="right">' . price(price2num($restopay, 'MT')) . '</td>';
278  print "</tr>\n";
279 
280  print '</table>';
281  }
282 }
283 
284 print '</div></div>';
285 
286 llxFooter();
287 $db->close();
llxFooter()
Footer empty.
Definition: index.php:43
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
img_previous($titlealt= 'default', $moreatt='')
Show previous logo.
img_next($titlealt= 'default', $moreatt='')
Show next logo.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:445
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Put here description of your class.
Definition: tva.class.php:33
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
llxHeader()
Header empty.
Definition: index.php:37
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:459
pt($db, $sql, $date)
print function
Definition: index.php:66
print
Draft customers invoices.
Definition: index.php:91
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.
vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction, $m=0)
Gets VAT to collect for the given year (and given quarter or month) The function gets the VAT in spli...
Definition: tax.lib.php:643