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.
 
 
 
 
 
 

446 lines
18 KiB

<?php
include_once 'util/relatoriosBase.php';
if ($_GET['window']) {
$tpLayout = 1;
}
class RelTransbordo extends Relatorios {
private $___modo;
private $___tipo;
public function __construct($idProg, $dbcon, $incDac) {
parent::__construct($idProg, $dbcon, $incDac);
$this->___dac = isset($_REQUEST['listaDacs']) ? $_REQUEST['listaDacs'] : '';
$this->___tipo = isset($_REQUEST['tipo']) ? $_REQUEST['tipo'] : 'TRANSBORDANDO';
$this->___dataIni = isset($_POST['dataIni']) ? $_POST['dataIni'] : date('d/m/Y');
$this->___dataFim = isset($_POST['dataFim']) ? $_POST['dataFim'] : date('d/m/Y');
$this->___modo = isset($_GET['window']) ? $_GET['window'] : null;
}
function ___FiltrosRelatorio() {
if ($this->___media != MEDIA_PRINT_GRID) {
/*
* Recupera os filtros da sess<EFBFBD>o do usu<EFBFBD>rio.
*/
list($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipo) = $_SESSION["SSstorageFiltros"];
$fltCsv = array();
if ($this->GetIncDac()) {
$fltCsv[] = "Fila:" . $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"><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', '%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, substr(LimpaString(GetDispProgSel($this->GetIdProg())), 0, 20), 'print.gif');
$lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_EXCEL, 'prt-xls.png');
$lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_PDF, 'prt-pdf.png');
$lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_CSV, 'prt-csv.png');
}
/*
* Rotulos.
*/
if ($_GET['window']) {
/*
* Personalise esta fun<EFBFBD><EFBFBD>o se necessitar de outras op<EFBFBD><EFBFBD>es de filtro.
*/
$filtro = '<table border="0" cellspacing="1" cellpadding="2" class="grid">';
$filtro .= '<tr>';
$filtro .= '<th align="center">Dac</th>';
$filtro .= '<th align="center">Data Inicial </th>';
$filtro .= '<th align="center">Data Final </th>';
$filtro .= '<th align="center">&nbsp;</th>';
$filtro .= '</tr>';
/*
* Valores.
*/
$filtro .= '<tr>';
$filtro .= "<td align=\"center\"><h2>{$this->___dac}</h2></th>";
$filtro .= '<td align="center"><h2>%s</h2></td>';
$filtro .= '<td align="center"><h2>%s</h2></td>';
$filtro .= '<td align="center">%s</td>';
$filtro .= '</tr>';
} else {
$filtro = '<table border="0" cellspacing="1" cellpadding="1">';
$filtro .= '<tr>';
if ($this->GetIncDac())
$filtro .= '<td>Fila</td>';
$filtro .= '<td>Data Inicial</td>';
$filtro .= '<td>Data Final </td>';
$filtro .= '<td>Tipo Transbordo </td>';
$filtro .= '<td align="center" valign="middle">&nbsp;</td>';
$filtro .= '</tr>';
/*
* Valores.
*/
$filtro .= '<tr>';
if ($this->GetIncDac()) {
$filtro .= "<td>$dacs</td>";
}
$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> <div class="geral"> ';
$filtro .= sprintf('<input name="tipo" class="clean" type="radio" id="tempoDuracao" value="TRANSBORDADO" %s>Entrada &nbsp;'
. '<input name="tipo" class="clean" type="radio" id="tempoDuracao" value="TRANSBORDANDO" %s>Sa<EFBFBD>da &nbsp;', $this->___tipo == 'TRANSBORDADO' ? 'checked' : '', $this->___tipo == 'TRANSBORDANDO' ? 'checked' : '');
$filtro .= '</div></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<EFBFBD>o dos relat?ios para impress<EFBFBD>o.
*/
$_SESSION["SSstorageFiltros"] = array($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipo);
return sprintf($filtro, $this->___dataIni, $this->___dataFim, $lkPrint);
}
protected function ___GetDadosDb() {
$dataIni = FormatDtMssql($this->___dataIni);
$dataFim = FormatDtMssql($this->___dataFim);
$dac = ($this->___dac == 'TODOS') ? '' : $this->___dac;
$tipo = ($this->___tipo == 'TRANSBORDANDO') ? 'S' : 'E';
$query = "select a.uniqueid, a.calldate, a.billsec as duracao, a.src, a.dst, c.fila, b.evento, c.fila || (case when(c.trbd_tipo = 'S')then ' >> ' else ' << ' end ) || trbd_origem_destino as tipo,
case
when(exists(select '' from pbx_eventos_dacs where fila = c.fila and uid2 = a.uniqueid and evento in('COMPLETEAGENT','COMPLETECALLER','TRANSFER')))then 'ATENDIDA'
when(a.billsec > 0 )then 'ATENDIDA'
else
'ABANDONADA' end as status, trbd_tipo
from pbx_bilhetes a
inner join pbx_eventos_dacs b on a.uniqueid = b.uid2
inner join pbx_eventos_transbordo c on c.uniqueid = a.uniqueid
where c.data_reg::date >= '$dataIni' and c.data_reg::date <= '$dataFim'
and b.evento = 'TRANSBORDANDO' ";
if($tipo){
$query .= " and trbd_tipo = '{$tipo}' ";
}
if ($dac && $_GET['window']) {
$query .= " and c.fila = '{$dac}' ";
} else if($dac){
$query .= " and c.fila = (SELECT nome FROM pbx_queues_grupos WHERE id = '{$dac}') ";
}
$query .= "order by b.evento, a.calldate;";
$result = $this->___GetQuery($query);
$row = pg_fetch_all($result);
$this->SetData($row ? $row : array());
}
protected function ___PreparaCsv() {
$dataRel = array();
$filtro = $this->___FiltrosRelatorio();
/*
* Inicia o relat<EFBFBD>rio.
*/
$dataRel[] = GenerateCsvFromArray($filtro);
$dadosCabecalio = array('Data/Hora', 'Fila', 'Origem', 'Destino', 'Duracao', 'Tipo Transbordo', 'Direcao', 'Status');
$dadosField = array('calldate', 'fila', 'src', 'dst', 'duracao', 'trbd_tipo', 'tipo', 'status');
/*
* Monta a linha de cabecalio.
*/
$dataRel[] = GenerateCsvFromArray($dadosCabecalio);
$somaReg = 0;
$somaDuracao = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$somaReg++;
$somaDuracao += $row['duracao'];
$row['src'] = ocultarTelefone($row['src']);
$row['duracao'] = SecondToStrTime($row['duracao']);
$row['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate']));
$row['trbd_tipo'] = $row['trbd_tipo'] == 'E' ? 'Transbordo Entrada' : 'Transbordo Sa<EFBFBD>da';
// Formata linha de dados.
$linha = array();
foreach ($dadosField as $value) {
$linha[] = $row["$value"];
}
$dataRel[] = GenerateCsvFromArray($linha);
}
$dataRel[] = GenerateCsvFromArray(array('Total Chamadas: ', $somaReg, '', 'Duracao Total: ', SecondToStrTime($somaDuracao)));
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaExcel() {
$dataRel = array();
$filtro = $this->___FiltrosRelatorio();
/*
* Inicia o relat<EFBFBD>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', 'Fila', 'Origem', 'Destino', 'Duracao', 'Tipo Transbordo', 'Direcao', 'Status');
$dadosField = array('calldate', 'fila', 'src', 'dst', 'duracao', 'trbd_tipo', 'tipo', 'status');
/*
* Monta a linha de cabecalio.
*/
$linha = array('LABEL');
foreach ($dadosCabecalio as $value) {
$linha[] = $value;
}
$dataRel[] = $linha;
$somaReg = 0;
$somaDuracao = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$somaReg++;
$somaDuracao += $row['duracao'];
$row['src'] = ocultarTelefone($row['src']);
$row['duracao'] = SecondToStrTime($row['duracao']);
$row['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate']));
$row['trbd_tipo'] = $row['trbd_tipo'] == 'E' ? 'Transbordo Entrada' : 'Transbordo Sa<EFBFBD>da';
// Formata linha de dados.
$linha = array('DADOS');
foreach ($dadosField as $key) {
$linha[] = $row["$key"];
}
$dataRel[] = $linha;
}
$dataRel[] = array('LABEL', 'Total Chamadas: ', $somaReg, '', 'Duracao Total: ', SecondToStrTime($somaDuracao));
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaGrid() {
$dataRel = array();
$dadosCabecalio = array(
'Data/Hora' => 'align="center"',
'Fila' => 'align="center"',
'Origem' => 'align="center"',
'Destino' => 'align="center"',
'Dura<EFBFBD><EFBFBD>o' => 'align="center"',
'Tipo Transbordo' => 'align="center"',
'Dire<EFBFBD><EFBFBD>o' => 'align="center"',
'Status' => 'align="center"'
);
$dadosField = array(
'calldate' => 'align="center"',
'fila' => 'align="center"',
'src' => 'align="center"',
'dst' => 'align="center"',
'duracao' => 'align="center"',
'trbd_tipo' => 'align="center"',
'tipo' => 'align="center"',
'status' => 'align="center"'
);
/*
* Inicia o relat<EFBFBD>rio.
*/
$dataRel[] = '<table width="100%" 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 (!$this->___modo) {
if (!IsPostBack() || !count($this->GetData()[0])) {
$dataRel[] = sprintf("<tr><td align=\"center\" colspan=\"%s\"><b>%s</b></td></tr></table>", count($dadosCabecalio), (!IsPostBack() ? 'Informe os parametros e clique em consultar!' : 'Nenhum registro encontado!'));
$this->___dataRel[] = $dataRel;
return;
}
}
$somaReg = 0;
$somaDuracao = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$somaReg++;
$somaDuracao += $row['duracao'];
$row['src'] = ocultarTelefone($row['src']);
$row['duracao'] = SecondToStrTime($row['duracao']);
$row['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate']));
$row['trbd_tipo'] = $row['trbd_tipo'] == 'E' ? 'Transbordo Entrada' : 'Transbordo Sa<EFBFBD>da';
// 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="4" align="left">Total Chamadas: %s</th><th colspan="4" align="left">Dura<EFBFBD><EFBFBD>o Total: %s</th></tr>';
$dataRel[] = sprintf($linha, $somaReg, SecondToStrTime($somaDuracao));
/*
* 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(
'Data/Hora' => 'C',
'Fila' => 'C',
'Origem' => 'C',
'Destino' => 'C',
'Dura<EFBFBD><EFBFBD>o' => 'C',
'Tipo Transbordo' => 'C',
'Dire<EFBFBD><EFBFBD>o' => 'C',
'Status' => 'C'
);
$dataHeader = array(
'calldate' => 'C',
'fila' => 'C',
'src' => 'C',
'dst' => 'C',
'duracao' => 'C',
'trbd_tipo' => 'C',
'tipo' => 'C',
'status' => 'C',
);
$somaReg = 0;
$dados = $this->GetData()[0];
$somaDuracao = 0;
$x = 0;
foreach ($dados as $row) {
$somaReg++;
$somaDuracao += $row['duracao'];
$dados[$x]['src'] = ocultarTelefone($row['src']);
$dados[$x]['duracao'] = SecondToStrTime($row['duracao']);
$dados[$x]['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate']));
$dados[$x]['evento'] = $row['evento'] == 'E' ? 'Transbordo Entrada' : 'Transbordo Sa<EFBFBD>da';
$x++;
}
$widthHeader = array(25, 25, 21, 21, 15, 25, 43, 20);
$totalizador = array('Total Chamadas: ' . $somaReg, '', '', '', '', 'Dura<EFBFBD><EFBFBD>o Total: ', SecondToStrTime($somaDuracao), '');
//Monta o array para passar para o prepara; Necess<EFBFBD>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<EFBFBD><EFBFBD>o para validar dados do formul<EFBFBD>rio.
*/
$this->___ValidaForm();
/*
* Recupera os dados do banco.
*/
$this->___ConteudoRelatorio();
/*
* Imprime relat<EFBFBD>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<EFBFBD>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');
}
}
$relTransbordo = new RelTransbordo($idProg, $dbcon, 1);
$relTransbordo->ExecutaRelatorio();