Files
portal-api/app/Support/ServiceExpirySync.php

24 lines
584 B
PHP

<?php
namespace App\Support;
use App\Models\ModuleVmware;
use App\Models\Service;
final class ServiceExpirySync
{
public static function toVmware(Service $service): int
{
if (! $service->vm_id || ! $service->expires_at) {
return 0;
}
$timestamp = $service->expires_at->timestamp;
return ModuleVmware::query()
->whereKey($service->vm_id)
->where(fn ($query) => $query->whereNull('next_due_date')->orWhere('next_due_date', '!=', $timestamp))
->update(['next_due_date' => $timestamp]);
}
}