dolibarr  9.0.0
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-2018 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
7  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
28 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php';
34 
35 // Load translation files required by the page
36 $langs->loadLangs(array("other","compta","banks","bills","companies","product","trips","admin"));
37 
38 // Date range
39 $year=GETPOST("year","int");
40 if (empty($year))
41 {
42  $year_current = strftime("%Y",dol_now());
43  $year_start = $year_current;
44 } else {
45  $year_current = $year;
46  $year_start = $year;
47 }
48 $date_start=dol_mktime(0,0,0,GETPOST("date_startmonth"),GETPOST("date_startday"),GETPOST("date_startyear"));
49 $date_end=dol_mktime(23,59,59,GETPOST("date_endmonth"),GETPOST("date_endday"),GETPOST("date_endyear"));
50 if (empty($date_start) || empty($date_end)) // We define date_start and date_end
51 {
52  $q=GETPOST("q","int");
53  if (empty($q))
54  {
55  if (GETPOST("month","int")) { $date_start=dol_get_first_day($year_start,GETPOST("month","int"),false); $date_end=dol_get_last_day($year_start,GETPOST("month","int"),false); }
56  else
57  {
58  $date_start=dol_get_first_day($year_start, $conf->global->SOCIETE_FISCAL_MONTH_START,false);
59  $date_end=dol_time_plus_duree($date_start, 1, 'y') - 1;
60  }
61  }
62  else
63  {
64  if ($q==1) { $date_start=dol_get_first_day($year_start,1,false); $date_end=dol_get_last_day($year_start,3,false); }
65  if ($q==2) { $date_start=dol_get_first_day($year_start,4,false); $date_end=dol_get_last_day($year_start,6,false); }
66  if ($q==3) { $date_start=dol_get_first_day($year_start,7,false); $date_end=dol_get_last_day($year_start,9,false); }
67  if ($q==4) { $date_start=dol_get_first_day($year_start,10,false); $date_end=dol_get_last_day($year_start,12,false); }
68  }
69 }
70 
71 // Define modetax (0 or 1)
72 // 0=normal, 1=option vat for services is on debit, 2=option on payments for products
73 $modetax = $conf->global->TAX_MODE;
74 if (GETPOSTISSET("modetax")) $modetax=GETPOST("modetax",'int');
75 if (empty($modetax)) $modetax=0;
76 
77 // Security check
78 $socid = GETPOST('socid','int');
79 if ($user->societe_id) $socid=$user->societe_id;
80 $result = restrictedArea($user, 'tax', '', '', 'charges');
81 
82 
91 function pt($db, $sql, $date)
92 {
93  global $conf, $bc,$langs;
94 
95  $result = $db->query($sql);
96  if ($result) {
97  $num = $db->num_rows($result);
98  $i = 0;
99  $total = 0;
100  print '<table class="noborder" width="100%">';
101 
102  print '<tr class="liste_titre">';
103  print '<td class="nowrap">'.$date.'</td>';
104  print '<td align="right">'.$langs->trans("ClaimedForThisPeriod").'</td>';
105  print '<td align="right">'.$langs->trans("PaidDuringThisPeriod").'</td>';
106  print "</tr>\n";
107 
108  $totalclaimed = 0;
109  $totalpaid = 0;
110  $amountclaimed = 0;
111  $amountpaid = 0;
112  $previousmonth = '';
113  $previousmode = '';
114  $mode = '';
115 
116  while ($i < $num) {
117  $obj = $db->fetch_object($result);
118  $mode = $obj->mode;
119 
120  //print $obj->dm.' '.$obj->mode.' '.$previousmonth.' '.$previousmode;
121  if ($obj->mode == 'claimed' && ! empty($previousmode))
122  {
123  print '<tr class="oddeven">';
124  print '<td class="nowrap">'.$previousmonth."</td>\n";
125  print '<td class="nowrap" align="right">'.price($amountclaimed)."</td>\n";
126  print '<td class="nowrap" align="right">'.price($amountpaid)."</td>\n";
127  print "</tr>\n";
128 
129  $amountclaimed = 0;
130  $amountpaid = 0;
131  }
132 
133  if ($obj->mode == 'claimed')
134  {
135  $amountclaimed = $obj->mm;
136  $totalclaimed = $totalclaimed + $amountclaimed;
137  }
138  if ($obj->mode == 'paid')
139  {
140  $amountpaid = $obj->mm;
141  $totalpaid = $totalpaid + $amountpaid;
142  }
143 
144  if ($obj->mode == 'paid')
145  {
146  print '<tr class="oddeven">';
147  print '<td class="nowrap">'.$obj->dm."</td>\n";
148  print '<td class="nowrap" align="right">'.price($amountclaimed)."</td>\n";
149  print '<td class="nowrap" align="right">'.price($amountpaid)."</td>\n";
150  print "</tr>\n";
151  $amountclaimed = 0;
152  $amountpaid = 0;
153  $previousmode = '';
154  $previousmonth = '';
155  }
156  else
157  {
158  $previousmode = $obj->mode;
159  $previousmonth = $obj->dm;
160  }
161 
162  $i++;
163  }
164 
165  if ($mode == 'claimed' && ! empty($previousmode))
166  {
167  print '<tr class="oddeven">';
168  print '<td class="nowrap">'.$previousmonth."</td>\n";
169  print '<td class="nowrap" align="right">'.price($amountclaimed)."</td>\n";
170  print '<td class="nowrap" align="right">'.price($amountpaid)."</td>\n";
171  print "</tr>\n";
172 
173  $amountclaimed = 0;
174  $amountpaid = 0;
175  }
176 
177  print '<tr class="liste_total">';
178  print '<td align="right">'.$langs->trans("Total").'</td>';
179  print '<td class="nowrap" align="right">'.price($totalclaimed).'</td>';
180  print '<td class="nowrap" align="right">'.price($totalpaid).'</td>';
181  print "</tr>";
182 
183  print "</table>";
184 
185  $db->free($result);
186  }
187  else {
188  dol_print_error($db);
189  }
190 }
191 
192 
193 /*
194  * View
195  */
196 
197 $form=new Form($db);
198 $company_static=new Societe($db);
199 $tva = new Tva($db);
200 
201 $description = '';
202 
203 // Show report header
204 $name = $langs->trans("ReportByMonth");
205 $calcmode='';
206 if ($modetax == 0) $calcmode=$langs->trans('OptionVATDefault');
207 if ($modetax == 1) $calcmode=$langs->trans('OptionVATDebitOption');
208 if ($modetax == 2) $calcmode=$langs->trans('OptionPaymentForProductAndServices');
209 $calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
210 
211 $description = $langs->trans("VATSummary").'<br>';
212 if ($conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') $description.=$langs->trans("RulesVATDueProducts");
213 if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment') $description.=$langs->trans("RulesVATInProducts");
214 if ($conf->global->TAX_MODE_SELL_SERVICE == 'invoice') $description.='<br>'.$langs->trans("RulesVATDueServices");
215 if ($conf->global->TAX_MODE_SELL_SERVICE == 'payment') $description.='<br>'.$langs->trans("RulesVATInServices");
216 if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
217  $description.='<br>'.$langs->trans("DepositsAreNotIncluded");
218 }
219 if (! empty($conf->global->MAIN_MODULE_ACCOUNTING)) $description.='<br>'.$langs->trans("ThisIsAnEstimatedValue");
220 
221 $period=$form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
222 
223 $builddate=dol_now();
224 
225 
226 llxHeader('', $name);
227 
228 //$textprevyear="<a href=\"index.php?year=" . ($year_current-1) . "\">".img_previous($langs->trans("Previous"), 'class="valignbottom"')."</a>";
229 //$textnextyear=" <a href=\"index.php?year=" . ($year_current+1) . "\">".img_next($langs->trans("Next"), 'class="valignbottom"')."</a>";
230 //print load_fiche_titre($langs->transcountry("VAT", $mysoc->country_code), $textprevyear." ".$langs->trans("Year")." ".$year_start." ".$textnextyear, 'title_accountancy.png');
231 
232 report_header($name,'',$period,$periodlink,$description,$builddate,$exportlink,array(),$calcmode);
233 //report_header($name,'',$textprevyear.$langs->trans("Year")." ".$year_start.$textnextyear,'',$description,$builddate,$exportlink,array(),$calcmode);
234 
235 
236 print '<br>';
237 
238 print '<div class="fichecenter"><div class="fichethirdleft">';
239 
240 print load_fiche_titre($langs->trans("VATSummary"), '', '');
241 
242 print '<table class="noborder" width="100%">';
243 print '<tr class="liste_titre">';
244 print '<td width="30%">'.$langs->trans("Year")." ".$y.'</td>';
245 print '<td align="right">'.$langs->trans("VATToPay").'</td>';
246 print '<td align="right">'.$langs->trans("VATToCollect").'</td>';
247 print '<td align="right">'.$langs->trans("Balance").'</td>';
248 print '<td>&nbsp;</td>'."\n";
249 print '</tr>'."\n";
250 
251 $tmp=dol_getdate($date_start);
252 $y = $tmp['year'];
253 $m = $tmp['mon'];
254 $tmp=dol_getdate($date_end);
255 $yend = $tmp['year'];
256 $mend = $tmp['mon'];
257 //var_dump($m);
258 $total=0; $subtotalcoll=0; $subtotalpaye=0; $subtotal=0;
259 $i=0; $mcursor=0;
260 
261 while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mcursor is to avoid too large loop
262 {
263  //$m = $conf->global->SOCIETE_FISCAL_MONTH_START + ($mcursor % 12);
264  if ($m == 13) $y++;
265  if ($m > 12) $m -= 12;
266  $mcursor++;
267 
268  $x_coll = tax_by_rate('vat', $db, $y, 0, 0, 0, $modetax, 'sell', $m);
269  $x_paye = tax_by_rate('vat', $db, $y, 0, 0, 0, $modetax, 'buy', $m);
270 
271  $x_both = array();
272  //now, from these two arrays, get another array with one rate per line
273  foreach(array_keys($x_coll) as $my_coll_rate)
274  {
275  $x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht'];
276  $x_both[$my_coll_rate]['coll']['vat'] = $x_coll[$my_coll_rate]['vat'];
277  $x_both[$my_coll_rate]['paye']['totalht'] = 0;
278  $x_both[$my_coll_rate]['paye']['vat'] = 0;
279  $x_both[$my_coll_rate]['coll']['links'] = '';
280  $x_both[$my_coll_rate]['coll']['detail'] = array();
281  foreach($x_coll[$my_coll_rate]['facid'] as $id=>$dummy) {
282  //$invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id];
283  //$invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id];
284  //$invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id];
285  //$company_static->fetch($x_coll[$my_coll_rate]['company_id'][$id]);
286  $x_both[$my_coll_rate]['coll']['detail'][] = array(
287  'id' =>$x_coll[$my_coll_rate]['facid'][$id],
288  'descr' =>$x_coll[$my_coll_rate]['descr'][$id],
289  'pid' =>$x_coll[$my_coll_rate]['pid'][$id],
290  'pref' =>$x_coll[$my_coll_rate]['pref'][$id],
291  'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id],
292  'payment_id'=>$x_coll[$my_coll_rate]['payment_id'][$id],
293  'payment_amount'=>$x_coll[$my_coll_rate]['payment_amount'][$id],
294  'ftotal_ttc'=>$x_coll[$my_coll_rate]['ftotal_ttc'][$id],
295  'dtotal_ttc'=>$x_coll[$my_coll_rate]['dtotal_ttc'][$id],
296  'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id],
297  'datef' =>$x_coll[$my_coll_rate]['datef'][$id],
298  'datep' =>$x_coll[$my_coll_rate]['datep'][$id],
299  //'company_link'=>$company_static->getNomUrl(1,'',20),
300  'ddate_start'=>$x_coll[$my_coll_rate]['ddate_start'][$id],
301  'ddate_end' =>$x_coll[$my_coll_rate]['ddate_end'][$id],
302  'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id],
303  'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id],
304  //'link' =>$invoice_customer->getNomUrl(1,'',12)
305  );
306  }
307  }
308 
309  // tva paid
310  foreach (array_keys($x_paye) as $my_paye_rate) {
311  $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht'];
312  $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat'];
313  if (!isset($x_both[$my_paye_rate]['coll']['totalht'])) {
314  $x_both[$my_paye_rate]['coll']['totalht'] = 0;
315  $x_both[$my_paye_rate]['coll']['vat'] = 0;
316  }
317  $x_both[$my_paye_rate]['paye']['links'] = '';
318  $x_both[$my_paye_rate]['paye']['detail'] = array();
319 
320  foreach ($x_paye[$my_paye_rate]['facid'] as $id=>$dummy)
321  {
322  // ExpenseReport
323  if ($x_paye[$my_paye_rate]['ptype'][$id] == 'ExpenseReportPayment')
324  {
325  //$expensereport->id=$x_paye[$my_paye_rate]['facid'][$id];
326  //$expensereport->ref=$x_paye[$my_paye_rate]['facnum'][$id];
327  //$expensereport->type=$x_paye[$my_paye_rate]['type'][$id];
328 
329  $x_both[$my_paye_rate]['paye']['detail'][] = array(
330  'id' =>$x_paye[$my_paye_rate]['facid'][$id],
331  'descr' =>$x_paye[$my_paye_rate]['descr'][$id],
332  'pid' =>$x_paye[$my_paye_rate]['pid'][$id],
333  'pref' =>$x_paye[$my_paye_rate]['pref'][$id],
334  'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id],
335  'payment_id' =>$x_paye[$my_paye_rate]['payment_id'][$id],
336  'payment_amount' =>$x_paye[$my_paye_rate]['payment_amount'][$id],
337  'ftotal_ttc' =>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
338  'dtotal_ttc' =>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
339  'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
340  'ddate_start' =>$x_paye[$my_paye_rate]['ddate_start'][$id],
341  'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
342  'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
343  'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
344  //'link' =>$expensereport->getNomUrl(1)
345  );
346  }
347  else
348  {
349  //$invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id];
350  //$invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id];
351  //$invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id];
352  //$company_static->fetch($x_paye[$my_paye_rate]['company_id'][$id]);
353  $x_both[$my_paye_rate]['paye']['detail'][] = array(
354  'id' =>$x_paye[$my_paye_rate]['facid'][$id],
355  'descr' =>$x_paye[$my_paye_rate]['descr'][$id],
356  'pid' =>$x_paye[$my_paye_rate]['pid'][$id],
357  'pref' =>$x_paye[$my_paye_rate]['pref'][$id],
358  'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id],
359  'payment_id'=>$x_paye[$my_paye_rate]['payment_id'][$id],
360  'payment_amount'=>$x_paye[$my_paye_rate]['payment_amount'][$id],
361  'ftotal_ttc'=>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
362  'dtotal_ttc'=>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
363  'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
364  'datef' =>$x_paye[$my_paye_rate]['datef'][$id],
365  'datep' =>$x_paye[$my_paye_rate]['datep'][$id],
366  //'company_link'=>$company_static->getNomUrl(1,'',20),
367  'ddate_start'=>$x_paye[$my_paye_rate]['ddate_start'][$id],
368  'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
369  'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
370  'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
371  //'link' =>$invoice_supplier->getNomUrl(1,'',12)
372  );
373  }
374  }
375  }
376  //now we have an array (x_both) indexed by rates for coll and paye
377 
378  $action = "tva";
379  $object = array(&$x_coll, &$x_paye, &$x_both);
380  $parameters["mode"] = $modetax;
381  $parameters["year"] = $y;
382  $parameters["month"] = $m;
383  $parameters["type"] = 'vat';
384 
385  // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
386  $hookmanager->initHooks(array('externalbalance'));
387  $reshook=$hookmanager->executeHooks('addVatLine',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
388 
389  if (! is_array($x_coll) && $coll_listbuy == -1)
390  {
391  $langs->load("errors");
392  print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
393  break;
394  }
395  if (! is_array($x_paye) && $coll_listbuy == -2)
396  {
397  print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
398  break;
399  }
400 
401 
402  print '<tr class="oddeven">';
403  print '<td class="nowrap"><a href="'.DOL_URL_ROOT.'/compta/tva/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>';
404 
405  $x_coll_sum = 0;
406  foreach (array_keys($x_coll) as $rate)
407  {
408  $subtot_coll_total_ht = 0;
409  $subtot_coll_vat = 0;
410 
411  foreach ($x_both[$rate]['coll']['detail'] as $index => $fields)
412  {
413  // Payment
414  $ratiopaymentinvoice=1;
415  if ($modetax != 1)
416  {
417  // Define type
418  // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
419  $type=(isset($fields['dtype'])?$fields['dtype']:$fields['ptype']);
420  // Try to enhance type detection using date_start and date_end for free lines where type
421  // was not saved.
422  if (!empty($fields['ddate_start'])) {
423  $type=1;
424  }
425  if (!empty($fields['ddate_end'])) {
426  $type=1;
427  }
428 
429  if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
430  || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice'))
431  {
432  //print $langs->trans("NA");
433  } else {
434  if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
435  $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
436  }
437  }
438  }
439  //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice);
440  $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
441  $temp_vat=$fields['vat']*$ratiopaymentinvoice;
442  $subtot_coll_total_ht += $temp_ht;
443  $subtot_coll_vat += $temp_vat;
444  $x_coll_sum += $temp_vat;
445  }
446  }
447  print "<td class=\"nowrap\" align=\"right\">".price(price2num($x_coll_sum,'MT'))."</td>";
448 
449  $x_paye_sum = 0;
450  foreach (array_keys($x_paye) as $rate)
451  {
452  $subtot_paye_total_ht = 0;
453  $subtot_paye_vat = 0;
454 
455  foreach ($x_both[$rate]['paye']['detail'] as $index => $fields)
456  {
457  // Payment
458  $ratiopaymentinvoice=1;
459  if ($modetax != 1)
460  {
461  // Define type
462  // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
463  $type=(isset($fields['dtype'])?$fields['dtype']:$fields['ptype']);
464  // Try to enhance type detection using date_start and date_end for free lines where type
465  // was not saved.
466  if (!empty($fields['ddate_start'])) {
467  $type=1;
468  }
469  if (!empty($fields['ddate_end'])) {
470  $type=1;
471  }
472 
473  if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
474  || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice'))
475  {
476  //print $langs->trans("NA");
477  } else {
478  if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
479  $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
480  }
481  }
482  }
483  //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice);
484  $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
485  $temp_vat=$fields['vat']*$ratiopaymentinvoice;
486  $subtot_paye_total_ht += $temp_ht;
487  $subtot_paye_vat += $temp_vat;
488  $x_paye_sum += $temp_vat;
489  }
490  }
491  print "<td class=\"nowrap\" align=\"right\">".price(price2num($x_paye_sum,'MT'))."</td>";
492 
493  $subtotalcoll = $subtotalcoll + $x_coll_sum;
494  $subtotalpaye = $subtotalpaye + $x_paye_sum;
495 
496  $diff = $x_coll_sum - $x_paye_sum;
497  $total = $total + $diff;
498  $subtotal = price2num($subtotal + $diff, 'MT');
499 
500  print "<td class=\"nowrap\" align=\"right\">".price(price2num($diff,'MT'))."</td>\n";
501  print "<td>&nbsp;</td>\n";
502  print "</tr>\n";
503 
504  $i++; $m++;
505  if ($i > 2)
506  {
507  print '<tr class="liste_total">';
508  print '<td align="right"><a href="quadri_detail.php?leftmenu=tax_vat&q='.($m/3).'&year='.$y.'">'.$langs->trans("SubTotal").'</a>:</td>';
509  print '<td class="nowrap" align="right">'.price(price2num($subtotalcoll,'MT')).'</td>';
510  print '<td class="nowrap" align="right">'.price(price2num($subtotalpaye,'MT')).'</td>';
511  print '<td class="nowrap" align="right">'.price(price2num($subtotal,'MT')).'</td>';
512  print '<td>&nbsp;</td></tr>';
513  $i = 0;
514  $subtotalcoll=0; $subtotalpaye=0; $subtotal=0;
515  }
516 }
517 print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("TotalToPay").':</td><td class="nowrap" align="right">'.price(price2num($total, 'MT')).'</td>';
518 print "<td>&nbsp;</td>\n";
519 print '</tr>';
520 
521 print '</table>';
522 
523 
524 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
525 
526 
527 
528 /*
529  * Payed
530  */
531 
532 print load_fiche_titre($langs->trans("VATPaid"), '', '');
533 
534 $sql='';
535 
536 $sql.= "SELECT SUM(amount) as mm, date_format(f.datev,'%Y-%m') as dm, 'claimed' as mode";
537 $sql.= " FROM ".MAIN_DB_PREFIX."tva as f";
538 $sql.= " WHERE f.entity = ".$conf->entity;
539 $sql.= " AND (f.datev >= '".$db->idate($date_start)."' AND f.datev <= '".$db->idate($date_end)."')";
540 $sql.= " GROUP BY dm";
541 
542 $sql.= " UNION ";
543 
544 $sql.= "SELECT SUM(amount) as mm, date_format(f.datep,'%Y-%m') as dm, 'paid' as mode";
545 $sql.= " FROM ".MAIN_DB_PREFIX."tva as f";
546 $sql.= " WHERE f.entity = ".$conf->entity;
547 $sql.= " AND (f.datep >= '".$db->idate($date_start)."' AND f.datep <= '".$db->idate($date_end)."')";
548 $sql.= " GROUP BY dm";
549 
550 $sql.= " ORDER BY dm ASC, mode ASC";
551 //print $sql;
552 
553 pt($db, $sql, $langs->trans("Month"));
554 
555 
556 if (! empty($conf->global->MAIN_FEATURES_LEVEL))
557 {
558  print '<br>';
559 
560  /*
561  * Recap
562  */
563 
564  print load_fiche_titre($langs->trans("VATBalance"), '', ''); // need to add translation
565 
566  $sql1 = "SELECT SUM(amount) as mm";
567  $sql1 .= " FROM " . MAIN_DB_PREFIX . "tva as f";
568  $sql1 .= " WHERE f.entity = " . $conf->entity;
569  $sql1 .= " AND f.datev >= '" . $db->idate($date_start) . "'";
570  $sql1 .= " AND f.datev <= '" . $db->idate($date_end) . "'";
571 
572  $result = $db->query($sql1);
573  if ($result) {
574  $obj = $db->fetch_object($result);
575  print '<table class="noborder" width="100%">';
576 
577  print "<tr>";
578  print '<td align="right">' . $langs->trans("VATDue") . '</td>';
579  print '<td class="nowrap" align="right">' . price(price2num($total, 'MT')) . '</td>';
580  print "</tr>\n";
581 
582  print "<tr>";
583  print '<td align="right">' . $langs->trans("VATPaid") . '</td>';
584  print '<td class="nowrap" align="right">' . price(price2num($obj->mm, 'MT')) . "</td>\n";
585  print "</tr>\n";
586 
587  $restopay = $total - $obj->mm;
588  print "<tr>";
589  print '<td align="right">' . $langs->trans("RemainToPay") . '</td>';
590  print '<td class="nowrap" align="right">' . price(price2num($restopay, 'MT')) . '</td>';
591  print "</tr>\n";
592 
593  print '</table>';
594  }
595 }
596 
597 print '</div></div>';
598 
599 llxFooter();
600 $db->close();
llxFooter()
Footer empty.
Definition: index.php:44
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
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...
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:453
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:35
Class to manage generation of HTML components Only common components must be here.
tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $direction, $m=0)
Gets Tax to collect for the given year (and given quarter or month) The function gets the Tax in spli...
Definition: tax.lib.php:559
GETPOSTISSET($paramname)
Return true if we are in a context of submitting a parameter.
Class to manage third parties objects (customers, suppliers, prospects...)
llxHeader()
Header empty.
Definition: index.php:36
dol_now($mode='gmt')
Return date for now.
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:467
pt($db, $sql, $date)
print function
Definition: index.php:91
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
dol_getdate($timestamp, $fast=false)
Return an array with locale date info.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
Definition: report.lib.php:41
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
Definition: date.lib.php:116
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...