feat: Enhance ServiceClientResource and InvoiceRepository with additional data fields; remove unused SVG icons
This commit is contained in:
@@ -18,13 +18,26 @@ class ServiceClientResource extends JsonResource
|
||||
return [];
|
||||
}
|
||||
|
||||
$orderItem = $this->orderItem;
|
||||
$product = $orderItem?->product;
|
||||
|
||||
return [
|
||||
'uuid' => $this->uuid,
|
||||
'uuid' => $this->uuid,
|
||||
'server_name' => $this->server_name,
|
||||
'status' => $this->status,
|
||||
'auto_renew' => $this->auto_renew,
|
||||
'started_at' => $this->started_at?->toISOString(),
|
||||
'expires_at' => $this->expires_at?->toISOString(),
|
||||
'status' => $this->status,
|
||||
'auto_renew' => $this->auto_renew,
|
||||
'started_at' => $this->started_at?->toISOString(),
|
||||
'expires_at' => $this->expires_at?->toISOString(),
|
||||
'os' => [
|
||||
'version' => $orderItem?->os?->version,
|
||||
'group' => $orderItem?->os?->osGroup?->name,
|
||||
],
|
||||
'specs' => $product ? [
|
||||
'cpu' => (int) ($product->cpu ?? 0),
|
||||
'ram' => (int) ($product->ram ?? 0),
|
||||
'disk' => (int) ($product->disk ?? 0),
|
||||
'bandwidth' => (int) ($product->bandwidth ?? 0),
|
||||
] : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,8 @@ class InvoiceRepository extends BaseApiRepository implements InvoiceRepositoryIn
|
||||
|
||||
public function createFromOrder(Order $order): Invoice
|
||||
{
|
||||
$maxMonths = $order->orderItems->max(fn($item) => $this->cycleToMonths($item->billing_cycle)) ?? 1;
|
||||
|
||||
$invoice = $this->model->create([
|
||||
'invoice_number' => OrderHelper::generateOrderNumber('INV'),
|
||||
'customer_id' => $order->customer_id,
|
||||
@@ -45,7 +47,7 @@ class InvoiceRepository extends BaseApiRepository implements InvoiceRepositoryIn
|
||||
'tax' => 0,
|
||||
'total' => $order->total,
|
||||
'status' => InvoiceStatus::UNPAID->value,
|
||||
'due_date' => now()->addDays(3)->toDateString(),
|
||||
'due_date' => now()->addMonths($maxMonths)->toDateString(),
|
||||
]);
|
||||
|
||||
// Create one invoice_item per order_item line
|
||||
|
||||
@@ -18,7 +18,7 @@ class ServiceClientRepository extends BaseApiRepository implements ServiceClient
|
||||
public function getActiveServices(int $limit = 10)
|
||||
{
|
||||
return $this->model
|
||||
->with(['orderItem' => fn($q) => $q->with('product')])
|
||||
->with(['orderItem' => fn($q) => $q->with(['product', 'os.osGroup'])])
|
||||
->orderByRaw("FIELD(status, 'active', 'pending', 'suspended', 'expired', 'cancelled', 'terminated')")
|
||||
->orderBy('started_at', 'desc')
|
||||
->paginate($limit);
|
||||
|
||||
Reference in New Issue
Block a user