Fixed: Management of option SERVICE_ARE_ECOMMERCE_200238EC

This commit is contained in:
Laurent Destailleur 2015-01-25 16:04:37 +01:00
parent ad68b3ca6c
commit 3ebaaa38d2
3 changed files with 57 additions and 21 deletions

View File

@ -3338,7 +3338,7 @@ function get_product_vat_for_country($idprod, $thirdparty_seller, $idprodfournpr
$sql.= " WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='".$thirdparty_seller->country_code."'";
$sql.= " ORDER BY t.taux DESC, t.recuperableonly ASC";
$sql.= $db->plimit(1);
print $sql;
$resql=$db->query($sql);
if ($resql)
{
@ -3464,7 +3464,7 @@ function get_default_tva($thirdparty_seller, $thirdparty_buyer, $idprod=0, $idpr
// we use the buyer VAT.
if (! empty($conf->global->SERVICE_ARE_ECOMMERCE_200238EC))
{
if (! $seller_in_cee && $buyer_in_cee && ! $thirdparty_buyer->isACompany())
if ($seller_in_cee && $buyer_in_cee && ! $thirdparty_buyer->isACompany())
{
//print 'VATRULE 0';
return get_product_vat_for_country($idprod,$thirdparty_buyer,$idprodfournprice);

View File

@ -2648,7 +2648,7 @@ class Societe extends CommonObject
{
global $conf;
// Define if third party is treated as company of not when nature is unknown
// Define if third party is treated as company (or not) when nature is unknown
$isacompany=empty($conf->global->MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES)?0:1; // 0 by default
if (! empty($this->tva_intra)) $isacompany=1;
else if (! empty($this->typent_code) && in_array($this->typent_code,array('TE_PRIVATE'))) $isacompany=0;

View File

@ -644,6 +644,7 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase
$this->savlangs=$langs;
$this->savdb=$db;
// Sellers
$companyfrnovat=new Societe($db);
$companyfrnovat->country_code='FR';
$companyfrnovat->tva_assuj=0;
@ -651,53 +652,88 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase
$companyfr=new Societe($db);
$companyfr->country_code='FR';
$companyfr->tva_assuj=1;
$companyfr->tva_intra='FR9999';
// Buyers
$companymc=new Societe($db);
$companymc->country_code='MC';
$companymc->tva_assuj=1;
$companyfr->tva_intra='MC9999';
$companyit=new Societe($db);
$companyit->country_code='IT';
$companyit->tva_assuj=1;
$companyit->tva_intra='IT99999';
$notcompanyit=new Societe($db);
$notcompanyit->country_code='IT';
$notcompanyit->tva_assuj=1;
$notcompanyit->tva_intra='';
$notcompanyit->typent_code='TE_PRIVATE';
$companyde=new Societe($db);
$companyde->country_code='DE';
$companyde->tva_assuj=1;
$companyde->tva_intra='DE99999';
$notcompanyde=new Societe($db);
$notcompanyde->country_code='DE';
$notcompanyde->tva_assuj=0;
$notcompanyde->tva_intra='';
$notcompanyde->typent_code='TE_PRIVATE';
$companyus=new Societe($db);
$companyus->country_code='US';
$companyus->tva_assuj=1;
$companyus->tva_intra='';
// Test RULE 0 (FR-IT)
// Test RULE 0 (FR-DE)
// Not tested
// Test RULE 1
$vat=get_default_tva($companyfrnovat,$companymc,0);
$this->assertEquals(0,$vat);
$this->assertEquals(0,$vat,'RULE 1');
// Test RULE 2 (FR-FR)
$vat=get_default_tva($companyfr,$companyfr,0);
$this->assertEquals(20,$vat);
$this->assertEquals(20,$vat,'RULE 2');
// Test RULE 2 (FR-MC)
$vat=get_default_tva($companyfr,$companymc,0);
$this->assertEquals(20,$vat);
$this->assertEquals(20,$vat,'RULE 2');
// Test RULE 3 (FR-IT)
// Test RULE 3 (FR-DE company)
$vat=get_default_tva($companyfr,$companyit,0);
$this->assertEquals(0,$vat);
$this->assertEquals(0,$vat,'RULE 3');
// Test RULE 4 (FR-IT)
$vat=get_default_tva($companyfr,$notcompanyit,0);
$this->assertEquals(20,$vat);
// Test RULE 4 (FR-DE not a company)
$vat=get_default_tva($companyfr,$notcompanyde,0);
$this->assertEquals(20,$vat,'RULE 4');
// Test RULE 5 (FR-US)
$vat=get_default_tva($companyfr,$companyus,0);
$this->assertEquals(0,$vat);
$this->assertEquals(0,$vat,'RULE 5');
// We do same tests but with option SERVICE_ARE_ECOMMERCE_200238EC on.
$conf->global->SERVICE_ARE_ECOMMERCE_200238EC = 1;
// Test RULE 1 (FR-US)
$vat=get_default_tva($companyfr,$companyus,0);
$this->assertEquals(0,$vat,'RULE 1 ECOMMERCE_200238EC');
// Test RULE 2 (FR-FR)
$vat=get_default_tva($companyfr,$companyfr,0);
$this->assertEquals(20,$vat,'RULE 2 ECOMMERCE_200238EC');
// Test RULE 3 (FR-DE company)
$vat=get_default_tva($companyfr,$companyde,0);
$this->assertEquals(0,$vat,'RULE 3 ECOMMERCE_200238EC');
// Test RULE 4 (FR-DE not a company)
$vat=get_default_tva($companyfr,$notcompanyde,0);
$this->assertEquals(19,$vat,'RULE 4 ECOMMERCE_200238EC');
// Test RULE 5 (FR-US)
$vat=get_default_tva($companyfr,$companyus,0);
$this->assertEquals(0,$vat,'RULE 5 ECOMMERCE_200238EC');
}
/**
@ -834,7 +870,7 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase
$this->assertEquals(1000, price2num('1 000.0'));
$this->assertEquals(1000, price2num('1 000','MT'));
$this->assertEquals(1000, price2num('1 000','MU'));
$this->assertEquals(1000.123456, price2num('1 000.123456'));
// Round down
@ -848,8 +884,8 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase
// Text can't be converted
$this->assertEquals('12.4$',price2num('12.4$'));
$this->assertEquals('12r.4$',price2num('12r.4$'));
return true;
return true;
}
}