Deploy Ladill Queue / deploy (push) Successful in 50s
Match Frontdesk: settings cards and nested routes, Pro-gated access, and legacy /admin redirects to /settings/branches and /settings/team.
104 lines
4.3 KiB
PHP
104 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Qms;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Controllers\Qms\Concerns\ScopesToAccount;
|
|
use App\Models\Branch;
|
|
use App\Services\Qms\AuditLogger;
|
|
use App\Services\Qms\PlanService;
|
|
use App\Services\Qms\QmsPermissions;
|
|
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): View
|
|
{
|
|
$this->authorizeAbility($request, 'settings.view');
|
|
$organization = $this->organization($request);
|
|
$member = $this->member($request);
|
|
$permissions = app(QmsPermissions::class);
|
|
$canManage = $permissions->can($member, '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'),
|
|
'hasPaidPlan' => $plans->hasPaidPlan($organization),
|
|
'isPro' => $plans->isPro($organization),
|
|
'isEnterprise' => $plans->isEnterprise($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'),
|
|
'proPriceMinor' => $plans->proPricePerBranchMinor(),
|
|
'activeBranchCount' => $plans->activeBranchCount($organization),
|
|
]);
|
|
}
|
|
|
|
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.');
|
|
}
|
|
}
|