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>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
ea5697cb81
commit
46aa138eec
@@ -4,6 +4,7 @@ namespace App\Models;
|
||||
|
||||
use App\Enums\Invoice\InvoiceStatus;
|
||||
use App\Traits\LogsActivity;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
@@ -41,6 +42,26 @@ class Invoice extends Model
|
||||
return '/hoa-don/' . ($this->order?->order_num ?? $this->invoice_number);
|
||||
}
|
||||
|
||||
/** @param iterable<Service> $services */
|
||||
public function scopeOfServices(Builder $query, iterable $services): Builder
|
||||
{
|
||||
$services = collect($services);
|
||||
$orderIds = $services->map(fn (Service $service) => $service->orderItem?->order_id)->filter()->unique()->values();
|
||||
|
||||
return $query->where(fn (Builder $q) => $q
|
||||
->whereIn('service_id', $services->pluck('id'))
|
||||
->orWhere(fn (Builder $q) => $q->whereNull('service_id')->whereIn('order_id', $orderIds)));
|
||||
}
|
||||
|
||||
public function belongsToService(Service $service): bool
|
||||
{
|
||||
if ($this->service_id !== null) {
|
||||
return (int) $this->service_id === (int) $service->id;
|
||||
}
|
||||
|
||||
return $this->order_id !== null && (int) $this->order_id === (int) $service->orderItem?->order_id;
|
||||
}
|
||||
|
||||
public function order()
|
||||
{
|
||||
return $this->belongsTo(Order::class, 'order_id');
|
||||
|
||||
@@ -9,6 +9,7 @@ class InvoiceAttachment extends Model
|
||||
{
|
||||
public const TYPE_PAYMENT_PROOF = 'payment_proof';
|
||||
public const TYPE_DEPLOYMENT = 'deployment';
|
||||
public const UPLOAD_RULE = 'required|file|mimes:jpg,jpeg,png,gif,webp,pdf,doc,docx,xls,xlsx|max:51200';
|
||||
|
||||
protected $table = 'invoice_attachments';
|
||||
|
||||
|
||||
+12
-1
@@ -15,6 +15,7 @@ class IpPool extends Model
|
||||
protected $fillable = [
|
||||
'uuid',
|
||||
'ip_address',
|
||||
'ip_block',
|
||||
'gateway',
|
||||
'cidr',
|
||||
'netmask',
|
||||
@@ -24,10 +25,10 @@ class IpPool extends Model
|
||||
'ip_role',
|
||||
'parent_ip',
|
||||
'customer_name',
|
||||
'customer_id',
|
||||
'service_name',
|
||||
'allocated_at',
|
||||
'revoked_at',
|
||||
'allocation_status',
|
||||
'service_id',
|
||||
'contact_email',
|
||||
'contact_cc',
|
||||
@@ -73,6 +74,16 @@ class IpPool extends Model
|
||||
return $this->belongsTo(ModuleNetwork::class, 'module_network_id', 'id');
|
||||
}
|
||||
|
||||
public function customer()
|
||||
{
|
||||
return $this->belongsTo(Customer::class);
|
||||
}
|
||||
|
||||
public function logs()
|
||||
{
|
||||
return $this->hasMany(IpPoolLog::class)->latest('id');
|
||||
}
|
||||
|
||||
public function service()
|
||||
{
|
||||
return $this->belongsTo(Service::class, 'service_id');
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ServiceAttachment extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
protected $appends = ['url'];
|
||||
|
||||
public function service()
|
||||
{
|
||||
return $this->belongsTo(Service::class);
|
||||
}
|
||||
|
||||
public function getUrlAttribute(): string
|
||||
{
|
||||
return Storage::disk($this->disk)->url($this->path);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -64,7 +64,7 @@ class User extends Authenticatable implements JWTSubject
|
||||
|
||||
public function getNameAttribute(): string
|
||||
{
|
||||
return trim("{$this->firstname} {$this->lastname}") ?: trim((string) $this->fullname);
|
||||
return trim((string) $this->fullname);
|
||||
}
|
||||
|
||||
public function staffOnline()
|
||||
|
||||
Reference in New Issue
Block a user