@@ -7,6 +7,7 @@ use App\Http\Requests\Administration\StoreTenantRequest;
|
||||
use App\Http\Requests\Administration\UpdateTenantRequest;
|
||||
use App\Models\Tenant;
|
||||
use App\Models\User;
|
||||
use App\Services\LicenseEntitlementService;
|
||||
use App\Services\TenantProvisioningService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Inertia\Inertia;
|
||||
@@ -21,6 +22,7 @@ class TenantController extends Controller
|
||||
$tenants = Tenant::query()
|
||||
->withCount('users')
|
||||
->with('installations:id,tenant_id,deployment_type,domain,status,last_seen_at')
|
||||
->with(['licenses' => fn ($query) => $query->latest('created_at')])
|
||||
->orderBy('name')
|
||||
->paginate(15)
|
||||
->withQueryString();
|
||||
@@ -32,12 +34,12 @@ class TenantController extends Controller
|
||||
{
|
||||
$this->authorize('create', Tenant::class);
|
||||
|
||||
return Inertia::render('administration/tenants/create');
|
||||
return Inertia::render('administration/tenants/create', ['plans' => config('billing.plans')]);
|
||||
}
|
||||
|
||||
public function store(StoreTenantRequest $request, TenantProvisioningService $service): RedirectResponse
|
||||
{
|
||||
$tenant = $service->createWithOwner($request->validated());
|
||||
$tenant = $service->createWithOwner($request->validated() + ['activate_license' => true, 'issued_by' => $request->user()->id]);
|
||||
|
||||
return to_route('administration.tenants.edit', $tenant)
|
||||
->with('success', 'Tenant dan Tenant Owner berhasil dibuat.');
|
||||
@@ -57,6 +59,8 @@ class TenantController extends Controller
|
||||
'tenant' => $tenant,
|
||||
'users' => $users,
|
||||
'installation' => $tenant->installations()->first(['id', 'deployment_type', 'domain', 'status', 'last_seen_at']),
|
||||
'license' => $tenant->licenses()->latest('created_at')->first(),
|
||||
'plans' => config('billing.plans'),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -71,6 +75,12 @@ class TenantController extends Controller
|
||||
'domain' => $data['deployment_domain'] ?? null,
|
||||
]);
|
||||
}
|
||||
$currentLicense = $tenant->licenses()->latest('created_at')->first();
|
||||
if (! empty($data['plan_code']) && $currentLicense?->plan !== $data['plan_code']) {
|
||||
$installation = $tenant->installations()->firstOrFail();
|
||||
$tenant->licenses()->whereIn('status', ['active', 'grace'])->update(['status' => 'revoked']);
|
||||
app(LicenseEntitlementService::class)->provisionInitial($tenant, $installation, $data['plan_code'], true, $request->user()->id);
|
||||
}
|
||||
|
||||
return back()->with('success', 'Tenant berhasil diperbarui.');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user