clients table updated

This commit is contained in:
Thekindbull 2025-09-02 10:11:29 +08:00
parent 9363bbf8fc
commit a3280091c5
6 changed files with 212 additions and 68 deletions

View File

@ -6,12 +6,12 @@
use Livewire\WithPagination;
use Livewire\WithoutUrlPagination;
use App\Models\User;
use App\Models\Agent\Agent;
use App\Models\Company\CompanyAdmin;
use App\Models\Deal\Deal;
use App\Models\Deal\DealStatus;
use App\Models\Deal\Client;
class ClientsTable extends Component
{
use WithPagination, WithoutUrlPagination;
@ -32,48 +32,85 @@ public function getDeals()
$deals = false;
$user = auth()->user();
$clients = false;
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->from('agents');
$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())
{
$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()
{
$deals = $this->getDeals();
$clients = $this->getDeals();
if ($this->status && $this->status == DealStatus::UNIQUE)
{
$deals = $deals
/*$deals = $deals
->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)
{
$deals = $deals
/*$deals = $deals
->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
{
$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(
'livewire.clients-table',
[
'deals' => $deals,
'clients' => $clients,
'statuses' => DealStatus::class
]
);
}
function getClients()
{
/*$clients = User::whereIn('id', function ($query)
{
});*/
$clients = false;
//$clients = Client::ofAgent();
return $clients;
}
}

View 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);
}
}

View File

@ -24,7 +24,6 @@ public function index(Request $request)
{
$filter = $request->filter;
}
return view('contracts::index', [
'mode' => $mode,
'filter' => $filter

View File

@ -3,6 +3,21 @@
<form method="get" action="{{ Request::fullUrl() }}">
<div class="d-block d-md-flex mb-3">
<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"
onclick="this.form.submit()" {{ $mode == 'all' ? 'checked' : '' }}>
<label class="btn p-2 fs-5" for="mode_all">Все</label>

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

View File

@ -1,68 +1,61 @@
<div>
<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>
@endif
<table class="table m-0">
<tbody class="">
@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">
<div class="m-2">
@foreach ($clients as $client)
<div class="row my-2">
<div class="col fw-semibold fs-5 align-middle">
{{ $client->name }}
</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
</div>
@if ($mode == 'full')
<div class="col-3 align-middle">
{{ $client->phone }}
</div>
<div class="col-1">
@if ($client->deals->count() == 1)
<a href="{{ route('contract', ['contract' => $client->deals->first()->contract]) }}"
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">
fill="currentColor" class="bi bi-file-earmark-text" 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" />
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>
</a>
@elseif($client->deals->count() > 1)
<?php
$filterRow = [];
foreach ($client->deals as $deal) {
$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"
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>
@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>
@endif
</div>
@endforeach
</div>
</div>
@if ($mode == 'full')
<div class="mt-3">
{{ $deals->links('vendor.pagination.bootstrap-5', ['scrollTo' => false]) }}
{{ $clients->links('vendor.pagination.bootstrap-5', ['scrollTo' => false]) }}
</div>
@endif
</div>