-
Notifications
You must be signed in to change notification settings - Fork 11
[IP-32]: implement payments options on invoice list #684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nielsdrost7
wants to merge
8
commits into
InvoicePlane:develop
Choose a base branch
from
underdogg-forks:feature/32-invoice-list-enter-payment
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a08b773
improved .gitignore
nielsdrost7 9ad1b60
style: fix Pint violations across factories, observers, and tests
nielsdrost7 00b3ada
improved .gitignore
nielsdrost7 b17fabb
quick improvements on composer.json and CLAUDE file
nielsdrost7 d449ff2
improve .gitignore
nielsdrost7 1170e42
fix: order Recent*Widget queries by id, not latest() on missing creat…
nielsdrost7 7de31de
chore: eliminate the SQLite testing fallback, run against real MariaDB
nielsdrost7 80e7422
feat(#32): enter a payment directly from the invoice list
nielsdrost7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
Modules/Invoices/Tests/Feature/EnterPaymentActionTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| <?php | ||
|
|
||
| namespace Modules\Invoices\Tests\Feature; | ||
|
|
||
| use Filament\Actions\Testing\TestAction; | ||
| use Livewire\Livewire; | ||
| use Modules\Core\Enums\Permission; | ||
| use Modules\Core\Tests\AbstractCompanyPanelTestCase; | ||
| use Modules\Core\Tests\Concerns\InteractsWithPermissions; | ||
| use Modules\Invoices\Enums\InvoiceStatus; | ||
| use Modules\Invoices\Filament\Company\Resources\Invoices\Pages\ListInvoices; | ||
| use Modules\Invoices\Models\Invoice; | ||
| use Modules\Payments\Enums\PaymentMethod; | ||
| use Modules\Payments\Enums\PaymentStatus; | ||
| use PHPUnit\Framework\Attributes\CoversClass; | ||
| use PHPUnit\Framework\Attributes\Test; | ||
|
|
||
| /** | ||
| * #32 - "Enter Payment" inline action on the invoice list: opens a modal | ||
| * pre-filled with the invoice's outstanding balance, creates a Payment on | ||
| * submit, and reconciles the invoice's status against what's been paid. | ||
| */ | ||
| #[CoversClass(ListInvoices::class)] | ||
| class EnterPaymentActionTest extends AbstractCompanyPanelTestCase | ||
| { | ||
| use InteractsWithPermissions; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
|
|
||
| $this->grantPermission(Permission::CREATE_PAYMENTS); | ||
| } | ||
|
|
||
| #[Test] | ||
| public function it_opens_the_enter_payment_modal_with_the_outstanding_balance_prefilled(): void | ||
| { | ||
| /* Arrange */ | ||
| $invoice = Invoice::factory()->for($this->company)->create([ | ||
| 'invoice_total' => 200.00, | ||
| 'invoice_status' => InvoiceStatus::SENT->value, | ||
| ]); | ||
|
|
||
| /* Act */ | ||
| $component = Livewire::actingAs($this->user) | ||
| ->test(ListInvoices::class) | ||
| ->mountAction(TestAction::make('enter_payment')->table($invoice)); | ||
|
|
||
| /* Assert */ | ||
| $component->assertSuccessful(); | ||
| $component->assertActionDataSet([ | ||
| 'payment_amount' => 200.00, | ||
| ]); | ||
| } | ||
|
|
||
| #[Test] | ||
| public function it_creates_a_payment_and_marks_the_invoice_paid_when_fully_settled(): void | ||
| { | ||
| /* Arrange */ | ||
| $invoice = Invoice::factory()->for($this->company)->create([ | ||
| 'invoice_total' => 150.00, | ||
| 'invoice_status' => InvoiceStatus::SENT->value, | ||
| ]); | ||
|
|
||
| /* Act */ | ||
| $component = Livewire::actingAs($this->user) | ||
| ->test(ListInvoices::class) | ||
| ->mountAction(TestAction::make('enter_payment')->table($invoice)) | ||
| ->setActionData([ | ||
| 'paid_at' => now()->toDateString(), | ||
| 'payment_method' => PaymentMethod::BANK_TRANSFER->value, | ||
| 'payment_status' => PaymentStatus::COMPLETED->value, | ||
| 'payment_amount' => 150.00, | ||
| ]) | ||
| ->callMountedAction(); | ||
|
|
||
| /* Assert */ | ||
| $component->assertSuccessful(); | ||
| $this->assertDatabaseHas('payments', [ | ||
| 'invoice_id' => $invoice->id, | ||
| 'payment_amount' => 150.00, | ||
| ]); | ||
| $this->assertDatabaseHas('invoices', [ | ||
| 'id' => $invoice->id, | ||
| 'invoice_status' => InvoiceStatus::PAID->value, | ||
| ]); | ||
| } | ||
|
|
||
| #[Test] | ||
| public function it_marks_the_invoice_partially_paid_when_the_payment_does_not_cover_the_full_balance(): void | ||
| { | ||
| /* Arrange */ | ||
| $invoice = Invoice::factory()->for($this->company)->create([ | ||
| 'invoice_total' => 200.00, | ||
| 'invoice_status' => InvoiceStatus::SENT->value, | ||
| ]); | ||
|
|
||
| /* Act */ | ||
| Livewire::actingAs($this->user) | ||
| ->test(ListInvoices::class) | ||
| ->mountAction(TestAction::make('enter_payment')->table($invoice)) | ||
| ->setActionData([ | ||
| 'paid_at' => now()->toDateString(), | ||
| 'payment_method' => PaymentMethod::BANK_TRANSFER->value, | ||
| 'payment_status' => PaymentStatus::COMPLETED->value, | ||
| 'payment_amount' => 50.00, | ||
| ]) | ||
| ->callMountedAction() | ||
| ->assertSuccessful(); | ||
|
|
||
| /* Assert */ | ||
| $this->assertDatabaseHas('invoices', [ | ||
| 'id' => $invoice->id, | ||
| 'invoice_status' => InvoiceStatus::PARTIALLY_PAID->value, | ||
| ]); | ||
| } | ||
|
|
||
| #[Test] | ||
| public function it_hides_the_enter_payment_action_once_the_invoice_is_fully_paid(): void | ||
| { | ||
| /* Arrange */ | ||
| $invoice = Invoice::factory()->for($this->company)->create([ | ||
| 'invoice_total' => 100.00, | ||
| 'invoice_status' => InvoiceStatus::PAID->value, | ||
| ]); | ||
|
|
||
| /* Act & Assert */ | ||
| Livewire::actingAs($this->user) | ||
| ->test(ListInvoices::class) | ||
| ->assertActionHidden(TestAction::make('enter_payment')->table($invoice)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win
Prevent N+1 queries in the outstanding balance accessor.
Using the
payments()query builder relationship method executes a new database query every time this accessor is accessed. If thepaymentsrelationship has been eager-loaded, you can prevent N+1 query issues by filtering the loaded collection directly instead of hitting the database again.⚡ Proposed optimization
public function getOutstandingBalanceAttribute(): float { - $paid = $this->payments() - ->where('payment_status', \Modules\Payments\Enums\PaymentStatus::COMPLETED->value) - ->sum('payment_amount'); + $paid = $this->relationLoaded('payments') + ? $this->payments->where('payment_status', \Modules\Payments\Enums\PaymentStatus::COMPLETED->value)->sum('payment_amount') + : $this->payments() + ->where('payment_status', \Modules\Payments\Enums\PaymentStatus::COMPLETED->value) + ->sum('payment_amount'); return max(0, (float) $this->invoice_total - (float) $paid); }📝 Committable suggestion
🤖 Prompt for AI Agents