city field in company table added

This commit is contained in:
Thekindbull 2025-06-10 22:20:29 +08:00
parent 81e247c19e
commit 520e972ead
11 changed files with 224 additions and 122 deletions

View File

@ -23,7 +23,8 @@ public function __invoke(Request $request)
'phone' => 'required', 'phone' => 'required',
'inn' => 'required|unique:companies', 'inn' => 'required|unique:companies',
'legal_address' => 'required', 'legal_address' => 'required',
'type' => Rule::enum(CompanyType::class) 'type' => Rule::enum(CompanyType::class),
'city_id' => 'required'
]); ]);
$request->request->add([ $request->request->add([
@ -31,12 +32,14 @@ public function __invoke(Request $request)
'status' => 'new' '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); $company = Company::create($data);
if (!$company) if (!$company)
{ {
return back()->withErrors(['msg' => 'Company creation error'])->withInput(); return back()->withErrors(['msg' => 'Company creation error'])->withInput();
} }
$data['callback_url'] = route('company.status.update', [ $data['callback_url'] = route('company.status.update', [
'company_id' => $company->id, 'company_id' => $company->id,
'secret' => $company->secret 'secret' => $company->secret

View File

@ -6,6 +6,7 @@
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\Company\Company; use App\Models\Company\Company;
use App\Models\Company\CompanyType; use App\Models\Company\CompanyType;
use App\Models\City;
class CreateCompanyFormController extends Controller class CreateCompanyFormController extends Controller
{ {
@ -15,14 +16,23 @@ class CreateCompanyFormController extends Controller
public function __invoke(Request $request) public function __invoke(Request $request)
{ {
$type = false; $type = false;
$city_id = false;
if ($request->has('type')) if ($request->has('type'))
{ {
$request->enum('type', CompanyType::class); $request->enum('type', CompanyType::class);
$type = $request->type; $type = $request->type;
} }
;
if ($request->has('city_id'))
{
$city_id = $request->city_id;
}
;
return view('company.create', [ return view('company.create', [
'type' => $type, 'type' => $type,
'typesList' => CompanyType::cases() 'city_id' => $city_id,
'typesList' => CompanyType::cases(),
'citiesList' => City::all()
]); ]);
} }
} }

View File

@ -34,7 +34,7 @@ public function index($companyId = null)
} }
$details = new Details($company); $details = new Details($company);
$details = $details->details; $details = $details->get();
if ($company->type == CompanyType::SelfEmployer || $company->type == CompanyType::SoleProperty) if ($company->type == CompanyType::SelfEmployer || $company->type == CompanyType::SoleProperty)
{ {
return view('company.details.selfemp', [ return view('company.details.selfemp', [

View File

@ -38,13 +38,14 @@ protected function rules()
'client.firstName' => ['required', 'string', 'max:255'], 'client.firstName' => ['required', 'string', 'max:255'],
'client.secondName' => ['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', 'regex:/^\+7 \d{3} \d{3}-\d{2}-\d{2}$/'],
'client.phone' => ['required', 'string']
]; ];
} }
public function mount() public function mount()
{ {
$userBroker = Agent::where('user_id', auth()->user()->id)->first(); $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 = [ $this->client = [
'firstName' => '', 'firstName' => '',
'secondName' => '', 'secondName' => '',
@ -68,7 +69,7 @@ public function update()
public function updated($propertyName) public function updated($propertyName)
{ {
$this->status = self::NEW; $this->status = self::NEW;
if ($propertyName == 'client.phone') /*if ($propertyName == 'client.phone')
{ {
//$this->dispatch('phone-updated', ['newPhone' => 111]); //$this->dispatch('phone-updated', ['newPhone' => 111]);
//$this->js("checkPhoneFormat('123')"); //$this->js("checkPhoneFormat('123')");
@ -92,7 +93,7 @@ public function updated($propertyName)
{ {
$this->client['phone'] = $phone; $this->client['phone'] = $phone;
} }
} }*/
$this->validateOnly($propertyName); $this->validateOnly($propertyName);
} }
public function render() public function render()

View File

@ -22,7 +22,8 @@ class Company extends Model
'legal_address', 'legal_address',
'details', 'details',
'status', 'status',
'secret' 'secret',
'city_id'
]; ];
protected $casts = [ protected $casts = [

View File

@ -10,30 +10,35 @@ class Details
{ {
use HasFactory; use HasFactory;
public $details; public $details;
private $company;
public function __construct(Company $company) public function __construct(Company $company)
{ {
$company; $this->company = $company;
if (!$company->details) }
public function get()
{ {
if ($company->type == CompanyType::SelfEmployer) if (!$this->company->details)
{ {
$company->details = $this->emptyForSelfEmp(); if ($this->company->type == CompanyType::SelfEmployer)
$company->save(); {
$this->company->details = $this->emptyForSelfEmp();
$this->company->save();
} }
; ;
if ($company->type == CompanyType::SoleProperty) if ($this->company->type == CompanyType::SoleProperty)
{ {
$company->details = $this->emptyForSelfEmp(); $this->company->details = $this->emptyForSelfEmp();
$company->save(); $this->company->save();
} }
; ;
if ($company->type == CompanyType::Agency) if ($this->company->type == CompanyType::Agency)
{ {
$company->details = $this->emptyForAgency(); $this->company->details = $this->emptyForAgency();
$company->save(); $this->company->save();
} }
} }
$this->details = $company->details; return $this->details = $this->company->details;
} }
private function emptyForSelfEmp() private function emptyForSelfEmp()
@ -42,11 +47,11 @@ private function emptyForSelfEmp()
'user' => [ 'user' => [
'firstName' => '', 'firstName' => '',
'secondName' => '', 'secondName' => '',
'email' => '', 'email' => $this->company->email,
'phone' => '' 'phone' => ''
], ],
'details' => [ 'details' => [
'inn' => '', 'inn' => $this->company->inn,
'snils' => '', 'snils' => '',
'bank' => [ 'bank' => [
'name' => '', 'name' => '',
@ -54,8 +59,8 @@ private function emptyForSelfEmp()
'cur' => '', 'cur' => '',
'pers' => '' 'pers' => ''
], ],
'address' => '', 'address' => $this->company->address,
'legal_address' => '' 'legal_address' => $this->company->legal_address
] ]
]; ];
return $data; return $data;
@ -64,11 +69,11 @@ private function emptyForSelfEmp()
private function emptyForAgency() private function emptyForAgency()
{ {
$data = [ $data = [
'name' => '', 'name' => $this->company->name,
'fullName' => '', 'fullName' => '',
'email' => '', 'email' => $this->company->email,
'details' => [ 'details' => [
'inn' => '', 'inn' => $this->company->inn,
'kpp' => '', 'kpp' => '',
'ogrn' => '', 'ogrn' => '',
'bank' => [ 'bank' => [
@ -77,8 +82,8 @@ private function emptyForAgency()
'cur' => '', 'cur' => '',
'pers' => '' 'pers' => ''
], ],
'address' => '', 'address' => $this->company->address,
'legal_address' => '', 'legal_address' => $this->company->legal_address,
'post_address' => '' 'post_address' => ''
] ]
]; ];

View File

@ -18,7 +18,13 @@ class Contract extends Model
'price', 'price',
'reward', 'reward',
'square', 'square',
'floor' 'floor',
'room',//Номер квартиры
'date',//дата ДДУ
'reg_date',//Дата регистрации ДДУ
'payment_type',//Вид оплаты
'reward'//Вознаграждение агента
]; ];
public function deal() public function deal()

View File

@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('companies', function (Blueprint $table)
{
$table->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)
{
//
});
}
};

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('client_contract', function (Blueprint $table)
{
$table->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)
{
//
});
}
};

View File

@ -6,16 +6,20 @@
<div class=""> <div class="">
<div class="h2">Регистрация</div> <div class="h2">Регистрация</div>
<div class=""> <div class="">
<form action="{{ route('company.create') }}" method="{{ ($type) ? 'post' : 'get' }}"> <form action="{{ route('company.create') }}" method="{{ $type ? 'post' : 'get' }}">
@csrf @csrf
<div class="mb-3"> <div class="mb-3">
<label for="companyType" class="form-label">Статус регистрации</label> <label for="companyType" class="form-label">Статус регистрации</label>
@if ($type) @if ($type)
<input type="text" class="form-control d-none" id="companyType" name="type" value="{{ $type }}"> <input type="text" class="form-control d-none" id="companyType" name="type"
value="{{ $type }}">
@endif @endif
<select class="form-select" @if($type) disabled @endif id="companyType" name="type" value="{{ old('type') }}"> <select class="form-select" @if ($type) disabled @endif id="companyType"
name="type" value="{{ old('type') }}">
@foreach ($typesList as $typesItem) @foreach ($typesList as $typesItem)
<option value="{{$typesItem->value}}" @if($type == $typesItem->value) selected @endif>{{ __($typesItem->name) }}</option> <option value="{{ $typesItem->value }}"
@if ($type == $typesItem->value) selected @endif>{{ __($typesItem->name) }}
</option>
@endforeach @endforeach
</select> </select>
@error('type') @error('type')
@ -24,9 +28,29 @@
</span> </span>
@enderror @enderror
</div> </div>
<div class="mb-3">
<label for="companyType" class="form-label">Город</label>
@if ($type)
<input type="text" class="form-control d-none" id="companyCity" name="city_id"
value="{{ $city_id }}">
@endif
<select class="form-select" @if ($type && $city_id) disabled @endif id="companyCity"
name="city_id" value="{{ old('city') }}">
@foreach ($citiesList as $cityItem)
<option value="{{ $cityItem->id }}" @if ($city_id && $city_id == $cityItem->id) selected @endif>
{{ __($cityItem->name) }}</option>
@endforeach
</select>
@error('city')
<span class="invalid-feedback d-block" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
@if ($type) @if ($type)
<div class="mb-3"> <div class="mb-3">
<label for="companyName" class="form-label">{{ __(ucfirst(strtolower($type)) . ' name') }}</label> <label for="companyName"
class="form-label">{{ __(ucfirst(strtolower($type)) . ' name') }}</label>
<input type="text" class="form-control" id="companyName" name="name" <input type="text" class="form-control" id="companyName" name="name"
value="{{ old('name') }}"> value="{{ old('name') }}">
@error('name') @error('name')
@ -77,7 +101,8 @@
</span> </span>
@enderror @enderror
<span class="fst-italic"> <span class="fst-italic">
На данный электронный адрес мы направим логин и пароль администратора для входа в личный кабинет На данный электронный адрес мы направим логин и пароль администратора для входа в личный
кабинет
</span> </span>
</div> </div>
@endif @endif

View File

@ -39,7 +39,7 @@ class="form-control rounded-4 @error('client.secondName') is-invalid @enderror"
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-12 col-xl-6"> <div class="col-12">
<div class="form-floating mb-3"> <div class="form-floating mb-3">
<input wire:model.live="client.phone" id="client.phone" type="tel" <input wire:model.live="client.phone" id="client.phone" type="tel"
class="form-control rounded-4 @error('client.phone') is-invalid @enderror" class="form-control rounded-4 @error('client.phone') is-invalid @enderror"
@ -52,19 +52,6 @@ class="form-control rounded-4 @error('client.phone') is-invalid @enderror"
@enderror @enderror
</div> </div>
</div> </div>
<div class="col-12 col-xl-6">
<div class="form-floating mb-3">
<input wire:model.live="client.city" disabled id="client.city" type="text"
class="form-control rounded-4 @error('client.city') is-invalid @enderror" name="client.city"
required autocomplete="city" placeholder="Город">
<label for="client.city">Город</label>
@error('client.city')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
</div> </div>
<div class="form-floating mb-3"> <div class="form-floating mb-3">
<select wire:model.live="client.complexId" <select wire:model.live="client.complexId"