feat(billing): renewals, coupons, VAT numbering, billing cycles and invoice payment tracking
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
ea9a53f742
commit
25f23d541e
@@ -54,6 +54,13 @@ class CustomerBillingService
|
||||
unset($data['date_paid']);
|
||||
}
|
||||
|
||||
if (array_key_exists('amount_paid', $data) && $data['amount_paid'] === null) {
|
||||
unset($data['amount_paid']);
|
||||
}
|
||||
if (isset($data['amount_paid']) && $data['amount_paid'] > (int) ($data['total'] ?? $invoice->total)) {
|
||||
abort(422, 'Số tiền đã thu không được lớn hơn tổng hóa đơn');
|
||||
}
|
||||
|
||||
// Đi qua repository (không gọi $invoice->update() trực tiếp) để cache
|
||||
// của invoiceRepository->filter() (dùng ở getInvoices) được xoá theo,
|
||||
// nếu không danh sách hóa đơn sẽ hiển thị dữ liệu cũ cho tới khi cache hết hạn.
|
||||
@@ -128,13 +135,17 @@ class CustomerBillingService
|
||||
{
|
||||
$customer = $this->resolveCustomer($uuid);
|
||||
|
||||
return $this->orderRepository->filter(['client' => $customer->id], [
|
||||
$orders = $this->orderRepository->filter(['client' => $customer->id], [
|
||||
'customer',
|
||||
'user:id,username',
|
||||
'payment',
|
||||
'invoices',
|
||||
...OrderItemServiceResource::relationsFor('orderItems'),
|
||||
]);
|
||||
|
||||
$orders->each(fn ($order) => $order->invoices->each(fn ($invoice) => $invoice->date_paid = $invoice->paid_at));
|
||||
|
||||
return $orders;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user