Fix user_client_events
This commit is contained in:
parent
c7d8320e12
commit
b52e682286
@ -2321,8 +2321,12 @@ if($request == 'saveOpenPrevStep'){
|
||||
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, deal_id, type, name, comment, create_date) VALUES ({$userId}, {$reqId}, {$dealId}, 'deal', 'Отмена сделки', 'Сделка отменена при возврате на предыдущий этап', NOW())");
|
||||
// Ставим cancel = 1 на все события сделки
|
||||
if ($dealId > 0) {
|
||||
mysql_query("UPDATE user_client_events SET cancel = 1 WHERE deal_id = {$dealId}");
|
||||
}
|
||||
// Запись в историю об отмене
|
||||
mysql_query("INSERT INTO user_client_events (user_id, req_id, deal_id, type, name, comment, create_date) VALUES ({$userId}, {$reqId}, {$dealId}, 'deal', 'Отмена сделки', 'Сделка отменена при возврате на предыдущий этап', NOW())");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -155,15 +155,15 @@ if ($_SESSION['id'] && ((isset($_GET['id']) && is_numeric($_GET['id']) && $_GET[
|
||||
// если смотрит руководитель - показываем все
|
||||
// if ($_SESSION['agency'] || $_SESSION['manager'] || $_SESSION['users_admin']) {
|
||||
|
||||
$sql = "SELECT e.id, e.comment, e.name, e.create_date, IF ((mango<>1 AND megafon<>1 AND telphin<>1 AND beeline<>1 AND mts<>1 AND tele2<>1 AND allo<>1), DATE_ADD(create_date, {$time_zone_sql}), create_date) as date_sort, e.checklist, e.type, e.type_call, e.user_id, e.partner_id, e.record, e.client_id, e.document_id, e.schedule_date, e.schedule_date_to, e.address, e.sum, e.from_id, e.calendar_view, `e`.`mango`, `e`.`megafon`, e.telphin,e.beeline, e.mts, e.tele2, e.allo, e.tracking, e.cancel, e.open_step "
|
||||
$sql = "SELECT e.id, e.comment, e.name, e.create_date, IF ((mango<>1 AND megafon<>1 AND telphin<>1 AND beeline<>1 AND mts<>1 AND tele2<>1 AND allo<>1), DATE_ADD(create_date, {$time_zone_sql}), create_date) as date_sort, e.checklist, e.type, e.type_call, e.user_id, e.partner_id, e.record, e.client_id, e.document_id, e.schedule_date, e.schedule_date_to, e.address, e.sum, e.from_id, e.calendar_view, `e`.`mango`, `e`.`megafon`, e.telphin,e.beeline, e.mts, e.tele2, e.allo, e.tracking, e.cancel, e.open_step, e.deal_id "
|
||||
. "FROM user_client_events as e WHERE e.client_id = $get[id] union
|
||||
SELECT ev.id, '' as comment, '' as name, ev.date as create_date, ev.date as date_sort, 0 as checklist, 'partner' as `type`, NULL as type_call, ev.user_id, 0 AS partner_id, '' as record, ev.client_id, '' as document_id, ev.date as schedule_date, '' as schedule_date_to, '' as address, '' as `sum`, ev.from_id, '' as calendar_view, '' as `mango`, '' as `megafon`, '' as telphin, '' as beeline, '' as mts, '' as tele2, '' as allo, '' as tracking, 0 as cancel, 0 as open_step from events_clients as ev WHERE ev.client_id = $get[id] and event = 'transmitted_parallel'
|
||||
ORDER BY date_sort ASC";
|
||||
|
||||
if(isset($get['req_id']) && $get['req_id'] > 0){
|
||||
$sql = "SELECT e.id, e.comment, e.name, e.create_date, IF ((mango<>1 AND megafon<>1 AND telphin<>1 AND beeline<>1 AND mts<>1 AND tele2<>1 AND allo<>1), DATE_ADD(create_date, {$time_zone_sql}), create_date) as date_sort, e.checklist, e.type, e.type_call, e.user_id, e.partner_id, e.record, e.client_id, e.document_id, e.req_id, e.old_req_id, e.schedule_date, e.schedule_date_to, e.address, e.sum, e.from_id, e.calendar_view, `e`.`mango`, `e`.`megafon`, e.telphin,e.beeline, e.mts, e.tele2, e.allo, e.tracking, e.cancel, e.open_step "
|
||||
$sql = "SELECT e.id, e.comment, e.name, e.create_date, IF ((mango<>1 AND megafon<>1 AND telphin<>1 AND beeline<>1 AND mts<>1 AND tele2<>1 AND allo<>1), DATE_ADD(create_date, {$time_zone_sql}), create_date) as date_sort, e.checklist, e.type, e.type_call, e.user_id, e.partner_id, e.record, e.client_id, e.document_id, e.req_id, e.old_req_id, e.schedule_date, e.schedule_date_to, e.address, e.sum, e.from_id, e.calendar_view, `e`.`mango`, `e`.`megafon`, e.telphin,e.beeline, e.mts, e.tele2, e.allo, e.tracking, e.cancel, e.open_step, e.deal_id "
|
||||
. "FROM user_client_events as e WHERE e.req_id = $get[req_id] union
|
||||
SELECT ev.id, '' as comment, '' as name, ev.date as create_date, ev.date as date_sort, 0 as checklist, 'partner' as `type`, NULL as type_call, ev.user_id, 0 AS partner_id, '' as record, ev.client_id, '' as document_id, ev.req_id, 0 as old_req_id, ev.date as schedule_date, '' as schedule_date_to, '' as address, '' as `sum`, ev.from_id, '' as calendar_view, '' as `mango`, '' as `megafon`, '' as telphin, '' as beeline, '' as mts, '' as tele2, '' as allo, '' as tracking, 0 as cancel, 0 as open_step
|
||||
SELECT ev.id, '' as comment, '' as name, ev.date as create_date, ev.date as date_sort, 0 as checklist, 'partner' as `type`, NULL as type_call, ev.user_id, 0 AS partner_id, '' as record, ev.client_id, '' as document_id, ev.req_id, 0 as old_req_id, ev.date as schedule_date, '' as schedule_date_to, '' as address, '' as `sum`, ev.from_id, '' as calendar_view, '' as `mango`, '' as `megafon`, '' as telphin, '' as beeline, '' as mts, '' as tele2, '' as allo, '' as tracking, 0 as cancel, 0 as open_step, 0 as deal_id
|
||||
from events_clients as ev WHERE ev.req_id = $get[req_id] and event = 'transmitted_parallel'
|
||||
ORDER BY date_sort ASC";
|
||||
|
||||
@ -174,9 +174,9 @@ ORDER BY date_sort ASC";
|
||||
$arrSin[] = $r_obj_sin['object_id'];
|
||||
}
|
||||
if(!empty($arrSin)){
|
||||
$sql = "SELECT e.id, e.comment, e.name, e.create_date, IF ((mango<>1 AND megafon<>1 AND telphin<>1 AND beeline<>1 AND mts<>1 AND tele2<>1 AND allo<>1), DATE_ADD(create_date, {$time_zone_sql}), create_date) as date_sort, e.checklist, e.type, e.type_call, e.user_id, e.partner_id, e.record, e.client_id, e.document_id, e.req_id, e.old_req_id, e.schedule_date, e.schedule_date_to, e.address, e.sum, e.from_id, e.calendar_view, `e`.`mango`, `e`.`megafon`, e.telphin,e.beeline, e.mts, e.tele2, e.allo, e.tracking, e.cancel, e.open_step "
|
||||
$sql = "SELECT e.id, e.comment, e.name, e.create_date, IF ((mango<>1 AND megafon<>1 AND telphin<>1 AND beeline<>1 AND mts<>1 AND tele2<>1 AND allo<>1), DATE_ADD(create_date, {$time_zone_sql}), create_date) as date_sort, e.checklist, e.type, e.type_call, e.user_id, e.partner_id, e.record, e.client_id, e.document_id, e.req_id, e.old_req_id, e.schedule_date, e.schedule_date_to, e.address, e.sum, e.from_id, e.calendar_view, `e`.`mango`, `e`.`megafon`, e.telphin,e.beeline, e.mts, e.tele2, e.allo, e.tracking, e.cancel, e.open_step, e.deal_id "
|
||||
. "FROM user_client_events as e WHERE e.req_id = $get[req_id] union
|
||||
SELECT ev.id, '' as comment, '' as name, ev.date as create_date, ev.date as date_sort, 0 as checklist, 'partner' as `type`, NULL as type_call, ev.user_id, 0 AS partner_id, '' as record, ev.client_id, '' as document_id, ev.req_id, 0 as old_req_id, ev.date as schedule_date, '' as schedule_date_to, '' as address, '' as `sum`, ev.from_id, '' as calendar_view, '' as `mango`, '' as `megafon`, '' as telphin, '' as beeline, '' as mts, '' as tele2, '' as allo, '' as tracking, 0 as cancel, 0 as open_step from events_clients as ev WHERE ev.req_id = $get[req_id] and event = 'transmitted_parallel'
|
||||
SELECT ev.id, '' as comment, '' as name, ev.date as create_date, ev.date as date_sort, 0 as checklist, 'partner' as `type`, NULL as type_call, ev.user_id, 0 AS partner_id, '' as record, ev.client_id, '' as document_id, ev.req_id, 0 as old_req_id, ev.date as schedule_date, '' as schedule_date_to, '' as address, '' as `sum`, ev.from_id, '' as calendar_view, '' as `mango`, '' as `megafon`, '' as telphin, '' as beeline, '' as mts, '' as tele2, '' as allo, '' as tracking, 0 as cancel, 0 as open_step, 0 as deal_id from events_clients as ev WHERE ev.req_id = $get[req_id] and event = 'transmitted_parallel'
|
||||
union
|
||||
SELECT e.id, e.comment, '' as name, e.create_date, e.create_date as date_sort, '0' as checklist, 'show_object' as type, NULL as type_call, e.user_id, '' as record, e.object_id, 0 as client_id, e.document_id, e.req_id, 0 as old_req_id, e.schedule_date, '' as schedule_date_to, e.address, e.sum, e.from_id, e.calendar_view, '' as `mango`, '' as `megafon`, '' as telphin, '' as beeline, '' as mts, '' as tele2, '' as allo, '' as tracking, e.cancel, 0 as open_step "
|
||||
. "FROM user_object_events as e WHERE e.req_id={$get['req_id']} AND e.object_id in (".implode(',', $arrSin).") AND e.type='show'
|
||||
@ -1085,29 +1085,9 @@ ORDER BY date_sort ASC";
|
||||
</div>
|
||||
<div class="chat-message <?=($event['cancel']==1) ? 'cancel' : ''?> deal">
|
||||
<?php
|
||||
$deal_id_for_edit = null;
|
||||
// Если в событии есть deal_id — используем его напрямую (включая отменённые сделки)
|
||||
if (!empty($event['deal_id'])) {
|
||||
$deal_id_for_edit = intval($event['deal_id']);
|
||||
} elseif (!empty($event['req_id'])) {
|
||||
$sql_deal = "SELECT id FROM deals WHERE (side_one_requisition_id = " . intval($event['req_id']) . " OR side_two_requisition_id = " . intval($event['req_id']) . ") AND status != 2 LIMIT 1";
|
||||
$rez_deal = mysql_query($sql_deal);
|
||||
if ($rez_deal && mysql_num_rows($rez_deal) > 0) {
|
||||
$row_deal = mysql_fetch_assoc($rez_deal);
|
||||
$deal_id_for_edit = $row_deal['id'];
|
||||
}
|
||||
}
|
||||
if (!$deal_id_for_edit && !empty($event['client_id'])) {
|
||||
$sql_deal_client = "SELECT d.id FROM deals d JOIN requisitions r ON (r.id = d.side_one_requisition_id OR r.id = d.side_two_requisition_id) WHERE r.client_id = " . intval($event['client_id']) . " AND d.status != 2 LIMIT 1";
|
||||
$rez_deal_client = mysql_query($sql_deal_client);
|
||||
if ($rez_deal_client && mysql_num_rows($rez_deal_client) > 0) {
|
||||
$row_deal_client = mysql_fetch_assoc($rez_deal_client);
|
||||
$deal_id_for_edit = $row_deal_client['id'];
|
||||
}
|
||||
}
|
||||
$isNewDeal = !empty($deal_id_for_edit);
|
||||
$deal_id_for_edit = !empty($event['deal_id']) ? intval($event['deal_id']) : null;
|
||||
?>
|
||||
<?php if (!$isNewDeal) { ?>
|
||||
<?php if (!$deal_id_for_edit) { ?>
|
||||
<div class="chat-complete<?=!in_array($event['user_id'], $usersCanEdit) ? ' hidden' : '' ?>">
|
||||
<div class="complete-button" data-id="<?=$event['id']?>">
|
||||
<input type="checkbox" class=""/>
|
||||
@ -1135,7 +1115,7 @@ ORDER BY date_sort ASC";
|
||||
<div class="head">
|
||||
<span>Сделка</span>
|
||||
<?php
|
||||
if ($isNewDeal) {
|
||||
if ($deal_id_for_edit) {
|
||||
$sql_deal_data = "SELECT * FROM deals WHERE id = " . intval($deal_id_for_edit) . " LIMIT 1";
|
||||
$rez_deal_data = mysql_query($sql_deal_data);
|
||||
$deal_data = mysql_fetch_assoc($rez_deal_data);
|
||||
@ -1222,11 +1202,13 @@ ORDER BY date_sort ASC";
|
||||
echo '</div>';
|
||||
}
|
||||
?>
|
||||
<?php if (!$event['cancel']) { ?>
|
||||
<div style="margin-top:8px;text-align:right;">
|
||||
<a href="javascript:{}" class="no-border" onclick="if(window.editDeal){window.editDeal(<?=intval($event['req_id'] ?: 0)?>, <?=$deal_id_for_edit?>)}" style="color:#43A047;font-size:13px;font-weight:500;">
|
||||
Подробнее →
|
||||
</a>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php } else { ?>
|
||||
<?php if ($event['sum']) { ?>
|
||||
<div class="message" style="font-size:13px;">Сумма сделки: <?=$event['sum']?><span class="rub">p</span></div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user