1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/DataMapper/Tax/US/Rule.php

132 lines
3.1 KiB
PHP
Raw Normal View History

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
*/
2023-03-29 05:23:06 +02:00
namespace App\DataMapper\Tax\US;
2023-03-18 13:06:32 +01:00
2023-04-10 07:51:38 +02:00
use App\DataMapper\Tax\BaseRule;
2023-03-24 08:02:34 +01:00
use App\DataMapper\Tax\RuleInterface;
2023-04-10 09:52:40 +02:00
use App\Models\Product;
2023-03-24 08:02:34 +01:00
2023-04-10 07:51:38 +02:00
class Rule extends BaseRule implements RuleInterface
2023-03-18 13:06:32 +01:00
{
2023-04-10 09:52:40 +02:00
public function init(): self
{
$this->calculateRates();
return $this;
}
2023-03-18 13:06:32 +01:00
2023-04-10 09:52:40 +02:00
public function override(): self
{
2023-03-29 04:13:50 +02:00
return $this;
}
2023-04-10 09:33:24 +02:00
public function tax($item = null): self
2023-03-24 08:02:34 +01:00
{
2023-04-02 23:48:59 +02:00
if ($this->client->is_tax_exempt) {
2023-03-26 22:57:29 +02:00
return $this->taxExempt();
2023-04-10 09:52:40 +02:00
} elseif($this->client->company->tax_data->regions->US->tax_all_subregions || $this->client->company->tax_data->regions->US->subregions->{$this->client_subregion}->apply_tax) {
2023-03-26 22:57:29 +02:00
2023-04-10 09:33:24 +02:00
$this->taxByType($item->tax_id);
2023-04-02 23:48:59 +02:00
return $this;
2023-04-10 09:52:40 +02:00
} elseif($this->client->company->tax_data->regions->{$this->client_region}->tax_all_subregions || $this->client->company->tax_data->regions->{$this->client_region}->subregions->{$this->client_subregion}->apply_tax) { //other regions outside of US
2023-04-10 07:51:38 +02:00
}
2023-03-24 08:58:59 +01:00
return $this;
2023-03-24 08:02:34 +01:00
}
2023-03-31 06:25:30 +02:00
public function taxByType($product_tax_type): self
2023-03-24 08:02:34 +01:00
{
2023-04-10 09:52:40 +02:00
match($product_tax_type) {
2023-03-28 22:53:46 +02:00
Product::PRODUCT_TYPE_EXEMPT => $this->taxExempt(),
2023-03-24 08:02:34 +01:00
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-29 04:13:50 +02:00
Product::PRODUCT_TYPE_REDUCED_TAX => $this->taxReduced(),
Product::PRODUCT_TYPE_OVERRIDE_TAX => $this->override(),
2023-03-24 08:02:34 +01:00
default => $this->default(),
};
return $this;
}
2023-03-24 08:58:59 +01:00
public function taxExempt(): self
2023-03-24 08:02:34 +01:00
{
$this->tax_name1 = '';
$this->tax_rate1 = 0;
2023-03-24 08:58:59 +01:00
return $this;
2023-03-24 08:02:34 +01:00
}
2023-03-24 08:58:59 +01:00
public function taxDigital(): self
2023-03-24 08:02:34 +01:00
{
2023-04-02 23:48:59 +02:00
$this->default();
2023-03-24 08:58:59 +01:00
return $this;
2023-03-24 08:02:34 +01:00
}
2023-03-24 08:58:59 +01:00
public function taxService(): self
2023-03-24 08:02:34 +01:00
{
2023-04-10 09:52:40 +02:00
if($this->tax_data->txbService == 'Y') {
2023-04-02 23:48:59 +02:00
$this->default();
2023-04-10 09:52:40 +02:00
}
2023-03-24 08:58:59 +01:00
return $this;
2023-03-24 08:02:34 +01:00
}
2023-03-24 08:58:59 +01:00
public function taxShipping(): self
2023-03-24 08:02:34 +01:00
{
2023-04-10 09:52:40 +02:00
if($this->tax_data->txbFreight == 'Y') {
2023-04-02 23:48:59 +02:00
$this->default();
2023-04-10 09:52:40 +02:00
}
2023-03-24 08:58:59 +01:00
return $this;
2023-03-24 08:02:34 +01:00
}
2023-03-24 08:58:59 +01:00
public function taxPhysical(): self
2023-03-24 08:02:34 +01:00
{
2023-04-02 23:48:59 +02:00
$this->default();
2023-03-24 08:58:59 +01:00
return $this;
2023-03-24 08:02:34 +01:00
}
2023-03-24 08:58:59 +01:00
public function default(): self
2023-03-24 08:02:34 +01:00
{
2023-04-02 23:48:59 +02:00
$this->tax_rate1 = $this->tax_data->taxSales * 100;
$this->tax_name1 = "{$this->tax_data->geoState} Sales Tax";
2023-03-24 08:58:59 +01:00
return $this;
2023-03-24 08:02:34 +01:00
}
2023-03-26 22:46:26 +02:00
public function taxReduced(): self
{
2023-04-02 23:48:59 +02:00
$this->default();
2023-03-26 22:46:26 +02:00
return $this;
}
2023-03-29 05:30:16 +02:00
public function calculateRates(): self
{
2023-04-10 09:52:40 +02:00
if($this->client_region != 'US' && $this->isTaxableRegion()) {
}
2023-03-29 05:30:16 +02:00
return $this;
}
2023-03-18 13:06:32 +01:00
}