Fix calendar mobile
This commit is contained in:
parent
7223bb33ae
commit
b00403a684
@ -14727,7 +14727,11 @@ class CommonController extends ApiController
|
|||||||
}
|
}
|
||||||
|
|
||||||
// События по заявкам и клиентам
|
// События по заявкам и клиентам
|
||||||
|
$seenDealIds = array();
|
||||||
$where2 = $where;
|
$where2 = $where;
|
||||||
|
if ($only_active) {
|
||||||
|
$where2[] = "`cancel` = 0";
|
||||||
|
}
|
||||||
$agency_id = \User::getUserAgencyID($user_id);
|
$agency_id = \User::getUserAgencyID($user_id);
|
||||||
if($agency_id == 13394 || $agency_id == 13430){
|
if($agency_id == 13394 || $agency_id == 13430){
|
||||||
$where2[] = "`megafon` = 0";
|
$where2[] = "`megafon` = 0";
|
||||||
@ -14735,84 +14739,193 @@ class CommonController extends ApiController
|
|||||||
|
|
||||||
$sql = "SELECT * FROM `user_client_events`
|
$sql = "SELECT * FROM `user_client_events`
|
||||||
WHERE `user_id` = '$user_id' AND
|
WHERE `user_id` = '$user_id' AND
|
||||||
`schedule_date` IS NOT NULL AND
|
`schedule_date` IS NOT NULL AND " . implode (' AND ', $where2);
|
||||||
`cancel` = 0 AND " . implode (' AND ', $where2);
|
|
||||||
|
|
||||||
if ($query = mysql_query($sql)) {
|
if ($query = mysql_query($sql)) {
|
||||||
|
$dealEvents = array();
|
||||||
while ($event = mysql_fetch_assoc($query)) {
|
while ($event = mysql_fetch_assoc($query)) {
|
||||||
|
if ($event['type'] == 'deal' && !empty($event['deal_id'])) {
|
||||||
|
$did = (int)$event['deal_id'];
|
||||||
|
if (!isset($dealEvents[$did])) {
|
||||||
|
$dealEvents[$did] = array();
|
||||||
|
}
|
||||||
|
$dealEvents[$did][] = $event;
|
||||||
|
} else {
|
||||||
|
if ($event['cancel'] == 1) continue;
|
||||||
|
|
||||||
$type = null;
|
$type = null;
|
||||||
$is_viewed = false;
|
$is_viewed = false;
|
||||||
|
|
||||||
|
$section = 'free';
|
||||||
|
if ($event['client_id'] > 0)
|
||||||
|
$section = 'clients';
|
||||||
|
else if($event['req_id'] > 0)
|
||||||
|
$section = 'requisitions';
|
||||||
|
|
||||||
|
$fio = '';
|
||||||
|
if ($event['client_id'] > 0) {
|
||||||
|
$q_cl = mysql_query("SELECT `fio` FROM `clients` WHERE `id` = {$event['client_id']}");
|
||||||
|
$fio = str_replace("\\","/", mysql_fetch_assoc($q_cl)['fio']);
|
||||||
|
} else if ($event['req_id'] > 0) {
|
||||||
|
$q_req = mysql_query("SELECT `name` from `requisitions` WHERE `id`={$event['req_id']}");
|
||||||
|
$fio = mysql_fetch_assoc($q_req)['name'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($fio)) {
|
||||||
|
$q_u = mysql_query("SELECT `first_name`, `last_name`, `middle_name` FROM `users` WHERE `id` = ".$event['user_id']);
|
||||||
|
$r_u = mysql_fetch_assoc($q_u);
|
||||||
|
$fio = '(исполнитель '.trim($r_u['last_name'] . ' ' . $r_u['first_name'] . ' ' . $r_u['middle_name']).')';
|
||||||
|
}
|
||||||
|
|
||||||
|
$fio = str_replace('"', "'", $fio);
|
||||||
|
$fio = str_replace('"', "'", $fio);
|
||||||
|
$title = $fio;
|
||||||
|
|
||||||
|
if ($event['calendar_view'] != 0)
|
||||||
|
$is_viewed = true;
|
||||||
|
|
||||||
|
if ($event['type'] == 'call') {
|
||||||
|
$type = "call";
|
||||||
|
$title = "Звонок " . $fio;
|
||||||
|
} else if ($event['type'] == 'meet') {
|
||||||
|
$type = "meet";
|
||||||
|
$title = "Встреча " . $fio;
|
||||||
|
} else if ($event['type'] == 'show') {
|
||||||
|
$type = "show";
|
||||||
|
$title = "Показ " . $fio;
|
||||||
|
} else if ($event['type'] == 'even') {
|
||||||
|
$type = "even";
|
||||||
|
$title = $event['name'] ." ". $fio;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_null($type)) {
|
||||||
|
$item_id++;
|
||||||
|
$list[] = [
|
||||||
|
'id' => $item_id,
|
||||||
|
'event_id' => (int)$event['id'],
|
||||||
|
'section' => $section,
|
||||||
|
'start' => date('Y-m-d H:i:s', strtotime($event['schedule_date'])),
|
||||||
|
'start_date' => date('Y-m-d', strtotime($event['schedule_date'])),
|
||||||
|
'start_time' => date('H:i:s', strtotime($event['schedule_date'])),
|
||||||
|
'client_id' => ($event['client_id']) ? (int)$event['client_id'] : null,
|
||||||
|
'object_id' => null,
|
||||||
|
'requisition_id' => ($event['req_id']) ? (int)$event['req_id'] : null,
|
||||||
|
'employee_id' => null,
|
||||||
|
'title' => $title,
|
||||||
|
'event_type' => $type,
|
||||||
|
'is_viewed' => $is_viewed,
|
||||||
|
'user_id' => $event['user_id']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Дедупликация сделок по deal_id — одно событие на сделку
|
||||||
|
foreach ($dealEvents as $did => $events) {
|
||||||
|
$q_deal = mysql_query("SELECT title, side_one_requisition_id, side_two_requisition_id FROM deals WHERE id = " . intval($did) . " LIMIT 1");
|
||||||
|
$deal = ($q_deal && mysql_num_rows($q_deal) > 0) ? mysql_fetch_assoc($q_deal) : null;
|
||||||
|
$dealTitle = $deal ? $deal['title'] : '';
|
||||||
|
$sideOneReqId = $deal ? (int)$deal['side_one_requisition_id'] : 0;
|
||||||
|
$sideTwoReqId = $deal ? (int)$deal['side_two_requisition_id'] : 0;
|
||||||
|
|
||||||
|
// Приоритет: 1) заявка стороны 1, 2) заявка стороны 2, 3) клиент, 4) req, 5) любое
|
||||||
|
$bestEvent = null;
|
||||||
|
foreach ($events as $ev) {
|
||||||
|
if ($sideOneReqId > 0 && (int)$ev['req_id'] == $sideOneReqId) { $bestEvent = $ev; break; }
|
||||||
|
}
|
||||||
|
if (!$bestEvent) {
|
||||||
|
foreach ($events as $ev) {
|
||||||
|
if ($sideTwoReqId > 0 && (int)$ev['req_id'] == $sideTwoReqId) { $bestEvent = $ev; break; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$bestEvent) {
|
||||||
|
foreach ($events as $ev) {
|
||||||
|
if (!empty($ev['client_id'])) { $bestEvent = $ev; break; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$bestEvent) {
|
||||||
|
foreach ($events as $ev) {
|
||||||
|
if (!empty($ev['req_id'])) { $bestEvent = $ev; break; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$bestEvent) {
|
||||||
|
$bestEvent = $events[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
$is_viewed = ($bestEvent['calendar_view'] != 0) || ($bestEvent['cancel'] == 1);
|
||||||
|
|
||||||
$section = 'free';
|
$section = 'free';
|
||||||
if ($event['client_id'] > 0)
|
if (!empty($bestEvent['client_id']))
|
||||||
$section = 'clients';
|
$section = 'clients';
|
||||||
else if($event['req_id'] > 0)
|
else if (!empty($bestEvent['req_id']))
|
||||||
$section = 'requisitions';
|
$section = 'requisitions';
|
||||||
|
|
||||||
$fio = '';
|
$item_id++;
|
||||||
if ($event['client_id'] > 0) {
|
$list[] = [
|
||||||
$q_cl = mysql_query("SELECT `fio` FROM `clients` WHERE `id` = {$event['client_id']}");
|
'id' => $item_id,
|
||||||
$fio = str_replace("\\","/", mysql_fetch_assoc($q_cl)['fio']);
|
'event_id' => (int)$bestEvent['id'],
|
||||||
} else if ($event['req_id'] > 0) {
|
'section' => $section,
|
||||||
$q_req = mysql_query("SELECT `name` from `requisitions` WHERE `id`={$event['req_id']}");
|
'start' => date('Y-m-d H:i:s', strtotime($bestEvent['schedule_date'])),
|
||||||
$fio = mysql_fetch_assoc($q_req)['name'];
|
'start_date' => date('Y-m-d', strtotime($bestEvent['schedule_date'])),
|
||||||
}
|
'start_time' => date('H:i:s', strtotime($bestEvent['schedule_date'])),
|
||||||
|
'client_id' => !empty($bestEvent['client_id']) ? (int)$bestEvent['client_id'] : null,
|
||||||
if (empty($fio)) {
|
'object_id' => null,
|
||||||
$q_u = mysql_query("SELECT `first_name`, `last_name`, `middle_name` FROM `users` WHERE `id` = ".$event['user_id']);
|
'requisition_id' => !empty($bestEvent['req_id']) ? (int)$bestEvent['req_id'] : null,
|
||||||
$r_u = mysql_fetch_assoc($q_u);
|
'employee_id' => null,
|
||||||
$fio = '(исполнитель '.trim($r_u['last_name'] . ' ' . $r_u['first_name'] . ' ' . $r_u['middle_name']).')';
|
'title' => "Сделка " . str_replace('"', "'", $dealTitle ?: 'без названия'),
|
||||||
}
|
'event_type' => 'deal',
|
||||||
|
'is_viewed' => $is_viewed,
|
||||||
$fio = str_replace('"', "'", $fio);
|
'user_id' => $bestEvent['user_id'],
|
||||||
$fio = str_replace('"', "'", $fio);
|
];
|
||||||
$title = $fio;
|
$seenDealIds[] = $did;
|
||||||
|
|
||||||
if ($event['calendar_view'] != 0)
|
|
||||||
$is_viewed = true;
|
|
||||||
|
|
||||||
if ($event['type'] == 'call') {
|
|
||||||
$type = "call";
|
|
||||||
$title = "Звонок " . $fio;
|
|
||||||
} else if ($event['type'] == 'meet') {
|
|
||||||
$type = "meet";
|
|
||||||
$title = "Встреча " . $fio;
|
|
||||||
} else if ($event['type'] == 'show') {
|
|
||||||
$type = "show";
|
|
||||||
$title = "Показ " . $fio;
|
|
||||||
} else if ($event['type'] == 'deal') {
|
|
||||||
$type = "deal";
|
|
||||||
$title = "Сделка " . $fio;
|
|
||||||
} else if ($event['type'] == 'even') {
|
|
||||||
$type = "even";
|
|
||||||
$title = $event['name'] ." ". $fio;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_null($type)) {
|
|
||||||
$item_id++;
|
|
||||||
$list[] = [
|
|
||||||
'id' => $item_id,
|
|
||||||
'event_id' => (int)$event['id'],
|
|
||||||
'section' => $section,
|
|
||||||
'start' => date('Y-m-d H:i:s', strtotime($event['schedule_date'])),
|
|
||||||
'start_date' => date('Y-m-d', strtotime($event['schedule_date'])),
|
|
||||||
'start_time' => date('H:i:s', strtotime($event['schedule_date'])),
|
|
||||||
'client_id' => ($event['client_id']) ? (int)$event['client_id'] : null,
|
|
||||||
'object_id' => null,
|
|
||||||
'requisition_id' => ($event['req_id']) ? (int)$event['req_id'] : null,
|
|
||||||
'employee_id' => null,
|
|
||||||
'title' => $title,
|
|
||||||
'event_type' => $type,
|
|
||||||
'is_viewed' => $is_viewed,
|
|
||||||
'user_id' => $event['user_id']
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$errors[] = mysql_error();
|
$errors[] = mysql_error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Добавляем сделки из deal_user для текущего пользователя
|
||||||
|
$sql_deals = "SELECT d.id, d.title, d.side_one_requisition_id FROM deals d
|
||||||
|
INNER JOIN deal_user du ON du.deal_id = d.id
|
||||||
|
WHERE du.user_id = " . intval($user_id) . "
|
||||||
|
AND d.id NOT IN (" . (empty($seenDealIds) ? '0' : implode(',', $seenDealIds)) . ")";
|
||||||
|
$q_deals = mysql_query($sql_deals);
|
||||||
|
while ($dealRow = mysql_fetch_assoc($q_deals)) {
|
||||||
|
$did = (int)$dealRow['id'];
|
||||||
|
$dealTitle = $dealRow['title'];
|
||||||
|
$sideOneReqId = (int)$dealRow['side_one_requisition_id'];
|
||||||
|
|
||||||
|
$q_dates = mysql_query("SELECT schedule_date, deal_id, cancel FROM user_client_events WHERE deal_id = " . $did . " AND type = 'deal' AND schedule_date IS NOT NULL ORDER BY schedule_date DESC LIMIT 1");
|
||||||
|
if ($q_dates && mysql_num_rows($q_dates) > 0) {
|
||||||
|
$dateRow = mysql_fetch_assoc($q_dates);
|
||||||
|
$scheduleDate = $dateRow['schedule_date'];
|
||||||
|
$isCancelled = ($dateRow['cancel'] == 1);
|
||||||
|
} else {
|
||||||
|
$q_created = mysql_query("SELECT created_at FROM deals WHERE id = " . $did);
|
||||||
|
$scheduleDate = ($q_created && mysql_num_rows($q_created) > 0) ? mysql_fetch_assoc($q_created)['created_at'] : date('Y-m-d H:i:s');
|
||||||
|
$isCancelled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($only_active && $isCancelled) continue;
|
||||||
|
|
||||||
|
$item_id++;
|
||||||
|
$list[] = [
|
||||||
|
'id' => $item_id,
|
||||||
|
'event_id' => $did,
|
||||||
|
'section' => 'requisitions',
|
||||||
|
'start' => date('Y-m-d H:i:s', strtotime($scheduleDate)),
|
||||||
|
'start_date' => date('Y-m-d', strtotime($scheduleDate)),
|
||||||
|
'start_time' => date('H:i:s', strtotime($scheduleDate)),
|
||||||
|
'client_id' => null,
|
||||||
|
'object_id' => null,
|
||||||
|
'requisition_id' => $sideOneReqId ?: null,
|
||||||
|
'employee_id' => null,
|
||||||
|
'title' => "Сделка " . str_replace('"', "'", $dealTitle),
|
||||||
|
'event_type' => 'deal',
|
||||||
|
'is_viewed' => $isCancelled,
|
||||||
|
'user_id' => $user_id,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
// Дни рождения клиентов
|
// Дни рождения клиентов
|
||||||
$where = ['1'];
|
$where = ['1'];
|
||||||
if (!is_null($start_date)){
|
if (!is_null($start_date)){
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user