authorize('customers.use'); if ($customer === null) { return; } $summary = $customerQueries->findSummary($customer); abort_if($summary === null, 404); $this->customerId = $summary->id; $this->storedPersonalIdentityCode = $summary->personalIdentityCodeMasked; $this->form->fillFromSummary($summary); } public function save(RegisterCustomer $registerCustomer, UpdateCustomer $updateCustomer): void { $this->authorize('customers.use'); if ($this->form->remove_personal_identity_code) { $this->authorize('customers.view-personal-identity-code'); } if (! $this->identityCodeAttemptAllowed()) { $this->resetErrorBag('form.personal_identity_code'); $this->addError('form.personal_identity_code', __('customers.errors.personal_identity_code_throttled')); return; } $data = $this->form->toData(); try { if ($this->customerId === null) { $customerId = $registerCustomer->execute($data); session()->flash('status', __('customers.created', ['name' => $data->name])); } else { $updateCustomer->execute($this->customerId, $data); $customerId = $this->customerId; session()->flash('status', __('customers.updated', ['name' => $data->name])); } } catch (CustomerNotFound) { abort(404); } catch (DomainException $exception) { $this->form->showDomainError($exception); return; } // The customer's page, where contacts and billing units are added. $this->redirectRoute('customers.show', $customerId, navigate: true); } /** * Counts a save that carries a new personal identity code; admins and * management, who see the codes anyway, are not limited. */ private function identityCodeAttemptAllowed(): bool { if (trim($this->form->personal_identity_code) === '' || Gate::allows('customers.view-personal-identity-code')) { return true; } $key = 'identity-code-save|'.auth()->id(); if (RateLimiter::tooManyAttempts($key, self::MAX_IDENTITY_CODE_SAVES_PER_HOUR)) { return false; } RateLimiter::hit($key, 3600); return true; } public function render(): mixed { return $this->view()->title(__($this->customerId === null ? 'customers.create_title' : 'customers.edit_title')); } }; ?>
{{ __($customerId === null ? 'customers.create_title' : 'customers.edit_title') }}
@if ($form->type === CustomerType::Company->value) {{-- No inputmode="numeric": the iOS number pad has no hyphen for 1234567-8. --}} @else {{-- Never filled from the stored code; type="text" because the code has letters. --}} @if ($storedPersonalIdentityCode !== null) @can('customers.view-personal-identity-code') @endcan @endif @endif