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

@ -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');
}
}

View File

@ -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()
]);
}
}

View File

@ -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', [

View File

@ -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()

View File

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

View File

@ -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;
}
}
}

View File

@ -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');
}
}
}

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

@ -1,32 +1,56 @@
@extends('layouts.guest')
@section('content')
<div class="">
<div class="">
<div class="">
<div class="h2">Регистрация</div>
<div class="">
<div class="h2">Регистрация</div>
<div class="">
<form action="{{ route('company.create') }}" method="{{ ($type) ? 'post' : 'get' }}">
@csrf
<form action="{{ route('company.create') }}" method="{{ $type ? 'post' : 'get' }}">
@csrf
<div class="mb-3">
<label for="companyType" class="form-label">Статус регистрации</label>
@if ($type)
<input type="text" class="form-control d-none" id="companyType" name="type"
value="{{ $type }}">
@endif
<select class="form-select" @if ($type) disabled @endif id="companyType"
name="type" value="{{ old('type') }}">
@foreach ($typesList as $typesItem)
<option value="{{ $typesItem->value }}"
@if ($type == $typesItem->value) selected @endif>{{ __($typesItem->name) }}
</option>
@endforeach
</select>
@error('type')
<span class="invalid-feedback d-block" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</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)
<div class="mb-3">
<label for="companyType" class="form-label">Статус регистрации</label>
@if($type)
<input type="text" class="form-control d-none" id="companyType" name="type" value="{{ $type }}">
@endif
<select class="form-select" @if($type) disabled @endif id="companyType" name="type" value="{{ old('type') }}">
@foreach($typesList as $typesItem)
<option value="{{$typesItem->value}}" @if($type == $typesItem->value) selected @endif>{{ __($typesItem->name) }}</option>
@endforeach
</select>
@error('type')
<span class="invalid-feedback d-block" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
@if($type)
<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"
value="{{ old('name') }}">
@error('name')
@ -77,14 +101,15 @@
</span>
@enderror
<span class="fst-italic">
На данный электронный адрес мы направим логин и пароль администратора для входа в личный кабинет
</span>
На данный электронный адрес мы направим логин и пароль администратора для входа в личный
кабинет
</span>
</div>
@endif
<input type="submit" class="btn btn-primary" value="Продолжить">
</form>
</div>
@endif
<input type="submit" class="btn btn-primary" value="Продолжить">
</form>
</div>
</div>
</div>
</div>
@endsection

View File

@ -39,7 +39,7 @@ class="form-control rounded-4 @error('client.secondName') is-invalid @enderror"
</div>
</div>
<div class="row">
<div class="col-12 col-xl-6">
<div class="col-12">
<div class="form-floating mb-3">
<input wire:model.live="client.phone" id="client.phone" type="tel"
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
</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 class="form-floating mb-3">
<select wire:model.live="client.complexId"