diff --git a/app/Livewire/AgentsTable.php b/app/Livewire/AgentsTable.php index 92023df..7b81517 100644 --- a/app/Livewire/AgentsTable.php +++ b/app/Livewire/AgentsTable.php @@ -20,9 +20,8 @@ public function mount($status = null) } public function render() { - $user = auth()->user(); - $admin = CompanyAdmin::where('user_id', $user->id)->first(); - $agents = Agent::where('company_id', $admin->company_id); + + $agents = GetAvailableAgents('Builder'); if ($this->status == AgentStatus::DISMISSED) { $agents->onlyTrashed(); diff --git a/app/Modules/ClientCreateForm/Views/livewire/form.blade.php b/app/Modules/ClientCreateForm/Views/livewire/form.blade.php index 4d06092..5e89c27 100644 --- a/app/Modules/ClientCreateForm/Views/livewire/form.blade.php +++ b/app/Modules/ClientCreateForm/Views/livewire/form.blade.php @@ -1,272 +1,284 @@ -
+
Загрузка формы...
-
- @if ($status == FormStatus::NEW || $status == FormStatus::IN_PROCESS || $status == FormStatus::READY) - -
-
-
-
-
- - - @error('contacts.' . $currentContactIndex . '.firstName') - - {{ $message }} - - @enderror -
-
-
-
- - - @error('contacts.' . $currentContactIndex . '.secondName') - - {{ $message }} - - @enderror -
+ @if(!$availableAgents) +
+
+ + + +
+
+ Вы пока не можете добавлять контакты и сделки +
+
+ @endif -
- @foreach ($contacts[$currentContactIndex]['phones'] as $phoneKey => $phone) -
-
- - - - @error('contacts.' . $currentContactIndex . '.phones.' . $phoneKey) - + @if($availableAgents && $complexes) +
+ @if ($status == FormStatus::NEW || $status == FormStatus::IN_PROCESS || $status == FormStatus::READY) + +
+
+
+
+
+ + + @error('contacts.' . $currentContactIndex . '.firstName') + {{ $message }} @enderror
- @if (count($contacts[$currentContactIndex]['phones']) == $phoneKey + 1 && - count($contacts[$currentContactIndex]['phones']) < $this->maxContactPhonesCount) - - - - - - +
+
+
+ + + @error('contacts.' . $currentContactIndex . '.secondName') + + {{ $message }} + + @enderror +
+ +
+ @foreach ($contacts[$currentContactIndex]['phones'] as $phoneKey => $phone) +
+
+ + + + @error('contacts.' . $currentContactIndex . '.phones.' . $phoneKey) + + {{ $message }} + + @enderror +
+ @if ( + count($contacts[$currentContactIndex]['phones']) == $phoneKey + 1 && + count($contacts[$currentContactIndex]['phones']) < $this->maxContactPhonesCount + ) + + + + + + + @endif +
+ @endforeach +
+ @if ($currentContactIndex == 0 && count($contacts) <= 2) +
+ + +
+ @endif + @if ($currentContactIndex > 0) + @endif
- @endforeach -
- @if ($currentContactIndex == 0 && count($contacts) <= 2) -
- - -
- @endif - @if ($currentContactIndex > 0) - - @endif
-
- -
- - - @error('complexId') - - {{ $message }} - - @enderror -
- @if (count($availableAgents) > 1)
- - @foreach ($availableAgents as $agent) - @endforeach - - @error('agentId') - + + @error('complexId') + {{ $message }} @enderror
+ @if (count($availableAgents) > 1) + +
+ + + @error('agentId') + + {{ $message }} + + @enderror +
+ @endif + + @if ($status != FormStatus::READY) +
+ +
+ @else +
+ +
+ @endif @endif - @if ($status != FormStatus::READY) -
- + @if ($status == FormStatus::SUCCESS) +
+ + + +
- @else -
- + +
Клиент добавлен
+
Мы проверим его уникальность и направим Вам информацию в личном + кабинете
+
+
@endif - @endif - @if ($status == FormStatus::SUCCESS) -
- - - - -
+ @if ($status == FormStatus::ERROR) +
+ + + + +
-
Клиент добавлен
-
Мы проверим его уникальность и направим Вам информацию в личном - кабинете
-
- -
- @endif - - @if ($status == FormStatus::ERROR) -
- - - - -
- -
Ой!
-
Кажется, возникла проблема на нашей стороне, мы уже ее решаем. - Попробуйте зайти сюда позже.
-
- -
- @endif -
+
Ой!
+
Кажется, возникла проблема на нашей стороне, мы уже ее решаем. + Попробуйте зайти сюда позже.
+
+ +
+ @endif +
+ @endif @script - + } + @endscript -
+
\ No newline at end of file diff --git a/app/Modules/Main/Helpers/helper.php b/app/Modules/Main/Helpers/helper.php index 93ae836..77a46ba 100644 --- a/app/Modules/Main/Helpers/helper.php +++ b/app/Modules/Main/Helpers/helper.php @@ -31,7 +31,7 @@ function AgentCompanyOfUser() } if (!function_exists('GetAvailableAgents')) { - function GetAvailableAgents() + function GetAvailableAgents($resultType = 'Collection') { $agents = false; if ($adminCompany = AdminCompanyOfUser()) { @@ -39,7 +39,7 @@ function GetAvailableAgents() } else { $cityManager = CityManager::where('user_id', auth()->user()->id); if ($cityManager->count()) { - $companies = Company::where('city_id', $cityManager->first()->city_id); + $companies = Company::whereIn('city_id', $cityManager->pluck('city_id')); if ($companies->count()) { $agents = Agent::whereIn('company_id', $companies->get()->pluck('id')); } @@ -48,11 +48,15 @@ function GetAvailableAgents() } } if ($agents === false) { - return []; + $agents = Agent::where('id', 0); } $agents->with('company:id,name'); $agents->with('user:id,name'); - return $agents->get(); + if ($resultType == 'Collection') { + return $agents->get(); + } else { + return $agents; + }; } } diff --git a/app/Modules/Main/Http/Controllers/Company/AgentsTableController.php b/app/Modules/Main/Http/Controllers/Company/AgentsTableController.php index b32f4fd..c230070 100644 --- a/app/Modules/Main/Http/Controllers/Company/AgentsTableController.php +++ b/app/Modules/Main/Http/Controllers/Company/AgentsTableController.php @@ -13,32 +13,20 @@ class AgentsTableController extends Controller { public function index(Request $request) { - $user = auth()->user(); - $admin = CompanyAdmin::where('user_id', $user->id); - if ($admin->count()) - { - $admin = $admin->first(); - $agents = Agent::where('company_id', $admin->company_id); - switch ( $request->status ) - { - case AgentStatus::DISMISSED: - $agents->whereNotNull('deleted_at'); - break; - default: - $agents->withTrashed(); - } + $agents = Agent::where('company_id', GetAvailableAgents()); + switch ($request->status) { + case AgentStatus::DISMISSED: + $agents->whereNotNull('deleted_at'); + break; + default: + $agents->withTrashed(); + } + + return view('main::company.agents.table', [ + //'agents' => $agents->get(), + 'status' => $request->status, + '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; - } } } diff --git a/app/Modules/Main/Http/Controllers/Company/CreateAgentController.php b/app/Modules/Main/Http/Controllers/Company/CreateAgentController.php index 3e0db4a..661be36 100644 --- a/app/Modules/Main/Http/Controllers/Company/CreateAgentController.php +++ b/app/Modules/Main/Http/Controllers/Company/CreateAgentController.php @@ -14,8 +14,9 @@ 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)) { abort(403, 'Unauthorized action'); diff --git a/app/Modules/Main/Http/Livewire/CreateAgentLivewire.php b/app/Modules/Main/Http/Livewire/CreateAgentLivewire.php index 200b008..a8dd7ec 100644 --- a/app/Modules/Main/Http/Livewire/CreateAgentLivewire.php +++ b/app/Modules/Main/Http/Livewire/CreateAgentLivewire.php @@ -9,15 +9,19 @@ class CreateAgentLivewire extends Component { + public $availableCompanies; public $companyId; public $containerId; - public function mount($containerId = 'createAgentModal', $companyId) + public function mount($containerId = 'createAgentModal') { - $this->companyId = $companyId; $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() { return view('main::agent.livewire.create', [ diff --git a/app/Modules/Main/Routes/web.php b/app/Modules/Main/Routes/web.php index f277bfe..0ffc8ac 100644 --- a/app/Modules/Main/Routes/web.php +++ b/app/Modules/Main/Routes/web.php @@ -13,8 +13,6 @@ Route::get('/main', [MainController::class, 'index']); - - Route::get('/company/confirmer', function () { 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::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('/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::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'); diff --git a/app/Modules/Main/Views/agent/livewire/create.blade.php b/app/Modules/Main/Views/agent/livewire/create.blade.php index 9d23d3d..cb06a99 100644 --- a/app/Modules/Main/Views/agent/livewire/create.blade.php +++ b/app/Modules/Main/Views/agent/livewire/create.blade.php @@ -2,41 +2,66 @@ \ No newline at end of file diff --git a/app/Modules/Main/Views/company/agents/table.blade.php b/app/Modules/Main/Views/company/agents/table.blade.php index 0a95dcb..0689939 100644 --- a/app/Modules/Main/Views/company/agents/table.blade.php +++ b/app/Modules/Main/Views/company/agents/table.blade.php @@ -38,5 +38,5 @@
@endif
- @livewire('company.agent.create', ['containerId' => 'createAgentModal', 'companyId' => $companyId]) + @livewire('company.agent.create', ['containerId' => 'createAgentModal']) @endsection diff --git a/resources/views/user/dashboard.blade.php b/resources/views/user/dashboard.blade.php index b44e9bd..c9385a3 100644 --- a/resources/views/user/dashboard.blade.php +++ b/resources/views/user/dashboard.blade.php @@ -40,8 +40,8 @@ class="list-group-item list-group-item-action p-3 bg-white rounded border border
-
-
+
+
Добавить клиента