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.
 
 
 
 
 
 

437 lines
18 KiB

<?php
include_once 'util/relatoriosBase.php';
class RelClassificacao extends Relatorios {
public function __construct($idProg, $dbcon, $incDac) {
parent::__construct($idProg, $dbcon, $incDac);
$this->___dac = isset($_POST['listaDacs']) ? $_POST['listaDacs'] : 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>' : '';
$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) : '';
$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;
$query = sprintf("SELECT clas_descricao, clit_descricao, count(*) as qtde, count(distinct e.uid2) as chmd
FROM 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)
WHERE 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
GROUP BY clas_descricao, clit_descricao", $dataIni, $dataFim, $dac);
$subQuery = sprintf("SELECT count(1) as chmd
FROM pbx_bilhetes d
INNER JOIN pbx_eventos_dacs e ON e.uid2 = d.uniqueid
INNER JOIN pbx_usuarios f ON f.matricula = substring(e.agente, 7, 4)
INNER JOIN pbx_dacs a ON a.nome = e.fila
WHERE d.data_bilhete >= '%s' AND d.data_bilhete <= '%s'
AND e.evento IN('COMPLETEAGENT','COMPLETECALLER', 'TRANSFER','COMPLETEAGENTRAMAL','COMPLETECALLERRAMAL','BUSY','NOANSWER', 'COMPLETAAGENT','COMPLETACALLER', 'TRANSFERORIG','BUSYS','NOANSWERS')
AND a.id = %s
AND d.lastapp <> 'Transferred Call'", $dataIni, $dataFim, $dac);
$result = $this->___GetQuery($query);
$row = pg_fetch_all($result);
$this->SetData($row ? $row : array());
$subResult = $this->___GetQuery($subQuery);
$subRow = pg_fetch_assoc($subResult ? $subResult : array());
$this->SetData($subRow);
}
protected function ___PreparaCsv() {
$dataRel = array();
$filtro = $this->___FiltrosRelatorio();
/*
* Inicia o relatório.
*/
$dataRel[] = GenerateCsvFromArray($filtro);
$dadosCabecalio = array('Classificacao', 'Servico', 'Porcentagem %', 'Quantidade');
$dadosField = array('clas_descricao', 'clit_descricao', 'chmd', 'qtde');
/*
* 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();
/*
* 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', 'Servico', 'Porcentagem %', 'Quantidade');
$dadosField = array('clas_descricao', 'clit_descricao', 'chmd', 'qtde');
/*
* 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();
$dadosCabecalio = array(
'Classificação' => 'align="left"',
'Serviço' => 'align="left"',
'Porcentagem %' => 'align="right"',
'Quantidade' => 'align="right"'
);
$dadosField = array(
'clas_descricao' => 'align="left"',
'clit_descricao' => 'align="left"',
'chmd' => 'align="right"',
'qtde' => 'align="right"'
);
/*
* 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;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$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;
}
/*
* Linha de totalizacao.
*/
$linha = '<tr><th colspan="3" 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"];
/**
* TABELA DADOS PRINCIPAIS
*/
//HEADER DA TABELA DO PDF -> DADOS EM ARRAY
$header = array(
'Classificação' => 'C',
'Serviço' => 'C',
'Porcentagem %' => 'C',
'Quantidade' => 'C'
);
$dataHeader = array(
'clas_descricao' => 'C',
'clit_descricao' => 'C',
'chmd' => 'C',
'qtde' => 'C'
);
$somaChmTotal = 0;
foreach ($this->GetData()[0] as $row) {
$somaChmTotal += $row['chmd'];
}
$somaReg = 0;
$dados = array();
$x = 0;
foreach ($this->GetData()[0] as $row) {
$somaReg += $row['qtde'];
$dados[$x]["clas_descricao"] = $row["clas_descricao"];
$dados[$x]["clit_descricao"] = $row["clit_descricao"];
$dados[$x]["chmd"] = round(!$somaChmTotal ? 0 : ($row['qtde'] * 100) / $somaChmTotal) . '%';
$dados[$x]["qtde"] = $row['qtde'];
$x++;
}
$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($header, $dataHeader, $dados, $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'
";
*/