Fix null req after cancel
This commit is contained in:
parent
d69faee418
commit
d490bcade9
@ -2310,12 +2310,17 @@ if($request == 'saveOpenPrevStep'){
|
||||
$is_cancel_deal = isset($data->is_cancel_deal) ? (int)$data->is_cancel_deal : 0;
|
||||
if ($is_cancel_deal && $reqId > 0) {
|
||||
// Находим сделку, связанную с заявкой
|
||||
$sql_deal = mysql_query("SELECT id FROM deals WHERE (side_one_requisition_id = {$reqId} OR side_two_requisition_id = {$reqId}) AND status != 2 LIMIT 1");
|
||||
$sql_deal = mysql_query("SELECT id, side_one_requisition_id, side_two_requisition_id FROM deals WHERE (side_one_requisition_id = {$reqId} OR side_two_requisition_id = {$reqId}) AND status != 2 LIMIT 1");
|
||||
if ($sql_deal && mysql_num_rows($sql_deal) > 0) {
|
||||
$row_deal = mysql_fetch_assoc($sql_deal);
|
||||
$dealId = (int)$row_deal['id'];
|
||||
// Ставим статус 2 (отменена)
|
||||
mysql_query("UPDATE deals SET status = 2 WHERE id = {$dealId}");
|
||||
// Обнуляем deal_id у связанных заявок
|
||||
$linkedReqs = array_filter(array_map('intval', [$row_deal['side_one_requisition_id'], $row_deal['side_two_requisition_id']]));
|
||||
if (!empty($linkedReqs)) {
|
||||
mysql_query("UPDATE requisitions SET deal_id = NULL WHERE id IN (" . implode(',', $linkedReqs) . ")");
|
||||
}
|
||||
// Запись в историю
|
||||
mysql_query("INSERT INTO user_client_events (user_id, req_id, type, name, comment, create_date) VALUES ({$userId}, {$reqId}, 'deal', 'Отмена сделки', 'Сделка отменена при возврате на предыдущий этап', NOW())");
|
||||
}
|
||||
|
||||
@ -74,6 +74,31 @@ var complexobjectspage = new Vue({
|
||||
|
||||
},
|
||||
|
||||
openObjectDeal(objectId) {
|
||||
var self = this;
|
||||
$.ajax({
|
||||
url: '/ajax/ajax_vue_requisitions.php',
|
||||
type: 'POST',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify({ request: 'get_deal_by_object', object_id: objectId }),
|
||||
success: function(response) {
|
||||
var res = typeof response === 'string' ? JSON.parse(response) : response;
|
||||
if (res.deals && res.deals.length > 0) {
|
||||
var tryCount = 0;
|
||||
function tryOpenDeal() {
|
||||
if (typeof window.editDeal === 'function') {
|
||||
window.editDeal(0, res.deals[0]);
|
||||
} else if (tryCount < 20) {
|
||||
tryCount++;
|
||||
setTimeout(tryOpenDeal, 200);
|
||||
}
|
||||
}
|
||||
tryOpenDeal();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
toggle_form_search() {
|
||||
(this.show_form) ? this.show_form = false: this.show_form = true;
|
||||
},
|
||||
@ -190,6 +215,33 @@ var complexobjectspage = new Vue({
|
||||
console.log(response.data);
|
||||
this.complex = response.data;
|
||||
|
||||
// Проверяем сделки для объектов
|
||||
if (this.complex.objects && Object.keys(this.complex.objects).length > 0) {
|
||||
var objectIds = [];
|
||||
for (var k in this.complex.objects) {
|
||||
objectIds.push(this.complex.objects[k].id);
|
||||
}
|
||||
var self = this;
|
||||
$.ajax({
|
||||
url: '/ajax/ajax_vue_requisitions.php',
|
||||
type: 'POST',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify({ request: 'get_deals_by_objects', object_ids: objectIds }),
|
||||
success: function(resp) {
|
||||
var res = typeof resp === 'string' ? JSON.parse(resp) : resp;
|
||||
if (res.deals_by_object) {
|
||||
for (var objId in res.deals_by_object) {
|
||||
for (var k in self.complex.objects) {
|
||||
if (self.complex.objects[k].id == objId) {
|
||||
self.$set(self.complex.objects[k], 'has_deal', 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//alert(this.is_budget);
|
||||
setTimeout(() => {
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user