Fixes for exclusive taxes

This commit is contained in:
David Bomba 2019-10-17 11:25:57 +11:00
parent c7a82d25b8
commit 66f1f9889b
3 changed files with 12 additions and 56 deletions

View File

@ -118,12 +118,7 @@ class InvoiceItemSum
}
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;
@ -132,61 +127,28 @@ class InvoiceItemSum
$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);
$item_tax_rate2_total = $this->calcLineTax($this->item->tax_rate2, $this->item);
$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);
$item_tax_rate3_total = $this->calcLineTax($this->item->tax_rate3, $this->item);
$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);
//todo if exclusive add on top, if inclusive need to reduce item rates
$this->setTotalTaxes($item_tax);
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)
{
$group_tax = [];

View File

@ -164,16 +164,9 @@ class InvoiceSum
private function calculateTotals()
{
if($this->settings->inclusive_taxes === false)
$this->total += $this->total_taxes;
else
{
$this->setSubTotal($this->getSubTotal() - $this->total_taxes);
}
return $this;
}
public function getInvoice()

View File

@ -120,8 +120,9 @@ class RandomDataSeeder extends Seeder
$invoices->each(function ($invoice) use($invoice_repo, $user, $company, $client){
//$invoice->settings->inclusive_taxes = (bool)random_int(0, 1);
$invoice->settings->inclusive_taxes = true;
//$settings = $invoice->settings;
//$settings->inclusive_taxes = (bool)random_int(0, 1);
//$invoice->settings = $settings;
$invoice_calc = new InvoiceSum($invoice, $invoice->settings);