dolibarr  17.0.4
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  * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
9  * Copyright (C) 2021 Open-Dsi <support@open-dsi.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <https://www.gnu.org/licenses/>.
23  */
24 
30 require '../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php';
36 
37 // Load translation files required by the page
38 $langs->loadLangs(array("other", "compta", "banks", "bills", "companies", "product", "trips", "admin"));
39 
40 $refresh = GETPOSTISSET('submit') ? true : false;
41 $year_current = GETPOSTISSET('year') ? GETPOST('year', 'int') : dol_print_date($now, '%Y', 'tzserver');
42 $year_start = $year_current;
43 $month_current = GETPOSTISSET('month') ? GETPOST('month', 'int') : dol_print_date($now, '%m', 'tzserver');
44 $month_start = $month_current;
45 
46 $refresh = true;
47 
48 include DOL_DOCUMENT_ROOT.'/compta/tva/initdatesforvat.inc.php';
49 
50 // Define modetax (0 or 1)
51 // 0=normal, 1=option vat for services is on debit, 2=option on payments for products
52 $modetax = $conf->global->TAX_MODE;
53 if (GETPOSTISSET("modetax")) {
54  $modetax = GETPOST("modetax", 'int');
55 }
56 if (empty($modetax)) {
57  $modetax = 0;
58 }
59 
60 // Security check
61 $socid = GETPOST('socid', 'int');
62 if ($user->socid) {
63  $socid = $user->socid;
64 }
65 $result = restrictedArea($user, 'tax', '', 'tva', 'charges');
66 
67 
76 function pt($db, $sql, $date)
77 {
78  global $conf, $bc, $langs, $form;
79 
80  $result = $db->query($sql);
81  if ($result) {
82  $num = $db->num_rows($result);
83  $i = 0;
84  $total = 0;
85  print '<table class="noborder centpercent">';
86 
87  print '<tr class="liste_titre">';
88  print '<td class="nowrap">'.$date.'</td>';
89  print '<td class="right">'.$langs->trans("ClaimedForThisPeriod").'</td>';
90  print '<td class="right">'.$langs->trans("PaidDuringThisPeriod").$form->textwithpicto('', $langs->trans('PaidDuringThisPeriodDesc'), 1).'</td>';
91  print "</tr>\n";
92 
93  $totalclaimed = 0;
94  $totalpaid = 0;
95  $amountclaimed = 0;
96  $amountpaid = 0;
97  $previousmonth = '';
98  $previousmode = '';
99  $mode = '';
100 
101  while ($i < $num) {
102  $obj = $db->fetch_object($result);
103  $mode = $obj->mode;
104 
105  //print $obj->dm.' '.$obj->mode.' '.$previousmonth.' '.$previousmode;
106  if ($obj->mode == 'claimed' && !empty($previousmode)) {
107  print '<tr class="oddeven">';
108  print '<td class="nowrap">'.$previousmonth."</td>\n";
109  print '<td class="nowrap right"><span class="amount">'.price($amountclaimed)."</span></td>\n";
110  print '<td class="nowrap right"><span class="amount">'.price($amountpaid)."</span></td>\n";
111  print "</tr>\n";
112 
113  $amountclaimed = 0;
114  $amountpaid = 0;
115  }
116 
117  if ($obj->mode == 'claimed') {
118  $amountclaimed = $obj->mm;
119  $totalclaimed = $totalclaimed + $amountclaimed;
120  }
121  if ($obj->mode == 'paid') {
122  $amountpaid = $obj->mm;
123  $totalpaid = $totalpaid + $amountpaid;
124  }
125 
126  if ($obj->mode == 'paid') {
127  print '<tr class="oddeven">';
128  print '<td class="nowrap">'.$obj->dm."</td>\n";
129  print '<td class="nowrap right"><span class="amount">'.price($amountclaimed)."</span></td>\n";
130  print '<td class="nowrap right"><span class="amount">'.price($amountpaid)."</span></td>\n";
131  print "</tr>\n";
132  $amountclaimed = 0;
133  $amountpaid = 0;
134  $previousmode = '';
135  $previousmonth = '';
136  } else {
137  $previousmode = $obj->mode;
138  $previousmonth = $obj->dm;
139  }
140 
141  $i++;
142  }
143 
144  if ($mode == 'claimed' && !empty($previousmode)) {
145  print '<tr class="oddeven">';
146  print '<td class="nowrap">'.$previousmonth."</td>\n";
147  print '<td class="nowrap right">'.price($amountclaimed)."</td>\n";
148  print '<td class="nowrap right">'.price($amountpaid)."</td>\n";
149  print "</tr>\n";
150 
151  $amountclaimed = 0;
152  $amountpaid = 0;
153  }
154 
155  print '<tr class="liste_total">';
156  print '<td class="right">'.$langs->trans("Total").'</td>';
157  print '<td class="nowrap right">'.price($totalclaimed).'</td>';
158  print '<td class="nowrap right">'.price($totalpaid).'</td>';
159  print "</tr>";
160 
161  print "</table>";
162 
163  $db->free($result);
164  } else {
165  dol_print_error($db);
166  }
167 }
168 
169 
170 /*
171  * View
172  */
173 
174 $form = new Form($db);
175 $company_static = new Societe($db);
176 $tva = new Tva($db);
177 
178 $fsearch = '<!-- hidden fields for form -->';
179 $fsearch .= '<input type="hidden" name="token" value="'.newToken().'">';
180 $fsearch .= '<input type="hidden" name="modetax" value="'.$modetax.'">';
181 
182 $description = $fsearch;
183 
184 // Show report header
185 $name = $langs->trans("VATReportByMonth");
186 $calcmode = '';
187 if ($modetax == 0) {
188  $calcmode = $langs->trans('OptionVATDefault');
189 }
190 if ($modetax == 1) {
191  $calcmode = $langs->trans('OptionVATDebitOption');
192 }
193 if ($modetax == 2) {
194  $calcmode = $langs->trans('OptionPaymentForProductAndServices');
195 }
196 $calcmode .= ' <span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRules", DOL_URL_ROOT.'/admin/taxes.php').')</span>';
197 
198 $description .= $langs->trans("VATSummary").'<br>';
199 if ($conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') {
200  $description .= $langs->trans("RulesVATDueProducts");
201 }
202 if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment') {
203  $description .= $langs->trans("RulesVATInProducts");
204 }
205 if ($conf->global->TAX_MODE_SELL_SERVICE == 'invoice') {
206  $description .= '<br>'.$langs->trans("RulesVATDueServices");
207 }
208 if ($conf->global->TAX_MODE_SELL_SERVICE == 'payment') {
209  $description .= '<br>'.$langs->trans("RulesVATInServices");
210 }
211 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
212  $description .= '<br>'.$langs->trans("DepositsAreNotIncluded");
213 }
214 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
215  $description .= $langs->trans("SupplierDepositsAreNotIncluded");
216 }
217 if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) {
218  $description .= '<br>'.$langs->trans("ThisIsAnEstimatedValue");
219 }
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, 'bill');
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 if ($refresh === true) {
239  print '<div class="fichecenter"><div class="fichethirdleft">';
240 
241  print load_fiche_titre($langs->trans("VATSummary"), '', '');
242 
243  print '<table class="noborder centpercent">';
244  print '<tr class="liste_titre">';
245  print '<td width="30%">' . $langs->trans("Year") . " " . $y . '</td>';
246  print '<td class="right">' . $langs->trans("VATToPay") . '</td>';
247  print '<td class="right">' . $langs->trans("VATToCollect") . '</td>';
248  print '<td class="right">' . $langs->trans("Balance") . '</td>';
249  print '<td>&nbsp;</td>' . "\n";
250  print '</tr>' . "\n";
251 
252  $tmp = dol_getdate($date_start);
253  $y = $tmp['year'];
254  $m = $tmp['mon'];
255  $tmp = dol_getdate($date_end);
256  $yend = $tmp['year'];
257  $mend = $tmp['mon'];
258  //var_dump($m);
259  $total = 0;
260  $subtotalcoll = 0;
261  $subtotalpaid = 0;
262  $subtotal = 0;
263  $i = 0;
264  $mcursor = 0;
265 
266  while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) { // $mcursor is to avoid too large loop
267  //$m = $conf->global->SOCIETE_FISCAL_MONTH_START + ($mcursor % 12);
268  if ($m == 13) {
269  $y++;
270  }
271  if ($m > 12) {
272  $m -= 12;
273  }
274  $mcursor++;
275 
276  $x_coll = tax_by_rate('vat', $db, $y, 0, 0, 0, $modetax, 'sell', $m);
277  $x_paye = tax_by_rate('vat', $db, $y, 0, 0, 0, $modetax, 'buy', $m);
278 
279  $x_both = array();
280  //now, from these two arrays, get another array with one rate per line
281  foreach (array_keys($x_coll) as $my_coll_rate) {
282  $x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht'];
283  $x_both[$my_coll_rate]['coll']['vat'] = $x_coll[$my_coll_rate]['vat'];
284  $x_both[$my_coll_rate]['paye']['totalht'] = 0;
285  $x_both[$my_coll_rate]['paye']['vat'] = 0;
286  $x_both[$my_coll_rate]['coll']['links'] = '';
287  $x_both[$my_coll_rate]['coll']['detail'] = array();
288  foreach ($x_coll[$my_coll_rate]['facid'] as $id => $dummy) {
289  //$invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id];
290  //$invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id];
291  //$invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id];
292  //$company_static->fetch($x_coll[$my_coll_rate]['company_id'][$id]);
293  $x_both[$my_coll_rate]['coll']['detail'][] = array(
294  'id' => $x_coll[$my_coll_rate]['facid'][$id],
295  'descr' => $x_coll[$my_coll_rate]['descr'][$id],
296  'pid' => $x_coll[$my_coll_rate]['pid'][$id],
297  'pref' => $x_coll[$my_coll_rate]['pref'][$id],
298  'ptype' => $x_coll[$my_coll_rate]['ptype'][$id],
299  'payment_id' => $x_coll[$my_coll_rate]['payment_id'][$id],
300  'payment_amount' => $x_coll[$my_coll_rate]['payment_amount'][$id],
301  'ftotal_ttc' => $x_coll[$my_coll_rate]['ftotal_ttc'][$id],
302  'dtotal_ttc' => $x_coll[$my_coll_rate]['dtotal_ttc'][$id],
303  'dtype' => $x_coll[$my_coll_rate]['dtype'][$id],
304  'datef' => $x_coll[$my_coll_rate]['datef'][$id],
305  'datep' => $x_coll[$my_coll_rate]['datep'][$id],
306  //'company_link'=>$company_static->getNomUrl(1,'',20),
307  'ddate_start' => $x_coll[$my_coll_rate]['ddate_start'][$id],
308  'ddate_end' => $x_coll[$my_coll_rate]['ddate_end'][$id],
309  'totalht' => $x_coll[$my_coll_rate]['totalht_list'][$id],
310  'vat' => $x_coll[$my_coll_rate]['vat_list'][$id],
311  //'link' =>$invoice_customer->getNomUrl(1,'',12)
312  );
313  }
314  }
315 
316  // tva paid
317  foreach (array_keys($x_paye) as $my_paye_rate) {
318  $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht'];
319  $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat'];
320  if (!isset($x_both[$my_paye_rate]['coll']['totalht'])) {
321  $x_both[$my_paye_rate]['coll']['totalht'] = 0;
322  $x_both[$my_paye_rate]['coll']['vat'] = 0;
323  }
324  $x_both[$my_paye_rate]['paye']['links'] = '';
325  $x_both[$my_paye_rate]['paye']['detail'] = array();
326 
327  foreach ($x_paye[$my_paye_rate]['facid'] as $id => $dummy) {
328  // ExpenseReport
329  if ($x_paye[$my_paye_rate]['ptype'][$id] == 'ExpenseReportPayment') {
330  //$expensereport->id=$x_paye[$my_paye_rate]['facid'][$id];
331  //$expensereport->ref=$x_paye[$my_paye_rate]['facnum'][$id];
332  //$expensereport->type=$x_paye[$my_paye_rate]['type'][$id];
333 
334  $x_both[$my_paye_rate]['paye']['detail'][] = array(
335  'id' => $x_paye[$my_paye_rate]['facid'][$id],
336  'descr' => $x_paye[$my_paye_rate]['descr'][$id],
337  'pid' => $x_paye[$my_paye_rate]['pid'][$id],
338  'pref' => $x_paye[$my_paye_rate]['pref'][$id],
339  'ptype' => $x_paye[$my_paye_rate]['ptype'][$id],
340  'payment_id' => $x_paye[$my_paye_rate]['payment_id'][$id],
341  'payment_amount' => $x_paye[$my_paye_rate]['payment_amount'][$id],
342  'ftotal_ttc' => price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
343  'dtotal_ttc' => price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
344  'dtype' => $x_paye[$my_paye_rate]['dtype'][$id],
345  'ddate_start' => $x_paye[$my_paye_rate]['ddate_start'][$id],
346  'ddate_end' => $x_paye[$my_paye_rate]['ddate_end'][$id],
347  'totalht' => price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
348  'vat' => $x_paye[$my_paye_rate]['vat_list'][$id],
349  //'link' =>$expensereport->getNomUrl(1)
350  );
351  } else {
352  //$invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id];
353  //$invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id];
354  //$invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id];
355  //$company_static->fetch($x_paye[$my_paye_rate]['company_id'][$id]);
356  $x_both[$my_paye_rate]['paye']['detail'][] = array(
357  'id' => $x_paye[$my_paye_rate]['facid'][$id],
358  'descr' => $x_paye[$my_paye_rate]['descr'][$id],
359  'pid' => $x_paye[$my_paye_rate]['pid'][$id],
360  'pref' => $x_paye[$my_paye_rate]['pref'][$id],
361  'ptype' => $x_paye[$my_paye_rate]['ptype'][$id],
362  'payment_id' => $x_paye[$my_paye_rate]['payment_id'][$id],
363  'payment_amount' => $x_paye[$my_paye_rate]['payment_amount'][$id],
364  'ftotal_ttc' => price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
365  'dtotal_ttc' => price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
366  'dtype' => $x_paye[$my_paye_rate]['dtype'][$id],
367  'datef' => $x_paye[$my_paye_rate]['datef'][$id],
368  'datep' => $x_paye[$my_paye_rate]['datep'][$id],
369  //'company_link'=>$company_static->getNomUrl(1,'',20),
370  'ddate_start' => $x_paye[$my_paye_rate]['ddate_start'][$id],
371  'ddate_end' => $x_paye[$my_paye_rate]['ddate_end'][$id],
372  'totalht' => price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
373  'vat' => $x_paye[$my_paye_rate]['vat_list'][$id],
374  //'link' =>$invoice_supplier->getNomUrl(1,'',12)
375  );
376  }
377  }
378  }
379  //now we have an array (x_both) indexed by rates for coll and paye
380 
381  $action = "tva";
382  $object = array(&$x_coll, &$x_paye, &$x_both);
383  $parameters["mode"] = $modetax;
384  $parameters["year"] = $y;
385  $parameters["month"] = $m;
386  $parameters["type"] = 'vat';
387 
388  // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
389  $hookmanager->initHooks(array('externalbalance'));
390  $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
391 
392 
393  print '<tr class="oddeven">';
394  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>';
395 
396  $x_coll_sum = 0;
397  foreach (array_keys($x_coll) as $rate) {
398  $subtot_coll_total_ht = 0;
399  $subtot_coll_vat = 0;
400 
401  foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) {
402  // Payment
403  $ratiopaymentinvoice = 1;
404  if ($modetax != 1) {
405  // Define type
406  // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
407  $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
408  // Try to enhance type detection using date_start and date_end for free lines where type
409  // was not saved.
410  if (!empty($fields['ddate_start'])) {
411  $type = 1;
412  }
413  if (!empty($fields['ddate_end'])) {
414  $type = 1;
415  }
416 
417  if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
418  || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) {
419  //print $langs->trans("NA");
420  } else {
421  if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
422  $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
423  }
424  }
425  }
426  //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice);
427  $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
428  $temp_vat = $fields['vat'] * $ratiopaymentinvoice;
429  $subtot_coll_total_ht += $temp_ht;
430  $subtot_coll_vat += $temp_vat;
431  $x_coll_sum += $temp_vat;
432  }
433  }
434  print '<td class="nowrap right"><span class="amount">' . price(price2num($x_coll_sum, 'MT')) . '</span></td>';
435 
436  $x_paye_sum = 0;
437  foreach (array_keys($x_paye) as $rate) {
438  $subtot_paye_total_ht = 0;
439  $subtot_paye_vat = 0;
440 
441  foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) {
442  // Payment
443  $ratiopaymentinvoice = 1;
444  if ($modetax != 1) {
445  // Define type
446  // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
447  $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
448  // Try to enhance type detection using date_start and date_end for free lines where type
449  // was not saved.
450  if (!empty($fields['ddate_start'])) {
451  $type = 1;
452  }
453  if (!empty($fields['ddate_end'])) {
454  $type = 1;
455  }
456 
457  if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
458  || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) {
459  //print $langs->trans("NA");
460  } else {
461  if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
462  $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
463  }
464  }
465  }
466  //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice);
467  $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
468  $temp_vat = $fields['vat'] * $ratiopaymentinvoice;
469  $subtot_paye_total_ht += $temp_ht;
470  $subtot_paye_vat += $temp_vat;
471  $x_paye_sum += $temp_vat;
472  }
473  }
474  print '<td class="nowrap right"><span class="amount">' . price(price2num($x_paye_sum, 'MT')) . '</span></td>';
475 
476  $subtotalcoll = $subtotalcoll + $x_coll_sum;
477  $subtotalpaid = $subtotalpaid + $x_paye_sum;
478 
479  $diff = $x_coll_sum - $x_paye_sum;
480  $total = $total + $diff;
481  $subtotal = price2num($subtotal + $diff, 'MT');
482 
483  print '<td class="nowrap right"><span class="amount">' . price(price2num($diff, 'MT')) . '</span></td>' . "\n";
484  print "<td>&nbsp;</td>\n";
485  print "</tr>\n";
486 
487  // Total
488  $i++;
489  $m++;
490  if ($i > 2) {
491  print '<tr class="liste_total">';
492  print '<td class="right"><a href="quadri_detail.php?leftmenu=tax_vat&q=' . round($m / 3) . '&year=' . $y . '">' . $langs->trans("SubTotal") . '</a>:</td>';
493  print '<td class="nowrap right">' . price(price2num($subtotalcoll, 'MT')) . '</td>';
494  print '<td class="nowrap right">' . price(price2num($subtotalpaid, 'MT')) . '</td>';
495  print '<td class="nowrap right">' . price(price2num($subtotal, 'MT')) . '</td>';
496  print '<td>&nbsp;</td></tr>';
497  $i = 0;
498  $subtotalcoll = 0;
499  $subtotalpaid = 0;
500  $subtotal = 0;
501  }
502  }
503  print '<tr class="liste_total"><td class="right" colspan="3">' . $langs->trans("TotalToPay") . ':</td><td class="nowrap right">' . price(price2num($total, 'MT')) . '</td>';
504  print "<td>&nbsp;</td>\n";
505  print '</tr>';
506 
507  print '</table>';
508 
509 
510  print '</div><div class="fichetwothirdright">';
511 
512 
513  /*
514  * Paid
515  */
516  print load_fiche_titre($langs->trans("VATPaid"), '', '');
517 
518  $sql = '';
519 
520  $sql .= "SELECT SUM(amount) as mm, date_format(tva.datev,'%Y-%m') as dm, 'claimed' as mode";
521  $sql .= " FROM " . MAIN_DB_PREFIX . "tva as tva";
522  $sql .= " WHERE tva.entity = " . $conf->entity;
523  $sql .= " AND (tva.datev >= '" . $db->idate($date_start) . "' AND tva.datev <= '" . $db->idate($date_end) . "')";
524  $sql .= " GROUP BY dm";
525 
526  $sql .= " UNION ";
527 
528  $sql .= "SELECT SUM(ptva.amount) as mm, date_format(tva.datev,'%Y-%m') as dm, 'paid' as mode";
529  $sql .= " FROM " . MAIN_DB_PREFIX . "tva as tva";
530  $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "payment_vat as ptva ON (tva.rowid = ptva.fk_tva)";
531  $sql .= " WHERE tva.entity = " . $conf->entity;
532  $sql .= " AND (tva.datev >= '" . $db->idate($date_start) . "' AND tva.datev <= '" . $db->idate($date_end) . "')";
533  $sql .= " GROUP BY dm";
534 
535  $sql .= " ORDER BY dm ASC, mode ASC";
536  //print $sql;
537 
538  pt($db, $sql, $langs->trans("Month"));
539 
540  print '</div>';
541 }
542 
543 llxFooter();
544 $db->close();
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
Put here description of your class.
Definition: tva.class.php:36
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
pt($db, $sql, $date)
print function
Definition: index.php:107
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
llxFooter()
Footer empty.
Definition: index.php:71
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:63
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
Definition: report.lib.php:41
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
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:699