authorizeAbility($request, 'settings.view'); $organization = $this->organization($request); $canManage = app(QmsPermissions::class)->can($this->member($request), 'settings.manage'); $branchCount = Branch::owned($this->ownerRef($request)) ->where('organization_id', $organization->id) ->count(); return view('qms.settings.edit', [ 'organization' => $organization, 'canManage' => $canManage, 'branchCount' => $branchCount, 'appointmentModes' => config('qms.appointment_modes'), 'industries' => config('qms.industry_templates'), ]); } public function update(Request $request): RedirectResponse { $this->authorizeAbility($request, 'settings.manage'); $organization = $this->organization($request); $owner = $this->ownerRef($request); $validated = $request->validate([ 'name' => ['required', 'string', 'max:255'], 'timezone' => ['required', 'timezone'], 'appointment_mode' => ['required', 'string', 'in:'.implode(',', array_keys(config('qms.appointment_modes')))], 'industry' => ['nullable', 'string'], 'notifications_enabled' => ['boolean'], 'care_integration_enabled' => ['nullable', 'boolean'], 'frontdesk_integration_enabled' => ['nullable', 'boolean'], 'logo' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp,svg', 'max:2048'], 'remove_logo' => ['nullable', 'boolean'], ]); $settings = $organization->settings ?? []; $settings['appointment_mode'] = $validated['appointment_mode']; $settings['industry'] = $validated['industry'] ?? $settings['industry'] ?? null; $settings['notifications_enabled'] = $request->boolean('notifications_enabled', true); $integrations = $settings['integrations'] ?? []; if ($request->has('care_integration_enabled')) { $integrations['care_enabled'] = $request->boolean('care_integration_enabled'); } if ($request->has('frontdesk_integration_enabled')) { $integrations['frontdesk_enabled'] = $request->boolean('frontdesk_integration_enabled'); } $settings['integrations'] = $integrations; $logoPath = $organization->logo_path; if ($request->boolean('remove_logo')) { OrganizationBranding::deleteStoredLogo($organization); $logoPath = null; } if ($request->hasFile('logo')) { $logoPath = OrganizationBranding::storeLogo($organization, $request->file('logo')); } $organization->update([ 'name' => $validated['name'], 'timezone' => $validated['timezone'], 'logo_path' => $logoPath, 'settings' => $settings, ]); AuditLogger::record($owner, 'organization.updated', $organization->id, $owner, \App\Models\Organization::class, $organization->id); return back()->with('success', 'Settings saved.'); } }