обновлена таблица вознаграждений в админке

This commit is contained in:
Thekindbull 2025-04-25 10:26:13 +08:00
parent d2ceee50f5
commit 7fddfd54c7
9 changed files with 476 additions and 319 deletions

View File

@ -37,7 +37,8 @@ protected function rules()
'agent' => ['required', 'integer'],
'client.firstName' => ['required', 'string', 'max:255'],
'client.secondName' => ['required', 'string', 'max:255'],
'client.phone' => ['required', 'string', 'regex:/\(?([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}$/']
];
}
public function mount()
@ -71,26 +72,22 @@ public function updated($propertyName)
{
//$this->dispatch('phone-updated', ['newPhone' => 111]);
//$this->js("checkPhoneFormat('123')");
$phone = preg_replace('/[^0-9]/', "", $this->client['phone']);
if (strlen($phone) == 10)
$phone = preg_replace('/[^0-9\+]+/', "", $this->client['phone']);
if (strlen($this->client['phone']) <= 2)
{
$sArea = substr($phone, 0, 3);
$sPrefix = substr($phone, 3, 3);
$sNumber = substr($phone, 6, 4);
$phone = "(" . $sArea . ")-" . $sPrefix . "-" . $sNumber;
$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;
}
elseif (strlen($this->client['phone']) == 1)
{
if ($this->client['phone'] == "8" || $this->client['phone'] == "7" || $this->client['phone'] == "+")
{
$this->client['phone'] = null;
}
else
{
$this->client['phone'] = $phone;
}
}
else
{
$this->client['phone'] = $phone;

View File

@ -31,17 +31,11 @@ public function index(Request $request)
'filter' => $request->filter
]);
}
public function edit(City $city)
{
return view('admin::companies.edit', [
'city' => $city,
]);
}
public function update(Request $request, City $city)
{
$city->update($request->only('name'));
return to_route('admin.companies');
return back();
}
public function create(Request $request)

View File

@ -8,7 +8,7 @@
use App\Models\Agent\Agent;
class Payments extends Component
{
public $value;
public $newValue;
public $companyId;
public function mount()
{
@ -27,8 +27,8 @@ public function back()
public function setPaymentValueForCompany(Company $company, Complex $complex)
{
$company->setPayment($complex, $this->value);
$this->value = null;
$company->setPayment($complex, $this->newValue);
$this->newValue = null;
}
public function unsetPaymentForCompany(Company $company, Complex $complex)
@ -38,14 +38,14 @@ public function unsetPaymentForCompany(Company $company, Complex $complex)
public function setPaymentValueForAgent(Agent $agent, Complex $complex)
{
$agent->setPayment($complex, $this->value);
$this->value = null;
$agent->setPayment($complex, $this->newValue);
$this->newValue = null;
}
public function setPaymentAsParentForAgent(Agent $agent, Complex $complex)
{
$agent->setAsParentPayment($complex);
$this->value = null;
$this->newValue = null;
}
public function unsetPaymentForAgent(Agent $agent, Complex $complex)
@ -53,6 +53,21 @@ public function unsetPaymentForAgent(Agent $agent, Complex $complex)
$agent->unsetPayment($complex);
}
public function setPaymentForAllAgentOfCompany(Company $company, Complex $complex)
{
$compPayment = $company->getPaymentable($complex);
$compPayment = $compPayment->value;
if ($compPayment == null || $compPayment == -1)
{
return false;
}
$agents = Agent::where('company_id', $company->id)->get();
foreach ($agents as $agent)
{
$agent->setPayment($complex, $compPayment);
}
}
public function render()
{
if ($this->companyId)

View File

@ -28,7 +28,7 @@
Route::post('/admin/companies/{company}/delete', [Modules\Admin\Http\Controllers\AdminUsersController::class, 'update'])->name('admin.companies.delete');
Route::get('/admin/cities', [Modules\Admin\Http\Controllers\AdminCitiesController::class, 'index'])->name('admin.cities');
Route::get('/admin/cities/{city}/edit', [Modules\Admin\Http\Controllers\AdminCitiesController::class, 'edit'])->name('admin.cities.edit');
Route::post('/admin/cities/{city}/update', [Modules\Admin\Http\Controllers\AdminCitiesController::class, 'update'])->name('admin.cities.update');
Route::post('/admin/cities/create', [Modules\Admin\Http\Controllers\AdminCitiesController::class, 'create'])->name('admin.cities.create');
Route::post('/admin/cities/{city}/delete', [Modules\Admin\Http\Controllers\AdminCitiesController::class, 'delete'])->name('admin.cities.delete');
Route::post('/admin/cities/{city}/restore', [Modules\Admin\Http\Controllers\AdminCitiesController::class, 'restore'])->withTrashed()->name('admin.cities.restore');

View File

@ -1,6 +1,11 @@
@php($title = 'Города')
@extends('layouts.admin')
@section('content')
<style>
.collapsing {
transition: none !important;
}
</style>
<div class="d-flex mb-3">
<form class="p-2 border rounded-3 border-1 bg-white" method="GET" action="{{ route('admin.cities') }}">
<input type="radio" class="btn-check" name="filter" value="all" id="option_all" autocomplete="off"
@ -36,7 +41,19 @@
@foreach ($cities as $city)
<tr scope="row" class="@if ($city->trashed()) bg-secondary @endif">
<td class="align-middle">
<div class="collapse show" data-bs-toggle="collapse"
data-bs-target="#collapseName{{ $city->id }}" id="collapseName{{ $city->id }}">
{{ $city->name }}
</div>
<div class="collapse" id="collapseName{{ $city->id }}">
<form action="{{ route('admin.cities.update', ['city' => $city]) }}" method="post">
@csrf
<input class="form-control form-control-lg w-100" name="name" type="text"
value="{{ $city->name }}" placeholder="Название города"
aria-label="default input example">
<input type="submit" hidden />
</form>
</div>
</td>
<td>
{{ $city->created_at ? $city->created_at->diffForHumans() : '' }}
@ -59,9 +76,12 @@
<button class="dropdown-item" type="submit">Восстановить</button>
</form>
@else
<a class="dropdown-item"
href="{{ route('admin.cities.edit', ['city' => $city]) }}">Редактировать</a>
<form method="post" action="{{ route('admin.cities.delete', ['city' => $city]) }}">
<button class="dropdown-item" type="button" data-bs-toggle="collapse"
data-bs-target="#collapseName{{ $city->id }}">
Редактировать
</button>
<form method="post"
action="{{ route('admin.cities.delete', ['city' => $city]) }}">
@csrf
<button class="dropdown-item" type="submit">Удалить</button>
</form>

View File

@ -1,24 +1,31 @@
<div>
<button wire:click="back" class="btn border-0 icon-link icon-link-hover fs-5 mb-3 text-decoration-none text-primary"
<div>
<button wire:click="back"
class="btn border-0 icon-link icon-link-hover fs-5 mb-3 text-decoration-none text-primary"
style="--bs-icon-link-transform: translate3d(-.125rem, 0, 0);" href="#">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chevron-left"
viewBox="0 0 16 16">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
class="bi bi-chevron-left" viewBox="0 0 16 16">
<path fill-rule="evenodd"
d="M11.354 1.646a.5.5 0 0 1 0 .708L5.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0" />
</svg>
{{ $company->name }}
</button>
<div class="fs-5 bg-light p-0 m-0 border border-1 rounded-4 py-3">
<table class="table m-0">
<table class="table m-0 table-striped-columns">
<thead>
<tr scope="col">
<th>Агент</th>
@foreach ($complexes as $complex)
<th>
{{ $complex->name }}
<div>
{{ $complex->city->name }}
</div>
<div>
@php($compPayment = $company->getPaymentable($complex))
<span class="badge bg-secondary">
<div class="dropdown">
<a class="btn bg-secondary-subtle btn-sm text-truncate" href="#"
role="button" data-bs-toggle="dropdown" aria-expanded="false">
@if ($compPayment->value === null)
Не установлено
@elseif($compPayment->value == -1)
@ -26,7 +33,44 @@
@else
{{ $compPayment->value }} %
@endif
<i class="bi bi-three-dots-vertical"></i>
</a>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item " href="#">
<span class="badge text-dark">Введите размер вознаграждения:
</span>
<div class="input-group mb-3">
<span class="input-group-text" id="basic-addon1">
<svg xmlns="http://www.w3.org/2000/svg" width="20"
height="20" fill="currentColor" class="bi bi-percent"
viewBox="0 0 16 16">
<path
d="M13.442 2.558a.625.625 0 0 1 0 .884l-10 10a.625.625 0 1 1-.884-.884l10-10a.625.625 0 0 1 .884 0M4.5 6a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3m0 1a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5m7 6a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3m0 1a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5" />
</svg>
</span>
<input class="form-control" type="text"
placeholder="Вознаграждение"
value="{{ $compPayment->value }}"
wire:model.lazy = "newValue"
wire:keydown.enter="setPaymentValueForCompany({{ $company->id }}, {{ $complex->id }})">
</div>
</a>
</li>
@if ($compPayment->value)
<li>
<hr class="dropdown-divider">
</li>
<li>
<button class="dropdown-item"
wire:click="setPaymentForAllAgentOfCompany({{ $company->id }}, {{ $complex->id }})">Установить
{{ $compPayment->value }}
% для всех агентов</button>
</li>
@endif
</ul>
</div>
</div>
</th>
@endforeach
@ -43,16 +87,30 @@
<td>
@if ($paymentable->value == null)
<div class="dropdown">
<button class="btn btn-light btn-sm" type="button" data-bs-toggle="dropdown"
<button class="btn btn-light" type="button" data-bs-toggle="dropdown"
aria-expanded="false">
Не установлено
</button>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item " href="#">
<input class="form-control form-control-sm" type="text"
placeholder="Процент вознаграждения" wire:model = "value"
<span class="badge text-dark">Введите размер вознаграждения:
</span>
<div class="input-group mb-3">
<span class="input-group-text" id="basic-addon1">
<svg xmlns="http://www.w3.org/2000/svg" width="20"
height="20" fill="currentColor"
class="bi bi-percent" viewBox="0 0 16 16">
<path
d="M13.442 2.558a.625.625 0 0 1 0 .884l-10 10a.625.625 0 1 1-.884-.884l10-10a.625.625 0 0 1 .884 0M4.5 6a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3m0 1a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5m7 6a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3m0 1a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5" />
</svg>
</span>
<input class="form-control" type="text"
placeholder="Вознаграждение"
value="{{ $paymentable->value }}"
wire:model = "newValue"
wire:keydown.enter="setPaymentValueForAgent({{ $agent->id }}, {{ $complex->id }})">
</div>
</a>
</li>
<li>
@ -65,16 +123,30 @@
</div>
@elseif($paymentable->value == -1)
<div class="dropdown">
<button class="btn btn-light btn-sm" type="button" data-bs-toggle="dropdown"
<button class="btn btn-light" type="button" data-bs-toggle="dropdown"
aria-expanded="false">
Наследовать
</button>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item " href="#">
<input class="form-control form-control-sm" type="text"
placeholder="Процент вознаграждения" wire:model = "value"
<span class="badge text-dark">Введите размер вознаграждения:
</span>
<div class="input-group mb-3">
<span class="input-group-text" id="basic-addon1">
<svg xmlns="http://www.w3.org/2000/svg" width="20"
height="20" fill="currentColor"
class="bi bi-percent" viewBox="0 0 16 16">
<path
d="M13.442 2.558a.625.625 0 0 1 0 .884l-10 10a.625.625 0 1 1-.884-.884l10-10a.625.625 0 0 1 .884 0M4.5 6a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3m0 1a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5m7 6a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3m0 1a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5" />
</svg>
</span>
<input class="form-control" type="text"
placeholder="Вознаграждение"
value="{{ $paymentable->value }}"
wire:model = "newValue"
wire:keydown.enter="setPaymentValueForAgent({{ $agent->id }}, {{ $complex->id }})">
</div>
</a>
</li>
<li>
@ -94,16 +166,28 @@
<ul class="dropdown-menu">
<li>
<a class="dropdown-item " href="#">
<input class="form-control form-control-sm" type="text"
placeholder="Процент вознаграждения"
value="{{ $paymentable->value }}" wire:model = "value"
<span class="badge text-dark">Введите размер вознаграждения:
</span>
<div class="input-group mb-3">
<span class="input-group-text" id="basic-addon1">
<svg xmlns="http://www.w3.org/2000/svg" width="20"
height="20" fill="currentColor"
class="bi bi-percent" viewBox="0 0 16 16">
<path
d="M13.442 2.558a.625.625 0 0 1 0 .884l-10 10a.625.625 0 1 1-.884-.884l10-10a.625.625 0 0 1 .884 0M4.5 6a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3m0 1a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5m7 6a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3m0 1a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5" />
</svg>
</span>
<input class="form-control" type="text"
placeholder="Вознаграждение"
value="{{ $paymentable->value }}"
wire:model = "newValue"
wire:keydown.enter="setPaymentValueForAgent({{ $agent->id }}, {{ $complex->id }})">
</div>
</a>
</li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item disabled" href="#">Наследовать</a></li>
<li><button class="dropdown-item"
wire:click="unsetPaymentForAgent({{ $agent->id }}, {{ $complex->id }})">Без
вознаграждения</button>
@ -122,3 +206,4 @@
</table>
</div>
</div>
</div>

View File

@ -1,52 +1,89 @@
<div class="fs-5 bg-light p-0 m-0 border border-1 rounded-4 py-3">
<table class="table m-0">
<div>
<table class="table m-0 table-striped-columns ">
<thead>
<tr scope="col">
<th>Компания</th>
@foreach ($complexes as $complex)
<th>{{ $complex->name }}
<div>
{{ $complex->city->name }}
</div>
</th>
@endforeach
<th></th>
</tr>
</thead>
<tbody class=" ">
@foreach ($companies as $company)
<tr scope="row">
<td class="align-middle">
<td class="">
<a class="text-dark icon-link icon-link-hover text-decoration-none" href="#"
wire:click="setCompany({{ $company->id }})">
{{ $company->name }}
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
class="bi bi-chevron-right" viewBox="0 0 16 16">
<path fill-rule="evenodd"
d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708" />
</svg>
</a>
</td>
@foreach ($complexes as $complex)
@php($paymentable = $company->getPaymentable($complex))
<td>
<td class="align-middle">
@if ($paymentable->value == null)
<div class="dropdown">
<button class="btn btn-light btn-sm" type="button" data-bs-toggle="dropdown"
<button class="btn btn-light" type="button" data-bs-toggle="dropdown"
aria-expanded="false">
Не установлено
</button>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item " href="#">
<input class="form-control form-control-sm" type="text"
placeholder="Процент вознаграждения" wire:model = "value"
<span class="badge text-dark">Введите размер вознаграждения:
</span>
<div class="input-group mb-3">
<span class="input-group-text" id="basic-addon1">
<svg xmlns="http://www.w3.org/2000/svg" width="20"
height="20" fill="currentColor" class="bi bi-percent"
viewBox="0 0 16 16">
<path
d="M13.442 2.558a.625.625 0 0 1 0 .884l-10 10a.625.625 0 1 1-.884-.884l10-10a.625.625 0 0 1 .884 0M4.5 6a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3m0 1a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5m7 6a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3m0 1a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5" />
</svg>
</span>
<input class="form-control" type="text"
placeholder="Вознаграждение"
value="{{ $paymentable->value }}" wire:model = "newValue"
wire:keydown.enter="setPaymentValueForCompany({{ $company->id }}, {{ $complex->id }})">
</div>
</a>
</li>
</ul>
</div>
@elseif($paymentable->value == -1)
<div class="dropdown">
<button class="btn btn-light btn-sm" type="button" data-bs-toggle="dropdown"
<button class="btn btn-light" type="button" data-bs-toggle="dropdown"
aria-expanded="false">
Наследовать
</button>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item " href="#">
<input class="form-control form-control-sm" type="text"
placeholder="Процент вознаграждения" wire:model = "value"
<span class="badge text-dark">Введите размер вознаграждения:
</span>
<div class="input-group mb-3">
<span class="input-group-text" id="basic-addon1">
<svg xmlns="http://www.w3.org/2000/svg" width="20"
height="20" fill="currentColor" class="bi bi-percent"
viewBox="0 0 16 16">
<path
d="M13.442 2.558a.625.625 0 0 1 0 .884l-10 10a.625.625 0 1 1-.884-.884l10-10a.625.625 0 0 1 .884 0M4.5 6a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3m0 1a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5m7 6a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3m0 1a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5" />
</svg>
</span>
<input class="form-control" type="text"
placeholder="Вознаграждение"
value="{{ $paymentable->value }}" wire:model = "newValue"
wire:keydown.enter="setPaymentValueForCompany({{ $company->id }}, {{ $complex->id }})">
</div>
</a>
</li>
<li>
@ -66,10 +103,23 @@
<ul class="dropdown-menu">
<li>
<a class="dropdown-item " href="#">
<input class="form-control form-control-sm" type="text"
placeholder="Процент вознаграждения"
value="{{ $paymentable->value }}" wire:model = "value"
<span class="badge text-dark">Введите размер вознаграждения:
</span>
<div class="input-group mb-3">
<span class="input-group-text" id="basic-addon1">
<svg xmlns="http://www.w3.org/2000/svg" width="20"
height="20" fill="currentColor" class="bi bi-percent"
viewBox="0 0 16 16">
<path
d="M13.442 2.558a.625.625 0 0 1 0 .884l-10 10a.625.625 0 1 1-.884-.884l10-10a.625.625 0 0 1 .884 0M4.5 6a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3m0 1a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5m7 6a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3m0 1a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5" />
</svg>
</span>
<input class="form-control" type="text"
placeholder="Вознаграждение"
value="{{ $paymentable->value }}"
wire:model.lazy = "newValue"
wire:keydown.enter="setPaymentValueForCompany({{ $company->id }}, {{ $complex->id }})">
</div>
</a>
</li>
<li>
@ -85,13 +135,10 @@
@endif
</td>
@endforeach
<td>
<button class="btn btn-light" wire:click="setCompany({{ $company->id }})">
<i class="bi bi-chevron-right"></i>
</button>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>

View File

@ -6,7 +6,7 @@
use App\Models\Complex;
trait Paymentable
{
private $defaultValue = null; // -1 || null
private $defaultValue = -1; // -1 || null
protected static function boot()
{
parent::boot();
@ -15,11 +15,6 @@ protected static function boot()
{
});
static::deleted(function ($item)
{
});
}
private function getClassName()

View File

@ -5,6 +5,10 @@ .bg-primary {
border-color: #ce4711 !important;
}
label {
color: rgba(var(--bs-body-color-rgb), .65);
}
.btn-secondary,
.btn-secondary:disabled {
color: white;