mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge pull request #6179 from beganovich/v5-0106-credits-show-where-due-date
(Client portal) Show only credits with `due_date` <= now()
This commit is contained in:
commit
c972d8696d
@ -26,7 +26,7 @@ class CreditsTable extends Component
|
|||||||
public $per_page = 10;
|
public $per_page = 10;
|
||||||
|
|
||||||
public $company;
|
public $company;
|
||||||
|
|
||||||
public function mount()
|
public function mount()
|
||||||
{
|
{
|
||||||
MultiDB::setDb($this->company->db);
|
MultiDB::setDb($this->company->db);
|
||||||
@ -37,6 +37,7 @@ class CreditsTable extends Component
|
|||||||
$query = Credit::query()
|
$query = Credit::query()
|
||||||
->where('client_id', auth('contact')->user()->client->id)
|
->where('client_id', auth('contact')->user()->client->id)
|
||||||
->where('status_id', '<>', Credit::STATUS_DRAFT)
|
->where('status_id', '<>', Credit::STATUS_DRAFT)
|
||||||
|
->whereDate('due_date', '<=', now())
|
||||||
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc')
|
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc')
|
||||||
->paginate($this->per_page);
|
->paginate($this->per_page);
|
||||||
|
|
||||||
|
91
tests/ClientPortal/CreditsTest.php
Normal file
91
tests/ClientPortal/CreditsTest.php
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
<?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://www.elastic.co/licensing/elastic-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Tests\ClientPortal;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Http\Livewire\CreditsTable;
|
||||||
|
use App\Models\Account;
|
||||||
|
use App\Models\Client;
|
||||||
|
use App\Models\ClientContact;
|
||||||
|
use App\Models\Company;
|
||||||
|
use App\Models\Credit;
|
||||||
|
use App\Models\User;
|
||||||
|
use Faker\Factory;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class CreditsTest extends TestCase
|
||||||
|
{
|
||||||
|
use DatabaseTransactions;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->faker = Factory::create();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testShowingOnlyQuotesWithDueDateLessOrEqualToNow()
|
||||||
|
{
|
||||||
|
$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]);
|
||||||
|
|
||||||
|
ClientContact::factory()->count(2)->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'client_id' => $client->id,
|
||||||
|
'company_id' => $company->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
Credit::factory()->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'company_id' => $company->id,
|
||||||
|
'client_id' => $client->id,
|
||||||
|
'number' => 'testing-number-01',
|
||||||
|
'due_date' => now()->subDays(5),
|
||||||
|
'status_id' => Credit::STATUS_SENT,
|
||||||
|
]);
|
||||||
|
|
||||||
|
Credit::factory()->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'company_id' => $company->id,
|
||||||
|
'client_id' => $client->id,
|
||||||
|
'number' => 'testing-number-02',
|
||||||
|
'due_date' => now(),
|
||||||
|
'status_id' => Credit::STATUS_SENT,
|
||||||
|
]);
|
||||||
|
|
||||||
|
Credit::factory()->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'company_id' => $company->id,
|
||||||
|
'client_id' => $client->id,
|
||||||
|
'number' => 'testing-number-03',
|
||||||
|
'due_date' => now()->addDays(5),
|
||||||
|
'status_id' => Credit::STATUS_SENT,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->actingAs($client->contacts->first(), 'contact');
|
||||||
|
|
||||||
|
Livewire::test(CreditsTable::class, ['company' => $company])
|
||||||
|
->assertSee('testing-number-01')
|
||||||
|
->assertSee('testing-number-02')
|
||||||
|
->assertDontSee('testing-number-03');
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user