mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-22 11:50:55 -04:00
Performance improvements removing unpaid gateway fees
This commit is contained in:
parent
84feb72e9e
commit
e22967f10d
@ -52,6 +52,7 @@ class Handler extends ExceptionHandler
|
|||||||
MaxAttemptsExceededException::class,
|
MaxAttemptsExceededException::class,
|
||||||
CommandNotFoundException::class,
|
CommandNotFoundException::class,
|
||||||
ValidationException::class,
|
ValidationException::class,
|
||||||
|
ModelNotFoundException::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -339,6 +339,10 @@ class InvoiceService
|
|||||||
|
|
||||||
public function removeUnpaidGatewayFees()
|
public function removeUnpaidGatewayFees()
|
||||||
{
|
{
|
||||||
|
//return early if type three does not exist.
|
||||||
|
if(!collect($this->invoice->line_items)->contains('type_id', 3))
|
||||||
|
return $this;
|
||||||
|
|
||||||
$this->invoice->line_items = collect($this->invoice->line_items)
|
$this->invoice->line_items = collect($this->invoice->line_items)
|
||||||
->reject(function ($item) {
|
->reject(function ($item) {
|
||||||
return $item->type_id == '3';
|
return $item->type_id == '3';
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
*/
|
*/
|
||||||
namespace Tests\Unit;
|
namespace Tests\Unit;
|
||||||
|
|
||||||
|
use App\Factory\InvoiceItemFactory;
|
||||||
use App\Utils\Traits\UserSessionAttributes;
|
use App\Utils\Traits\UserSessionAttributes;
|
||||||
use Illuminate\Support\Facades\Session;
|
use Illuminate\Support\Facades\Session;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
@ -19,13 +20,10 @@ use Tests\TestCase;
|
|||||||
*/
|
*/
|
||||||
class CollectionMergingTest extends TestCase
|
class CollectionMergingTest extends TestCase
|
||||||
{
|
{
|
||||||
use UserSessionAttributes;
|
|
||||||
|
|
||||||
public function setUp() :void
|
public function setUp() :void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
Session::start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUniqueValues()
|
public function testUniqueValues()
|
||||||
@ -62,4 +60,21 @@ class CollectionMergingTest extends TestCase
|
|||||||
$intersect = $collection->intersectByKeys($collection->flatten(1)->unique());
|
$intersect = $collection->intersectByKeys($collection->flatten(1)->unique());
|
||||||
$this->assertEquals(11, $intersect->count());
|
$this->assertEquals(11, $intersect->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testExistenceInCollection()
|
||||||
|
{
|
||||||
|
|
||||||
|
$items = InvoiceItemFactory::generate(5);
|
||||||
|
|
||||||
|
$this->assertFalse(collect($items)->contains('type_id', "3"));
|
||||||
|
$this->assertFalse(collect($items)->contains('type_id', 3));
|
||||||
|
|
||||||
|
$item = InvoiceItemFactory::create();
|
||||||
|
$item->type_id = "3";
|
||||||
|
$items[] = $item;
|
||||||
|
|
||||||
|
$this->assertTrue(collect($items)->contains('type_id', "3"));
|
||||||
|
$this->assertTrue(collect($items)->contains('type_id', 3));
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user