dolibarr  18.0.0-alpha
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 $periodlink = '';
233 $exportlink = '';
234 
235 report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
236 //report_header($name,'',$textprevyear.$langs->trans("Year")." ".$year_start.$textnextyear,'',$description,$builddate,$exportlink,array(),$calcmode);
237 
238 
239 print '<br>';
240 
241 if ($refresh === true) {
242  print '<div class="fichecenter"><div class="fichethirdleft">';
243 
244  print load_fiche_titre($langs->trans("VATSummary"), '', '');
245 
246  print '<table class="noborder centpercent">';
247  print '<tr class="liste_titre">';
248  print '<td width="30%">' . $langs->trans("Year") . '</td>';
249  print '<td class="right">' . $langs->trans("VATToPay") . '</td>';
250  print '<td class="right">' . $langs->trans("VATToCollect") . '</td>';
251  print '<td class="right">' . $langs->trans("Balance") . '</td>';
252  print '<td>&nbsp;</td>' . "\n";
253  print '</tr>' . "\n";
254 
255  $tmp = dol_getdate($date_start);
256  $y = $tmp['year'];
257  $m = $tmp['mon'];
258  $tmp = dol_getdate($date_end);
259  $yend = $tmp['year'];
260  $mend = $tmp['mon'];
261  //var_dump($m);
262  $total = 0;
263  $subtotalcoll = 0;
264  $subtotalpaid = 0;
265  $subtotal = 0;
266  $i = 0;
267  $mcursor = 0;
268 
269  while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) { // $mcursor is to avoid too large loop
270  //$m = $conf->global->SOCIETE_FISCAL_MONTH_START + ($mcursor % 12);
271  if ($m == 13) {
272  $y++;
273  }
274  if ($m > 12) {
275  $m -= 12;
276  }
277  $mcursor++;
278 
279  $x_coll = tax_by_rate('vat', $db, $y, 0, 0, 0, $modetax, 'sell', $m);
280  $x_paye = tax_by_rate('vat', $db, $y, 0, 0, 0, $modetax, 'buy', $m);
281 
282  $x_both = array();
283  //now, from these two arrays, get another array with one rate per line
284  foreach (array_keys($x_coll) as $my_coll_rate) {
285  $x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht'];
286  $x_both[$my_coll_rate]['coll']['vat'] = $x_coll[$my_coll_rate]['vat'];
287  $x_both[$my_coll_rate]['paye']['totalht'] = 0;
288  $x_both[$my_coll_rate]['paye']['vat'] = 0;
289  $x_both[$my_coll_rate]['coll']['links'] = '';
290  $x_both[$my_coll_rate]['coll']['detail'] = array();
291  foreach ($x_coll[$my_coll_rate]['facid'] as $id => $dummy) {
292  //$invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id];
293  //$invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id];
294  //$invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id];
295  //$company_static->fetch($x_coll[$my_coll_rate]['company_id'][$id]);
296  $x_both[$my_coll_rate]['coll']['detail'][] = array(
297  'id' => $x_coll[$my_coll_rate]['facid'][$id],
298  'descr' => $x_coll[$my_coll_rate]['descr'][$id],
299  'pid' => $x_coll[$my_coll_rate]['pid'][$id],
300  'pref' => $x_coll[$my_coll_rate]['pref'][$id],
301  'ptype' => $x_coll[$my_coll_rate]['ptype'][$id],
302  'payment_id' => $x_coll[$my_coll_rate]['payment_id'][$id],
303  'payment_amount' => $x_coll[$my_coll_rate]['payment_amount'][$id],
304  'ftotal_ttc' => $x_coll[$my_coll_rate]['ftotal_ttc'][$id],
305  'dtotal_ttc' => $x_coll[$my_coll_rate]['dtotal_ttc'][$id],
306  'dtype' => $x_coll[$my_coll_rate]['dtype'][$id],
307  'datef' => $x_coll[$my_coll_rate]['datef'][$id],
308  'datep' => $x_coll[$my_coll_rate]['datep'][$id],
309  //'company_link'=>$company_static->getNomUrl(1,'',20),
310  'ddate_start' => $x_coll[$my_coll_rate]['ddate_start'][$id],
311  'ddate_end' => $x_coll[$my_coll_rate]['ddate_end'][$id],
312  'totalht' => $x_coll[$my_coll_rate]['totalht_list'][$id],
313  'vat' => $x_coll[$my_coll_rate]['vat_list'][$id],
314  //'link' =>$invoice_customer->getNomUrl(1,'',12)
315  );
316  }
317  }
318 
319  // tva paid
320  foreach (array_keys($x_paye) as $my_paye_rate) {
321  $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht'];
322  $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat'];
323  if (!isset($x_both[$my_paye_rate]['coll']['totalht'])) {
324  $x_both[$my_paye_rate]['coll']['totalht'] = 0;
325  $x_both[$my_paye_rate]['coll']['vat'] = 0;
326  }
327  $x_both[$my_paye_rate]['paye']['links'] = '';
328  $x_both[$my_paye_rate]['paye']['detail'] = array();
329 
330  foreach ($x_paye[$my_paye_rate]['facid'] as $id => $dummy) {
331  // ExpenseReport
332  if ($x_paye[$my_paye_rate]['ptype'][$id] == 'ExpenseReportPayment') {
333  //$expensereport->id=$x_paye[$my_paye_rate]['facid'][$id];
334  //$expensereport->ref=$x_paye[$my_paye_rate]['facnum'][$id];
335  //$expensereport->type=$x_paye[$my_paye_rate]['type'][$id];
336 
337  $x_both[$my_paye_rate]['paye']['detail'][] = array(
338  'id' => $x_paye[$my_paye_rate]['facid'][$id],
339  'descr' => $x_paye[$my_paye_rate]['descr'][$id],
340  'pid' => $x_paye[$my_paye_rate]['pid'][$id],
341  'pref' => $x_paye[$my_paye_rate]['pref'][$id],
342  'ptype' => $x_paye[$my_paye_rate]['ptype'][$id],
343  'payment_id' => $x_paye[$my_paye_rate]['payment_id'][$id],
344  'payment_amount' => $x_paye[$my_paye_rate]['payment_amount'][$id],
345  'ftotal_ttc' => price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
346  'dtotal_ttc' => price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
347  'dtype' => $x_paye[$my_paye_rate]['dtype'][$id],
348  'ddate_start' => $x_paye[$my_paye_rate]['ddate_start'][$id],
349  'ddate_end' => $x_paye[$my_paye_rate]['ddate_end'][$id],
350  'totalht' => price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
351  'vat' => $x_paye[$my_paye_rate]['vat_list'][$id],
352  //'link' =>$expensereport->getNomUrl(1)
353  );
354  } else {
355  //$invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id];
356  //$invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id];
357  //$invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id];
358  //$company_static->fetch($x_paye[$my_paye_rate]['company_id'][$id]);
359  $x_both[$my_paye_rate]['paye']['detail'][] = array(
360  'id' => $x_paye[$my_paye_rate]['facid'][$id],
361  'descr' => $x_paye[$my_paye_rate]['descr'][$id],
362  'pid' => $x_paye[$my_paye_rate]['pid'][$id],
363  'pref' => $x_paye[$my_paye_rate]['pref'][$id],
364  'ptype' => $x_paye[$my_paye_rate]['ptype'][$id],
365  'payment_id' => $x_paye[$my_paye_rate]['payment_id'][$id],
366  'payment_amount' => $x_paye[$my_paye_rate]['payment_amount'][$id],
367  'ftotal_ttc' => price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
368  'dtotal_ttc' => price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
369  'dtype' => $x_paye[$my_paye_rate]['dtype'][$id],
370  'datef' => $x_paye[$my_paye_rate]['datef'][$id],
371  'datep' => $x_paye[$my_paye_rate]['datep'][$id],
372  //'company_link'=>$company_static->getNomUrl(1,'',20),
373  'ddate_start' => $x_paye[$my_paye_rate]['ddate_start'][$id],
374  'ddate_end' => $x_paye[$my_paye_rate]['ddate_end'][$id],
375  'totalht' => price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
376  'vat' => $x_paye[$my_paye_rate]['vat_list'][$id],
377  //'link' =>$invoice_supplier->getNomUrl(1,'',12)
378  );
379  }
380  }
381  }
382  //now we have an array (x_both) indexed by rates for coll and paye
383 
384  $action = "tva";
385  $object = array(&$x_coll, &$x_paye, &$x_both);
386  $parameters["mode"] = $modetax;
387  $parameters["year"] = $y;
388  $parameters["month"] = $m;
389  $parameters["type"] = 'vat';
390 
391  // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
392  $hookmanager->initHooks(array('externalbalance'));
393  $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
394 
395 
396  print '<tr class="oddeven">';
397  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>';
398 
399  $x_coll_sum = 0;
400  foreach (array_keys($x_coll) as $rate) {
401  $subtot_coll_total_ht = 0;
402  $subtot_coll_vat = 0;
403 
404  foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) {
405  // Payment
406  $ratiopaymentinvoice = 1;
407  if ($modetax != 1) {
408  // Define type
409  // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
410  $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
411  // Try to enhance type detection using date_start and date_end for free lines where type
412  // was not saved.
413  if (!empty($fields['ddate_start'])) {
414  $type = 1;
415  }
416  if (!empty($fields['ddate_end'])) {
417  $type = 1;
418  }
419 
420  if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
421  || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) {
422  //print $langs->trans("NA");
423  } else {
424  if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
425  $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
426  }
427  }
428  }
429  //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice);
430  $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
431  $temp_vat = $fields['vat'] * $ratiopaymentinvoice;
432  $subtot_coll_total_ht += $temp_ht;
433  $subtot_coll_vat += $temp_vat;
434  $x_coll_sum += $temp_vat;
435  }
436  }
437  print '<td class="nowrap right"><span class="amount">' . price(price2num($x_coll_sum, 'MT')) . '</span></td>';
438 
439  $x_paye_sum = 0;
440  foreach (array_keys($x_paye) as $rate) {
441  $subtot_paye_total_ht = 0;
442  $subtot_paye_vat = 0;
443 
444  foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) {
445  // Payment
446  $ratiopaymentinvoice = 1;
447  if ($modetax != 1) {
448  // Define type
449  // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
450  $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
451  // Try to enhance type detection using date_start and date_end for free lines where type
452  // was not saved.
453  if (!empty($fields['ddate_start'])) {
454  $type = 1;
455  }
456  if (!empty($fields['ddate_end'])) {
457  $type = 1;
458  }
459 
460  if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
461  || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) {
462  //print $langs->trans("NA");
463  } else {
464  if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
465  $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
466  }
467  }
468  }
469  //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice);
470  $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
471  $temp_vat = $fields['vat'] * $ratiopaymentinvoice;
472  $subtot_paye_total_ht += $temp_ht;
473  $subtot_paye_vat += $temp_vat;
474  $x_paye_sum += $temp_vat;
475  }
476  }
477  print '<td class="nowrap right"><span class="amount">' . price(price2num($x_paye_sum, 'MT')) . '</span></td>';
478 
479  $subtotalcoll = $subtotalcoll + $x_coll_sum;
480  $subtotalpaid = $subtotalpaid + $x_paye_sum;
481 
482  $diff = $x_coll_sum - $x_paye_sum;
483  $total = $total + $diff;
484  $subtotal = price2num($subtotal + $diff, 'MT');
485 
486  print '<td class="nowrap right"><span class="amount">' . price(price2num($diff, 'MT')) . '</span></td>' . "\n";
487  print "<td>&nbsp;</td>\n";
488  print "</tr>\n";
489 
490  // Total
491  $i++;
492  $m++;
493  if ($i > 2) {
494  print '<tr class="liste_total">';
495  print '<td class="right"><a href="quadri_detail.php?leftmenu=tax_vat&q=' . round($m / 3) . '&year=' . $y . '">' . $langs->trans("SubTotal") . '</a>:</td>';
496  print '<td class="nowrap right">' . price(price2num($subtotalcoll, 'MT')) . '</td>';
497  print '<td class="nowrap right">' . price(price2num($subtotalpaid, 'MT')) . '</td>';
498  print '<td class="nowrap right">' . price(price2num($subtotal, 'MT')) . '</td>';
499  print '<td>&nbsp;</td></tr>';
500  $i = 0;
501  $subtotalcoll = 0;
502  $subtotalpaid = 0;
503  $subtotal = 0;
504  }
505  }
506  print '<tr class="liste_total"><td class="right" colspan="3">' . $langs->trans("TotalToPay") . ':</td><td class="nowrap right">' . price(price2num($total, 'MT')) . '</td>';
507  print "<td>&nbsp;</td>\n";
508  print '</tr>';
509 
510  print '</table>';
511 
512 
513  print '</div><div class="fichetwothirdright">';
514 
515 
516  /*
517  * Paid
518  */
519  print load_fiche_titre($langs->trans("VATPaid"), '', '');
520 
521  $sql = '';
522 
523  $sql .= "SELECT SUM(amount) as mm, date_format(tva.datev,'%Y-%m') as dm, 'claimed' as mode";
524  $sql .= " FROM " . MAIN_DB_PREFIX . "tva as tva";
525  $sql .= " WHERE tva.entity = " . $conf->entity;
526  $sql .= " AND (tva.datev >= '" . $db->idate($date_start) . "' AND tva.datev <= '" . $db->idate($date_end) . "')";
527  $sql .= " GROUP BY dm";
528 
529  $sql .= " UNION ";
530 
531  $sql .= "SELECT SUM(ptva.amount) as mm, date_format(tva.datev,'%Y-%m') as dm, 'paid' as mode";
532  $sql .= " FROM " . MAIN_DB_PREFIX . "tva as tva";
533  $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "payment_vat as ptva ON (tva.rowid = ptva.fk_tva)";
534  $sql .= " WHERE tva.entity = " . $conf->entity;
535  $sql .= " AND (tva.datev >= '" . $db->idate($date_start) . "' AND tva.datev <= '" . $db->idate($date_end) . "')";
536  $sql .= " GROUP BY dm";
537 
538  $sql .= " ORDER BY dm ASC, mode ASC";
539  //print $sql;
540 
541  pt($db, $sql, $langs->trans("Month"));
542 
543  print '</div>';
544 }
545 
546 llxFooter();
547 $db->close();
dol_getdate
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
Definition: functions.lib.php:2816
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:50
tax_by_rate
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
$sql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:745
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5363
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:530
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4994
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5834
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2566
llxFooter
llxFooter()
Footer empty.
Definition: index.php:71
llxHeader
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
restrictedArea
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.
Definition: security.lib.php:341
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:431
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
pt
pt($db, $sql, $date)
print function
Definition: index.php:107
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2947
price
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.
Definition: functions.lib.php:5708
dol_mktime
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...
Definition: functions.lib.php:2859
report_header
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
Definition: report.lib.php:41
Tva
Put here description of your class.
Definition: tva.class.php:35