110function pt(
$db, $sql, $date)
112 global
$conf, $bc, $langs, $form;
114 $result =
$db->query($sql);
116 $num =
$db->num_rows($result);
119 print
'<table class="noborder centpercent">';
121 print
'<tr class="liste_titre">';
122 print
'<td class="nowrap">'.$date.
'</td>';
123 print
'<td class="right">'.$langs->trans(
"ClaimedForThisPeriod").
'</td>';
124 print
'<td class="right">'.$langs->trans(
"PaidDuringThisPeriod").$form->textwithpicto(
'', $langs->trans(
'PaidDuringThisPeriodDesc'), 1).
'</td>';
136 $obj =
$db->fetch_object($result);
140 if ($obj->mode ==
'claimed' && !empty($previousmode)) {
141 print
'<tr class="oddeven">';
142 print
'<td class="nowrap">'.$previousmonth.
"</td>\n";
143 print
'<td class="nowrap right"><span class="amount">'.price($amountclaimed).
"</span></td>\n";
144 print
'<td class="nowrap right"><span class="amount">'.price($amountpaid).
"</span></td>\n";
151 if ($obj->mode ==
'claimed') {
152 $amountclaimed = $obj->mm;
153 $totalclaimed += $amountclaimed;
155 if ($obj->mode ==
'paid') {
156 $amountpaid = $obj->mm;
157 $totalpaid += $amountpaid;
160 if ($obj->mode ==
'paid') {
161 print
'<tr class="oddeven">';
162 print
'<td class="nowrap">'.$obj->dm.
"</td>\n";
163 print
'<td class="nowrap right"><span class="amount">'.price($amountclaimed).
"</span></td>\n";
164 print
'<td class="nowrap right"><span class="amount">'.price($amountpaid).
"</span></td>\n";
171 $previousmode = $obj->mode;
172 $previousmonth = $obj->dm;
178 if ($mode ==
'claimed' && !empty($previousmode)) {
179 print
'<tr class="oddeven">';
180 print
'<td class="nowrap">'.$previousmonth.
"</td>\n";
181 print
'<td class="nowrap right">'.price($amountclaimed).
"</td>\n";
182 print
'<td class="nowrap right">'.price($amountpaid).
"</td>\n";
189 print
'<tr class="liste_total">';
190 print
'<td class="right">'.$langs->trans(
"Total").
'</td>';
191 print
'<td class="nowrap right">'.price($totalclaimed).
'</td>';
192 print
'<td class="nowrap right">'.price($totalpaid).
'</td>';
212$fsearch =
'<!-- hidden fields for form -->';
213$fsearch .=
'<input type="hidden" name="token" value="'.newToken().
'">';
214$fsearch .=
'<input type="hidden" name="modetax" value="'.$modetax.
'">';
216$description = $fsearch;
219$name = $langs->trans(
"VATReportByMonth");
222 $calcmode = $langs->trans(
'OptionVATDefault');
225 $calcmode = $langs->trans(
'OptionVATDebitOption');
228 $calcmode = $langs->trans(
'OptionPaymentForProductAndServices');
230$calcmode .=
' <span class="opacitymedium">('.$langs->trans(
"TaxModuleSetupToModifyRules", DOL_URL_ROOT.
'/admin/taxes.php').
')</span>';
232$description .= $langs->trans(
"VATSummary").
'<br>';
234 $description .= $langs->trans(
"RulesVATDueProducts");
237 $description .= $langs->trans(
"RulesVATInProducts");
240 $description .=
'<br>'.$langs->trans(
"RulesVATDueServices");
243 $description .=
'<br>'.$langs->trans(
"RulesVATInServices");
246 $description .=
'<br>'.$langs->trans(
"DepositsAreNotIncluded");
249 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
252 $description .=
'<br>'.$langs->trans(
"ThisIsAnEstimatedValue");
255$period = $form->selectDate(
$date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
269report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
275if ($refresh ===
true) {
276 print
'<div class="fichecenter"><div class="fichethirdleft">';
280 print
'<table class="noborder centpercent">';
281 print
'<tr class="liste_titre">';
282 print
'<td width="30%">' . $langs->trans(
"Year") .
'</td>';
283 print
'<td class="right">' . $langs->trans(
"VATToPay") .
'</td>';
284 print
'<td class="right">' . $langs->trans(
"VATToCollect") .
'</td>';
285 print
'<td class="right">' . $langs->trans(
"Balance") .
'</td>';
286 print
'<td> </td>' .
"\n";
287 print
'</tr>' .
"\n";
293 $yend = $tmp[
'year'];
303 while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) {
313 $x_coll =
tax_by_rate(
'vat',
$db, $y, 0, 0, 0, $modetax,
'sell', $m);
314 $x_paye =
tax_by_rate(
'vat',
$db, $y, 0, 0, 0, $modetax,
'buy', $m);
318 foreach (array_keys($x_coll) as $my_coll_rate) {
319 $x_both[$my_coll_rate] = array(
325 $x_both[$my_coll_rate][
'coll'][
'totalht'] = $x_coll[$my_coll_rate][
'totalht'];
326 $x_both[$my_coll_rate][
'coll'][
'vat'] = $x_coll[$my_coll_rate][
'vat'];
327 $x_both[$my_coll_rate][
'paye'][
'totalht'] = 0;
328 $x_both[$my_coll_rate][
'paye'][
'vat'] = 0;
329 $x_both[$my_coll_rate][
'coll'][
'links'] =
'';
330 $x_both[$my_coll_rate][
'coll'][
'detail'] = array();
331 foreach ($x_coll[$my_coll_rate][
'facid'] as
$id => $dummy) {
336 $x_both[$my_coll_rate][
'coll'][
'detail'][] = array(
337 'id' => $x_coll[$my_coll_rate][
'facid'][
$id],
338 'descr' => $x_coll[$my_coll_rate][
'descr'][
$id],
339 'pid' => $x_coll[$my_coll_rate][
'pid'][
$id],
340 'pref' => $x_coll[$my_coll_rate][
'pref'][
$id],
341 'ptype' => $x_coll[$my_coll_rate][
'ptype'][
$id],
342 'payment_id' => $x_coll[$my_coll_rate][
'payment_id'][
$id],
343 'payment_amount' => $x_coll[$my_coll_rate][
'payment_amount'][
$id],
344 'ftotal_ttc' => $x_coll[$my_coll_rate][
'ftotal_ttc'][
$id],
345 'dtotal_ttc' => $x_coll[$my_coll_rate][
'dtotal_ttc'][
$id],
346 'dtype' => $x_coll[$my_coll_rate][
'dtype'][
$id],
347 'datef' => $x_coll[$my_coll_rate][
'datef'][
$id],
348 'datep' => $x_coll[$my_coll_rate][
'datep'][
$id],
350 'ddate_start' => $x_coll[$my_coll_rate][
'ddate_start'][
$id],
351 'ddate_end' => $x_coll[$my_coll_rate][
'ddate_end'][
$id],
352 'totalht' => $x_coll[$my_coll_rate][
'totalht_list'][
$id],
353 'vat' => $x_coll[$my_coll_rate][
'vat_list'][
$id],
360 foreach (array_keys($x_paye) as $my_paye_rate) {
361 $x_both[$my_paye_rate][
'paye'][
'totalht'] = $x_paye[$my_paye_rate][
'totalht'];
362 $x_both[$my_paye_rate][
'paye'][
'vat'] = $x_paye[$my_paye_rate][
'vat'];
363 if (!isset($x_both[$my_paye_rate][
'coll'][
'totalht'])) {
364 $x_both[$my_paye_rate][
'coll'][
'totalht'] = 0;
365 $x_both[$my_paye_rate][
'coll'][
'vat'] = 0;
367 $x_both[$my_paye_rate][
'paye'][
'links'] =
'';
368 $x_both[$my_paye_rate][
'paye'][
'detail'] = array();
370 foreach ($x_paye[$my_paye_rate][
'facid'] as
$id => $dummy) {
372 if ($x_paye[$my_paye_rate][
'ptype'][
$id] ==
'ExpenseReportPayment') {
377 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
378 'id' => $x_paye[$my_paye_rate][
'facid'][
$id],
379 'descr' => $x_paye[$my_paye_rate][
'descr'][
$id],
380 'pid' => $x_paye[$my_paye_rate][
'pid'][
$id],
381 'pref' => $x_paye[$my_paye_rate][
'pref'][
$id],
382 'ptype' => $x_paye[$my_paye_rate][
'ptype'][
$id],
383 'payment_id' => $x_paye[$my_paye_rate][
'payment_id'][
$id],
384 'payment_amount' => $x_paye[$my_paye_rate][
'payment_amount'][
$id],
385 'ftotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][
$id]),
386 'dtotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][
$id]),
387 'dtype' => $x_paye[$my_paye_rate][
'dtype'][
$id],
388 'ddate_start' => $x_paye[$my_paye_rate][
'ddate_start'][
$id],
389 'ddate_end' => $x_paye[$my_paye_rate][
'ddate_end'][
$id],
390 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][
$id]),
391 'vat' => $x_paye[$my_paye_rate][
'vat_list'][
$id],
399 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
400 'id' => $x_paye[$my_paye_rate][
'facid'][
$id],
401 'descr' => $x_paye[$my_paye_rate][
'descr'][
$id],
402 'pid' => $x_paye[$my_paye_rate][
'pid'][
$id],
403 'pref' => $x_paye[$my_paye_rate][
'pref'][
$id],
404 'ptype' => $x_paye[$my_paye_rate][
'ptype'][
$id],
405 'payment_id' => $x_paye[$my_paye_rate][
'payment_id'][
$id],
406 'payment_amount' => $x_paye[$my_paye_rate][
'payment_amount'][
$id],
407 'ftotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][
$id]),
408 'dtotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][
$id]),
409 'dtype' => $x_paye[$my_paye_rate][
'dtype'][
$id],
410 'datef' => $x_paye[$my_paye_rate][
'datef'][
$id],
411 'datep' => $x_paye[$my_paye_rate][
'datep'][
$id],
413 'ddate_start' => $x_paye[$my_paye_rate][
'ddate_start'][
$id],
414 'ddate_end' => $x_paye[$my_paye_rate][
'ddate_end'][
$id],
415 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][
$id]),
416 'vat' => $x_paye[$my_paye_rate][
'vat_list'][
$id],
425 $object = array(&$x_coll, &$x_paye, &$x_both);
426 $parameters = array();
427 $parameters[
"mode"] = $modetax;
428 $parameters[
"year"] = $y;
429 $parameters[
"month"] = $m;
430 $parameters[
"type"] =
'vat';
433 $hookmanager->initHooks(array(
'externalbalance'));
434 $reshook = $hookmanager->executeHooks(
'addVatLine', $parameters, $object, $action);
437 print
'<tr class="oddeven">';
438 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>';
441 foreach (array_keys($x_coll) as $rate) {
442 $subtot_coll_total_ht = 0;
443 $subtot_coll_vat = 0;
445 foreach ($x_both[$rate][
'coll'][
'detail'] as $index => $fields) {
447 $ratiopaymentinvoice = 1;
451 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
453 if (!empty($fields[
'ddate_start'])) {
456 if (!empty($fields[
'ddate_end'])) {
464 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
465 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
470 $temp_ht = (float) $fields[
'totalht'] * $ratiopaymentinvoice;
471 $temp_vat = $fields[
'vat'] * $ratiopaymentinvoice;
472 $subtot_coll_total_ht += $temp_ht;
473 $subtot_coll_vat += $temp_vat;
474 $x_coll_sum += $temp_vat;
477 print
'<td class="nowrap right"><span class="amount">' .
price(
price2num($x_coll_sum,
'MT')) .
'</span></td>';
480 foreach (array_keys($x_paye) as $rate) {
481 $subtot_paye_total_ht = 0;
482 $subtot_paye_vat = 0;
484 foreach ($x_both[$rate][
'paye'][
'detail'] as $index => $fields) {
486 $ratiopaymentinvoice = 1;
490 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
492 if (!empty($fields[
'ddate_start'])) {
495 if (!empty($fields[
'ddate_end'])) {
503 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
504 $ratiopaymentinvoice = ($fields[
'payment_amount'] / (float) $fields[
'ftotal_ttc']);
509 $temp_ht = (float) $fields[
'totalht'] * $ratiopaymentinvoice;
510 $temp_vat = $fields[
'vat'] * $ratiopaymentinvoice;
511 $subtot_paye_total_ht += $temp_ht;
512 $subtot_paye_vat += $temp_vat;
513 $x_paye_sum += $temp_vat;
516 print
'<td class="nowrap right"><span class="amount">' .
price(
price2num($x_paye_sum,
'MT')) .
'</span></td>';
518 $subtotalcoll += $x_coll_sum;
519 $subtotalpaid += $x_paye_sum;
521 $diff = $x_coll_sum - $x_paye_sum;
523 $subtotal =
price2num($subtotal + $diff,
'MT');
525 print
'<td class="nowrap right"><span class="amount">' .
price(
price2num($diff,
'MT')) .
'</span></td>' .
"\n";
526 print
"<td> </td>\n";
533 print
'<tr class="liste_total">';
534 print
'<td class="right"><a href="quadri_detail.php?leftmenu=tax_vat&q=' . round($m / 3) .
'&year=' . $y .
'">' . $langs->trans(
"SubTotal") .
'</a>:</td>';
535 print
'<td class="nowrap right">' .
price(
price2num($subtotalcoll,
'MT')) .
'</td>';
536 print
'<td class="nowrap right">' .
price(
price2num($subtotalpaid,
'MT')) .
'</td>';
537 print
'<td class="nowrap right">' .
price(
price2num($subtotal,
'MT')) .
'</td>';
538 print
'<td> </td></tr>';
545 print
'<tr class="liste_total"><td class="right" colspan="3">' . $langs->trans(
"TotalToPay") .
':</td><td class="nowrap right">' .
price(
price2num($total,
'MT')) .
'</td>';
546 print
"<td> </td>\n";
552 print
'</div><div class="fichetwothirdright">';
562 $sql .=
"SELECT SUM(amount) as mm, date_format(tva.datev,'%Y-%m') as dm, 'claimed' as mode";
563 $sql .=
" FROM " . MAIN_DB_PREFIX .
"tva as tva";
564 $sql .=
" WHERE tva.entity = " .
$conf->entity;
565 $sql .=
" AND (tva.datev >= '" .
$db->idate(
$date_start) .
"' AND tva.datev <= '" .
$db->idate($date_end) .
"')";
566 $sql .=
" GROUP BY dm";
570 $sql .=
"SELECT SUM(ptva.amount) as mm, date_format(tva.datev,'%Y-%m') as dm, 'paid' as mode";
571 $sql .=
" FROM " . MAIN_DB_PREFIX .
"tva as tva";
572 $sql .=
" INNER JOIN " . MAIN_DB_PREFIX .
"payment_vat as ptva ON (tva.rowid = ptva.fk_tva)";
573 $sql .=
" WHERE tva.entity = " .
$conf->entity;
574 $sql .=
" AND (tva.datev >= '" .
$db->idate(
$date_start) .
"' AND tva.datev <= '" .
$db->idate($date_end) .
"')";
575 $sql .=
" GROUP BY dm";
577 $sql .=
" ORDER BY dm ASC, mode ASC";
580 pt(
$db, $sql, $langs->trans(
"Month"));