authorizeAbility($request, 'settings.view'); $organization = $this->organization($request); $canManage = app(FrontdeskPermissions::class)->isAdmin($this->member($request)); $branches = Branch::owned($this->ownerRef($request)) ->where('organization_id', $organization->id) ->count(); $monthlyUsage = $usage->forOrganization($organization); $plan = $plans->plan($organization); $freeEmailAllowance = $plans->freeEmailsPerMonth($organization); return view('frontdesk.settings.edit', [ 'organization' => $organization, 'canManage' => $canManage, 'branchCount' => $branches, 'roles' => config('frontdesk.roles'), 'deviceTypes' => config('frontdesk.device_types'), 'notificationChannels' => config('frontdesk.notification_channels'), 'notificationEvents' => config('frontdesk.notification_events'), 'plan' => $plan, 'isPro' => $plans->isPro($organization), 'isEnterprise' => $plans->isEnterprise($organization), 'hasPaidPlan' => $plans->hasPaidPlan($organization), 'billedBranches' => $plans->billedBranches($organization), 'activeBranchCount' => $plans->activeBranchCount($organization), 'proPriceMinor' => $plans->proPricePerBranchMinor(), 'monthlyUsage' => $monthlyUsage, 'freeEmailAllowance' => $freeEmailAllowance, 'emailCostFormatted' => $pricing->formatMinor($pricing->emailCostMinor()), 'smsCostFormatted' => $pricing->formatMinor( $pricing->smsCostMinor('Sample SMS message for pricing display.'), ), ]); } public function update(Request $request, QueueClient $queue): 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'], 'badge_expiry_hours' => ['required', 'integer', 'min:1', 'max:24'], 'kiosk_reset_seconds' => ['required', 'integer', 'min:30', 'max:600'], 'contractor_badge_expiry_hours' => ['nullable', 'integer', 'min:1', 'max:24'], 'visitor_policy' => ['nullable', 'string', 'max:5000'], 'notification_channels' => ['nullable', 'array'], 'notification_channels.*' => ['string', 'in:'.implode(',', array_keys(config('frontdesk.notification_channels')))], 'notification_events' => ['nullable', 'array'], 'report_daily_recipients' => ['nullable', 'string', 'max:2000'], 'logo' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp,svg', 'max:2048'], 'remove_logo' => ['nullable', 'boolean'], 'employee_kiosk_enabled' => ['nullable', 'boolean'], 'queue_integration_enabled' => ['nullable', 'boolean'], ]); $settings = $organization->settings ?? []; $settings['onboarded'] = true; $wantsQueue = $request->boolean('queue_integration_enabled'); $hadQueue = (bool) data_get($settings, 'queue_integration_enabled', false); $settings['queue_integration_enabled'] = $wantsQueue; if ($wantsQueue && $queue->configured()) { $branch = Branch::owned($owner)->where('organization_id', $organization->id)->orderBy('name')->first(); try { $queue->enable($owner, $organization->name, $branch?->name); } catch (\Throwable) { return back()->withInput()->with('error', 'Could not provision Ladill Queue for this account. Ensure Queue API keys are configured and Queue allows Frontdesk integration.'); } } $settings['badge_expiry_hours'] = $validated['badge_expiry_hours']; $settings['kiosk_reset_seconds'] = $validated['kiosk_reset_seconds']; $settings['visitor_policy'] = $validated['visitor_policy'] ?? null; $settings['employee_kiosk_enabled'] = $request->boolean('employee_kiosk_enabled'); $settings['notification_channels'] = $validated['notification_channels'] ?? ['email']; $eventKeys = array_keys(config('frontdesk.notification_events', [])); $submittedEvents = $validated['notification_events'] ?? []; $settings['notification_events'] = []; foreach ($eventKeys as $key) { $settings['notification_events'][$key] = (bool) ($submittedEvents[$key] ?? false); } if (array_key_exists('report_daily_recipients', $validated)) { $settings['report_daily_recipients'] = array_values(array_filter(array_map( 'trim', explode(',', (string) ($validated['report_daily_recipients'] ?? '')), ))); } if (! empty($validated['contractor_badge_expiry_hours'])) { $settings['type_badge_expiry_hours'] = array_merge( $settings['type_badge_expiry_hours'] ?? [], ['contractor' => (int) $validated['contractor_badge_expiry_hours']], ); } $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, ]); return back()->with('success', 'Settings saved.'); } }