diff --git a/app/Http/Controllers/Qms/SettingsController.php b/app/Http/Controllers/Qms/SettingsController.php index a1158eb..6dbe493 100644 --- a/app/Http/Controllers/Qms/SettingsController.php +++ b/app/Http/Controllers/Qms/SettingsController.php @@ -64,9 +64,9 @@ class SettingsController extends Controller $validated = $request->validate([ 'name' => ['required', 'string', 'max:255'], - 'timezone' => ['required', 'timezone'], + 'timezone' => ['required', 'string', 'timezone:all'], 'appointment_mode' => ['required', 'string', 'in:'.implode(',', array_keys(config('qms.appointment_modes')))], - 'industry' => ['nullable', 'string', 'in:'.implode(',', array_keys(config('industry_packages.packages', [])))], + 'industry' => ['nullable', 'string', 'max:64'], 'notifications_enabled' => ['boolean'], 'care_integration_enabled' => ['nullable', 'boolean'], 'frontdesk_integration_enabled' => ['nullable', 'boolean'], @@ -74,10 +74,17 @@ class SettingsController extends Controller 'remove_logo' => ['nullable', 'boolean'], ]); + $registry = app(IndustryPackageRegistry::class); $settings = $organization->settings ?? []; + $industry = isset($validated['industry']) && $validated['industry'] !== '' + ? $registry->resolveKey($validated['industry']) + : ($settings['industry'] ?? null); + $settings['appointment_mode'] = $validated['appointment_mode']; $previousIndustry = $settings['industry'] ?? null; - $settings['industry'] = $validated['industry'] ?? $settings['industry'] ?? null; + if ($industry !== null) { + $settings['industry'] = $industry; + } $settings['notifications_enabled'] = $request->boolean('notifications_enabled', true); $integrations = $settings['integrations'] ?? []; if ($request->has('care_integration_enabled')) { @@ -108,7 +115,8 @@ class SettingsController extends Controller AuditLogger::record($owner, 'organization.updated', $organization->id, $owner, \App\Models\Organization::class, $organization->id); - $industryChanged = $settings['industry'] && $settings['industry'] !== $previousIndustry; + $industryChanged = ($settings['industry'] ?? null) && ($settings['industry'] ?? null) !== $previousIndustry; + $packageNote = ''; if ($industryChanged) { $branch = Branch::query() ->where('organization_id', $organization->id) @@ -116,15 +124,19 @@ class SettingsController extends Controller ->orderBy('id') ->first(); if ($branch) { - app(IndustryPackageInstaller::class)->install($organization->fresh(), $branch, $settings['industry'], [ - 'actor_ref' => $owner, - ]); + try { + app(IndustryPackageInstaller::class)->install($organization->fresh(), $branch, $settings['industry'], [ + 'actor_ref' => $owner, + ]); + $packageNote = ' Industry package re-provisioned.'; + } catch (\Throwable $e) { + report($e); + $packageNote = ' Settings saved, but industry package re-provision failed — try Reinstall package.'; + } } } - return back()->with('success', $industryChanged - ? 'Settings saved. Industry package re-provisioned.' - : 'Settings saved.'); + return back()->with('success', 'Settings saved.'.$packageNote); } public function reinstallPackage(Request $request, IndustryPackageInstaller $installer): RedirectResponse diff --git a/resources/views/qms/settings/edit.blade.php b/resources/views/qms/settings/edit.blade.php index e4e732f..d9c77d0 100644 --- a/resources/views/qms/settings/edit.blade.php +++ b/resources/views/qms/settings/edit.blade.php @@ -24,6 +24,17 @@