Fix turnover invoiced by vat rate and country. Use fiscal month start.

This commit is contained in:
Laurent Destailleur 2018-05-22 23:09:27 +02:00
parent 354198b31e
commit d072c2eb5d

View File

@ -1,9 +1,5 @@
<?php <?php
/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2018 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2006-2007, 2015 Yannick Warnier <ywarnier@beeznest.org>
* Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -20,8 +16,7 @@
*/ */
/** /**
* \file htdocs/compta/tva/quadri_detail.php * \file htdocs/compta/stats/byratecountry.php
* \ingroup tax
* \brief VAT by rate * \brief VAT by rate
*/ */
@ -240,8 +235,13 @@ print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td width="6%" class="right">' . $langs->trans("TurnoverbyVatrate") . '</td>'; print '<tr class="liste_titre"><td width="6%" class="right">' . $langs->trans("TurnoverbyVatrate") . '</td>';
print '<td align="left">' . $langs->trans("ProductOrService") . '</td>'; print '<td align="left">' . $langs->trans("ProductOrService") . '</td>';
print '<td align="left">' . $langs->trans("Country") . '</td>'; print '<td align="left">' . $langs->trans("Country") . '</td>';
for($i = 1; $i <= 12; $i ++) { $i=0;
print '<td width="60" align="right">' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '</td>'; while($i < 12)
{
$j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START)?1:$conf->global->SOCIETE_FISCAL_MONTH_START);
if ($j > 12) $j -= 12;
print '<td width="60" align="right">' . $langs->trans('MonthShort' . str_pad($j, 2, '0', STR_PAD_LEFT)) . '</td>';
$i++;
} }
print '<td width="60" align="right"><b>' . $langs->trans("TotalHT") . '</b></td></tr>'; print '<td width="60" align="right"><b>' . $langs->trans("TotalHT") . '</b></td></tr>';
@ -271,31 +271,56 @@ dol_syslog("htdocs/compta/tva/index.php sql=" . $sql, LOG_DEBUG);
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) { if ($resql) {
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$totalpermonth = array();
while ( $row = $db->fetch_row($resql)) { while ( $obj = $db->fetch_object($resql)) {
print '<tr class="oddeven"><td class="right">' . vatrate($row[0]) . '</td>'; print '<tr class="oddeven"><td class="right">' . vatrate($obj->vatrate) . '</td>';
if ($row[1] == 0) { if ($obj->product_type == 0) {
print '<td align="left">'. $langs->trans("Product") . '</td>'; print '<td align="left">'. $langs->trans("Product") . '</td>';
} else { } else {
print '<td align="left">'. $langs->trans("Service") . '</td>'; print '<td align="left">'. $langs->trans("Service") . '</td>';
} }
print '<td>' .$row[2] . '</td>'; print '<td>' .$obj->country . '</td>';
for($i = 0; $i < 12; $i++) {
for($i = 3; $i <= 14; $i ++) { $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START)?1:$conf->global->SOCIETE_FISCAL_MONTH_START);
print '<td align="right" width="6%">' . price($row[$i]) . '</td>'; if ($j > 12) $j -= 12;
$monthj = 'month'.str_pad($j, 2, '0', STR_PAD_LEFT);
print '<td align="right" width="6%">' . price($obj->$monthj) . '</td>';
$totalpermonth[$j]=(empty($totalpermonth[$j])?0:$totalpermonth[$j])+$obj->$monthj;
} }
print '<td align="right" width="6%"><b>' . price($row[15]) . '</b></td>'; print '<td align="right" width="6%"><b>' . price($obj->total) . '</b></td>';
$totalpermonth['total']=(empty($totalpermonth['total'])?0:$totalpermonth['total'])+$obj->total;
print '</tr>'; print '</tr>';
} }
$db->free($resql); $db->free($resql);
// Total
print '<tr class="liste_total"><td class="right"></td>';
print '<td align="left"></td>';
print '<td></td>';
for($i = 0; $i < 12; $i++) {
$j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START)?1:$conf->global->SOCIETE_FISCAL_MONTH_START);
if ($j > 12) $j -= 12;
$monthj = 'month'.str_pad($j, 2, '0', STR_PAD_LEFT);
print '<td align="right" width="6%">' . price($totalpermonth[$j]) . '</td>';
}
print '<td align="right" width="6%"><b>' . price($totalpermonth['total']) . '</b></td>';
print '</tr>';
} else { } else {
print $db->lasterror(); // Show last sql error print $db->lasterror(); // Show last sql error
} }
print '<tr class="liste_titre"><td width="6%" class="right">' . $langs->trans("PurchasebyVatrate") . '</td>'; print '<tr class="liste_titre"><td width="6%" class="right">' . $langs->trans("PurchasebyVatrate") . '</td>';
print '<td align="left">' . $langs->trans("ProductOrService") . '</td>'; print '<td align="left">' . $langs->trans("ProductOrService") . '</td>';
print '<td align="left">' . $langs->trans("Country") . '</td>'; print '<td align="left">' . $langs->trans("Country") . '</td>';
for($i = 1; $i <= 12; $i ++) { $i=0;
print '<td width="60" align="right">' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '</td>'; while($i < 12)
{
$j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START)?1:$conf->global->SOCIETE_FISCAL_MONTH_START);
if ($j > 12) $j -= 12;
print '<td width="60" align="right">' . $langs->trans('MonthShort' . str_pad($j, 2, '0', STR_PAD_LEFT)) . '</td>';
$i++;
} }
print '<td width="60" align="right"><b>' . $langs->trans("TotalHT") . '</b></td></tr>'; print '<td width="60" align="right"><b>' . $langs->trans("TotalHT") . '</b></td></tr>';
@ -326,22 +351,40 @@ dol_syslog("htdocs/compta/tva/index.php sql=" . $sql, LOG_DEBUG);
$resql2 = $db->query($sql2); $resql2 = $db->query($sql2);
if ($resql2) { if ($resql2) {
$num = $db->num_rows($resql2); $num = $db->num_rows($resql2);
$totalpermonth = array();
while ( $row = $db->fetch_row($resql2)) { while ( $obj = $db->fetch_object($resql2)) {
print '<tr class="oddeven"><td class="right">' . vatrate($row[0]) . '</td>'; print '<tr class="oddeven"><td class="right">' . vatrate($obj->vatrate) . '</td>';
if ($row[1] == 0) { if ($obj->product_type == 0) {
print '<td align="left">'. $langs->trans("Product") . '</td>'; print '<td align="left">'. $langs->trans("Product") . '</td>';
} else { } else {
print '<td align="left">'. $langs->trans("Service") . '</td>'; print '<td align="left">'. $langs->trans("Service") . '</td>';
} }
print '<td>' . $row[2] . '</td>'; print '<td>' . $obj->country . '</td>';
for($i = 3; $i <= 14; $i ++) { for($i = 0; $i < 12; $i++) {
print '<td align="right" width="6%">' . price($row[$i]) . '</td>'; $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START)?1:$conf->global->SOCIETE_FISCAL_MONTH_START);
if ($j > 12) $j -= 12;
$monthj = 'month'.str_pad($j, 2, '0', STR_PAD_LEFT);
print '<td align="right" width="6%">' . price($obj->$monthj) . '</td>';
$totalpermonth[$j]=(empty($totalpermonth[$j])?0:$totalpermonth[$j])+$obj->$monthj;
} }
print '<td align="right" width="6%"><b>' . price($row[15]) . '</b></td>'; print '<td align="right" width="6%"><b>' . price($obj->total) . '</b></td>';
$totalpermonth['total']=(empty($totalpermonth['total'])?0:$totalpermonth['total'])+$obj->total;
print '</tr>'; print '</tr>';
} }
$db->free($resql2); $db->free($resql2);
// Total
print '<tr class="liste_total"><td class="right"></td>';
print '<td align="left"></td>';
print '<td></td>';
for($i = 0; $i < 12; $i++) {
$j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START)?1:$conf->global->SOCIETE_FISCAL_MONTH_START);
if ($j > 12) $j -= 12;
$monthj = 'month'.str_pad($j, 2, '0', STR_PAD_LEFT);
print '<td align="right" width="6%">' . price($totalpermonth[$j]) . '</td>';
}
print '<td align="right" width="6%"><b>' . price($totalpermonth['total']) . '</b></td>';
print '</tr>';
} else { } else {
print $db->lasterror(); // Show last sql error print $db->lasterror(); // Show last sql error
} }