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.
 
 
 
 
 
 

415 lines
16 KiB

<?php
include_once 'util/relatoriosBase.php';
class RelSemRetorno extends Relatorios {
private $___origem;
public function __construct($idProg, $dbcon, $incDac) {
parent::__construct($idProg, $dbcon, $incDac);
$this->___origem = isset($_POST["origem"]) ? $_POST["origem"] : '';
$this->___dataIni = IsPostBack() ? $_POST['dataIni'] : date('d/m/Y') . " 00:00";
$this->___dataFim = IsPostBack() ? $_POST['dataFim'] : date('d/m/Y') . " 23:59";
}
function ___ValidaForm() {
parent::___ValidaForm();
}
function ___FiltrosRelatorio() {
if ($this->___media != MEDIA_PRINT_GRID) {
/*
* Recupera os filtros da sess<EFBFBD>o do usu<EFBFBD>rio.
*/
list($this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"];
if ($this->___media == MEDIA_PRINT_HTML) {
return sprintf("Data Inicial: %s Data Final: %s ", $this->___dataIni, $this->___dataFim);
}
$fltCsv = array();
$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;
}
$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');
}
/*
* Personalise esta fun<EFBFBD><EFBFBD>o se necessitar de outras op<EFBFBD><EFBFBD>es de filtro.
*/
$filtro = '<table class="filtro" border="0" cellspacing="1" cellpadding="1">';
/*
* Rotulos.
*/
$filtro .= '<tr>';
$filtro .= '<td>Data Inicial </td>';
$filtro .= '<td>Data Final </td>';
$filtro .= '<td>Telefone Destino </td>';
$filtro .= '<td>&nbsp</td>';
$filtro .= '<td align="center" valign="middle">&nbsp;</td>';
$filtro .= '<td>Meu Ramal </td>';
$filtro .= '</tr>';
/*
* Valores.
*/
$filtro .= '<tr>';
$filtro .= '<td><input name="dataIni" id="dataIni" type="text" size="25" maxlength="16" value="%s" onkeyup="formataDataHora(this)" title="dd/mm/aaaa HH:mm"></td>';
$filtro .= '<td><input name="dataFim" id="dataFim" type="text" size="25" maxlength="16" value="%s" onkeyup="formataDataHora(this)" title="dd/mm/aaaa HH:mm"></td>';
$filtro .= sprintf('<td><input name="origem" id="origem" type="text" size="15" maxlength="15" value="%s" title="N<EFBFBD>mero de telefone"></td></span></td>', $this->___origem);
$filtro .= '<td><input type="submit" name="btConsulta" id="btConsulta" value="Consultar"></td>';
$filtro .= '<td>%s</td>';
$filtro .= "<td nowrap=\"nowrap\"><div class=\"btGeral\" style=\"width:80px;text-align: center; border-color: #999; border-width: 2px\"><b><span id=\"ramal_monitor\">".GetRamalMonitorar(RAMAL_MONITOR_AGENTE)."</span></b><a href=\"javaScript:RegistraRamalMonitorApl('99','".RAMAL_MONITOR_AGENTE."', '".CANAL_MONITOR_AGENTE."');\"><img src=\"imgSite/chamadas.png\" alt=\"Configurar Ramal\" title=\"Configurar Ramal\" width=\"16\" border=\"0\" style=\"vertical-align: bottom; margin: 1px;\"> </a></div></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->___dataIni, $this->___dataFim);
return sprintf($filtro, $this->___dataIni, $this->___dataFim, $lkPrint);
}
protected function ___GetDadosDb() {
$dataIni = strlen($this->___dataIni) == 10 ? FormatDtMssql($this->___dataIni) . " 00:00" : FormatDtMssql(substr($this->___dataIni, 0, 10)) . substr($this->___dataIni, 10, 16);
$dataFim = strlen($this->___dataFim) == 10 ? FormatDtMssql($this->___dataFim) . " 23:59" : FormatDtMssql(substr($this->___dataFim, 0, 10)) . substr($this->___dataFim, 10, 16);
$origem = $this->___origem;
$query = "SELECT abdsr_numero, ramal, COUNT(abdsr_numero) AS quantidade, SUM(duration) AS tempo_total, MIN(abdsr_data_hora_inicio) AS ultima_chamada
FROM pbx_bilhetes a
INNER JOIN pbx_abandonadas_semretorno b ON a.uniqueid = b.abdsr_uniqueid
INNER JOIN pbx_abandonadas_status c ON b.abdsr_uniqueid = c.uniqueid
WHERE calldate::TIMESTAMP >= '$dataIni' AND calldate::TIMESTAMP <= '$dataFim'
AND disposition = 'NO ANSWER'
AND abdsr_numero <> ''
AND ramal <> '0'
AND abdsr_data_hora_retorno IS NULL";
if ($origem) {
$query .= " AND ramal = '$origem'";
}
$query .= " GROUP BY 1,2 ORDER BY 5 DESC";
$result = $this->___GetQuery($query);
$row = pg_fetch_all($result);
$this->SetData($row ? $row : array());
}
protected function ___PreparaCsv() {
$dataRel = array();
$filtro = $this->___FiltrosRelatorio();
$dataRel[] = GenerateCsvFromArray($filtro);
$dadosCabecalio = array(
'Data/Hora Ultima Chamada',
'Origem',
'Destino',
'Quantidade',
'Tempo total Espera'
);
$dadosField = array(
'ultima_chamada',
'abdsr_numero',
'ramal',
'quantidade',
'tempo_total'
);
$dataRel[] = GenerateCsvFromArray($dadosCabecalio);
$somaEspera = 0;
$somaReg = 0;
$somaQuantidade = 0;
/*
* Inicia o relat<EFBFBD>rio.
*/
foreach ($this->GetData()[0] as $row) {
$somaEspera += $row['tempo_total'];
$somaQuantidade += $row['quantidade'];
$row["ultima_chamada"] = date('d/m/Y H:i', strtotime($row["ultima_chamada"]));
$row["tempo_total"] ? $row["tempo_total"] = SecondToStrTime($row["tempo_total"]) : $row["tempo_total"] = '00:00:00';
$somaReg ++;
$linha = array();
foreach ($dadosField as $key) {
$linha[] = $row["$key"];
}
$dataRel[] = GenerateCsvFromArray($linha);
}
$linha = array('Total: ' . $somaReg, '', '', 'Quantidade: ' . $somaQuantidade, 'Tempo Espera:' . SecondToStrTime($somaEspera));
$dataRel[] = GenerateCsvFromArray($linha);
$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 Ultima Chamada',
'Origem',
'Destino',
'Quantidade',
'Tempo total Espera'
);
$dadosField = array(
'ultima_chamada',
'abdsr_numero',
'ramal',
'quantidade',
'tempo_total'
);
/*
* Monta a linha de cabecalio.
*/
$linha = array('LABEL');
foreach ($dadosCabecalio as $value) {
$linha[] = $value;
}
$dataRel[] = $linha;
$somaEspera = 0;
$somaReg = 0;
$somaQuantidade = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$somaEspera += $row['tempo_total'];
$somaQuantidade += $row['quantidade'];
$row["ultima_chamada"] = date('d/m/Y H:i', strtotime($row["ultima_chamada"]));
$row["tempo_total"] ? $row["tempo_total"] = SecondToStrTime($row["tempo_total"]) : $row["tempo_total"] = '00:00:00';
$somaReg ++;
// Formata linha de dados.
$linha = array('DADOS');
foreach ($dadosField as $key) {
$linha[] = $row["$key"];
}
$dataRel[] = $linha;
}
$linha = array('LABEL', 'Total: ' . $somaReg, '', '', 'Quantidade: ' . $somaQuantidade, 'Tempo Espera:' . SecondToStrTime($somaEspera));
$dataRel[] = $linha;
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaGrid() {
$dadosCabecalio = array(
'Data/Hora <EFBFBD>ltima Chamada' => 'align="center"',
'Origem' => 'align="left"',
'Destino' => 'align="left"',
'Quantidade' => 'align="left"',
'Tempo total Espera' => 'align="center"',
'Retornar' => 'align="center"'
);
$dadosField = array(
'ultima_chamada' => 'align="center"',
'abdsr_numero' => 'align="left"',
'ramal' => 'align="left"',
'quantidade' => 'align="left"',
'tempo_total' => 'align="center"',
'retornar' => 'align="center"'
);
/*
* Inicia o relatorio
*/
$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), (!IsPostBack() ? 'Informe os parametros e clique em consultar!' : 'Nenhum registro encontado!'));
$this->___dataRel[] = $dataRel;
return;
}
$somaEspera = 0;
$somaReg = 0;
$somaQuantidade = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$img = "<img src=\"imgSite/ramalOn16.png\" border=\"0\" width=\"20\" alt=\"Retornar Chamada Perdida\" title=\"Retornar para [ {$row['abdsr_numero']} ]\">";
$somaEspera += $row['tempo_total'];
$somaQuantidade += $row['quantidade'];
$row['abdsr_numero'] = ocultarTelefone($row['abdsr_numero']);
$row['ramal'] = ocultarTelefone($row['ramal']);
$row["ultima_chamada"] = date('d/m/Y H:i', strtotime($row["ultima_chamada"]));
$row["tempo_total"] ? $row["tempo_total"] = SecondToStrTime($row["tempo_total"]) : $row["tempo_total"] = '00:00:00';
$row['retornar'] = sprintf("<a href=\"javaScript:RetornaAbd('%s');\">$img</a>", Encrypt($row['abdsr_numero']));
$somaReg ++;
// 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: %s</th><th align="left">Quantidade: %s</th><th>Total Espera: %s</th><th></th></tr>';
$dataRel[] = sprintf($linha, $somaReg, $somaQuantidade, SecondToStrTime($somaEspera));
/*
* Fecha relatorio.
*/
$dataRel[] = '</table>';
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaHtml() {
}
protected function ___PreparaPdf() {
list($this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"];
$dadosCabecalio = array(
'Data/Hora <EFBFBD>ltima Chamada' => 'C',
'Origem' => 'C',
'Destino' => 'C',
'Quantidade' => 'C',
'Tempo total Espera' => 'C'
);
$dadosField = array(
'ultima_chamada' => 'C',
'abdsr_numero' => 'C',
'ramal' => 'C',
'quantidade' => 'C',
'tempo_total' => 'C'
);
$dados = $this->GetData()[0];
$somaEspera = 0;
$somaReg = 0;
$somaQuantidade = 0;
foreach ($dados as $row) {
$somaEspera += $row['tempo_total'];
$somaQuantidade += $row['quantidade'];
$dados[$somaReg]["ultima_chamada"] = date('d/m/Y H:i:s', strtotime($row["ultima_chamada"]));
$dados[$somaReg]["tempo_total"] = $row["tempo_total"] ? SecondToStrTime($row["tempo_total"]) : '00:00:00';
$somaReg ++;
}
$widthHeader = array(50, 30, 35, 35, 40);
$totaliza = array('Total: ' . $somaReg, '', '', 'Quantidade: ' . $somaQuantidade, 'Total Espera: ' . SecondToStrTime($somaEspera));
//Monta o array para passar para o prepara; Necess<EFBFBD>rio passar 6 parametros
$table1 = array($dadosCabecalio, $dadosField, $dados, $widthHeader, $totaliza, 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');
}
}
$relSemRetorno = new RelSemRetorno($idProg, $dbcon, 0);
$relSemRetorno->ExecutaRelatorio();