1068 lines
51 KiB
PHP
1068 lines
51 KiB
PHP
<?php
|
||
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
|
||
|
||
|
||
$cl = new Clients();
|
||
|
||
/*ini_set('display_errors', 1);
|
||
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);*/
|
||
ini_set('max_execution_time', 300);
|
||
|
||
$usersArr = json_decode($_POST['responsible'], true);
|
||
//file_put_contents(__DIR__.'/log.txt', date('H:i:s'));
|
||
$usersId = $cl -> getUsersFilter($usersArr, $_POST['user_id'], $_POST['users_admin']);
|
||
//var_dump($usersId);
|
||
$rows = $row = $row_obj = $row_add = $row_do = $row_pr = array();
|
||
//file_put_contents(__DIR__.'/log.txt', var_dump($_POST));
|
||
//var_dump($_POST);
|
||
//$_SESSION['filter_emp'] = $_POST['responsible'];
|
||
$bd_usl_managers = '';
|
||
$bd_usl = " AND cancel=0";
|
||
$arrIdUser = array();
|
||
$arrIdAgent = array();
|
||
|
||
foreach($usersId as $userId){
|
||
$arrIdUser[] = $userId;
|
||
$arrIdAgent[] = $userId;
|
||
}
|
||
$period = 'all';
|
||
$whereTasks = "";
|
||
$bd_priod = '';
|
||
$bd_do_period = '';
|
||
$table = 'clients';
|
||
$date_add = 'date_add';
|
||
$pole_agent = 'id_agent';
|
||
$script = 'clients.php';
|
||
$pole_event = 'client_id';
|
||
if(isset($_POST['client_req']) && $_POST['client_req'] == 1){
|
||
$table = 'requisitions';
|
||
$date_add = 'created_at';
|
||
$pole_agent = 'user_id';
|
||
$script = 'requisitions.php';
|
||
$pole_event = 'req_id';
|
||
//$bd_usl .= " AND cancel=0";
|
||
}
|
||
|
||
|
||
if(isset($_POST['period'])){
|
||
//$_SESSION['client_period'] = $_POST['period'];
|
||
$period = $_POST['period'];
|
||
if($period == 'dates'){
|
||
// $_SESSION['client_period'] = 'period';
|
||
$onDate = date('Y-m-d 00:00:00', strtotime($_POST['onDate']));
|
||
if(empty($onDate)) $onDate = '1970-01-01 00:00:00';
|
||
|
||
if(!empty($_POST['offDate'])) {
|
||
$offDate = date('Y-m-d 23:59:59', strtotime($_POST['offDate']));
|
||
} else {
|
||
$offDate = date('Y-m-d 23:59:59');
|
||
}
|
||
$bd_piriod .= " AND $date_add between '{$onDate}' AND '{$offDate}'";
|
||
$bd_do_period .= " AND $date_add < '{$onDate}'";
|
||
$_SESSION['on_date'] = $_POST['onDate'];
|
||
$_SESSION['off_date'] = $_POST['offDate'];
|
||
} else {
|
||
unset($_SESSION['on_date']);
|
||
unset($_SESSION['off_date']);
|
||
$arrPeriod = ['today' => '-0 day', 'week' => '-6 day', 'month' => '-30 day', 'quarter' => '-120 day', 'year' => '-365'];
|
||
$days = date('Y-m-d', strtotime($arrPeriod[$_POST['period']]));
|
||
$bd_piriod .= " AND $date_add > '{$days}'";
|
||
$bd_do_period .= " AND $date_add < '{$days}'";
|
||
//$whereTasks = " and DATE(create_date) > '{$days}'";
|
||
//$_SESSION['client_period'] = $_POST['period'];
|
||
}
|
||
} else {
|
||
//unset($_SESSION['client_period']);
|
||
}
|
||
//echo $period;
|
||
/* echo $bd_piriod."\n";
|
||
echo $bd_do_period."\n";
|
||
$period = 'all';
|
||
$whereTasks = "";
|
||
$bd_period = '';
|
||
$bd_do_period = '';
|
||
|
||
if(isset($_POST['period'])){
|
||
|
||
$period = $_POST['period'];
|
||
}
|
||
$onDate = null;
|
||
$offDate = null;
|
||
if(isset($_POST['onDate'])){
|
||
$onDate = $_POST['onDate'];
|
||
}
|
||
if(isset($_POST['offDate'])){
|
||
$offDate = $_POST['offDate'];
|
||
}
|
||
$dates = getPeriod($period, $onDate, $offDate);
|
||
$date_between = $dates['between'];
|
||
|
||
var_dump($dates);*/
|
||
|
||
if($table == 'requisitions'){
|
||
if (isset($_POST['charts_activities']) && !empty($_POST['charts_activities']) && $_POST['charts_activities'] != 'null') {
|
||
$activitiesArr = json_decode(html_entity_decode($_POST['charts_activities']), ENT_QUOTES);
|
||
$bd_usl .= " AND requisitions.id IN (
|
||
SELECT req_id FROM requisitions_activities
|
||
WHERE activity_id IN (" . implode(", ", $activitiesArr) . ")
|
||
)";
|
||
}
|
||
} else {
|
||
|
||
|
||
if (isset($_POST['charts_activities']) && !empty($_POST['charts_activities']) && $_POST['charts_activities'] != 'null') {
|
||
$activitiesArr = json_decode(html_entity_decode($_POST['charts_activities']), ENT_QUOTES);
|
||
$bd_usl .= " AND client.id IN (
|
||
SELECT client_id FROM clients_activities
|
||
WHERE activity_id IN (" . implode(", ", $activitiesArr) . ")
|
||
)";
|
||
|
||
|
||
}
|
||
}
|
||
|
||
|
||
if(isset($_POST['charts_type'])){
|
||
$typesArr = json_decode(html_entity_decode($_POST['charts_type']), ENT_QUOTES);
|
||
if(!empty($typesArr)){
|
||
$typeArr = array();
|
||
foreach($typesArr as $typeCl){
|
||
$typeArr[] = "work_type like '%"{$typeCl}"%'";
|
||
}
|
||
$bd_usl .= " AND (".implode(" OR ",$typeArr).")";
|
||
}
|
||
$_SESSION['filter_client_type'] = $_POST['charts_type'];
|
||
} else {
|
||
unset($_SESSION['filter_client_type']);
|
||
}
|
||
|
||
|
||
|
||
|
||
if(isset($_POST['charts_rol'])){
|
||
$rolesArr = json_decode(html_entity_decode($_POST['charts_rol']), ENT_QUOTES);
|
||
if(!empty($rolesArr)){
|
||
$sroleArr = array();
|
||
foreach($rolesArr as $roleCl){
|
||
$roleArr[] = "`role` like '%"{$roleCl}"%'";
|
||
}
|
||
$bd_usl .= " AND (".implode(" OR ",$roleArr).")";
|
||
}
|
||
$_SESSION['filter_client_rol'] = $_POST['charts_rol'];
|
||
} else {
|
||
unset($_SESSION['filter_client_rol']);
|
||
}
|
||
|
||
if(isset($_POST['source'])){
|
||
$sourcesArr = json_decode(html_entity_decode($_POST['source']), ENT_QUOTES);
|
||
$sourceArr = array();
|
||
if(!empty($sourcesArr )){
|
||
foreach($sourcesArr as $sourceCl){
|
||
if($sourceCl == 0){
|
||
$sourceArr[] = "`source` is null";
|
||
$sourceArr[] = "`source` = ''";
|
||
$sourceArr[] = "`source` = 'null'";
|
||
} else {
|
||
$sourceArr[] = "`source` = '{$sourceCl}'";
|
||
}
|
||
}
|
||
$bd_usl .= " AND (".implode(" OR ",$sourceArr).")";
|
||
|
||
|
||
}
|
||
}
|
||
|
||
if(isset($_POST['funnel'])){
|
||
$funnelArr = json_decode(html_entity_decode($_POST['funnel']), ENT_QUOTES);
|
||
if(!empty($funnelArr)){
|
||
$bd_usl .= " AND funnel_id in (".implode(', ',$funnelArr).")";
|
||
}
|
||
}
|
||
$dates = getPeriod($period, $_POST['onDate'], $_POST['offDate']);
|
||
$date_between = $dates['between']; //var_dump($dates);
|
||
$whereTasks = '';//$dates['whereTasks'];
|
||
|
||
$row = array();
|
||
|
||
$bd_usl_managers = " AND who_work in (".implode(", ",$arrIdUser).")";
|
||
$sql = "SELECT `who_work`, count(*) as total FROM $table WHERE 1 $bd_usl_managers $bd_usl and $date_add $date_between group by `who_work`";
|
||
// echo $sql;
|
||
|
||
$q = mysql_query($sql);
|
||
while($r = mysql_fetch_assoc($q)){
|
||
$row[$r['who_work']] = $r['total'];
|
||
}
|
||
|
||
$sql = "SELECT `who_work`, step_id, count(*) as total FROM $table WHERE 1 $bd_usl_managers $bd_usl and $date_add $date_between and deleted=0 group by `who_work`, step_id";
|
||
// echo $sql;
|
||
|
||
$q = mysql_query($sql);
|
||
while($r = mysql_fetch_assoc($q)){
|
||
$row_all[$r['who_work']][$r['step_id']] = $r['total'];
|
||
|
||
}
|
||
|
||
|
||
|
||
/*$sql = "SELECT `who_work`, `step_id`, count(*) as total FROM clients WHERE 1 $bd_usl_managers $bd_usl $bd_do_period group by `who_work`,`step_id`";
|
||
|
||
$q = mysql_query($sql);
|
||
while($r = mysql_fetch_assoc($q)){
|
||
$row_do[$r['who_work']][$r['step_id']] = $r['total'];
|
||
}*/
|
||
$agencyId = User::getUserAgencyID();
|
||
$sql_denial = "SELECT * FROM denial_work WHERE (agency_id = 0 or agency_id={$agencyId})";
|
||
if($agencyId == 19895){
|
||
$sql_denial = "SELECT * FROM denial_work WHERE agency_id = {$agencyId} AND del = 0";
|
||
}
|
||
$q_denial = mysql_query($sql_denial);
|
||
$list_denial = array();
|
||
$list_denial[] = 0;
|
||
while($r_denial = mysql_fetch_assoc($q_denial)){
|
||
$list_denial[] = $r_denial['id'];
|
||
}
|
||
|
||
//file_put_contents(__DIR__.'/log.txt', file_get_contents(__DIR__.'/log.txt').'\r\n'.date('H:i:s'));
|
||
/* $dates = getPeriod($period, $_POST['onDate'], $_POST['offDate']);
|
||
$date_between = $dates['between'];
|
||
$whereTasks = $dates['whereTasks'];*/
|
||
|
||
$sql = "SELECT `who_work`, `step_id`, count(*) as total FROM $table WHERE 1 $bd_usl_managers $bd_usl and $date_add $date_between and deleted = 0 group by `who_work`,`step_id`";
|
||
|
||
//echo $sql;
|
||
$q = mysql_query($sql);
|
||
while($r = mysql_fetch_assoc($q)){
|
||
$row_left[$r['who_work']][$r['step_id']] = $r['total'];
|
||
}
|
||
|
||
$bd_usl_agent = " AND $pole_agent in (".implode(", ",$arrIdAgent).")";
|
||
$sql = "SELECT `who_work`, count(*) as total FROM $table WHERE 1 $bd_usl_managers $bd_usl and $date_add $date_between group by `who_work`";
|
||
if($table == 'requisitions'){
|
||
$sql = "SELECT user_id, count(*) as total FROM $table WHERE 1 $bd_usl_agent $bd_usl and $date_add $date_between group by user_id";
|
||
}
|
||
|
||
// echo $sql;
|
||
|
||
$q = mysql_query($sql);
|
||
while($r = mysql_fetch_assoc($q)){
|
||
if($table == 'requisitions'){
|
||
$row_add[$r['user_id']] = $r['total'];
|
||
} else {
|
||
$row_add[$r['who_work']] = $r['total'];
|
||
}
|
||
}
|
||
|
||
/*$arr_add_clients = array();
|
||
$sql = "SELECT clients.who_work, events_clients.dop_text, count(*) as total FROM $table LEFT JOIN events_clients on clients.id = events_clients.client_id WHERE 1 $bd_usl_managers $bd_usl AND events_clients.event='stageedit' and $date_add $date_between group by clients.who_work, events_clients.dop_text";
|
||
//echo $sql."\n\n";
|
||
$q = mysql_query($sql);
|
||
while($r = mysql_fetch_assoc($q)){
|
||
$arr_add_clients[] = $r;
|
||
}*/
|
||
|
||
|
||
$row_del = array();
|
||
$row_del_all = array();
|
||
$sql = "SELECT `who_work`, `denial`, `step_id`, count(*) as total FROM $table WHERE 1 $bd_usl_managers $bd_usl and $date_add $date_between and deleted <> 0 and confirm <> 10 group by `who_work`, `denial`, `step_id`";
|
||
|
||
$q = mysql_query($sql);
|
||
while($r = mysql_fetch_assoc($q)){
|
||
if(!isset($row_del[$r['who_work']][$r['step_id']][$r['denial']])) $row_del[$r['who_work']][$r['step_id']][$r['denial']] = 0;
|
||
$row_del[$r['who_work']][$r['step_id']][$r['denial']] += $r['total'];
|
||
if(!isset($row_del_all[$r['who_work']])) $row_del_all[$r['who_work']] = 0;
|
||
$row_del_all[$r['who_work']] += $r['total'];
|
||
}
|
||
|
||
$arr_do_clients = array();
|
||
$sql = "SELECT {$table}.who_work, events_clients.dop_text, {$table}.id FROM $table LEFT JOIN events_clients on {$table}.id = events_clients.{$pole_event} WHERE 1 $bd_usl_managers $bd_usl AND events_clients.event='stageedit' AND $date_add $date_between ";
|
||
|
||
//echo $sql."\n\n";
|
||
$q = mysql_query($sql);
|
||
while($r = mysql_fetch_assoc($q)){
|
||
$arr_do_clients[] = $r;
|
||
}
|
||
//var_dump($arr_do_clients);
|
||
//Сделки
|
||
$sql = "SELECT `who_work`, sum(summa) as summa, count(*) as total FROM $table WHERE 1 $bd_usl_managers $bd_usl and deleted = 1 and confirm = 10 and "
|
||
. "(SELECT `date_update` FROM `events_clients` WHERE {$pole_event} = {$table}.id AND `event` = 'delete' order by id desc limit 1) $date_between group by `who_work`" ;
|
||
//echo $sql;
|
||
$q = mysql_query($sql);
|
||
while($r = mysql_fetch_assoc($q)){
|
||
$row_summa[$r['who_work']] = $r['summa'];
|
||
$row_sdelka[$r['who_work']] = $r['total'];
|
||
}
|
||
|
||
$steps = array();
|
||
$steps_row = array();
|
||
$prev_step = array();
|
||
$next_step = array();
|
||
$arrEventOld =array();
|
||
$arrEvent = array();
|
||
$funnelArr = json_decode(html_entity_decode($_POST['funnel']), ENT_QUOTES);
|
||
if(!empty($funnelArr && count($funnelArr) == 1)){
|
||
$funnelId = $funnelArr[0];
|
||
|
||
$sqlst = "SELECT * FROM funnel_steps WHERE funnel_id=$funnelId AND deleted=0 ORDER by main DESC, order_number, branch" ;
|
||
$qst = mysql_query($sqlst);
|
||
|
||
while($st = mysql_fetch_assoc($qst)){
|
||
|
||
$steps[] = $st['id'];
|
||
$steps_row[] = $st;
|
||
}
|
||
|
||
$sqlcl = "SELECT `id`, confirm, step_id FROM $table WHERE 1 $bd_usl_managers $bd_usl and $date_add $date_between and step_id in (".implode(',', $steps).")";
|
||
// echo $sqlcl;
|
||
|
||
$qcl = mysql_query($sqlcl);
|
||
$ro = mysql_num_rows($qcl);
|
||
|
||
$whereEv = array();
|
||
$tempEv = array();
|
||
//$tempEv[] = 0;
|
||
$whereTr = '';
|
||
$tempTr = array();
|
||
// $tempTr[] = 0;
|
||
if($ro > 0){
|
||
while($rcl = mysql_fetch_assoc($qcl)){
|
||
// if($rcl['confirm'] == 1){
|
||
$tempEv[$rcl['step_id']][] = $rcl['id'];
|
||
//}
|
||
$tempTr[] = $rcl['id'];
|
||
}
|
||
}
|
||
|
||
foreach($steps as $step){
|
||
if(isset($tempEv[$step])){
|
||
$whereEv[$step] = ' AND '.$pole_event.' in ('.implode(', ', $tempEv[$step]).') ';
|
||
$whereEvPr[$step] = ' AND id_client in ('.implode(', ', $tempEv[$step]).') ';
|
||
}
|
||
|
||
}
|
||
|
||
$whereTr = ' AND '.$pole_event.' in ('.implode(', ', $tempTr).') ';
|
||
|
||
/* $sql_ac = "SELECT count(*), user_id, (select user_id from {$table} WHERE {$table}.id=events_clients.{$pole_event}) as parent_user_id FROM events_clients WHERE user_id in (". implode(', ', $usersId).") $whereTr AND event='accepted' and (SELECT id FROM events_clients as ec WHERE ec.{$pole_event} = events_clients.{$pole_event} AND event='transmitted' and ec.date_update = events_clients.date_update) is null and date $date_between group by user_id , {$pole_event}";
|
||
//echo $sql_ac."\n";
|
||
$q_ac = mysql_query($sql_ac);
|
||
while($r_ac = mysql_fetch_assoc($q_ac)){
|
||
|
||
if(isset($row_add[$r_ac['parent_user_id']]) && $row_add[$r_ac['parent_user_id']] > 0){
|
||
$row_add[$r_ac['parent_user_id']]--;
|
||
}
|
||
|
||
if(!isset($row_add[$r_ac['user_id']])) $row_add[$r_ac['user_id']] = 0;
|
||
$row_add[$r_ac['user_id']]++;
|
||
|
||
|
||
} */
|
||
|
||
|
||
//Переданные клиенты
|
||
|
||
/* $sql = "SELECT count(id) as total, user_id, {$pole_event} FROM events_clients WHERE user_id in (". implode(', ', $usersId).") and event='transmitted' $whereTr and date $date_between group by user_id,{$pole_event}" ;
|
||
echo $sql."\n\n";
|
||
$rez = mysql_query($sql);
|
||
while($r = mysql_fetch_assoc($rez)){
|
||
if(!isset($row_transmitted[$r['user_id']][$st['id']])) $row_transmitted[$r['user_id']][$st['id']] = 0;
|
||
$row_transmitted[$r['user_id']][$st['id']]++;
|
||
}
|
||
|
||
//Принятые клиенты
|
||
$sql = "SELECT count(id) as total, user_id,{$pole_event} FROM events_clients WHERE user_id in (". implode(', ', $usersId).") and event='accepted' $whereTr and date $date_between group by user_id, {$pole_event}" ;
|
||
//echo $sql."\n\n";
|
||
$rez = mysql_query($sql);
|
||
while($r = mysql_fetch_assoc($rez)){
|
||
if(!isset($row_accepted[$r['user_id']][$st['id']])) $row_accepted[$r['user_id']][$st['id']] = 0;
|
||
$row_accepted[$r['user_id']][$st['id']]++;
|
||
}*/
|
||
|
||
|
||
|
||
// считаем события клиентов
|
||
/* $sql = "SELECT count(id) as total, user_id, type FROM user_client_events WHERE user_id in (". implode(', ', $usersId).") and calendar_view = 0 AND cancel=0
|
||
and schedule_date is not null $whereTasks $whereEv and DATE_FORMAT(schedule_date, '%Y-%m-%d %H:%i:%s') < '".date("Y-m-d H:i:s")."' group by user_id, type";
|
||
// echo $sql;
|
||
$rez = mysql_query($sql);
|
||
while($r = mysql_fetch_assoc($rez)){
|
||
$arrEventOld[] = $r;
|
||
|
||
}
|
||
|
||
|
||
// считаем события клиентов
|
||
$sql = "SELECT count(id) as total, user_id, type FROM user_client_events WHERE user_id in (". implode(', ', $usersId).") and calendar_view = 0 AND cancel=0
|
||
and schedule_date is not null $whereTasks $whereEv and DATE_FORMAT(schedule_date, '%Y-%m-%d %H:%i:%s') > '".date("Y-m-d H:i:s")."' group by user_id,type";
|
||
//echo $sql;
|
||
$rez = mysql_query($sql);
|
||
|
||
while($r = mysql_fetch_assoc($rez)){
|
||
$arrEvent[] = $r;
|
||
|
||
}
|
||
|
||
// считаем события клиентов
|
||
$sql = "SELECT count(id) as total, user_id,type FROM user_client_events WHERE user_id in (". implode(', ', $usersId).") and calendar_view = 1 AND cancel=0
|
||
and schedule_date is not null $whereTasks $whereEv group by user_id,type";
|
||
//echo $sql;
|
||
//$work_sql = $sql;
|
||
$rez = mysql_query($sql);
|
||
|
||
while($r = mysql_fetch_assoc($rez)){
|
||
if(!isset($row_task_slung[$r['user_id']][$r['type']][$st['id']])) $row_task_slung[$r['user_id']][$r['type']][$st['id']] = 0;
|
||
$row_task_slung[$r['user_id']][$r['type']][$st['id']] = $r['total'];
|
||
}
|
||
|
||
|
||
// считаем события клиентов
|
||
$sql = "SELECT count(id) as total, user_id,type FROM user_client_events WHERE user_id in (". implode(', ', $usersId).") AND cancel=1
|
||
and schedule_date is not null $whereTasks $whereEv group by user_id,type";
|
||
//echo $sql;
|
||
//$work_sql = $sql;
|
||
$rez = mysql_query($sql);
|
||
|
||
while($r = mysql_fetch_assoc($rez)){
|
||
if(!isset($row_task_cancel[$r['user_id']][$r['type']][$st['id']])) $row_task_cancel[$r['user_id']][$r['type']][$st['id']] = 0;
|
||
$row_task_cancel[$r['user_id']][$r['type']][$st['id']] = $r['total'];
|
||
}*/
|
||
// var_dump($arrEvent);
|
||
foreach($steps_row as $st){
|
||
//С предыдущего этапа
|
||
// и на этап
|
||
//var_dump($arr_do_clients);
|
||
foreach ($arr_do_clients as $row_step) {
|
||
if(!isset($prev_step[$row_step['who_work']][$st['id']])) $prev_step[$row_step['who_work']][$st['id']] = 0;
|
||
if(!isset($next_step[$row_step['who_work']][$st['id']])) $next_step[$row_step['who_work']][$st['id']] = 0;
|
||
/*echo $st['id'].'-';
|
||
echo $st['name'].'-';
|
||
echo $row_step['dop_text']."\n\n";*/
|
||
if(strpos($row_step['dop_text'], "на «".$st['name']."»") !== false && strpos($row_step['dop_text'],"(Этап открыт повторно)") === false){
|
||
//echo $row_step['dop_text']."\n\n";
|
||
$prev_step[$row_step['who_work']][$st['id']]++;
|
||
}
|
||
if(strpos($row_step['dop_text'], "c «".$st['name']."»") !== false && strpos($row_step['dop_text'],"(Этап открыт повторно)") === false){
|
||
//echo $row_step['dop_text']."\n\n";
|
||
$next_step[$row_step['who_work']][$st['id']]++;
|
||
|
||
|
||
}
|
||
if(strpos($row_step['dop_text'],"(Этап открыт повторно)") !== false && strpos($row_step['dop_text'], "c «".$st['name']."»") !== false){
|
||
|
||
$prev_step[$row_step['who_work']][$st['id']]--;
|
||
}
|
||
if(strpos($row_step['dop_text'],"(Этап открыт повторно)") !== false && strpos($row_step['dop_text'], "на «".$st['name']."»") !== false){
|
||
|
||
$next_step[$row_step['who_work']][$st['id']]--;
|
||
}
|
||
|
||
|
||
}
|
||
|
||
// считаем события клиентов
|
||
if(isset($whereEv[$st['id']])){
|
||
|
||
$sql = "SELECT user_id, type, step_id FROM user_client_events WHERE user_id in (". implode(', ', $usersId).") and calendar_view = 0 AND cancel=0
|
||
and schedule_date is not null $whereTasks {$whereEv[$st['id']]} and DATE_FORMAT(schedule_date, '%Y-%m-%d %H:%i:%s') < '".date("Y-m-d H:i:s")."'";
|
||
// echo $sql;
|
||
$rez = mysql_query($sql);
|
||
while($r = mysql_fetch_assoc($rez)){
|
||
if($r['step_id'] > 0){
|
||
if(!isset($row_task_old[$r['user_id']][$r['type']][$r['step_id']])) $row_task_old[$r['user_id']][$r['type']][$r['step_id']] = 0;
|
||
$row_task_old[$r['user_id']][$r['type']][$r['step_id']]++;
|
||
} else {
|
||
if(!isset($row_task_old[$r['user_id']][$r['type']][$st['id']])) $row_task_old[$r['user_id']][$r['type']][$st['id']] = 0;
|
||
$row_task_old[$r['user_id']][$r['type']][$st['id']]++;
|
||
}
|
||
|
||
}
|
||
|
||
|
||
$sql = "SELECT user_id, type, step_id FROM user_client_events WHERE user_id in (". implode(', ', $usersId).") and calendar_view = 0 AND cancel=0
|
||
and schedule_date is not null $whereTasks {$whereEv[$st['id']]} and DATE_FORMAT(schedule_date, '%Y-%m-%d %H:%i:%s') > '".date("Y-m-d H:i:s")."'";
|
||
//echo $sql;
|
||
$rez = mysql_query($sql);
|
||
|
||
while($r = mysql_fetch_assoc($rez)){
|
||
if($r['step_id'] > 0){
|
||
if(!isset($row_task[$r['user_id']][$r['type']][$r['step_id']])) $row_task[$r['user_id']][$r['type']][$r['step_id']] = 0;
|
||
$row_task[$r['user_id']][$r['type']][$r['step_id']]++;
|
||
} else {
|
||
if(!isset($row_task[$r['user_id']][$r['type']][$st['id']])) $row_task[$r['user_id']][$r['type']][$st['id']] = 0;
|
||
$row_task[$r['user_id']][$r['type']][$st['id']]++;
|
||
}
|
||
|
||
}
|
||
|
||
|
||
// считаем события клиентов
|
||
$sql = "SELECT user_id,type, step_id FROM user_client_events WHERE user_id in (". implode(', ', $usersId).") and calendar_view = 1 AND cancel=0
|
||
and schedule_date is not null $whereTasks {$whereEv[$st['id']]}";
|
||
|
||
/* if($st['id'] == 626)
|
||
echo $sql;*/
|
||
//$work_sql = $sql;
|
||
$rez = mysql_query($sql);
|
||
|
||
while($r = mysql_fetch_assoc($rez)){
|
||
if($r['step_id'] > 0){
|
||
if(!isset($row_task_slung[$r['user_id']][$r['type']][$r['step_id']])) $row_task_slung[$r['user_id']][$r['type']][$r['step_id']] = 0;
|
||
$row_task_slung[$r['user_id']][$r['type']][$r['step_id']]++;
|
||
} else {
|
||
if(!isset($row_task_slung[$r['user_id']][$r['type']][$st['id']])) $row_task_slung[$r['user_id']][$r['type']][$st['id']] = 0;
|
||
$row_task_slung[$r['user_id']][$r['type']][$st['id']]++;
|
||
}
|
||
}
|
||
|
||
|
||
// считаем события клиентов
|
||
$sql = "SELECT user_id,type, step_id FROM user_client_events WHERE user_id in (". implode(', ', $usersId).") AND cancel=1
|
||
and schedule_date is not null $whereTasks {$whereEv[$st['id']]}";
|
||
//echo $sql;
|
||
//$work_sql = $sql;
|
||
$rez = mysql_query($sql);
|
||
|
||
while($r = mysql_fetch_assoc($rez)){
|
||
if($r['step_id'] > 0){
|
||
if(!isset($row_task_cancel[$r['user_id']][$r['type']][$r['step_id']])) $row_task_cancel[$r['user_id']][$r['type']][$r['step_id']] = 0;
|
||
$row_task_cancel[$r['user_id']][$r['type']][$r['step_id']]++;
|
||
} else {
|
||
if(!isset($row_task_cancel[$r['user_id']][$r['type']][$st['id']])) $row_task_cancel[$r['user_id']][$r['type']][$st['id']] = 0;
|
||
$row_task_cancel[$r['user_id']][$r['type']][$st['id']]++;
|
||
}
|
||
}
|
||
|
||
//Переданные клиенты
|
||
|
||
$sql = "SELECT count(id) as total, user_id, {$pole_event} FROM events_clients WHERE user_id in (". implode(', ', $usersId).") and event='transmitted' {$whereEv[$st['id']]} and date $date_between group by user_id ,{$pole_event}" ;
|
||
// echo $sql."\n\n";
|
||
$rez = mysql_query($sql);
|
||
while($r = mysql_fetch_assoc($rez)){
|
||
if(!isset($row_transmitted[$r['user_id']][$st['id']])) $row_transmitted[$r['user_id']][$st['id']] = 0;
|
||
$row_transmitted[$r['user_id']][$st['id']]++;
|
||
}
|
||
|
||
//Принятые клиенты
|
||
$sql = "SELECT count(id) as total, user_id,{$pole_event} FROM events_clients WHERE user_id in (". implode(', ', $usersId).") and event='accepted' {$whereEv[$st['id']]} and date $date_between group by user_id, {$pole_event}" ;
|
||
//echo $sql."\n\n";
|
||
$rez = mysql_query($sql);
|
||
while($r = mysql_fetch_assoc($rez)){
|
||
if(!isset($row_accepted[$r['user_id']][$st['id']])) $row_accepted[$r['user_id']][$st['id']] = 0;
|
||
$row_accepted[$r['user_id']][$st['id']]++;
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
}
|
||
|
||
/*if($_SESSION['id'] == 5238){
|
||
var_dump($row_task_old);
|
||
}*/
|
||
|
||
// var_dump($next_step);
|
||
|
||
$typesArr = ['call', 'deal', 'even', 'meet', 'show'];
|
||
$array_menedgers = array();
|
||
|
||
$departmentClass = new Department;
|
||
$departments = $departmentClass->getDepartments();
|
||
//var_dump($departments);
|
||
|
||
$users = array();
|
||
$sql_users = "SELECT id, agency, manager, agency_name, first_name, last_name, middle_name, id_manager, role_id FROM users WHERE id in (". implode(', ', $usersId).")";
|
||
$q_users = mysql_query($sql_users);
|
||
while($r_users = mysql_fetch_assoc($q_users)){
|
||
$users[$r_users['id']] = $r_users;
|
||
}
|
||
|
||
foreach($usersId as $key => $id){
|
||
$arrTemp = array();
|
||
$mstr = $users[$id];//mysql_fetch_assoc(mysql_query("SELECT agency, manager, agency_name, first_name, last_name, middle_name, id_manager FROM users WHERE id=".$id));
|
||
if($mstr['agency']){
|
||
$master = "Агентство ". trim($mstr['agency_name']) ." (". trim($mstr['last_name'] . ' ' . $mstr['first_name'] . ' ' . $mstr['middle_name']).")";
|
||
$arrTemp['post'] = 'agency';
|
||
$arrTemp['agency_name'] = $mstr['agency_name'];
|
||
}
|
||
else if($mstr['role_id'] > 0 && isset($departments[$mstr['role_id']])){
|
||
$master = trim($mstr['last_name'] . ' ' . $mstr['first_name'] . ' ' . $mstr['middle_name']).' ('.$departments[$mstr['role_id']]['role_name'].' '.$departments[$mstr['role_id']]['dep_name'].')';
|
||
if($mstr['manager']){
|
||
$arrTemp['post'] = 'manager';
|
||
} else {
|
||
$arrTemp['post'] = 'agent';
|
||
}
|
||
|
||
}
|
||
else if($mstr['manager']){
|
||
$master = "Менеджер " . trim($mstr['last_name'] . ' ' . $mstr['first_name'] . ' ' . $mstr['middle_name']);
|
||
$arrTemp['post'] = 'manager';
|
||
|
||
}
|
||
else {
|
||
$master = "Агент " . trim($mstr['last_name'] . ' ' . $mstr['first_name'] . ' ' . $mstr['middle_name']);
|
||
$arrTemp['post'] = 'agent';
|
||
}
|
||
$arrTemp['id_manager'] = $mstr['id_manager'];
|
||
$arrTemp['id'] = $id;
|
||
$arrTemp['fio'] = $master;
|
||
$arrTemp['work'] = 0;
|
||
$arrTemp['work_do'] = 0;
|
||
|
||
if(isset($row[$id])) {
|
||
$arrTemp['work'] = $row[$id];
|
||
if($arrTemp['post'] == 'manager'){
|
||
$array_menedgers[$id]['work'] = $row[$id];
|
||
}
|
||
|
||
}
|
||
|
||
$arrTemp['work_add'] = 0;
|
||
|
||
if(isset($row_add[$id])) {
|
||
$arrTemp['work_add'] = $row_add[$id];
|
||
if($arrTemp['post'] == 'manager'){
|
||
$array_menedgers[$id]['work_add'] = $row_add[$id];
|
||
|
||
}
|
||
}
|
||
|
||
$arrTemp['work_del_all'] = 0;
|
||
if(isset($row_del_all[$id])) {
|
||
$arrTemp['work_del_all'] = $row_del_all[$id];
|
||
if($arrTemp['post'] == 'manager'){
|
||
$array_menedgers[$id]['work_del_all'] = $row_del_all[$id];
|
||
}
|
||
}
|
||
|
||
$arrTemp['summa'] = 0;
|
||
if(isset($row_summa[$id])) {
|
||
$arrTemp['summa'] = $row_summa[$id];
|
||
if($arrTemp['post'] == 'manager'){
|
||
$array_menedgers[$id]['summa'] = $row_summa[$id];
|
||
}
|
||
}
|
||
|
||
$arrTemp['sdelka'] = 0;
|
||
if(isset($row_sdelka[$id])) {
|
||
$arrTemp['sdelka'] = $row_sdelka[$id];
|
||
if($arrTemp['post'] == 'manager'){
|
||
$array_menedgers[$id]['sdelka'] = $row_sdelka[$id];
|
||
}
|
||
}
|
||
|
||
/*if(isset($row_do[$id])) {
|
||
|
||
foreach($row_do[$id] as $step=>$total){
|
||
$arrTemp['work_do_'.$step] = array('total'=>$total, 'step'=>$step);
|
||
if($arrTemp['post'] == 'manager'){
|
||
$array_menedgers[$id]['work_do_'.$step] = $total;
|
||
}
|
||
}
|
||
}*/
|
||
|
||
if(isset($row_left[$id])) {
|
||
foreach($row_left[$id] as $step=>$total){
|
||
$arrTemp['work_left_'.$step] = $total;
|
||
if($arrTemp['post'] == 'manager'){
|
||
$array_menedgers[$id]['work_left_'.$step] = $total;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
//var_dump($step_not);
|
||
if(isset($row_transmitted[$id])){
|
||
foreach($row_transmitted[$id] as $step=>$total){
|
||
$arrTemp['transmitted_'.$step] = $total;
|
||
if($arrTemp['post'] == 'manager'){
|
||
$array_menedgers[$id]['transmitted_'.$step] = $total;
|
||
}
|
||
}
|
||
}
|
||
|
||
if(isset($row_accepted[$id])){
|
||
foreach($row_accepted[$id] as $step=>$total){
|
||
$arrTemp['accepted_'.$step] = $total;
|
||
if($arrTemp['post'] == 'manager'){
|
||
$array_menedgers[$id]['accepted_'.$step] = $total;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
//var_dump($prev_step);
|
||
$step_not = array();
|
||
if(!empty($steps)){
|
||
foreach($steps as $step){
|
||
$arrTemp['work_prev_step_'.$step] = 0;
|
||
$arrTemp['work_next_step_'.$step] = 0;
|
||
$arrTemp['work_all_'.$step] = 0;
|
||
//var_dump($row_all[$id]);
|
||
$step_not[] = $step;
|
||
if(isset($row_all[$id])) {
|
||
|
||
$arrTemp['work_all_'.$step] += $row_all[$id][$step];
|
||
if($arrTemp['post'] == 'manager'){
|
||
if(!isset($array_menedgers[$id]['work_all_'.$step])) $array_menedgers[$id]['work_all_'.$step] = 0;
|
||
$array_menedgers[$id]['work_all_'.$step] += $row_all[$id][$step];
|
||
}
|
||
|
||
}
|
||
|
||
if(isset($prev_step[$id][$step])){
|
||
$arrTemp['work_prev_step_'.$step] += $prev_step[$id][$step];
|
||
if($arrTemp['post'] == 'manager'){
|
||
if(!isset($array_menedgers[$id]['work_prev_step_'.$step])) $array_menedgers[$id]['work_prev_step_'.$step] = 0;
|
||
$array_menedgers[$id]['work_prev_step_'.$step] += $prev_step[$id][$step];
|
||
}
|
||
// var_dump($prev_step[$id]);
|
||
}
|
||
if(isset($next_step[$id][$step])){
|
||
$arrTemp['work_next_step_'.$step] += $next_step[$id][$step];
|
||
/*if($arrTemp['post'] == 'manager'){
|
||
if(!isset($array_menedgers[$id]['work_next_step_'.$step])) $array_menedgers[$id]['work_next_step_'.$step] = 0;
|
||
$array_menedgers[$id]['work_next_step_'.$step] += $next_step[$id][$step];
|
||
}*/
|
||
// var_dump($prev_step[$id]);
|
||
}
|
||
//echo $arrTemp['work_next_step_'.$step]."\n";
|
||
//var_dump($arrTemp['work_all_'.$step]);
|
||
|
||
if(isset($row_task_old[$id])) {
|
||
foreach($typesArr as $type){
|
||
if(!isset($arrTemp[$type][$step]['task_old'])) $arrTemp[$type][$step]['task_old'] = 0;
|
||
if(isset($row_task_old[$id][$type][$step])){
|
||
$arrTemp[$type][$step]['task_old'] += $row_task_old[$id][$type][$step];
|
||
if($arrTemp['post'] == 'manager'){
|
||
$array_menedgers[$id][$type][$step]['task_old'] = $row_task_old[$id][$type][$step];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if(isset($row_task[$id])) {
|
||
foreach($typesArr as $type){
|
||
if(!isset($arrTemp[$type][$step]['task_new'])) $arrTemp[$type][$step]['task_new'] = 0;
|
||
if(isset($row_task[$id][$type][$step])){
|
||
$arrTemp[$type][$step]['task_new'] += $row_task[$id][$type][$step];
|
||
if($arrTemp['post'] == 'manager'){
|
||
$array_menedgers[$id][$type][$step]['task_new'] = $row_task[$id][$type][$step];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if(isset($row_task_slung[$id])) {
|
||
foreach($typesArr as $type){
|
||
if(!isset($arrTemp[$type][$step]['task_slung'])) $arrTemp[$type][$step]['task_slung'] = 0;
|
||
if(isset($row_task_slung[$id][$type][$step])){
|
||
$arrTemp[$type][$step]['task_slung'] += $row_task_slung[$id][$type][$step];
|
||
if($arrTemp['post'] == 'manager'){
|
||
$array_menedgers[$id][$type][$step]['task_slung'] = $row_task_slung[$id][$type][$step];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
if(isset($row_task_cancel[$id])) {
|
||
foreach($typesArr as $type){
|
||
if(!isset($arrTemp[$type][$step]['task_cancel'])) $arrTemp[$type][$step]['task_cancel'] = 0;
|
||
if(isset($row_task_cancel[$id][$type][$step])){
|
||
$arrTemp[$type][$step]['task_cancel'] += $row_task_cancel[$id][$type][$step];
|
||
if($arrTemp['post'] == 'manager'){
|
||
$array_menedgers[$id][$type][$step]['task_cancel'] = $row_task_cancel[$id][$type][$step];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
foreach($list_denial as $denial){
|
||
$arrTemp[$step]['denial_'.$denial] = 0;
|
||
if(isset($row_del[$id][$step][$denial])){
|
||
$arrTemp[$step]['denial_'.$denial] = $row_del[$id][$step][$denial];
|
||
if($arrTemp['post'] == 'manager'){
|
||
$array_menedgers[$id][$step]['denial_'.$denial] = $row_del[$id][$step][$denial];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
if(isset($rows[$mstr['id_manager']])){
|
||
|
||
foreach($steps as $step){
|
||
|
||
/*if(isset($arrTemp['work_do_'.$step]['total'])) {
|
||
if(!isset($rows[$mstr['id_manager']]['work_do_'.$step]['total'])) $rows[$mstr['id_manager']]['work_do_'.$step] = array('total'=>0, 'step'=>$step);
|
||
$rows[$mstr['id_manager']]['work_do_'.$step] = array('total'=>(int)$rows[$mstr['id_manager']]['work_do_'.$step]['total'] + (int)$arrTemp['work_do_'.$step]['total'], 'step'=>$step);
|
||
}*/
|
||
|
||
// if(isset($row_left[$id][$step])) {
|
||
// if(!isset($rows[$mstr['id_manager']]['work_left_'.$step])) $rows[$mstr['id_manager']]['work_left_'.$step] = 0;
|
||
// $rows[$mstr['id_manager']]['work_left_'.$step] = (int)$rows[$mstr['id_manager']]['work_left_'.$step] + (int)$row_left[$id][$step];
|
||
|
||
// }
|
||
|
||
// if(isset($arrTemp['work_all_'.$step])) {
|
||
// if(!isset($rows[$mstr['id_manager']]['work_all_'.$step])) $rows[$mstr['id_manager']]['work_all_'.$step] = 0;
|
||
// $rows[$mstr['id_manager']]['work_all_'.$step] = (int)$rows[$mstr['id_manager']]['work_all_'.$step] + (int)$arrTemp['work_all_'.$step];
|
||
|
||
// }
|
||
|
||
// if(isset($arrTemp['work_prev_step_'.$step])) {
|
||
// if(!isset($rows[$mstr['id_manager']]['work_prev_step_'.$step])) $rows[$mstr['id_manager']]['work_prev_step_'.$step] = 0;
|
||
// $rows[$mstr['id_manager']]['work_prev_step_'.$step] = (int)$rows[$mstr['id_manager']]['work_prev_step_'.$step] + (int)$arrTemp['work_prev_step_'.$step];
|
||
|
||
// }
|
||
|
||
/* if(isset($arrTemp['work_next_step_'.$step])) {
|
||
if(!isset($rows[$mstr['id_manager']]['work_next_step_'.$step])) $rows[$mstr['id_manager']]['work_next_step_'.$step] = 0;
|
||
$rows[$mstr['id_manager']]['work_next_step_'.$step] = (int)$rows[$mstr['id_manager']]['work_next_step_'.$step] + (int)$arrTemp['work_next_step_'.$step];
|
||
|
||
}*/
|
||
//echo $rows[$mstr['id_manager']]['work_next_step_'.$step]."\n\n";
|
||
/*if(isset($row_transmitted[$id][$step])) {
|
||
if(!isset($rows[$mstr['id_manager']]['transmitted_'.$step]['total'])) $rows[$mstr['id_manager']]['transmitted_'.$step] = array('total'=>0, 'step'=>$step);
|
||
$rows[$mstr['id_manager']]['transmitted_'.$step] = array('total'=>(int)$rows[$mstr['id_manager']]['transmitted_'.$step]['total'] + (int)$row_transmitted[$id][$step], 'step'=>$step);
|
||
|
||
}
|
||
|
||
if(isset($row_accepted[$id][$step])) {
|
||
if(!isset($rows[$mstr['id_manager']]['accepted_'.$step]['total'])) $rows[$mstr['id_manager']]['accepted_'.$step] = array('total'=>0, 'step'=>$step);
|
||
$rows[$mstr['id_manager']]['accepted_'.$step] = array('total'=>(int)$rows[$mstr['id_manager']]['accepted_'.$step]['total'] + (int)$row_accepted[$id][$step], 'step'=>$step);
|
||
|
||
}*/
|
||
|
||
|
||
|
||
// foreach($typesArr as $type){
|
||
// if(isset($row_task_old[$id])) {
|
||
// if(!isset($rows[$mstr['id_manager']][$type][$step]['task_old'])) $rows[$mstr['id_manager']][$type][$step]['task_old'] = 0;
|
||
// if(!isset($arrTemp[$type][$step]['task_old'])) $arrTemp[$type][$step]['task_old'] = 0;
|
||
// $rows[$mstr['id_manager']][$type][$step]['task_old'] = (int)$rows[$mstr['id_manager']][$type][$step]['task_old'] + (int)$arrTemp[$type][$step]['task_old'];
|
||
// }
|
||
// if(isset($row_task[$id])) {
|
||
// if(!isset($rows[$mstr['id_manager']][$type][$step]['task_new'])) $rows[$mstr['id_manager']][$type][$step]['task_new'] = 0;
|
||
// if(!isset($arrTemp[$type][$step]['task_new'])) $arrTemp[$type][$step]['task_new'] = 0;
|
||
// $rows[$mstr['id_manager']][$type][$step]['task_new'] = (int)$rows[$mstr['id_manager']][$type][$step]['task_new'] + (int)$arrTemp[$type][$step]['task_new'];
|
||
// }
|
||
|
||
// if(isset($row_task_slung[$id])) {
|
||
// if(!isset($rows[$mstr['id_manager']][$type][$step]['task_slung'])) $rows[$mstr['id_manager']][$type][$step]['task_slung'] = 0;
|
||
// if(!isset($arrTemp[$type][$step]['task_slung'])) $arrTemp[$type][$step]['task_slung'] = 0;
|
||
// $rows[$mstr['id_manager']][$type][$step]['task_slung'] = (int)$rows[$mstr['id_manager']][$type][$step]['task_slung'] + (int)$arrTemp[$type][$step]['task_slung'];
|
||
// }
|
||
// if(isset($row_task_cancel[$id])) {
|
||
// if(!isset($rows[$mstr['id_manager']][$type][$step]['task_cancel'])) $rows[$mstr['id_manager']][$type][$step]['task_cancel'] = 0;
|
||
// if(!isset($arrTemp[$type][$step]['task_cancel'])) $arrTemp[$type][$step]['task_cancel'] = 0;
|
||
// $rows[$mstr['id_manager']][$type][$step]['task_cancel'] = (int)$rows[$mstr['id_manager']][$type][$step]['task_cancel'] + (int)$arrTemp[$type][$step]['task_cancel'];
|
||
// }
|
||
|
||
// }
|
||
|
||
// foreach($list_denial as $denial){
|
||
// if(isset($row_del[$id][$step][$denial])){
|
||
// $rows[$mstr['id_manager']][$step]['denial_'.$denial] = (int)$rows[$mstr['id_manager']][$step]['denial_'.$denial] + $row_del[$id][$step][$denial];
|
||
// }
|
||
// }
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
// $rows[$mstr['id_manager']]['work'] = (int)$rows[$mstr['id_manager']]['work'] + (int)$row[$id];
|
||
// $rows[$mstr['id_manager']]['work_add'] = (int)$rows[$mstr['id_manager']]['work_add'] + (int)$row_add[$id];
|
||
|
||
// $rows[$mstr['id_manager']]['summa'] = (int)$rows[$mstr['id_manager']]['summa'] + (int)$row_summa[$id];
|
||
// $rows[$mstr['id_manager']]['sdelka'] = (int)$rows[$mstr['id_manager']]['sdelka'] + (int)$row_sdelka[$id];
|
||
|
||
// $rows[$mstr['id_manager']]['work_del_all'] = (int)$rows[$mstr['id_manager']]['work_del_all'] + $row_del_all[$id];
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
$rows[$id] = $arrTemp;
|
||
}
|
||
//file_put_contents(__DIR__.'/log.txt', file_get_contents(__DIR__.'/log.txt').'\r\n'.date('H:i:s'));
|
||
//var_dump($rows);
|
||
$res = array();
|
||
//print_r($rows);
|
||
foreach ($rows as $key => $row ){
|
||
if(isset($rows[$row['id_manager']]) && $row['post'] == 'manager'){
|
||
|
||
|
||
$i=0;
|
||
foreach($steps as $step){
|
||
|
||
// $rows[$row['id_manager']]['work_do_'.$step] = array('total' => (int)$rows[$row['id_manager']]['work_do_'.$step]['total'] + (int)$row['work_do_'.$step]['total'] - (int)$array_menedgers[$row['id']]['work_do_'.$step], 'step'=> $step) ;
|
||
|
||
//$rows[$row['id_manager']]['work_left_'.$step] = (int)$rows[$row['id_manager']]['work_left_'.$step] + (int)$row['work_left_'.$step] - (int)$array_menedgers[$row['id']]['work_left_'.$step];
|
||
//$rows[$row['id_manager']]['work_all_'.$step] = (int)$rows[$row['id_manager']]['work_all_'.$step] + (int)$row['work_all_'.$step] - (int)$array_menedgers[$row['id']]['work_all_'.$step];
|
||
//$rows[$row['id_manager']]['work_prev_step_'.$step] = (int)$rows[$row['id_manager']]['work_prev_step_'.$step] + (int)$row['work_prev_step_'.$step]-(int)$array_menedgers[$row['id']]['work_prev_step_'.$step] ;
|
||
//$rows[$row['id_manager']]['work_next_step_'.$step] = (int)$rows[$row['id_manager']]['work_next_step_'.$step] + (int)$row['work_next_step_'.$step]-(int)$array_menedgers[$row['id']]['work_next_step_'.$step] ;
|
||
|
||
/*$rows[$row['id_manager']]['transmitted_'.$step] = array('total' => (int)$rows[$row['id_manager']]['transmitted_'.$step]['total'] + (int)$row['transmitted_'.$step]['total']-(int)$array_menedgers[$row['id']]['transmitted_'.$step], 'step'=> $step) ;
|
||
$rows[$row['id_manager']]['accepted_'.$step] = array('total' => (int)$rows[$row['id_manager']]['accepted_'.$step]['total'] + (int)$row['accepted_'.$step]['total']-(int)$array_menedgers[$row['id']]['accepted_'.$step], 'step'=> $step) ;
|
||
*/
|
||
|
||
$i++;
|
||
}
|
||
|
||
|
||
|
||
if(!empty($steps)){
|
||
foreach($steps as $step){
|
||
|
||
foreach($typesArr as $type){
|
||
if(!isset($rows[$row['id_manager']][$type][$step]['task_old'])) $rows[$row['id_manager']][$type][$step]['task_old'] = 0;
|
||
$rows[$row['id_manager']][$type][$step]['task_old'] = (int)$rows[$row['id_manager']][$type][$step]['task_old'] + (int)$row[$type][$step]['task_old']-(int)$array_menedgers[$row['id']][$type][$step]['task_old'];
|
||
}
|
||
|
||
|
||
|
||
foreach($typesArr as $type){
|
||
if(!isset($rows[$row['id_manager']][$type][$step]['task_new'])) $rows[$row['id_manager']][$type][$step]['task_new'] = 0;
|
||
$rows[$row['id_manager']][$type][$step]['task_new'] = (int)$rows[$row['id_manager']][$type][$step]['task_new'] + (int)$row[$type][$step]['task_new']-(int)$array_menedgers[$row['id']][$type][$step]['task_new'];
|
||
}
|
||
|
||
|
||
foreach($typesArr as $type){
|
||
if(!isset($rows[$row['id_manager']][$type][$step]['task_slung'])) $rows[$row['id_manager']][$type][$step]['task_slung'] = 0;
|
||
$rows[$row['id_manager']][$type][$step]['task_slung'] = (int)$rows[$row['id_manager']][$type][$step]['task_slung'] + (int)$row[$type][$step]['task_slung']-(int)$array_menedgers[$row['id']][$type][$step]['task_slung'];
|
||
}
|
||
|
||
|
||
foreach($typesArr as $type){
|
||
if(!isset($rows[$row['id_manager']][$type][$step]['task_cancel'])) $rows[$row['id_manager']][$type][$step]['task_cancel'] = 0;
|
||
$rows[$row['id_manager']][$type][$step]['task_cancel'] = (int)$rows[$row['id_manager']][$type][$step]['task_cancel'] + (int)$row[$type][$step]['task_cancel']-(int)$array_menedgers[$row['id']][$type][$step]['task_cancel'];
|
||
}
|
||
|
||
foreach($list_denial as $denial){
|
||
|
||
$rows[$row['id_manager']][$step]['denial_'.$denial] = (int)$rows[$row['id_manager']][$step]['denial_'.$denial] + (int)$row[$step]['denial_'.$denial] - (int)$array_menedgers[$row['id']][$step]['denial_'.$denial];
|
||
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
$rows[$row['id_manager']]['work'] = (int)$rows[$row['id_manager']]['work'] + (int)$row['work']-(int)$array_menedgers[$row['id']]['work'];
|
||
$rows[$row['id_manager']]['work_add'] = (int)$rows[$row['id_manager']]['work_add'] + (int)$row['work_add']-(int)$array_menedgers[$row['id']]['work_add'];
|
||
$rows[$row['id_manager']]['summa'] = (int)$rows[$row['id_manager']]['summa'] + (int)$row['summa']-(int)$array_menedgers[$row['id']]['summa'];
|
||
$rows[$row['id_manager']]['sdelka'] = (int)$rows[$row['id_manager']]['sdelka'] + (int)$row['sdelka']-(int)$array_menedgers[$row['id']]['sdelka'];
|
||
$rows[$row['id_manager']]['work_del_all'] = (int)$rows[$row['id_manager']]['work_del_all'] + (int)$row['work_del_all']-(int)$array_menedgers[$row['id']]['work_del_all'];
|
||
|
||
}
|
||
//$res[] = $row;
|
||
}
|
||
|
||
$part_href = '';
|
||
|
||
if(isset($activitiesArr) && !empty($activitiesArr)){
|
||
$part_href .= '&activities='.implode(", ", $activitiesArr);
|
||
}
|
||
|
||
|
||
if(isset($sourcesArr) && !empty($sourcesArr)){
|
||
$part_href .= '&source='.implode(", ", $sourcesArr);
|
||
}
|
||
|
||
if(isset($period) && $period == 'dates'){
|
||
if(isset($dates['dateStart'])){
|
||
$part_href .= '&date_start='.strtotime($dates['dateStart']);
|
||
}
|
||
if(isset($dates['dateEnd'])){
|
||
$part_href .= '&date_end='.strtotime($dates['dateEnd']);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
foreach ($rows as $user_id => $row ){
|
||
$id = $row['id'];
|
||
$row['conversion'] = round($row['sdelka']/$row['work']*100, 2).'%';
|
||
$row['conversion_del'] = round($row['work_del_all']/$row['work']*100, 2).'%';
|
||
$row['sdelka_summa'] = $row['sdelka'].'/'.number_format($row['summa'],0 , '.', ' ');
|
||
|
||
|
||
$i = 0;
|
||
|
||
foreach($steps as $step){
|
||
|
||
$row['work_all_'.$step] = '<a data-val="'.$row['work_all_'.$step].'" target="_blank" href="/'.$script.'?filter_stage=filter_stage_work&emp='.$user_id.'&funnelId='.$funnelId.'&period='.$period.'&resetFilter=1&step='.$step.'&filter_emp=[\'I_' . $id . '\']'.$part_href.'">'.$row['work_all_'.$step].'</a>';
|
||
$row['conversion_'.$step] = round (($row['work_next_step_'.$step]/$row['work_prev_step_'.$step])*100,2) ."%";
|
||
|
||
if($i == 0){
|
||
$row['conversion_'.$step] = round (($row['work_next_step_'.$step]/$row['work'])*100,2) ."%";
|
||
|
||
}
|
||
if(!isset($row['work_left_'.$step])) $row['work_left_'.$step] = 0;
|
||
$row['work_left_'.$step] = '<a data-val="'.$row['work_left_'.$step].'" target="_blank" href="/'.$script.'?filter_stage=filter_stage_work&emp='.$user_id.'&funnelId='.$funnelId.'&period='.$period.'&resetFilter=1&step='.$step.'&filter_emp=[\'I_' . $id . '\']'.$part_href.'">'.$row['work_left_'.$step].'</a>';
|
||
if(!isset($row['accepted_'.$step])) $row['accepted_'.$step] = 0;
|
||
$row['accepted_'.$step] = '<a data-val="'.$row['accepted_'.$step].'" href="/'.$script.'?filter_stage=filter_work_add&emp='.$user_id.'&funnelId='.$funnelId.'&period='.$period.'&step='.$step.'&resetFilter=1&filter_emp=[\'I_' . $id . '\']&accepted=1'.$part_href.'" target="_blank">'.$row['accepted_'.$step].'</a>';
|
||
if(!isset($row['transmitted_'.$step])) $row['transmitted_'.$step] = 0;
|
||
$row['transmitted_'.$step] = '<a data-val="'.$row['transmitted_'.$step].'" href="/'.$script.'?filter_stage=filter_work_add&emp='.$user_id.'&funnelId='.$funnelId.'&period='.$period.'&step='.$step.'&resetFilter=1&filter_emp=[\'I_' . $id . '\']&transmitted=1'.$part_href.'" target="_blank">'.$row['transmitted_'.$step].'</a>';
|
||
|
||
$row['closest_'.$step.'_all'] = 0;
|
||
foreach($list_denial as $denial){
|
||
$row['closest_'.$step.'_'.$denial] = 0;
|
||
if(isset($row[$step]['denial_'.$denial])){
|
||
$row['closest_'.$step.'_'.$denial] = $row[$step]['denial_'.$denial];
|
||
}
|
||
$row['closest_'.$step.'_all'] += $row['closest_'.$step.'_'.$denial];
|
||
$row['closest_'.$step.'_'.$denial] = '<a data-val="'.$row['closest_'.$step.'_'.$denial].'" href="/'.$script.'?filter_stage=filter_stage_close&emp='.$user_id.'&funnelId='.$funnelId.'&period='.$period.'&resetFilter=1&step='.$step.'&filter_emp=[\'I_' . $id . '\']&denial='.$denial.'&date_closer=11'.$part_href.'" target="_blank">'.$row['closest_'.$step.'_'.$denial].'</a>';
|
||
|
||
}
|
||
$row['conversionclosest_'.$step] = round (($row['closest_'.$step.'_all']/$row['work_prev_step_'.$step])*100,2).'%';
|
||
if($i == 0){
|
||
$row['conversionclosest_'.$step] = round (($row['closest_'.$step.'_all']/$row['work'])*100,2).'%';
|
||
$row['work'] = '<a data-val="'.$row['work'].'" href="/'.$script.'?filter_stage=filter_work_wor&emp='.$user_id.'&funnelId='.$funnelId.'&period='.$period.'&resetFilter=1&filter_emp=[\'I_' . $id . '\']'.$part_href.'" target="_blank">'.$row['work'].'</a>';
|
||
}
|
||
$row['closest_'.$step.'_all'] = '<a data-val="'.$row['closest_'.$step.'_all'].'" href="/'.$script.'?filter_stage=filter_stage_close&emp='.$user_id.'&funnelId='.$funnelId.'&period='.$period.'&step='.$step.'&resetFilter=1&filter_emp=[\'I_' . $id . '\']'.$part_href.'" target="_blank">'.$row['closest_'.$step.'_all'].'</a>';
|
||
$row['work_next_step_'.$step] = $row['work_next_step_'.$step];
|
||
$row['work_prev_step_'.$step] = $row['work_prev_step_'.$step];
|
||
//$row[]
|
||
|
||
$i++;
|
||
}
|
||
|
||
$row['work_add'] = '<a data-val="'.$row['work_add'].'" target="_blank" href="/'.$script.'?filter_stage=filter_work_add&emp='.$user_id.'&funnelId='.$funnelId.'&period='.$period.'&step=all&resetFilter=1&filter_emp=[\'I_' . $id . '\']'.$part_href.'">'.$row['work_add'].'</a>';
|
||
|
||
$res[] = $row;
|
||
|
||
|
||
//$res[]
|
||
}
|
||
|
||
$result = array(
|
||
'rows' => $res,
|
||
'total' => count($usersId),
|
||
'totalNotFiltered'=>count($usersId),
|
||
|
||
);
|
||
/*$time = microtime(true) - $start;
|
||
file_put_contents(__DIR__.'/log.txt', 'Время выполнения скрипта: '.round($time, 4).' сек.');*/
|
||
echo json_encode($result);
|
||
/*{
|
||
"current": 1,
|
||
"rowCount": 10,
|
||
"rows": [
|
||
{
|
||
"id": 19,
|
||
"sender": "123@test.de",
|
||
"": "2014-05-30T22:15:00"
|
||
},
|
||
{
|
||
"id": 14,
|
||
"sender": "123@test.de",
|
||
"received": "2014-05-30T20:15:00"
|
||
},
|
||
...
|
||
],
|
||
"total": 1123
|
||
}*/
|