update email template

This commit is contained in:
baodev0
2026-09-09 16:56:22 +07:00
parent d3d9f76ba0
commit 2365ef72e9
210 changed files with 6335 additions and 4688 deletions
@@ -13,8 +13,7 @@ class AdminUserResource extends JsonResource
'id' => $this->id,
'username' => $this->username,
'email' => $this->email,
'firstname' => $this->firstname,
'lastname' => $this->lastname,
'fullname' => $this->fullname,
'phone' => $this->phone,
'department' => $this->department,
'start_date' => $this->start_date?->toDateString(),
+36 -1
View File
@@ -14,6 +14,7 @@ class OrderResource extends JsonResource
'order_num' => $this->order_num,
'customer' => $this->whenLoaded('customer', fn() => [
'id' => $this->customer->id,
'uuid' => $this->customer->uuid,
'fullname' => $this->customer->fullname,
'email' => $this->customer->email,
'phone' => $this->customer->phone ?? null,
@@ -46,10 +47,44 @@ class OrderResource extends JsonResource
'due_date' => $this->invoice->due_date,
'date_paid' => $this->invoice->paid_at,
]),
// An order can have many invoices (1 initial + N renewals) — this is the full list.
'invoices' => $this->whenLoaded('invoices', fn() => $this->invoices->map(fn($invoice) => [
'id' => $invoice->id,
'invoice_number' => $invoice->invoice_number,
'invoice_type' => $invoice->invoice_type,
'sub_total' => $invoice->sub_total,
'discount_amount' => $invoice->discount_amount,
'tax' => $invoice->tax,
'total' => $invoice->total,
'status' => $invoice->status,
'date' => $invoice->created_at,
'due_date' => $invoice->due_date,
'date_paid' => $invoice->paid_at,
'billing_period_start' => $invoice->billing_period_start,
'billing_period_end' => $invoice->billing_period_end,
// Which service(s)/product(s) this invoice actually bills for — without this,
// an invoice was a black box: just a total with no visible line items.
'items' => $invoice->relationLoaded('invoiceItems')
? $invoice->invoiceItems->map(fn($item) => [
'id' => $item->id,
'product_id' => $item->product_id,
'product_name' => $item->product?->name,
'product_type' => $item->product?->product_type,
'type' => $item->type,
'description' => $item->description,
'months' => $item->months,
'quantity' => $item->quantity,
'unit_price' => $item->unit_price,
'total_price' => $item->total_price,
])
: [],
])),
'sub_total' => $this->sub_total,
'discount_amount' => $this->discount_amount,
'total' => $this->total,
'payment_method' => $this->whenLoaded('payment', fn() => $this->payment->name, $this->payment_method),
// Order has no payment_id FK — `payment` relation is always null. Fall back to
// the raw payment_method string instead of letting whenLoaded() mask it with null.
'payment_method' => $this->payment?->name ?? $this->payment_method,
'payment_proof' => $this->payment_proof,
'note' => $this->note,
'client_ip' => $this->client_ip,
@@ -27,6 +27,9 @@ class ProductResource extends JsonResource
'page_type' => $this->resolvePageType($this->product_type),
'product_categories_id' => $this->whenLoaded('category', fn() => $this->category?->id),
'category' => $this->whenLoaded('category', fn() => $this->category?->name),
// Which billing_cycle values this product's category expects (drives cycle
// pickers in the UI) — e.g. domain is annual-only, IT service can be one_time.
'category_billing_cycles' => $this->whenLoaded('category', fn() => $this->category?->billing_cycles),
'service_plan_id' => $this->service_plan_id,
'cpu' => $this->cpu,
'ram' => $this->ram,
@@ -37,18 +40,21 @@ class ProductResource extends JsonResource
'setup_fee' => $this->setup_fee,
'min_price' => $minPrice,
'billing_type' => $this->whenLoaded('pricings', function () {
$hasOnetime = $this->pricings->where('billing_cycle', 'onetime')->isNotEmpty();
$hasRecurring = $this->pricings->where('billing_cycle', '!=', 'onetime')->isNotEmpty();
return ($hasOnetime && !$hasRecurring) ? 'onetime' : 'recurring';
// 'one_time' (with underscore) is the convention used everywhere else in the
// app (OrderHelper::cycleToMonths, ServiceExpiry, renewService, product_pricings
// migration comment) — this used to check 'onetime' and never matched real rows.
$hasOnetime = $this->pricings->where('billing_cycle', 'one_time')->isNotEmpty();
$hasRecurring = $this->pricings->where('billing_cycle', '!=', 'one_time')->isNotEmpty();
return ($hasOnetime && !$hasRecurring) ? 'one_time' : 'recurring';
}),
'currency' => $this->whenLoaded('pricings', fn () => $this->pricings->first()?->currency ?? 'VND'),
'price_monthly' => $this->whenLoaded('pricings', fn () => optional($this->pricings->firstWhere('billing_cycle', 'monthly'))->price),
'price_quarterly' => $this->whenLoaded('pricings', fn () => optional($this->pricings->firstWhere('billing_cycle', 'quarterly'))->price),
'price_semiannually' => $this->whenLoaded('pricings', fn () => optional($this->pricings->firstWhere('billing_cycle', 'semiannually'))->price),
'price_semiannually' => $this->whenLoaded('pricings', fn () => optional($this->pricings->firstWhere('billing_cycle', 'semi_annually'))->price),
'price_annually' => $this->whenLoaded('pricings', fn () => optional($this->pricings->firstWhere('billing_cycle', 'annually'))->price),
'price_biennially' => $this->whenLoaded('pricings', fn () => optional($this->pricings->firstWhere('billing_cycle', 'biennially'))->price),
'price_triennially' => $this->whenLoaded('pricings', fn () => optional($this->pricings->firstWhere('billing_cycle', 'triennially'))->price),
'price_onetime' => $this->whenLoaded('pricings', fn () => optional($this->pricings->firstWhere('billing_cycle', 'onetime'))->price),
'price_onetime' => $this->whenLoaded('pricings', fn () => optional($this->pricings->firstWhere('billing_cycle', 'one_time'))->price),
'is_active' => $this->is_active,
'created_at' => $this->created_at,
'os_ids' => $osIds,