diff --git a/app/Http/Controllers/Company/CreateCompanyController.php b/app/Http/Controllers/Company/CreateCompanyController.php index c7d024e..cc16dc0 100644 --- a/app/Http/Controllers/Company/CreateCompanyController.php +++ b/app/Http/Controllers/Company/CreateCompanyController.php @@ -31,7 +31,6 @@ public function __invoke(Request $request) 'secret' => bin2hex(random_bytes(16)), 'status' => 'new' ]); - //dd($request->all()); $data = $request->only('name', 'email', 'inn', 'legal_address', 'secret', 'status', 'type', 'phone'); $company = Company::create($data); if (!$company) diff --git a/app/Livewire/CreateClientForm.php b/app/Livewire/CreateClientForm.php index 0fda970..8efdfae 100644 --- a/app/Livewire/CreateClientForm.php +++ b/app/Livewire/CreateClientForm.php @@ -9,6 +9,7 @@ use App\Models\Complex; use App\Models\Agent\Agent; use App\Models\Bitrix\SendClient; +use App\Models\Company\CompanyAdmin; class CreateClientForm extends Component @@ -21,6 +22,7 @@ class CreateClientForm extends Component public $complexes; public $status; public $result; + public $agent; protected $messages = [ 'client.firstName.required' => 'Необходимо указать имя клиента', 'client.secondName.required' => 'Необходимо указать фамилию клиента', @@ -47,6 +49,7 @@ public function mount() 'complexId' => '' ]; $this->status = self::NEW; + $this->agent = false; } public function update() { @@ -96,7 +99,18 @@ public function render() { $this->status = self::READY; } - return view('livewire.create-client-form'); + $data = []; + if ($adminAccount = CompanyAdmin::where('user_id', auth()->user()->id)->first()) + { + $data = [ + 'adminAccount' => $adminAccount, + 'agents' => Agent::where('company_id', $adminAccount->company_id)->get() + ]; + } + return view( + 'livewire.create-client-form', + $data + ); } public function resetData() { @@ -109,7 +123,7 @@ public function back() public function save() { $validated = $this->validate($this->rules()); - $agent = Agent::where('user_id', auth()->user()->id)->first(); + $agent = $this->agent || Agent::where('user_id', auth()->user()->id)->first()->id; $phone = '+7' . $this->client['phone']; $newUser = User::updateOrCreate( ['phone' => $phone], @@ -119,7 +133,7 @@ public function save() ] ); $data = [ - 'agent_id' => $agent->id + 'agent_id' => $agent , 'client_id' => $newUser->id , @@ -129,7 +143,7 @@ public function save() if ($newDeal = Deal::create($data)) { - if ($bitrixId = $this->sendToBitrix($newDeal->id)) + if ($bitrixId = $this->sendToBitrix($newDeal)) { $newDeal->bitrix_id = $bitrixId; $newDeal->status = DealStatus::MODERATION; @@ -144,10 +158,11 @@ public function save() } return $this->status = self::ERROR; } - public function sendToBitrix($id) + public function sendToBitrix(Deal $deal) { - $user = auth()->user(); - $agent = Agent::where('user_id', $user->id)->first(); + //$user = auth()->user(); + //$agent = Agent::where(column: 'user_id', $user->id)->first(); + $agent = $deal->agent; $agentName = $agent->user->getPartialsName(); $data = [ 'CLIENT_FIRST_NAME' => $this->client['firstName'], @@ -160,7 +175,7 @@ public function sendToBitrix($id) 'OBJECT_NAME' => Complex::find($this->client['complexId'])->name, 'CALLBACK_URL' => route('deal.confirm', ['hash' => $this->client['confirmToken']]), ]; - $sender = new SendClient($id, $data); + $sender = new SendClient($deal->id, $data); $response = $sender->send(); if ($response) { diff --git a/resources/views/clients/table.blade.php b/resources/views/clients/table.blade.php index 05611a7..8a622eb 100644 --- a/resources/views/clients/table.blade.php +++ b/resources/views/clients/table.blade.php @@ -2,7 +2,7 @@ @section('content')
-
+
@@ -28,7 +28,7 @@
diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 5a544d4..5149d76 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -83,7 +83,7 @@
@include('left-panel')
-
+
@yield('content')
diff --git a/resources/views/left-panel.blade.php b/resources/views/left-panel.blade.php index 43d3d2b..373826a 100644 --- a/resources/views/left-panel.blade.php +++ b/resources/views/left-panel.blade.php @@ -2,7 +2,7 @@
+ + @if($adminAccount) +
+ + + @error('agent') + + {{ $message }} + + @enderror +
+ @endif + @if ($status == self::READY && !$errors->any())