2023-03-18 13:06:32 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\DataMapper\Tax\de;
|
|
|
|
|
2023-03-26 22:46:26 +02:00
|
|
|
use App\Models\Client;
|
2023-03-24 08:58:59 +01:00
|
|
|
use App\Models\Product;
|
2023-03-27 22:47:07 +02:00
|
|
|
use App\DataMapper\Tax\BaseRule;
|
2023-03-19 06:14:04 +01:00
|
|
|
use App\DataMapper\Tax\RuleInterface;
|
2023-03-24 08:58:59 +01:00
|
|
|
use App\DataMapper\Tax\ZipTax\Response;
|
2023-03-19 06:14:04 +01:00
|
|
|
|
2023-03-27 22:47:07 +02:00
|
|
|
class Rule extends BaseRule implements RuleInterface
|
2023-03-18 13:06:32 +01:00
|
|
|
{
|
2023-03-27 22:47:07 +02:00
|
|
|
|
2023-03-19 06:14:04 +01:00
|
|
|
public float $vat_rate = 19;
|
2023-03-18 13:06:32 +01:00
|
|
|
|
|
|
|
public float $vat_threshold = 10000;
|
|
|
|
|
2023-03-19 06:14:04 +01:00
|
|
|
public float $vat_reduced_rate = 7;
|
2023-03-18 13:06:32 +01:00
|
|
|
|
|
|
|
public float $vat_reduced_threshold = 10000;
|
|
|
|
|
2023-03-19 06:14:04 +01:00
|
|
|
public bool $consumer_tax_exempt = false;
|
2023-03-18 13:06:32 +01:00
|
|
|
|
2023-03-19 06:14:04 +01:00
|
|
|
public bool $business_tax_exempt = true;
|
2023-03-18 13:06:32 +01:00
|
|
|
|
|
|
|
public bool $eu_business_tax_exempt = true;
|
|
|
|
|
|
|
|
public bool $foreign_business_tax_exempt = true;
|
2023-03-19 06:14:04 +01:00
|
|
|
|
|
|
|
public bool $foreign_consumer_tax_exempt = true;
|
|
|
|
|
2023-03-24 08:58:59 +01:00
|
|
|
public string $tax_name1 = '';
|
2023-03-28 08:37:38 +02:00
|
|
|
|
2023-03-24 08:58:59 +01:00
|
|
|
public float $tax_rate1 = 0;
|
|
|
|
|
|
|
|
public string $tax_name2 = '';
|
2023-03-28 08:37:38 +02:00
|
|
|
|
2023-03-24 08:58:59 +01:00
|
|
|
public float $tax_rate2 = 0;
|
|
|
|
|
|
|
|
public string $tax_name3 = '';
|
2023-03-28 08:37:38 +02:00
|
|
|
|
2023-03-24 08:58:59 +01:00
|
|
|
public float $tax_rate3 = 0;
|
|
|
|
|
2023-03-26 22:46:26 +02:00
|
|
|
protected ?Client $client;
|
2023-03-24 08:58:59 +01:00
|
|
|
|
2023-03-26 22:57:29 +02:00
|
|
|
protected ?Response $tax_data;
|
|
|
|
|
2023-03-26 22:46:26 +02:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setClient(Client $client): self
|
|
|
|
{
|
|
|
|
$this->client = $client;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setTaxData(Response $tax_data): self
|
2023-03-24 08:58:59 +01:00
|
|
|
{
|
|
|
|
$this->tax_data = $tax_data;
|
2023-03-26 22:46:26 +02:00
|
|
|
|
|
|
|
return $this;
|
2023-03-24 08:58:59 +01:00
|
|
|
}
|
|
|
|
|
2023-03-27 05:47:01 +02:00
|
|
|
//need to add logic here to capture if
|
2023-03-24 08:58:59 +01:00
|
|
|
public function tax(): self
|
|
|
|
{
|
2023-03-27 05:47:01 +02:00
|
|
|
if($this->client->is_tax_exempt || $this->client->has_valid_vat_number)
|
2023-03-26 22:57:29 +02:00
|
|
|
return $this->taxExempt();
|
|
|
|
|
2023-03-26 22:14:10 +02:00
|
|
|
$this->tax_name1 = $this->vat_rate;
|
2023-03-27 05:47:01 +02:00
|
|
|
$this->tax_rate1 = "MwSt.";
|
2023-03-24 08:58:59 +01:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function taxByType(?int $product_tax_type): self
|
|
|
|
{
|
2023-03-26 22:57:29 +02:00
|
|
|
|
|
|
|
if ($this->client->is_tax_exempt) {
|
|
|
|
return $this->taxExempt();
|
|
|
|
}
|
|
|
|
|
2023-03-24 08:58:59 +01:00
|
|
|
if(!$product_tax_type)
|
|
|
|
return $this;
|
|
|
|
|
|
|
|
match($product_tax_type){
|
|
|
|
Product::PRODUCT_TAX_EXEMPT => $this->taxExempt(),
|
|
|
|
Product::PRODUCT_TYPE_DIGITAL => $this->taxDigital(),
|
|
|
|
Product::PRODUCT_TYPE_SERVICE => $this->taxService(),
|
|
|
|
Product::PRODUCT_TYPE_SHIPPING => $this->taxShipping(),
|
|
|
|
Product::PRODUCT_TYPE_PHYSICAL => $this->taxPhysical(),
|
2023-03-26 22:46:26 +02:00
|
|
|
Product::PRODUCT_TYPE_REDUCED_TAX => $this->taxReduced(),
|
2023-03-24 08:58:59 +01:00
|
|
|
default => $this->default(),
|
|
|
|
};
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2023-03-26 22:46:26 +02:00
|
|
|
public function taxReduced(): self
|
|
|
|
{
|
|
|
|
$this->tax_rate1 = $this->vat_reduced_rate;
|
2023-03-27 05:47:01 +02:00
|
|
|
$this->tax_name1 = 'ermäßigte MwSt.';
|
2023-03-26 22:46:26 +02:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2023-03-24 08:58:59 +01:00
|
|
|
public function taxExempt(): self
|
|
|
|
{
|
|
|
|
$this->tax_name1 = '';
|
|
|
|
$this->tax_rate1 = 0;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function taxDigital(): self
|
|
|
|
{
|
|
|
|
$this->tax();
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function taxService(): self
|
|
|
|
{
|
2023-03-27 05:47:01 +02:00
|
|
|
$this->tax();
|
2023-03-24 08:58:59 +01:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function taxShipping(): self
|
2023-03-19 06:14:04 +01:00
|
|
|
{
|
2023-03-27 05:47:01 +02:00
|
|
|
$this->tax();
|
2023-03-24 08:58:59 +01:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function taxPhysical(): self
|
|
|
|
{
|
|
|
|
$this->tax();
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function default(): self
|
|
|
|
{
|
|
|
|
|
|
|
|
$this->tax_name1 = '';
|
|
|
|
$this->tax_rate1 = 0;
|
|
|
|
|
2023-03-19 06:14:04 +01:00
|
|
|
return $this;
|
|
|
|
}
|
2023-03-18 13:06:32 +01:00
|
|
|
}
|