diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 97e7666..8b6b610 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Support\Str; class Invoice extends Model @@ -72,6 +73,11 @@ class Invoice extends Model return $this->hasMany(InvoiceLine::class); } + public function payments(): HasMany + { + return $this->hasMany(Payment::class); + } + public function recalculateTotal(): void { $this->attributes['total'] = $this->lines()->sum('amount'); diff --git a/resources/views/components/⚡edit-payment.blade.php b/resources/views/components/⚡edit-payment.blade.php new file mode 100644 index 0000000..621d860 --- /dev/null +++ b/resources/views/components/⚡edit-payment.blade.php @@ -0,0 +1,151 @@ +with('client')->get()->sortBy('client.abbreviation'); + } + + public function loadContacts(): void + { + if (!$this->invoice_id) { + $this->contacts = []; + return; + } + $invoice = Invoice::find($this->invoice_id); + $this->contacts = $invoice?->client?->contacts ?? collect(); + } + + public function updatedInvoiceId(): void + { + $this->loadContacts(); + $this->contact_id = null; + } + + #[On('edit-payment')] + public function loadPayment(int $paymentId): void + { + $this->payment = Payment::findOrFail($paymentId); + + $this->invoice_id = $this->payment->invoice_id; + $this->loadContacts(); + $this->contact_id = $this->payment->contact_id; + $this->payment_date = $this->payment->payment_date->format('Y-m-d'); + $this->status = $this->payment->status; + $this->payment_method = $this->payment->payment_method; + $this->reference = $this->payment->reference; + $this->amount = $this->payment->amount; + $this->notes = $this->payment->notes; + + Flux::modal('edit-payment')->show(); + } + + public function save(): void + { + $this->validate(); + + $this->payment->update([ + 'invoice_id' => $this->invoice_id, + 'contact_id' => $this->contact_id, + 'payment_date' => $this->payment_date, + 'status' => $this->status, + 'payment_method' => $this->payment_method, + 'reference' => $this->reference, + 'amount' => $this->amount, + 'notes' => $this->notes, + ]); + + Flux::modal('edit-payment')->close(); + $this->dispatch('payment-updated'); + } +}; +?> + +
+ +
+ Edit Payment + + + + + + @foreach ($this->invoices as $invoice) + + @endforeach + + + + + @foreach($contacts as $contact) + {{ $contact->full_name }} + @endforeach + + + + @foreach(PaymentStatus::cases() as $s) + {{ $s->label() }} + @endforeach + + + + @foreach(PaymentMethod::cases() as $method) + {{ $method->label() }} + @endforeach + + + + + + + + +
+ Update Payment + Cancel +
+ +
+
\ No newline at end of file diff --git a/resources/views/components/⚡payment-list.blade.php b/resources/views/components/⚡payment-list.blade.php index 7ba1e26..51185aa 100644 --- a/resources/views/components/⚡payment-list.blade.php +++ b/resources/views/components/⚡payment-list.blade.php @@ -19,6 +19,11 @@ new class extends Component { { } + public function deletePayment(Payment $payment): void + { + $payment->delete(); + } + }; ?> @@ -34,6 +39,7 @@ new class extends Component { Payment Method
Reference
Fee Amount Amount Paid + @@ -46,6 +52,24 @@ new class extends Component { {{ $payment->payment_method->label() }}
{{ $payment->reference }}
{{ formatMoney($payment->fee_amount) }} {{ formatMoney($payment->amount) }} + + + + + + Edit + + Delete + + + + @endforeach
diff --git a/resources/views/payments/index.blade.php b/resources/views/payments/index.blade.php index 9153be7..37f1440 100644 --- a/resources/views/payments/index.blade.php +++ b/resources/views/payments/index.blade.php @@ -4,5 +4,6 @@ +