mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixes for tests
This commit is contained in:
parent
fa9f9ab462
commit
79383b8811
@ -147,6 +147,8 @@ class BaseRule implements RuleInterface
|
|||||||
|
|
||||||
$this->configTaxData();
|
$this->configTaxData();
|
||||||
|
|
||||||
|
nlog($this->invoice->tax_data);
|
||||||
|
|
||||||
$this->tax_data = new Response($this->invoice->tax_data);
|
$this->tax_data = new Response($this->invoice->tax_data);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -176,7 +178,8 @@ class BaseRule implements RuleInterface
|
|||||||
* Destination - Client Tax Data
|
* Destination - Client Tax Data
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
$tax_data = new Response([]);
|
// $tax_data = new Response([]);
|
||||||
|
$tax_data = false;
|
||||||
|
|
||||||
if($this->seller_region == 'US' && $this->client_region == 'US'){
|
if($this->seller_region == 'US' && $this->client_region == 'US'){
|
||||||
|
|
||||||
@ -215,9 +218,9 @@ class BaseRule implements RuleInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Applies the tax data to the invoice */
|
/** Applies the tax data to the invoice */
|
||||||
if($this->invoice instanceof Invoice) {
|
if($this->invoice instanceof Invoice && $tax_data) {
|
||||||
|
|
||||||
$this->invoice->tax_data = $tax_data;
|
$this->invoice->tax_data = $tax_data ;
|
||||||
|
|
||||||
if(\DB::transactionLevel() == 0)
|
if(\DB::transactionLevel() == 0)
|
||||||
$this->invoice->saveQuietly();
|
$this->invoice->saveQuietly();
|
||||||
@ -273,7 +276,7 @@ class BaseRule implements RuleInterface
|
|||||||
public function defaultForeign(): self
|
public function defaultForeign(): self
|
||||||
{
|
{
|
||||||
|
|
||||||
if($this->client_region == 'US') {
|
if($this->client_region == 'US' && isset($this->tax_data?->taxSales)) {
|
||||||
|
|
||||||
$this->tax_rate1 = $this->tax_data->taxSales * 100;
|
$this->tax_rate1 = $this->tax_data->taxSales * 100;
|
||||||
$this->tax_name1 = "{$this->tax_data->geoState} Sales Tax";
|
$this->tax_name1 = "{$this->tax_data->geoState} Sales Tax";
|
||||||
|
@ -30,10 +30,10 @@ class Rule extends BaseRule implements RuleInterface
|
|||||||
public bool $eu_business_tax_exempt = true;
|
public bool $eu_business_tax_exempt = true;
|
||||||
|
|
||||||
/** @var bool $foreign_business_tax_exempt */
|
/** @var bool $foreign_business_tax_exempt */
|
||||||
public bool $foreign_business_tax_exempt = true;
|
public bool $foreign_business_tax_exempt = false;
|
||||||
|
|
||||||
/** @var bool $foreign_consumer_tax_exempt */
|
/** @var bool $foreign_consumer_tax_exempt */
|
||||||
public bool $foreign_consumer_tax_exempt = true;
|
public bool $foreign_consumer_tax_exempt = false;
|
||||||
|
|
||||||
/** @var float $tax_rate */
|
/** @var float $tax_rate */
|
||||||
public float $tax_rate = 0;
|
public float $tax_rate = 0;
|
||||||
@ -223,38 +223,42 @@ class Rule extends BaseRule implements RuleInterface
|
|||||||
public function calculateRates(): self
|
public function calculateRates(): self
|
||||||
{
|
{
|
||||||
if ($this->client->is_tax_exempt) {
|
if ($this->client->is_tax_exempt) {
|
||||||
// nlog("tax exempt");
|
nlog("tax exempt");
|
||||||
$this->tax_rate = 0;
|
$this->tax_rate = 0;
|
||||||
$this->reduced_tax_rate = 0;
|
$this->reduced_tax_rate = 0;
|
||||||
}
|
}
|
||||||
elseif($this->client_subregion != $this->client->company->tax_data->seller_subregion && in_array($this->client_subregion, $this->eu_country_codes) && $this->client->has_valid_vat_number && $this->eu_business_tax_exempt)
|
elseif($this->client_subregion != $this->client->company->tax_data->seller_subregion && in_array($this->client_subregion, $this->eu_country_codes) && $this->client->has_valid_vat_number && $this->eu_business_tax_exempt)
|
||||||
{
|
{
|
||||||
// nlog("euro zone and tax exempt");
|
nlog("euro zone and tax exempt");
|
||||||
$this->tax_rate = 0;
|
$this->tax_rate = 0;
|
||||||
$this->reduced_tax_rate = 0;
|
$this->reduced_tax_rate = 0;
|
||||||
}
|
}
|
||||||
elseif(!in_array($this->client_subregion, $this->eu_country_codes) && ($this->foreign_consumer_tax_exempt || $this->foreign_business_tax_exempt)) //foreign + tax exempt
|
elseif(!in_array($this->client_subregion, $this->eu_country_codes) && ($this->foreign_consumer_tax_exempt || $this->foreign_business_tax_exempt)) //foreign + tax exempt
|
||||||
{
|
{
|
||||||
// nlog("foreign and tax exempt");
|
nlog("foreign and tax exempt");
|
||||||
$this->tax_rate = 0;
|
$this->tax_rate = 0;
|
||||||
$this->reduced_tax_rate = 0;
|
$this->reduced_tax_rate = 0;
|
||||||
}
|
}
|
||||||
|
elseif(!in_array($this->client_subregion, $this->eu_country_codes))
|
||||||
|
{
|
||||||
|
$this->defaultForeign();
|
||||||
|
}
|
||||||
elseif(in_array($this->client_subregion, $this->eu_country_codes) && !$this->client->has_valid_vat_number) //eu country / no valid vat
|
elseif(in_array($this->client_subregion, $this->eu_country_codes) && !$this->client->has_valid_vat_number) //eu country / no valid vat
|
||||||
{
|
{
|
||||||
if(($this->client->company->tax_data->seller_subregion != $this->client_subregion) && $this->client->company->tax_data->regions->EU->has_sales_above_threshold)
|
if(($this->client->company->tax_data->seller_subregion != $this->client_subregion) && $this->client->company->tax_data->regions->EU->has_sales_above_threshold)
|
||||||
{
|
{
|
||||||
// nlog("eu zone with sales above threshold");
|
nlog("eu zone with sales above threshold");
|
||||||
$this->tax_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->country->iso_3166_2}->tax_rate;
|
$this->tax_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->country->iso_3166_2}->tax_rate;
|
||||||
$this->reduced_tax_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->country->iso_3166_2}->reduced_tax_rate;
|
$this->reduced_tax_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->country->iso_3166_2}->reduced_tax_rate;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// nlog("EU with intra-community supply ie DE to DE");
|
nlog("EU with intra-community supply ie DE to DE");
|
||||||
$this->tax_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->company->country()->iso_3166_2}->tax_rate;
|
$this->tax_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->company->country()->iso_3166_2}->tax_rate;
|
||||||
$this->reduced_tax_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->company->country()->iso_3166_2}->reduced_tax_rate;
|
$this->reduced_tax_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->company->country()->iso_3166_2}->reduced_tax_rate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// nlog("default tax");
|
nlog("default tax");
|
||||||
$this->tax_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->company->country()->iso_3166_2}->tax_rate;
|
$this->tax_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->company->country()->iso_3166_2}->tax_rate;
|
||||||
$this->reduced_tax_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->company->country()->iso_3166_2}->reduced_tax_rate;
|
$this->reduced_tax_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->company->country()->iso_3166_2}->reduced_tax_rate;
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,8 @@ class EuTaxTest extends TestCase
|
|||||||
'user_id' => $this->user->id,
|
'user_id' => $this->user->id,
|
||||||
'company_id' => $company->id,
|
'company_id' => $company->id,
|
||||||
'country_id' => 840,
|
'country_id' => 840,
|
||||||
|
'state' => 'CA',
|
||||||
|
'postal_code' => '90210',
|
||||||
'shipping_country_id' => 840,
|
'shipping_country_id' => 840,
|
||||||
'has_valid_vat_number' => false,
|
'has_valid_vat_number' => false,
|
||||||
'is_tax_exempt' => false,
|
'is_tax_exempt' => false,
|
||||||
@ -113,13 +115,88 @@ class EuTaxTest extends TestCase
|
|||||||
'taxSales' => 0.07,
|
'taxSales' => 0.07,
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$invoice = $invoice->calc()->getInvoice()->service()->markSent()->save();
|
$invoice = $invoice->calc()->getInvoice()->service()->markSent()->save();
|
||||||
|
|
||||||
$this->assertEquals(107, $invoice->amount);
|
$this->assertEquals(107, $invoice->amount);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testEuToAuTaxCalculation()
|
||||||
|
{
|
||||||
|
|
||||||
|
$settings = CompanySettings::defaults();
|
||||||
|
$settings->country_id = '276'; // germany
|
||||||
|
|
||||||
|
$tax_data = new TaxModel();
|
||||||
|
$tax_data->seller_subregion = 'DE';
|
||||||
|
$tax_data->regions->EU->has_sales_above_threshold = false;
|
||||||
|
$tax_data->regions->EU->tax_all_subregions = true;
|
||||||
|
$tax_data->regions->AU->tax_all_subregions = true;
|
||||||
|
$tax_data->regions->AU->has_sales_above_threshold = true;
|
||||||
|
|
||||||
|
$company = Company::factory()->create([
|
||||||
|
'account_id' => $this->account->id,
|
||||||
|
'settings' => $settings,
|
||||||
|
'tax_data' => $tax_data,
|
||||||
|
'calculate_taxes' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$client = Client::factory()->create([
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'company_id' => $company->id,
|
||||||
|
'country_id' => 36,
|
||||||
|
'shipping_country_id' => 36,
|
||||||
|
'has_valid_vat_number' => false,
|
||||||
|
'is_tax_exempt' => false,
|
||||||
|
// 'tax_data' => new Response([
|
||||||
|
// 'geoState' => 'CA',
|
||||||
|
// 'taxSales' => 0.07,
|
||||||
|
// ]),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$invoice = Invoice::factory()->create([
|
||||||
|
'company_id' => $company->id,
|
||||||
|
'client_id' => $client->id,
|
||||||
|
'status_id' => 1,
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'uses_inclusive_taxes' => false,
|
||||||
|
'discount' => 0,
|
||||||
|
'line_items' => [
|
||||||
|
[
|
||||||
|
'product_key' => 'Test',
|
||||||
|
'notes' => 'Test',
|
||||||
|
'cost' => 100,
|
||||||
|
'quantity' => 1,
|
||||||
|
'tax_name1' => '',
|
||||||
|
'tax_rate1' => 0,
|
||||||
|
'tax_name2' => '',
|
||||||
|
'tax_rate2' => 0,
|
||||||
|
'tax_name3' => '',
|
||||||
|
'tax_rate3' => 0,
|
||||||
|
'type_id' => '1',
|
||||||
|
'tax_id' => Product::PRODUCT_TYPE_PHYSICAL,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'tax_rate1' => 0,
|
||||||
|
'tax_rate2' => 0,
|
||||||
|
'tax_rate3' => 0,
|
||||||
|
'tax_name1' => '',
|
||||||
|
'tax_name2' => '',
|
||||||
|
'tax_name3' => '',
|
||||||
|
// 'tax_data' => new Response([
|
||||||
|
// 'geoState' => 'CA',
|
||||||
|
// 'taxSales' => 0.07,
|
||||||
|
// ]),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$invoice = $invoice->calc()->getInvoice()->service()->markSent()->save();
|
||||||
|
|
||||||
|
$this->assertEquals(110, $invoice->amount);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function testInvoiceTaxCalcDetoBeNoVat()
|
public function testInvoiceTaxCalcDetoBeNoVat()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user