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.
 
 
 
 
 
 

490 lines
21 KiB

<?php
include_once 'util/relatoriosBase.php';
class RelDesligamento extends Relatorios {
private $___duracao;
private $___agente;
public function __construct($idProg, $dbcon, $incDac) {
parent::__construct($idProg, $dbcon, $incDac);
$this->___duracao = isset($_REQUEST['duracao']) ? $_REQUEST['duracao'] : '';
$this->___dac = isset($_POST['listaDacs']) ? $_POST['listaDacs'] : 0;
$this->___agente = isset($_POST["listaAgente"]) ? $_POST["listaAgente"] : 0;
}
function ___FiltrosRelatorio() {
if ($this->___media != MEDIA_PRINT_GRID) {
/*
* Recupera os filtros da sesssão do usu�rio.
*/
list($this->___dac, $this->___dataIni, $this->___dataFim) = $_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 ", $fila, $this->___dataIni, $this->___dataFim);
}
$tipoRel = !$this->___tipoRelatorio ? '' : 'checked="checked"';
$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');
}
/*
* Personalise esta função se necessitar de outras opções de filtro.
*/
$filtro = '<table border="0" cellspacing="1" cellpadding="1">';
/*
* Rotulos.
*/
$filtro .= '<tr>';
if ($this->GetIncDac())
$filtro .= '<td>Fila</td>';
$filtro .= '<td>Data Inicial</td>';
$filtro .= '<td>Data Final </td>';
$filtro .= '<td>Agente </td>';
$filtro .= '<td>Duração (<=)</td>';
$filtro .= '<td align="center" valign="middle">&nbsp;</td>';
$filtro .= '</tr>';
/*
* Valores.
*/
$filtro .= '<tr>';
if ($this->GetIncDac())
$filtro .= sprintf('<td>%s</td>', $dacs);
$filtro .= sprintf('<td><input name="dataIni" id="dataIni" type="text" size="15" maxlength="10" value="%s" onkeyup="formataData(this)" title="dd/mm/aaaa"></td>', $this->___dataIni);
$filtro .= sprintf('<td><input name="dataFim" id="dataFim" type="text" size="15" maxlength="10" value="%s" onkeyup="formataData(this)" title="dd/mm/aaaa"></td>', $this->___dataFim);
$filtro .= sprintf("<td>%s</td>", $this->___GetAgentes($this->___agente));
$filtro .= sprintf('<td><input name="duracao" id="duracao" type="text" size="15" maxlength="10" value="%s" title="Duração em segundos!" /></td>', $this->___duracao);
$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);
return sprintf($filtro, $lkPrint);
}
protected function ___GetDadosDb() {
$dataIni = FormatDtMssql($this->___dataIni);
$dataFim = FormatDtMssql($this->___dataFim);
$dac = $this->___dac;
$agente = $this->___agente;
$duracao = $this->___duracao;
$query = "SELECT c.id AS id_dac, c.nome AS nome_dac, a.calldate, d.id AS id_usuario, d.nome AS nome_usuario, d.apelido, a.src AS numero,
CASE WHEN(b.evento = 'TRANSFER')THEN b.param4 else b.param2 END AS duracao,
CASE WHEN(b.evento IN('COMPLETECALLER', 'COMPLETEAGENTRAMAL'))THEN 'A' ELSE 'B' END AS desligado_por,
CASE WHEN(b.evento IN('COMPLETEAGENT', 'COMPLETECALLER', 'TRANSFER'))THEN 'F' ELSE 'R' END AS tipo_ligacao
FROM pbx_bilhetes a
INNER JOIN pbx_eventos_dacs b ON b.uid2 = a.uniqueid
INNER JOIN pbx_dacs c ON c.nome = b.fila
INNER JOIN pbx_usuarios d ON d.matricula = substring(b.agente, 7, 4)
AND calldate::date >= '%s'
AND calldate::date <= '%s'
AND c.id = %s
AND b.evento in('COMPLETEAGENT', 'COMPLETECALLER', 'TRANSFER','COMPLETEAGENTRAMAL','COMPLETECALLERRAMAL')
";
if ($agente) {
$query .= "AND apelido = '$agente'";
}
if ($duracao) {
$query .= "AND CASE WHEN(b.param2 <> '' AND length(b.param2)::INT <= 5)THEN b.param2::INT ELSE 0 END <= $duracao";
}
$query .= "ORDER BY calldate";
$sqlQuery = sprintf($query, $dataIni, $dataFim, $dac);
$result = $this->___GetQuery($sqlQuery);
$row = pg_fetch_all($result);
$this->SetData($row ? $row : array());
}
protected function ___PreparaCsv() {
$dataRel = array();
$filtro = $this->___FiltrosRelatorio();
/*
* Inicia o relatório.
*/
$dataRel[] = GenerateCsvFromArray($filtro);
$dadosCabecalio = array('Data/Hora' => 'align="center"', 'Agente' => 'align="center"', 'Origem' => 'align="center"', 'Duracao' => 'align="center"', 'Desligado' => 'align="center"', 'Tipo' => 'align="center"');
$dadosField = array('calldate' => 'align="center"', 'apelido' => 'align="center"', 'numero' => 'align="center"', 'duracao' => 'align="center"', 'desligado_por' => 'align="center"', 'tipo_ligacao' => 'align="center"');
/*
* Monta a linha de cabecalio.
*/
$dataRel[] = GenerateCsvFromArray(array_keys($dadosCabecalio));
$somaTempo = 0;
$somaQtde = 0;
$somaA = 0;
$somaB = 0;
$somaF = 0;
$somaR = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$somaQtde ++;
$somaTempo += $row["duracao"];
$row['desligado_por'] == "A" ? $somaA++ : $somaB++;
$row['tipo_ligacao'] == "F" ? $somaF++ : $somaR++;
$row['numero'] = ocultarTelefone($row['numero']);
$row["calldate"] = date('d/m/Y H:i', strtotime($row["calldate"]));
$row["duracao"] = SecondToStrTime($row["duracao"]);
// Formata linha de dados.
$linha = array();
foreach ($dadosField as $key => $value) {
$linha[] = $row["$key"];
}
$dataRel[] = GenerateCsvFromArray($linha);
}
$dataRel[] = GenerateCsvFromArray(array('', '', '', ''));
$totalCabecalio = array('Desligadas por A', 'Desligadas por B', 'Total', 'Duracao', 'Tipo');
$dataRel[] = GenerateCsvFromArray($totalCabecalio);
$dataRel[] = GenerateCsvFromArray(array('Desligada pelo Cliente: '.$somaA, 'Desligada pelo Atendente: '.$somaB, $somaQtde, SecondToStrTime($somaTempo), 'Fila: '.$somaF.' | Ramal: '.$somaR));
$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', 'Agente', 'Origem', 'Duracao', 'Desligada', 'Tipo');
$dadosField = array('calldate', 'apelido', 'numero', 'duracao', 'desligado_por', 'tipo_ligacao');
/*
* Monta a linha de cabecalio.
*/
$linha = array('LABEL');
foreach ($dadosCabecalio as $value) {
$linha[] = $value;
}
$dataRel[] = $linha;
$somaTempo = 0;
$somaQtde = 0;
$somaA = 0;
$somaB = 0;
$somaF = 0;
$somaR = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$somaQtde ++;
$somaTempo += $row["duracao"];
$row['desligado_por'] == "A" ? $somaA++ : $somaB++;
$row['tipo_ligacao'] == "F" ? $somaF++ : $somaR++;
$row['numero'] = ocultarTelefone($row['numero']);
$row["calldate"] = date('d/m/Y H:i', strtotime($row["calldate"]));
$row["duracao"] = SecondToStrTime($row["duracao"]);
// Formata linha de dados.
$linha = array('DADOS');
foreach ($dadosField as $key) {
$linha[] = $row["$key"];
}
$dataRel[] = $linha;
}
$dataRel[] = array('LABEL', '', '', '', '', '', '');
$totalCabecalio = array('Desligadas por A', 'Desligadas por B', 'Total', 'Duracao', 'Tipo');
$linhaTotal = array('LABEL');
foreach ($totalCabecalio as $value) {
$linhaTotal[] = $value;
}
$dataRel[] = $linhaTotal;
$linhaTotal = array('DADOS', 'Desligada pelo Cliente: ' . $somaA, 'Desligada pelo Atendente: ' . $somaB, $somaQtde, SecondToStrTime($somaTempo), 'Fila: ' . $somaF . ' | Ramal: ' . $somaR);
$dataRel[] = $linhaTotal;
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaGrid() {
$dadosCabecalio = array(
'Data/Hora' => 'align="center"',
'Agente' => 'align="left"',
'Origem' => 'align="left"',
'Duração' => 'align="center"',
'Desligado' => 'align="center"',
'Tipo' => 'align="center"'
);
$dadosField = array(
'calldate' => 'align="center"',
'apelido' => 'align="left"',
'numero' => 'align="left"',
'duracao' => 'align="center"',
'desligado_por' => 'align="center"',
'tipo_ligacao' => '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;
}
$somaTempo = 0;
$somaQuantidade = 0;
$somaA = 0;
$somaB = 0;
$somaF = 0;
$somaR = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$row['desligado_por'] == "A" ? $somaA++ : $somaB++;
$row['tipo_ligacao'] == "F" ? $somaF++ : $somaR++;
$row['numero'] = ocultarTelefone($row['numero']);
$somaTempo += $row['duracao'];
$somaQuantidade ++;
$row["calldate"] = date('d/m/Y H:i', strtotime($row["calldate"]));
$row["duracao"] = SecondToStrTime($row["duracao"]);
// Formata linha de dados.
$linha = "<tr>";
foreach ($dadosField as $key => $value) {
$linha .= sprintf("<td %s>%s</td>", $value, $row["$key"]);
}
$linha .= "</tr>";
$dataRel[] = $linha;
}
$dataRel[] = '</table><br>';
$linhaTotalizador = "<table width=\"60%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" class=\"grid\">";
$linhaTotalizador .= "<tr><th colspan=\"2\" align=\"center\">Totaliza&ccedil;&atilde;o</th></tr>";
$linhaTotalizador .= sprintf("<tr><th width=\"120\">Desligadas por A</th><td align=\"left\">%s (A liga&ccedil;&atilde;o foi desligada pelo cliente)</td></tr>", $somaA);
$linhaTotalizador .= sprintf("<tr><th>Desligadas por B</th><td align=\"left\">%s (A liga&ccedil;&atilde;o foi desligada pelo atendente)</td></tr>", $somaB);
$linhaTotalizador .= sprintf("<tr><th>Total</th><td align=\"left\">%s</td></tr>", $somaQuantidade);
$linhaTotalizador .= sprintf("<tr><th>Dura&ccedil;&atilde;o</th><td align=\"left\">%s</td></tr>", SecondToStrTime($somaTempo));
$linhaTotalizador .= sprintf("<tr><th>Tipo</th><td align=\"left\">Total Fila (F): %s Total Ramal (R): %s</td></tr>", $somaF, $somaR);
$linhaTotalizador .= "</table>";
$dataRel[] = $linhaTotalizador;
//$dataRel[] = sprintf($linha);
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaHtml() {
}
protected function ___PreparaPdf() {
list($this->___dac, $this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"];
/**
* TABELA DADOS PRINCIPAIS
*/
$somaQtde = 0;
$somaTempo = 0;
$somaA = 0;
$somaB = 0;
$somaF = 0;
$somaR = 0;
$dados = array();
$x = 0;
//HEADER DA TABELA DO PDF -> DADOS EM ARRAY
$header = array(
'Data/Hora' => 'C',
'Agente' => 'C',
'Origem' => 'C',
'Duração' => 'C',
'Desligado' => 'C',
'Tipo' => 'C'
);
$dataHeader = array(
'calldate' => 'C',
'apelido' => 'C',
'numero' => 'C',
'duracao' => 'C',
'desligado_por' => 'C',
'tipo_ligacao' => 'C'
);
foreach ($this->GetData()[0] as $row) {
$row['desligado_por'] == "A" ? $somaA++ : $somaB++;
$row['tipo_ligacao'] == "F" ? $somaF++ : $somaR++;
$somaTempo += $row['duracao'];
$somaQtde ++;
$dados[$x]['desligado_por'] = $row['desligado_por'];
$dados[$x]['tipo_ligacao'] = $row['tipo_ligacao'];
$dados[$x]['numero'] = ocultarTelefone($row['numero']);
$dados[$x]['apelido'] = $row['apelido'];
$dados[$x]["calldate"] = date('d/m/Y H:i', strtotime($row["calldate"]));
$dados[$x]["duracao"] = SecondToStrTime($row["duracao"]);
$x++;
}
$widthHeader = array(45, 40, 45, 30, 15, 15);
//Monta o array para passar para o prepara; Necessário passar 6 parametros
$table1 = array($header, $dataHeader, $dados, $widthHeader, 0, 0);
//Tabela do Totalizador com os Dados
$headerTotal = array(
'Desligadas por A' => 'C',
'Desligadas por B' => 'C',
'Total' => 'C',
'Duração' => 'C',
'Tipo Ligação' => 'C'
);
$dataHdTotal = array(
'desligada_a' => 'C',
'desligada_b' => 'C',
'totalDes' => 'C',
'duracao' => 'C',
'tipo_ligacao' => 'C'
);
$dadosTotal = array(
$dadosT = array(
'desligada_a' => 'Desligada pelo Cliente: ' . $somaA,
'desligada_b' => 'Desligada pelo Atendente: ' . $somaB,
'totalDes' => $somaQtde,
'duracao' => SecondToStrTime($somaTempo),
'tipo_ligacao' => "Fila: " . $somaF . ' | Ramal:' . $somaR
));
$widthTotal = array(47, 48, 25, 25, 45);
$table2 = array($headerTotal, $dataHdTotal, $dadosTotal, $widthTotal, 0, 0);
$this->___dataRel = array($table1, $table2);
}
protected function ___GetAgentes($selAgente) {
$agentes = array();
foreach ($this->GetData()[0] as $agente) {
array_push($agentes, $agente['apelido']);
}
$fltAgentes = array_unique($agentes);
$sel = !$selAgente ? "selected" : "";
$row = "<select name=\"listaAgente\" id=\"listaAgente\" size=\"1\">";
$row .= "<option value=\"0\" $sel>Todos</option>";
foreach ($fltAgentes as $agts) {
$selected = $agts == $selAgente ? "selected" : '';
$row .= sprintf("<option value=\"%s\" %s>%s</option>", $agts, $selected, $agts);
}
$row .= "</select>";
return $row;
}
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');
}
}
$relDesligamento = new RelDesligamento($idProg, $dbcon, 1);
$relDesligamento->ExecutaRelatorio();
?>