Files
portal-api/app/Models/ModuleVmware.php
T
baodev0 7314313198 Refactor order payment process and enhance invoice details
- Updated `payOrder` method in `OrderControllerRefactor` to accept `orderNum` instead of `id` for better clarity and functionality.
- Implemented `findByOrderNum` method in `OrderRepository` to retrieve orders based on order number and customer ID.
- Enhanced `InvoiceDetailResource` to include VMware details and removed unnecessary fields.
- Added `service_plan_id` to `ProductResource` and updated the `Product` model to establish a relationship with `ServicePlan`.
- Created `ServicePlan` and `ServicePlanPlesk` models along with their respective controllers and migrations for managing hosting service plans.
- Updated API routes to include endpoints for managing service plans.
- Modified email templates to standardize support phone number across various customer communications.
2026-08-11 10:12:25 +07:00

98 lines
2.5 KiB
PHP

<?php
namespace App\Models;
use App\Traits\LogsActivity;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class ModuleVmware extends Model
{
use HasFactory, LogsActivity;
protected $table = 'module_vmware';
protected $fillable = [
'name',
'module_ip_address',
'port',
'order_id',
'first_payment',
'next_payment',
'next_due_date',
'next_invoice',
'user',
'password',
'hostname',
'vmware_id',
'vcenter_id',
'os_id',
'customer_id',
'status',
'service_id',
'ip',
'dns',
'plain_password',
'virtual_machine_id',
'cpu',
'ram_mb',
'disk_gb',
];
// NOTE: password must NOT use 'hashed' cast — it is a VM guest credential
// used in plaintext by PowerShell scripts (Invoke-VMScript) via SSH/PowerCLI.
// plain_password uses Laravel's 'encrypted' cast (APP_KEY, AES-256-CBC): stored
// encrypted at rest, transparently decrypted on read — no code elsewhere changes.
protected $casts = [
'plain_password' => 'encrypted',
];
public function customer()
{
return $this->belongsTo(\App\Models\Customer::class);
}
public function ipAddress()
{
return $this->belongsTo(\App\Models\ModuleIpAddress::class, 'module_ip_address', 'id');
}
public function vCenter()
{
return $this->belongsTo(\App\Models\vCenter::class, 'vcenter_id', 'id');
}
public function os()
{
return $this->belongsTo(\App\Models\Os::class);
}
public function osGroup()
{
return $this->belongsTo(\App\Models\OsGroup::class);
}
public function order()
{
return $this->belongsTo(\App\Models\Order::class);
}
public function virtualMachine()
{
return $this->hasOne(\App\Models\VirtualMachines::class, 'vm_id', 'vmware_id');
}
public function services()
{
return $this->hasMany(\App\Models\Service::class, 'vm_id', 'vmware_id');
}
/** Direct link via service_id FK (new). */
public function service()
{
return $this->belongsTo(\App\Models\Service::class, 'service_id');
}
public function getStatus()
{
return match ($this->status) {
1 => '<span class="badge bg-success">Active</span>',
2 => '<span class="badge bg-secondary">Cancel</span>',
default => '<span class="badge bg-danger">Pending</span>',
};
}
}