Files
portal-api/app/Models/IpPoolLog.php
T
baodev0andClaude Opus 5.5 46aa138eec feat(admin): IP pool allocation, billing exports, service attachments
- IP pool: sheet import (xlsx/csv) matched by address, bulk allocate/revoke
  with notification email (ip_allocated/ip_revoked), ip_pool_logs history.
- Orders/invoices: Excel export on branded template (BrandedReportWriter),
  shared billing filters, order item service info in list responses.
- Web design quote Excel export; activity log export.
- Service attachments with copy-to-invoice; deployment invoice attachments.
- Customer email attachments stored on disk and attached by path.
- Admin password change endpoint; user.fullname backfill migration;
  orders.user_id backfill from logs.
- Disable deploy workflow until CI/CD is set up.
- Ignore stored customer email and service attachment uploads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 19:58:36 +07:00

61 lines
1.9 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class IpPoolLog extends Model
{
public const ALLOCATED = 'allocated';
public const REVOKED = 'revoked';
public const VM_ASSIGNED = 'vm_assigned';
public const VM_RELEASED = 'vm_released';
public const UPDATED_AT = null;
protected $casts = ['effective_date' => 'date:Y-m-d'];
protected $fillable = [
'ip_pool_id', 'ip_address', 'action', 'effective_date', 'status_from', 'status_to',
'customer_id', 'customer_name', 'service_name', 'service_id', 'vm_name', 'email_to', 'user_id', 'note',
];
public static function record(IpPool $pool, string $action, string $statusFrom, array $attributes = []): self
{
return self::create([
'ip_pool_id' => $pool->id,
'ip_address' => $pool->ip_address,
'action' => $action,
'status_from' => $statusFrom,
'status_to' => $pool->status,
'user_id' => auth('admin')->id(),
...$attributes,
]);
}
public static function recordVm(?int $poolId, string $action, string $statusFrom, ModuleVmware $vm, ?string $note = null): void
{
$pool = $poolId ? IpPool::find($poolId) : null;
if (!$pool) {
return;
}
$service = Service::where('id', $vm->service_id)->orWhere('vm_id', $vm->id)->first(['id', 'server_name']);
self::record($pool, $action, $statusFrom, [
'vm_name' => $vm->name,
'service_id' => $service?->id,
'service_name' => $service?->server_name,
'customer_id' => $vm->customer_id,
'customer_name' => Customer::whereKey($vm->customer_id)->value('fullname'),
'note' => $note,
]);
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}