mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 03:17:35 -05:00 
			
		
		
		
	Refactor for taxes
This commit is contained in:
		
							parent
							
								
									6c0c0d9372
								
							
						
					
					
						commit
						bd7722f6f0
					
				@ -99,7 +99,7 @@ class BaseRule implements RuleInterface
 | 
				
			|||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function tax(): self
 | 
					    public function tax($product_tax_type): self
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -81,11 +81,15 @@ class Rule extends BaseRule implements RuleInterface
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //need to add logic here to capture if
 | 
					    //need to add logic here to capture if
 | 
				
			||||||
    public function tax(): self
 | 
					    public function tax($type): self
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if($this->client->is_tax_exempt)
 | 
					        
 | 
				
			||||||
 | 
					        if ($this->client->is_tax_exempt) 
 | 
				
			||||||
            return $this->taxExempt();
 | 
					            return $this->taxExempt();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ($type) 
 | 
				
			||||||
 | 
					            return $this->taxByType($type);
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        $this->tax_rate1  = $this->vat_rate;
 | 
					        $this->tax_rate1  = $this->vat_rate;
 | 
				
			||||||
        $this->tax_name1 = "MwSt.";
 | 
					        $this->tax_name1 = "MwSt.";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -18,7 +18,7 @@ interface RuleInterface
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    public function init();
 | 
					    public function init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function tax();
 | 
					    public function tax(mixed $type);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function taxByType($type);
 | 
					    public function taxByType($type);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -55,15 +55,24 @@ class Rule implements RuleInterface
 | 
				
			|||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function tax(): self
 | 
					    public function tax($type): self
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if($this->client->is_tax_exempt)
 | 
					        
 | 
				
			||||||
 | 
					        if ($this->client->is_tax_exempt) {
 | 
				
			||||||
            return $this->taxExempt();
 | 
					            return $this->taxExempt();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else if($this->client->company->tax_data->regions->US->tax_all){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $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";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return $this;
 | 
					            return $this;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if($type)
 | 
				
			||||||
 | 
					            return $this->taxByType($type);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return $this;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -72,11 +81,6 @@ class Rule implements RuleInterface
 | 
				
			|||||||
        if(!$product_tax_type)
 | 
					        if(!$product_tax_type)
 | 
				
			||||||
            return $this;
 | 
					            return $this;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
        if ($this->client->is_tax_exempt) {
 | 
					 | 
				
			||||||
            return $this->taxExempt();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        match($product_tax_type){
 | 
					        match($product_tax_type){
 | 
				
			||||||
            Product::PRODUCT_TYPE_EXEMPT => $this->taxExempt(),
 | 
					            Product::PRODUCT_TYPE_EXEMPT => $this->taxExempt(),
 | 
				
			||||||
            Product::PRODUCT_TYPE_DIGITAL => $this->taxDigital(),
 | 
					            Product::PRODUCT_TYPE_DIGITAL => $this->taxDigital(),
 | 
				
			||||||
@ -101,7 +105,7 @@ class Rule implements RuleInterface
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function taxDigital(): self
 | 
					    public function taxDigital(): self
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->tax();
 | 
					        $this->default();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -109,7 +113,7 @@ class Rule implements RuleInterface
 | 
				
			|||||||
    public function taxService(): self
 | 
					    public function taxService(): self
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if($this->tax_data->txbService == 'Y')
 | 
					        if($this->tax_data->txbService == 'Y')
 | 
				
			||||||
            $this->tax();
 | 
					            $this->default();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -117,14 +121,14 @@ class Rule implements RuleInterface
 | 
				
			|||||||
    public function taxShipping(): self
 | 
					    public function taxShipping(): self
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if($this->tax_data->txbFreight == 'Y')
 | 
					        if($this->tax_data->txbFreight == 'Y')
 | 
				
			||||||
            $this->tax();
 | 
					            $this->default();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function taxPhysical(): self
 | 
					    public function taxPhysical(): self
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->tax();
 | 
					        $this->default();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -132,15 +136,15 @@ class Rule implements RuleInterface
 | 
				
			|||||||
    public function default(): self
 | 
					    public function default(): self
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
        $this->tax_name1 = 'Tax Exempt';
 | 
					        $this->tax_rate1 = $this->tax_data->taxSales * 100;
 | 
				
			||||||
        $this->tax_rate1 = 0;
 | 
					        $this->tax_name1 = "{$this->tax_data->geoState} Sales Tax";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function taxReduced(): self
 | 
					    public function taxReduced(): self
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->tax();
 | 
					        $this->default();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -199,11 +199,7 @@ class InvoiceItemSum
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    private function calcTaxesAutomatically(): self
 | 
					    private function calcTaxesAutomatically(): self
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if ($this->invoice->company->tax_all_products || ( property_exists($this->item, 'tax_id') && $this->item->tax_id != '')) {
 | 
					        $this->rule->tax($this->item->tax_id ?? null);
 | 
				
			||||||
            $this->rule->tax();
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            $this->rule->init()->taxByType($this->item->tax_id);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        $this->item->tax_name1 = $this->rule->tax_name1;
 | 
					        $this->item->tax_name1 = $this->rule->tax_name1;
 | 
				
			||||||
        $this->item->tax_rate1 = $this->rule->tax_rate1;
 | 
					        $this->item->tax_rate1 = $this->rule->tax_rate1;
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,6 @@
 | 
				
			|||||||
<?php
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use App\Models\Client;
 | 
				
			||||||
use App\Models\Company;
 | 
					use App\Models\Company;
 | 
				
			||||||
use Illuminate\Support\Facades\Schema;
 | 
					use Illuminate\Support\Facades\Schema;
 | 
				
			||||||
use Illuminate\Database\Schema\Blueprint;
 | 
					use Illuminate\Database\Schema\Blueprint;
 | 
				
			||||||
@ -31,6 +32,14 @@ return new class extends Migration
 | 
				
			|||||||
                   $company->tax_data = null;
 | 
					                   $company->tax_data = null;
 | 
				
			||||||
                   $company->save();
 | 
					                   $company->save();
 | 
				
			||||||
               });
 | 
					               });
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        Client::query()
 | 
				
			||||||
 | 
					               ->cursor()
 | 
				
			||||||
 | 
					               ->each(function ($client) {
 | 
				
			||||||
 | 
					                   $client->tax_data = null;
 | 
				
			||||||
 | 
					                   $client->save();
 | 
				
			||||||
 | 
					               });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
				
			|||||||
@ -204,7 +204,6 @@ class UsTaxTest extends TestCase
 | 
				
			|||||||
        $client->save();
 | 
					        $client->save();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $company = $invoice->company;
 | 
					        $company = $invoice->company;
 | 
				
			||||||
        $company->tax_all_products = false;
 | 
					 | 
				
			||||||
        $tax_data = $company->tax_data;
 | 
					        $tax_data = $company->tax_data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $tax_data->regions->US->has_sales_above_threshold = true;
 | 
					        $tax_data->regions->US->has_sales_above_threshold = true;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user