Add close step in funnel
This commit is contained in:
parent
1462683304
commit
4eae476d2f
@ -2395,4 +2395,43 @@ if($request == 'get_deal_data'){
|
||||
exit();
|
||||
}
|
||||
|
||||
if($request == 'get_deals_linked_reqs'){
|
||||
$req_ids = isset($data->req_ids) ? $data->req_ids : [];
|
||||
$req_ids = array_map('intval', $req_ids);
|
||||
$reqs = [];
|
||||
if (count($req_ids) > 0) {
|
||||
$ids_str = implode(',', $req_ids);
|
||||
$sql = "SELECT id, name, deleted, stage FROM requisitions WHERE id IN ($ids_str)";
|
||||
$q = $pdo->query($sql);
|
||||
if($q && $pdo->num_rows($q) > 0){
|
||||
while($r = $pdo->fetch_assoc($q)){
|
||||
$r['id'] = (int)$r['id'];
|
||||
$r['deleted'] = (int)$r['deleted'];
|
||||
$reqs[] = $r;
|
||||
}
|
||||
}
|
||||
}
|
||||
echo json_encode(['reqs' => $reqs]);
|
||||
exit();
|
||||
}
|
||||
|
||||
if($request == 'get_deals_linked_objects'){
|
||||
$object_ids = isset($data->object_ids) ? $data->object_ids : [];
|
||||
$object_ids = array_map('intval', $object_ids);
|
||||
$objects = [];
|
||||
if (count($object_ids) > 0) {
|
||||
$ids_str = implode(',', $object_ids);
|
||||
$sql = "SELECT id, nazv, adres FROM objects WHERE id IN ($ids_str)";
|
||||
$q = $pdo->query($sql);
|
||||
if($q && $pdo->num_rows($q) > 0){
|
||||
while($r = $pdo->fetch_assoc($q)){
|
||||
$r['id'] = (int)$r['id'];
|
||||
$objects[] = $r;
|
||||
}
|
||||
}
|
||||
}
|
||||
echo json_encode(['objects' => $objects]);
|
||||
exit();
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@ -4858,6 +4858,32 @@
|
||||
if (!$this->db->query($sql))
|
||||
$errors[] = $this->db->errorInfo();
|
||||
|
||||
// Обновление статуса сделки при закрытии заявки
|
||||
if (!empty($requisistion['deal_id']) && $requisistion['deal_id'] > 0) {
|
||||
$dealId = intval($requisistion['deal_id']);
|
||||
// Проверяем, есть ли другие заявки в сделке, которые ещё не закрыты
|
||||
$otherReqsSql = "SELECT COUNT(*) as cnt FROM requisitions WHERE deal_id = $dealId AND deleted = 0 AND id != $id";
|
||||
$otherReqsRow = $this->db->fetch_assoc($this->db->query($otherReqsSql));
|
||||
$otherReqsOpen = $otherReqsRow['cnt'] > 0;
|
||||
|
||||
if ($is_deal || !$otherReqsOpen) {
|
||||
// Если сделка (is_deal=true) ИЛИ все заявки закрыты — ставим статус 1 (успешная)
|
||||
$this->db->query("UPDATE deals SET status = 1 WHERE id = $dealId AND status != 2");
|
||||
|
||||
// Запись в историю сделки
|
||||
$userObj = new User;
|
||||
$userObj->get($user_id);
|
||||
$comment = "Заявка #$id закрыта.";
|
||||
if ($is_deal && isset($post['summa'])) {
|
||||
$comment .= " Совершена сделка на ".$post['summa']." руб.";
|
||||
}
|
||||
if (!$otherReqsOpen) {
|
||||
$comment .= " Все заявки сделки закрыты. Сделка завершена.";
|
||||
}
|
||||
$this->db->query("INSERT INTO user_client_events (user_id, req_id, type, name, comment, create_date) VALUES ($user_id, $id, 'deal', 'Закрытие сделки', '".addslashes($comment)."', NOW())");
|
||||
}
|
||||
}
|
||||
|
||||
// Удаление фильтра автопоиска
|
||||
$autosearch_instce = $this->autosearch_instce;
|
||||
$autosearch_instce->deleteFilterByReq($id, $user_id);
|
||||
|
||||
@ -119,7 +119,12 @@ var ac = new Vue({
|
||||
penthouse: 'Пентхаус',
|
||||
duplex: 'Дуплекс',
|
||||
cottage: 'Коттедж',
|
||||
}
|
||||
},
|
||||
dealCloseData: null,
|
||||
dealCloseReqs: [],
|
||||
dealCloseObjects: [],
|
||||
dealCloseAgentCommission: 0,
|
||||
dealCloseSumma: 0,
|
||||
},
|
||||
methods: {
|
||||
closedStep: function(id, clientId) {
|
||||
@ -492,6 +497,11 @@ var ac = new Vue({
|
||||
this.open_step_load = true;
|
||||
ac.pole_dop_close_step = [];
|
||||
this.is_looad = false;
|
||||
this.dealCloseData = null;
|
||||
this.dealCloseReqs = [];
|
||||
this.dealCloseObjects = [];
|
||||
this.dealCloseAgentCommission = 0;
|
||||
this.dealCloseSumma = 0;
|
||||
if ($('#client-history__bg').css('display') == 'block') {
|
||||
$('#client-history__bg').css('zIndex', '99988');
|
||||
}
|
||||
@ -705,7 +715,60 @@ var ac = new Vue({
|
||||
})
|
||||
.catch(function(error) {
|
||||
console.log(error);
|
||||
});
|
||||
});
|
||||
|
||||
// Загрузка данных сделки для блока закрытия
|
||||
if (ac.step.is_deal === 1) {
|
||||
axios.post('/ajax/ajax_vue_requisitions.php', {
|
||||
request: 'get_deal_by_req',
|
||||
req_id: ac.reqId,
|
||||
})
|
||||
.then(function(response) {
|
||||
var res = typeof response.data === 'string' ? JSON.parse(response.data) : response.data;
|
||||
if (res.deal_id) {
|
||||
axios.post('/ajax/ajax_vue_requisitions.php', {
|
||||
request: 'get_deal_data',
|
||||
deal_id: res.deal_id,
|
||||
})
|
||||
.then(function(dealRes) {
|
||||
var dealData = dealRes.data.deal;
|
||||
if (dealData) {
|
||||
ac.dealCloseData = dealData;
|
||||
ac.dealCloseAgentCommission = dealData.agent_commission || 0;
|
||||
ac.dealCloseSumma = dealData.contract_price || 0;
|
||||
|
||||
// Загрузка связанных заявок
|
||||
var reqIds = [];
|
||||
if (dealData.side_one_requisition_id) reqIds.push(dealData.side_one_requisition_id);
|
||||
if (dealData.side_two_requisition_id) reqIds.push(dealData.side_two_requisition_id);
|
||||
if (reqIds.length > 0) {
|
||||
axios.post('/ajax/ajax_vue_requisitions.php', {
|
||||
request: 'get_deals_linked_reqs',
|
||||
req_ids: reqIds,
|
||||
})
|
||||
.then(function(reqRes) {
|
||||
ac.dealCloseReqs = reqRes.data.reqs || [];
|
||||
});
|
||||
}
|
||||
|
||||
// Загрузка связанных объектов
|
||||
var objIds = [];
|
||||
if (dealData.side_one_object_id) objIds.push(dealData.side_one_object_id);
|
||||
if (dealData.side_two_object_id) objIds.push(dealData.side_two_object_id);
|
||||
if (objIds.length > 0) {
|
||||
axios.post('/ajax/ajax_vue_requisitions.php', {
|
||||
request: 'get_deals_linked_objects',
|
||||
object_ids: objIds,
|
||||
})
|
||||
.then(function(objRes) {
|
||||
ac.dealCloseObjects = objRes.data.objects || [];
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
IsJsonString(str) {
|
||||
|
||||
@ -5400,6 +5400,55 @@ $user_id = $_SESSION['id'];
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<!-- Блок информации о сделке при закрытии этапа -->
|
||||
<?php if (in_array((int)$_SESSION['id'], $allowed_users_deal)) { ?>
|
||||
<div v-if="step.is_deal === 1 && currentPage.includes('/requisitions.php')" class="form-block" style="border: 1px solid #e0e0e0; border-radius: 5px; padding: 15px; margin-top: 10px;">
|
||||
<div class="label" style="font-weight: 600; margin-bottom: 10px; width: 100%;">Информация о сделке</div>
|
||||
<div v-if="dealCloseData">
|
||||
<div v-if="dealCloseData.title" style="margin-bottom: 8px;">
|
||||
<span style="font-weight: 500;">Название:</span> {{ dealCloseData.title }}
|
||||
</div>
|
||||
|
||||
<!-- Связанные заявки -->
|
||||
<div v-if="dealCloseReqs.length > 0" style="margin-top: 10px;">
|
||||
<span style="font-weight: 500;">Связанные заявки:</span>
|
||||
<div v-for="req in dealCloseReqs" style="padding: 5px 0; border-bottom: 1px solid #f0f0f0;">
|
||||
<span style="color: #666;">{{ req.name }}</span>
|
||||
<span v-if="req.deleted == 1" style="color: #43A047; margin-left: 5px;">✓ закрыта</span>
|
||||
<span v-else style="color: #f57c00; margin-left: 5px;">открыта</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Связанные объекты -->
|
||||
<div v-if="dealCloseObjects.length > 0" style="margin-top: 10px;">
|
||||
<span style="font-weight: 500;">Связанные объекты:</span>
|
||||
<div v-for="obj in dealCloseObjects" style="padding: 5px 0; border-bottom: 1px solid #f0f0f0;">
|
||||
<span style="color: #666;">{{ obj.nazv }}</span>
|
||||
<span style="color: #999; margin-left: 5px;">{{ obj.adres }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Фактические данные -->
|
||||
<div style="margin-top: 12px; padding-top: 10px; border-top: 1px solid #e0e0e0;">
|
||||
<div class="label" style="font-weight: 500; margin-bottom: 8px; width: 100%;">Фактические данные</div>
|
||||
<div class="form-block">
|
||||
<div style="width: 100%;" class="label">Комиссия агента (руб.)</div>
|
||||
<div class="inputs">
|
||||
<input v-model="dealCloseAgentCommission" type="number" class="text" style="width: 200px;" placeholder="0">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-block">
|
||||
<div style="width: 100%;" class="label">Сумма сделки (руб.)</div>
|
||||
<div class="inputs">
|
||||
<input v-model="dealCloseSumma" type="number" class="text" style="width: 200px;" placeholder="0">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else style="color: #999;">Загрузка данных сделки...</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user