clients form updated for second contact

This commit is contained in:
Thekindbull 2025-06-18 17:12:19 +08:00
parent a032cd52aa
commit c5f369e2a5
19 changed files with 415 additions and 137 deletions

View File

@ -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
{

View File

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

View File

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

View File

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

View File

@ -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 = [

View File

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

View File

@ -0,0 +1,5 @@
<?php
return [
];

View File

@ -0,0 +1,27 @@
<?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::create('contracts', function (Blueprint $table) {
$table->id();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('contracts');
}
};

View File

@ -0,0 +1,17 @@
<?php
namespace Modules\Contracts\Http\Controllers;
use Modules\Contracts\Models\Contract;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class ContractsController extends Controller
{
public function index()
{
return view('contracts::index');
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace Modules\Contracts\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\Deal\Deal;
class Contract extends Model
{
use HasFactory;
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $table = 'client_contract';
protected $fillable = [
'deal_id',
'status',
'comment',
'price',
'reward',
'square',
'floor',
'room',//Номер квартиры
'date',//дата ДДУ
'reg_date',//Дата регистрации ДДУ
'payment_type',//Вид оплаты
'plan7_id'//ид помещения из plan7
];
public function deal()
{
return $this->belongsTo(Deal::class, 'deal_id');
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace Modules\Contracts\Models;
class ContractStatus
{
const NEW = 'NEW';
const TREATY = 'TREATY';
const RESERVATION = 'RESERVATION';
const SUCCESS = "SUSSCESS";
const DECLINE = "DECLINE";
}

View File

@ -0,0 +1,68 @@
<?php
namespace Modules\Contract\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Blade;
use Livewire\Livewire;
class ModuleServiceProvider extends ServiceProvider
{
protected String $moduleName = 'Contract';
public function register()
{
$this->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('<name>', \Modules\<NAME>\Http\Livewire\<NAME>::class);
}
protected function registerComponent()
{
//Blade::component('<name>', \Modules\<NAME>\Http\Components\<NAME>::class);
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace Modules\Contract\Providers;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
{
public function map()
{
$this->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'));
}
}

View File

@ -0,0 +1,13 @@
<?php
use Illuminate\Support\Facades\Route;
use Modules\Contracts\Http\Controllers\ContractsController;
Route::middleware(['auth'])->group(function() {
Route::get('/contract', [ContractsController::class, 'index']);
Route::middleware(['hasAccess'])->group(function() {
/** Routes that need to be protected - Маршруты которые нужно защитить */
});
});

View File

@ -0,0 +1,4 @@
@extends('layouts.app')
@section('content')
<h1> Example views </h1>
@endsection

View File

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

View File

@ -17,15 +17,15 @@
<label class="btn p-2 fs-5" for="option7">Не
уникальные</label>
</div>
<!--<div class="ms-auto p-2">
<select class="form-select form-select-lg" disabled aria-label="Large select example">
<option selected="">Город: любой</option>
@foreach ($cities as $city)
<option value="{{ $city->id }}">{{ $city->name }}</option>
@endforeach
</select>
</div>-->
<div class="ms-auto p-2">
<select class="form-select form-select-lg" disabled aria-label="Large select example">
<option selected="">Город: любой</option>
@foreach ($cities as $city)
<option value="{{ $city->id }}">{{ $city->name }}</option>
@endforeach
</select>
</div>
<div class="p-2">
<button type="button" class="btn btn-primary py-2 px-3 fs-5" data-bs-toggle="modal"
data-bs-target="#createClientModal">
<i class="bi bi-person-plus"></i> <span class="d-inline d-md-none">Добавить клиента</span>
@ -59,9 +59,9 @@
<livewire:createClientForm />
</div>
<!--<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Отмена</button>
<input type="submit" class="btn btn-primary" value="Добавить">
</div>-->
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Отмена</button>
<input type="submit" class="btn btn-primary" value="Добавить">
</div>-->
</div>
</div>
</div>

View File

@ -9,54 +9,140 @@
<div class="h4 pb-2 mb-4 fw-bold ">
<small>Добавить клиента</small>
</div>
<div class="row">
<div class="col-12 col-xl-6">
<div class="form-floating mb-3">
<input wire:model.live="client.firstName" id="client.firstName" type="text"
class="form-control rounded-4 @error('client.firstName') is-invalid @enderror"
name="client.firstName" required autocomplete="client.firstName" placeholder="Имя">
<label for="client.firstName">Имя</label>
@error('client.firstName')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
<div class="col-12 col-xl-6">
<div class="form-floating mb-3">
<input wire:model.live="client.secondName" id="client.secondName" type="text"
class="form-control rounded-4 @error('client.secondName') is-invalid @enderror"
name="client.secondName" required autocomplete="client.secondName" placeholder="Фамилия">
<label for="client.secondName">Фамилия</label>
@error('client.secondName')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
<div class="bg-secondary-subtle rounded-4 mb-3">
<div
class="p-3 rounded-4 rounded-top-4 @if ($clientSecondary) shadow-sm bg-dark-subtle @endif">
<div class="row mb-2">
<div class="col-12 col-xl-6">
<div class="form-floating mb-3">
<input wire:model.live="client.firstName" id="client.firstName" type="text"
class="form-control rounded-4 @error('client.firstName') is-invalid @enderror"
name="client.firstName" required autocomplete="client.firstName" placeholder="Имя">
<label for="client.firstName">Имя</label>
@error('client.firstName')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
<div class="col-12 col-xl-6">
<div class="form-floating mb-3">
<input wire:model.live="client.secondName" id="client.secondName" type="text"
class="form-control rounded-4 @error('client.secondName') is-invalid @enderror"
name="client.secondName" required autocomplete="client.secondName"
placeholder="Фамилия">
<label for="client.secondName">Фамилия</label>
@error('client.secondName')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
</div>
<div class="row">
<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"
name="client.phone" required autocomplete="phone" placeholder="Телефон клиента">
<label for="client.phone">Телефон</label>
@error('client.phone')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
<div class="row">
<div class="col-12 hstack gap-2 mb-3">
<div class="form-floating me-auto w-100">
<input wire:model="client.phone" id="client.phone" type="tel" data-phone-pattern
class="form-control rounded-4 @error('client.phone') is-invalid @enderror"
name="client.phone" required autocomplete="phone" placeholder="Телефон клиента">
<label for="client.phone">Телефон</label>
@error('client.phone')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
@if ($clientSecondary == false)
<a class="" wire:click="getClientSecondary">
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="30"
fill="currentColor" class="bi bi-plus-circle" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16" />
<path
d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4" />
</svg>
</a>
@endif
</div>
</div>
</div>
@if ($clientSecondary)
<div class="p-3" wire:transition.origin.top>
<div class="d-flex">
<div class="p-2 w-100">СУПРУГ / СУПРУГА</div>
<div class="p-2 flex-shrink-1">
<a class="" wire:click="deleteClientSecondary">
<svg xmlns="http://www.w3.org/2000/svg" width="25" height="25"
fill="currentColor" class="bi bi-person-dash" viewBox="0 0 16 16">
<path
d="M12.5 16a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7M11 12h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1 0-1m0-7a3 3 0 1 1-6 0 3 3 0 0 1 6 0M8 7a2 2 0 1 0 0-4 2 2 0 0 0 0 4" />
<path
d="M8.256 14a4.5 4.5 0 0 1-.229-1.004H3c.001-.246.154-.986.832-1.664C4.484 10.68 5.711 10 8 10q.39 0 .74.025c.226-.341.496-.65.804-.918Q8.844 9.002 8 9c-5 0-6 3-6 4s1 1 1 1z" />
</svg>
</a>
</div>
</div>
<div>
<div class="row">
<div class="col-12 col-xl-6">
<div class="form-floating mb-3">
<input wire:model.live="clientSecondary.firstName"
id="clientSecondary.firstName" type="text"
class="form-control rounded-4 @error('clientSecondary.firstName') is-invalid @enderror"
name="clientSecondary.firstName" required
autocomplete="clientSecondary.firstName" placeholder="Имя">
<label for="clientSecondary.firstName">Имя</label>
@error('clientSecondary.firstName')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
<div class="col-12 col-xl-6">
<div class="form-floating mb-3">
<input wire:model.live="clientSecondary.secondName"
id="clientSecondary.secondName" type="text"
class="form-control rounded-4 @error('clientSecondary.secondName') is-invalid @enderror"
name="clientSecondary.secondName" required
autocomplete="clientSecondary.secondName" placeholder="Фамилия">
<label for="clientSecondary.secondName">Фамилия</label>
@error('clientSecondary.secondName')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="form-floating">
<input wire:model="clientSecondary.phone" id="clientSecondary.phone"
type="tel" data-phone-pattern
class="form-control rounded-4 @error('client.phone') is-invalid @enderror"
name="clientSecondary.phone" required autocomplete="phone"
placeholder="Телефон клиента">
<label for="clientSecondary.phone">Телефон</label>
@error('clientSecondary.phone')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
</div>
</div>
</div>
@endif
</div>
<div class="form-floating mb-3">
<select wire:model.live="client.complexId"
class="form-select rounded-4 @error('client.complexId') is-invalid @enderror" id="client.complexId"
name="client.complexId" aria-label="Жилой комплекс">
class="form-select rounded-4 @error('client.complexId') is-invalid @enderror"
id="client.complexId" name="client.complexId" aria-label="Жилой комплекс">
<option selected></option>
@foreach ($complexes as $complex)
<option value="{{ $complex->id }}">
@ -147,28 +233,32 @@ class="bi bi-emoji-astonished" viewBox="0 0 16 16">
</div>
@script
<script>
function checkPhoneFormat() {
alert(1);
return;
var digits = phone.replace(/^8/, '7').replace(/[^\d]+/, '');
if (digits.length < 11) {
return phone;
eventCalllback = function(e) {
var el = e.target,
clearVal = el.dataset.phoneClear,
pattern = el.dataset.phonePattern,
matrix_def = "+7(___) ___-__-__",
matrix = pattern ? pattern : matrix_def,
i = 0,
def = matrix.replace(/\D/g, ""),
val = e.target.value.replace(/\D/g, "");
if (clearVal !== 'false' && e.type === 'blur') {
if (val.length < matrix.match(/([\_\d])/g).length) {
e.target.value = '';
return;
}
}
// Домашний?
if (digits.substr(0, 2) === '74') {
// Для белгородских (и похожих) домашних возвращаем нормальное форматирование
// Для остальных пытаемся
return digits.substr(0, 3) === '747' ?
digits.replace(/^(\d)(\d+)(\d\d)(\d\d)(\d\d)$/, '+$1 ($2) $3$4$5') :
digits.replace(/^(\d)(\d+)(\d\d\d)(\d\d)(\d\d)$/, '+$1 ($2) $3$4$5');
if (def.length >= val.length) val = def;
e.target.value = matrix.replace(/./g, function(a) {
return /[_\d]/.test(a) && i < val.length ? val.charAt(i++) : i >= val.length ? "" :
a
});
}
var phone_inputs = document.querySelectorAll('[data-phone-pattern]');
for (let elem of phone_inputs) {
for (let ev of ['input', 'blur', 'focus']) {
elem.addEventListener(ev, eventCalllback);
}
// Для русских мобильных возвращаем нормальное форматирование
// Для остальных пытаемся
return digits.substr(0, 2) === '79' ?
digits.replace(/^(\d)(\d+)(\d\d\d)(\d\d)(\d\d)$/, '+$1 $2 $3$4$5') :
digits.replace(/^(\d)(\d+)(\d\d\d)(\d\d)(\d\d)$/, '+$1$2 $3$4$5');
}
</script>
@endscript

View File

@ -15,6 +15,13 @@
'name' => 'Клиенты',
'icon' => 'person',
];
$items[] = [
'target' => 'route',
'route' => 'clients.table',
'name' => 'Договоры',
'icon' => 'files-alt',
];
}
if (in_array($roles::AGENT, $userRoles) || in_array($roles::COMPANY_ADMIN, $userRoles)) {
$items[] = [