contracts module updated
This commit is contained in:
parent
c1397ae4a7
commit
2a8fa63369
@ -56,9 +56,10 @@ public function __invoke(Request $request)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$password = $user->setForcedPassword(false);
|
$password = $user->setForcedPassword(false);
|
||||||
$adminUser = User::find($admin->user_id);
|
//$adminUser = User::find($admin->user_id);
|
||||||
$adminUser->notify(instance: new UserRegistered($user->email, password: $password));
|
//$adminUser->notify(new UserRegistered($user->email, password: $password));
|
||||||
return redirect()->route('company.agents.table')->with('success', 'thank you');
|
//return redirect()->route('company.agents.table')->with('success', 'thank you');
|
||||||
|
return back()->with('success', 'Пароль для пользователя установлен: ' . $password);
|
||||||
}
|
}
|
||||||
return to_route('company.agents.table');
|
return to_route('company.agents.table');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Company;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Models\Company\CompanyAdmin;
|
||||||
|
use App\Models\Agent\Agent;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
use App\Notifications\UserRegistered;
|
||||||
|
|
||||||
|
class ResetAgentPasswordController extends Controller
|
||||||
|
{
|
||||||
|
public function __invoke(Request $request, Agent $agent)
|
||||||
|
{
|
||||||
|
$admin = CompanyAdmin::where('user_id', auth()->id());
|
||||||
|
if (!$admin->count())
|
||||||
|
{
|
||||||
|
abort(404);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$admin = $admin->first();
|
||||||
|
if ($agent->company_id != $admin->company_id)
|
||||||
|
{
|
||||||
|
return back();
|
||||||
|
}
|
||||||
|
$user = $agent->user;
|
||||||
|
|
||||||
|
if ($request->sendToEmail)
|
||||||
|
{
|
||||||
|
$user->setForcedPassword();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$password = $user->setForcedPassword(false);
|
||||||
|
return back()->with('success', 'Пароль для пользователя "' . $user->name . '" сброшен. Новый пароль: ' . $password);
|
||||||
|
}
|
||||||
|
return back();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -145,7 +145,7 @@ public function save()
|
|||||||
,
|
,
|
||||||
'complex_id' => $this->client['complexId']
|
'complex_id' => $this->client['complexId']
|
||||||
];
|
];
|
||||||
$data['confirm_token'] = $this->client['confirmToken'] = hash('sha256', json_encode($data));
|
//$data['confirm_token'] = $this->client['confirmToken'] = hash('sha256', json_encode($data));
|
||||||
|
|
||||||
if ($newDeal = Deal::create($data))
|
if ($newDeal = Deal::create($data))
|
||||||
{
|
{
|
||||||
@ -166,8 +166,6 @@ public function save()
|
|||||||
}
|
}
|
||||||
public function sendToBitrix(Deal $deal)
|
public function sendToBitrix(Deal $deal)
|
||||||
{
|
{
|
||||||
//$user = auth()->user();
|
|
||||||
//$agent = Agent::where(column: 'user_id', $user->id)->first();
|
|
||||||
$agent = $deal->agent;
|
$agent = $deal->agent;
|
||||||
$agentName = $agent->user->getPartialsName();
|
$agentName = $agent->user->getPartialsName();
|
||||||
$data = [
|
$data = [
|
||||||
@ -179,7 +177,7 @@ public function sendToBitrix(Deal $deal)
|
|||||||
'BROKER_PHONE' => $agent->user->phone,
|
'BROKER_PHONE' => $agent->user->phone,
|
||||||
'BROKER_INN' => $agent->company->inn,
|
'BROKER_INN' => $agent->company->inn,
|
||||||
'OBJECT_NAME' => Complex::find($this->client['complexId'])->name,
|
'OBJECT_NAME' => Complex::find($this->client['complexId'])->name,
|
||||||
'CALLBACK_URL' => route('api.client', ['hash' => $this->client['confirmToken']]),
|
'CALLBACK_URL' => route('api.client', ['hash' => $deal->confirmToken]),
|
||||||
];
|
];
|
||||||
$sender = new SendClient($deal->id, $data);
|
$sender = new SendClient($deal->id, $data);
|
||||||
$response = $sender->send();
|
$response = $sender->send();
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
class SendClient
|
class SendClient
|
||||||
{
|
{
|
||||||
private $IBLOCK_TYPE_ID = 'lists';
|
private $IBLOCK_TYPE_ID = 'lists';
|
||||||
|
|
||||||
//CONFIG для Альфы
|
//CONFIG для Альфы
|
||||||
@ -46,7 +46,10 @@ public function __construct($id, $data)
|
|||||||
$this->data = $finalData;
|
$this->data = $finalData;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
public function setBitrixId($id)
|
||||||
|
{
|
||||||
|
$this->data['PROPERTY_123'] = $id;
|
||||||
|
}
|
||||||
public function send()
|
public function send()
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
@ -58,4 +61,4 @@ public function send()
|
|||||||
$sender = new BitrixSender($this->URL, $data);
|
$sender = new BitrixSender($this->URL, $data);
|
||||||
return $sender->send();
|
return $sender->send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -42,14 +42,18 @@ public function contract()
|
|||||||
|
|
||||||
protected static function booted(): void
|
protected static function booted(): void
|
||||||
{
|
{
|
||||||
|
|
||||||
|
static::creating(function (Deal $deal)
|
||||||
|
{
|
||||||
|
$deal->confirm_token = hash('sha256', json_encode($deal->all()));
|
||||||
|
});
|
||||||
|
|
||||||
static::created(function (Deal $deal)
|
static::created(function (Deal $deal)
|
||||||
{
|
{
|
||||||
UserRole::create([
|
UserRole::create([
|
||||||
'user_id' => $deal->client_id,
|
'user_id' => $deal->client_id,
|
||||||
'role_id' => Role::CLIENT
|
'role_id' => Role::CLIENT
|
||||||
]);
|
]);
|
||||||
|
|
||||||
//$this->notify();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
static::deleted(function (Deal $deal)
|
static::deleted(function (Deal $deal)
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
use App\Models\Deal\DealStatus;
|
use App\Models\Deal\DealStatus;
|
||||||
use Modules\Bitrix\Models\BitrixId;
|
use Modules\Bitrix\Models\BitrixId;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Models\Bitrix\SendClient;
|
||||||
//use App\Models\User\UserRole;
|
//use App\Models\User\UserRole;
|
||||||
//use App\Models\User\Role;
|
//use App\Models\User\Role;
|
||||||
|
|
||||||
@ -61,7 +62,7 @@ public function syncDeals(Agent $agent)
|
|||||||
;
|
;
|
||||||
$dealItem = false;
|
$dealItem = false;
|
||||||
$bitrixId = BitrixId::where('bx_id', $deal['deal']['deal_id'])
|
$bitrixId = BitrixId::where('bx_id', $deal['deal']['deal_id'])
|
||||||
->where('bitrixable_type', get_class(new Deal()));
|
->where('bitrixable_type', Deal::class);
|
||||||
//Загрузка сделок
|
//Загрузка сделок
|
||||||
if ($bitrixId->count() == 0)
|
if ($bitrixId->count() == 0)
|
||||||
{
|
{
|
||||||
@ -90,6 +91,38 @@ public function syncDeals(Agent $agent)
|
|||||||
'plan7_id' => $inDeal['plan7_id']
|
'plan7_id' => $inDeal['plan7_id']
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
$this->sendDealToBitrix($dealItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendDealToBitrix(Deal $deal)
|
||||||
|
{
|
||||||
|
$deal->refresh();
|
||||||
|
$client = $deal->user;
|
||||||
|
$agent = $deal->agent;
|
||||||
|
$clientName = $client->getPartialsName();
|
||||||
|
$agentName = $agent->user->getPartialsName();
|
||||||
|
$data = [
|
||||||
|
'CLIENT_FIRST_NAME' => $clientName['firstName'],
|
||||||
|
'CLIENT_SECOND_NAME' => $clientName['secondName'],
|
||||||
|
'CLIENT_PHONE' => $client->phone,
|
||||||
|
'BROKER_FIRST_NAME' => $agentName['firstName'],
|
||||||
|
'BROKER_SECOND_NAME' => $agentName['secondName'],
|
||||||
|
'BROKER_PHONE' => $agent->user->phone,
|
||||||
|
'BROKER_INN' => $agent->company->inn,
|
||||||
|
'OBJECT_NAME' => $deal->complex->name,
|
||||||
|
'CALLBACK_URL' => route('api.client', ['hash' => $deal->confirm_token]),
|
||||||
|
];
|
||||||
|
$sender = new SendClient($deal->id, $data);
|
||||||
|
$sender->setBitrixId($deal->bitrixId());
|
||||||
|
$response = $sender->send();
|
||||||
|
if ($response)
|
||||||
|
{
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@
|
|||||||
{{ __($userRole->role->name) }}
|
{{ __($userRole->role->name) }}
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
{{ $userRole->created_at->diffForHumans() }}
|
{{ $userRole->created_at?->diffForHumans() }}
|
||||||
</td>
|
</td>
|
||||||
<td class="text-end">
|
<td class="text-end">
|
||||||
<div class="dropdown" style="">
|
<div class="dropdown" style="">
|
||||||
|
|||||||
@ -50,7 +50,7 @@
|
|||||||
{{ $user->phone }}
|
{{ $user->phone }}
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
{{ $user->created_at->diffForHumans() }}
|
{{ $user->created_at?->diffForHumans() }}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="dropdown" style="">
|
<div class="dropdown" style="">
|
||||||
|
|||||||
@ -9,18 +9,44 @@
|
|||||||
use App\Models\Deal\Deal;
|
use App\Models\Deal\Deal;
|
||||||
use App\Models\Deal\Contract;
|
use App\Models\Deal\Contract;
|
||||||
use App\Models\Deal\ContractStatus;
|
use App\Models\Deal\ContractStatus;
|
||||||
|
use App\Models\User\UserRole;
|
||||||
|
use App\Models\User\Role;
|
||||||
|
use App\Models\Company\CompanyAdmin;
|
||||||
|
|
||||||
class ContractsTableLivewire extends Component
|
class ContractsTableLivewire extends Component
|
||||||
{
|
{
|
||||||
public function mount()
|
public function mount()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
function getSelectingAgents()
|
||||||
|
{
|
||||||
|
if (
|
||||||
|
$userRole =
|
||||||
|
UserRole::where('user_id', auth()->id())
|
||||||
|
->where('role_id', Role::COMPANY_ADMIN)
|
||||||
|
->count() == 1
|
||||||
|
)
|
||||||
|
{
|
||||||
|
$companyAdmin = CompanyAdmin::where('user_id', auth()->id())->first();
|
||||||
|
return $agentsIds = Agent::where('company_id', $companyAdmin->company_id)->pluck('id');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return [auth()->id()];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
$contracts = Contract::all();
|
|
||||||
|
$contracts = Contract::whereHas('deal', function ($dealSubQuery)
|
||||||
|
{
|
||||||
|
$dealSubQuery->with('deals')
|
||||||
|
->whereIn('agent_id', $this->getSelectingAgents());
|
||||||
|
});
|
||||||
|
|
||||||
return view('contracts::livewire.table.index', [
|
return view('contracts::livewire.table.index', [
|
||||||
'contracts' => $contracts,
|
'contracts' => $contracts->get(),
|
||||||
'statuses' => ContractStatus::class
|
'statuses' => ContractStatus::class
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,6 @@
|
|||||||
<label class="btn p-2 fs-5" for="option7">Оконченные</label>
|
<label class="btn p-2 fs-5" for="option7">Оконченные</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="ms-auto hstack gap-2">
|
<div class="ms-auto hstack gap-2">
|
||||||
<div>Всего: 136 договоров</div>
|
|
||||||
<button type="button" class="btn bg-white p-3 fw-bold border rounded-3 border-1" data-bs-toggle="modal"
|
<button type="button" class="btn bg-white p-3 fw-bold border rounded-3 border-1" data-bs-toggle="modal"
|
||||||
data-bs-target="#contractFilterModal">
|
data-bs-target="#contractFilterModal">
|
||||||
Фильтр <i class="bi bi-person-plus"></i>
|
Фильтр <i class="bi bi-person-plus"></i>
|
||||||
|
|||||||
@ -30,10 +30,25 @@
|
|||||||
{{ $contract->square }}
|
{{ $contract->square }}
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
{{ $contract->price }}
|
<?php
|
||||||
|
$price = Number::forHumans($contract->price, precision: 2);
|
||||||
|
$price = str_replace('million', 'млн', $price);
|
||||||
|
$price = str_replace('thousand', 'тыс', $price);
|
||||||
|
$price = $price . ' ₽';
|
||||||
|
$price = str_replace(' ', ' ', $price);
|
||||||
|
?>
|
||||||
|
{!! $price !!}
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
{{ $contract->reward }}
|
<?php
|
||||||
|
$contract->reward = $contract->reward ? $contract->reward : 0;
|
||||||
|
$reward = Number::forHumans($contract->reward, precision: 2);
|
||||||
|
$reward = str_replace('million', 'млн', $reward);
|
||||||
|
$reward = str_replace('thousand', 'тыс', $reward);
|
||||||
|
$reward = $reward . ' ₽';
|
||||||
|
$reward = str_replace(' ', ' ', $reward);
|
||||||
|
?>
|
||||||
|
{!! $reward !!}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="py-1 px-3 border rounded rounded-5"
|
<div class="py-1 px-3 border rounded rounded-5"
|
||||||
|
|||||||
@ -87,7 +87,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-10 px-0 px-md-4">
|
<div class="col-10 px-0 px-md-4">
|
||||||
@if (session('success'))
|
@if (session('success'))
|
||||||
|
<div class="alert alert-success">
|
||||||
{{ session('success') }}
|
{{ session('success') }}
|
||||||
|
</div>
|
||||||
@endif
|
@endif
|
||||||
@foreach ($errors->all() as $error)
|
@foreach ($errors->all() as $error)
|
||||||
{{ $error }}
|
{{ $error }}
|
||||||
|
|||||||
@ -4,9 +4,6 @@
|
|||||||
<tbody class="">
|
<tbody class="">
|
||||||
@foreach ($agents as $num => $agent)
|
@foreach ($agents as $num => $agent)
|
||||||
<tr>
|
<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">
|
<td class="fw-semibold fs-5 align-middle">
|
||||||
{{ $agent->user->name }}
|
{{ $agent->user->name }}
|
||||||
@if (env('APP_DEBUG'))
|
@if (env('APP_DEBUG'))
|
||||||
@ -20,18 +17,25 @@
|
|||||||
{{ $agent->user->email }}
|
{{ $agent->user->email }}
|
||||||
</td>
|
</td>
|
||||||
@if (!$agent->trashed())
|
@if (!$agent->trashed())
|
||||||
<td class="align-middle text-center bg-white">
|
<td class="align-middle text-center">
|
||||||
<a class="btn"
|
<div class="dropdown" style="">
|
||||||
|
<button class="btn btn-light" type="button" id="dropdownMenuButton"
|
||||||
|
data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||||
|
<i class="bi bi-three-dots-vertical"></i>
|
||||||
|
</button>
|
||||||
|
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
|
||||||
|
<form action="{{ route('company.agent.password.reset', ['agent' => $agent]) }}"
|
||||||
|
method="post">
|
||||||
|
@csrf
|
||||||
|
<input type="submit" class="dropdown-item" value="Сбросить пароль">
|
||||||
|
</form>
|
||||||
|
<a class="dropdown-item"
|
||||||
wire:confirm = "Выбранный агент потеряет доступ к личному кабинету и больше не сможет создавать новые контакты.\nПродолжить?"
|
wire:confirm = "Выбранный агент потеряет доступ к личному кабинету и больше не сможет создавать новые контакты.\nПродолжить?"
|
||||||
wire:click = "dismiss({{ $agent->id }})">
|
wire:click = "dismiss({{ $agent->id }})">
|
||||||
<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>
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</td>
|
</td>
|
||||||
@else
|
@else
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
|
|||||||
@ -45,6 +45,7 @@
|
|||||||
Route::post('/company/{company}/details/', [App\Http\Controllers\Company\DetailsController::class, 'store'])->name('company.details.store');
|
Route::post('/company/{company}/details/', [App\Http\Controllers\Company\DetailsController::class, 'store'])->name('company.details.store');
|
||||||
Route::get('/agents/table', [App\Http\Controllers\Company\AgentsTableController::class, 'index'])->name('company.agents.table');
|
Route::get('/agents/table', [App\Http\Controllers\Company\AgentsTableController::class, 'index'])->name('company.agents.table');
|
||||||
Route::post('/company/agents/store/', App\Http\Controllers\Company\CreateAgentController::class)->name('company.agents.store');
|
Route::post('/company/agents/store/', App\Http\Controllers\Company\CreateAgentController::class)->name('company.agents.store');
|
||||||
|
Route::post('/company/agents/{agent}/password/reset/', App\Http\Controllers\Company\ResetAgentPasswordController::class)->name('company.agent.password.reset');
|
||||||
Route::get('/company/agents/{agent}/delete', App\Http\Controllers\Company\DeleteAgentController::class)->name('company.agents.delete');
|
Route::get('/company/agents/{agent}/delete', App\Http\Controllers\Company\DeleteAgentController::class)->name('company.agents.delete');
|
||||||
Route::get('/company/agents/{agent}/restore', App\Http\Controllers\Company\RestoreAgentController::class)->name('company.agents.restore');
|
Route::get('/company/agents/{agent}/restore', App\Http\Controllers\Company\RestoreAgentController::class)->name('company.agents.restore');
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user