diff --git a/js/crm_vue.js b/js/crm_vue.js index 23ebe5d..3699bdd 100644 --- a/js/crm_vue.js +++ b/js/crm_vue.js @@ -436,20 +436,24 @@ var ac = new Vue({ // Сначала загружаем данные сделки, потом открываем модал var loadDealData = function(callback) { + console.log('[DEAL_CLOSE] loadDealData started, reqId:', ac.reqId); 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; + console.log('[DEAL_CLOSE] get_deal_by_req response:', res); if (res.deal_id) { + console.log('[DEAL_CLOSE] found deal_id:', res.deal_id, ', loading deal data...'); 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) { + var dealData = dealRes.data.deal; + console.log('[DEAL_CLOSE] get_deal_data response:', dealData); + if (dealData) { ac.dealCloseData = dealData; ac.dealCloseAgentCommission = dealData.agent_commission || 0; ac.dealCloseSumma = dealData.contract_price || 0; diff --git a/templates/footer.php b/templates/footer.php index 555e5f8..fa12c65 100644 --- a/templates/footer.php +++ b/templates/footer.php @@ -4185,66 +4185,113 @@ $user_id = $_SESSION['id']; }); function renderDealCloseContent() { var d = window.dealCloseData; - if (!d) return; + console.log('[DEAL_CLOSE] renderDealCloseContent called, dealCloseData:', d); + if (!d) { console.log('[DEAL_CLOSE] dealCloseData is null/undefined'); return; } var html = ''; if (d.title) html += '
Название: ' + d.title + '
'; if (d.contract_price) html += '
Сумма в договоре: ' + Number(d.contract_price).toLocaleString('ru-RU') + ' руб.
'; if (d.agent_commission) html += '
Комиссия агента: ' + Number(d.agent_commission).toLocaleString('ru-RU') + ' руб.
'; + console.log('[DEAL_CLOSE] basic html:', html); + $('#deal_close_content').html(html); + // Собираем ID заявок и объектов var reqIds = []; if (d.side_one_requisition_id) reqIds.push(d.side_one_requisition_id); if (d.side_two_requisition_id) reqIds.push(d.side_two_requisition_id); + var objIds = []; + if (d.side_one_object_id) objIds.push(d.side_one_object_id); + if (d.side_two_object_id) objIds.push(d.side_two_object_id); + console.log('[DEAL_CLOSE] reqIds:', reqIds, 'objIds:', objIds); + + var pending = 0; + if (reqIds.length > 0) pending++; + if (objIds.length > 0) pending++; + + if (pending === 0) { + console.log('[DEAL_CLOSE] no reqs or objects, rendering fact data'); + renderFactData(d); + return; + } + + var reqData = null; + var objData = null; + + function tryRender() { + console.log('[DEAL_CLOSE] tryRender called, reqData:', reqData, 'objData:', objData); + if (reqData !== null && objData !== null) { + if (reqData.length > 0) { + var reqHtml = '
Связанные заявки:
'; + reqData.forEach(function(req) { + reqHtml += '
' + req.name; + reqHtml += req.deleted == 1 ? ' ✓ закрыта' : ' открыта'; + reqHtml += '
'; + }); + console.log('[DEAL_CLOSE] appending reqHtml:', reqHtml); + $('#deal_close_content').append(reqHtml); + } else { + console.log('[DEAL_CLOSE] no requisitions found'); + } + if (objData.length > 0) { + var objHtml = '
Связанные объекты:
'; + objData.forEach(function(obj) { + objHtml += '
' + obj.nazv + ' ' + obj.adres + '
'; + }); + console.log('[DEAL_CLOSE] appending objHtml:', objHtml); + $('#deal_close_content').append(objHtml); + } else { + console.log('[DEAL_CLOSE] no objects found'); + } + renderFactData(d); + } + } + if (reqIds.length > 0) { + console.log('[DEAL_CLOSE] loading requisitions...'); $.ajax({ url: '/ajax/ajax_vue_requisitions.php', type: 'POST', contentType: 'application/json', + dataType: 'json', data: JSON.stringify({ request: 'get_deals_linked_reqs', req_ids: reqIds }), success: function(reqRes) { - var reqs = reqRes.reqs || []; - if (reqs.length > 0) { - html += '
Связанные заявки:
'; - reqs.forEach(function(req) { - html += '
' + req.name; - html += req.deleted == 1 ? ' ✓ закрыта' : ' открыта'; - html += '
'; - }); - } - - var objIds = []; - if (d.side_one_object_id) objIds.push(d.side_one_object_id); - if (d.side_two_object_id) objIds.push(d.side_two_object_id); - if (objIds.length > 0) { - $.ajax({ - url: '/ajax/ajax_vue_requisitions.php', - type: 'POST', - contentType: 'application/json', - data: JSON.stringify({ request: 'get_deals_linked_objects', object_ids: objIds }), - success: function(objRes) { - var objs = objRes.objects || []; - if (objs.length > 0) { - html += '
Связанные объекты:
'; - objs.forEach(function(obj) { - html += '
' + obj.nazv + ' ' + obj.adres + '
'; - }); - } - html += '
Фактические данные
'; - html += '
Комиссия агента: ' + (d.agent_commission || 0) + ' руб. | Сумма сделки: ' + (d.contract_price || 0) + ' руб.
'; - $('#deal_close_content').html(html); - } - }); - } else { - html += '
Фактические данные
'; - html += '
Комиссия агента: ' + (d.agent_commission || 0) + ' руб. | Сумма сделки: ' + (d.contract_price || 0) + ' руб.
'; - $('#deal_close_content').html(html); - } + console.log('[DEAL_CLOSE] requisitions response:', reqRes); + reqData = reqRes.reqs || []; + tryRender(); + }, + error: function(xhr, status, error) { + console.log('[DEAL_CLOSE] requisitions error:', status, error); + reqData = []; + tryRender(); } }); - } else { - html += '
Фактические данные
'; - html += '
Комиссия агента: ' + (d.agent_commission || 0) + ' руб. | Сумма сделки: ' + (d.contract_price || 0) + ' руб.
'; - $('#deal_close_content').html(html); } + if (objIds.length > 0) { + console.log('[DEAL_CLOSE] loading objects...'); + $.ajax({ + url: '/ajax/ajax_vue_requisitions.php', + type: 'POST', + contentType: 'application/json', + dataType: 'json', + data: JSON.stringify({ request: 'get_deals_linked_objects', object_ids: objIds }), + success: function(objRes) { + console.log('[DEAL_CLOSE] objects response:', objRes); + objData = objRes.objects || []; + tryRender(); + }, + error: function(xhr, status, error) { + console.log('[DEAL_CLOSE] objects error:', status, error); + objData = []; + tryRender(); + } + }); + } + } + + function renderFactData(d) { + console.log('[DEAL_CLOSE] renderFactData called'); + var html = '
Фактические данные
'; + html += '
Комиссия агента: ' + (d.agent_commission || 0) + ' руб. | Сумма сделки: ' + (d.contract_price || 0) + ' руб.
'; + $('#deal_close_content').append(html); }