update logic
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?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
|
||||
{
|
||||
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->payment_method,
|
||||
'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()),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Api\Service\Order;
|
||||
|
||||
use App\Enums\Invoice\InvoiceStatus;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class InvoiceSummaryResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'invoice_number' => $this->invoice_number,
|
||||
'service_name' => $this->order?->orderItems->first()?->product?->name ?? ('Đơn hàng ' . $this->order?->order_num),
|
||||
'total' => (float) $this->total,
|
||||
'status' => $this->status,
|
||||
'status_text' => InvoiceStatus::tryFrom((int) $this->status)?->label() ?? '-',
|
||||
'created_at' => $this->created_at?->toISOString(),
|
||||
'order_id' => $this->order?->id,
|
||||
'order_num' => $this->order?->order_num,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Api\Service\Order;
|
||||
|
||||
use App\Enums\Invoice\InvoiceStatus;
|
||||
use App\Enums\Order\OrderStatus;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class OrderDetailResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'order_num' => $this->order_num,
|
||||
'status' => $this->status,
|
||||
'status_text' => OrderStatus::from((int) $this->status)->label(),
|
||||
'total' => (float) $this->total,
|
||||
'created_at' => $this->created_at?->toISOString(),
|
||||
'customer' => $this->whenLoaded('customer', fn () => [
|
||||
'id' => $this->customer->id,
|
||||
'name' => $this->customer->fullname,
|
||||
'email' => $this->customer->email,
|
||||
]),
|
||||
'invoice' => $this->whenLoaded('invoice', fn () => [
|
||||
'id' => $this->invoice->id,
|
||||
'invoice_number' => $this->invoice->invoice_number,
|
||||
'status' => $this->invoice->status,
|
||||
'status_text' => InvoiceStatus::tryFrom((int) $this->invoice->status)?->label() ?? '-',
|
||||
'sub_total' => (float) $this->invoice->sub_total,
|
||||
'tax' => (float) $this->invoice->tax,
|
||||
'total' => (float) $this->invoice->total,
|
||||
'due_date' => $this->invoice->due_date?->toISOString(),
|
||||
'paid_at' => $this->invoice->paid_at?->toISOString(),
|
||||
]),
|
||||
'items' => $this->whenLoaded('orderItems') ? OrderItemResource::collection($this->orderItems) : [],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Api\Service\Order;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class OrderItemResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'billing_cycle' => $this->billing_cycle,
|
||||
'months' => $this->months,
|
||||
'server_name' => $this->server_name,
|
||||
'os_id' => $this->os_id,
|
||||
'price' => (float) $this->price,
|
||||
'service' => $this->whenLoaded('service', fn () => [
|
||||
'id' => $this->service->id,
|
||||
'status' => $this->service->status,
|
||||
'status_text' => $this->service->status_label,
|
||||
'retry_requested_at' => $this->service->retry_requested_at?->toISOString(),
|
||||
'can_retry_provisioning' => $this->service->status === 'pending' && ! $this->service->retry_requested_at,
|
||||
]),
|
||||
'product' => $this->whenLoaded('product', fn () => [
|
||||
'id' => $this->product->id,
|
||||
'uuid' => $this->product->uuid,
|
||||
'name' => $this->product->name,
|
||||
'product_type' => $this->product->product_type,
|
||||
'specs' => [
|
||||
'cpu' => $this->product->cpu,
|
||||
'ram' => $this->product->ram,
|
||||
'disk' => $this->product->disk,
|
||||
'bandwidth' => $this->product->bandwidth,
|
||||
],
|
||||
]),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Api\Service\Order;
|
||||
|
||||
use App\Enums\Invoice\InvoiceStatus;
|
||||
use App\Enums\Order\OrderStatus;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class OrderSummaryResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'order_num' => $this->order_num,
|
||||
'status' => $this->status,
|
||||
'status_text' => OrderStatus::from((int) $this->status)->label(),
|
||||
'total' => (float) $this->total,
|
||||
'created_at' => $this->created_at?->toISOString(),
|
||||
'invoice' => $this->whenLoaded('invoice', fn () => [
|
||||
'id' => $this->invoice->id,
|
||||
'invoice_number' => $this->invoice->invoice_number,
|
||||
'status' => $this->invoice->status,
|
||||
'status_text' => InvoiceStatus::tryFrom((int) $this->invoice->status)?->label() ?? '-',
|
||||
'total' => (float) $this->invoice->total,
|
||||
]),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Api\Service\Order;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ServiceDetailResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'uuid' => $this->uuid,
|
||||
'service_name' => $this->product?->name ?? $this->server_name,
|
||||
'server_name' => $this->server_name,
|
||||
'product_type' => $this->product?->product_type,
|
||||
'billing_cycle' => $this->orderItem?->billing_cycle,
|
||||
'status' => $this->status,
|
||||
'status_text' => $this->status_label,
|
||||
'auto_renew' => (bool) $this->auto_renew,
|
||||
'started_at' => $this->started_at?->toISOString(),
|
||||
'expires_at' => $this->expires_at?->toISOString(),
|
||||
'note' => $this->note,
|
||||
'invoice_id' => $this->invoice_id,
|
||||
'invoice_number' => $this->invoice?->invoice_number,
|
||||
'product' => $this->whenLoaded('product', fn () => [
|
||||
'id' => $this->product->id,
|
||||
'uuid' => $this->product->uuid,
|
||||
'name' => $this->product->name,
|
||||
'product_type' => $this->product->product_type,
|
||||
'specs' => [
|
||||
'cpu' => $this->product->cpu,
|
||||
'ram' => $this->product->ram,
|
||||
'disk' => $this->product->disk,
|
||||
'bandwidth' => $this->product->bandwidth,
|
||||
],
|
||||
]),
|
||||
'addons' => $this->whenLoaded('addons', fn () => $this->addons->map(fn ($a) => [
|
||||
'type' => $a->addon_type,
|
||||
'value' => $a->addon_value,
|
||||
'price' => $a->price,
|
||||
])->all()),
|
||||
'vmware' => $this->whenLoaded('vmware', fn () => $this->vmware ? [
|
||||
'id' => $this->vmware->id,
|
||||
'name' => $this->vmware->name,
|
||||
'hostname' => $this->vmware->hostname,
|
||||
'ip_address' => $this->vmware->ipAddress?->ip,
|
||||
'os_name' => $this->vmware->os?->name,
|
||||
'status' => $this->vmware->status,
|
||||
'next_due_date' => $this->vmware->next_due_date?->toISOString(),
|
||||
] : null),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Api\Service\Order;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ServiceSummaryResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'uuid' => $this->uuid,
|
||||
'service_name' => $this->product?->name ?? $this->server_name,
|
||||
'server_name' => $this->server_name,
|
||||
'product_type' => $this->product?->product_type,
|
||||
'billing_cycle' => $this->orderItem?->billing_cycle,
|
||||
'status' => $this->status,
|
||||
'status_text' => $this->status_label,
|
||||
'auto_renew' => (bool) $this->auto_renew,
|
||||
'started_at' => $this->started_at?->toISOString(),
|
||||
'expires_at' => $this->expires_at?->toISOString(),
|
||||
'invoice_id' => $this->invoice_id,
|
||||
'invoice_number' => $this->invoice?->invoice_number,
|
||||
'addons' => $this->whenLoaded('addons', fn () => $this->addons->map(fn ($a) => [
|
||||
'type' => $a->addon_type,
|
||||
'value' => $a->addon_value,
|
||||
'price' => $a->price,
|
||||
])->all()),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user