diff --git a/app/Http/Livewire/CreditsTable.php b/app/Http/Livewire/CreditsTable.php index 9e254b9c0e50..97ac843fa8f4 100644 --- a/app/Http/Livewire/CreditsTable.php +++ b/app/Http/Livewire/CreditsTable.php @@ -26,7 +26,7 @@ class CreditsTable extends Component public $per_page = 10; public $company; - + public function mount() { MultiDB::setDb($this->company->db); @@ -37,6 +37,7 @@ class CreditsTable extends Component $query = Credit::query() ->where('client_id', auth('contact')->user()->client->id) ->where('status_id', '<>', Credit::STATUS_DRAFT) + ->whereDate('due_date', '<=', now()) ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc') ->paginate($this->per_page); diff --git a/tests/ClientPortal/CreditsTest.php b/tests/ClientPortal/CreditsTest.php new file mode 100644 index 000000000000..16ab0923a8b2 --- /dev/null +++ b/tests/ClientPortal/CreditsTest.php @@ -0,0 +1,91 @@ +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'); + } +}