Skip to content

Commit

Permalink
Merge pull request #7132 from Gecka-Apps/5.0-fix1
Browse files Browse the repository at this point in the history
Fixes local taxes repports by rate
  • Loading branch information
eldy committed Jul 10, 2017
2 parents 65ea0fc + 64a5be3 commit 1617dee
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 22 deletions.
16 changes: 7 additions & 9 deletions htdocs/compta/localtax/quadri_detail.php
Expand Up @@ -54,8 +54,9 @@
$year_current = $year;
$year_start = $year;
}
$date_start=dol_mktime(0,0,0,$_REQUEST["date_startmonth"],$_REQUEST["date_startday"],$_REQUEST["date_startyear"]);
$date_end=dol_mktime(23,59,59,$_REQUEST["date_endmonth"],$_REQUEST["date_endday"],$_REQUEST["date_endyear"]);

$date_start = dol_mktime( 0, 0, 0, GETPOST( "date_startmonth" ), GETPOST( "date_startday" ), GETPOST( "date_startyear" ) );
$date_end = dol_mktime( 23, 59, 59, GETPOST( "date_endmonth" ), GETPOST( "date_endday" ), GETPOST( "date_endyear" ) );
// Quarter
if (empty($date_start) || empty($date_end)) // We define date_start and date_end
{
Expand Down Expand Up @@ -92,12 +93,9 @@
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'tax', '', '', 'charges');



/*
/**
* View
*/

$morequerystring='';
$listofparams=array('date_startmonth','date_startyear','date_startday','date_endmonth','date_endyear','date_endday');
foreach($listofparams as $param)
Expand All @@ -118,6 +116,7 @@

$fsearch.=' <input type="hidden" name="year" value="'.$year.'">';
$fsearch.=' <input type="hidden" name="modetax" value="'.$modetax.'">';
$fsearch.=' <input type="hidden" name="localTaxType" value="'.$local.'">';

$calc=$conf->global->MAIN_INFO_LOCALTAX_CALC.$local;

Expand Down Expand Up @@ -196,9 +195,8 @@
$i=0;

// Load arrays of datas
$x_coll = vat_by_date($db, 0, 0, $date_start, $date_end, $modetax, 'sell');
$x_paye = vat_by_date($db, 0, 0, $date_start, $date_end, $modetax, 'buy');

$x_coll = tax_by_date('localtax' . $local, $db, 0, 0, $date_start, $date_end, $modetax, 'sell');
$x_paye = tax_by_date('localtax' . $local, $db, 0, 0, $date_start, $date_end, $modetax, 'buy');

echo '<table class="noborder" width="100%">';

Expand Down
53 changes: 40 additions & 13 deletions htdocs/core/lib/tax.lib.php
Expand Up @@ -181,11 +181,12 @@ function vat_by_thirdparty($db, $y, $date_start, $date_end, $modetax, $direction
}

/**
* Gets VAT to collect for the given year (and given quarter or month)
* The function gets the VAT in split results, as the VAT declaration asks
* to report the amounts for different VAT rates as different lines.
* Gets Tax to collect for the given year (and given quarter or month)
* The function gets the Tax in split results, as the Tax declaration asks
* to report the amounts for different Tax rates as different lines.
* This function also accounts recurrent invoices.
*
* @param string $type Tax type, either 'vat', 'localtax1' or 'localtax2'
* @param DoliDB $db Database handler object
* @param int $y Year
* @param int $q Quarter
Expand All @@ -196,7 +197,7 @@ function vat_by_thirdparty($db, $y, $date_start, $date_end, $modetax, $direction
* @param int $m Month
* @return array List of quarters with vat
*/
function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction, $m=0)
function tax_by_date($type, $db, $y, $q, $date_start, $date_end, $modetax, $direction, $m=0)
{
global $conf;

Expand All @@ -210,8 +211,6 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
$fk_facture2='fk_facture';
$fk_payment='fk_paiement';
$total_tva='total_tva';
$total_localtax1='total_localtax1';
$total_localtax2='total_localtax2';
$paymenttable='paiement';
$paymentfacturetable='paiement_facture';
$invoicefieldref='facnumber';
Expand All @@ -224,21 +223,28 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
$fk_facture2='fk_facturefourn';
$fk_payment='fk_paiementfourn';
$total_tva='tva';
$total_localtax1='total_localtax1';
$total_localtax2='total_localtax2';
$paymenttable='paiementfourn';
$paymentfacturetable='paiementfourn_facturefourn';
$invoicefieldref='ref';
}

if ( strpos( $type, 'localtax' ) === 0 ) {
$f_rate = $type . '_tx';
} else {
$f_rate = 'tva_tx';
}

$total_localtax1='total_localtax1';
$total_localtax2='total_localtax2';

// CAS DES BIENS

// Define sql request
$sql='';
if ($modetax == 1) // Option vat on delivery for goods (payment) and debit invoice for services
{
// Count on delivery date (use invoice date as delivery is unknown)
$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_tx as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
$sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
$sql.= " d.date_start as date_start, d.date_end as date_end,";
$sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
Expand Down Expand Up @@ -273,7 +279,7 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
else // Option vat on delivery for goods (payments) and payments for services
{
// Count on delivery date (use invoice date as delivery is unknown)
$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_tx as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
$sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
$sql.= " d.date_start as date_start, d.date_end as date_end,";
$sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef as date_f, s.nom as company_name, s.rowid as company_id,";
Expand Down Expand Up @@ -378,7 +384,7 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
if ($modetax == 1) // Option vat on delivery for goods (payment) and debit invoice for services
{
// Count on invoice date
$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_tx as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
$sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
$sql.= " d.date_start as date_start, d.date_end as date_end,";
$sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
Expand Down Expand Up @@ -413,7 +419,7 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
else // Option vat on delivery for goods (payments) and payments for services
{
// Count on payments date
$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_tx as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
$sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
$sql.= " d.date_start as date_start, d.date_end as date_end,";
$sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
Expand Down Expand Up @@ -522,7 +528,7 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
$sql='';

// Count on payments date
$sql = "SELECT e.rowid, d.product_type as dtype, e.rowid as facid, d.tva_tx as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.total_tva as total_vat, e.note_private as descr,";
$sql = "SELECT e.rowid, d.product_type as dtype, e.rowid as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.total_tva as total_vat, e.note_private as descr,";
$sql .=" d.total_localtax1 as total_localtax1, d.total_localtax2 as total_localtax2, ";
$sql.= " e.date_debut as date_start, e.date_fin as date_end,";
$sql.= " e.ref as facnum, e.total_ttc as ftotal_ttc, e.date_create, s.nom as company_name, s.rowid as company_id, d.fk_c_type_fees as type,";
Expand Down Expand Up @@ -622,3 +628,24 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
return $list;
}

/**
* Gets VAT to collect for the given year (and given quarter or month)
* The function gets the VAT in split results, as the VAT declaration asks
* to report the amounts for different VAT rates as different lines.
* This function also accounts recurrent invoices.
*
* @param DoliDB $db Database handler object
* @param int $y Year
* @param int $q Quarter
* @param string $date_start Start date
* @param string $date_end End date
* @param int $modetax 0 or 1 (option vat on debit)
* @param int $direction 'sell' (customer invoice) or 'buy' (supplier invoices)
* @param int $m Month
* @return array List of quarters with vat
*/
function vat_by_date ($db, $y, $q, $date_start, $date_end, $modetax, $direction, $m=0)
{
return tax_by_date('vat', $db, $y, $q, $date_start, $date_end, $modetax, $direction, $m);
}

0 comments on commit 1617dee

Please sign in to comment.