diff --git a/ajax/ajax_vue_clients.php b/ajax/ajax_vue_clients.php index 805ed4a..06e9f29 100644 --- a/ajax/ajax_vue_clients.php +++ b/ajax/ajax_vue_clients.php @@ -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())"); } diff --git a/js/vue_scripts/complex_objects_page_vue.js b/js/vue_scripts/complex_objects_page_vue.js index 9f42d5a..0953fb0 100644 --- a/js/vue_scripts/complex_objects_page_vue.js +++ b/js/vue_scripts/complex_objects_page_vue.js @@ -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(() => {