Deal with non-completed payments correctly.
This commit is contained in:
parent
43d4869532
commit
2deaa14dcf
|
|
@ -4,6 +4,7 @@ namespace App\Models;
|
||||||
|
|
||||||
use App\Casts\MoneyCast;
|
use App\Casts\MoneyCast;
|
||||||
use App\Enums\InvoiceStatus;
|
use App\Enums\InvoiceStatus;
|
||||||
|
use App\Enums\PaymentStatus;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
@ -89,7 +90,7 @@ class Invoice extends Model
|
||||||
|
|
||||||
public function recalculateTotalPayments(): void
|
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->saveQuietly();
|
||||||
|
|
||||||
$this->refresh();
|
$this->refresh();
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,12 @@
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
@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)
|
||||||
<div class="mb-8">
|
<div class="mb-8">
|
||||||
<h2 class="text-sm font-semibold text-gray-500 uppercase mb-4">Payments Received</h2>
|
<h2 class="text-sm font-semibold text-gray-500 uppercase mb-4">Payments Received</h2>
|
||||||
<table class="w-full">
|
<table class="w-full">
|
||||||
|
|
@ -80,7 +85,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach($invoice->payments as $payment)
|
@foreach($completedPayments as $payment)
|
||||||
<tr class="border-b border-gray-200">
|
<tr class="border-b border-gray-200">
|
||||||
<td class="py-2 text-gray-600">{{ $payment->payment_date->format('F j, Y') }}</td>
|
<td class="py-2 text-gray-600">{{ $payment->payment_date->format('F j, Y') }}</td>
|
||||||
<td class="py-2 text-gray-600">{{ $payment->payment_method->label() }}</td>
|
<td class="py-2 text-gray-600">{{ $payment->payment_method->label() }}</td>
|
||||||
|
|
@ -103,6 +108,34 @@
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
@if($pendingPayments->count() > 0)
|
||||||
|
<div class="mb-8">
|
||||||
|
<h2 class="text-sm font-semibold text-gray-500 uppercase mb-4">Pending Payments</h2>
|
||||||
|
<table class="w-full">
|
||||||
|
<thead>
|
||||||
|
<tr class="border-b border-gray-300">
|
||||||
|
<th class="text-left py-2 text-sm font-semibold text-gray-600">Date</th>
|
||||||
|
<th class="text-left py-2 text-sm font-semibold text-gray-600">Method</th>
|
||||||
|
<th class="text-left py-2 text-sm font-semibold text-gray-600">Reference</th>
|
||||||
|
<th class="text-left py-2 text-sm font-semibold text-gray-600">Status</th>
|
||||||
|
<th class="text-right py-2 text-sm font-semibold text-gray-600">Amount</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach($pendingPayments as $payment)
|
||||||
|
<tr class="border-b border-gray-200">
|
||||||
|
<td class="py-2 text-gray-600">{{ $payment->payment_date->format('F j, Y') }}</td>
|
||||||
|
<td class="py-2 text-gray-600">{{ $payment->payment_method->label() }}</td>
|
||||||
|
<td class="py-2 text-gray-600">{{ $payment->reference }}</td>
|
||||||
|
<td class="py-2 text-gray-600">{{ $payment->status->label() }}</td>
|
||||||
|
<td class="py-2 text-right text-gray-800">{{ formatMoney($payment->amount) }}</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
@if($invoice->balance_due != 0)
|
@if($invoice->balance_due != 0)
|
||||||
<div class="mb-12 p-4 bg-gray-50 rounded">
|
<div class="mb-12 p-4 bg-gray-50 rounded">
|
||||||
<h2 class="text-sm font-semibold text-gray-500 uppercase mb-2">Payment</h2>
|
<h2 class="text-sm font-semibold text-gray-500 uppercase mb-2">Payment</h2>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue