feat(payments): add customer ledgers and allocations (#744)

This commit is contained in:
Darko Gjorgjijoski
2026-08-05 03:28:35 +02:00
committed by GitHub
parent 8ae82ae91e
commit f322c2b74d
74 changed files with 5693 additions and 693 deletions
+18
View File
@@ -120,6 +120,24 @@ class InvoiceResource extends JsonResource
return (object) $quantities;
}
),
// Allocation rows explain how this invoice was settled without
// reintroducing the removed singular payment.invoice relation.
// They are loaded for the detail response only, so index listings
// remain free of per-row payment queries.
'payment_allocations' => $this->when(
$this->relationLoaded('allocations'),
fn () => $this->allocations->map(fn ($allocation) => [
'id' => $allocation->id,
'payment_id' => $allocation->payment_id,
'amount' => $allocation->amount,
'base_amount' => $allocation->base_amount,
'payment' => $allocation->relationLoaded('payment') && $allocation->payment ? [
'id' => $allocation->payment->id,
'payment_number' => $allocation->payment->payment_number,
'formatted_payment_date' => $allocation->payment->formattedPaymentDate,
] : null,
])->values()
),
'items' => $this->when($this->items()->exists(), function () {
return InvoiceItemResource::collection($this->items);
}),