Joywork/ajax/getGridTableFunnel.php

250 lines
15 KiB
PHP
Raw Permalink Normal View History

2026-05-22 20:21:54 +02:00
<?php
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
$agency_id = 0;
if(isset($_POST['agency_id'])){
$agency_id = (int)$_POST['agency_id'];
}
$sql_d = "SELECT * FROM denial_work WHERE (agency_id = 0 or agency_id={$agency_id}) and del = 0";
if($agency_id == 19895){
$sql_d = "SELECT * FROM denial_work WHERE agency_id = {$agency_id} AND del = 0";
}
$q_d = mysql_query($sql_d);
$row_d = mysql_num_rows($q_d);
$list_denial = array();
while($r_d = mysql_fetch_assoc($q_d))
{
$list_denial[] = $r_d;
}
$sql = 'SELECT item_list FROM `reclame_table` WHERE id_user='.$_SESSION['id']. ' AND id_table=6';
$reSql = mysql_query($sql);
$res = mysql_fetch_assoc($reSql);
$resList = $res['item_list'];
// echo $resList;
$columnVisible = array();
if(!empty($resList)){
$columnVisible = explode(',',$resList);
}
// var_dump($columnVisible);
?>
<style>
.bootstrap-table .fixed-table-pagination .float-right.pagination-detail
{
display: flex;
align-items: center;
}
.bootstrap-table .fixed-table-pagination .float-right.pagination-detail .page-list
{
display: flex;
align-items: center;
text-wrap-mode: nowrap;
text-wrap: nowrap;
flex-direction: row-reverse;
}
.bootstrap-table .fixed-table-pagination .float-right.pagination-detail .page-list .open > .dropdown-menu
{
left: -6.7rem;
}
.bootstrap-table .fixed-table-pagination .float-right.pagination-detail .page-list .open > .dropdown-menu .dropdown-item.active
{
padding: .25rem 1.5rem;
}
</style>
<div class="table-responsive">
<div id="export_stat_funnel" style="margin-left: 20px; " class="crm__new-client">
<a style="padding: 3px 15px 6px; background: -moz-linear-gradient(top, #fff, #f5f5f5);
background: -webkit-linear-gradient(top, #fff, #f5f5f5);
background: -o-linear-gradient(top, #fff, #f5f5f5);
background: -ms-linear-gradient(top, #fff, #f5f5f5);
background: linear-gradient(top, #fff, #f5f5f5);
cursor: pointer;
position: absolute;
margin-top: 17px;
border: 1px solid #d0d0d0; border-bottom: 1px solid #d0d0d0;" href="javascript:{}" class="jw__g-button">Экспорт в Excel</a>
</div>
<div class="buttons-toolbar" style="padding-top: 15px">
</div>
<!-- <div id="table-funnel-keep-selection-fixed" class="bootstrap-table bootstrap4" style="display:none; position:absolute;z-index: 999;">
<div class="fixed-table-container fixed-height">
<table style="border-bottom: 0px;" class="table table-bordered table-hover">
<thead style="border-bottom: 0px;"></thead>
</table>
</div>
<div class="fixed-table-body">
<table class="table table-bordered table-hover">
<tbody>
</tbody>
</table>
</div>
</div> -->
<table class="table table-bordered"
id="table-funnel-keep-selection"
data-locale="ru-RU"
data-toggle="table"
data-height="650"
data-show-refresh="true"
data-show-columns="true"
data-buttons-toolbar=".buttons-toolbar"
data-show-columns-toggle-all="true"
data-ajax="ajaxRequest"
data-loading-template="loadingTemplate"
data-pagination="true"
data-pagination-h-align="left"
data-pagination-detail-h-align="right"
data-page-size="30"
data-show-footer="true"
data-fixed-scroll="true"
>
<thead>
<?php
if(isset($_POST['funnel'])){
$funnelArr = json_decode(html_entity_decode($_POST['funnel']), ENT_QUOTES);
if(!empty($funnelArr && count($funnelArr) == 1)){
$funnelId = $funnelArr[0];
$steps = array();
$sql = "SELECT * FROM funnel_steps WHERE funnel_id=$funnelId AND deleted=0 ORDER by main DESC, order_number, branch" ;
$q = mysql_query($sql);
?>
<tr>
<th data-field="fio" data-formatter="sourceFormatter" data-cell-style="cellStyleForObject" data-class="table_white active_in_footer_fio" data-switchable="false" data-footer-formatter="Итого" rowspan="3">ФИО</th>
<?php
$i = 0;
while($r = mysql_fetch_assoc($q)){
$colspan = 15;
if($i == 0) $colspan = 16;
$colspan = $colspan+$row_d;
?>
<th data-class="table_white inactive_in_footer inactive_in_footer_step_funnel_<?=$i?>_<?=$r['id']?>" data-field="step_funnel_<?=$r['id']?>" colspan="<?=$colspan?>"><?=$r['name']?></th>
<?php
$steps[] = $r['id'];
$i++;
}
?>
<th style="border: 0;" colspan="3" rowspan="2" data-class="table_white inactive_in_footer inactive_in_footer_client_<?=$i?>_<?=$r['id']?>">Сделки</th>
</tr>
<tr>
<?php
foreach($steps as $key => $step){
$colspan = 7;
if($key == 0) $colspan = 8;
?>
<th colspan="<?=$colspan?>" data-class="table_white inactive_in_footer inactive_in_footer_client_<?=$colspan?>_<?=$key?>">Клиент</th>
<th colspan="5" data-class="table_white inactive_in_footer inactive_in_footer_z_v_p_o_<?=$colspan?>_<?=$key?>">Задачи запланированные/Выполненные/Просроченные/Отмененные</th>
<th colspan="<?=($row_d+3)?>" data-field="closed_<?=$key?>" data-class="table_white inactive_in_footer inactive_in_footer_closed_<?=$key?>">Закрытие</th>
<?php }
?>
</tr>
<tr>
<?php
foreach($steps as $key => $step){
?>
<th data-visible="<?=(!empty($columnVisible) && !in_array('work_all_'.$step, $columnVisible) ? 'false' : 'true')?>" data-class="table_white active_in_footer_work_all_<?=$step?>" data-cell-style="cellStyleForObject" data-sortable="true" data-sorter="linkSorter" data-field="work_all_<?=$step?>" data-footer-formatter="footerPriceFormatter">Клиентов на этапе всего</th>
<?php
if($key == 0){ ?>
<th data-visible="<?=(!empty($columnVisible) && !in_array('work_add', $columnVisible) ? 'false' : 'true')?>" data-cell-style="cellStyleForObject" data-class="table_white active_in_footer_work_add" data-sortable="true" data-sorter="linkSorter" data-field="work_add" data-footer-formatter="footerPriceFormatter">Создано новых клиентов </th>
<th data-visible="<?=(!empty($columnVisible) && !in_array('work', $columnVisible) ? 'false' : 'true')?>" data-cell-style="cellStyleForObject" data-class="table_white active_in_footer_work" data-sortable="true" data-sorter="linkSorter" data-field="work" data-footer-formatter="footerPriceFormatter">Клиентов было в работе </th>
<?php } else { ?>
<th data-visible="<?=(!empty($columnVisible) && !in_array('work_prev_step_'.$step, $columnVisible) ? 'false' : 'true')?>" data-cell-style="cellStyleForObject" data-class="table_white active_in_footer_work_prev_step_<?=$step?>" data-sortable="true" data-sorter="linkSorter" data-field="work_prev_step_<?=$step?>" data-footer-formatter="footerPriceFormatter">Перешло с предыдущего этапа </th>
<?php } ?>
<th data-visible="<?=(!empty($columnVisible) && !in_array('work_left_'.$step, $columnVisible) ? 'false' : 'true')?>" data-cell-style="cellStyleForObject" data-class="table_white active_in_footer_work_left_<?=$step?>" data-sortable="true" data-sorter="linkSorter" data-field="work_left_<?=$step?>" data-footer-formatter="footerPriceFormatter">Клиентов осталось на этапе</th>
<th data-visible="<?=(!empty($columnVisible) && !in_array('accepted_'.$step, $columnVisible) ? 'false' : 'true')?>" data-cell-style="cellStyleForObject" data-class="table_white active_in_footer_accepted_<?=$step?>" data-sortable="true" data-sorter="linkSorter" data-field="accepted_<?=$step?>" data-footer-formatter="footerPriceFormatter">Передано сотруднику</th>
<th data-visible="<?=(!empty($columnVisible) && !in_array('transmitted_'.$step, $columnVisible) ? 'false' : 'true')?>" data-cell-style="cellStyleForObject" data-class="table_white active_in_footer_transmitted_<?=$step?>" data-sortable="true" data-sorter="linkSorter" data-field="transmitted_<?=$step?>" data-footer-formatter="footerPriceFormatter">Передано от сотрудника</th>
<th data-visible="<?=(!empty($columnVisible) && !in_array('work_next_step_'.$step, $columnVisible) ? 'false' : 'true')?>" data-cell-style="cellStyleForObject" data-class="table_white active_in_footer_work_next_step_<?=$step?>" data-sortable="true" data-sorter="linkSorter" data-field="work_next_step_<?=$step?>" data-footer-formatter="footerPriceFormatter">Клиентов перешло на следующие этапы</th>
<th data-visible="<?=(!empty($columnVisible) && !in_array('conversion_'.$step, $columnVisible) ? 'false' : 'true')?>" data-cell-style="cellStyleForObject" data-class="table_white active_in_footer_conversion_<?=$step?>" data-sortable="true" data-sorter="linkSorter" data-field="conversion_<?=$step?>" data-footer-formatter="<?=($key == 0) ? 'procentFormaterrForFunnelConv' : 'procentFormaterrForFunnelConvPole'?>">Конверсия перехода на следующий этап</th>
<th data-visible="<?=(!empty($columnVisible) && !in_array('call_'.$step, $columnVisible) ? 'false' : 'true')?>" data-cell-style="cellStyleForObject" data-formatter="taskDetailFormatter" data-class="table_white active_in_footer_call_<?=$step?>" data-sortable="true" data-sorter="linkSorter" data-field="call_<?=$step?>" data-footer-formatter="footerTaskDetailFormatter">Звонок</th>
<th data-visible="<?=(!empty($columnVisible) && !in_array('meet_'.$step, $columnVisible) ? 'false' : 'true')?>" data-cell-style="cellStyleForObject" data-formatter="taskDetailFormatter" data-class="table_white active_in_footer_meet_<?=$step?>" data-sortable="true" data-sorter="linkSorter" data-field="meet_<?=$step?>" data-footer-formatter="footerTaskDetailFormatter">Встреча</th>
<th data-visible="<?=(!empty($columnVisible) && !in_array('show_'.$step, $columnVisible) ? 'false' : 'true')?>" data-cell-style="cellStyleForObject" data-formatter="taskDetailFormatter" data-class="table_white active_in_footer_show_<?=$step?>" data-sortable="true" data-sorter="linkSorter" data-field="show_<?=$step?>" data-footer-formatter="footerTaskDetailFormatter">Показ</th>
<th data-visible="<?=(!empty($columnVisible) && !in_array('deal_'.$step, $columnVisible) ? 'false' : 'true')?>" data-cell-style="cellStyleForObject" data-formatter="taskDetailFormatter" data-class="table_white active_in_footer_deal_<?=$step?>" data-sortable="true" data-sorter="linkSorter" data-field="deal_<?=$step?>" data-footer-formatter="footerTaskDetailFormatter">Сделка</th>
<th data-visible="<?=(!empty($columnVisible) && !in_array('even_'.$step, $columnVisible) ? 'false' : 'true')?>" data-cell-style="cellStyleForObject" data-formatter="taskDetailFormatter" data-class="table_white active_in_footer_even_<?=$step?>" data-sortable="true" data-sorter="linkSorter" data-field="even_<?=$step?>" data-footer-formatter="footerTaskDetailFormatter">Задача произвольная</th>
<?php
foreach($list_denial as $denial)
{
?>
<th data-visible="<?=(!empty($columnVisible) && !in_array('closest_'.$step.'_'.$denial['id'], $columnVisible) ? 'false' : 'true')?>" data-cell-style="cellStyleForObject" data-class="table_white active_in_footer_closest_<?=$step?>_<?=$denial['id']?>" data-sortable="true" data-sorter="linkSorter" data-field="closest_<?=$step?>_<?=$denial['id']?>" data-footer-formatter="footerPriceFormatter">
<?=$denial['name']?>
</th>
<?php
}
?>
<th data-visible="<?=(!empty($columnVisible) && !in_array('closest_'.$step.'_0', $columnVisible) ? 'false' : 'true')?>" data-cell-style="cellStyleForObject" data-class="table_white active_in_footer_closest_<?=$step?>_0" data-sortable="true" data-sorter="linkSorter" data-field="closest_<?=$step?>_0" data-footer-formatter="footerPriceFormatter">Другие причины</th>
<th data-visible="<?=(!empty($columnVisible) && !in_array('closest_'.$step.'_all', $columnVisible) ? 'false' : 'true')?>" data-cell-style="cellStyleForObject" data-class="table_white active_in_footer_closest_<?=$step?>_all" data-sortable="true" data-sorter="linkSorter" data-field="closest_<?=$step?>_all" data-footer-formatter="footerPriceFormatter">Итого</th>
<th data-visible="<?=(!empty($columnVisible) && !in_array('conversionclosest_'.$step, $columnVisible) ? 'false' : 'true')?>" data-cell-style="cellStyleForObject" data-class="table_white active_in_footer_conversionclosest_<?=$step?>" data-sortable="true" data-sorter="linkSorter" data-field="conversionclosest_<?=$step?>" data-footer-formatter="<?=($key == 0) ? 'procentFormaterrForFunnelConv' : 'procentFormaterrForFunnelConvPole'?>">Конверсия закрытия</th>
<?php
}
?>
<th data-visible="<?=(!empty($columnVisible) && !in_array('summa', $columnVisible) ? 'false' : 'true')?>" data-cell-style="cellStyleForObject" data-class="table_white active_in_footer_summa" data-sortable="true" data-sorter="linkSorter" data-field="sdelka_summa" data-footer-formatter="footerSdelkaPriceFormatter">Количество/Сумма</th>
<th data-visible="<?=(!empty($columnVisible) && !in_array('conversion', $columnVisible) ? 'false' : 'true')?>" data-cell-style="cellStyleForObject" data-class="table_white active_in_footer_conversion" data-sortable="true" data-sorter="linkSorter" data-field="conversion" data-footer-formatter="conversionFormaterrForFunnel">Конверсия в сделку</th>
<th data-visible="<?=(!empty($columnVisible) && !in_array('conversion_del', $columnVisible) ? 'false' : 'true')?>" data-cell-style="cellStyleForObject" data-class="table_white active_in_footer_conversion_del" data-sortable="true" data-sorter="linkSorter" data-field="conversion_del" data-footer-formatter="conversionFormaterrForFunnel">Конверсия в отказ</th>
</tr>
<?php
}
}
?>
</thead>
</table>
</div>
<script>
function resList() {
let res = '<?=$resList?>';
return false;
}
resList('<?=$resList?>');
function saveTableColumn(_this) {
let arr = [];
let idUser = <?= $_SESSION['id'];?>;
_this.closest('.dropdown-menu').find('input').each(function(){
$(this).is(':checked') ? arr.push($(this).attr('data-field')) : '';
})
//console.log(arr);
$.ajax({
url:"/ajax/getReclameTable.php",
method: 'post',
data: {arrPunkt: arr, idTable: 6, idUser: idUser},
success: function(data) {
console.log(data);
}
});
}
//arr = false;
</script>