fix of contracts
This commit is contained in:
parent
b400487e0c
commit
043653df9c
@ -27,7 +27,8 @@ public function __invoke(Deal $deal, Request $request)
|
||||
'date' => $request->date,//дата ДДУ
|
||||
'reg_date' => $request->reg_date,//Дата регистрации ДДУ
|
||||
'payment_type' => $request->payment_type,//Вид оплаты
|
||||
'plan7_id' => $request->plan7_id
|
||||
'plan7_id' => $request->plan7_id,
|
||||
'base64_image' => $request->plan_image
|
||||
]
|
||||
);
|
||||
$agent = $deal->agent;
|
||||
|
||||
@ -38,6 +38,7 @@ public function setAgentId(Request $request, Agent $agent)
|
||||
}
|
||||
public function syncDeals(Agent $agent)
|
||||
{
|
||||
$importedCount = 0;
|
||||
$url = 'https://b24alfa.pro/channels/lk/getDealsOfContact?id=' . $agent->bitrixId();
|
||||
$data = file_get_contents($url);
|
||||
$deals = json_decode($data, true);
|
||||
@ -51,7 +52,7 @@ public function syncDeals(Agent $agent)
|
||||
//Загрузка контактов
|
||||
if ($deal['contacts'][0]['phone'])
|
||||
{
|
||||
$client = User::createOrFirst(
|
||||
$client = User::firstOrCreate(
|
||||
['phone' => $deal['contacts'][0]['phone']],
|
||||
[
|
||||
'name' => $deal['contacts'][0]['name'],
|
||||
@ -60,7 +61,7 @@ public function syncDeals(Agent $agent)
|
||||
);
|
||||
}
|
||||
;
|
||||
$dealItem = false;
|
||||
$dealItem = false; //собственный, не из битрикса
|
||||
$bitrixId = BitrixId::where('bx_id', $deal['deal']['deal_id'])
|
||||
->where('bitrixable_type', Deal::class);
|
||||
//Загрузка сделок
|
||||
@ -80,7 +81,10 @@ public function syncDeals(Agent $agent)
|
||||
$dealItem = Deal::find($bitrixId->bitrixable_id);
|
||||
}
|
||||
;
|
||||
$inDeal = $deal['deal'];
|
||||
$inDeal = $deal['deal'];//входящие данные по сделке
|
||||
if ($dealItem)
|
||||
{
|
||||
$importedCount++;
|
||||
$contract = Contract::updateOrCreate(
|
||||
['deal_id' => $dealItem->id],
|
||||
[
|
||||
@ -94,6 +98,8 @@ public function syncDeals(Agent $agent)
|
||||
$this->sendDealToBitrix($dealItem);
|
||||
}
|
||||
}
|
||||
return back()->with('success', 'Импортировано ' . $importedCount . ' сделок');
|
||||
}
|
||||
|
||||
function sendDealToBitrix(Deal $deal)
|
||||
{
|
||||
|
||||
@ -34,4 +34,19 @@ public function setBitrixId($id): bool
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::deleted(function ($bitrixableItem)
|
||||
{
|
||||
$this->bitrixable()->delete();
|
||||
});
|
||||
|
||||
static::forceDeleted(function ($bitrixableItem)
|
||||
{
|
||||
$this->bitrixable()->delete();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -11,9 +11,9 @@
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('contracts', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->timestamps();
|
||||
Schema::table('client_contract', function (Blueprint $table)
|
||||
{
|
||||
$table->longText('base64_image')->nullable(); // Or not nullable if required
|
||||
});
|
||||
}
|
||||
|
||||
@ -22,6 +22,6 @@ public function up(): void
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('contracts');
|
||||
//Schema::dropIfExists('contracts');
|
||||
}
|
||||
};
|
||||
@ -16,4 +16,18 @@ public function index()
|
||||
'status' => 'all'
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete(Contract $contract)
|
||||
{
|
||||
$deal = $contract->deal();
|
||||
if ($contract->delete())
|
||||
{
|
||||
if ($deal->delete())
|
||||
{
|
||||
return back()->with('success', 'Договор был успешно удален из базы данных');
|
||||
|
||||
}
|
||||
}
|
||||
return back()->withErrors('Не удалось корректно удалить договор и сделку. Попробуйте позже.');
|
||||
}
|
||||
}
|
||||
@ -25,7 +25,8 @@ class Contract extends Model
|
||||
'date',//дата ДДУ
|
||||
'reg_date',//Дата регистрации ДДУ
|
||||
'payment_type',//Вид оплаты
|
||||
'plan7_id'//ид помещения из plan7
|
||||
'plan7_id',//ид помещения из plan7
|
||||
'base64_image'
|
||||
];
|
||||
|
||||
public function deal()
|
||||
|
||||
@ -3,9 +3,30 @@
|
||||
class ContractStatus
|
||||
{
|
||||
const NEW = 'NEW';
|
||||
const TREATY = 'TREATY'; //переговоры
|
||||
const TREATY = 'TREATY'; //Выплачено
|
||||
const RESERVATION = 'RESERVATION'; //бронь
|
||||
const SUCCESS = "SUCCESS";
|
||||
const DECLINE = "DECLINE";
|
||||
}
|
||||
|
||||
public static function getName($status)
|
||||
{
|
||||
return __('contracts.status_' . $status);
|
||||
}
|
||||
public static function getHtmlColor($status)
|
||||
{
|
||||
switch ( $status )
|
||||
{
|
||||
case self::NEW:
|
||||
return '#ccc';
|
||||
case self::RESERVATION:
|
||||
return '#4fb5e5';
|
||||
case self::TREATY:
|
||||
return '#e3e54f';
|
||||
case self::SUCCESS:
|
||||
return '#4fe576';
|
||||
case self::DECLINE:
|
||||
return '#eb612c';
|
||||
}
|
||||
return '#ccc';
|
||||
}
|
||||
}
|
||||
@ -6,4 +6,6 @@
|
||||
Route::middleware(['auth'])->group(function ()
|
||||
{
|
||||
Route::get('/contracts', [ContractsController::class, 'index'])->name('contracts');
|
||||
Route::post('/contracts/{contract}/delete', [ContractsController::class, 'delete'])->name('contract.delete');
|
||||
|
||||
});
|
||||
@ -1,4 +1,4 @@
|
||||
@php($statuses = App\Models\Deal\ContractStatus::class)
|
||||
@php($statuses = Modules\Contracts\Models\ContractStatus::class)
|
||||
<div>
|
||||
<div class="fs-5 bg-light p-0 m-0 border border-1 rounded-4 py-3">
|
||||
<table class="table m-0">
|
||||
@ -51,8 +51,8 @@
|
||||
{!! $reward !!}
|
||||
</td>
|
||||
<td>
|
||||
<div class="py-1 px-3 border rounded rounded-5"
|
||||
style="background-color:{{ $statuses::getColor($contract->status) }}">
|
||||
<div class="py-1 px-3 border rounded rounded-5 text-center"
|
||||
style="background-color:{{ $statuses::getHtmlColor($contract->status) }}">
|
||||
{{ $statuses::getName($contract->status) }}
|
||||
</div>
|
||||
</td>
|
||||
@ -65,10 +65,11 @@
|
||||
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
|
||||
<a class="dropdown-item"
|
||||
href="{{ route('contract', ['contract' => $contract->id]) }}">Детали</a>
|
||||
<!--<form method="post" action="">
|
||||
<form method="post"
|
||||
action="{{ route('contract.delete', ['contract' => $contract]) }}">
|
||||
@csrf
|
||||
<button class="dropdown-item" type="submit">Удалить</button>
|
||||
</form>-->
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
@ -2,8 +2,8 @@
|
||||
return [
|
||||
'status_NEW' => 'Новый',
|
||||
'status_TREATY' => 'Выплачено',
|
||||
'status_RESERVATION' => 'Забронировано',
|
||||
'status_SUSSCESS' => 'Успех',
|
||||
'status_RESERVATION' => 'Бронь',
|
||||
'status_SUCCESS' => 'Успех',
|
||||
'status_DECLINE' => 'Отклонен'
|
||||
|
||||
];
|
||||
@ -107,7 +107,8 @@ class="bi bi-pen" viewBox="0 0 16 16">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col col-lg-4 p-3">
|
||||
<div class="rounded-4 h-100 w-100" style="background-color:#ebeef5"></div>
|
||||
<div class="rounded-4 h-100 w-100" style="background-color:#ebeef5"
|
||||
data-base64="{{ $contract->base64_image }}"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user