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:
baodev0
2026-10-15 19:58:36 +07:00
co-authored by Claude Opus 5.5
parent ea5697cb81
commit 46aa138eec
95 changed files with 4247 additions and 454 deletions
@@ -0,0 +1,82 @@
<?php
namespace App\Http\Controllers\Api\Admin\Service\Concerns;
use App\Models\Invoice;
use App\Models\InvoiceAttachment;
use App\Models\Service;
use App\Models\ServiceAttachment;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
trait HandlesServiceAttachments
{
public function listAttachments(int $id): JsonResponse
{
$service = Service::with('orderItem')->findOrFail($id);
return response()->json([
'error' => false,
'data' => [
'attachments' => ServiceAttachment::where('service_id', $id)->latest()->get(),
'invoices' => $this->linkedInvoices(collect([$service])),
],
]);
}
public function uploadAttachment(Request $request, int $id): JsonResponse
{
Service::findOrFail($id);
$request->validate(['file' => InvoiceAttachment::UPLOAD_RULE]);
$file = $request->file('file');
$attachment = ServiceAttachment::create([
'service_id' => $id,
'filename' => $file->getClientOriginalName(),
'path' => $file->store("service-attachments/{$id}", 'public'),
'disk' => 'public',
'mime_type' => $file->getMimeType(),
'size' => $file->getSize(),
'uploaded_by' => $request->user()?->username ?? $request->user()?->name ?? 'admin',
]);
return response()->json(['error' => false, 'message' => 'File uploaded successfully', 'data' => $attachment], 201);
}
public function deleteAttachment(int $id, int $attachmentId): JsonResponse
{
$attachment = ServiceAttachment::where('service_id', $id)->findOrFail($attachmentId);
Storage::disk($attachment->disk)->delete($attachment->path);
$attachment->delete();
return response()->json(['error' => false, 'message' => 'Attachment deleted']);
}
public function copyAttachmentToInvoice(Request $request, int $id, int $attachmentId): JsonResponse
{
$service = Service::with('orderItem')->findOrFail($id);
$attachment = ServiceAttachment::where('service_id', $id)->findOrFail($attachmentId);
$invoiceId = (int) $request->validate(['invoice_id' => 'required|integer'])['invoice_id'];
$invoice = Invoice::ofServices([$service])->findOrFail($invoiceId);
$path = "invoice-attachments/{$invoice->id}/" . basename($attachment->path);
if (!Storage::disk('public')->exists($path)) {
Storage::disk('public')->put($path, Storage::disk($attachment->disk)->readStream($attachment->path));
}
$copy = InvoiceAttachment::firstOrCreate(
['invoice_id' => $invoice->id, 'path' => $path],
[
'type' => InvoiceAttachment::TYPE_DEPLOYMENT,
'filename' => $attachment->filename,
'disk' => 'public',
'mime_type' => $attachment->mime_type,
'size' => $attachment->size,
'uploaded_by' => $request->user()?->username ?? $request->user()?->name ?? 'admin',
],
);
return response()->json(['error' => false, 'message' => 'Attachment copied to invoice', 'data' => $copy], 201);
}
}
@@ -3,26 +3,31 @@
namespace App\Http\Controllers\Api\Admin\Service;
use App\Helpers\OrderHelper;
use App\Http\Controllers\Api\Admin\Service\Concerns\HandlesServiceAttachments;
use App\Http\Controllers\Controller;
use App\Jobs\VirtualMachine\Provision\ResendVmCredentialsEmailJob;
use App\Models\ActivityLog;
use App\Models\DomainPricing;
use App\Models\Invoice;
use App\Models\ModuleVmware;
use App\Models\Service;
use App\Services\Customer\CustomerServiceAssignment;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Collection;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class ServiceController extends Controller
{
use HandlesServiceAttachments;
public function __construct(private readonly CustomerServiceAssignment $assignment) {}
public function index(Request $request): JsonResponse
{
$perPage = min((int) ($request->per_page ?? 15), 100);
$query = Service::with(['customer:id,uuid,fullname,email', 'product:id,uuid,name', 'invoice:id,invoice_number', 'vmware:id,name,module_ip_address'])
$query = Service::with(['customer:id,uuid,fullname,email', 'product:id,uuid,name', 'invoice:id,invoice_number', 'vmware:id,name,module_ip_address', 'orderItem:id,order_id', 'orderItem.order:id,order_num'])
->where(fn($q) => $q->whereNull('order_item_id')->orWhereNull('type')->orWhere('type', '!=', 'domain'))
->when($request->filter, fn($q, $v) => $q->where('server_name', 'like', "%{$v}%"))
->when($request->status, fn($q, $v) => $q->where('status', $v))
@@ -30,6 +35,11 @@ class ServiceController extends Controller
->when($request->boolean('unassigned'), fn($q) => $q->whereNull('customer_id'));
$paginator = $query->latest()->paginate($perPage);
$invoices = $this->linkedInvoices($paginator->getCollection());
$paginator->getCollection()->each(fn (Service $service) => $service->setAttribute(
'linked_invoices',
$invoices->filter(fn (Invoice $invoice) => $invoice->belongsToService($service))->values(),
));
return response()->json([
'error' => false,
@@ -72,11 +82,12 @@ class ServiceController extends Controller
public function show(int $id): JsonResponse
{
$service = Service::with(['customer', 'product', 'orderItem', 'invoice', 'vmware.os.osGroup', 'addons', ...Service::HOSTING_ACCOUNT_RELATIONS])
$service = Service::with(['customer', 'product', 'orderItem.order:id,order_num', 'invoice', 'vmware.os.osGroup', 'addons', ...Service::HOSTING_ACCOUNT_RELATIONS])
->findOrFail($id);
ModuleVmware::resolveVirtualMachineIds([$service->vmware]);
$service->setAttribute('linked_invoices', $this->linkedInvoices(collect([$service])));
$service->setAttribute('activity_logs', ActivityLog::where('subject_type', Service::class)
->where('subject_id', $service->id)
->latest('id')
@@ -86,6 +97,15 @@ class ServiceController extends Controller
return response()->json(['error' => false, 'data' => $service]);
}
/** @param Collection<int, Service> $services */
private function linkedInvoices(Collection $services): Collection
{
return Invoice::ofServices($services)
->with('order:id,order_num')
->latest('id')
->get(['id', 'order_id', 'service_id', 'invoice_number', 'invoice_type', 'status', 'total', 'created_at']);
}
public function bulkAction(Request $request): JsonResponse
{
$data = $request->validate([