Compare commits
2 Commits
7d163e0412
...
a3280091c5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a3280091c5 | ||
|
|
9363bbf8fc |
@ -6,12 +6,12 @@
|
|||||||
use Livewire\WithPagination;
|
use Livewire\WithPagination;
|
||||||
use Livewire\WithoutUrlPagination;
|
use Livewire\WithoutUrlPagination;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
use App\Models\Agent\Agent;
|
use App\Models\Agent\Agent;
|
||||||
use App\Models\Company\CompanyAdmin;
|
use App\Models\Company\CompanyAdmin;
|
||||||
use App\Models\Deal\Deal;
|
use App\Models\Deal\Deal;
|
||||||
|
|
||||||
use App\Models\Deal\DealStatus;
|
use App\Models\Deal\DealStatus;
|
||||||
|
use App\Models\Deal\Client;
|
||||||
class ClientsTable extends Component
|
class ClientsTable extends Component
|
||||||
{
|
{
|
||||||
use WithPagination, WithoutUrlPagination;
|
use WithPagination, WithoutUrlPagination;
|
||||||
@ -32,48 +32,85 @@ public function getDeals()
|
|||||||
$deals = false;
|
$deals = false;
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
|
|
||||||
|
$clients = false;
|
||||||
|
|
||||||
if ($admin = CompanyAdmin::where('user_id', $user->id)->first())
|
if ($admin = CompanyAdmin::where('user_id', $user->id)->first())
|
||||||
{
|
{
|
||||||
$deals = Deal::whereIn('agent_id', function ($query) use ($admin)
|
/*$deals = Deal::whereIn('agent_id', function ($query) use ($admin)
|
||||||
{
|
{
|
||||||
$query->select('id');
|
$query->select('id');
|
||||||
$query->from('agents');
|
$query->from('agents');
|
||||||
$query->where('company_id', $admin->company_id);
|
$query->where('company_id', $admin->company_id);
|
||||||
|
});*/
|
||||||
|
$agentsOfCompany = Agent::where('company_id', $admin->company_id)->get()->pluck('id');
|
||||||
|
$clients = Client::whereIn('id', function ($query) use ($agentsOfCompany)
|
||||||
|
{
|
||||||
|
$query->select('client_id')
|
||||||
|
->from('deals')
|
||||||
|
->whereIn('agent_id', $agentsOfCompany);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
elseif ($agent = Agent::where('user_id', $user->id)->first())
|
elseif ($agent = Agent::where('user_id', $user->id)->first())
|
||||||
{
|
{
|
||||||
$deals = Deal::where('agent_id', $agent->id);
|
//$deals = Deal::where('agent_id', $agent->id);
|
||||||
|
|
||||||
|
$clients = Client::whereIn('id', function ($query) use ($agent)
|
||||||
|
{
|
||||||
|
$query->select('client_id')
|
||||||
|
->from('deals')
|
||||||
|
->where('agent_id', $agent->id);
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return $deals;
|
$clients = $clients->orderBy('name');
|
||||||
|
return $clients;
|
||||||
}
|
}
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
$deals = $this->getDeals();
|
$clients = $this->getDeals();
|
||||||
if ($this->status && $this->status == DealStatus::UNIQUE)
|
if ($this->status && $this->status == DealStatus::UNIQUE)
|
||||||
{
|
{
|
||||||
$deals = $deals
|
/*$deals = $deals
|
||||||
->whereIn('status', [DealStatus::UNIQUE])
|
->whereIn('status', [DealStatus::UNIQUE])
|
||||||
->orderBy('id', 'desc')->paginate($this->count, ['*'], 'unique_clients');
|
->orderBy('id', 'desc')->paginate($this->count, ['*'], 'unique_clients');*/
|
||||||
|
$clients = $clients->whereHas('deals', function ($query)
|
||||||
|
{
|
||||||
|
$query->where('status', DealStatus::UNIQUE);
|
||||||
|
})->paginate($this->count, ['*'], 'unique_clients');
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
elseif ($this->status && $this->status == DealStatus::NOT_UNIQUE)
|
elseif ($this->status && $this->status == DealStatus::NOT_UNIQUE)
|
||||||
{
|
{
|
||||||
$deals = $deals
|
/*$deals = $deals
|
||||||
->whereIn('status', [DealStatus::MODERATION, DealStatus::NEW , DealStatus::NOT_UNIQUE])
|
->whereIn('status', [DealStatus::MODERATION, DealStatus::NEW , DealStatus::NOT_UNIQUE])
|
||||||
->orderBy('id', 'desc')->paginate($this->count, ['*'], 'not_unique_clients');
|
->orderBy('id', 'desc')->paginate($this->count, ['*'], 'not_unique_clients');*/
|
||||||
|
$clients = $clients->whereHas('deals', function ($query)
|
||||||
|
{
|
||||||
|
$query->whereIn('status', [DealStatus::MODERATION, DealStatus::NEW , DealStatus::NOT_UNIQUE]);
|
||||||
|
})->paginate($this->count, ['*'], 'not_unique_clients');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$deals = $deals->orderBy('id', 'desc')->paginate($this->count, ['*'], 'all_clients');
|
/*$deals = $deals->orderBy('id', 'desc')->paginate($this->count, ['*'], 'all_clients');*/
|
||||||
|
$clients = $clients->paginate($this->count, ['*'], 'all_clients');
|
||||||
}
|
}
|
||||||
;
|
|
||||||
|
|
||||||
return view(
|
return view(
|
||||||
'livewire.clients-table',
|
'livewire.clients-table',
|
||||||
[
|
[
|
||||||
'deals' => $deals,
|
'clients' => $clients,
|
||||||
'statuses' => DealStatus::class
|
'statuses' => DealStatus::class
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
function getClients()
|
||||||
|
{
|
||||||
|
/*$clients = User::whereIn('id', function ($query)
|
||||||
|
{
|
||||||
|
|
||||||
|
});*/
|
||||||
|
$clients = false;
|
||||||
|
//$clients = Client::ofAgent();
|
||||||
|
return $clients;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
30
app/Models/Deal/Client.php
Normal file
30
app/Models/Deal/Client.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Deal;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
|
use Illuminate\Notifications\Notifiable;
|
||||||
|
use Laravel\Sanctum\HasApiTokens;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Models\Deal\Deal;
|
||||||
|
use App\Models\Agent\Agent;
|
||||||
|
class Client extends User
|
||||||
|
{
|
||||||
|
protected $table = 'users';
|
||||||
|
public function deals()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Deal::class, 'client_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dealsWithContracts()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Deal::class, 'client_id')->whereHas('contracts');
|
||||||
|
}
|
||||||
|
public function ofAgent(Agent $agent)
|
||||||
|
{
|
||||||
|
return $this->deals->where('agent_id', $agent->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -24,7 +24,6 @@ public function index(Request $request)
|
|||||||
{
|
{
|
||||||
$filter = $request->filter;
|
$filter = $request->filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('contracts::index', [
|
return view('contracts::index', [
|
||||||
'mode' => $mode,
|
'mode' => $mode,
|
||||||
'filter' => $filter
|
'filter' => $filter
|
||||||
|
|||||||
@ -3,6 +3,21 @@
|
|||||||
<form method="get" action="{{ Request::fullUrl() }}">
|
<form method="get" action="{{ Request::fullUrl() }}">
|
||||||
<div class="d-block d-md-flex mb-3">
|
<div class="d-block d-md-flex mb-3">
|
||||||
<div class="border rounded-3 border-1 p-1 bg-white">
|
<div class="border rounded-3 border-1 p-1 bg-white">
|
||||||
|
<?php
|
||||||
|
$filterFormArray = [];
|
||||||
|
foreach ($filter as $key => $filterValue) {
|
||||||
|
if (!is_array($filterValue)) {
|
||||||
|
$filterFormArray['filter[' . $key . ']'] = $filterValue;
|
||||||
|
} else {
|
||||||
|
foreach ($filterValue as $num => $value) {
|
||||||
|
$filterFormArray['filter[' . $key . '][' . $num . ']'] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
@foreach ($filterFormArray as $key => $filterValue)
|
||||||
|
<input type="hidden" name="{{ $key }}" value="{{ $filterValue }}">
|
||||||
|
@endforeach
|
||||||
<input type="radio" class="btn-check" name="mode" value="all" id="mode_all" autocomplete="off"
|
<input type="radio" class="btn-check" name="mode" value="all" id="mode_all" autocomplete="off"
|
||||||
onclick="this.form.submit()" {{ $mode == 'all' ? 'checked' : '' }}>
|
onclick="this.form.submit()" {{ $mode == 'all' ? 'checked' : '' }}>
|
||||||
<label class="btn p-2 fs-5" for="mode_all">Все</label>
|
<label class="btn p-2 fs-5" for="mode_all">Все</label>
|
||||||
@ -17,7 +32,7 @@
|
|||||||
|
|
||||||
<input type="radio" class="btn-check" name="mode" value="declined" id="mode_declined"
|
<input type="radio" class="btn-check" name="mode" value="declined" id="mode_declined"
|
||||||
autocomplete="off" onclick="this.form.submit()" {{ $mode == 'declined' ? 'checked' : '' }}>
|
autocomplete="off" onclick="this.form.submit()" {{ $mode == 'declined' ? 'checked' : '' }}>
|
||||||
<label class="btn p-2 fs-5" for="mode_declined">Отмененные</label>
|
<label class="btn p-2 fs-5" for="mode_declined">Отклоненные</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="ms-auto hstack gap-2">
|
<div class="ms-auto hstack gap-2">
|
||||||
<button type="button" class="lh-1 btn bg-white p-3 fw-bold border rounded-3 border-1"
|
<button type="button" class="lh-1 btn bg-white p-3 fw-bold border rounded-3 border-1"
|
||||||
|
|||||||
70
resources/views/livewire/clients-table.blade copy.php
Normal file
70
resources/views/livewire/clients-table.blade copy.php
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<div>
|
||||||
|
<div class="fs-5 bg-light p-0 m-0 border border-1 rounded-4 overflow-hidden">
|
||||||
|
@if ($deals->count() == 0)
|
||||||
|
<div class="text-center py-5">Нет данных для отображения</div>
|
||||||
|
@endif
|
||||||
|
<table class="table m-0">
|
||||||
|
<tbody class="">
|
||||||
|
@php($clientId = false)
|
||||||
|
@php($dealsCountForClient = 0)
|
||||||
|
@foreach ($deals as $deal)
|
||||||
|
<tr>
|
||||||
|
<!--<td>
|
||||||
|
<img src="../../images/icons/user.png" class="img-fluid align-middle" style="height: 50px;">
|
||||||
|
</td>-->
|
||||||
|
<td class="fw-semibold fs-5 align-middle">
|
||||||
|
{{ $deal->user->name }}
|
||||||
|
@if ($deal->status == $statuses::MODERATION)
|
||||||
|
<div>
|
||||||
|
<span class="badge text-bg-secondary">
|
||||||
|
На проверке уникальности
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</td>
|
||||||
|
@if ($mode == 'full')
|
||||||
|
<td class="align-middle">
|
||||||
|
{{ $deal->user->phone }}
|
||||||
|
</td>
|
||||||
|
<td class="align-middle">
|
||||||
|
{{ $deal->user->email }}
|
||||||
|
</td>
|
||||||
|
<td class="align-middle">
|
||||||
|
{{ $deal->complex->city->name }}
|
||||||
|
</td>
|
||||||
|
<td class="align-middle text-end d-none">
|
||||||
|
<a href="#" class="btn">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
|
||||||
|
fill="currentColor" class="bi bi-three-dots-vertical" viewBox="0 0 16 16">
|
||||||
|
<path
|
||||||
|
d="M9.5 13a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0m0-5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0m0-5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0" />
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
@if ($deal->contract)
|
||||||
|
<td class="align-middle text-center bg-white">
|
||||||
|
|
||||||
|
<a href="{{ route('contract', ['contract' => $deal->contract]) }}" class="btn">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
|
||||||
|
fill="currentColor" class="bi bi-arrow-right" viewBox="0 0 16 16">
|
||||||
|
<path fill-rule="evenodd"
|
||||||
|
d="M1 8a.5.5 0 0 1 .5-.5h11.793l-3.147-3.146a.5.5 0 0 1 .708-.708l4 4a.5.5 0 0 1 0 .708l-4 4a.5.5 0 0 1-.708-.708L13.293 8.5H1.5A.5.5 0 0 1 1 8" />
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</td>
|
||||||
|
@else
|
||||||
|
<td></td>
|
||||||
|
@endif
|
||||||
|
@endif
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
@if ($mode == 'full')
|
||||||
|
<div class="mt-3">
|
||||||
|
{{ $deals->links('vendor.pagination.bootstrap-5', ['scrollTo' => false]) }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
@ -1,68 +1,61 @@
|
|||||||
<div>
|
<div>
|
||||||
<div class="fs-5 bg-light p-0 m-0 border border-1 rounded-4 overflow-hidden">
|
<div class="fs-5 bg-light p-0 m-0 border border-1 rounded-4 overflow-hidden">
|
||||||
@if ($deals->count() == 0)
|
@if ($clients->count() == 0)
|
||||||
<div class="text-center py-5">Нет данных для отображения</div>
|
<div class="text-center py-5">Нет данных для отображения</div>
|
||||||
@endif
|
@endif
|
||||||
<table class="table m-0">
|
<div class="m-2">
|
||||||
<tbody class="">
|
@foreach ($clients as $client)
|
||||||
@foreach ($deals as $deal)
|
<div class="row my-2">
|
||||||
<tr>
|
<div class="col fw-semibold fs-5 align-middle">
|
||||||
<!--<td>
|
{{ $client->name }}
|
||||||
<img src="../../images/icons/user.png" class="img-fluid align-middle" style="height: 50px;">
|
|
||||||
</td>-->
|
|
||||||
<td class="fw-semibold fs-5 align-middle">
|
|
||||||
{{ $deal->user->name }}
|
|
||||||
@if ($deal->status == $statuses::MODERATION)
|
|
||||||
<div>
|
|
||||||
<span class="badge text-bg-secondary">
|
|
||||||
На проверке уникальности
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-1">
|
||||||
|
@if ($client->deals->count() > 1)
|
||||||
|
<span
|
||||||
|
class="badge rounded rounded-pill bg-primary">{{ $client->deals()->whereHas('contract')->count() }}</span>
|
||||||
@endif
|
@endif
|
||||||
</td>
|
</div>
|
||||||
@if ($mode == 'full')
|
@if ($mode == 'full')
|
||||||
<td class="align-middle">
|
<div class="col-3 align-middle">
|
||||||
{{ $deal->user->phone }}
|
{{ $client->phone }}
|
||||||
</td>
|
</div>
|
||||||
<td class="align-middle">
|
<div class="col-1">
|
||||||
{{ $deal->user->email }}
|
@if ($client->deals->count() == 1)
|
||||||
</td>
|
<a href="{{ route('contract', ['contract' => $client->deals->first()->contract]) }}"
|
||||||
<td class="align-middle">
|
class="btn">
|
||||||
{{ $deal->complex->city->name }}
|
|
||||||
</td>
|
|
||||||
<td class="align-middle text-end d-none">
|
|
||||||
<a href="#" class="btn">
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
|
||||||
fill="currentColor" class="bi bi-three-dots-vertical" viewBox="0 0 16 16">
|
fill="currentColor" class="bi bi-file-earmark-text" viewBox="0 0 16 16">
|
||||||
<path
|
<path
|
||||||
d="M9.5 13a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0m0-5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0m0-5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0" />
|
d="M5.5 7a.5.5 0 0 0 0 1h5a.5.5 0 0 0 0-1zM5 9.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5m0 2a.5.5 0 0 1 .5-.5h2a.5.5 0 0 1 0 1h-2a.5.5 0 0 1-.5-.5" />
|
||||||
|
<path
|
||||||
|
d="M9.5 0H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V4.5zm0 1v2A1.5 1.5 0 0 0 11 4.5h2V14a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1z" />
|
||||||
</svg>
|
</svg>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
@elseif($client->deals->count() > 1)
|
||||||
@if ($deal->contract)
|
<?php
|
||||||
<td class="align-middle text-center bg-white">
|
$filterRow = [];
|
||||||
|
foreach ($client->deals as $deal) {
|
||||||
<a href="{{ route('contract', ['contract' => $deal->contract]) }}" class="btn">
|
$filterRow[] = 'filter[deal_id][]=' . $deal->id;
|
||||||
|
}
|
||||||
|
$filterRow = implode('&', $filterRow);
|
||||||
|
?>
|
||||||
|
<a href="{{ route('contracts', [$filterRow]) }}" class="btn">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
|
||||||
fill="currentColor" class="bi bi-arrow-right" viewBox="0 0 16 16">
|
fill="currentColor" class="bi bi-arrow-right" viewBox="0 0 16 16">
|
||||||
<path fill-rule="evenodd"
|
<path fill-rule="evenodd"
|
||||||
d="M1 8a.5.5 0 0 1 .5-.5h11.793l-3.147-3.146a.5.5 0 0 1 .708-.708l4 4a.5.5 0 0 1 0 .708l-4 4a.5.5 0 0 1-.708-.708L13.293 8.5H1.5A.5.5 0 0 1 1 8" />
|
d="M1 8a.5.5 0 0 1 .5-.5h11.793l-3.147-3.146a.5.5 0 0 1 .708-.708l4 4a.5.5 0 0 1 0 .708l-4 4a.5.5 0 0 1-.708-.708L13.293 8.5H1.5A.5.5 0 0 1 1 8" />
|
||||||
</svg>
|
</svg>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
</td>
|
|
||||||
@else
|
|
||||||
<td></td>
|
|
||||||
@endif
|
@endif
|
||||||
|
</div>
|
||||||
@endif
|
@endif
|
||||||
</tr>
|
</div>
|
||||||
@endforeach
|
@endforeach
|
||||||
</tbody>
|
</div>
|
||||||
</table>
|
|
||||||
</div>
|
</div>
|
||||||
@if ($mode == 'full')
|
@if ($mode == 'full')
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
{{ $deals->links('vendor.pagination.bootstrap-5', ['scrollTo' => false]) }}
|
{{ $clients->links('vendor.pagination.bootstrap-5', ['scrollTo' => false]) }}
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user