contracts module updated
This commit is contained in:
parent
c1397ae4a7
commit
2a8fa63369
@ -56,9 +56,10 @@ public function __invoke(Request $request)
|
||||
else
|
||||
{
|
||||
$password = $user->setForcedPassword(false);
|
||||
$adminUser = User::find($admin->user_id);
|
||||
$adminUser->notify(instance: new UserRegistered($user->email, password: $password));
|
||||
return redirect()->route('company.agents.table')->with('success', 'thank you');
|
||||
//$adminUser = User::find($admin->user_id);
|
||||
//$adminUser->notify(new UserRegistered($user->email, password: $password));
|
||||
//return redirect()->route('company.agents.table')->with('success', 'thank you');
|
||||
return back()->with('success', 'Пароль для пользователя установлен: ' . $password);
|
||||
}
|
||||
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']
|
||||
];
|
||||
$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))
|
||||
{
|
||||
@ -166,8 +166,6 @@ public function save()
|
||||
}
|
||||
public function sendToBitrix(Deal $deal)
|
||||
{
|
||||
//$user = auth()->user();
|
||||
//$agent = Agent::where(column: 'user_id', $user->id)->first();
|
||||
$agent = $deal->agent;
|
||||
$agentName = $agent->user->getPartialsName();
|
||||
$data = [
|
||||
@ -179,7 +177,7 @@ public function sendToBitrix(Deal $deal)
|
||||
'BROKER_PHONE' => $agent->user->phone,
|
||||
'BROKER_INN' => $agent->company->inn,
|
||||
'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);
|
||||
$response = $sender->send();
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class SendClient
|
||||
{
|
||||
{
|
||||
private $IBLOCK_TYPE_ID = 'lists';
|
||||
|
||||
//CONFIG для Альфы
|
||||
@ -13,49 +13,52 @@ class SendClient
|
||||
private $URL = 'https://b24alfa.pro/rest/3165/v90a792nderzu0dj/lists.element.add.json';
|
||||
private $IBLOCK_ID = 27;
|
||||
private $ID;
|
||||
const NAME = "NAME";
|
||||
const NAME = "NAME";
|
||||
const CLIENT_SECOND_NAME = "PROPERTY_94";
|
||||
const CLIENT_FIRST_NAME = "PROPERTY_95";
|
||||
const CLIENT_PHONE = "PROPERTY_96";
|
||||
const CLIENT_FIRST_NAME = "PROPERTY_95";
|
||||
const CLIENT_PHONE = "PROPERTY_96";
|
||||
const BROKER_SECOND_NAME = "PROPERTY_97";
|
||||
const BROKER_FIRST_NAME = "PROPERTY_98";
|
||||
const BROKER_PHONE = "PROPERTY_99";
|
||||
const OBJECT_NAME = "PROPERTY_100";
|
||||
const CALLBACK_URL = "PROPERTY_105";
|
||||
const BROKER_FIRST_NAME = "PROPERTY_98";
|
||||
const BROKER_PHONE = "PROPERTY_99";
|
||||
const OBJECT_NAME = "PROPERTY_100";
|
||||
const CALLBACK_URL = "PROPERTY_105";
|
||||
private $data = [];
|
||||
|
||||
public function __construct($id, $data)
|
||||
{
|
||||
{
|
||||
$this->ID = env('BITRIX_CODE_PREFIX', '') . $id;
|
||||
$data = array_change_key_case($data, CASE_UPPER);
|
||||
$finalData = [];
|
||||
$refl = new \ReflectionClass(__CLASS__);
|
||||
$constants = $refl->getConstants();
|
||||
foreach ($constants as $constName => $constValue)
|
||||
{
|
||||
{
|
||||
foreach ($data as $key => $value)
|
||||
{
|
||||
{
|
||||
if ($constName == $key)
|
||||
{
|
||||
{
|
||||
$finalData[$constValue] = $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$finalData['NAME'] = $finalData[self::CLIENT_FIRST_NAME] . ' ' . $finalData[self::CLIENT_SECOND_NAME];
|
||||
$this->data = $finalData;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
public function setBitrixId($id)
|
||||
{
|
||||
$this->data['PROPERTY_123'] = $id;
|
||||
}
|
||||
public function send()
|
||||
{
|
||||
{
|
||||
$data = [
|
||||
'IBLOCK_TYPE_ID' => $this->IBLOCK_TYPE_ID,
|
||||
'IBLOCK_ID' => $this->IBLOCK_ID,
|
||||
'ELEMENT_CODE' => $this->ID,
|
||||
'FIELDS' => $this->data
|
||||
'IBLOCK_ID' => $this->IBLOCK_ID,
|
||||
'ELEMENT_CODE' => $this->ID,
|
||||
'FIELDS' => $this->data
|
||||
];
|
||||
$sender = new BitrixSender($this->URL, $data);
|
||||
return $sender->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -42,14 +42,18 @@ public function contract()
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
|
||||
static::creating(function (Deal $deal)
|
||||
{
|
||||
$deal->confirm_token = hash('sha256', json_encode($deal->all()));
|
||||
});
|
||||
|
||||
static::created(function (Deal $deal)
|
||||
{
|
||||
UserRole::create([
|
||||
'user_id' => $deal->client_id,
|
||||
'role_id' => Role::CLIENT
|
||||
]);
|
||||
|
||||
//$this->notify();
|
||||
});
|
||||
|
||||
static::deleted(function (Deal $deal)
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
use App\Models\Deal\DealStatus;
|
||||
use Modules\Bitrix\Models\BitrixId;
|
||||
use App\Models\User;
|
||||
use App\Models\Bitrix\SendClient;
|
||||
//use App\Models\User\UserRole;
|
||||
//use App\Models\User\Role;
|
||||
|
||||
@ -61,7 +62,7 @@ public function syncDeals(Agent $agent)
|
||||
;
|
||||
$dealItem = false;
|
||||
$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)
|
||||
{
|
||||
@ -90,6 +91,38 @@ public function syncDeals(Agent $agent)
|
||||
'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) }}
|
||||
</td>
|
||||
<td class="align-middle">
|
||||
{{ $userRole->created_at->diffForHumans() }}
|
||||
{{ $userRole->created_at?->diffForHumans() }}
|
||||
</td>
|
||||
<td class="text-end">
|
||||
<div class="dropdown" style="">
|
||||
|
||||
@ -20,9 +20,9 @@
|
||||
|
||||
<div class="ms-auto p-2">
|
||||
<!--<button type="button" class="btn btn-primary py-2 px-3 fs-5" data-bs-toggle="modal"
|
||||
data-bs-target="#createAgentModal">
|
||||
<i class="bi bi-person-plus"></i>
|
||||
</button>-->
|
||||
data-bs-target="#createAgentModal">
|
||||
<i class="bi bi-person-plus"></i>
|
||||
</button>-->
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@ -50,7 +50,7 @@
|
||||
{{ $user->phone }}
|
||||
</td>
|
||||
<td class="align-middle">
|
||||
{{ $user->created_at->diffForHumans() }}
|
||||
{{ $user->created_at?->diffForHumans() }}
|
||||
</td>
|
||||
<td>
|
||||
<div class="dropdown" style="">
|
||||
|
||||
@ -9,18 +9,44 @@
|
||||
use App\Models\Deal\Deal;
|
||||
use App\Models\Deal\Contract;
|
||||
use App\Models\Deal\ContractStatus;
|
||||
use App\Models\User\UserRole;
|
||||
use App\Models\User\Role;
|
||||
use App\Models\Company\CompanyAdmin;
|
||||
|
||||
class ContractsTableLivewire extends Component
|
||||
{
|
||||
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()
|
||||
{
|
||||
$contracts = Contract::all();
|
||||
|
||||
$contracts = Contract::whereHas('deal', function ($dealSubQuery)
|
||||
{
|
||||
$dealSubQuery->with('deals')
|
||||
->whereIn('agent_id', $this->getSelectingAgents());
|
||||
});
|
||||
|
||||
return view('contracts::livewire.table.index', [
|
||||
'contracts' => $contracts,
|
||||
'contracts' => $contracts->get(),
|
||||
'statuses' => ContractStatus::class
|
||||
]);
|
||||
}
|
||||
|
||||
@ -12,7 +12,6 @@
|
||||
<label class="btn p-2 fs-5" for="option7">Оконченные</label>
|
||||
</div>
|
||||
<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"
|
||||
data-bs-target="#contractFilterModal">
|
||||
Фильтр <i class="bi bi-person-plus"></i>
|
||||
|
||||
@ -30,10 +30,25 @@
|
||||
{{ $contract->square }}
|
||||
</td>
|
||||
<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 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>
|
||||
<div class="py-1 px-3 border rounded rounded-5"
|
||||
|
||||
@ -87,7 +87,9 @@
|
||||
</div>
|
||||
<div class="col-10 px-0 px-md-4">
|
||||
@if (session('success'))
|
||||
{{ session('success') }}
|
||||
<div class="alert alert-success">
|
||||
{{ session('success') }}
|
||||
</div>
|
||||
@endif
|
||||
@foreach ($errors->all() as $error)
|
||||
{{ $error }}
|
||||
|
||||
@ -4,9 +4,6 @@
|
||||
<tbody class="">
|
||||
@foreach ($agents as $num => $agent)
|
||||
<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">
|
||||
{{ $agent->user->name }}
|
||||
@if (env('APP_DEBUG'))
|
||||
@ -20,18 +17,25 @@
|
||||
{{ $agent->user->email }}
|
||||
</td>
|
||||
@if (!$agent->trashed())
|
||||
<td class="align-middle text-center bg-white">
|
||||
<a class="btn"
|
||||
wire:confirm = "Выбранный агент потеряет доступ к личному кабинету и больше не сможет создавать новые контакты.\nПродолжить?"
|
||||
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>
|
||||
<td class="align-middle text-center">
|
||||
<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:click = "dismiss({{ $agent->id }})">
|
||||
Уволить
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
@else
|
||||
<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::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/{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}/restore', App\Http\Controllers\Company\RestoreAgentController::class)->name('company.agents.restore');
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user