mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 11:44:35 -04:00
Fixes for exclusive taxes
This commit is contained in:
parent
c7a82d25b8
commit
66f1f9889b
@ -118,12 +118,7 @@ class InvoiceItemSum
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function calcTaxes()
|
private function calcTaxes()
|
||||||
{\Log::error(print_r($this->settings,1));
|
{
|
||||||
if($this->settings->inclusive_taxes == true)
|
|
||||||
return $this->calcInclusiveTaxes();
|
|
||||||
|
|
||||||
\Log::error("calculating exclusive taxes");
|
|
||||||
\Log::error($this->settings->inclusive_taxes);
|
|
||||||
|
|
||||||
$item_tax = 0;
|
$item_tax = 0;
|
||||||
|
|
||||||
@ -132,61 +127,28 @@ class InvoiceItemSum
|
|||||||
|
|
||||||
$item_tax += $item_tax_rate1_total;
|
$item_tax += $item_tax_rate1_total;
|
||||||
|
|
||||||
|
if($item_tax_rate1_total > 0)
|
||||||
$this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total);
|
$this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total);
|
||||||
|
|
||||||
|
|
||||||
$item_tax_rate2_total = $this->calcLineTax($this->item->tax_rate2, $this->item);
|
$item_tax_rate2_total = $this->calcLineTax($this->item->tax_rate2, $this->item);
|
||||||
|
|
||||||
$item_tax += $item_tax_rate2_total;
|
$item_tax += $item_tax_rate2_total;
|
||||||
|
|
||||||
|
if($item_tax_rate2_total > 0)
|
||||||
$this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $item_tax_rate2_total);
|
$this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $item_tax_rate2_total);
|
||||||
|
|
||||||
|
|
||||||
$item_tax_rate3_total = $this->calcLineTax($this->item->tax_rate3, $this->item);
|
$item_tax_rate3_total = $this->calcLineTax($this->item->tax_rate3, $this->item);
|
||||||
|
|
||||||
$item_tax += $item_tax_rate3_total;
|
$item_tax += $item_tax_rate3_total;
|
||||||
|
|
||||||
|
if($item_tax_rate3_total > 0)
|
||||||
$this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total);
|
$this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total);
|
||||||
|
|
||||||
|
|
||||||
//todo if exclusive add on top, if inclusive need to reduce item rates
|
|
||||||
$this->setTotalTaxes($item_tax);
|
$this->setTotalTaxes($item_tax);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Inclusive taxes are a different beast
|
|
||||||
* the line totals are changed when implementing
|
|
||||||
* inclusive taxes so we need to handle this away from the
|
|
||||||
* calcTaxes method.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private function calcInclusiveTaxes()
|
|
||||||
{
|
|
||||||
\Log::error("calculating inclusive taxes");
|
|
||||||
$tax1 = $this->inclusiveTax($this->item->tax_rate1, $this->item);
|
|
||||||
$tax2 = $this->inclusiveTax($this->item->tax_rate2, $this->item);
|
|
||||||
$tax3 = $this->inclusiveTax($this->item->tax_rate3, $this->item);
|
|
||||||
|
|
||||||
if($tax1>0)
|
|
||||||
$this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $tax1);
|
|
||||||
|
|
||||||
if($tax2>0)
|
|
||||||
$this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $tax2);
|
|
||||||
|
|
||||||
if($tax3>0)
|
|
||||||
$this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $tax3);
|
|
||||||
|
|
||||||
$total_taxes = ($tax1 + $tax2 + $tax3);
|
|
||||||
|
|
||||||
$this->setTotalTaxes($this->getTotalTaxes() + $total_taxes);
|
|
||||||
|
|
||||||
$this->item->line_total -= $total_taxes;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function groupTax($tax_name, $tax_rate, $tax_total)
|
private function groupTax($tax_name, $tax_rate, $tax_total)
|
||||||
{
|
{
|
||||||
$group_tax = [];
|
$group_tax = [];
|
||||||
|
@ -164,16 +164,9 @@ class InvoiceSum
|
|||||||
|
|
||||||
private function calculateTotals()
|
private function calculateTotals()
|
||||||
{
|
{
|
||||||
|
|
||||||
if($this->settings->inclusive_taxes === false)
|
|
||||||
$this->total += $this->total_taxes;
|
$this->total += $this->total_taxes;
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->setSubTotal($this->getSubTotal() - $this->total_taxes);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getInvoice()
|
public function getInvoice()
|
||||||
|
@ -120,8 +120,9 @@ class RandomDataSeeder extends Seeder
|
|||||||
|
|
||||||
$invoices->each(function ($invoice) use($invoice_repo, $user, $company, $client){
|
$invoices->each(function ($invoice) use($invoice_repo, $user, $company, $client){
|
||||||
|
|
||||||
//$invoice->settings->inclusive_taxes = (bool)random_int(0, 1);
|
//$settings = $invoice->settings;
|
||||||
$invoice->settings->inclusive_taxes = true;
|
//$settings->inclusive_taxes = (bool)random_int(0, 1);
|
||||||
|
//$invoice->settings = $settings;
|
||||||
|
|
||||||
$invoice_calc = new InvoiceSum($invoice, $invoice->settings);
|
$invoice_calc = new InvoiceSum($invoice, $invoice->settings);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user