Deploy 2: 2FA (App + Email) + REST API + CSV import-export + auto backup
- Filament v5 multiFactorAuthentication enabled on both panels (App + Email) - HasAppAuthentication + HasEmailAuthentication on User and SuperAdmin - Migration: app_authentication_secret + recovery_codes + email_authentication_at - Sanctum REST API: /api/v1/login, /me, clients, vehicles, work-orders - EnsureTokenMatchesTenant middleware blocks cross-tenant token usage - CsvImportExport service: clients + vehicles bulk via plain CSV - Import/Export buttons on Client + Vehicle list pages - ApiTokens page in tenant panel (generate/revoke + last-used) - BackupAllTenantsCommand + scheduler (daily 03:00, retain 14 days) - Background scheduler in entrypoint.sh
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Models\Tenant\WorkOrder;
|
||||
use App\Tenancy\TenantManager;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class WorkOrderApiController
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$q = WorkOrder::query()->with(['client:id,name,phone', 'vehicle:id,plate,brand,model']);
|
||||
if ($status = $request->query('status')) {
|
||||
$q->where('status', $status);
|
||||
}
|
||||
if ($s = $request->query('search')) {
|
||||
$q->where(function ($qq) use ($s) {
|
||||
$qq->where('number', 'like', "%{$s}%")
|
||||
->orWhereHas('vehicle', fn ($v) => $v->where('plate', 'like', "%{$s}%"));
|
||||
});
|
||||
}
|
||||
return response()->json($q->latest()->paginate(min((int) $request->query('per_page', 25), 100)));
|
||||
}
|
||||
|
||||
public function show(WorkOrder $workOrder): JsonResponse
|
||||
{
|
||||
return response()->json($workOrder->load(['client', 'vehicle', 'master', 'works', 'parts', 'payments']));
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'client_id' => 'required|exists:clients,id',
|
||||
'vehicle_id' => 'required|exists:vehicles,id',
|
||||
'master_id' => 'nullable|exists:users,id',
|
||||
'opened_at' => 'nullable|date',
|
||||
'mileage_in' => 'nullable|integer|min:0',
|
||||
'complaint' => 'nullable|string',
|
||||
'status' => 'in:new,diagnosis,agreement,approved,in_work,awaiting_parts,ready,done,cancelled',
|
||||
]);
|
||||
$tenantId = app(TenantManager::class)->currentId();
|
||||
$data['number'] = WorkOrder::generateNumber($tenantId);
|
||||
$data['opened_at'] ??= now();
|
||||
$data['status'] ??= 'new';
|
||||
$data['pay_status'] = 'unpaid';
|
||||
$data['discount_pct'] = 0;
|
||||
$data['total'] = 0;
|
||||
$wo = WorkOrder::create($data);
|
||||
return response()->json($wo, 201);
|
||||
}
|
||||
|
||||
public function update(Request $request, WorkOrder $workOrder): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'status' => 'sometimes|in:new,diagnosis,agreement,approved,in_work,awaiting_parts,ready,done,cancelled',
|
||||
'mileage_out' => 'nullable|integer|min:0',
|
||||
'diagnosis' => 'nullable|string',
|
||||
'recommendations' => 'nullable|string',
|
||||
'discount_pct' => 'nullable|numeric|min:0|max:100',
|
||||
]);
|
||||
$workOrder->update($data);
|
||||
$workOrder->recalcTotal();
|
||||
return response()->json($workOrder->fresh());
|
||||
}
|
||||
|
||||
public function destroy(WorkOrder $workOrder): JsonResponse
|
||||
{
|
||||
$workOrder->delete();
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user