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:
baodev0
2026-10-19 16:37:56 +07:00
co-authored by Claude Sonnet 5.5
parent ea9a53f742
commit 25f23d541e
134 changed files with 4926 additions and 185 deletions
@@ -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;
}
/**