Files
isaacclad b6f229ab9a
Deploy Ladill Frontdesk / deploy (push) Has been cancelled
Tighten Pro alert caps and move custom badges to Enterprise.
Pro includes 5,000 email and 5,000 SMS host alerts per month with hard
monthly caps; Enterprise is unlimited. Custom badge templates are
Enterprise-only, and plan benefit copy matches the new limits.
2026-07-16 08:37:06 +00:00

154 lines
7.0 KiB
PHP

<?php
namespace App\Http\Controllers\Frontdesk;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Frontdesk\Concerns\ScopesToAccount;
use App\Models\Branch;
use App\Services\Frontdesk\FrontdeskPermissions;
use App\Services\Frontdesk\NotificationPricingService;
use App\Services\Frontdesk\NotificationUsageService;
use App\Services\Frontdesk\PlanService;
use App\Services\Queue\QueueClient;
use App\Support\OrganizationBranding;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class SettingsController extends Controller
{
use ScopesToAccount;
public function edit(Request $request, PlanService $plans, NotificationUsageService $usage, NotificationPricingService $pricing): View
{
$this->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);
$freeSmsAllowance = $plans->freeSmsPerMonth($organization);
$member = $this->member($request);
$permissions = app(FrontdeskPermissions::class);
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),
'hasBranchesFeature' => $plans->hasFeature($organization, 'branches'),
'hasTeamFeature' => $plans->hasFeature($organization, 'team'),
'canViewBranches' => $permissions->can($member, 'admin.branches.view'),
'canViewTeam' => $permissions->can($member, 'admin.members.view'),
'billedBranches' => $plans->billedBranches($organization),
'activeBranchCount' => $plans->activeBranchCount($organization),
'proPriceMinor' => $plans->proPricePerBranchMinor(),
'monthlyUsage' => $monthlyUsage,
'freeEmailAllowance' => $freeEmailAllowance,
'freeSmsAllowance' => $freeSmsAllowance,
'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.');
}
}