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
@@ -3,6 +3,7 @@
namespace App\Http\Resources\Api\Service\Order;
use App\Enums\Invoice\InvoiceStatus;
use App\Enums\Order\OrderStatus;
use App\Models\InvoiceAttachment;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
@@ -20,7 +21,10 @@ class InvoiceDetailResource extends JsonResource
'status_text' => InvoiceStatus::tryFrom((int) $this->status)?->label() ?? '-',
'sub_total' => (float) $this->sub_total,
'discount_amount' => (float) ($this->discount_amount ?? 0),
'coupon_code' => $this->coupon_code,
'tax' => (float) $this->tax,
'lookup_code' => $this->lookup_code,
'vat_number' => $this->vat_number,
'total' => (float) $this->total,
// Công nợ: đã thu / còn thiếu. Dịch vụ chỉ kích hoạt khi outstanding = 0.
'amount_paid' => (float) $this->amount_paid,
@@ -37,7 +41,10 @@ class InvoiceDetailResource extends JsonResource
]),
'order' => $this->whenLoaded('order', fn () => [
'order_num' => $this->order->order_num,
'status' => (int) $this->order->status,
'status_text' => OrderStatus::tryFrom((int) $this->order->status)?->label() ?? '-',
'total' => (float) $this->order->total,
'created_at' => $this->order->created_at?->toISOString(),
]),
'items' => $this->whenLoaded('order', fn () => $this->order->orderItems->map(fn ($item) => [
'product_name' => $item->product?->name,
@@ -47,8 +54,9 @@ class InvoiceDetailResource extends JsonResource
'months' => $item->months,
'os_id' => $item->os_id,
])->values()->all()),
'service' => $this->whenLoaded('order', fn () => $this->resolveService()),
'attachments' => $this->whenLoaded('attachments', fn () => $this->attachments
->where('type', '!=', InvoiceAttachment::TYPE_DEPLOYMENT)
->whereNotIn('type', [InvoiceAttachment::TYPE_DEPLOYMENT, InvoiceAttachment::TYPE_CONTRACT])
->values()
->map(fn ($a) => [
'filename' => $a->filename,
@@ -62,6 +70,24 @@ class InvoiceDetailResource extends JsonResource
];
}
private function resolveService(): ?array
{
$items = $this->order->orderItems;
$item = $this->service_id
? $items->first(fn ($i) => (int) $i->service?->id === (int) $this->service_id)
: null;
$item ??= $items->first();
return $item ? [
'product_id' => $item->product_id,
'name' => $item->product?->name,
'billing_cycle' => $item->billing_cycle,
'months' => $item->months,
'server_name' => $item->server_name,
'product_type' => $item->product?->product_type,
] : null;
}
private function resolveVmware(\App\Models\ModuleVmware $vm): array
{
return [