554 lines
20 KiB
PHP
554 lines
20 KiB
PHP
|
|
<?php
|
||
|
|
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
|
||
|
|
require_once($_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php');
|
||
|
|
/*error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
|
||
|
|
ini_set('display_startup_errors', 1);
|
||
|
|
ini_set('display_errors', '1');*/
|
||
|
|
|
||
|
|
// hide_client_contacts: маскируем fio/email/phone клиента в Excel-выгрузке.
|
||
|
|
$hideContactsExcel = function_exists('should_hide_contacts_for_current_user')
|
||
|
|
&& should_hide_contacts_for_current_user();
|
||
|
|
|
||
|
|
$date = date('d.m.Y H-i-s');
|
||
|
|
//$name = 'clients.xlsx';
|
||
|
|
|
||
|
|
$columns = json_decode($_POST['columns'], true);
|
||
|
|
//$clients = $columns['clients'];
|
||
|
|
|
||
|
|
//*********************** СБОР ДАННЫХ ******************************************//
|
||
|
|
|
||
|
|
$currentUserId = $_SESSION['id'];
|
||
|
|
|
||
|
|
$user_view = new User;
|
||
|
|
$user_view->get($currentUserId);
|
||
|
|
|
||
|
|
if (!isset($user_view->agencyId)) {
|
||
|
|
$user_view->agencyId = $currentUserId;
|
||
|
|
$user_view->agencyName = $user_view->agency_name;
|
||
|
|
}
|
||
|
|
|
||
|
|
$agency_id = (int) $user_view->agencyId;
|
||
|
|
|
||
|
|
$tableId = (int) $columns['id'];
|
||
|
|
|
||
|
|
$tableDBO = mysql_query("SELECT * FROM `stat_tables` WHERE `id`=$tableId");
|
||
|
|
$table;
|
||
|
|
while ($row = mysql_fetch_assoc($tableDBO)) {
|
||
|
|
$table = $row;
|
||
|
|
$table['json_funnel'] = json_decode(htmlspecialchars_decode($table['json_funnel']), true);
|
||
|
|
|
||
|
|
for ($j = 0; $j < count($table['json_funnel']); $j++) {
|
||
|
|
for ($i = 0; $i < count($table['json_funnel'][$j]['steps']); $i++) {
|
||
|
|
$stepId = (int) $table['json_funnel'][$j]['steps'][$i]['id'];
|
||
|
|
$stepDBO = mysql_query("SELECT name FROM `funnel_steps` WHERE `id`=$stepId");
|
||
|
|
while ($row2 = mysql_fetch_assoc($stepDBO)) {
|
||
|
|
$table['json_funnel'][$j]['steps'][$i]['name'] = $row2['name'];
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$table['json_add'] = json_decode(htmlspecialchars_decode($table['json_add']), true);
|
||
|
|
}
|
||
|
|
|
||
|
|
$clients = array();
|
||
|
|
|
||
|
|
for ($i = 0; $i < count($table['json_funnel']); $i++) {
|
||
|
|
$funnelId = (int) $table['json_funnel'][$i]['id'];
|
||
|
|
|
||
|
|
$sqlDBO = "SELECT * FROM `clients` WHERE `funnel_id`=$funnelId";
|
||
|
|
if(isset($table['json_add']['sources']) && !empty($table['json_add']['sources'])){
|
||
|
|
$sqlDBO .= " AND source in (".implode(', ', $table['json_add']['sources']).")";
|
||
|
|
}
|
||
|
|
|
||
|
|
$clientsDBO = mysql_query($sqlDBO);
|
||
|
|
|
||
|
|
while ($row = mysql_fetch_assoc($clientsDBO)) {
|
||
|
|
array_push($clients, $row);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
for ($i = 0; $i < count($clients); $i++) {
|
||
|
|
|
||
|
|
$eventsDBO = mysql_query("SELECT id, comment,create_date FROM user_client_events WHERE client_id=" . $clients[$i]['id']);
|
||
|
|
$events = array();
|
||
|
|
while ($row = mysql_fetch_assoc($eventsDBO)) {
|
||
|
|
array_push($events, $row);
|
||
|
|
}
|
||
|
|
$clients[$i]['events'] = $events;
|
||
|
|
$clients[$i]['objects'] = json_decode(htmlspecialchars_decode($clients[$i]['objects']), true);
|
||
|
|
$objectsId = '';
|
||
|
|
for ($j = 1; $j < count($clients[$i]['objects']); $j++) {
|
||
|
|
if(isset($clients[$i]['objects'][$j])){
|
||
|
|
$objectsId .= ' or id = ' . $clients[$i]['objects'][$j];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$objects = array();
|
||
|
|
if($clients[$i]['objects'][0] . $objectsId != ''){
|
||
|
|
$objectsDBO = mysql_query("SELECT adres, nazv, stoim FROM objects WHERE id=" . $clients[$i]['objects'][0] . $objectsId);
|
||
|
|
|
||
|
|
while ($row = mysql_fetch_assoc($objectsDBO)) {
|
||
|
|
array_push($objects, $row);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$clients[$i]['objectsInfo'] = $objects;
|
||
|
|
|
||
|
|
$agent_main = mysql_fetch_assoc(mysql_query("SELECT first_name, last_name, middle_name FROM users WHERE id=" . $clients[$i]['who_work']));
|
||
|
|
$clients[$i]['agent'] = trim($agent_main['last_name'] . ' ' . $agent_main['first_name'] . ' ' . $agent_main['middle_name']);
|
||
|
|
if($clients[$i]['doer_clients'] == 1) {
|
||
|
|
$doers = json_decode(html_entity_decode($clients[$i]['doers']), true);
|
||
|
|
foreach($doers as $user => $doer) {
|
||
|
|
if ($doer == 1) {
|
||
|
|
$agent = mysql_fetch_assoc(mysql_query("SELECT first_name, last_name, middle_name FROM users WHERE id=" . $user));
|
||
|
|
$clients[$i]['agent'] .= ", " . trim($agent['last_name'] . ' ' . $agent['first_name'] . ' ' . $agent['middle_name']);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
if (((int) $clients[$i]['source']) > 0) {
|
||
|
|
$source = mysql_fetch_assoc(mysql_query("SELECT source FROM advertising_sources WHERE id=" . $clients[$i]['source']));
|
||
|
|
$clients[$i]['source'] = $source['source'];
|
||
|
|
} else {
|
||
|
|
$clients[$i]['source'] = '';
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
$eventsClientsDBO = mysql_query("SELECT * FROM events_clients where event='stageedit' AND client_id=" . $clients[$i]['id']);
|
||
|
|
$eventsClients = array();
|
||
|
|
while ($row = mysql_fetch_assoc($eventsClientsDBO)) {
|
||
|
|
$user = mysql_fetch_assoc(mysql_query("SELECT fio FROM users WHERE id=" . $row['user_id']));
|
||
|
|
$row['user'] = trim($user['last_name'] . ' ' . $user['first_name'] . ' ' . $user['middle_name']);
|
||
|
|
array_push($eventsClients, $row);
|
||
|
|
}
|
||
|
|
|
||
|
|
$doersEventDBO = mysql_query("SELECT * FROM doers_emp_client where client_id=" . $clients[$i]['id']." AND confirm = 1 group by step_id, client_id, doer_id");
|
||
|
|
$doersEvent = array();
|
||
|
|
while ($row = mysql_fetch_assoc($doersEventDBO)) {
|
||
|
|
$doer = mysql_fetch_assoc(mysql_query("SELECT first_name, last_name, middle_name FROM users WHERE id=" . $row['doer_id']));
|
||
|
|
$row['doer'] = trim($doer['last_name'] . ' ' . $doer['first_name'] . ' ' . $doer['middle_name']);
|
||
|
|
|
||
|
|
$user_work = mysql_fetch_assoc(mysql_query("SELECT first_name, last_name, middle_name FROM users WHERE id=" . $row['who_work']));
|
||
|
|
$row['user_work'] = trim($user_work['last_name'] . ' ' . $user_work['first_name'] . ' ' . $user_work['middle_name']);
|
||
|
|
array_push($doersEvent, $row);
|
||
|
|
}
|
||
|
|
|
||
|
|
$clients[$i]['doersEvent'] = $doersEvent;
|
||
|
|
$clients[$i]['eventsClients'] = $eventsClients;
|
||
|
|
$agentadd = mysql_fetch_assoc(mysql_query("SELECT first_name, last_name, middle_name FROM users WHERE id=" . $clients[$i]['id_agent']));
|
||
|
|
$clients[$i]['agentadd'] = trim($agentadd['last_name'] . ' ' . $agentadd['first_name'] . ' ' . $agentadd['middle_name']);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
/*$tableData = array();
|
||
|
|
$tableData['clients'] = $clients;
|
||
|
|
$tableData['table'] = $table;
|
||
|
|
|
||
|
|
echo (json_encode($tableData));*/
|
||
|
|
|
||
|
|
//**************************** конец **************************************************//
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||
|
|
|
||
|
|
$spreadsheet = new Spreadsheet();
|
||
|
|
$sheet = $spreadsheet->getActiveSheet();
|
||
|
|
|
||
|
|
$sheet->setTitle('Статистика клиентов');
|
||
|
|
$arrColExccel = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU','AV','AW','AX','AY','AZ',
|
||
|
|
'BA','BB','BC','BD','BE','BF','BG','BH','BI','BJ','BK','BL','BM','BN','BO','BP','BQ','BR','BS','BT','BU','BV','BW','BX','BY','BZ'];
|
||
|
|
$columnStart = 'A';
|
||
|
|
$rowStart = 3;
|
||
|
|
$arrayHeder = [$columnStart => ['title'=>'№','width'=>5,'rowspan'=>2],
|
||
|
|
'B' => ['title'=>'ФИО','width'=>35, 'rowspan'=>2]
|
||
|
|
];
|
||
|
|
$j=2;
|
||
|
|
$addSteps = $columns['json_add'];
|
||
|
|
//var_dump($addSteps);
|
||
|
|
|
||
|
|
|
||
|
|
if (isset($addSteps['email'])){
|
||
|
|
$arrayHeder[$arrColExccel[$j]] = ['title'=>'email', 'width'=>20,'rowspan'=>2];
|
||
|
|
$j++;
|
||
|
|
}
|
||
|
|
if (isset($addSteps['phone'])) {
|
||
|
|
$arrayHeder[$arrColExccel[$j]] = ['title'=>'Телефон', 'width'=>20,'rowspan'=>2];
|
||
|
|
$j++;
|
||
|
|
}
|
||
|
|
if (isset($addSteps['client_type'])) {
|
||
|
|
$arrayHeder[$arrColExccel[$j]] = ['title'=>'Тип клиента', 'width'=>20,'rowspan'=>2];
|
||
|
|
$j++;
|
||
|
|
}
|
||
|
|
if (isset($addSteps['client_role'])) {
|
||
|
|
$arrayHeder[$arrColExccel[$j]] = ['title'=>'Роль клиента', 'width'=>20,'rowspan'=>2];
|
||
|
|
$j++;
|
||
|
|
}
|
||
|
|
if (isset($addSteps['property_type'])) {
|
||
|
|
$arrayHeder[$arrColExccel[$j]] = ['title'=>'Тип недвижимости', 'width'=>20,'rowspan'=>2];
|
||
|
|
$j++;
|
||
|
|
}
|
||
|
|
if (isset($addSteps['objects'])) {
|
||
|
|
$arrayHeder[$arrColExccel[$j]] = ['title'=>'Объекты', 'width'=>15,'rowspan'=>2];
|
||
|
|
$j++;
|
||
|
|
$arrayHeder[$arrColExccel[$j]] = ['title'=>'Цены объектов', 'width'=>15,'rowspan'=>2];
|
||
|
|
$j++;
|
||
|
|
}
|
||
|
|
if (isset($addSteps['budget'])) {
|
||
|
|
$arrayHeder[$arrColExccel[$j]] = ['title'=>'Бюджет', 'width'=>20,'rowspan'=>2];
|
||
|
|
$j++;
|
||
|
|
}
|
||
|
|
if (isset($addSteps['description'])) {
|
||
|
|
$arrayHeder[$arrColExccel[$j]] = ['title'=>'Описание', 'width'=>20,'rowspan'=>2];
|
||
|
|
$j++;
|
||
|
|
}
|
||
|
|
if (isset($addSteps['responsible'])) {
|
||
|
|
$arrayHeder[$arrColExccel[$j]] = ['title'=>'Ответственный', 'width'=>20,'rowspan'=>2];
|
||
|
|
$j++;
|
||
|
|
}
|
||
|
|
if (isset($addSteps['source'])) {
|
||
|
|
$arrayHeder[$arrColExccel[$j]] = ['title'=>'Источник', 'width'=>20,'rowspan'=>2];
|
||
|
|
$j++;
|
||
|
|
}
|
||
|
|
if (isset($addSteps['curr'])) {
|
||
|
|
$arrayHeder[$arrColExccel[$j]] = ['title'=>'Текущий этап', 'width'=>20,'rowspan'=>2];
|
||
|
|
$j++;
|
||
|
|
}
|
||
|
|
$arrayHeder2 = array();
|
||
|
|
foreach ($columns['json_funnel'] as $col) {
|
||
|
|
$funnelSteps = $col['steps'];
|
||
|
|
//var_dump($funnelSteps);
|
||
|
|
|
||
|
|
foreach ($funnelSteps as $step) {
|
||
|
|
|
||
|
|
$fieldsCount = 0;
|
||
|
|
|
||
|
|
$jj = $j;
|
||
|
|
if ($step['self']) {
|
||
|
|
$fieldsCount += 3;
|
||
|
|
|
||
|
|
$arrayHeder2[$arrColExccel[$jj]] = ['title'=>'Дата', 'width'=>15, 'row'=>1];
|
||
|
|
$jj++;
|
||
|
|
$arrayHeder2[$arrColExccel[$jj]] = ['title'=>'Менеджер', 'width'=>15, 'row'=>1];
|
||
|
|
$jj++;
|
||
|
|
$arrayHeder2[$arrColExccel[$jj]] = ['title'=>'Ответственные', 'width'=>15, 'row'=>1];
|
||
|
|
$jj++;
|
||
|
|
}
|
||
|
|
|
||
|
|
foreach ($step['fields'] as $field) {
|
||
|
|
$fieldsCount++;
|
||
|
|
|
||
|
|
$arrayHeder2[$arrColExccel[$jj++]] = ['title'=>$field, 'width'=>15, 'row'=>1];
|
||
|
|
$jj++;
|
||
|
|
}
|
||
|
|
|
||
|
|
$arrayHeder[$arrColExccel[$j]] = ['title'=>$step['name'], 'width'=>15, 'colspan'=>($fieldsCount-1), 'row'=>0];
|
||
|
|
$j = $j + $fieldsCount;
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
$textFilters = '';
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
$sheet->setCellValue('B1', "ФИЛЬТРЫ: ");
|
||
|
|
$sheet->getStyle('B1')->getFont()->applyFromArray( [ 'name' => 'Arial', 'bold' => TRUE, 'italic' => FALSE, 'strikethrough' => FALSE, 'color' => [ 'rgb' => '808080' ] ] );
|
||
|
|
$sheet->getStyle('B')->getAlignment()->setWrapText(true);
|
||
|
|
$sheet->getStyle('B1')->getAlignment()->setWrapText(true);
|
||
|
|
|
||
|
|
$sheet->setCellValue('C1', $textFilters);
|
||
|
|
$sheet->mergeCells('C1:'.$arrColExccel[$j-1].'1');
|
||
|
|
|
||
|
|
|
||
|
|
$styleArray = array(
|
||
|
|
'borders' => array(
|
||
|
|
'allBorders' => array(
|
||
|
|
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||
|
|
'color' => array('rgb' => '808080'),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
foreach($arrayHeder as $h => $w){
|
||
|
|
$rw = $rowStart;
|
||
|
|
if(isset($w['row'])){
|
||
|
|
$rw = $rowStart + (int)$w['row'];
|
||
|
|
}
|
||
|
|
$sheet->setCellValue($h.$rw, $w['title']);
|
||
|
|
$sheet->getColumnDimension($h)->setWidth($w['width']);
|
||
|
|
$sheet->getStyle($h.$rw)->getFont()->applyFromArray( [ 'name' => 'Arial', 'bold' => TRUE, 'italic' => FALSE, 'strikethrough' => FALSE, 'color' => [ 'rgb' => '808080' ], ] );
|
||
|
|
|
||
|
|
$sheet->getStyle($h)->getAlignment()->setWrapText(true);
|
||
|
|
$sheet->getStyle($h.$rw)->getAlignment()->setWrapText(true);
|
||
|
|
if(isset($w['rowspan'])){
|
||
|
|
$sheet->mergeCells($h.$rw.':'.$h.($rw+1));
|
||
|
|
}
|
||
|
|
if(isset($w['colspan'])){
|
||
|
|
$in = array_search($h, $arrColExccel);
|
||
|
|
if($in !== false){
|
||
|
|
$index = $in + (int)$w['colspan'];
|
||
|
|
$h2 = $arrColExccel[$index];
|
||
|
|
$sheet->mergeCells($h.$rw.':'.$h2.$rw);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
foreach($arrayHeder2 as $h => $w){
|
||
|
|
$rw = $rowStart;
|
||
|
|
if(isset($w['row'])){
|
||
|
|
$rw = $rowStart + (int)$w['row'];
|
||
|
|
}
|
||
|
|
$sheet->setCellValue($h.$rw, $w['title']);
|
||
|
|
$sheet->getColumnDimension($h)->setWidth($w['width']);
|
||
|
|
$sheet->getStyle($h.$rw)->getFont()->applyFromArray( [ 'name' => 'Arial', 'bold' => TRUE, 'italic' => FALSE, 'strikethrough' => FALSE, 'color' => [ 'rgb' => '808080' ], ] );
|
||
|
|
|
||
|
|
$sheet->getStyle($h)->getAlignment()->setWrapText(true);
|
||
|
|
$sheet->getStyle($h.$rw)->getAlignment()->setWrapText(true);
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
$sheet ->getStyle('A'.($rowStart).':'.$arrColExccel[$j-1].($rowStart+1 + count($clients)))->applyFromArray($styleArray);
|
||
|
|
|
||
|
|
$i = $rowStart+2;
|
||
|
|
$k = 1;
|
||
|
|
|
||
|
|
foreach ($clients as $key => $client) {
|
||
|
|
|
||
|
|
foreach ($client['events'] as $keyj => $ev_j) {
|
||
|
|
$ev_j['create_date'] = date('d.m.Y',strtotime($ev_j['create_date']));
|
||
|
|
$client['steps'] = array();
|
||
|
|
//var_dump($client['eventsClients']);
|
||
|
|
foreach ($client['eventsClients'] as $eventsClients) {
|
||
|
|
$qwe = explode('«', $eventsClients['dop_text'])[1];
|
||
|
|
//var_dump($qwe);
|
||
|
|
$client['steps'][explode('»',$qwe)[0]] = array('user'=>$eventsClients['user'], 'date'=>date('d.m.Y',strtotime($eventsClients['date'])));
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
$sheet->setCellValue('A'.$i, $k);
|
||
|
|
$fioCell = $hideContactsExcel ? mask_fio_if_contains_phone($client['fio']) : $client['fio'];
|
||
|
|
$sheet->setCellValue('B'.$i, $fioCell);
|
||
|
|
$j = 2;
|
||
|
|
if (isset($addSteps['email'])){
|
||
|
|
$emailCell = $hideContactsExcel ? mask_client_email($client['email']) : $client['email'];
|
||
|
|
$sheet->setCellValue($arrColExccel[$j].$i, $emailCell);
|
||
|
|
$j++;
|
||
|
|
}
|
||
|
|
if (isset($addSteps['phone'])) {
|
||
|
|
$phoneCell = $hideContactsExcel ? mask_client_phone($client['phone']) : $client['phone'];
|
||
|
|
$sheet->setCellValue($arrColExccel[$j].$i, $phoneCell);
|
||
|
|
$j++;
|
||
|
|
}
|
||
|
|
if (isset($addSteps['client_type'])) {
|
||
|
|
$client_type = json_decode(html_entity_decode($client['work_type']), true);
|
||
|
|
$sheet->setCellValue($arrColExccel[$j].$i, implode(', ',$client_type));
|
||
|
|
$j++;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (isset($addSteps['client_role'])) {
|
||
|
|
$client_role = json_decode(html_entity_decode($client['client_role']), true);
|
||
|
|
$sheet->setCellValue($arrColExccel[$j].$i, implode(', ',$client_role));
|
||
|
|
$j++;
|
||
|
|
}
|
||
|
|
if (isset($addSteps['property_type'])) {
|
||
|
|
$property_type = json_decode(html_entity_decode($client['property_type']), true);
|
||
|
|
$sheet->setCellValue($arrColExccel[$j].$i, implode(', ',$property_type));
|
||
|
|
$j++;
|
||
|
|
}
|
||
|
|
if (isset($addSteps['objects'])) {
|
||
|
|
$object = '';
|
||
|
|
$stoim = '';
|
||
|
|
if(!empty($client['objectsInfo'])){
|
||
|
|
foreach ($client['objectsInfo'] as $obj) {
|
||
|
|
if($object != '') $object .= '; ';
|
||
|
|
if($stoim != '') $stoim .= '; ';
|
||
|
|
$object .= $obj['nazv'].'; '.$obj['adres'];
|
||
|
|
$stoim .= $obj['stoim'];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$sheet->setCellValue($arrColExccel[$j].$i, $object);
|
||
|
|
$j++;
|
||
|
|
$sheet->setCellValue($arrColExccel[$j].$i, $stoim);
|
||
|
|
$j++;
|
||
|
|
}
|
||
|
|
if (isset($addSteps['budget'])) {
|
||
|
|
$sheet->setCellValue($arrColExccel[$j].$i, $client['budget']);
|
||
|
|
$j++;
|
||
|
|
}
|
||
|
|
if (isset($addSteps['description'])) {
|
||
|
|
$sheet->setCellValue($arrColExccel[$j].$i, str_replace('<br>', ' ', $client['opis']));
|
||
|
|
$j++;
|
||
|
|
}
|
||
|
|
if (isset($addSteps['responsible'])) {
|
||
|
|
$sheet->setCellValue($arrColExccel[$j].$i, $client['agent']);
|
||
|
|
$j++;
|
||
|
|
}
|
||
|
|
if (isset($addSteps['source'])) {
|
||
|
|
$sheet->setCellValue($arrColExccel[$j].$i, $client['source']);
|
||
|
|
$j++;
|
||
|
|
}
|
||
|
|
if (isset($addSteps['curr'])) {
|
||
|
|
$source = '';
|
||
|
|
if(!empty($client['eventsClients'])){
|
||
|
|
$text = $client['eventsClients'][count($client['eventsClients'])-1]['dop_text'];
|
||
|
|
$var = explode('«',$text);
|
||
|
|
$text2 = $var[count($var)-1];
|
||
|
|
$text3 = explode('»',$text2)[0];
|
||
|
|
$source = $text3;
|
||
|
|
} else {
|
||
|
|
$source = "Новый";
|
||
|
|
}
|
||
|
|
$sheet->setCellValue($arrColExccel[$j].$i, $source);
|
||
|
|
$j++;
|
||
|
|
}
|
||
|
|
|
||
|
|
foreach($columns['json_funnel'] as $funnelSteps) {
|
||
|
|
//var_dump($funnelSteps);
|
||
|
|
foreach ($funnelSteps['steps'] as $js => $step) {
|
||
|
|
foreach ($client['events'] as $ke => $event) {
|
||
|
|
|
||
|
|
if (isset ($event['name']) && ($step['name'] == $event['name'])) {
|
||
|
|
if ($step['self'] == 1) {
|
||
|
|
//echo $step['name'];
|
||
|
|
$steps_date = '';
|
||
|
|
$steps_user = '';
|
||
|
|
$steps_doers = '';
|
||
|
|
|
||
|
|
foreach ($client['doersEvent'] as $doersEvent){
|
||
|
|
|
||
|
|
if($doersEvent['step_id'] == $step['id']){
|
||
|
|
if($steps_doers == '') $steps_doers .= $doersEvent['user_work'];
|
||
|
|
$steps_doers .= ', '.$doersEvent['doer'];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/*var_dump($step['name']);
|
||
|
|
var_dump($client['steps']);*/
|
||
|
|
foreach ($client['steps'] as $key => $steps) {
|
||
|
|
|
||
|
|
if ($step['name'] == $key) {
|
||
|
|
$steps_date = $steps['date'];
|
||
|
|
$steps_user = $steps['user'];
|
||
|
|
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($steps_date == '') {
|
||
|
|
$steps_date = $event['create_date'];
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
if($steps_doers == ''){
|
||
|
|
$steps_doers = $client['agent_main'];
|
||
|
|
}
|
||
|
|
$sheet->setCellValue($arrColExccel[$j].$i, $steps_date);
|
||
|
|
$j++;
|
||
|
|
$sheet->setCellValue($arrColExccel[$j].$i, $steps_user);
|
||
|
|
$j++;
|
||
|
|
$sheet->setCellValue($arrColExccel[$j].$i, $steps_doers);
|
||
|
|
$j++;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
foreach ($step['fields'] as $field) {
|
||
|
|
foreach ($event['comment'] as $com) {
|
||
|
|
if ($field == $com[0]) {
|
||
|
|
$sheet->setCellValue($arrColExccel[$j].$i, str_replace('<br>', ' ', $com[1]));
|
||
|
|
$j++;
|
||
|
|
//html +='<p title="' + data.clients[i].events[k].comment[m][1].replace(/\<br\>/gi, ' ') + '">' + data.clients[i].events[k].comment[m][1].replace(/\<br\>/gi, ' ') + '</p>';
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
//echo $ke.' ';
|
||
|
|
|
||
|
|
|
||
|
|
} else if ($ke == (count($client['events']) - 1)) {
|
||
|
|
|
||
|
|
if ($step['self'] == 1) {
|
||
|
|
//echo $step['self'];
|
||
|
|
$steps_date = '';
|
||
|
|
$steps_user = '';
|
||
|
|
$steps_doers = '';
|
||
|
|
|
||
|
|
foreach ($client['steps'] as $key => $steps) {
|
||
|
|
|
||
|
|
if ($step['name'] == $key) {
|
||
|
|
$steps_date = $steps['date'];
|
||
|
|
$steps_user = $steps['user'];
|
||
|
|
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
//console.log(data.clients[i].doersEvent);
|
||
|
|
|
||
|
|
foreach ($client['doersEvent'] as $doersEvent ){
|
||
|
|
|
||
|
|
|
||
|
|
if($doersEvent['step_id'] == $step['id']){
|
||
|
|
if($steps_doers == '') $steps_doers .= $doersEvent['user_work'];
|
||
|
|
$steps_doers .= ', '.$doersEvent['doer'];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($steps_date == '' && $steps_user != '') {
|
||
|
|
$steps_date = $event['create_date'];
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($js == 0 && $steps_user == '') {
|
||
|
|
$steps_user = $client['agentadd'];
|
||
|
|
}
|
||
|
|
|
||
|
|
if($steps_user != '' && $steps_doers == ''){
|
||
|
|
$steps_doers = $client['agent_main'];
|
||
|
|
}
|
||
|
|
|
||
|
|
$sheet->setCellValue($arrColExccel[$j].$i, $steps_date);
|
||
|
|
$j++;
|
||
|
|
$sheet->setCellValue($arrColExccel[$j].$i, $steps_user);
|
||
|
|
$j++;
|
||
|
|
$sheet->setCellValue($arrColExccel[$j].$i, $steps_doers);
|
||
|
|
$j++;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$i++;
|
||
|
|
$k++;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
$writer = new Xlsx($spreadsheet);
|
||
|
|
//echo $_SERVER['DOCUMENT_ROOT'].'server/excel';
|
||
|
|
if(!file_exists($_SERVER['DOCUMENT_ROOT'].'/server/excel')){
|
||
|
|
mkdir($_SERVER['DOCUMENT_ROOT'].'/server/excel', 0777);
|
||
|
|
}
|
||
|
|
|
||
|
|
$name_file = '/server/excel/statistics_clients_dop_'.$date.'.xlsx';
|
||
|
|
$name = 'statistics_clients_dop_'.$date.'.xlsx';
|
||
|
|
|
||
|
|
|
||
|
|
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||
|
|
$writer->save($_SERVER['DOCUMENT_ROOT'].$name_file);
|
||
|
|
$res['file'] = $name_file;
|
||
|
|
$res['result'] = 'ok';
|
||
|
|
$res['name'] = $name;
|
||
|
|
echo json_encode($res);
|