You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

554 lines
21 KiB

<?php
include_once 'util/relatoriosBase.php';
class RelClassificacao extends Relatorios {
private $___servico;
public function __construct($idProg, $dbcon, $incDac) {
parent::__construct($idProg, $dbcon, $incDac);
$this->___dac = isset($_POST['listaDacs']) ? $_POST['listaDacs'] : 0;
$this->___servico = isset($_POST["listaServico"]) ? $_POST["listaServico"] : 0;
}
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 = '<a href="index.php?idProg=%s&media=%s&tipoRelatorio=%s"><img src="imgSite/%s" alt="Clique aqui para imprimir!" width="24" height="24" border="0"></a>';
$prtHtml = "<a href=\"javaScript:NovaJanela('index.php?idProg=%s&media=%s&tipoRelatorio=%s', '%s', '720', '700', 'scrollbars=YES');\"><img src=\"imgSite/%s\" alt=\"Clique aqui para imprimir!\" width=\"24\" height=\"24\" border=\"0\"></a>";
$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 operações de filtro.
*/
$filtro = '<table border="0" cellspacing="1" cellpadding="1">';
/*
* Rotulos.
*/
$filtro .= '<tr>';
$this->GetIncDac() ? $filtro .= '<td>Fila</td>' : '';
if (GetUsoServico()) {
$filtro .= '<td>Serviço </td>';
}
$filtro .= '<td>Data Inicial</td>';
$filtro .= '<td>Data Final </td>';
$filtro .= '<td align="center" valign="middle">&nbsp;</td>';
$filtro .= '</tr>';
/*
* Valores.
*/
$filtro .= '<tr>';
$this->GetIncDac() ? $filtro .= sprintf('<td>%s</td>', $dacs) : '';
if (GetUsoServico()) {
$filtro .= sprintf('<td>%s</td>', GetIdentRota(false, $this->___servico));
}
$filtro .= '<td><input name="dataIni" id="dataIni" type="text" size="15" maxlength="10" value="%s" onkeyup="formataData(this)" title="dd/mm/aaaa"></td>';
$filtro .= '<td><input name="dataFim" id="dataFim" type="text" size="15" maxlength="10" value="%s" onkeyup="formataData(this)" title="dd/mm/aaaa"></td>';
$filtro .= '<td><input type="submit" name="btConsulta" id="btConsulta" value="Consultar"></td>';
$filtro .= '<td>%s</td>';
$filtro .= '</tr>';
$filtro .= '</table>';
/*
* Guarda os filtros passados para recuperar na emissão dos relatórios para impressão.
*/
$_SESSION["SSstorageFiltros"] = array($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio);
return sprintf($filtro, $this->___dataIni, $this->___dataFim, $lkPrint);
}
protected function ___GetDadosDb() {
$dataIni = FormatDtMssql($this->___dataIni);
$dataFim = FormatDtMssql($this->___dataFim);
$dac = $this->___dac;
$srv = $this->___servico;
$mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA;
$queryCabecalio = "SELECT" . ($mostraColunaServicos ? " coalesce(s.serv_id, 'Não Informado') as serv_id," : "") . " clas_descricao, clit_descricao, count(*) as qtde, count(distinct e.uid2) as chmd";
$query = "\nFROM pbx_classifica_reg a
INNER JOIN pbx_classifica_atendimento b ON b.clas_id = a.clas_id
INNER JOIN pbx_classifica_item c ON c.clit_id = a.clit_id
INNER JOIN pbx_bilhetes d ON d.uniqueid = a.id_bilhetes
INNER JOIN pbx_eventos_dacs e ON e.uid2 = d.uniqueid
INNER JOIN pbx_usuarios f ON f.matricula = substring(e.agente, 7, 4)";
if (GetUsoServico()) {
$query .= "\nleft join pbx_servicos_registra s on s.uniqueid = d.uniqueid";
}
$query .= "\nWHERE d.data_bilhete >= '%s' AND d.data_bilhete <= '%s'
AND d.lastapp <> 'Transferred Call'
AND e.evento in('COMPLETEAGENT','COMPLETECALLER', 'TRANSFER','COMPLETEAGENTRAMAL','COMPLETECALLERRAMAL','BUSY','NOANSWER', 'COMPLETAAGENT','COMPLETACALLER', 'TRANSFERORIG','BUSYS','NOANSWERS')
AND a.id_dac = %s";
if (GetUsoServico() && $srv) {
$query .= "\nand s.serv_id = '{$srv}'";
}
$queryGroup .= $mostraColunaServicos ? "\nGROUP BY clas_descricao, clit_descricao, s.serv_id" : "\nGROUP BY clas_descricao, clit_descricao\n";
$queryOrder .= $mostraColunaServicos ? "\norder by s.serv_id, clas_descricao, clit_descricao" : "\norder by clas_descricao, clit_descricao\n";
$query = sprintf($query, $dataIni, $dataFim, $dac);
$queryDados = ($queryCabecalio . $query . $queryGroup . $queryOrder);
$queryCabecalio = "\nSELECT count(distinct d.uniqueid) as chmd ";
$result = $this->___GetQuery($queryDados);
$row = pg_fetch_all($result);
$this->SetData($row ? $row : array());
$subResult = $this->___GetQuery($queryCabecalio . $query);
$subRow = pg_fetch_assoc($subResult ? $subResult : array());
$this->SetData($subRow);
}
protected function ___PreparaCsv() {
$dataRel = array();
$filtro = $this->___FiltrosRelatorio();
$mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA;
/*
* Inicia o relatório.
*/
$dataRel[] = GenerateCsvFromArray($filtro);
$dadosCabecalio = array('Classificacao', 'Item', 'Porcentagem %', 'Quantidade');
$dadosField = array('clas_descricao', 'clit_descricao', 'chmd', 'qtde');
if ($mostraColunaServicos) {
$dadosCabecalio = array_merge(['Servico'], $dadosCabecalio);
$dadosField = array_merge(['serv_id'], $dadosField);
}
/*
* Monta a linha de cabecalio.
*/
$dataRel[] = GenerateCsvFromArray($dadosCabecalio);
$somaChmTotal = 0;
foreach ($this->GetData()[0] as $row) {
$somaChmTotal += $row['chmd'];
}
$somaReg = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$somaReg += $row['qtde'];
$row['clit_descricao'] = RemoveAcentos($row['clit_descricao']);
$row['chmd'] = round(!$somaChmTotal ? 0 : ($row['qtde'] * 100) / $somaChmTotal) . '%';
// Formata linha de dados.
$linha = array();
foreach ($dadosField as $value) {
$linha[] = $row["$value"];
}
$dataRel[] = GenerateCsvFromArray($linha);
}
$dataRel[] = GenerateCsvFromArray(array('Total Chamadas: ' . $this->GetData()[1]['chmd'], '', '', 'Registros: ' . $somaReg));
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaExcel() {
$dataRel = 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;
$dadosCabecalio = array('Classificacao', 'Item', 'Porcentagem %', 'Quantidade');
$dadosField = array('clas_descricao', 'clit_descricao', 'chmd', 'qtde');
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;
$somaChmTotal = 0;
foreach ($this->GetData()[0] as $row) {
$somaChmTotal += $row['chmd'];
}
$somaReg = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$somaReg += $row['qtde'];
$row['clit_descricao'] = RemoveAcentos($row['clit_descricao']);
$row['chmd'] = round(!$somaChmTotal ? 0 : ($row['qtde'] * 100) / $somaChmTotal) . '%';
// Formata linha de dados.
$linha = array('DADOS');
foreach ($dadosField as $key) {
$linha[] = $row["$key"];
}
$dataRel[] = $linha;
}
$dataRel[] = array('LABEL', 'Total Chamadas: ' . $this->GetData()[1]['chmd'], '', '', 'Registros: ' . $somaReg);
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaGrid() {
$dataRel = array();
$mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA;
$dadosCabecalio = array(
'Classificação' => 'align="left"',
'Item' => 'align="left"',
'Porcentagem %' => 'align="right"',
'Quantidade' => 'align="right"'
);
$dadosField = array(
'clas_descricao' => 'align="left"',
'clit_descricao' => 'align="left"',
'chmd' => 'align="right"',
'qtde' => 'align="right"'
);
if ($mostraColunaServicos) {
$dadosCabecalio = array_merge(['Serviço' => 'align="center"'], $dadosCabecalio);
$dadosField = array_merge(['serv_id' => 'align="left"'], $dadosField);
}
/*
* Inicia o relatório.
*/
$dataRel[] = '<table width="70%" cellpadding="2" class="grid">';
/*
* Monta a linha de cabecalio.
*/
$linha = '<tr>';
foreach ($dadosCabecalio as $key => $value) {
$linha .= sprintf("<th %s>%s</th>", $value, $key);
}
$linha .= "</tr>";
$dataRel[] = $linha;
/*
* Verifica se retornou dados
*/
if (!IsPostBack() || !count($this->GetData()[0])) {
$dataRel[] = sprintf("<tr><td align=\"center\" colspan=\"%s\">%s<td></tr></table>", count($dadosCabecalio) - 1, (!IsPostBack() ? 'Informe os parametros e clique em consultar!' : 'Nenhum registro encontado!'));
$this->___dataRel[] = $dataRel;
return;
}
$somaChmTotal = 0;
foreach ($this->GetData()[0] as $row) {
$somaChmTotal += $row['chmd'];
}
$somaReg = 0;
$somaServico = 0;
$srv = '';
$oldSrv = '';
$agrupaServico = function($row, $somaChmTotal) use(&$somaServico, &$dataRel, &$srv, &$oldSrv) {
$style = 'style="font-weight: bold; padding: 0; margin: 0; padding-left: 6px; padding-right: 6px; background-color: #4F71C0 !important"';
$srv = $row["serv_id"];
if (!$oldSrv) {
$oldSrv = $srv;
}
if ((($srv != $oldSrv)) || !$row) {
$perc = !$somaChmTotal ? 0 : round(($somaServico / $somaChmTotal) * 100.0);
$dataRel[] = sprintf("<tr><th colspan=\"3\" align=\"center\" {$style}>Total [%s] </th><th colspan=\"1\" align=\"right\" {$style}>%s</th><th colspan=\"1\" align=\"right\" {$style}>%s</th></tr>", $oldSrv, $perc . "%", $somaServico);
$oldSrv = $srv;
$somaServico = 0;
}
$somaServico += $row['qtde'];
};
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
if ($mostraColunaServicos) {
$agrupaServico($row, $somaChmTotal);
}
$somaReg += $row['qtde'];
$row['chmd'] = round(!$somaChmTotal ? 0 : ($row['qtde'] * 100) / $somaChmTotal) . '%';
// Formata linha de dados.
$linha = "<tr>";
foreach ($dadosField as $key => $value) {
$linha .= sprintf("<td %s>%s</td>", $value, $row["$key"]);
}
$linha .= "</tr>";
$dataRel[] = $linha;
}
$colspan = 3;
if ($mostraColunaServicos) {
$agrupaServico(false, $somaChmTotal);
$colspan = 4;
}
/*
* Linha de totalizacao.
*/
$linha = '<tr><th colspan="' . $colspan .'" align="left">Total Chamadas: %s</th><th align="right">Registros: %s</th></tr>';
$dataRel[] = sprintf($linha, $this->GetData()[1]['chmd'], $somaReg);
/*
* Fecha relatorio.
*/
$dataRel[] = '</table>';
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaHtml() {
}
protected function ___PreparaPdf() {
list($this->___dac, $this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"];
$mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA;
/**
* TABELA DADOS PRINCIPAIS
*/
//HEADER DA TABELA DO PDF -> DADOS EM ARRAY
$dadosCabecalio = array(
'Classificação' => 'C',
'Item' => 'C',
'Porcentagem %' => 'C',
'Quantidade' => 'C'
);
$dadosField = array(
'clas_descricao' => 'C',
'clit_descricao' => 'C',
'chmd' => 'C',
'qtde' => 'C'
);
if ($mostraColunaServicos) {
$dadosCabecalio = array_merge(['Serviço' => 'C'], $dadosCabecalio);
$dadosField = array_merge(['serv_id' => 'C'], $dadosField);
}
$somaChmTotal = 0;
foreach ($this->GetData()[0] as $row) {
$somaChmTotal += $row['chmd'];
}
$somaReg = 0;
$dados = array();
$somaServico = 0;
$srv = '';
$oldSrv = '';
$dadosTable = [];
$agrupaServico = function($row, $somaChmTotal) use(&$somaServico, &$dadosTable, &$srv, &$oldSrv) {
$style = 'style="font-weight: bold; padding: 0; margin: 0; padding-left: 6px; padding-right: 6px; background-color: #4F71C0 !important"';
$srv = $row["serv_id"];
if (!$oldSrv) {
$oldSrv = $srv;
}
if ((($srv != $oldSrv)) || !$row) {
$perc = !$somaChmTotal ? 0 : (($somaServico / $somaChmTotal) * 100.0);
$data = [];
$data['serv_id'] = "TOTAL[$oldSrv]";
$data['clas_descricao'] = ' ';
$data['clit_descricao'] = ' ';
$data['chmd'] = round($perc);
$data['qtde'] = $somaServico;
$data['cor_linha_dados'] = 225;
$dadosTable[] = $data;
$oldSrv = $srv;
$somaDuracaoServico = 0;
$oldSrv = $srv;
$somaServico = 0;
}
$somaServico += $row['qtde'];
};
foreach ($this->GetData()[0] as $row) {
if ($mostraColunaServicos) {
$agrupaServico($row, $somaChmTotal);
}
$somaReg += $row['qtde'];
$row["chmd"] = round(!$somaChmTotal ? 0 : ($row['qtde'] * 100) / $somaChmTotal) . '%';
$dadosTable[] = $row;
}
if ($mostraColunaServicos) {
$agrupaServico(false, $somaChmTotal);
$widthHeader = array(42, 43, 43, 30, 30);
$totalizador = array('Total Chamadas: ' . $this->GetData()[1]['chmd'], '','', '', 'Registros: ' . $somaReg);
} else {
$widthHeader = array(47, 47, 47, 47);
$totalizador = array('Total Chamadas: ' . $this->GetData()[1]['chmd'], '', '', 'Registros: ' . $somaReg);
}
//Monta o array para passar para o prepara; Necessário passar 6 parametros
$table1 = array($dadosCabecalio, $dadosField, $dadosTable, $widthHeader, $totalizador, 0);
$this->___dataRel = array($table1);
}
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');
}
}
$relClassficacao = new RelClassificacao($idProg, $dbcon, 1);
$relClassficacao->ExecutaRelatorio();
/*
* *************************************************************************
* BACKUP DA QUERY ANTERIOR
* *************************************************************************
$query = " select clas_descricao, clit_descricao, count(*) as qtde, count(distinct e.uid2) as chmd
from pbx_classifica_reg a, pbx_classifica_atendimento b, pbx_classifica_item c,
pbx_bilhetes d, pbx_eventos_dacs e, pbx_usuarios f
where b.clas_id = a.clas_id
and c.clit_id = a.clit_id
and d.uniqueid = a.id_bilhetes
and d.lastapp <> 'Transferred Call'
and e.uid2 = d.uniqueid
and e.evento in('COMPLETEAGENT','COMPLETECALLER', 'TRANSFER','COMPLETEAGENTRAMAL','COMPLETECALLERRAMAL','BUSY','NOANSWER', 'COMPLETAAGENT','COMPLETACALLER', 'TRANSFERORIG','BUSYS','NOANSWERS')
and f.matricula = substring(e.agente, 7, 4)
and coalesce(a.id_dac, 0) = case when($dac > 0)then $dac else coalesce(a.id_dac, 0) end
and d.data_bilhete >= '$dt' and d.data_bilhete <= '$dt'
group by clas_descricao, clit_descricao";
if ($total) {
$query = "select count(1) as chmd
from pbx_bilhetes d, pbx_eventos_dacs e, pbx_usuarios f, pbx_dacs a
where e.uid2 = d.uniqueid
and e.evento in('COMPLETEAGENT','COMPLETECALLER', 'TRANSFER','COMPLETEAGENTRAMAL','COMPLETECALLERRAMAL','BUSY','NOANSWER', 'COMPLETAAGENT','COMPLETACALLER', 'TRANSFERORIG','BUSYS','NOANSWERS')
and a.nome = e.fila
and f.matricula = substring(e.agente, 7, 4)
and d.lastapp <> 'Transferred Call'
and coalesce(a.id, 0) = case when($dac > 0)then $dac else coalesce(a.id, 0) end
and d.data_bilhete >= '$dt' and d.data_bilhete <= '$dt'
";
*/