dolibarr  7.0.0-beta
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2011-2014 Juanjo Menent <jmenent@2byte.es>
3  * Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
24 require '../../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
26 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
28 
29 $langs->load("other");
30 $langs->load("compta");
31 $langs->load("banks");
32 $langs->load("bills");
33 
34 $localTaxType=GETPOST('localTaxType', 'int');
35 
36 $year=GETPOST("year","int");
37 if ($year == 0)
38 {
39  $year_current = strftime("%Y",time());
40  $year_start = $year_current;
41 } else {
42  $year_current = $year;
43  $year_start = $year;
44 }
45 
46 // Security check
47 $socid = isset($_GET["socid"])?$_GET["socid"]:'';
48 if ($user->societe_id)
49  $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"]))
56  $modetax=$_GET["modetax"];
57 
66 function pt ($db, $sql, $date)
67 {
68  global $conf, $bc,$langs;
69 
70  $result = $db->query($sql);
71  if ($result) {
72  $num = $db->num_rows($result);
73  $i = 0;
74  $total = 0;
75  print '<table class="noborder" width="100%">';
76  print '<tr class="liste_titre">';
77  print '<td class="nowrap" width="60%">'.$date.'</td>';
78  print '<td align="right">'.$langs->trans("Amount").'</td>';
79  print '<td>&nbsp;</td>'."\n";
80  print "</tr>\n";
81  $var=True;
82  while ($i < $num) {
83  $obj = $db->fetch_object($result);
84 
85  print '<tr class="oddeven">';
86  print '<td class="nowrap">'.$obj->dm."</td>\n";
87  $total = $total + $obj->mm;
88 
89  print '<td class="nowrap" align="right">'.price($obj->mm)."</td><td >&nbsp;</td>\n";
90  print "</tr>\n";
91 
92  $i++;
93  }
94  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>";
95 
96  print "</table>";
97  $db->free($result);
98  } else {
99  dol_print_error($db);
100  }
101 }
102 
103 
104 /*
105  * View
106  */
107 
108 llxHeader();
109 
110 if($localTaxType==1) {
111  $LT='LT1';
112  $LTSummary='LT1Summary';
113  $LTPaid='LT1Paid';
114  $LTCustomer='LT1Customer';
115  $LTSupplier='LT1Supplier';
116  $CalcLT= $conf->global->MAIN_INFO_LOCALTAX_CALC1;
117 } else {
118  $LT='LT2';
119  $LTSummary='LT2Summary';
120  $LTPaid='LT2Paid';
121  $LTCustomer='LT2Customer';
122  $LTSupplier='LT2Supplier';
123  $CalcLT= $conf->global->MAIN_INFO_LOCALTAX_CALC2;
124 }
125 
126 
127 $textprevyear="<a href=\"index.php?localTaxType=".$localTaxType."&year=" . ($year_current-1) . "\">".img_previous()."</a>";
128 $textnextyear=" <a href=\"index.php?localTaxType=".$localTaxType."&year=" . ($year_current+1) . "\">".img_next()."</a>";
129 
130 print load_fiche_titre($langs->transcountry($LT,$mysoc->country_code),"$textprevyear ".$langs->trans("Year")." $year_start $textnextyear", 'title_accountancy.png');
131 
132 print $langs->trans("LTReportBuildWithOptionDefinedInModule").'<br>';
133 print '('.$langs->trans("TaxModuleSetupToModifyRulesLT",DOL_URL_ROOT.'/admin/company.php').')<br>';
134 print '<br>';
135 
136 print '<table width="100%" class="notopnoleftnoright">';
137 print '<tr><td class="notopnoleft width="50%">';
138 print load_fiche_titre($langs->transcountry($LTSummary,$mysoc->country_code), '', '');
139 print '</td><td>&nbsp;</td><td>';
140 print load_fiche_titre($langs->transcountry($LTPaid,$mysoc->country_code), '', '');
141 print '</td></tr>';
142 
143 print '<tr><td class="notopnoleft" width="50%" valign="top">';
144 
145 print '<table class="noborder" width="100%">';
146 print '<tr class="liste_titre">';
147 print '<td width="30%">'.$langs->trans("Year")." ".$y."</td>";
148 if($CalcLT==0) {
149  print "<td align=\"right\">".$langs->transcountry($LTCustomer,$mysoc->country_code)."</td>";
150  print "<td align=\"right\">".$langs->transcountry($LTSupplier,$mysoc->country_code)."</td>";
151 }
152 if($CalcLT==1) {
153  print "<td align=\"right\">".$langs->transcountry($LTSupplier,$mysoc->country_code)."</td><td></td>";
154 }
155 if($CalcLT==2) {
156  print "<td align=\"right\">".$langs->transcountry($LTCustomer,$mysoc->country_code)."</td><td></td>";
157 }
158 
159 print "<td align=\"right\">".$langs->trans("TotalToPay")."</td>";
160 print "<td>&nbsp;</td>\n";
161 print "</tr>\n";
162 
163 $y = $year_current ;
164 
165 $var=True;
166 $total=0; $subtotalcoll=0; $subtotalpaye=0; $subtotal=0;
167 $i=0;
168 for ($m = 1 ; $m < 13 ; $m++ ) {
169  $coll_listsell = vat_by_date($db, $y, 0, 0, 0, $modetax, 'sell', $m);
170  $coll_listbuy = vat_by_date($db, $y, 0, 0, 0, $modetax, 'buy', $m);
171 
172  $action = "tva";
173  $object = array(&$coll_listsell, &$coll_listbuy);
174  $parameters["mode"] = $modetax;
175  $parameters["year"] = $y;
176  $parameters["month"] = $m;
177  $parameters["type"] = 'localtax'.$localTaxType;
178 
179  // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
180  $hookmanager->initHooks(array('externalbalance'));
181  $reshook=$hookmanager->executeHooks('addVatLine',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
182 
183  if (! is_array($coll_listbuy) && $coll_listbuy == -1) {
184  $langs->load("errors");
185  print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
186  break;
187  }
188  if (! is_array($coll_listbuy) && $coll_listbuy == -2) {
189  print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
190  break;
191  }
192 
193 
194  print '<tr class="oddeven">';
195  print '<td class="nowrap">'.dol_print_date(dol_mktime(0,0,0,$m,1,$y),"%b %Y").'</td>';
196  if($CalcLT==0) {
197  $x_coll = 0;
198  foreach($coll_listsell as $vatrate=>$val) {
199  $x_coll+=$val[$localTaxType==1?'localtax1':'localtax2'];
200  }
201  $subtotalcoll = $subtotalcoll + $x_coll;
202  print "<td class=\"nowrap\" align=\"right\">".price($x_coll)."</td>";
203 
204  $x_paye = 0;
205  foreach($coll_listbuy as $vatrate=>$val) {
206  $x_paye+=$val[$localTaxType==1?'localtax1':'localtax2'];
207  }
208  $subtotalpaye = $subtotalpaye + $x_paye;
209  print "<td class=\"nowrap\" align=\"right\">".price($x_paye)."</td>";
210  } elseif($CalcLT==1) {
211  $x_paye = 0;
212  foreach($coll_listbuy as $vatrate=>$val) {
213  $x_paye+=$val[$localTaxType==1?'localtax1':'localtax2'];
214  }
215  $subtotalpaye = $subtotalpaye + $x_paye;
216  print "<td class=\"nowrap\" align=\"right\">".price($x_paye)."</td><td></td>";
217  } elseif($CalcLT==2) {
218  $x_coll = 0;
219  foreach($coll_listsell as $vatrate=>$val) {
220  $x_coll+=$val[$localTaxType==1?'localtax1':'localtax2'];
221  }
222  $subtotalcoll = $subtotalcoll + $x_coll;
223  print "<td class=\"nowrap\" align=\"right\">".price($x_coll)."</td><td></td>";
224 
225  }
226 
227  if($CalcLT==0) {
228  $diff= $x_coll - $x_paye;
229  } elseif($CalcLT==1) {
230  $diff= $x_paye;
231  } elseif($CalcLT==2) {
232  $diff= $x_coll;
233  }
234 
235  $total = $total + $diff;
236  $subtotal = $subtotal + $diff;
237 
238  print "<td class=\"nowrap\" align=\"right\">".price($diff)."</td>\n";
239  print "<td>&nbsp;</td>\n";
240  print "</tr>\n";
241 
242  $i++;
243  if ($i > 2) {
244  print '<tr class="liste_total">';
245  print '<td align="right">'.$langs->trans("SubTotal").':</td>';
246  if($CalcLT==0) {
247  print '<td class="nowrap" align="right">'.price($subtotalcoll).'</td>';
248  print '<td class="nowrap" align="right">'.price($subtotalpaye).'</td>';
249  print '<td class="nowrap" align="right">'.price($subtotal).'</td>';
250  } elseif($CalcLT==1) {
251  print '<td class="nowrap" align="right">'.price($subtotalpaye).'</td><td></td>';
252  print '<td class="nowrap" align="right">'.price($subtotal).'</td>';
253  } elseif($CalcLT==2) {
254  print '<td class="nowrap" align="right">'.price($subtotalcoll).'</td><td></td>';
255  print '<td class="nowrap" align="right">'.price($subtotal).'</td>';
256  }
257  print '<td>&nbsp;</td></tr>';
258  $i = 0;
259  $subtotalcoll=0; $subtotalpaye=0; $subtotal=0;
260  }
261 }
262 print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("TotalToPay").':</td><td class="nowrap" align="right">'.price($total).'</td>';
263 print "<td>&nbsp;</td>\n";
264 print '</tr>';
265 
266 print '</table>';
267 
268 print '</td><td>&nbsp;</td><td valign="top" width="50%">';
269 
270 /*
271  * Payed
272  */
273 
274 $sql = "SELECT SUM(amount) as mm, date_format(f.datev,'%Y-%m') as dm";
275 $sql.= " FROM ".MAIN_DB_PREFIX."localtax as f";
276 $sql.= " WHERE f.entity = ".$conf->entity;
277 $sql.= " AND f.datev >= '".$db->idate(dol_get_first_day($y,1,false))."'";
278 $sql.= " AND f.datev <= '".$db->idate(dol_get_last_day($y,12,false))."'";
279 $sql.= " AND localtaxtype=".$localTaxType;
280 $sql.= " GROUP BY dm";
281 $sql.= " ORDER BY dm ASC";
282 
283 pt($db, $sql,$langs->trans("Year")." $y");
284 
285 print '</td></tr></table>';
286 
287 print '</td></tr>';
288 print '</table>';
289 
290 llxFooter();
291 $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...
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_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
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