для регионаольного менеджера добавлена возможность дбавления агентов и создания сделок от их имени

This commit is contained in:
developer 2025-12-09 17:07:45 +08:00
parent 474c97d4e8
commit 7b5e42f0d0
10 changed files with 329 additions and 298 deletions

View File

@ -20,9 +20,8 @@ public function mount($status = null)
} }
public function render() public function render()
{ {
$user = auth()->user();
$admin = CompanyAdmin::where('user_id', $user->id)->first(); $agents = GetAvailableAgents('Builder');
$agents = Agent::where('company_id', $admin->company_id);
if ($this->status == AgentStatus::DISMISSED) if ($this->status == AgentStatus::DISMISSED)
{ {
$agents->onlyTrashed(); $agents->onlyTrashed();

View File

@ -1,272 +1,284 @@
<?php <?php
use Modules\ClientCreateForm\Http\Livewire\FormStatus; use Modules\ClientCreateForm\Http\Livewire\FormStatus;
?> ?>
<div> <div class="flex-fill">
<div class="w-100 text-center" wire:loading wire:target="save, resetData, back"> <div class="w-100 text-center" wire:loading wire:target="save, resetData, back">
<div class="spinner-border " style="width: 4rem; height: 4rem;" role="status"> <div class="spinner-border " style="width: 4rem; height: 4rem;" role="status">
<span class="visually-hidden">Загрузка формы...</span> <span class="visually-hidden">Загрузка формы...</span>
</div> </div>
</div> </div>
<div class="w-100" wire:loading.remove wire:target="save, resetData, back"> @if(!$availableAgents)
@if ($status == FormStatus::NEW || $status == FormStatus::IN_PROCESS || $status == FormStatus::READY) <div class="w-100 text-center">
<ul class="nav nav-tabs d-flex align-items-end border-0 pb-0"> <div>
@foreach ($contacts as $contactIndex => $contactItem) <svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" fill="currentColor" class="bi bi-lock"
<li viewBox="0 0 16 16">
class="nav-item overflow-hidden @if ($contactIndex == $currentContactIndex) rounded-top border-top border-end border-start bg-light @else m-1 bg-secondary-subtle rounded rouded-5 @endif"> <path fill-rule="evenodd"
<a class="nav-link me-1 border-0 @if ($contactIndex == $currentContactIndex) active text-primary @else py-1 text-dark @endif" d="M8 0a4 4 0 0 1 4 4v2.05a2.5 2.5 0 0 1 2 2.45v5a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 2 13.5v-5a2.5 2.5 0 0 1 2-2.45V4a4 4 0 0 1 4-4M4.5 7A1.5 1.5 0 0 0 3 8.5v5A1.5 1.5 0 0 0 4.5 15h7a1.5 1.5 0 0 0 1.5-1.5v-5A1.5 1.5 0 0 0 11.5 7zM8 1a3 3 0 0 0-3 3v2h6V4a3 3 0 0 0-3-3" />
aria-current="page" href="#" wire:click="setCurrentContactIndex({{ $contactIndex }})"> </svg>
<i class="bi bi-person-standing"></i> </div>
<span class="d-none d-xl-inline"> <div class="my-2">
@if (array_key_exists($contactIndex, $contactLabels)) Вы пока не можете добавлять контакты и сделки
{{ $contactLabels[$contactIndex] }} </div>
@else </div>
Контакт {{ $contactIndex + 1 }} @endif
@endif
</span>
</a>
</li>
@endforeach
@if ($maxContactsCount > count($contacts))
<li class="align-middle ps-2 mb-2">
<a class="text-light " href="#" wire:click="addContact">
<svg xmlns="http://www.w3.org/2000/svg" width="25" height="25" fill="currentColor"
class="bi bi-person-fill-add" viewBox="0 0 16 16">
<path
d="M12.5 16a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7m.5-5v1h1a.5.5 0 0 1 0 1h-1v1a.5.5 0 0 1-1 0v-1h-1a.5.5 0 0 1 0-1h1v-1a.5.5 0 0 1 1 0m-2-6a3 3 0 1 1-6 0 3 3 0 0 1 6 0" />
<path
d="M2 13c0 1 1 1 1 1h5.256A4.5 4.5 0 0 1 8 12.5a4.5 4.5 0 0 1 1.544-3.393Q8.844 9.002 8 9c-5 0-6 3-6 4" />
</svg>
</a>
</li>
@endif
</ul>
<div class="bg-light border border-1 rounded-bottom-4 mb-2 pb-2" style="margin-top:-1px">
<div class="mt-3">
<div class="row mx-2 g-2">
<div class="col-12 col-xl-6">
<div class="form-floating mb-3 m-xl-0">
<input wire:model.live="contacts.{{ $currentContactIndex }}.firstName"
id="contacts.{{ $currentContactIndex }}.firstName" type="text"
class="form-control rounded-4 @error('contacts.' . $currentContactIndex . '.firstName') is-invalid @enderror"
name="contacts.{{ $currentContactIndex }}.firstName" required
autocomplete="contacts.{{ $currentContactIndex }}.firstName" placeholder="Имя">
<label for="contacts.{{ $currentContactIndex }}.firstName">Имя</label>
@error('contacts.' . $currentContactIndex . '.firstName')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
<div class="col-12 col-xl-6">
<div class="form-floating mb-3 m-xl-0">
<input wire:model.live="contacts.{{ $currentContactIndex }}.secondName"
id="contacts.{{ $currentContactIndex }}.secondName" type="text"
class="form-control rounded-4 @error('contacts.' . $currentContactIndex . '.secondName') is-invalid @enderror"
name="contacts.{{ $currentContactIndex }}.secondName" required
autocomplete="contacts.{{ $currentContactIndex }}.secondName"
placeholder="Фамилия">
<label for="contacts.{{ $currentContactIndex }}.secondName">Фамилия</label>
@error('contacts.' . $currentContactIndex . '.secondName')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div> @if($availableAgents && $complexes)
@foreach ($contacts[$currentContactIndex]['phones'] as $phoneKey => $phone) <div class="w-100" wire:loading.remove wire:target="save, resetData, back">
<div class="col-12 hstack gap-2"> @if ($status == FormStatus::NEW || $status == FormStatus::IN_PROCESS || $status == FormStatus::READY)
<div class="form-floating me-auto w-100"> <ul class="nav nav-tabs d-flex align-items-end border-0 pb-0">
<input @foreach ($contacts as $contactIndex => $contactItem)
wire:model.live="contacts.{{ $currentContactIndex }}.phones.{{ $phoneKey }}" <li
id="contacts.{{ $currentContactIndex }}.phones.{{ $phoneKey }}" class="nav-item overflow-hidden @if ($contactIndex == $currentContactIndex) rounded-top border-top border-end border-start bg-light @else m-1 bg-secondary-subtle rounded rouded-5 @endif">
type="text" data-phone-pattern <a class="nav-link me-1 border-0 @if ($contactIndex == $currentContactIndex) active text-primary @else py-1 text-dark @endif"
class="form-control rounded-4 @error('contacts.' . $currentContactIndex . '.phones.' . $phoneKey) is-invalid @enderror" aria-current="page" href="#" wire:click="setCurrentContactIndex({{ $contactIndex }})">
name="contacts.{{ $currentContactIndex }}.phones.{{ $phoneKey }}" required <i class="bi bi-person-standing"></i>
autocomplete="phone" placeholder="Телефон клиента"> <span class="d-none d-xl-inline">
<label @if (array_key_exists($contactIndex, $contactLabels))
for="contacts.{{ $currentContactIndex }}.phones.{{ $phoneKey }}">Телефон {{ $contactLabels[$contactIndex] }}
{{ count($contacts[$currentContactIndex]['phones']) > 1 ? ' ' . ($phoneKey + 1) : '' }}</label> @else
Контакт {{ $contactIndex + 1 }}
@error('contacts.' . $currentContactIndex . '.phones.' . $phoneKey) @endif
<span class="invalid-feedback d-block" role="alert"> </span>
</a>
</li>
@endforeach
@if ($maxContactsCount > count($contacts))
<li class="align-middle ps-2 mb-2">
<a class="text-light " href="#" wire:click="addContact">
<svg xmlns="http://www.w3.org/2000/svg" width="25" height="25" fill="currentColor"
class="bi bi-person-fill-add" viewBox="0 0 16 16">
<path
d="M12.5 16a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7m.5-5v1h1a.5.5 0 0 1 0 1h-1v1a.5.5 0 0 1-1 0v-1h-1a.5.5 0 0 1 0-1h1v-1a.5.5 0 0 1 1 0m-2-6a3 3 0 1 1-6 0 3 3 0 0 1 6 0" />
<path
d="M2 13c0 1 1 1 1 1h5.256A4.5 4.5 0 0 1 8 12.5a4.5 4.5 0 0 1 1.544-3.393Q8.844 9.002 8 9c-5 0-6 3-6 4" />
</svg>
</a>
</li>
@endif
</ul>
<div class="bg-light border border-1 rounded-bottom-4 mb-2 pb-2" style="margin-top:-1px">
<div class="mt-3">
<div class="row mx-2 g-2">
<div class="col-12 col-xl-6">
<div class="form-floating mb-3 m-xl-0">
<input wire:model.live="contacts.{{ $currentContactIndex }}.firstName"
id="contacts.{{ $currentContactIndex }}.firstName" type="text"
class="form-control rounded-4 @error('contacts.' . $currentContactIndex . '.firstName') is-invalid @enderror"
name="contacts.{{ $currentContactIndex }}.firstName" required
autocomplete="contacts.{{ $currentContactIndex }}.firstName" placeholder="Имя">
<label for="contacts.{{ $currentContactIndex }}.firstName">Имя</label>
@error('contacts.' . $currentContactIndex . '.firstName')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong> <strong>{{ $message }}</strong>
</span> </span>
@enderror @enderror
</div> </div>
@if (count($contacts[$currentContactIndex]['phones']) == $phoneKey + 1 && </div>
count($contacts[$currentContactIndex]['phones']) < $this->maxContactPhonesCount) <div class="col-12 col-xl-6">
<a class="" href="#" wire:click="addPhoneForClient" <div class="form-floating mb-3 m-xl-0">
title="Добавить еще один телефон для клиента"> <input wire:model.live="contacts.{{ $currentContactIndex }}.secondName"
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" id="contacts.{{ $currentContactIndex }}.secondName" type="text"
fill="currentColor" class="bi bi-plus-circle" viewBox="0 0 16 16"> class="form-control rounded-4 @error('contacts.' . $currentContactIndex . '.secondName') is-invalid @enderror"
<path name="contacts.{{ $currentContactIndex }}.secondName" required
d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16" /> autocomplete="contacts.{{ $currentContactIndex }}.secondName" placeholder="Фамилия">
<path <label for="contacts.{{ $currentContactIndex }}.secondName">Фамилия</label>
d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4" /> @error('contacts.' . $currentContactIndex . '.secondName')
</svg> <span class="invalid-feedback" role="alert">
</a> <strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
@foreach ($contacts[$currentContactIndex]['phones'] as $phoneKey => $phone)
<div class="col-12 hstack gap-2">
<div class="form-floating me-auto w-100">
<input wire:model.live="contacts.{{ $currentContactIndex }}.phones.{{ $phoneKey }}"
id="contacts.{{ $currentContactIndex }}.phones.{{ $phoneKey }}" type="text"
data-phone-pattern
class="form-control rounded-4 @error('contacts.' . $currentContactIndex . '.phones.' . $phoneKey) is-invalid @enderror"
name="contacts.{{ $currentContactIndex }}.phones.{{ $phoneKey }}" required
autocomplete="phone" placeholder="Телефон клиента">
<label for="contacts.{{ $currentContactIndex }}.phones.{{ $phoneKey }}">Телефон
{{ count($contacts[$currentContactIndex]['phones']) > 1 ? ' ' . ($phoneKey + 1) : '' }}</label>
@error('contacts.' . $currentContactIndex . '.phones.' . $phoneKey)
<span class="invalid-feedback d-block" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
@if (
count($contacts[$currentContactIndex]['phones']) == $phoneKey + 1 &&
count($contacts[$currentContactIndex]['phones']) < $this->maxContactPhonesCount
)
<a class="" href="#" wire:click="addPhoneForClient"
title="Добавить еще один телефон для клиента">
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" fill="currentColor"
class="bi bi-plus-circle" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16" />
<path
d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4" />
</svg>
</a>
@endif
</div>
@endforeach
<div class="col-12">
@if ($currentContactIndex == 0 && count($contacts) <= 2)
<div class="form-check form-switch">
<input class="form-check-input" wire:click="toggleSecondContact" type="checkbox"
role="switch" id="switchCheckChecked" @if (count($contacts) == 2) checked @endif>
<label class="form-check-label" for="switchCheckChecked">Добавить контакт
супруга/супруги</label>
</div>
@endif
@if ($currentContactIndex > 0)
<div class="text-end">
<a wire:click="deleteContact" class="text-primary"
style="text-decoration: underline dotted;" href="#">
Удалить контакт</a>
</div>
@endif @endif
</div> </div>
@endforeach
<div class="col-12">
@if ($currentContactIndex == 0 && count($contacts) <= 2)
<div class="form-check form-switch">
<input class="form-check-input" wire:click="toggleSecondContact" type="checkbox"
role="switch" id="switchCheckChecked"
@if (count($contacts) == 2) checked @endif>
<label class="form-check-label" for="switchCheckChecked">Добавить контакт
супруга/супруги</label>
</div>
@endif
@if ($currentContactIndex > 0)
<div class="text-end">
<a wire:click="deleteContact" class="text-primary"
style="text-decoration: underline dotted;" href="#">
Удалить контакт</a>
</div>
@endif
</div> </div>
</div> </div>
</div> </div>
</div>
<div class="form-floating mb-3">
<select wire:model.live="complexId"
class="form-select rounded-4 @error('complexId') is-invalid @enderror" id="complexId"
name="complexId" aria-label="Жилой комплекс">
<option selected></option>
@foreach ($complexes as $complex)
<option value="{{ $complex['id'] }}">
{{ $complex['name'] }}
</option>
@endforeach
</select>
<label for="complexId">Жилой комплекс</label>
@error('complexId')
<span class="invalid-feedback " role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
@if (count($availableAgents) > 1)
<div class="form-floating mb-3"> <div class="form-floating mb-3">
<select wire:model.live="agentId" <select wire:model.live="complexId" class="form-select rounded-4 @error('complexId') is-invalid @enderror"
class="form-select rounded-4 @error('agentId') is-invalid @enderror" id="agentId" id="complexId" name="complexId" aria-label="Жилой комплекс">
name="agent" aria-label="Агент">
<option selected></option> <option selected></option>
@foreach ($availableAgents as $agent) @foreach ($complexes as $complex)
<option value="{{ $agent['id'] }}"> <option value="{{ $complex['id'] }}">
{{ $agent['user']['name'] }} {{ $complex['name'] }}
</option> </option>
@endforeach @endforeach
</select> </select>
<label for="agentId">Агент</label> <label for="complexId">Жилой комплекс</label>
@error('agentId') @error('complexId')
<span class="invalid-feedback" role="alert"> <span class="invalid-feedback " role="alert">
<strong>{{ $message }}</strong> <strong>{{ $message }}</strong>
</span> </span>
@enderror @enderror
</div> </div>
@if (count($availableAgents) > 1)
<div class="form-floating mb-3">
<select wire:model.live="agentId" class="form-select rounded-4 @error('agentId') is-invalid @enderror"
id="agentId" name="agent" aria-label="Агент">
<option selected></option>
@foreach ($availableAgents as $agent)
<option value="{{ $agent['id'] }}">
{{ $agent['user']['name'] }}
</option>
@endforeach
</select>
<label for="agentId">Агент</label>
@error('agentId')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
@endif
@if ($status != FormStatus::READY)
<div class="">
<button disabled class="btn btn-secondary disabled rounded-4 fw-bold fs-5 w-100 py-3"
style="background-color: #20184d;">
Создать нового клиента
</button>
</div>
@else
<div class="">
<button wire:click="save" class="btn btn-secondary rounded-4 fw-bold fs-5 w-100 py-3"
style="background-color: #20184d;">
Создать нового клиента
</button>
</div>
@endif
@endif @endif
@if ($status != FormStatus::READY) @if ($status == FormStatus::SUCCESS)
<div class=""> <div class="text-center fs-1">
<button disabled class="btn btn-secondary disabled rounded-4 fw-bold fs-5 w-100 py-3" <svg xmlns="http://www.w3.org/2000/svg" width="60" height="60" fill="currentColor"
style="background-color: #20184d;"> class="bi bi-check-circle-fill" viewBox="0 0 16 16">
Создать нового клиента <path
</button> d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0m-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z">
</path>
</svg>
</div> </div>
@else
<div class=""> <div class="text-center fs-3">Клиент добавлен</div>
<button wire:click="save" class="btn btn-secondary rounded-4 fw-bold fs-5 w-100 py-3" <div class="text-center fs-5 ">Мы проверим его уникальность и направим Вам информацию в личном
style="background-color: #20184d;"> кабинете</div>
Создать нового клиента <div class="text-center mt-3">
</button> <button wire:click="resetData" class="btn active border-white border-3 rounded">Добавить еще</button>
</div> </div>
@endif @endif
@endif
@if ($status == FormStatus::SUCCESS) @if ($status == FormStatus::ERROR)
<div class="text-center fs-1"> <div class="text-center fs-1 mt-3">
<svg xmlns="http://www.w3.org/2000/svg" width="60" height="60" fill="currentColor" <svg xmlns="http://www.w3.org/2000/svg" width="60" height="60" fill="currentColor"
class="bi bi-check-circle-fill" viewBox="0 0 16 16"> class="bi bi-emoji-astonished" viewBox="0 0 16 16">
<path <path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16" />
d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0m-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z"> <path
</path> d="M7 6.5C7 7.328 6.552 8 6 8s-1-.672-1-1.5S5.448 5 6 5s1 .672 1 1.5m4 0c0 .828-.448 1.5-1 1.5s-1-.672-1-1.5S9.448 5 10 5s1 .672 1 1.5M4.884 4.022a2 2 0 0 1 1.458-.048.5.5 0 0 0 .316-.948 3 3 0 0 0-2.167.077 3.1 3.1 0 0 0-.773.478q-.036.03-.07.064l-.002.001a.5.5 0 0 0 .707.708l-.001.002.001-.002a2 2 0 0 1 .122-.1 2 2 0 0 1 .41-.232Zm6.232 0a2 2 0 0 0-1.458-.048.5.5 0 1 1-.316-.948 3 3 0 0 1 2.168.077 3 3 0 0 1 .773.478l.07.064v.001a.5.5 0 0 1-.706.708l.002.002-.002-.002a2 2 0 0 0-.122-.1 2 2 0 0 0-.41-.232ZM8 10c-.998 0-1.747.623-2.247 1.246-.383.478.08 1.06.687.98q1.56-.202 3.12 0c.606.08 1.07-.502.687-.98C9.747 10.623 8.998 10 8 10" />
</svg> </svg>
</div> </div>
<div class="text-center fs-3">Клиент добавлен</div> <div class="text-center fs-3">Ой!</div>
<div class="text-center fs-5 ">Мы проверим его уникальность и направим Вам информацию в личном <div class="text-center fs-5 ">Кажется, возникла проблема на нашей стороне, мы уже ее решаем.
кабинете</div> Попробуйте зайти сюда позже.</div>
<div class="text-center mt-3"> <div class="text-center my-3">
<button wire:click="resetData" class="btn active border-white border-3 rounded">Добавить еще</button> <button wire:click="back" class="btn btn-lg active border-2 rounded">Повторить</button>
</div> </div>
@endif @endif
</div>
@if ($status == FormStatus::ERROR) @endif
<div class="text-center fs-1 mt-3">
<svg xmlns="http://www.w3.org/2000/svg" width="60" height="60" fill="currentColor"
class="bi bi-emoji-astonished" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16" />
<path
d="M7 6.5C7 7.328 6.552 8 6 8s-1-.672-1-1.5S5.448 5 6 5s1 .672 1 1.5m4 0c0 .828-.448 1.5-1 1.5s-1-.672-1-1.5S9.448 5 10 5s1 .672 1 1.5M4.884 4.022a2 2 0 0 1 1.458-.048.5.5 0 0 0 .316-.948 3 3 0 0 0-2.167.077 3.1 3.1 0 0 0-.773.478q-.036.03-.07.064l-.002.001a.5.5 0 0 0 .707.708l-.001.002.001-.002a2 2 0 0 1 .122-.1 2 2 0 0 1 .41-.232Zm6.232 0a2 2 0 0 0-1.458-.048.5.5 0 1 1-.316-.948 3 3 0 0 1 2.168.077 3 3 0 0 1 .773.478l.07.064v.001a.5.5 0 0 1-.706.708l.002.002-.002-.002a2 2 0 0 0-.122-.1 2 2 0 0 0-.41-.232ZM8 10c-.998 0-1.747.623-2.247 1.246-.383.478.08 1.06.687.98q1.56-.202 3.12 0c.606.08 1.07-.502.687-.98C9.747 10.623 8.998 10 8 10" />
</svg>
</div>
<div class="text-center fs-3">Ой!</div>
<div class="text-center fs-5 ">Кажется, возникла проблема на нашей стороне, мы уже ее решаем.
Попробуйте зайти сюда позже.</div>
<div class="text-center my-3">
<button wire:click="back" class="btn btn-lg active border-2 rounded">Повторить</button>
</div>
@endif
</div>
@script @script
<script> <script>
eventCalllback = function(e) { eventCalllback = function (e) {
var el = e.target, var el = e.target,
clearVal = el.dataset.phoneClear, clearVal = el.dataset.phoneClear,
pattern = el.dataset.phonePattern, pattern = el.dataset.phonePattern,
matrix_def = "+7(___) ___-__-__", matrix_def = "+7(___) ___-__-__",
matrix = pattern ? pattern : matrix_def, matrix = pattern ? pattern : matrix_def,
i = 0, i = 0,
def = matrix.replace(/\D/g, ""), def = matrix.replace(/\D/g, ""),
val = e.target.value.replace(/\D/g, ""); val = e.target.value.replace(/\D/g, "");
if (clearVal !== 'false' && e.type === 'blur') { if (clearVal !== 'false' && e.type === 'blur') {
if (val.length < matrix.match(/([\_\d])/g).length) { if (val.length < matrix.match(/([\_\d])/g).length) {
e.target.value = ''; e.target.value = '';
return; return;
}
} }
if (def.length >= val.length) val = def;
e.target.value = matrix.replace(/./g, function(a) {
return /[_\d]/.test(a) && i < val.length ? val.charAt(i++) : i >= val.length ? "" :
a
});
} }
if (def.length >= val.length) val = def;
document.addEventListener('livewire:initialized', () => { e.target.value = matrix.replace(/./g, function (a) {
setPhonePatternToInput(); return /[_\d]/.test(a) && i < val.length ? val.charAt(i++) : i >= val.length ? "" :
}) a
$wire.on('phoneInputAdded', () => {
setInterval(() => {
setPhonePatternToInput()
}, 2000)
}); });
}
function setPhonePatternToInput() { document.addEventListener('livewire:initialized', () => {
var phone_inputs = document.querySelectorAll('[data-phone-pattern]'); setPhonePatternToInput();
for (let elem of phone_inputs) { })
for (let ev of ['input', 'blur', 'focus']) {
elem.addEventListener(ev, eventCalllback); $wire.on('phoneInputAdded', () => {
} setInterval(() => {
setPhonePatternToInput()
}, 2000)
});
function setPhonePatternToInput() {
var phone_inputs = document.querySelectorAll('[data-phone-pattern]');
for (let elem of phone_inputs) {
for (let ev of ['input', 'blur', 'focus']) {
elem.addEventListener(ev, eventCalllback);
} }
} }
</script> }
</script>
@endscript @endscript
</div> </div>

View File

@ -31,7 +31,7 @@ function AgentCompanyOfUser()
} }
if (!function_exists('GetAvailableAgents')) { if (!function_exists('GetAvailableAgents')) {
function GetAvailableAgents() function GetAvailableAgents($resultType = 'Collection')
{ {
$agents = false; $agents = false;
if ($adminCompany = AdminCompanyOfUser()) { if ($adminCompany = AdminCompanyOfUser()) {
@ -39,7 +39,7 @@ function GetAvailableAgents()
} else { } else {
$cityManager = CityManager::where('user_id', auth()->user()->id); $cityManager = CityManager::where('user_id', auth()->user()->id);
if ($cityManager->count()) { if ($cityManager->count()) {
$companies = Company::where('city_id', $cityManager->first()->city_id); $companies = Company::whereIn('city_id', $cityManager->pluck('city_id'));
if ($companies->count()) { if ($companies->count()) {
$agents = Agent::whereIn('company_id', $companies->get()->pluck('id')); $agents = Agent::whereIn('company_id', $companies->get()->pluck('id'));
} }
@ -48,11 +48,15 @@ function GetAvailableAgents()
} }
} }
if ($agents === false) { if ($agents === false) {
return []; $agents = Agent::where('id', 0);
} }
$agents->with('company:id,name'); $agents->with('company:id,name');
$agents->with('user:id,name'); $agents->with('user:id,name');
return $agents->get(); if ($resultType == 'Collection') {
return $agents->get();
} else {
return $agents;
};
} }
} }

View File

@ -13,32 +13,20 @@ class AgentsTableController extends Controller
{ {
public function index(Request $request) public function index(Request $request)
{ {
$user = auth()->user(); $agents = Agent::where('company_id', GetAvailableAgents());
$admin = CompanyAdmin::where('user_id', $user->id); switch ($request->status) {
if ($admin->count()) case AgentStatus::DISMISSED:
{ $agents->whereNotNull('deleted_at');
$admin = $admin->first(); break;
$agents = Agent::where('company_id', $admin->company_id); default:
switch ( $request->status ) $agents->withTrashed();
{ }
case AgentStatus::DISMISSED:
$agents->whereNotNull('deleted_at'); return view('main::company.agents.table', [
break; //'agents' => $agents->get(),
default: 'status' => $request->status,
$agents->withTrashed(); 'cities' => City::all()
} ])->with('statuses', AgentStatus::class);
return view('main::company.agents.table', [
'agents' => $agents->get(),
'companyId' => $admin->company_id,
'status' => $request->status,
'cities' => City::all()
])->with('statuses', AgentStatus::class);
}
else
{
abort(code: 401);
return;
}
} }
} }

View File

@ -14,8 +14,9 @@
class CreateAgentController extends Controller class CreateAgentController extends Controller
{ {
public function __invoke(Request $request, Company $company) public function __invoke(Request $request)
{ {
$company = Company::findOrFail($request->company_id);
if ($request->user()->cannot('update', $company)) if ($request->user()->cannot('update', $company))
{ {
abort(403, 'Unauthorized action'); abort(403, 'Unauthorized action');

View File

@ -9,15 +9,19 @@
class CreateAgentLivewire extends Component class CreateAgentLivewire extends Component
{ {
public $availableCompanies;
public $companyId; public $companyId;
public $containerId; public $containerId;
public function mount($containerId = 'createAgentModal', $companyId) public function mount($containerId = 'createAgentModal')
{ {
$this->companyId = $companyId;
$this->containerId = $containerId; $this->containerId = $containerId;
$availableCompaniesIds = GetAvailableAgents('Builder')->pluck('company_id');
$this->availableCompanies = Company::whereIn('id', $availableCompaniesIds)->get();
if ($this->availableCompanies->count() == 1) {
$this->companyId = $this->availableCompanies->first()->id;
};
} }
public function render() public function render()
{ {
return view('main::agent.livewire.create', [ return view('main::agent.livewire.create', [

View File

@ -13,8 +13,6 @@
Route::get('/main', [MainController::class, 'index']); Route::get('/main', [MainController::class, 'index']);
Route::get('/company/confirmer', function () Route::get('/company/confirmer', function ()
{ {
return view(view: 'company.post_confirmer'); return view(view: 'company.post_confirmer');
@ -26,7 +24,7 @@
Route::post('/company/{company}/details/', [Modules\Main\Http\Controllers\Company\DetailsController::class, 'store'])->name('company.details.store'); Route::post('/company/{company}/details/', [Modules\Main\Http\Controllers\Company\DetailsController::class, 'store'])->name('company.details.store');
Route::get('/agents/table', [Modules\Main\Http\Controllers\Company\AgentsTableController::class, 'index'])->name('company.agents.table'); Route::get('/agents/table', [Modules\Main\Http\Controllers\Company\AgentsTableController::class, 'index'])->name('company.agents.table');
//Route::post('/company/agents/store/', Modules\Main\Http\Controllers\Company\CreateAgentController::class)->name('company.agents.store'); //Route::post('/company/agents/store/', Modules\Main\Http\Controllers\Company\CreateAgentController::class)->name('company.agents.store');
Route::post('/companies/{company?}/agents/store/', Modules\Main\Http\Controllers\Company\CreateAgentController::class)->name('company.agents.store'); Route::post('/companies/agents/store/', Modules\Main\Http\Controllers\Company\CreateAgentController::class)->name('company.agents.store');
Route::post('/company/agents/{agent}/password/reset/', Modules\Main\Http\Controllers\Company\ResetAgentPasswordController::class)->name('company.agent.password.reset'); Route::post('/company/agents/{agent}/password/reset/', Modules\Main\Http\Controllers\Company\ResetAgentPasswordController::class)->name('company.agent.password.reset');
Route::get('/company/agents/{agent}/delete', Modules\Main\Http\Controllers\Company\DeleteAgentController::class)->name('company.agents.delete'); Route::get('/company/agents/{agent}/delete', Modules\Main\Http\Controllers\Company\DeleteAgentController::class)->name('company.agents.delete');
Route::get('/company/agents/{agent}/restore', Modules\Main\Http\Controllers\Company\RestoreAgentController::class)->name('company.agents.restore'); Route::get('/company/agents/{agent}/restore', Modules\Main\Http\Controllers\Company\RestoreAgentController::class)->name('company.agents.restore');

View File

@ -2,41 +2,66 @@
<div class="modal fade" id="{{ $containerId }}" tabindex="-1" aria-labelledby="createAgentModalLabel" <div class="modal fade" id="{{ $containerId }}" tabindex="-1" aria-labelledby="createAgentModalLabel"
aria-hidden="true"> aria-hidden="true">
<div class="modal-dialog modal-dialog-centered"> <div class="modal-dialog modal-dialog-centered">
<form class="modal-content" action="{{ route('company.agents.store', ['company' => $companyId]) }}" <form class="modal-content" action="{{ route('company.agents.store') }}" method="post">
method="post">
<div class="modal-header"> <div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">Новый агент</h1> <h1 class="modal-title fs-5" id="exampleModalLabel">Новый агент</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div> </div>
<div class="modal-body"> @if($availableCompanies->count() == 0)
@csrf <div class="modal-body">
<div class="mb-3"> Нет доступных агентств для продолжения работы
<label for="agentName" class="form-label">Полное имя (ФИО)</label>
<input type="text" class="form-control" id="agentName" name="name">
</div> </div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">ОК</button>
</div>
@else
<div class="modal-body">
@csrf
@if($availableCompanies->count() > 1)
<div class="mb-3">
<label for="companyId" class="form-label">Агентство</label>
<select wire:model="companyId" class="form-select @error('companyId') is-invalid @enderror"
id="companyId" name="company_id" aria-label="Агентство">
<option selected></option>
@foreach ($availableCompanies as $company)
<option value="{{ $company['id'] }}">
{{ $company['name'] }}
</option>
@endforeach
</select>
</div>
@elseif($availableCompanies->count() == 1)
<input type="hidden" class="form-control" id="company_id" name="company_id"
value="{{ $companyId }}">
@endif
<div class="mb-3">
<label for="agentName" class="form-label">Полное имя (ФИО)</label>
<input type="text" class="form-control" id="agentName" name="name">
</div>
<div class="mb-3"> <div class="mb-3">
<label for="agentEmail" class="form-label">Электронная почта</label> <label for="agentEmail" class="form-label">Электронная почта</label>
<input type="text" class="form-control" id="agentEmail" name="email"> <input type="text" class="form-control" id="agentEmail" name="email">
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="agentPhone" class="form-label">Телефон</label> <label for="agentPhone" class="form-label">Телефон</label>
<input type="text" class="form-control" id="agentPhone" name="phone"> <input type="text" class="form-control" id="agentPhone" name="phone">
</div> </div>
<div class="mb-3 form-check form-switch"> <div class="mb-3 form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="sendEmailSwitch" <input class="form-check-input" type="checkbox" role="switch" id="sendEmailSwitch"
name="sendToEmail" checked> name="sendToEmail" checked>
<label class="form-check-label" for="sendEmailSwitch">Отправить учетные данные на электронную <label class="form-check-label" for="sendEmailSwitch">Отправить учетные данные на электронную
почту</label> почту</label>
</div>
</div> </div>
</div> <div class="modal-footer">
<div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Отмена</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Отмена</button> <input type="submit" class="btn btn-primary" value="Добавить">
<input type="submit" class="btn btn-primary" value="Добавить"> </div>
</div> @endif
</form> </form>
</div> </div>
</div> </div>
</div> </div>

View File

@ -38,5 +38,5 @@
</div> </div>
@endif @endif
</div> </div>
@livewire('company.agent.create', ['containerId' => 'createAgentModal', 'companyId' => $companyId]) @livewire('company.agent.create', ['containerId' => 'createAgentModal'])
@endsection @endsection

View File

@ -40,8 +40,8 @@ class="list-group-item list-group-item-action p-3 bg-white rounded border border
</div> </div>
</div> </div>
<div class="col-12 col-lg-6"> <div class="col-12 col-lg-6">
<div class="p-2 px-sm-4 py-sm-3 bg-primary border rounded-3 mx-auto h-100" style="min-height:30em;"> <div class="p-2 px-sm-4 py-sm-3 bg-primary border rounded-3 mx-auto h-100" style="">
<div class="h4 pb-2 mb-2 fw-bold "> <div class="h4 pb-2 mb-2 fw-bold d-flex flex-column">
<small>Добавить клиента</small> <small>Добавить клиента</small>
</div> </div>
<livewire:ClientCreator /> <livewire:ClientCreator />