mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 14:54:34 -04:00
Mock tests for invoice calculations
This commit is contained in:
parent
1ce11fcb36
commit
f7c31bd5a1
27
app/Factory/InvoiceFactory.php
Normal file
27
app/Factory/InvoiceFactory.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Factory;
|
||||||
|
|
||||||
|
class InvoiceFactory
|
||||||
|
{
|
||||||
|
public static function create() :\stdClass
|
||||||
|
{
|
||||||
|
$item = new \stdClass;
|
||||||
|
$item->qty = 0;
|
||||||
|
$item->cost = 0;
|
||||||
|
$item->product_key = '';
|
||||||
|
$item->notes = '';
|
||||||
|
$item->discount = 0;
|
||||||
|
$item->is_amount_discount = true;
|
||||||
|
$item->tax_name1 = '';
|
||||||
|
$item->tax_rate1 = 0;
|
||||||
|
$item->tax_name2 = '';
|
||||||
|
$item->tax_rate2 = 0;
|
||||||
|
$item->sort_id = 0;
|
||||||
|
$item->line_total = 0;
|
||||||
|
$item->invoice_item_type_id = 0;
|
||||||
|
|
||||||
|
return $item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -56,12 +56,20 @@ class InvoiceCalc
|
|||||||
{
|
{
|
||||||
$this->calcLineItems()
|
$this->calcLineItems()
|
||||||
->calcDiscount()
|
->calcDiscount()
|
||||||
->sumCustomValues()
|
->calcCustomValues()
|
||||||
->calcBalance();
|
->calcBalance()
|
||||||
|
->calcPartial();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function calcPartial()
|
||||||
|
{
|
||||||
|
if ( !$this->invoice->id && isset($this->invoice->partial) ) {
|
||||||
|
$this->invoice->partial = max(0, min($this->formatValue($this->invoice->partial, 2), $this->invoice->balance));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function calcDiscount()
|
private function calcDiscount()
|
||||||
{
|
{
|
||||||
if ($this->invoice->discount != 0) {
|
if ($this->invoice->discount != 0) {
|
||||||
@ -81,7 +89,15 @@ class InvoiceCalc
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function sumBalance()
|
|
||||||
|
/**
|
||||||
|
* Calculates the balance.
|
||||||
|
*
|
||||||
|
* //todo need to understand this better
|
||||||
|
*
|
||||||
|
* @return self The balance.
|
||||||
|
*/
|
||||||
|
private function calcBalance()
|
||||||
{
|
{
|
||||||
|
|
||||||
if(isset($this->invoice->id) && $this->invoice->id >= 1)
|
if(isset($this->invoice->id) && $this->invoice->id >= 1)
|
||||||
@ -95,7 +111,7 @@ class InvoiceCalc
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function sumCustomValues()
|
private function calcCustomValues()
|
||||||
{
|
{
|
||||||
$this->total += $this->getSubTotal();
|
$this->total += $this->getSubTotal();
|
||||||
|
|
||||||
|
@ -369,7 +369,6 @@ class CreateUsersTable extends Migration
|
|||||||
$t->string('custom_value3')->nullable();
|
$t->string('custom_value3')->nullable();
|
||||||
$t->string('custom_value4')->nullable();
|
$t->string('custom_value4')->nullable();
|
||||||
|
|
||||||
$t->decimal('total', 13,2);
|
|
||||||
$t->decimal('amount', 13, 2);
|
$t->decimal('amount', 13, 2);
|
||||||
$t->decimal('balance', 13, 2);
|
$t->decimal('balance', 13, 2);
|
||||||
$t->decimal('partial', 13, 2)->nullable();
|
$t->decimal('partial', 13, 2)->nullable();
|
||||||
|
21
tests/Unit/InvoiceTest.php
Normal file
21
tests/Unit/InvoiceTest.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit;
|
||||||
|
|
||||||
|
use App\Factory\InvoiceItemFactory;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @covers App\Helpers\Invoice\InvoiceCalc
|
||||||
|
*/
|
||||||
|
class InvoiceTest extends TestCase
|
||||||
|
{
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user