mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 15:04:37 -04:00
Fixes baseline errors in tests
This commit is contained in:
parent
616dc23c63
commit
82c1df5c6d
@ -5,6 +5,7 @@ namespace App\Helpers\Invoice;
|
|||||||
use App\Helpers\Invoice\InvoiceItemCalc;
|
use App\Helpers\Invoice\InvoiceItemCalc;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Utils\Traits\NumberFormatter;
|
use App\Utils\Traits\NumberFormatter;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for invoice calculations.
|
* Class for invoice calculations.
|
||||||
@ -43,10 +44,11 @@ class InvoiceCalc
|
|||||||
* @param \App\Models\Invoice $invoice The invoice
|
* @param \App\Models\Invoice $invoice The invoice
|
||||||
* @param \stdClass $settings The settings
|
* @param \stdClass $settings The settings
|
||||||
*/
|
*/
|
||||||
public function __construct(Invoice $invoice, \stdClass $settings)
|
public function __construct($invoice, \stdClass $settings)
|
||||||
{
|
{
|
||||||
$this->invoice = $invoice;
|
$this->invoice = $invoice;
|
||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
|
$this->tax_map = new Collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,7 +67,7 @@ class InvoiceCalc
|
|||||||
|
|
||||||
private function calcPartial()
|
private function calcPartial()
|
||||||
{
|
{
|
||||||
if ( !$this->invoice->id && isset($this->invoice->partial) ) {
|
if ( !isset($this->invoice->id) && isset($this->invoice->partial) ) {
|
||||||
$this->invoice->partial = max(0, min($this->formatValue($this->invoice->partial, 2), $this->invoice->balance));
|
$this->invoice->partial = max(0, min($this->formatValue($this->invoice->partial, 2), $this->invoice->balance));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,21 +119,23 @@ class InvoiceCalc
|
|||||||
|
|
||||||
// custom fields charged taxes
|
// custom fields charged taxes
|
||||||
if ($this->invoice->custom_value1 && $this->settings->custom_taxes1) {
|
if ($this->invoice->custom_value1 && $this->settings->custom_taxes1) {
|
||||||
$this->total += $invoice->custom_value1;
|
$this->total += $this->invoice->custom_value1;
|
||||||
}
|
}
|
||||||
if ($invoice->custom_value2 && $invoice->custom_taxes2) {
|
if ($this->invoice->custom_value2 && $this->invoice->custom_taxes2) {
|
||||||
$this->total += $invoice->custom_value2;
|
$this->total += $this->invoice->custom_value2;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->calcTaxes();
|
$this->calcTaxes();
|
||||||
|
|
||||||
// custom fields not charged taxes
|
// custom fields not charged taxes
|
||||||
if ($invoice->custom_value1 && ! $this->settings->custom_taxes1) {
|
if ($this->invoice->custom_value1 && ! $this->settings->custom_taxes1) {
|
||||||
$this->total += $invoice->custom_value1;
|
$this->total += $this->invoice->custom_value1;
|
||||||
}
|
}
|
||||||
if ($invoice->custom_value2 && ! $this->settings->custom_taxes2) {
|
if ($this->invoice->custom_value2 && ! $this->settings->custom_taxes2) {
|
||||||
$this->total += $invoice->custom_value2;
|
$this->total += $this->invoice->custom_value2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -147,6 +151,7 @@ class InvoiceCalc
|
|||||||
$this->total += $this->total_taxes;
|
$this->total += $this->total_taxes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -161,7 +166,7 @@ class InvoiceCalc
|
|||||||
|
|
||||||
foreach($this->invoice->line_items as $item) {
|
foreach($this->invoice->line_items as $item) {
|
||||||
|
|
||||||
$item_calc = new InvoiceItemCalc($item);
|
$item_calc = new InvoiceItemCalc($item, $this->settings);
|
||||||
$item_calc->process();
|
$item_calc->process();
|
||||||
|
|
||||||
|
|
||||||
@ -197,9 +202,9 @@ class InvoiceCalc
|
|||||||
*
|
*
|
||||||
* @return float The sub total.
|
* @return float The sub total.
|
||||||
*/
|
*/
|
||||||
private function getSubTotal()
|
public function getSubTotal()
|
||||||
{
|
{
|
||||||
return $this->subtotal;
|
return $this->sub_total;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -209,7 +214,7 @@ class InvoiceCalc
|
|||||||
*
|
*
|
||||||
* @return self $this
|
* @return self $this
|
||||||
*/
|
*/
|
||||||
private function setSubTotal($value)
|
public function setSubTotal($value)
|
||||||
{
|
{
|
||||||
$this->sub_total = $value;
|
$this->sub_total = $value;
|
||||||
|
|
||||||
@ -221,7 +226,7 @@ class InvoiceCalc
|
|||||||
*
|
*
|
||||||
* @return Collection The tax map.
|
* @return Collection The tax map.
|
||||||
*/
|
*/
|
||||||
private function getTaxMap()
|
public function getTaxMap()
|
||||||
{
|
{
|
||||||
return $this->tax_map;
|
return $this->tax_map;
|
||||||
}
|
}
|
||||||
@ -233,7 +238,7 @@ class InvoiceCalc
|
|||||||
*
|
*
|
||||||
* @return self $this
|
* @return self $this
|
||||||
*/
|
*/
|
||||||
private function setTaxMap($value)
|
public function setTaxMap($value)
|
||||||
{
|
{
|
||||||
$htis->tax_map = $value;
|
$htis->tax_map = $value;
|
||||||
|
|
||||||
@ -245,7 +250,7 @@ class InvoiceCalc
|
|||||||
*
|
*
|
||||||
* @return float The total discount.
|
* @return float The total discount.
|
||||||
*/
|
*/
|
||||||
private function getTotalDiscount()
|
public function getTotalDiscount()
|
||||||
{
|
{
|
||||||
return $this->total_discount;
|
return $this->total_discount;
|
||||||
}
|
}
|
||||||
@ -257,7 +262,7 @@ class InvoiceCalc
|
|||||||
*
|
*
|
||||||
* @return self $this
|
* @return self $this
|
||||||
*/
|
*/
|
||||||
private function setTotalDiscount($value)
|
public function setTotalDiscount($value)
|
||||||
{
|
{
|
||||||
$this->total_discount = $value;
|
$this->total_discount = $value;
|
||||||
|
|
||||||
@ -269,7 +274,7 @@ class InvoiceCalc
|
|||||||
*
|
*
|
||||||
* @return float The total taxes.
|
* @return float The total taxes.
|
||||||
*/
|
*/
|
||||||
private function getTotalTaxes()
|
public function getTotalTaxes()
|
||||||
{
|
{
|
||||||
return $this->total_taxes;
|
return $this->total_taxes;
|
||||||
}
|
}
|
||||||
@ -281,7 +286,7 @@ class InvoiceCalc
|
|||||||
*
|
*
|
||||||
* @return self ( $this )
|
* @return self ( $this )
|
||||||
*/
|
*/
|
||||||
private function setTotalTaxes($value)
|
public function setTotalTaxes($value)
|
||||||
{
|
{
|
||||||
$this->total_taxes = $value;
|
$this->total_taxes = $value;
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ namespace App\Helpers\Invoice;
|
|||||||
|
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Utils\Traits\NumberFormatter;
|
use App\Utils\Traits\NumberFormatter;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
class InvoiceItemCalc
|
class InvoiceItemCalc
|
||||||
{
|
{
|
||||||
@ -29,7 +30,7 @@ class InvoiceItemCalc
|
|||||||
|
|
||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
|
|
||||||
$this->tax_collection = collect();
|
$this->tax_collection = new Collection;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +123,7 @@ class InvoiceItemCalc
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function getLimeItem()
|
public function getLineItem()
|
||||||
{
|
{
|
||||||
|
|
||||||
return $this->item;
|
return $this->item;
|
||||||
@ -155,12 +156,12 @@ class InvoiceItemCalc
|
|||||||
|
|
||||||
public function getTotalDiscounts()
|
public function getTotalDiscounts()
|
||||||
{
|
{
|
||||||
return $this->total_dicounts;
|
return $this->total_discounts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTotalDiscounts($total)
|
public function setTotalDiscounts($total)
|
||||||
{
|
{
|
||||||
$this->total_dicounts = $total;
|
$this->total_discounts = $total;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ namespace Tests\Unit;
|
|||||||
|
|
||||||
use App\Factory\InvoiceFactory;
|
use App\Factory\InvoiceFactory;
|
||||||
use App\Factory\InvoiceItemFactory;
|
use App\Factory\InvoiceItemFactory;
|
||||||
|
use App\Helpers\Invoice\InvoiceCalc;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,6 +40,7 @@ class InvoiceTest extends TestCase
|
|||||||
$settings->custom_taxes1 = true;
|
$settings->custom_taxes1 = true;
|
||||||
$settings->custom_taxes2 = true;
|
$settings->custom_taxes2 = true;
|
||||||
$settings->inclusive_taxes = true;
|
$settings->inclusive_taxes = true;
|
||||||
|
$settings->precision = 2;
|
||||||
|
|
||||||
return $settings;
|
return $settings;
|
||||||
}
|
}
|
||||||
@ -62,4 +64,11 @@ class InvoiceTest extends TestCase
|
|||||||
return $line_items;
|
return $line_items;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testInvoiceTotals()
|
||||||
|
{
|
||||||
|
$this->invoice_calc->build();
|
||||||
|
|
||||||
|
$this->assertEquals($this->invoice_calc->getSubTotal(), 20);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user