$this->id, 'order_num' => $this->order_num, 'customer' => $this->whenLoaded('customer', fn() => [ 'id' => $this->customer->id, 'fullname' => $this->customer->fullname, 'email' => $this->customer->email, 'phone' => $this->customer->phone ?? null, ]), 'user' => $this->whenLoaded('user', fn() => [ 'id' => $this->user->id, 'firstname' => $this->user->firstname, 'lastname' => $this->user->lastname, 'email' => $this->user->email, ]), 'payment' => $this->whenLoaded('payment', fn() => [ 'id' => $this->payment->id, 'name' => $this->payment->name, 'type' => $this->payment->type, ]), 'discount' => $this->whenLoaded('discount', fn() => [ 'id' => $this->discount->id, 'code' => $this->discount->code, 'value' => $this->discount->value, ]), 'invoice' => $this->whenLoaded('invoice', fn() => [ 'id' => $this->invoice->id, 'invoice_number' => $this->invoice->invoice_number, 'sub_total' => $this->invoice->sub_total, 'discount_amount' => $this->invoice->discount_amount, 'tax' => $this->invoice->tax, 'total' => $this->invoice->total, 'status' => $this->invoice->status, 'date' => $this->invoice->created_at, 'due_date' => $this->invoice->due_date, 'date_paid' => $this->invoice->paid_at, ]), '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), 'payment_proof' => $this->payment_proof, 'note' => $this->note, 'client_ip' => $this->client_ip, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'vmwares' => $this->whenLoaded('moduleVmwares', fn() => $this->moduleVmwares->map(fn($vm) => [ 'id' => $vm->id, 'vmware_id' => $vm->vmware_id, 'name' => $vm->name, 'hostname' => $vm->hostname, 'user' => $vm->user, 'ip' => $vm->ipAddress?->ip, 'os_id' => $vm->os_id, 'status' => $vm->status, 'next_due_date' => $vm->next_due_date, ])), 'order_items' => $this->whenLoaded('orderItems', fn() => $this->orderItems->map(function ($item) { return [ 'id' => $item->id, 'product' => $item->product ? [ 'id' => $item->product->id, 'name' => $item->product->name, 'product_type' => $item->product->product_type, ] : null, 'os' => $item->os ? [ 'id' => $item->os->id, 'name' => $item->os->name, 'version' => $item->os->version, ] : null, 'billing_cycle' => $item->billing_cycle, 'months' => $item->months, 'expiry_date' => $item->expiry_date, 'quantity' => $item->quantity, 'server_name' => $item->server_name, 'price' => $item->price, 'service' => $item->service ? [ 'id' => $item->service->id, 'vm_id' => $item->service->vm_id, 'status' => $item->service->status, 'started_at' => $item->service->started_at, 'expires_at' => $item->service->expires_at, ] : null, ]; })), ]; } }