mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Fixes for inclusive taxes
This commit is contained in:
parent
1dc2aa6eac
commit
1c5421faff
@ -28,10 +28,27 @@ trait CustomValuer
|
||||
public function valuerTax($custom_value, $has_custom_invoice_taxes)
|
||||
{
|
||||
|
||||
if (isset($custom_value) && is_numeric($custom_value) && $has_custom_invoice_taxes) {
|
||||
if (isset($custom_value) && is_numeric($custom_value) && $has_custom_invoice_taxes !== false) {
|
||||
return round($custom_value * ($this->invoice->tax_rate1 / 100), 2) + round($custom_value * ($this->invoice->tax_rate2 / 100), 2) + round($custom_value * ($this->invoice->tax_rate3 / 100), 2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function multiInclusiveTax($value, $has_custom_invoice_taxes) {
|
||||
|
||||
if (isset($custom_value) && is_numeric($custom_value) && $has_custom_invoice_taxes !== false) {
|
||||
|
||||
$tax = 0;
|
||||
|
||||
$tax += $this->formatValue($custom_value - ($custom_value / (1 + ($this->invoice->tax_rate1 / 100))), 2);
|
||||
$tax += $this->formatValue($custom_value - ($custom_value / (1 + ($this->invoice->tax_rate2 / 100))), 2);
|
||||
$tax += $this->formatValue($custom_value - ($custom_value / (1 + ($this->invoice->tax_rate3 / 100))), 2);
|
||||
|
||||
return round($tax,2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -106,20 +106,22 @@ class InvoiceSumInclusive
|
||||
|
||||
private function calculateCustomValues()
|
||||
{
|
||||
$this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge1, $this->invoice->custom_surcharge_tax1);
|
||||
|
||||
$this->total_taxes += $this->multiInclusiveTax($this->invoice->custom_surcharge1, $this->invoice->custom_surcharge_tax1);
|
||||
$this->total_custom_values += $this->valuer($this->invoice->custom_surcharge1);
|
||||
|
||||
$this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge2, $this->invoice->custom_surcharge_tax2);
|
||||
$this->total_taxes += $this->multiInclusiveTax($this->invoice->custom_surcharge2, $this->invoice->custom_surcharge_tax2);
|
||||
$this->total_custom_values += $this->valuer($this->invoice->custom_surcharge2);
|
||||
|
||||
$this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge3, $this->invoice->custom_surcharge_tax3);
|
||||
$this->total_taxes += $this->multiInclusiveTax($this->invoice->custom_surcharge3, $this->invoice->custom_surcharge_tax3);
|
||||
$this->total_custom_values += $this->valuer($this->invoice->custom_surcharge3);
|
||||
|
||||
$this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge4, $this->invoice->custom_surcharge_tax4);
|
||||
$this->total_taxes += $this->multiInclusiveTax($this->invoice->custom_surcharge4, $this->invoice->custom_surcharge_tax4);
|
||||
$this->total_custom_values += $this->valuer($this->invoice->custom_surcharge4);
|
||||
|
||||
|
||||
$this->total += $this->total_custom_values;
|
||||
nlog($this->total_taxes);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -136,24 +138,22 @@ nlog($this->total_taxes);
|
||||
}
|
||||
|
||||
//Handles cases where the surcharge is not taxed
|
||||
if(is_numeric($this->invoice->custom_surcharge1) && $this->invoice->custom_surcharge1 > 0 && !$this->invoice->custom_surcharge_tax1) {
|
||||
$amount -= $this->invoice->custom_surcharge1;
|
||||
if(is_numeric($this->invoice->custom_surcharge1) && $this->invoice->custom_surcharge1 > 0 && $this->invoice->custom_surcharge_tax1) {
|
||||
$amount += $this->invoice->custom_surcharge1;
|
||||
}
|
||||
|
||||
if(is_numeric($this->invoice->custom_surcharge2) && $this->invoice->custom_surcharge2 > 0 && !$this->invoice->custom_surcharge_tax2) {
|
||||
$amount -= $this->invoice->custom_surcharge2;
|
||||
if(is_numeric($this->invoice->custom_surcharge2) && $this->invoice->custom_surcharge2 > 0 && $this->invoice->custom_surcharge_tax2) {
|
||||
$amount += $this->invoice->custom_surcharge2;
|
||||
}
|
||||
|
||||
if(is_numeric($this->invoice->custom_surcharge3) && $this->invoice->custom_surcharge3 > 0 && !$this->invoice->custom_surcharge_tax3) {
|
||||
$amount -= $this->invoice->custom_surcharge3;
|
||||
if(is_numeric($this->invoice->custom_surcharge3) && $this->invoice->custom_surcharge3 > 0 && $this->invoice->custom_surcharge_tax3) {
|
||||
$amount += $this->invoice->custom_surcharge3;
|
||||
}
|
||||
|
||||
if(is_numeric($this->invoice->custom_surcharge4) && $this->invoice->custom_surcharge4 > 0 && !$this->invoice->custom_surcharge_tax4) {
|
||||
$amount -= $this->invoice->custom_surcharge4;
|
||||
if(is_numeric($this->invoice->custom_surcharge4) && $this->invoice->custom_surcharge4 > 0 && $this->invoice->custom_surcharge_tax4) {
|
||||
$amount += $this->invoice->custom_surcharge4;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (is_string($this->invoice->tax_name1) && strlen($this->invoice->tax_name1) > 1) {
|
||||
$tax = $this->calcInclusiveLineTax($this->invoice->tax_rate1, $amount);
|
||||
$this->total_taxes += $tax;
|
||||
@ -172,8 +172,7 @@ nlog($this->total_taxes);
|
||||
$this->total_taxes += $tax;
|
||||
$this->total_tax_map[] = ['name' => $this->invoice->tax_name3.' '.floatval($this->invoice->tax_rate3).'%', 'total' => $tax];
|
||||
}
|
||||
nlog($this->total_taxes);
|
||||
nlog($this->total_tax_map);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -374,7 +373,7 @@ nlog($this->total_tax_map);
|
||||
|
||||
$this->total_taxes += $total_line_tax;
|
||||
}
|
||||
nlog($this->total_taxes);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -204,7 +204,11 @@ class Invoice extends BaseModel
|
||||
'is_deleted' => 'bool',
|
||||
'is_amount_discount' => 'bool',
|
||||
'tax_data' => 'object',
|
||||
'partial_due_date' => 'date:Y-m-d'
|
||||
'partial_due_date' => 'date:Y-m-d',
|
||||
'custom_surcharge_tax1' => 'bool',
|
||||
'custom_surcharge_tax2' => 'bool',
|
||||
'custom_surcharge_tax3' => 'bool',
|
||||
'custom_surcharge_tax4' => 'bool',
|
||||
];
|
||||
|
||||
protected $with = [];
|
||||
|
@ -109,7 +109,9 @@ class InvoiceInclusiveTest extends TestCase
|
||||
$this->invoice->tax_name1 = 'GST';
|
||||
$this->invoice->tax_rate1 = 10;
|
||||
$this->invoice->is_amount_discount = true;
|
||||
$this->invoice->line_items = $this->buildLineItems();
|
||||
|
||||
nlog("xxx");
|
||||
nlog($this->invoice->withoutRelations()->toArray());
|
||||
|
||||
$calc = $this->invoice->calc();
|
||||
|
Loading…
Reference in New Issue
Block a user