mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-09-20 16:31:33 +02:00
Doc blocks for Rules
This commit is contained in:
parent
b3d9dc3a51
commit
47e35fe4d1
@ -16,30 +16,49 @@ use App\DataMapper\Tax\BaseRule;
|
||||
use App\DataMapper\Tax\RuleInterface;
|
||||
|
||||
class Rule extends BaseRule implements RuleInterface
|
||||
{
|
||||
{
|
||||
/** @var string $seller_region */
|
||||
public string $seller_region = 'EU';
|
||||
|
||||
|
||||
/** @var bool $consumer_tax_exempt */
|
||||
public bool $consumer_tax_exempt = false;
|
||||
|
||||
|
||||
/** @var bool $business_tax_exempt */
|
||||
public bool $business_tax_exempt = false;
|
||||
|
||||
|
||||
/** @var bool $eu_business_tax_exempt */
|
||||
public bool $eu_business_tax_exempt = true;
|
||||
|
||||
|
||||
/** @var bool $foreign_business_tax_exempt */
|
||||
public bool $foreign_business_tax_exempt = true;
|
||||
|
||||
|
||||
/** @var bool $foreign_consumer_tax_exempt */
|
||||
public bool $foreign_consumer_tax_exempt = true;
|
||||
|
||||
|
||||
/** @var float $tax_rate */
|
||||
public float $tax_rate = 0;
|
||||
|
||||
|
||||
/** @var float $reduced_tax_rate */
|
||||
public float $reduced_tax_rate = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the rules and builds any required data.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function init(): self
|
||||
{
|
||||
$this->calculateRates();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the correct tax rate based on the product type.
|
||||
*
|
||||
* @param mixed $product_tax_type
|
||||
* @return self
|
||||
*/
|
||||
public function taxByType($product_tax_type): self
|
||||
{
|
||||
|
||||
@ -60,7 +79,12 @@ class Rule extends BaseRule implements RuleInterface
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the tax rate for a reduced tax product
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function taxReduced(): self
|
||||
{
|
||||
$this->tax_rate1 = $this->reduced_tax_rate;
|
||||
@ -68,7 +92,12 @@ class Rule extends BaseRule implements RuleInterface
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the tax rate for a tax exempt product
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function taxExempt(): self
|
||||
{
|
||||
$this->tax_name1 = '';
|
||||
@ -76,37 +105,56 @@ class Rule extends BaseRule implements RuleInterface
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the tax rate for a digital product
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function taxDigital(): self
|
||||
{
|
||||
// $this->tax();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the tax rate for a service product
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function taxService(): self
|
||||
{
|
||||
// $this->tax();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the tax rate for a shipping product
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function taxShipping(): self
|
||||
{
|
||||
// $this->tax();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the tax rate for a physical product
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function taxPhysical(): self
|
||||
{
|
||||
// $this->tax();
|
||||
|
||||
$this->tax_rate1 = $this->tax_rate;
|
||||
$this->tax_name1 = 'MwSt.';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the tax rate for a default product
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function default(): self
|
||||
{
|
||||
|
||||
@ -115,28 +163,38 @@ class Rule extends BaseRule implements RuleInterface
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the tax rate for an override product
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function override(): self
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the tax rates based on the client's location.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function calculateRates(): self
|
||||
{
|
||||
if ($this->client->is_tax_exempt) {
|
||||
nlog("tax exempt");
|
||||
// nlog("tax exempt");
|
||||
$this->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)
|
||||
{
|
||||
nlog("euro zone and tax exempt");
|
||||
// nlog("euro zone and tax exempt");
|
||||
$this->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
|
||||
{
|
||||
nlog("foreign and tax exempt");
|
||||
// nlog("foreign and tax exempt");
|
||||
$this->tax_rate = 0;
|
||||
$this->reduced_tax_rate = 0;
|
||||
}
|
||||
@ -144,18 +202,18 @@ class Rule extends BaseRule implements RuleInterface
|
||||
{
|
||||
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->reduced_tax_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->country->iso_3166_2}->reduced_tax_rate;
|
||||
}
|
||||
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->reduced_tax_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->company->country()->iso_3166_2}->reduced_tax_rate;
|
||||
}
|
||||
}
|
||||
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->reduced_tax_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->company->country()->iso_3166_2}->reduced_tax_rate;
|
||||
}
|
||||
|
@ -13,13 +13,22 @@ namespace App\DataMapper\Tax;
|
||||
|
||||
class TaxModel
|
||||
{
|
||||
|
||||
|
||||
/** @var mixed $seller_subregion */
|
||||
public string $seller_subregion = 'CA';
|
||||
|
||||
|
||||
/** @var mixed $version */
|
||||
public string $version = 'alpha';
|
||||
|
||||
|
||||
/** @var mixed $regions */
|
||||
public object $regions;
|
||||
|
||||
|
||||
/**
|
||||
* __construct
|
||||
*
|
||||
* @param mixed $model
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(public ?TaxModel $model = null)
|
||||
{
|
||||
|
||||
@ -29,7 +38,12 @@ class TaxModel
|
||||
$this->regions = $model;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the rules and builds any required data.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->regions = new \stdClass();
|
||||
@ -43,7 +57,12 @@ class TaxModel
|
||||
|
||||
return $this->regions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds the model for Australian Taxes
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
private function auRegion(): self
|
||||
{
|
||||
$this->regions->AU = new \stdClass();
|
||||
@ -54,7 +73,12 @@ class TaxModel
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds the model for Australian Subregions
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
private function auSubRegions(): self
|
||||
{
|
||||
|
||||
@ -66,7 +90,12 @@ class TaxModel
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds the model for US Taxes
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
private function usRegion(): self
|
||||
{
|
||||
$this->regions->US->has_sales_above_threshold = false;
|
||||
@ -75,7 +104,12 @@ class TaxModel
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds the model for EU Taxes
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
private function euRegion(): self
|
||||
{
|
||||
|
||||
@ -86,7 +120,12 @@ class TaxModel
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds the model for US States
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
private function usSubRegions(): self
|
||||
{
|
||||
$this->regions->US->subregions = new \stdClass();
|
||||
@ -293,7 +332,12 @@ class TaxModel
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create the EU member countries
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
private function euSubRegions(): self
|
||||
{
|
||||
|
||||
|
@ -15,14 +15,21 @@ use App\DataMapper\Tax\BaseRule;
|
||||
use App\DataMapper\Tax\RuleInterface;
|
||||
use App\Models\Product;
|
||||
|
||||
/**
|
||||
* The rules apply US => US taxes using the tax calculator.
|
||||
*
|
||||
* US => Foreign taxes we check the product types still for exemptions, and we all back to the client country tax rate.
|
||||
*/
|
||||
class Rule extends BaseRule implements RuleInterface
|
||||
{
|
||||
public string $seller_region = 'US';
|
||||
|
||||
/** @var string $seller_region */
|
||||
public string $seller_region = 'US';
|
||||
|
||||
/**
|
||||
* The rules apply US => US taxes using the tax calculator.
|
||||
*
|
||||
* US => Foreign taxes we check the product types still for exemptions, and we all back to the client country tax rate.
|
||||
* Initializes the rules and builds any required data.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function init(): self
|
||||
{
|
||||
@ -30,12 +37,23 @@ class Rule extends BaseRule implements RuleInterface
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Override tax class, we use this when we do not modify the input taxes
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function override(): self
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the correct tax rate based on the product type.
|
||||
*
|
||||
* @param mixed $product_tax_type
|
||||
* @return self
|
||||
*/
|
||||
public function taxByType($product_tax_type): self
|
||||
{
|
||||
|
||||
@ -52,7 +70,12 @@ class Rule extends BaseRule implements RuleInterface
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the tax as exempt (0)
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function taxExempt(): self
|
||||
{
|
||||
$this->tax_name1 = '';
|
||||
@ -60,14 +83,24 @@ class Rule extends BaseRule implements RuleInterface
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the tax rate for a digital product
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function taxDigital(): self
|
||||
{
|
||||
$this->default();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the tax rate for a service product
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function taxService(): self
|
||||
{
|
||||
if($this->tax_data->txbService == 'Y') {
|
||||
@ -76,7 +109,12 @@ class Rule extends BaseRule implements RuleInterface
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the tax rate for a shipping product
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function taxShipping(): self
|
||||
{
|
||||
if($this->tax_data->txbFreight == 'Y') {
|
||||
@ -85,14 +123,24 @@ class Rule extends BaseRule implements RuleInterface
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the tax rate for a physical product
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function taxPhysical(): self
|
||||
{
|
||||
$this->default();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the tax rate for an undefined product uses the default tax rate for the client county
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function default(): self
|
||||
{
|
||||
|
||||
@ -101,19 +149,26 @@ class Rule extends BaseRule implements RuleInterface
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the tax rate for a reduced tax product
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function taxReduced(): self
|
||||
{
|
||||
$this->default();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the tax rates to be applied
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function calculateRates(): self
|
||||
{
|
||||
if($this->client_region != 'US' && $this->isTaxableRegion())
|
||||
return $this;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,9 @@ class InvoiceItemSum
|
||||
'SI', // Slovenia
|
||||
'SK', // Slovakia
|
||||
|
||||
'US', //USA
|
||||
'US', // USA
|
||||
|
||||
'AU', // Australia
|
||||
];
|
||||
|
||||
protected $invoice;
|
||||
|
Loading…
Reference in New Issue
Block a user