From 520e972ead3761aa6e96a6a5dcbc6f0f0d6f0372 Mon Sep 17 00:00:00 2001 From: Thekindbull Date: Tue, 10 Jun 2025 22:20:29 +0800 Subject: [PATCH] city field in company table added --- .../Company/CreateCompanyController.php | 31 +++--- .../Company/CreateCompanyFormController.php | 26 +++-- .../Controllers/Company/DetailsController.php | 2 +- app/Livewire/CreateClientForm.php | 9 +- app/Models/Company/Company.php | 3 +- app/Models/Company/Details.php | 101 +++++++++--------- app/Models/Deal/Contract.php | 14 ++- ...725_add_city_column_to_companies_table.php | 31 ++++++ ...6_add_new_requisites_to_contract_table.php | 33 ++++++ resources/views/company/create.blade.php | 81 +++++++++----- .../livewire/create-client-form.blade.php | 15 +-- 11 files changed, 224 insertions(+), 122 deletions(-) create mode 100644 database/migrations/2025_06_10_083725_add_city_column_to_companies_table.php create mode 100644 database/migrations/2025_06_10_095056_add_new_requisites_to_contract_table.php diff --git a/app/Http/Controllers/Company/CreateCompanyController.php b/app/Http/Controllers/Company/CreateCompanyController.php index 047db5c..4d05880 100644 --- a/app/Http/Controllers/Company/CreateCompanyController.php +++ b/app/Http/Controllers/Company/CreateCompanyController.php @@ -10,20 +10,21 @@ use App\Models\Company\CompanyType; use App\Models\Bitrix\SendCompany; class CreateCompanyController extends Controller - { +{ /** * Handle the incoming request. */ public function __invoke(Request $request) - { + { $request->enum('type', CompanyType::class); $validated = $request->validate([ - 'name' => 'required|max:255', - 'email' => 'required|email|unique:companies', - 'phone' => 'required', - 'inn' => 'required|unique:companies', + 'name' => 'required|max:255', + 'email' => 'required|email|unique:companies', + 'phone' => 'required', + 'inn' => 'required|unique:companies', 'legal_address' => 'required', - 'type' => Rule::enum(CompanyType::class) + 'type' => Rule::enum(CompanyType::class), + 'city_id' => 'required' ]); $request->request->add([ @@ -31,22 +32,24 @@ public function __invoke(Request $request) 'status' => 'new' ]); - $data = $request->only('name', 'email', 'inn', 'legal_address', 'secret', 'status', 'type', 'phone'); + $data = $request->only('name', 'email', 'inn', 'legal_address', 'secret', 'status', 'type', 'phone', 'city_id'); $company = Company::create($data); + if (!$company) - { + { return back()->withErrors(['msg' => 'Company creation error'])->withInput(); - } + } + $data['callback_url'] = route('company.status.update', [ 'company_id' => $company->id, - 'secret' => $company->secret + 'secret' => $company->secret ]); $companyConfirmByBitrix = new SendCompany($company->id, $data); if (!$sender = $companyConfirmByBitrix->send()) - { + { $company->delete(); return back()->withErrors(['msg' => 'Error with bitrix sender'])->withInput(); - } - return view('company.created'); } + return view('company.created'); } +} diff --git a/app/Http/Controllers/Company/CreateCompanyFormController.php b/app/Http/Controllers/Company/CreateCompanyFormController.php index 4536750..9043ae7 100644 --- a/app/Http/Controllers/Company/CreateCompanyFormController.php +++ b/app/Http/Controllers/Company/CreateCompanyFormController.php @@ -6,23 +6,33 @@ use Illuminate\Http\Request; use App\Models\Company\Company; use App\Models\Company\CompanyType; +use App\Models\City; class CreateCompanyFormController extends Controller - { +{ /** * Handle the incoming request. */ public function __invoke(Request $request) - { + { $type = false; + $city_id = false; if ($request->has('type')) - { + { $request->enum('type', CompanyType::class); $type = $request->type; - } - return view('company.create', [ - 'type' => $type, - 'typesList' => CompanyType::cases() - ]); } + ; + if ($request->has('city_id')) + { + $city_id = $request->city_id; + } + ; + return view('company.create', [ + 'type' => $type, + 'city_id' => $city_id, + 'typesList' => CompanyType::cases(), + 'citiesList' => City::all() + ]); } +} diff --git a/app/Http/Controllers/Company/DetailsController.php b/app/Http/Controllers/Company/DetailsController.php index 6f3e5ee..1eafae3 100644 --- a/app/Http/Controllers/Company/DetailsController.php +++ b/app/Http/Controllers/Company/DetailsController.php @@ -34,7 +34,7 @@ public function index($companyId = null) } $details = new Details($company); - $details = $details->details; + $details = $details->get(); if ($company->type == CompanyType::SelfEmployer || $company->type == CompanyType::SoleProperty) { return view('company.details.selfemp', [ diff --git a/app/Livewire/CreateClientForm.php b/app/Livewire/CreateClientForm.php index 0ddf6a2..2efb830 100644 --- a/app/Livewire/CreateClientForm.php +++ b/app/Livewire/CreateClientForm.php @@ -38,13 +38,14 @@ protected function rules() '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 \d{3} \d{3}-\d{2}-\d{2}$/'] + //'client.phone' => ['required', 'string', 'regex:/^\+7 \d{3} \d{3}-\d{2}-\d{2}$/'], + 'client.phone' => ['required', 'string'] ]; } public function mount() { $userBroker = Agent::where('user_id', auth()->user()->id)->first(); - $this->complexes = Complex::all(); + $this->complexes = Complex::where('city_id', $userBroker->company->city_id)->get(); $this->client = [ 'firstName' => '', 'secondName' => '', @@ -68,7 +69,7 @@ public function update() public function updated($propertyName) { $this->status = self::NEW; - if ($propertyName == 'client.phone') + /*if ($propertyName == 'client.phone') { //$this->dispatch('phone-updated', ['newPhone' => 111]); //$this->js("checkPhoneFormat('123')"); @@ -92,7 +93,7 @@ public function updated($propertyName) { $this->client['phone'] = $phone; } - } + }*/ $this->validateOnly($propertyName); } public function render() diff --git a/app/Models/Company/Company.php b/app/Models/Company/Company.php index 989417c..be96800 100644 --- a/app/Models/Company/Company.php +++ b/app/Models/Company/Company.php @@ -22,7 +22,8 @@ class Company extends Model 'legal_address', 'details', 'status', - 'secret' + 'secret', + 'city_id' ]; protected $casts = [ diff --git a/app/Models/Company/Details.php b/app/Models/Company/Details.php index 1fe7f86..1282ef5 100644 --- a/app/Models/Company/Details.php +++ b/app/Models/Company/Details.php @@ -7,81 +7,86 @@ use App\Models\Company\Company; class Details - { +{ use HasFactory; public $details; + private $company; public function __construct(Company $company) + { + $this->company = $company; + } + + public function get() + { + if (!$this->company->details) { - $company; - if (!$company->details) + if ($this->company->type == CompanyType::SelfEmployer) { - if ($company->type == CompanyType::SelfEmployer) - { - $company->details = $this->emptyForSelfEmp(); - $company->save(); - } - ; - if ($company->type == CompanyType::SoleProperty) - { - $company->details = $this->emptyForSelfEmp(); - $company->save(); - } - ; - if ($company->type == CompanyType::Agency) - { - $company->details = $this->emptyForAgency(); - $company->save(); - } + $this->company->details = $this->emptyForSelfEmp(); + $this->company->save(); + } + ; + if ($this->company->type == CompanyType::SoleProperty) + { + $this->company->details = $this->emptyForSelfEmp(); + $this->company->save(); + } + ; + if ($this->company->type == CompanyType::Agency) + { + $this->company->details = $this->emptyForAgency(); + $this->company->save(); } - $this->details = $company->details; } + return $this->details = $this->company->details; + } private function emptyForSelfEmp() - { + { $data = [ - 'user' => [ - 'firstName' => '', + 'user' => [ + 'firstName' => '', 'secondName' => '', - 'email' => '', - 'phone' => '' + 'email' => $this->company->email, + 'phone' => '' ], 'details' => [ - 'inn' => '', - 'snils' => '', - 'bank' => [ + 'inn' => $this->company->inn, + 'snils' => '', + 'bank' => [ 'name' => '', - 'bik' => '', - 'cur' => '', + 'bik' => '', + 'cur' => '', 'pers' => '' ], - 'address' => '', - 'legal_address' => '' + 'address' => $this->company->address, + 'legal_address' => $this->company->legal_address ] ]; return $data; - } + } private function emptyForAgency() - { + { $data = [ - 'name' => '', + 'name' => $this->company->name, 'fullName' => '', - 'email' => '', - 'details' => [ - 'inn' => '', - 'kpp' => '', - 'ogrn' => '', - 'bank' => [ + 'email' => $this->company->email, + 'details' => [ + 'inn' => $this->company->inn, + 'kpp' => '', + 'ogrn' => '', + 'bank' => [ 'name' => '', - 'bik' => '', - 'cur' => '', + 'bik' => '', + 'cur' => '', 'pers' => '' ], - 'address' => '', - 'legal_address' => '', - 'post_address' => '' + 'address' => $this->company->address, + 'legal_address' => $this->company->legal_address, + 'post_address' => '' ] ]; return $data; - } } +} diff --git a/app/Models/Deal/Contract.php b/app/Models/Deal/Contract.php index 6d23d59..41b8519 100644 --- a/app/Models/Deal/Contract.php +++ b/app/Models/Deal/Contract.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model; class Contract extends Model - { +{ use HasFactory; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; @@ -18,11 +18,17 @@ class Contract extends Model 'price', 'reward', 'square', - 'floor' + 'floor', + + 'room',//Номер квартиры + 'date',//дата ДДУ + 'reg_date',//Дата регистрации ДДУ + 'payment_type',//Вид оплаты + 'reward'//Вознаграждение агента ]; public function deal() - { + { return $this->belongsTo(Deal::class, 'deal_id'); - } } +} diff --git a/database/migrations/2025_06_10_083725_add_city_column_to_companies_table.php b/database/migrations/2025_06_10_083725_add_city_column_to_companies_table.php new file mode 100644 index 0000000..d27bdef --- /dev/null +++ b/database/migrations/2025_06_10_083725_add_city_column_to_companies_table.php @@ -0,0 +1,31 @@ +unsignedBigInteger('city_id')->nullable(); + $table->foreign('city_id')->references('id')->on('cities')->nullOnDelete(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('companies', function (Blueprint $table) + { + // + }); + } +}; diff --git a/database/migrations/2025_06_10_095056_add_new_requisites_to_contract_table.php b/database/migrations/2025_06_10_095056_add_new_requisites_to_contract_table.php new file mode 100644 index 0000000..f10d9c6 --- /dev/null +++ b/database/migrations/2025_06_10_095056_add_new_requisites_to_contract_table.php @@ -0,0 +1,33 @@ +string('room')->nullable(); + $table->date('date')->nullable(); + $table->date('reg_date')->nullable(); + $table->string('payment_type')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('client_contract', function (Blueprint $table) + { + // + }); + } +}; diff --git a/resources/views/company/create.blade.php b/resources/views/company/create.blade.php index 1d057ec..ad1f7ca 100644 --- a/resources/views/company/create.blade.php +++ b/resources/views/company/create.blade.php @@ -1,32 +1,56 @@ @extends('layouts.guest') @section('content') +
+
Регистрация
-
Регистрация
-
-
- @csrf + + @csrf +
+ + @if ($type) + + @endif + + @error('type') + + {{ $message }} + + @enderror +
+
+ + @if ($type) + + @endif + + @error('city') + + {{ $message }} + + @enderror +
+ @if ($type)
- - @if($type) - - @endif - - @error('type') - - {{ $message }} - - @enderror -
- @if($type) -
- + @error('name') @@ -77,14 +101,15 @@ @enderror - На данный электронный адрес мы направим логин и пароль администратора для входа в личный кабинет - + На данный электронный адрес мы направим логин и пароль администратора для входа в личный + кабинет +
- @endif - -
-
+ @endif + +
+
@endsection diff --git a/resources/views/livewire/create-client-form.blade.php b/resources/views/livewire/create-client-form.blade.php index a2e417f..6afa4c0 100644 --- a/resources/views/livewire/create-client-form.blade.php +++ b/resources/views/livewire/create-client-form.blade.php @@ -39,7 +39,7 @@ class="form-control rounded-4 @error('client.secondName') is-invalid @enderror"
-
+
-
-
- - - @error('client.city') - - {{ $message }} - - @enderror -
-