From c5f369e2a57595fb1b41444f0e0cdca8bac87c7f Mon Sep 17 00:00:00 2001 From: Thekindbull Date: Wed, 18 Jun 2025 17:12:19 +0800 Subject: [PATCH] clients form updated for second contact --- .../Bitrix/ContractApiController.php | 5 +- .../Controllers/ClientsTableController.php | 25 +- .../Controllers/Deal/ContractController.php | 15 +- .../NotificationProbeController.php | 3 - app/Livewire/CreateClientForm.php | 53 ++--- app/Models/Deal/Deal.php | 2 +- app/Modules/Contracts/Config/config.php | 5 + ...25_06_18_020419_create_contracts_table.php | 27 +++ .../Http/Controllers/ContractsController.php | 17 ++ app/Modules/Contracts/Models/Contract.php | 35 +++ .../Contracts/Models/ContractStatus.php | 11 + .../Providers/ModuleServiceProvider.php | 68 ++++++ .../Providers/RouteServiceProvider.php | 24 ++ app/Modules/Contracts/Routes/web.php | 13 ++ app/Modules/Contracts/Views/index.blade.php | 4 + app/Notifications/ContractUpdated.php | 2 +- resources/views/clients/table.blade.php | 22 +- .../livewire/create-client-form.blade.php | 214 +++++++++++++----- resources/views/livewire/main-menu.blade.php | 7 + 19 files changed, 415 insertions(+), 137 deletions(-) create mode 100644 app/Modules/Contracts/Config/config.php create mode 100644 app/Modules/Contracts/Database/Migrations/2025_06_18_020419_create_contracts_table.php create mode 100644 app/Modules/Contracts/Http/Controllers/ContractsController.php create mode 100644 app/Modules/Contracts/Models/Contract.php create mode 100644 app/Modules/Contracts/Models/ContractStatus.php create mode 100644 app/Modules/Contracts/Providers/ModuleServiceProvider.php create mode 100644 app/Modules/Contracts/Providers/RouteServiceProvider.php create mode 100644 app/Modules/Contracts/Routes/web.php create mode 100644 app/Modules/Contracts/Views/index.blade.php diff --git a/app/Http/Controllers/Bitrix/ContractApiController.php b/app/Http/Controllers/Bitrix/ContractApiController.php index 5b99ccc..2f50964 100644 --- a/app/Http/Controllers/Bitrix/ContractApiController.php +++ b/app/Http/Controllers/Bitrix/ContractApiController.php @@ -6,9 +6,8 @@ use Illuminate\Http\Request; use App\Models\Deal\Deal; -use App\Models\Deal\Contract; -use App\Models\Deal\ContractStatus; -use App\Models\Agent\Agent; +use Modules\Contracts\Models\Contract; +use Modules\Contracts\Models\ContractStatus; use App\Notifications\ContractUpdated; class ContractApiController { diff --git a/app/Http/Controllers/ClientsTableController.php b/app/Http/Controllers/ClientsTableController.php index 2cb07b9..ea299fb 100644 --- a/app/Http/Controllers/ClientsTableController.php +++ b/app/Http/Controllers/ClientsTableController.php @@ -5,18 +5,13 @@ use Illuminate\Http\Request; use App\Models\Deal\Deal; -use App\Models\Agent\Agent; use App\Models\Company\CompanyAdmin; - use App\Models\City; -use App\Models\Deal\ContractStatus; - - class ClientsTableController extends Controller - { +{ public function index(Request $request) - { + { return view( 'clients.table', [ @@ -25,28 +20,28 @@ public function index(Request $request) ] ); - } + } public function getAllDealsInCompany(Request $request) - { + { $user = auth()->user(); if (!$admin = CompanyAdmin::where('user_id', $user->id)->first()) - { + { abort(401); - } + } $deals = Deal::whereIn('agent_id', function ($query) use ($admin) - { + { $query->select('id'); $query->from('agents'); $query->where('company_id', $admin->company_id); - })->get(); + })->get(); return view( 'clients.table', [ - 'deals' => $deals, + 'deals' => $deals, 'status' => $request->status, 'cities' => City::all() ] ); - } } +} diff --git a/app/Http/Controllers/Deal/ContractController.php b/app/Http/Controllers/Deal/ContractController.php index 19f073a..6e2f916 100644 --- a/app/Http/Controllers/Deal/ContractController.php +++ b/app/Http/Controllers/Deal/ContractController.php @@ -5,15 +5,12 @@ use App\Http\Controllers\Controller; use Illuminate\Http\Request; -use App\Models\Deal\Deal; -use App\Models\Deal\Contract; -use App\Models\Deal\ContractStatus; -use App\Models\Agent\Agent; +use Modules\Contracts\Models\Contract; class ContractController extends Controller - { +{ public function index(Contract $contract) - { + { return view( 'clients.contract.index', [ @@ -21,10 +18,10 @@ public function index(Contract $contract) ] ); - } + } public function getAllDealsInCompany(Request $request) - { + { $user = auth()->user(); - } } +} diff --git a/app/Http/Controllers/NotificationProbeController.php b/app/Http/Controllers/NotificationProbeController.php index eaca7e3..db65b34 100644 --- a/app/Http/Controllers/NotificationProbeController.php +++ b/app/Http/Controllers/NotificationProbeController.php @@ -5,9 +5,6 @@ use Illuminate\Http\Request; use App\Models\Deal\Deal; -use App\Notifications\UniqueContact; -use App\Notifications\NotUniqueContact; -use App\Notifications\ContractUpdated; use App\Notifications\Deal\DealCreated; diff --git a/app/Livewire/CreateClientForm.php b/app/Livewire/CreateClientForm.php index 64bb99f..0bc1e11 100644 --- a/app/Livewire/CreateClientForm.php +++ b/app/Livewire/CreateClientForm.php @@ -19,6 +19,7 @@ class CreateClientForm extends Component const SUCCESS = 3; const READY = 4; public $client; + public $clientSecondary; public $complexes; public $status; public $result; @@ -26,8 +27,8 @@ class CreateClientForm extends Component protected $messages = [ 'client.firstName.required' => 'Необходимо указать имя клиента', 'client.secondName.required' => 'Необходимо указать фамилию клиента', - 'client.phone.required' => 'Необходимо указать телефон без кода страны "+7" или "8"', - 'client.phone.regex' => 'Телефон должен содержать 10 симвлов без указания кода страны "+7" или "8"', + 'client.phone.required' => 'Необходимо указать телефон', + 'client.phone.regex' => 'Телефон должен быть в международном формате', 'client.phone.unique' => 'Клиент с таким телефоном уже существует', 'agent.integer' => 'Необходимо указать агента, от которого добавляется контакт' ]; @@ -37,9 +38,9 @@ protected function rules() 'agent' => ['required', 'integer'], 'client.firstName' => ['required', 'string', 'max:255'], 'client.secondName' => ['required', 'string', 'max:255'], - //'client.phone' => ['required', 'string', 'regex:/^(\+7)([0-9]{3})([-]{1})([0-9]{3})([-]{1})([0-9]{4})/i'] + 'client.phone' => ['required', 'string', 'regex:/^(\+7)([0-9]{3})([-]{1})([0-9]{3})([-]{1})([0-9]{4})/i'] //'client.phone' => ['required', 'string', 'regex:/^\+7 \d{3} \d{3}-\d{2}-\d{2}$/'], - 'client.phone' => ['required', 'string'] + //'client.phone' => ['required', 'string'] ]; } public function mount() @@ -68,6 +69,7 @@ public function mount() $this->complexes = Complex::where('city_id', $admin->company_id)->get(); } } + $this->clientSecondary = false; } public function update() { @@ -76,33 +78,21 @@ public function update() public function updated($propertyName) { $this->status = self::NEW; - /*if ($propertyName == 'client.phone') - { - //$this->dispatch('phone-updated', ['newPhone' => 111]); - //$this->js("checkPhoneFormat('123')"); - $phone = preg_replace('/[^0-9\+]+/', "", $this->client['phone']); - if (strlen($this->client['phone']) <= 2) - { - $this->client['phone'] = "+7"; - } - elseif (strlen($phone) <= 12) - { - $code = substr($phone, 0, 2); - $sArea = substr($phone, 2, 3); - $sPrefix = substr($phone, 5, 3); - $sNumber1 = substr($phone, 8, 2); - $sNumber2 = substr($phone, 10, 2); - - $phone = $code . " " . $sArea . " " . $sPrefix . "-" . $sNumber1 . "-" . $sNumber2; - $this->client['phone'] = $phone; - } - else - { - $this->client['phone'] = $phone; - } - }*/ $this->validateOnly($propertyName); } + public function getClientSecondary() + { + $this->clientSecondary = [ + 'firstName' => '', + 'secondName' => '', + 'phone' => '', + 'complexId' => '' + ]; + } + public function deleteClientSecondary() + { + $this->clientSecondary = false; + } public function render() { if ( @@ -141,12 +131,11 @@ public function back() public function save() { $validated = $this->validate($this->rules()); - $phone = '+7' . $this->client['phone']; $newUser = User::updateOrCreate( - ['phone' => $phone], + ['phone' => $this->client['phone']], [ 'name' => trim($this->client['firstName'] . ' ' . $this->client['secondName']), - 'phone' => $phone + 'phone' => $this->client['phone'] ] ); $data = [ diff --git a/app/Models/Deal/Deal.php b/app/Models/Deal/Deal.php index 083e377..ea690c4 100644 --- a/app/Models/Deal/Deal.php +++ b/app/Models/Deal/Deal.php @@ -7,7 +7,7 @@ use App\Models\User\UserRole; use App\Models\User\Role; - +use Modules\Contracts\Models\Contract; use Illuminate\Notifications\Notifiable; class Deal extends Model diff --git a/app/Modules/Contracts/Config/config.php b/app/Modules/Contracts/Config/config.php new file mode 100644 index 0000000..ce09543 --- /dev/null +++ b/app/Modules/Contracts/Config/config.php @@ -0,0 +1,5 @@ +id(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('contracts'); + } +}; diff --git a/app/Modules/Contracts/Http/Controllers/ContractsController.php b/app/Modules/Contracts/Http/Controllers/ContractsController.php new file mode 100644 index 0000000..0dd602b --- /dev/null +++ b/app/Modules/Contracts/Http/Controllers/ContractsController.php @@ -0,0 +1,17 @@ +belongsTo(Deal::class, 'deal_id'); + } +} \ No newline at end of file diff --git a/app/Modules/Contracts/Models/ContractStatus.php b/app/Modules/Contracts/Models/ContractStatus.php new file mode 100644 index 0000000..e205c94 --- /dev/null +++ b/app/Modules/Contracts/Models/ContractStatus.php @@ -0,0 +1,11 @@ +app->register(RouteServiceProvider::class); + } + + public function boot() + { + $this->registerViews(); + $this->registerLivewireViews(); + $this->registerMigrations(); + $this->registerConfig(); + $this->registerComponent(); + $this->registerLivewire(); + } + + protected function registerViews() + { + $moduleViewsPath = __DIR__.'/../Views'; + $this->loadViewsFrom( + $moduleViewsPath, strtolower($this->moduleName) + ); + } + + protected function registerLivewireViews() + { + $moduleViewsPath = __DIR__.'/../Views/livewire'; + $this->loadViewsFrom( + $moduleViewsPath, strtolower($this->moduleName) + ); + } + + protected function registerMigrations() + { + $this->loadMigrationsFrom( + app_path('Modules/'.$this->moduleName.'/Database/Migrations') + ); + } + + protected function registerConfig() + { + $path = app_path('Modules/'.$this->moduleName.'/Config/config.php'); + $this->mergeConfigFrom( + $path, strtolower($this->moduleName) + ); + } + + protected function registerLivewire() + { + //Livewire::component('', \Modules\\Http\Livewire\::class); + } + + protected function registerComponent() + { + //Blade::component('', \Modules\\Http\Components\::class); + } +} \ No newline at end of file diff --git a/app/Modules/Contracts/Providers/RouteServiceProvider.php b/app/Modules/Contracts/Providers/RouteServiceProvider.php new file mode 100644 index 0000000..6f69b87 --- /dev/null +++ b/app/Modules/Contracts/Providers/RouteServiceProvider.php @@ -0,0 +1,24 @@ +registerWebRoutes(); + } + + protected function registerWebRoutes() + { + //Add Web Routes with web Guard + Route::middleware('web') + //Set Default Controllers Namespace + ->namespace('Modules\\Contract\\Http\\Controllers') + ->group(app_path('Modules/Contract/Routes/web.php')); + } +} \ No newline at end of file diff --git a/app/Modules/Contracts/Routes/web.php b/app/Modules/Contracts/Routes/web.php new file mode 100644 index 0000000..2eb49f0 --- /dev/null +++ b/app/Modules/Contracts/Routes/web.php @@ -0,0 +1,13 @@ +group(function() { + + Route::get('/contract', [ContractsController::class, 'index']); + + Route::middleware(['hasAccess'])->group(function() { + /** Routes that need to be protected - Маршруты которые нужно защитить */ + }); +}); \ No newline at end of file diff --git a/app/Modules/Contracts/Views/index.blade.php b/app/Modules/Contracts/Views/index.blade.php new file mode 100644 index 0000000..f8198cf --- /dev/null +++ b/app/Modules/Contracts/Views/index.blade.php @@ -0,0 +1,4 @@ +@extends('layouts.app') + @section('content') +

Example views

+ @endsection \ No newline at end of file diff --git a/app/Notifications/ContractUpdated.php b/app/Notifications/ContractUpdated.php index cbdb740..169df0b 100644 --- a/app/Notifications/ContractUpdated.php +++ b/app/Notifications/ContractUpdated.php @@ -7,7 +7,7 @@ use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -use App\Models\Deal\Contract; +use Modules\Contracts\Models\Contract; use App\Models\Deal\DealStatus; class ContractUpdated extends Notification diff --git a/resources/views/clients/table.blade.php b/resources/views/clients/table.blade.php index 385adf4..f12c377 100644 --- a/resources/views/clients/table.blade.php +++ b/resources/views/clients/table.blade.php @@ -17,15 +17,15 @@ +
- -
-
+ + + --> diff --git a/resources/views/livewire/create-client-form.blade.php b/resources/views/livewire/create-client-form.blade.php index 6afa4c0..f80b651 100644 --- a/resources/views/livewire/create-client-form.blade.php +++ b/resources/views/livewire/create-client-form.blade.php @@ -9,54 +9,140 @@
Добавить клиента
-
-
-
- - - @error('client.firstName') - - {{ $message }} - - @enderror -
-
-
-
- - - @error('client.secondName') - - {{ $message }} - - @enderror -
+
+
+
+
+
+ + + @error('client.firstName') + + {{ $message }} + + @enderror +
+
+
+
+ + + @error('client.secondName') + + {{ $message }} + + @enderror +
-
-
-
-
-
- - - @error('client.phone') - - {{ $message }} - - @enderror +
+
+
+
+
+ + + @error('client.phone') + + {{ $message }} + + @enderror +
+ @if ($clientSecondary == false) + + + + + + + @endif +
+ @if ($clientSecondary) +
+
+
СУПРУГ / СУПРУГА
+ +
+
+
+
+
+ + + @error('clientSecondary.firstName') + + {{ $message }} + + @enderror +
+
+
+
+ + + @error('clientSecondary.secondName') + + {{ $message }} + + @enderror +
+ +
+
+
+
+
+ + + @error('clientSecondary.phone') + + {{ $message }} + + @enderror +
+
+
+
+
+ @endif