59 lines
2.4 KiB
PHP
59 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources\Api\Service\Order;
|
|
|
|
use App\Enums\Invoice\InvoiceStatus;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class InvoiceDetailResource extends JsonResource
|
|
{
|
|
use ResolvesPaymentMethod;
|
|
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'invoice_number' => $this->invoice_number,
|
|
'invoice_type' => $this->invoice_type,
|
|
'status' => $this->status,
|
|
'status_text' => InvoiceStatus::tryFrom((int) $this->status)?->label() ?? '-',
|
|
'sub_total' => (float) $this->sub_total,
|
|
'discount_amount' => (float) ($this->discount_amount ?? 0),
|
|
'tax' => (float) $this->tax,
|
|
'total' => (float) $this->total,
|
|
'payment_method' => $this->resolvePaymentMethod($this->resource),
|
|
'auto_renew' => (bool) $this->auto_renew,
|
|
'created_at' => $this->created_at?->toISOString(),
|
|
'due_date' => $this->due_date?->toISOString(),
|
|
'paid_at' => $this->paid_at?->toISOString(),
|
|
'customer' => $this->whenLoaded('customer', fn () => [
|
|
'id' => $this->customer->id,
|
|
'name' => $this->customer->fullname,
|
|
'email' => $this->customer->email,
|
|
'address' => $this->customer->address,
|
|
]),
|
|
'order' => $this->whenLoaded('order', fn () => [
|
|
'id' => $this->order->id,
|
|
'order_num' => $this->order->order_num,
|
|
'total' => (float) $this->order->total,
|
|
]),
|
|
'items' => $this->whenLoaded('order', fn () => $this->order->orderItems->map(fn ($item) => [
|
|
'id' => $item->id,
|
|
'product_name' => $item->product?->name,
|
|
'server_name' => $item->server_name,
|
|
'billing_cycle' => $item->billing_cycle,
|
|
'price' => (float) $item->price,
|
|
'months' => $item->months,
|
|
'os_id' => $item->os_id,
|
|
])->values()->all()),
|
|
'attachments' => $this->whenLoaded('attachments', fn () => $this->attachments->map(fn ($a) => [
|
|
'id' => $a->id,
|
|
'filename' => $a->filename,
|
|
'url' => $a->url,
|
|
'mime_type' => $a->mime_type,
|
|
])->all()),
|
|
];
|
|
}
|
|
}
|