mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 06:04:34 -04:00
Tests for credit balances
This commit is contained in:
parent
55159b32a5
commit
84dd24c070
@ -51,6 +51,7 @@ class ClientService
|
|||||||
$credits = $this->client->credits
|
$credits = $this->client->credits
|
||||||
->where('is_deleted', false)
|
->where('is_deleted', false)
|
||||||
->where('balance', '>', 0)
|
->where('balance', '>', 0)
|
||||||
|
->where('due_date', '<=', now())
|
||||||
->sortBy('created_at');
|
->sortBy('created_at');
|
||||||
|
|
||||||
return Number::roundValue($credits->sum('balance'), $this->client->currency()->precision);
|
return Number::roundValue($credits->sum('balance'), $this->client->currency()->precision);
|
||||||
|
79
tests/Unit/CreditBalanceTest.php
Normal file
79
tests/Unit/CreditBalanceTest.php
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
namespace Tests\Unit;
|
||||||
|
|
||||||
|
use App\Models\Account;
|
||||||
|
use App\Models\Client;
|
||||||
|
use App\Models\Company;
|
||||||
|
use App\Models\Credit;
|
||||||
|
use App\Models\User;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
class CreditBalanceTest extends TestCase
|
||||||
|
{
|
||||||
|
public function setUp() :void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->faker = \Faker\Factory::create();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreditBalance()
|
||||||
|
{
|
||||||
|
|
||||||
|
$account = Account::factory()->create();
|
||||||
|
$user = User::factory()->create(
|
||||||
|
['account_id' => $account->id, 'email' => $this->faker->safeEmail]
|
||||||
|
);
|
||||||
|
|
||||||
|
$company = Company::factory()->create(['account_id' => $account->id]);
|
||||||
|
$client = Client::factory()->create(['company_id' => $company->id, 'user_id' => $user->id]);
|
||||||
|
|
||||||
|
$credit = Credit::factory()->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'company_id' => $company->id,
|
||||||
|
'client_id' => $client->id,
|
||||||
|
'balance' => 10,
|
||||||
|
'number' => 'testing-number-01',
|
||||||
|
'status_id' => Credit::STATUS_SENT,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals($client->service()->getCreditBalance(), 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testExpiredCreditBalance()
|
||||||
|
{
|
||||||
|
|
||||||
|
$account = Account::factory()->create();
|
||||||
|
$user = User::factory()->create(
|
||||||
|
['account_id' => $account->id, 'email' => $this->faker->safeEmail]
|
||||||
|
);
|
||||||
|
|
||||||
|
$company = Company::factory()->create(['account_id' => $account->id]);
|
||||||
|
$client = Client::factory()->create(['company_id' => $company->id, 'user_id' => $user->id]);
|
||||||
|
|
||||||
|
$credit = Credit::factory()->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'company_id' => $company->id,
|
||||||
|
'client_id' => $client->id,
|
||||||
|
'balance' => 10,
|
||||||
|
'due_date' => now()->addDays(5),
|
||||||
|
'number' => 'testing-number-02',
|
||||||
|
'status_id' => Credit::STATUS_SENT,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals($client->service()->getCreditBalance(), 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user