mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Add exclusive taxes to line items
This commit is contained in:
parent
d6e8c66f1c
commit
33c05b1ad0
@ -43,6 +43,8 @@ class InvoiceItem
|
||||
|
||||
public $line_total = 0;
|
||||
|
||||
public $gross_line_total = 0;
|
||||
|
||||
public $date = '';
|
||||
|
||||
public $custom_value1 = '';
|
||||
@ -72,6 +74,7 @@ class InvoiceItem
|
||||
'tax_rate3' => 'float',
|
||||
'sort_id' => 'string',
|
||||
'line_total' => 'float',
|
||||
'gross_line_total' => 'float',
|
||||
'date' => 'string',
|
||||
'custom_value1' => 'string',
|
||||
'custom_value2' => 'string',
|
||||
|
@ -28,6 +28,8 @@ class InvoiceItemSum
|
||||
|
||||
private $line_total;
|
||||
|
||||
private $gross_line_total;
|
||||
|
||||
private $currency;
|
||||
|
||||
private $total_taxes;
|
||||
@ -38,6 +40,8 @@ class InvoiceItemSum
|
||||
|
||||
private $sub_total;
|
||||
|
||||
private $gross_sub_total;
|
||||
|
||||
private $total_discount;
|
||||
|
||||
private $tax_collection;
|
||||
@ -83,6 +87,8 @@ class InvoiceItemSum
|
||||
{
|
||||
$this->sub_total += $this->getLineTotal();
|
||||
|
||||
$this->gross_sub_total += $this->getGrossLineTotal();
|
||||
|
||||
$this->line_items[] = $this->item;
|
||||
|
||||
return $this;
|
||||
@ -148,6 +154,8 @@ class InvoiceItemSum
|
||||
|
||||
$this->setTotalTaxes($this->formatValue($item_tax, $this->currency->precision));
|
||||
|
||||
$this->item->gross_line_total = $this->getLineTotal() + $item_tax;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -186,6 +194,11 @@ class InvoiceItemSum
|
||||
return $this->item->line_total;
|
||||
}
|
||||
|
||||
public function getGrossLineTotal()
|
||||
{
|
||||
return $this->item->gross_line_total;
|
||||
}
|
||||
|
||||
public function getLineItems()
|
||||
{
|
||||
return $this->line_items;
|
||||
@ -208,6 +221,11 @@ class InvoiceItemSum
|
||||
return $this->sub_total;
|
||||
}
|
||||
|
||||
public function getGrossSubTotal()
|
||||
{
|
||||
return $this->gross_line_total;
|
||||
}
|
||||
|
||||
public function setSubTotal($value)
|
||||
{
|
||||
$this->sub_total = $value;
|
||||
|
@ -42,6 +42,8 @@ class InvoiceSum
|
||||
|
||||
private $sub_total;
|
||||
|
||||
private $gross_sub_total;
|
||||
|
||||
/**
|
||||
* Constructs the object with Invoice and Settings object.
|
||||
*
|
||||
@ -75,7 +77,8 @@ class InvoiceSum
|
||||
$this->invoice->line_items = $this->invoice_items->getLineItems();
|
||||
$this->total = $this->invoice_items->getSubTotal();
|
||||
$this->setSubTotal($this->invoice_items->getSubTotal());
|
||||
|
||||
$this->setGrossSubTotal($this->invoice_items->getGrossSubTotal());
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -266,6 +269,18 @@ class InvoiceSum
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getGrossSubTotal()
|
||||
{
|
||||
return $this->gross_sub_total;
|
||||
}
|
||||
|
||||
public function setGrossSubTotal($value)
|
||||
{
|
||||
$this->gross_sub_total = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTotalDiscount()
|
||||
{
|
||||
return $this->total_discount;
|
||||
|
@ -175,6 +175,7 @@ class HtmlEngine
|
||||
$data['$invoice.discount'] = ['value' => Number::formatMoney($this->entity_calc->getTotalDiscount(), $this->client) ?: ' ', 'label' => ctrans('texts.discount')];
|
||||
$data['$discount'] = &$data['$invoice.discount'];
|
||||
$data['$subtotal'] = ['value' => Number::formatMoney($this->entity_calc->getSubTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.subtotal')];
|
||||
$data['$gross_subtotal'] = ['value' => Number::formatMoney($this->entity_calc->getGrossSubTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.subtotal')];
|
||||
|
||||
if($this->entity->uses_inclusive_taxes)
|
||||
$data['$net_subtotal'] = ['value' => Number::formatMoney(($this->entity_calc->getSubTotal() - $this->entity->total_taxes), $this->client) ?: ' ', 'label' => ctrans('texts.net_subtotal')];
|
||||
|
@ -51,6 +51,29 @@ class InvoiceItemTest extends TestCase
|
||||
$this->assertEquals($item_calc->getLineTotal(), 10);
|
||||
}
|
||||
|
||||
public function testInvoiceItemTotalSimpleWithGrossTaxes()
|
||||
{
|
||||
$item = InvoiceItemFactory::create();
|
||||
$item->quantity = 1;
|
||||
$item->cost = 10;
|
||||
$item->is_amount_discount = true;
|
||||
$item->tax_rate1 = 10;
|
||||
|
||||
$settings = new \stdClass;
|
||||
$settings->inclusive_taxes = false;
|
||||
$settings->precision = 2;
|
||||
|
||||
$this->invoice->line_items = [$item];
|
||||
|
||||
$item_calc = new InvoiceItemSum($this->invoice, $settings);
|
||||
$item_calc->process();
|
||||
|
||||
$this->assertEquals($item_calc->getLineTotal(), 10);
|
||||
$this->assertEquals($item_calc->getGrossLineTotal(), 11);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testInvoiceItemTotalSimpleWithDiscount()
|
||||
{
|
||||
$item = InvoiceItemFactory::create();
|
||||
@ -71,6 +94,29 @@ class InvoiceItemTest extends TestCase
|
||||
$this->assertEquals($item_calc->getLineTotal(), 8);
|
||||
}
|
||||
|
||||
public function testInvoiceItemTotalSimpleWithDiscountAndGrossLineTotal()
|
||||
{
|
||||
$item = InvoiceItemFactory::create();
|
||||
$item->quantity = 1;
|
||||
$item->cost = 10;
|
||||
$item->is_amount_discount = true;
|
||||
$item->discount = 2;
|
||||
$item->tax_rate1 = 10;
|
||||
|
||||
$this->invoice->line_items = [$item];
|
||||
|
||||
$settings = new \stdClass;
|
||||
$settings->inclusive_taxes = false;
|
||||
$settings->precision = 2;
|
||||
|
||||
$item_calc = new InvoiceItemSum($this->invoice, $settings);
|
||||
$item_calc->process();
|
||||
|
||||
$this->assertEquals($item_calc->getLineTotal(), 8);
|
||||
$this->assertEquals($item_calc->getGrossLineTotal(), 8.8);
|
||||
|
||||
}
|
||||
|
||||
public function testInvoiceItemTotalSimpleWithDiscountWithPrecision()
|
||||
{
|
||||
$item = InvoiceItemFactory::create();
|
||||
|
Loading…
Reference in New Issue
Block a user