diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php
index c0801b7..6417fae 100644
--- a/app/Models/Invoice.php
+++ b/app/Models/Invoice.php
@@ -4,6 +4,7 @@ namespace App\Models;
use App\Casts\MoneyCast;
use App\Enums\InvoiceStatus;
+use App\Enums\PaymentStatus;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@@ -89,7 +90,7 @@ class Invoice extends Model
public function recalculateTotalPayments(): void
{
- $this->attributes['total_payments'] = $this->payments()->sum('amount');
+ $this->attributes['total_payments'] = $this->payments()->where('status', PaymentStatus::COMPLETED)->sum('amount');
$this->saveQuietly();
$this->refresh();
diff --git a/resources/views/invoices/show.blade.php b/resources/views/invoices/show.blade.php
index 648a3bb..ccb6fbb 100644
--- a/resources/views/invoices/show.blade.php
+++ b/resources/views/invoices/show.blade.php
@@ -67,7 +67,12 @@
- @if($invoice->payments->count() > 0)
+ @php
+ $completedPayments = $invoice->payments->where('status', \App\Enums\PaymentStatus::COMPLETED);
+ $pendingPayments = $invoice->payments->where('status', '!=', \App\Enums\PaymentStatus::COMPLETED);
+ @endphp
+
+ @if($completedPayments->count() > 0)
Payments Received
@@ -80,7 +85,7 @@
- @foreach($invoice->payments as $payment)
+ @foreach($completedPayments as $payment)
| {{ $payment->payment_date->format('F j, Y') }} |
{{ $payment->payment_method->label() }} |
@@ -103,6 +108,34 @@
@endif
+ @if($pendingPayments->count() > 0)
+
+
Pending Payments
+
+
+
+ | Date |
+ Method |
+ Reference |
+ Status |
+ Amount |
+
+
+
+ @foreach($pendingPayments as $payment)
+
+ | {{ $payment->payment_date->format('F j, Y') }} |
+ {{ $payment->payment_method->label() }} |
+ {{ $payment->reference }} |
+ {{ $payment->status->label() }} |
+ {{ formatMoney($payment->amount) }} |
+
+ @endforeach
+
+
+
+ @endif
+
@if($invoice->balance_due != 0)
Payment