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.
 
 
 
 
 
 

671 lines
25 KiB

<?php
include_once 'util/relatoriosBase.php';
class RelClassificacaoDetalhes extends Relatorios
{
private $___classificacao;
private $___classItem;
private $___agente;
private $___servico;
private $___tipoRelatorio;
public function __construct($idProg, $dbcon, $incDac)
{
parent::__construct($idProg, $dbcon, $incDac);
$this->___dac = isset($_POST['listaDacs']) ? $_POST['listaDacs'] : 0;
$this->___classificacao = isset($_POST['listaClas']) ? $_POST['listaClas'] : 0;
$this->___classItem = isset($_POST['listaItem']) ? $_POST['listaItem'] : 0;
$this->___agente = isset($_POST["listaAgente"]) ? $_POST["listaAgente"] : null;
$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"';
if ($this->___dataIni && $this->___dataFim) {
$agentes = $this->retornaAgente();
}
/*
* Personalise esta função se necessitar de outras operações de filtro.
*/
$filtro = '<table border="0" cellspacing="1" cellpadding="1">';
/*
* Rotulos.
*/
$filtro .= '<tr>';
$filtro .= $this->GetIncDac() ? '<td>Fila</td>' : '';
$filtro .= GetUsoServico() ? '<td>Serviço</td>' : '';
$filtro .= '<td>Data Inicial</td>';
$filtro .= '<td>Data Final </td>';
$filtro .= '<td>Agente </td>';
$filtro .= '<td>Classificação </td>';
$filtro .= '<td>Classificação Item </td>';
$filtro .= '<td align="center" valign="middle">&nbsp;</td>';
$filtro .= '</tr>';
/*
* Valores.
*/
global $dbcon;
$filtro .= '<tr>';
$filtro .= $this->GetIncDac() ? 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>$agentes</td>";
$filtro .= sprintf('<td>%s</td>', GetClassificacao($dbcon, $this->___classificacao, $this->___dac));
$filtro .= sprintf('<td>%s</td>', GetItem($dbcon, $this->___classificacao, $this->___classItem));
$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;
$classificacao = $this->___classificacao;
$classificaItem = $this->___classItem;
$agente = $this->___agente ? $this->___agente : 0;
$srv = $this->___servico;
$mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA;
$query = "SELECT " . ($mostraColunaServicos ? "coalesce(s.serv_id, 'Não Informado') as serv_id," : "") . " calldate, apelido, src AS origem, dst AS destino, f.nome, clas_descricao, clit_descricao,tplg_descricao,
CASE WHEN (g.conf_uid <> '' AND g.conf_discado = 1) THEN 'S' ELSE 'N' END AS discador
FROM pbx_bilhetes a
INNER JOIN pbx_tipo_ligacao h ON h.tplg_codigo = a.tipo_chamada
INNER JOIN pbx_classifica_reg b ON a.uniqueid = b.id_bilhetes AND a.calldate = (SELECT MAX(calldate) FROM pbx_bilhetes WHERE uniqueid = b.id_bilhetes)
INNER JOIN pbx_classifica_atendimento c ON c.clas_id = b.clas_id
INNER JOIN pbx_classifica_item d ON d.clit_id = b.clit_id
INNER JOIN pbx_usuarios e ON e.matricula = b.matricula
INNER JOIN pbx_dacs f ON f.id = b.id_dac ";
if (GetUsoServico()) {
$query .= "\nleft join pbx_servicos_registra s on s.uniqueid = a.uniqueid ";
}
$query .= "\n LEFT JOIN pbx_campanha_contato_fone g ON a.uniqueid = g.conf_uid
WHERE data_bilhete >= '%s' AND data_bilhete <= '%s'
AND a.lastapp <> 'Transferred Call'
AND b.id_dac = %s";
if ($classificacao) {
$query .= "AND b.clas_id = $classificacao";
}
if ($classificaItem) {
$query .= "AND b.clit_id = $classificaItem";
}
if ($agente) {
$query .= "AND apelido = '$agente'";
}
if (GetUsoServico() && $srv) {
$query .= "\nand s.serv_id = '{$srv}'";
}
$query .= $mostraColunaServicos ? "ORDER BY s.serv_id, calldate" : "ORDER BY calldate";
$query = sprintf($query, $dataIni, $dataFim, $dac);
$subQuery = "SELECT count(1) as chmd FROM pbx_bilhetes a
INNER JOIN pbx_eventos_dacs b ON b.uid2 = a.uniqueid AND b.evento in('COMPLETEAGENT','COMPLETECALLER', 'TRANSFER','COMPLETEAGENTRAMAL','COMPLETECALLERRAMAL','BUSY','NOANSWER', 'COMPLETAAGENT','COMPLETACALLER', 'TRANSFERORIG','BUSYS','NOANSWERS')
INNER JOIN pbx_usuarios c ON c.matricula = substring(b.agente, 7, 4)
INNER JOIN pbx_dacs d ON d.nome = b.fila";
if (GetUsoServico()) {
$subQuery .= "\nleft join pbx_servicos_registra s on s.uniqueid = a.uniqueid ";
}
$subQuery .= "\nWHERE data_bilhete >= '%s' AND data_bilhete <= '%s'
AND d.id = %s
AND a.lastapp <> 'Transferred Call'";
if (GetUsoServico() && $srv) {
$subQuery .= "\nand s.serv_id = '{$srv}'";
}
$subQuery = sprintf($subQuery, $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);
$this->SetData($subRow ? $subRow : array());
$this->SetData($this->___agente ? $this->___agente : 0);
}
protected function ___PreparaCsv()
{
$dataRel = array();
$filtro = $this->___FiltrosRelatorio();
/*
* Inicia o relatório.
*/
$dataRel[] = GenerateCsvFromArray($filtro);
$dadosCabecalio = array(
'Data/Hora',
'Origem',
'Destino',
'Agente',
'Classificacao',
'Item',
'Tipo',
'Discador',
);
$dadosField = array(
'data_reg',
'origem',
'destino',
'apelido',
'clas_descricao',
'clit_descricao',
'tplg_descricao',
'discador',
);
if (GetUsoServico() == RELATORIO_SERVICOS_HABILITA) {
$dadosCabecalio = array_merge(['Servico'], $dadosCabecalio);
$dadosField = array_merge(['serv_id'], $dadosField);
}
/*
* Monta a linha de cabecalio.
*/
$dataRel[] = GenerateCsvFromArray($dadosCabecalio);
$somaReg = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$somaReg++;
$row['clit_descricao'] = RemoveAcentos($row['clit_descricao']);
$row['clas_descricao'] = RemoveAcentos($row['clas_descricao']);
$row['tplg_descricao'] = explode(' ', $row['tplg_descricao'])[0];
$row['data_reg'] = date('d/m/Y H:i:s', strtotime($row['data_reg']));
$row['origem'] = ocultarTelefone($row['origem']);
$row['destino'] = ocultarTelefone($row['destino']);
// 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(
'Data/Hora',
'Origem',
'Destino',
'Agente',
'Classificacao',
'Item',
'Tipo',
'Discador'
);
$dadosField = array(
'data_reg',
'origem',
'destino',
'apelido',
'clas_descricao',
'clit_descricao',
'tplg_descricao',
'discador'
);
if (GetUsoServico() == RELATORIO_SERVICOS_HABILITA) {
$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['clit_descricao'] = RemoveAcentos($row['clit_descricao']);
$row['clas_descricao'] = RemoveAcentos($row['clas_descricao']);
$row['tplg_descricao'] = explode(' ', $row['tplg_descricao'])[0];
$row['data_reg'] = date('d/m/Y H:i:s', strtotime($row['data_reg']));
$row['origem'] = ocultarTelefone($row['origem']);
$row['destino'] = ocultarTelefone($row['destino']);
// 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(
'Data/Hora' => 'align="center"',
'Origem' => 'align="left"',
'Destino' => 'align="left"',
'Agente' => 'align="left"',
'Classificação' => 'align="left"',
'Item' => 'align="center"',
'Tipo' => 'align="center"',
'Discador' => 'align="Center"'
);
$dadosField = array(
'data_reg' => 'align="center"',
'origem' => 'align="left"',
'destino' => 'align="left"',
'apelido' => 'align="left"',
'clas_descricao' => 'align="left"',
'clit_descricao' => 'align="center"',
'tplg_descricao' => 'align="center"',
'discador' => 'align="Center"'
);
if ($mostraColunaServicos) {
$dadosCabecalio['Serviço'] = 'align="center"';
$dadosField['serv_id'] = 'align="left"';
}
if ($permiteEditaClassificacao) {
$dadosCabecalio['Editar Classificação'] = 'align="center"';
$dadosField['editarClassificacao'] = 'align="center"';
}
/*
* Inicia o relat�rio.
*/
$dataRel[] = '<table width="90%" 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;
}
$somaReg = 0;
$somaServico = 0;
$srv = '';
$oldSrv = '';
$agrupaServico = function ($row) 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) {
$dataRel[] = sprintf("<tr><th colspan=\"8\" align=\"center\" {$style}>Total [%s] </th><th colspan=\"2\" align=\"right\" {$style}>%s</th></tr>", $oldSrv, $somaServico);
$oldSrv = $srv;
$somaServico = 0;
}
$somaServico++;
};
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
if ($mostraColunaServicos) {
$agrupaServico($row);
}
$somaReg++;
$row["calldate"] = date('d/m/Y H:i:s', strtotime($row["calldate"]));
$row['tplg_descricao'] = explode(' ', $row['tplg_descricao'])[0];
$row['origem'] = ocultarTelefone($row['origem']);
$row['destino'] = ocultarTelefone($row['destino']);
if ($permiteEditaClassificacao) {
$row['editarClassificacao'] = sprintf("<a href=\"javaScript:NovaJanela('index.php?idProg=367&pbxRequest=1&regClassId=%s', 'jneditaClassificado', '0', '0', 'resizable=no,location=no,scrollbars=no');\">
<img src=\"imgSite/class16.png\" width=\"16\" border=\"0\" height=\"16\" title=\"Clique para editar esta classificação.\"
alt=\"Clique para editar esta classificação.\" align=\"absmiddle\"></a>", $row['reg_class_id']);
}
// 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.
*/
$colspan = 7;
if ($mostraColunaServicos) {
$agrupaServico(false);
$colspan = 8;
}
$linha = '<tr><th colspan="' . $colspan . '" align="left">Total [ Chamadas Periodo ]: %s</th><th colspan="2" 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(
'Data/Hora' => 'C',
'Origem' => 'C',
'Destino' => 'C',
'Agente' => 'C',
'Classificação' => 'C',
'Item' => 'C',
'Tipo' => 'C',
'Discador' => 'C',
);
$dadosField = array(
'data_reg' => 'C',
'origem' => 'C',
'destino' => 'C',
'apelido' => 'C',
'clas_descricao' => 'C',
'clit_descricao' => 'C',
'tplg_descricao' => 'C',
'discador' => 'C',
);
if ($mostraColunaServicos) {
$dadosCabecalio = array_merge(['Serviço' => 'C'], $dadosCabecalio);
$dadosField = array_merge(['serv_id' => 'C'], $dadosField);
}
$somaReg = 0;
$somaServico = 0;
$srv = '';
$oldSrv = '';
$dadosTable = [];
$agrupaServico = function ($row) use (&$somaServico, &$dadosTable, &$srv, &$oldSrv) {
$somaChmTotal = 0;
$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['data_reg'] = ' ';
$data['origem'] = ' ';
$data['apelido'] = ' ';
$data['clas_descricao'] = ' ';
$data['clit_descricao'] = ' ';
$data['tplg_descricao'] = ' ';
$data['discador'] = $somaServico;
$data['cor_linha_dados'] = 225;
$dadosTable[] = $data;
$oldSrv = $srv;
$oldSrv = $srv;
$somaServico = 0;
}
$somaServico++;
};
foreach ($this->GetData()[0] as $row) {
if ($mostraColunaServicos) {
$agrupaServico($row);
}
$somaReg++;
$row['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate']));
$row['tplg_descricao'] = explode(' ', $row['tplg_descricao'])[0];
$row['origem'] = ocultarTelefone($row['origem']);
$row['destino'] = ocultarTelefone($row['destino']);
$dadosTable[] = $row;
}
if ($mostraColunaServicos) {
$agrupaServico(false);
$widthHeader = array(20, 20, 15, 25, 25, 20, 20, 15);
$totalizador = array('Total Chamadas: ' . $this->GetData()[1]['chmd'], '', '', '', '', 'Registros: ' . $somaReg, '', '',);
} else {
$widthHeader = array(20, 15, 30, 35, 35, 20, 20, 15);
$totalizador = array('Total Chamadas: ' . $this->GetData()[1]['chmd'], '', '', '', 'Registros: ' . $somaReg, '', '',);
}
//Monta o array para passar para o prepara; Necessário passar 6 parametros
$table = array($dadosCabecalio, $dadosField, $dadosTable, $widthHeader, $totalizador, 0);
$this->___dataRel = array($table);
}
protected function retornaAgente()
{
global $dbcon;
$org_id = GetOrganizacao();
$codSel = $this->GetData()[2] ? $this->GetData()[2] : '';
$agentes = "<select name=\"listaAgente\" id=\"listaAgente\" size=\"1\">";
$agentes .= "<option value=\"0\">Todos</option>";
$query = sprintf("SELECT apelido AS nome
FROM pbx_usuarios u
INNER JOIN pbx_organizacao_usuarios ou ON ou.id_usuario = u.id
WHERE EXISTS(SELECT '' FROM pbx_eventos_agentes WHERE id_dac = %s
AND matricula = u.matricula
AND CAST(login as date) >= '%s'
AND CAST(login as date) <= '%s')
AND ou.id_organizacao = $org_id ", $this->___dac, FormatDtMssql($this->___dataIni), FormatDtMssql($this->___dataFim));
$result = pg_query($dbcon, $query);
if (!$result) {
return '<select name=\"listaAgente\"><option value=\"0\"> ----- </option></select>';
}
while ($dados = pg_fetch_row($result)) {
if ($codSel == $dados[0]) {
$sel = "selected";
$i = 1;
} else {
$sel = "";
}
$agentes .= "<option value=\"$dados[0]\" $sel>$dados[0]</option>";
}
$agentes .= "</select>";
return $agentes;
}
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');
}
}
$relClassDetalhes = new RelClassificacaoDetalhes($idProg, $dbcon, 1);
$relClassDetalhes->ExecutaRelatorio();