mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Fixes for surcharge tax calculations
This commit is contained in:
parent
93de61d75d
commit
fe7356cc89
@ -1 +1 @@
|
||||
5.8.51
|
||||
5.8.52
|
@ -35,7 +35,7 @@ trait CustomValuer
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function multiInclusiveTax($value, $has_custom_invoice_taxes) {
|
||||
public function multiInclusiveTax($custom_value, $has_custom_invoice_taxes) {
|
||||
|
||||
if (isset($custom_value) && is_numeric($custom_value) && $has_custom_invoice_taxes !== false) {
|
||||
|
||||
|
@ -74,8 +74,8 @@ class InvoiceSumInclusive
|
||||
{
|
||||
$this->calculateLineItems()
|
||||
->calculateDiscount()
|
||||
->calculateCustomValues()
|
||||
->calculateInvoiceTaxes()
|
||||
->calculateCustomValues()
|
||||
->setTaxMap()
|
||||
->calculateTotals() //just don't add the taxes!!
|
||||
->calculateBalance()
|
||||
@ -119,7 +119,6 @@ class InvoiceSumInclusive
|
||||
$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;
|
||||
|
||||
return $this;
|
||||
@ -138,21 +137,21 @@ class InvoiceSumInclusive
|
||||
}
|
||||
|
||||
//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);
|
||||
|
@ -17,8 +17,8 @@ return [
|
||||
'require_https' => env('REQUIRE_HTTPS', true),
|
||||
'app_url' => rtrim(env('APP_URL', ''), '/'),
|
||||
'app_domain' => env('APP_DOMAIN', 'invoicing.co'),
|
||||
'app_version' => env('APP_VERSION', '5.8.51'),
|
||||
'app_tag' => env('APP_TAG', '5.8.51'),
|
||||
'app_version' => env('APP_VERSION', '5.8.52'),
|
||||
'app_tag' => env('APP_TAG', '5.8.52'),
|
||||
'minimum_client_version' => '5.0.16',
|
||||
'terms_version' => '1.0.1',
|
||||
'api_secret' => env('API_SECRET', false),
|
||||
|
@ -210,6 +210,127 @@ class InvoiceTest extends TestCase
|
||||
$this->assertNull($invoice->partial_due_date);
|
||||
}
|
||||
|
||||
public function testSurchargesAndTaxes()
|
||||
{
|
||||
|
||||
$invoice = InvoiceFactory::create($this->company->id, $this->user->id);
|
||||
$invoice->client_id = $this->client->id;
|
||||
$invoice->uses_inclusive_taxes = true;
|
||||
$invoice->discount = 0;
|
||||
$invoice->is_amount_discount = true;
|
||||
$invoice->status_id = 2;
|
||||
$invoice->tax_name1 = 'GST';
|
||||
$invoice->tax_rate1 = 10;
|
||||
$invoice->custom_surcharge1 = 100;
|
||||
$invoice->custom_surcharge_tax1 = true;
|
||||
|
||||
$line_items = [];
|
||||
|
||||
$line_item = new InvoiceItem();
|
||||
$line_item->quantity = 1;
|
||||
$line_item->cost = 100;
|
||||
$line_item->tax_rate1 = 0;
|
||||
$line_item->tax_name1 = '';
|
||||
$line_item->product_key = 'line1';
|
||||
$line_item->notes = 'Test';
|
||||
$line_item->tax_id = 1;
|
||||
$line_items[] = $line_item;
|
||||
|
||||
$invoice->line_items = $line_items;
|
||||
$invoice->save();
|
||||
|
||||
$calc = $invoice->calc();
|
||||
$invoice = $calc->getInvoice();
|
||||
|
||||
$this->assertEquals(200, $invoice->amount);
|
||||
$this->assertEquals(200, $invoice->balance);
|
||||
$this->assertEquals(0,$invoice->paid_to_date);
|
||||
$this->assertEquals(18.18, $calc->getTotalTaxes());
|
||||
|
||||
}
|
||||
|
||||
public function testSurchargesAndTaxes2()
|
||||
{
|
||||
|
||||
$invoice = InvoiceFactory::create($this->company->id, $this->user->id);
|
||||
$invoice->client_id = $this->client->id;
|
||||
$invoice->uses_inclusive_taxes = true;
|
||||
$invoice->discount = 0;
|
||||
$invoice->is_amount_discount = true;
|
||||
$invoice->status_id = 2;
|
||||
$invoice->tax_name1 = '';
|
||||
$invoice->tax_rate1 = 0;
|
||||
$invoice->custom_surcharge1 = 100;
|
||||
$invoice->custom_surcharge_tax1 = true;
|
||||
|
||||
$line_items = [];
|
||||
|
||||
$line_item = new InvoiceItem();
|
||||
$line_item->quantity = 1;
|
||||
$line_item->cost = 100;
|
||||
$line_item->tax_rate1 = 0;
|
||||
$line_item->tax_name1 = '';
|
||||
$line_item->product_key = 'line1';
|
||||
$line_item->notes = 'Test';
|
||||
$line_item->tax_id = 1;
|
||||
$line_item->tax_name1 = 'GST';
|
||||
$line_item->tax_rate1 = 10;
|
||||
$line_items[] = $line_item;
|
||||
|
||||
$invoice->line_items = $line_items;
|
||||
$invoice->save();
|
||||
|
||||
$calc = $invoice->calc();
|
||||
$invoice = $calc->getInvoice();
|
||||
|
||||
$this->assertEquals(200, $invoice->amount);
|
||||
$this->assertEquals(200, $invoice->balance);
|
||||
$this->assertEquals(0,$invoice->paid_to_date);
|
||||
$this->assertEquals(9.09, $calc->getTotalTaxes());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testSurchargesAndTaxesExclusive()
|
||||
{
|
||||
|
||||
$invoice = InvoiceFactory::create($this->company->id, $this->user->id);
|
||||
$invoice->client_id = $this->client->id;
|
||||
$invoice->uses_inclusive_taxes = false;
|
||||
$invoice->discount = 0;
|
||||
$invoice->is_amount_discount = true;
|
||||
$invoice->status_id = 2;
|
||||
$invoice->tax_name1 = 'GST';
|
||||
$invoice->tax_rate1 = 10;
|
||||
$invoice->custom_surcharge1 = 10;
|
||||
$invoice->custom_surcharge_tax1 = true;
|
||||
|
||||
$line_items = [];
|
||||
|
||||
$line_item = new InvoiceItem();
|
||||
$line_item->quantity = 1;
|
||||
$line_item->cost = 10;
|
||||
$line_item->tax_rate1 = 0;
|
||||
$line_item->tax_name1 = '';
|
||||
$line_item->product_key = 'line1';
|
||||
$line_item->notes = 'Test';
|
||||
$line_item->tax_id = 1;
|
||||
$line_items[] = $line_item;
|
||||
|
||||
$invoice->line_items = $line_items;
|
||||
$invoice->save();
|
||||
|
||||
$calc = $invoice->calc();
|
||||
$invoice = $calc->getInvoice();
|
||||
|
||||
$this->assertEquals(22, $invoice->amount);
|
||||
$this->assertEquals(22, $invoice->balance);
|
||||
$this->assertEquals(0,$invoice->paid_to_date);
|
||||
$this->assertEquals(2, $calc->getTotalTaxes());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testGrossTaxAmountCalcuations()
|
||||
{
|
||||
$invoice = InvoiceFactory::create($this->company->id, $this->user->id);
|
||||
|
Loading…
Reference in New Issue
Block a user