___tipoRelatorio = isset($_REQUEST['tipoRelatorio']) ? $_REQUEST['tipoRelatorio'] : 0; $this->___servico = isset($_POST["listaServico"]) ? $_POST["listaServico"] : 0; } function ___ValidaForm() { parent::___ValidaForm(); if (!IsPostBack()) { return; } if ($this->GetIncDac() && !StrToIntDef($this->___dac)) { GeraExcept('Informe uma Fila!'); } } function ___FiltrosRelatorio() { if ($this->___media != MEDIA_PRINT_GRID) { /* * Recupera os filtros da sess�o do usu�rio. */ list($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio) = $_SESSION["SSstorageFiltros"]; if ($this->___media == MEDIA_PRINT_HTML) { $fila = $this->GetIncDac() ? 'Fila: ' . GetDacDesc($this->GetDbCon(), $this->GetIdProg() . ' ') : ''; return sprintf("%sData Inicial: %s Data Final: %s Tipo: %s", $fila, $this->___dataIni, $this->___dataFim, ($this->___tipoRelatorio ? 'Analítico' : 'Sintético')); } $fltCsv = array(); if ($this->GetIncDac()) { $fltCsv[] = 'Fila:' . GetDacDesc($this->GetDbCon(), $this->___dac); } $fltCsv[] = "Data Inicial:" . $this->___dataIni; $fltCsv[] = "Data Final:" . $this->___dataFim; $fltCsv[] = "Data Emissao:" . date('d/m/Y H:i:s'); $fltCsv[] = "Emitido Por:" . GetLogin(); return $fltCsv; } if ($this->GetIncDac()) { $dacs = GetDac($this->GetDbCon(), $this->___dac, "", 0, 1, 0, 0, 1); } $lkPrint = ""; if ($this->___dataCount) { $prt = 'Clique aqui para imprimir!'; $prtHtml = "\"Clique"; $lkPrint .= sprintf($prtHtml, $this->GetidProg(), MEDIA_PRINT_HTML, $this->___tipoRelatorio, substr(LimpaString(GetDispProgSel($this->GetIdProg())), 0, 20), 'print.gif'); $lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_EXCEL, $this->___tipoRelatorio, 'prt-xls.png'); $lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_PDF, $this->___tipoRelatorio, 'prt-pdf.png'); $lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_CSV, $this->___tipoRelatorio, 'prt-csv.png'); } $tipoRel = !$this->___tipoRelatorio ? '' : 'checked="checked"'; /* * Personalise esta fun��o se necessitar de outras op��es de filtro. */ $filtro = ''; /* * Rotulos. */ $filtro .= ''; $filtro .= $this->GetIncDac() ? '' : ''; $filtro .= GetUsoServico() ? '' : ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; /* * Valores. */ $filtro .= ''; $filtro .= $this->GetIncDac() ? sprintf('', $dacs) : ''; if (GetUsoServico()) { $filtro .= sprintf('', GetIdentRota(false, $this->___servico)); } $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= '
FilaServiçoData InicialData Final Analítico 
%s%s%s
'; /* * Guarda os filtros passados para recuperar na emiss�o dos relat?ios para impress�o. */ $_SESSION["SSstorageFiltros"] = array($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio); return sprintf($filtro, $tipoRel, $this->___dataIni, $this->___dataFim, $lkPrint); } function ___PreparaExcel() { $nomeDac = ""; $dataRel = array(); $dataAgrup = array(); $filtro = $this->___FiltrosRelatorio(); $mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA; /* * Inicia o relatório. */ /* * Cria os filtros */ $linha = array('LABEL'); foreach ($filtro as $values) { list($label, $value) = explode(":", $values); $linha[] = $label; } $dataRel[] = $linha; $linha = array('DADOS'); foreach ($filtro as $values) { list($label, $value) = explode(":", $values); $linha[] = $value; } $dataRel[] = $linha; if (!$this->___tipoRelatorio) { $dadosCabecalio = array('Data', 'Hora', 'Origem', 'Quantidade', 'Tempo', 'TMAB'); $dadosField = array('data', 'hora', 'origem', 'qtde', 'tempo', 'tmab'); if ($mostraColunaServicos) { $dadosCabecalio = array_merge(['Servico'], $dadosCabecalio); $dadosField = array_merge(['serv_id'], $dadosField); } /* * Monta a linha de cabecalio. */ $linha = array('LABEL'); foreach ($dadosCabecalio as $value) { $linha[] = $value; } $dataRel[] = $linha; $somaTempo = 0; $somaQuantidade = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $row["data"] = substr(FormataDBDataHora($row["data"]), 0, 10); $row["hora"] = str_pad($row["hora"], 2, "0", STR_PAD_LEFT); $row["tmab"] = SecondToStrTime(round(($row["tempo"] / $row["qtde"]), 0)); $somaTempo += $row["tempo"]; $somaQuantidade += $row["qtde"]; $row["tempo"] = SecondToStrTime(round($row["tempo"], 0)); // Formata linha de dados. $linha = array('DADOS'); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = $linha; } if ($mostraColunaServicos) { $linha = array('LABEL', 'Total', '', '', '', $somaQuantidade, SecondToStrTime($somaTempo), SecondToStrTime(round(($somaTempo / $somaQuantidade), 0))); } else { $linha = array('LABEL', 'Total', '', '', $somaQuantidade, SecondToStrTime($somaTempo), SecondToStrTime(round(($somaTempo / $somaQuantidade), 0))); } // $linha = 'Total%s%s%s'; $dataRel[] = $linha; $this->___dataRel[] = $dataRel; $dataRel = array(); /* * Agrupamento */ foreach ($this->GetData()[1] as $row) { $total = 0; $linha = array("LABEL", "Tempo Espera"); $linha1 = array("DADOS", "Chamadas Abandonadas"); foreach ($row as $key => $value) { $linha[] = $key; $linha1[] = StrToIntDef($value); $total += StrToIntDef($value); } $linha[] = "Total"; $linha1[] = $total; $dataRel[] = $linha; $dataRel[] = $linha1; } $this->___dataRel[] = $dataRel; } else { $dadosCabecalio = array('Data', 'Hora', 'Origem', 'Logado', 'Pausa', 'Ocupado', 'Indisponivel', 'Nao Classificado', 'Retorno', 'Pos. Chegada', 'Pos. Abandono', 'Tempo', 'TMAB'); $dadosField = array('data', 'hora', 'origem', 'qtd_logado', 'qtd_pausa', 'qtd_ocupado', 'qtd_indisponivel', 'qtd_naoclassificado', 'retornado', 'posicao_chegada', 'posicao_abandono', 'tempo', 'tmab'); if ($mostraColunaServicos) { $dadosCabecalio = array_merge(['Servico'], $dadosCabecalio); $dadosField = array_merge(['serv_id'], $dadosField); } /* * Inicia o relatorio. */ /* * Monta a linha de cabecalio. */ $linha = array('LABEL'); foreach ($dadosCabecalio as $value) { $linha[] = $value; } $dataRel[] = $linha; $somaTempo = 0; $somaQuantidade = 0; $arUseSoma = array('qtd_logado', 'qtd_pausa', 'qtd_ocupado', 'qtd_indisponivel', 'qtd_naoclassificado', 'tempo'); $arSoma = array('qtd_logado' => 0, 'qtd_pausa' => 0, 'qtd_ocupado' => 0, 'qtd_indisponivel' => 0, 'qtd_naoclassificado' => 0, 'retornado' => '-', 'posicao_chegada' => '-', 'posicao_abandono' => '-', 'tempo' => 0, 'tmab' => 0); foreach ($this->GetData()[0] as $row) { //$somaTMAB += $row["tmab"]; $somaTempo += $row["tempo"]; /* * Soma as colunas. */ foreach ($arUseSoma as $value) { $arSoma["$value"] += StrToIntDef($row["$value"]); } /* * Linhas de dados. */ $row["data"] = substr(FormataDBDataHora($row["data"]), 0, 10); $row["hora"] = str_pad($row["hora"], 2, "0", STR_PAD_LEFT); $row['retornado'] = $row['retornado'] ? $row['retornado'] : "-"; $row["tmab"] = SecondToStrTime($row["tempo"]); $row["tempo"] = SecondToStrTime($row["tempo"]); // Formata linha de dados. $linha = array('DADOS'); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = $linha; } /* * Linha de totalizacao. */ $arSoma['tempo'] = SecondToStrTime($somaTempo); $arSoma['tmab'] = SecondToStrTime(round($somaTempo / count($this->GetData()[0]))); if ($mostraColunaServicos) { $linha = array('LABEL', 'Total', '', ''); } else { $linha = array('LABEL', 'Total', '', ''); } foreach ($arSoma as $soma) { $linha[] = $soma; } $dataRel[] = $linha; $this->___dataRel[] = $dataRel; } } function ___PreparaCsv() { $nomeDac = ""; $dataRel = array(); $dataAgrup = array(); $filtro = $this->___FiltrosRelatorio(); $mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA; /* * Inicia o relat�rio. */ $dataRel[] = GenerateCsvFromArray($filtro); if (!$this->___tipoRelatorio) { $dadosCabecalio = array('Data' => 'align="center"', 'Hora' => 'align="center"', 'Origem' => 'align="left"', 'Quantidade' => 'align="right"', 'Tempo' => 'align="center"', 'TMAB' => 'align="center"'); $dadosField = array('data' => 'align="center"', 'hora' => 'align="center"', 'origem' => 'align="left"', 'qtde' => 'align="right"', 'tempo' => 'align="center"', 'tmab' => 'align="center"'); if ($mostraColunaServicos) { $dadosCabecalio = array_merge(['Servico'], $dadosCabecalio); $dadosField = array_merge(['serv_id'], $dadosField); } /* * Monta a linha de cabecalio. */ $dataRel[] = GenerateCsvFromArray(array_keys($dadosCabecalio)); $somaTempo = 0; $somaQuantidade = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $row["data"] = substr(FormataDBDataHora($row["data"]), 0, 10); $row["hora"] = str_pad($row["hora"], 2, "0", STR_PAD_LEFT); $row["tmab"] = SecondToStrTime(round(($row["tempo"] / $row["qtde"]), 0)); $somaTempo += $row["tempo"]; $somaQuantidade += $row["qtde"]; $row["tempo"] = SecondToStrTime(round($row["tempo"], 0)); // Formata linha de dados. $linha = array(); foreach ($dadosField as $key => $value) { $linha[] = $row["$key"]; } $dataRel[] = GenerateCsvFromArray($linha); } $this->___dataRel[] = $dataRel; $dataRel = array(); /* * Agrupamento */ foreach ($this->GetData()[1] as $row) { $total = 0; $linha = array("Tempo Espera"); $linha1 = array("Chamadas Abandonadas"); foreach ($row as $key => $value) { $linha[] = $key; $linha1[] = StrToIntDef($value); $total += StrToIntDef($value); } $linha[] = "Total"; $linha1[] = $total; $dataRel[] = GenerateCsvFromArray($linha); $dataRel[] = GenerateCsvFromArray($linha1); } $this->___dataRel[] = $dataRel; } else { $dadosCabecalio = array('Data' => 'align="center"', 'Hora' => 'align="center"', 'Origem' => 'align="left"' , 'Logado' => 'align="right"', 'Pausa' => 'align="right"', 'Ocupado' => 'align="right"', 'Indisponível' => 'align="right"' , 'Não Classificado' => 'align="right"', 'Retorno' => 'align="center"', 'Pos. Chegada' => 'align="right"', 'Pos. Abandono' => 'align="right"' , 'Tempo' => 'align="center"', 'TMAB' => 'align="center"' ); $dadosField = array('data' => 'align="center"', 'hora' => 'align="center"', 'origem' => 'align="left"' , 'qtd_logado' => 'align="right"', 'qtd_pausa' => 'align="right"', 'qtd_ocupado' => 'align="right"', 'qtd_indisponivel' => 'align="right"' , 'qtd_naoclassificado' => 'align="right"', 'retornado' => 'align="center"', 'posicao_chegada' => 'align="right"', 'posicao_abandono' => 'align="right"' , 'tempo' => 'align="center"', 'tmab' => 'align="center"' ); if ($mostraColunaServicos) { $dadosCabecalio = array_merge(['Servico'], $dadosCabecalio); $dadosField = array_merge(['serv_id'], $dadosField); } /* * Inicia o relat�rio. */ /* * Monta a linha de cabecalio. */ $dataRel[] = GenerateCsvFromArray(array_keys($dadosCabecalio)); $somaTempo = 0; $somaTMAB = 0; $arUseSoma = array('qtd_logado', 'qtd_pausa', 'qtd_ocupado', 'qtd_indisponivel', 'qtd_naoclassificado', 'tempo'); $arSoma = array('qtd_logado' => 0, 'qtd_pausa' => 0, 'qtd_ocupado' => 0, 'qtd_indisponivel' => 0, 'qtd_naoclassificado' => 0, 'retornado' => '-', 'posicao_chegada' => '-', 'posicao_abandono' => '-', 'tempo' => 0, 'tmab' => 0, 'lkRel' => '-'); foreach ($this->GetData()[0] as $row) { $somaTempo += $row["tempo"]; $row["data"] = FormataDBDataHora($row["data"]); $row["hora"] = substr(FormataDBDataHora($row["hora"]), 11, 2); $row['retornado'] = $row['retornado'] ? $row['retornado'] : "-"; $row["tmab"] = SecondToStrTime($row["tempo"]); $row['tempo'] = SecondToStrTime($row["tempo"]); /* * Soma as colunas. */ foreach ($arUseSoma as $value) { $arSoma["$value"] += StrToIntDef($row["$value"]); } // Formata linha de dados. $linha = array(); foreach ($dadosField as $key => $value) { $linha[] = $row["$key"]; } $dataRel[] = GenerateCsvFromArray($linha); } /* * Linha de totalizacao. */ $arSoma['tempo'] = SecondToStrTime($somaTempo); $arSoma['tmab'] = SecondToStrTime(round($somaTempo / count($this->GetData()[0]))); if ($mostraColunaServicos) { $linha = array('Total', '', ''); } else { $linha = array('Total', '', ''); } foreach ($arSoma as $soma) { $linha[] = $soma; } $dataRel[] = GenerateCsvFromArray($linha); $this->___dataRel[] = $dataRel; } } function ___PreparaGrid() { $nomeDac = ""; $dataRel = array(); $dataAgrup = array(); $mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA; if (!$this->___tipoRelatorio) { $dadosCabecalio = array( 'Data' => 'align="center"', 'Hora' => 'align="center"', 'Origem' => 'align="left"', 'Quantidade' => 'align="right"', 'Tempo' => 'align="center"', 'TMAB' => 'align="center"' ); $dadosField = array( 'data' => 'align="center"', 'hora' => 'align="center"', 'origem' => 'align="left"', 'qtde' => 'align="right"', 'tempo' => 'align="center"', 'tmab' => 'align="center"' ); if ($mostraColunaServicos) { $dadosCabecalio = array_merge(['Serviço' => 'align="center"'], $dadosCabecalio); $dadosField = array_merge(['serv_id' => 'align="left"'], $dadosField); } /* * Inicia o relat�rio. */ $dataRel[] = ''; /* * Monta a linha de cabecalio. */ $linha = ''; foreach ($dadosCabecalio as $key => $value) { $linha .= sprintf("", $value, $key); } $linha .= ""; $dataRel[] = $linha; /* * Verifica se retornou dados */ if (!IsPostBack() || !count($this->GetData()[0])) { $dataRel[] = sprintf("
%s
%s
", count($dadosCabecalio) - 1, (!IsPostBack() ? 'Informe os parametros e clique em consultar!' : 'Nenhum registro encontado!')); $this->___dataRel[] = $dataRel; return; } $somaTempo = 0; $somaQuantidade = 0; $somaReg = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $somaReg ++; $row['origem'] = ocultarTelefone($row['origem']); $row["data"] = substr(FormataDBDataHora($row["data"]), 0, 10); $row["hora"] = str_pad($row["hora"], 2, "0", STR_PAD_LEFT); $row["tmab"] = SecondToStrTime(round(($row["tempo"] / $row["qtde"]), 0)); $somaTempo += $row["tempo"]; $somaQuantidade += $row["qtde"]; $row["tempo"] = SecondToStrTime(round($row["tempo"], 0)); // Formata linha de dados. $linha = ""; foreach ($dadosField as $key => $value) { $linha .= sprintf("%s", $value, $row["$key"]); } $linha .= ""; $dataRel[] = $linha; } /* * Linha de totalizacao. */ $colspan = $mostraColunaServicos ? 3 : 2; $linha = 'Total%s%s%s%s'; $dataRel[] = sprintf($linha, $somaReg, $somaQuantidade, SecondToStrTime($somaTempo), SecondToStrTime(round(($somaTempo / $somaQuantidade), 0))); /* * Fecha relatorio. */ $dataRel[] = ''; $this->___dataRel[] = $dataRel; $dataRel = array(); /* * Agrupamento */ foreach ($this->GetData()[1] as $row) { $total = 0; $linha = '' . ""; $linha1 = ""; foreach ($row as $key => $value) { $linha .= sprintf("", $key); $linha1 .= sprintf("", StrToIntDef($value)); $total += $value; } $linha .= ""; $linha1 .= "
Tempo Espera
Chamadas Abandonadas%s%sTotal
$total
"; $dataRel[] = $linha . $linha1; } $this->___dataRel[] = $dataRel; } else { $dadosCabecalio = array( 'Data' => 'align="center"', 'Hora' => 'align="center"', 'Origem' => 'align="left"', 'Logado' => 'align="right"', 'Pausa' => 'align="right"', 'Ocupado' => 'align="right"', 'Indisponivel' => 'align="right"', 'Nao Classificado' => 'align="right"', 'Retorno' => 'align="center"', 'Pos. Chegada' => 'align="right"', 'Pos. Abandono' => 'align="right"', 'Tempo' => 'align="center"', 'TMAB' => 'align="center"', '-' => 'align="center"' ); $dadosField = array( 'data' => 'align="center"', 'hora' => 'align="center"', 'origem' => 'align="left"', 'qtd_logado' => 'align="right"', 'qtd_pausa' => 'align="right"', 'qtd_ocupado' => 'align="right"', 'qtd_indisponivel' => 'align="right"', 'qtd_naoclassificado' => 'align="right"', 'retornado' => 'align="center"', 'posicao_chegada' => 'align="right"', 'posicao_abandono' => 'align="right"', 'tempo' => 'align="center"', 'tmab' => 'align="center"', 'linkRel' => 'align="center"' ); $getUsoServico = false; if ($mostraColunaServicos) { $dadosCabecalio = array_merge(['Serviço' => 'align="center"'], $dadosCabecalio); $dadosField = array_merge(['serv_id' => 'align="left"'], $dadosField); $getUsoServico = true; } /* * Inicia o relat�rio. */ $dataRel[] = ''; /* * Monta a linha de cabecalio. */ $linha = ''; foreach ($dadosCabecalio as $key => $value) { $linha .= sprintf("", $value, $key); } $linha .= ""; $dataRel[] = $linha; /* * Verifica se retornou dados */ if (!IsPostBack() || !count($this->GetData()[0])) { $dataRel[] = sprintf("
%s
%s
", count($dadosCabecalio) - 1, (!IsPostBack() ? 'Informe os parametros e clique em consultar!' : 'Nenhum registro encontado!')); $this->___dataRel[] = $dataRel; return; } $somaTempo = 0; $arUseSoma = array('qtd_logado', 'qtd_pausa', 'qtd_ocupado', 'qtd_indisponivel', 'qtd_naoclassificado', 'tempo'); $arSoma = array('qtd_logado' => 0, 'qtd_pausa' => 0, 'qtd_ocupado' => 0, 'qtd_indisponivel' => 0, 'qtd_naoclassificado' => 0, 'retornado' => '-', 'posicao_chegada' => '-', 'posicao_abandono' => '-', 'tempo' => 0, 'tmab' => 0, 'lkRel' => '-'); $somaReg = 0; foreach ($this->GetData()[0] as $row) { $somaReg++; $srv = $getUsoServico ? $row['serv_id'] : ''; /* * Links para detalhamento. */ $imgrel = "\"Detalhes"; $linkRel = "$imgrel"; $row["linkRel"] = sprintf($linkRel, $row["hora"], $row["hora_fim"], $row["fila"], base64_encode($row["uniqueid"]), $row["qtd_logado"], $row["qtd_pausa"], $row["qtd_ocupado"], $row["qtd_indisponivel"], $row["qtd_naoclassificado"], $row["posicao_chegada"], $row["posicao_abandono"], $row['agente_retorno'] ? $row['agente_retorno'] : " - ", $row['retornado'] ? $row['retornado'] : "", ($srv ? "&serv_id=$srv" : "")); $somaTempo += $row["tempo"]; $row['origem'] = ocultarTelefone($row['origem']); $row["data"] = FormataDBDataHora($row["data"]); $row['hora'] = substr(FormataDBDataHora($row["hora"]), 11, 2); $row["retornado"] = $row["retornado"] ? "SIM" : "NÃO"; $row["tmab"] = SecondToStrTime($row["tempo"]); $row['tempo'] = SecondToStrTime($row['tempo']); /* * Soma as colunas. */ foreach ($arUseSoma as $value) { $arSoma["$value"] += $row["$value"]; } /* * Linhas de dados. */ $row["hora"] = str_pad($row["hora"], 2, "0", STR_PAD_LEFT); // Formata linha de dados. $linha = ""; foreach ($dadosField as $key => $value) { $linha .= sprintf("%s", $value, $row["$key"]); } $linha .= ""; $dataRel[] = $linha; } /* * Linha de totalizacao. */ $arSoma['tempo'] = SecondToStrTime($somaTempo); $arSoma['tmab'] = SecondToStrTime(round($somaTempo / count($this->GetData()[0]))); $colspan = $mostraColunaServicos ? 3 : 2; $linha = 'Total'; $linha .= "Registros: {$somaReg}"; foreach ($arSoma as $soma) { $linha .= sprintf("%s", (is_numeric($soma) ? 'right' : 'center'), $soma); } $linha .= ''; $dataRel[] = $linha; $this->___dataRel[] = $dataRel; } } function ___PreparaHtml() { ; } function ___PreparaPdf() { $nomeDac = ""; list($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio) = $_SESSION["SSstorageFiltros"]; /** * TABELA DADOS PRINCIPAIS */ $somaTMAB = 0; $somaTempo = 0; $dados = array(); $mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA; if (!$this->___tipoRelatorio) { foreach ($this->GetData()[0] as $row) { $somaQtd += $row["qtde"]; $somaTempo += $row["tempo"]; $row["data"] = substr(FormataDBDataHora($row["data"]), 0, 10); $row["hora"] = str_pad($row["hora"], 2, "0", STR_PAD_LEFT); $row["tmab"] = SecondToStrTime(round($row["tempo"] / $row["qtde"])); $row["tempo"] = SecondToStrTime(round($row["tempo"], 0)); $dados[] = $row; } //HEADER DA TABELA DO PDF -> DADOS EM ARRAY $header = array( 'Data' => 'C', 'Hora' => 'C', 'Origem' => 'L', 'Quantidade' => 'R', 'Tempo' => 'C', 'TMAB' => 'C' ); $dataHeader = array( 'data' => 'C', 'hora' => 'C', 'origem' => 'L', 'qtde' => 'R', 'tempo' => 'C', 'tmab' => 'C' ); if ($mostraColunaServicos) { $header = array_merge(['Serviço' => 'C'], $header); $dataHeader = array_merge(['serv_id' => 'C'], $dataHeader); $widthHeader = array(35, 30, 20, 35, 20, 25, 25); $totaliza = array( 'Total', '', '', '', $somaQtd, SecondToStrTime($somaTempo), SecondToStrTime(round($somaTempo / $somaQtd))); } else { $widthHeader = array(35, 20, 45, 20, 35, 35); $totaliza = array( 'Total', '', '', $somaQtd, SecondToStrTime($somaTempo), SecondToStrTime(round($somaTempo / $somaQtd))); } //Monta o array para passar para o prepara; Necessário passar 6 parametros $table1 = array($header, $dataHeader, $dados, $widthHeader, $totaliza, 0); /** * TABELA DE TOTALIZAÇÃO */ $headerTotal = array( 'TE <= 10' => 'C', '10 < TE <= 20' => 'C', '20 < TE <= 30' => 'C', '30 < TE <= 60' => 'C', '60 < TE <= 120' => 'C', '120 < TE <= 180' => 'C', '180 < TE <= 300' => 'C', '300 < TE' => 'C' ); $widthHeaderTotal = array(22, 22, 22, 22, 25, 25, 25, 20, 20); $table2 = array($headerTotal, $headerTotal, $this->GetData()[1], $widthHeaderTotal, '', 1); $this->___dataRel = array($table1, $table2); } else { $header = array( 'Data' => 'C', 'Hora' => 'C', 'Origem' => 'L', 'Logado' => 'R', 'Pausa' => 'R', 'Ocupado' => 'R', 'Indisponivel' => 'R', 'N Class.' => 'R', 'Retorno' => 'C', 'Pos. Chegada' => 'R', 'Pos. Aban.' => 'R', 'Tempo' => 'C', 'TMAB' => 'C' ); $dataHeader = array( 'data' => 'C', 'hora' => 'C', 'origem' => 'L', 'qtd_logado' => 'R', 'qtd_pausa' => 'R', 'qtd_ocupado' => 'R', 'qtd_indisponivel' => 'R', 'qtd_naoclassificado' => 'R', 'retornado' => 'C', 'posicao_chegada' => 'R', 'posicao_abandono' => 'R', 'tempo' => 'C', 'tmab' => 'C' ); if ($mostraColunaServicos) { $header = array_merge(['Serviço' => 'C'], $header); $dataHeader = array_merge(['serv_id' => 'L'], $dataHeader); } $arUseSoma = array('qtd_logado', 'qtd_pausa', 'qtd_ocupado', 'qtd_indisponivel', 'qtd_naoclassificado', 'tempo'); $arSoma = array('qtd_logado' => 0, 'qtd_pausa' => 0, 'qtd_ocupado' => 0, 'qtd_indisponivel' => 0, 'qtd_naoclassificado' => 0, 'retornado' => '-', 'posicao_chegada' => '-', 'posicao_abandono' => '-', 'tempo' => 0, 'tmab' => 0); //$somaReg = 0; foreach ($this->GetData()[0] as $row) { $somaTempo += $row["tempo"]; $dados[$x]["data"] = date('d/m/Y', strtotime($row["data"])); $dados[$x]["hora"] = substr(FormataDBDataHora($row["hora"]), 11, 2); $dados[$x]["origem"] = $row["origem"]; $dados[$x]["qtd_logado"] = $row["qtd_logado"]; $dados[$x]["qtd_pausa"] = $row["qtd_pausa"]; $dados[$x]["qtd_ocupado"] = $row["qtd_ocupado"]; $dados[$x]["qtd_indisponivel"] = $row["qtd_indisponivel"]; $dados[$x]["qtd_naoclassificado"] = $row["qtd_naoclassificado"]; $dados[$x]['tempo_disp'] = SecondToStrTime($row["tempo"]); $dados[$x]['posicao_chegada'] = $row['posicao_chegada']; $dados[$x]['posicao_abandono'] = $row['posicao_abandono']; $dados[$x]['retornado'] = $row['retornado'] ? $row['retornado'] : "-"; $dados[$x]['tmab'] = SecondToStrTime($row["tempo"]); $dados[$x]['tempo'] = SecondToStrTime($row["tempo"]); $dados[$x]["serv_id"] = substr($row["serv_id"], 0, 36); $x++; foreach ($arUseSoma as $value) { $arSoma["$value"] += $row["$value"]; } } if ($mostraColunaServicos) { $widthHeader = array(36, 15, 5, 15, 7, 7, 15, 15, 15, 10, 15, 15, 15, 15); $totaliza = array('Total', '', '', '', $arSoma['qtd_logado'], $arSoma['qtd_pausa'], $arSoma['qtd_ocupado'], $arSoma['qtd_indisponivel'], $arSoma['qtd_naoclassificado'], $arSoma['retornado'], $arSoma['posicao_chegada'], $arSoma['posicao_abandono'], SecondToStrTime($somaTempo), SecondToStrTime(round($somaTempo / count($this->GetData()[0])))); } else { $widthHeader = array(20, 5, 20, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15); $totaliza = array('Total', '', '', $arSoma['qtd_logado'], $arSoma['qtd_pausa'], $arSoma['qtd_ocupado'], $arSoma['qtd_indisponivel'], $arSoma['qtd_naoclassificado'], $arSoma['retornado'], $arSoma['posicao_chegada'], $arSoma['posicao_abandono'], SecondToStrTime($somaTempo), SecondToStrTime(round($somaTempo / count($this->GetData()[0])))); } $table1 = array($header, $dataHeader, $dados, $widthHeader, $totaliza, 0); $this->___dataRel = array($table1); } } function ___GetDadosDb() { $query = ''; $dataIni = FormatDtMssql($this->___dataIni); $dataFim = FormatDtMssql($this->___dataFim); $dac = GetDacDesc($this->GetDbCon(), $this->___dac); $analitico = $this->___tipoRelatorio; $srv = $this->___servico; $mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA; if ($analitico) { $query = "SELECT a.uniqueid,b.fila, a.data_bilhete AS data, MIN(calldate::timestamp) AS hora, MIN(a.calldate::timestamp) + (b.param3::bigint * interval '1 second') as hora_fim, src AS origem,strtoint(b.param2) AS posicao_chegada, abdsr_data_retorno AS retornado,abdsr_agente AS agente_retorno, strtoint(b.param1) AS posicao_abandono,abdsr_agt_logado AS qtd_logado, abdsr_agt_pausa AS qtd_pausa,abdsr_agt_ocupado AS qtd_ocupado, abdsr_agt_indisponivel AS qtd_indisponivel, abdsr_agt_nao_classificado AS qtd_naoclassificado, STRTOINT(param3) AS tempo " . ($mostraColunaServicos ? ",s.serv_id" : "") . " FROM pbx_bilhetes a inner JOIN pbx_eventos_dacs b ON a.uniqueid = b.uid2 inner JOIN pbx_abandonadas_semretorno c ON c.abdsr_uniqueid = a.uniqueid "; if (GetUsoServico()) { $query .= "\nleft join pbx_servicos_registra s on s.uniqueid = a.uniqueid "; } $query .= "\nWHERE data_bilhete >= '%s' AND data_bilhete <= '%s' AND b.evento = 'ABANDON' AND a.lastapp <> 'Transferred Call' AND b.fila = '%s'"; if (GetUsoServico() && $srv) { $query .= "\nand s.serv_id = '{$srv}'"; } $query .= " GROUP BY 1,2,3,6,7,8,9,10,11,12,13,14,15,param3 " . ($mostraColunaServicos ? ", s.serv_id" : "") . " ORDER BY " . ($mostraColunaServicos ? " s.serv_id," : "") . " 2,3"; $query = sprintf($query, $dataIni, $dataFim, $dac); // if ($tipo == 1) { // $query = sprintf("SELECT b.calldate, b.src ,b.dst, c.fila, d.apelido // FROM pbx_bilhetes b // INNER JOIN pbx_eventos_dacs c ON c.uid2 = b.uniqueid // INNER JOIN pbx_abandonadas_status e ON e.uniqueid = b.uniqueid // INNER JOIN pbx_usuarios d ON e.matricula = d.matricula // WHERE c.evento = 'ABANDON' // AND upper(c.fila) = upper('%s') // AND b.data_bilhete >= '%s' // AND b.lastapp <> 'Transferred Call' // ORDER BY 1",$dac,$dataIni); // } } else { $query = "SELECT " . ($mostraColunaServicos ? "s.serv_id," : "") . " b.fila, a.data_bilhete as data, date_part('hour', calldate) as hora, a.src as origem, count(*) as qtde, sum(strtoint(param3)) as tempo FROM pbx_bilhetes a INNER JOIN pbx_eventos_dacs b ON a.uniqueid = b.uid2 INNER JOIN pbx_abandonadas_semretorno c ON c.abdsr_uniqueid = a.uniqueid"; if (GetUsoServico()) { $query .= "\nleft join pbx_servicos_registra s on s.uniqueid = a.uniqueid "; } $query .= "\nWHERE data_bilhete >= '%s' AND data_bilhete <= '%s' AND b.evento = 'ABANDON' AND a.lastapp <> 'Transferred Call' AND b.fila = '%s'"; if (GetUsoServico() && $srv) { $query .= "\nand s.serv_id = '{$srv}'"; } $query .= "\nGROUP BY " . ($mostraColunaServicos ? "s.serv_id," : "") . " b.fila, a.data_bilhete,date_part('hour', a.calldate), a.src ORDER BY " . ($mostraColunaServicos ? "1," : "") . "2,3"; $query = sprintf($query, $dataIni, $dataFim, $dac); } //if(IsAdmin()){echo $query ; exit;} $result = $this->___GetQuery($query); while ($row = pg_fetch_array($result, null, PGSQL_ASSOC)) { $dataRel[] = $row; } $this->SetData($dataRel); $query = "SELECT SUM(CASE WHEN(STRTOINT(param3) <= 10)THEN 1 END) AS \"TE <= 10\", SUM(CASE WHEN((STRTOINT(param3) > 10) AND (STRTOINT(param3) <= 20))THEN 1 END) AS \"10 < TE <= 20\", SUM(CASE WHEN((STRTOINT(param3) > 20) AND (STRTOINT(param3) <= 30))THEN 1 END) AS \"20 < TE <= 30\", SUM(CASE WHEN((STRTOINT(param3) > 30) AND (STRTOINT(param3) <= 60))THEN 1 END) AS \"30 < TE <= 60\", SUM(CASE WHEN((STRTOINT(param3) > 60) AND (STRTOINT(param3) <= 120))THEN 1 END) AS \"60 < TE <= 120\", SUM(CASE WHEN((STRTOINT(param3) > 120) AND (STRTOINT(param3) <= 180))THEN 1 END) AS \"120 < TE <= 180\", SUM(CASE WHEN((STRTOINT(param3) > 180) AND (STRTOINT(param3) <= 300))THEN 1 END) AS \"180 < TE <= 300\", SUM(CASE WHEN(STRTOINT(param3) > 300)THEN 1 END) AS \"300 < TE\" FROM pbx_bilhetes a INNER JOIN pbx_eventos_dacs b ON b.uid2 = a.uniqueid INNER JOIN pbx_abandonadas_semretorno c ON c.abdsr_uniqueid = a.uniqueid"; if (GetUsoServico()) { $query .= "\nleft join pbx_servicos_registra s on s.uniqueid = a.uniqueid "; } $query .= "\nWHERE a.data_bilhete >= '%s' AND a.data_bilhete <= '%s' AND b.evento = 'ABANDON' AND a.lastapp <> 'Transferred Call' AND 1 = CASE WHEN(b.evento = 'ABANDON')THEN (CASE WHEN(NOT EXISTS(SELECT '' FROM ast_eventos_dacs WHERE uid2 = b.uid2 AND evento = 'TRANSBORDANDO' AND fila = b.fila)) THEN 1 ELSE 0 END) ELSE 1 END AND b.fila = '%s'"; if (GetUsoServico() && $srv) { $query .= "\nand s.serv_id = '{$srv}'"; } $query .= "\nORDER BY 1,2"; $query = sprintf($query, $dataIni, $dataFim, $dac); $dataRel = array(); $result = $this->___GetQuery($query); while ($row = pg_fetch_array($result, null, PGSQL_ASSOC)) { $dataRel[] = $row; } $this->SetData($dataRel); } public function ExecutaRelatorio() { global $jsStartup, $jsJQuery, $smarty; try { /* * Use esta fun��o para validar dados do formul�rio. */ $this->___ValidaForm(); /* * Recupera os dados do banco. */ $this->___ConteudoRelatorio(); /* * Imprime relat�rio de acordo com a media passada. */ $conteudoRelatorio = $this->___ImprimeRelatorio(); } catch (Exception $exc) { $this->SetMsg($exc->getMessage()); $jsStartup[] = sprintf("alert('%s');", $this->GetMsg()); $this->___GravaLog(); } /* * Inclua os scripts necess�rios aqui. */ $jsJQuery[] = "\$('#dataIni').keypress(function(){formataDataHora(this);}) "; $jsJQuery[] = "\$('#dataFim').keypress(function(){formataDataHora(this);}) "; $smarty->assign('filtros', $this->___FiltrosRelatorio()); $smarty->assign('conteudo', $conteudoRelatorio); $smarty->assign('msg', $this->GetMsg()); GetTemplate($smarty, 'relatoriosGrid.tpl'); } } $relAbd = new RelAbandonadasFila($idProg, $dbcon, 1); $relAbd->ExecutaRelatorio(); ?>