forked from SimplesIP/pabx-app
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.
371 lines
15 KiB
371 lines
15 KiB
<?php |
|
include_once 'util/relatoriosBase.php'; |
|
$tpLayout = 1; |
|
|
|
class EntrantesTipoLigacaoCompl extends Relatorios { |
|
|
|
private $___tempoDuracao; |
|
private $___tipoRel; |
|
|
|
public function __construct($idProg, $dbcon, $incDac) { |
|
parent::__construct($idProg, $dbcon, $incDac); |
|
$this->___tempoDuracao = isset($_GET['dur']) ? $_GET['dur'] : 1; |
|
$this->___tipoRel = isset($_GET['tipo']) ? base64_decode($_GET['tipo']) : ''; |
|
$this->___dataIni = isset($_GET['dataIni']) ? $_GET['dataIni'] : date('d/m/Y'); |
|
$this->___dataFim = isset($_GET['dataFim']) ? $_GET['dataFim'] : date('d/m/Y'); |
|
} |
|
|
|
function ___ValidaForm() { |
|
parent::___ValidaForm(); |
|
if (empty($this->___tempoDuracao)) { |
|
GeraExcept('Informe um tempo de duração!'); |
|
} |
|
} |
|
|
|
function ___FiltrosRelatorio() { |
|
if ($this->___media != MEDIA_PRINT_GRID) { |
|
/* |
|
* Recupera os filtros da sess�o do usu�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ção se necessitar de outras opções de filtro. |
|
*/ |
|
$filtro = '<table border="0" cellspacing="1" cellpadding="1" class="grid">'; |
|
/* |
|
* Rotulos. |
|
*/ |
|
$filtro .= '<tr>'; |
|
$filtro .= '<th align="center">Relatório</th>'; |
|
$filtro .= '<th align="center">Impressão</th>'; |
|
$filtro .= '</tr>'; |
|
|
|
/* |
|
* Valores. |
|
*/ |
|
$filtro .= '<tr>'; |
|
$filtro .= '<th style="padding:1px 5px"><h2>%s</h2></th>'; |
|
$filtro .= '<td style="padding:1px 5px">%s</td>'; |
|
$filtro .= '</tr>'; |
|
$filtro .= '</table>'; |
|
|
|
/* |
|
* Guarda os filtros passados para recuperar na emiss�o dos relat?ios para impress�o. |
|
*/ |
|
//$_SESSION["SSstorageFiltros"] = array($this->___dataIni, $this->___dataFim,$this->___tipoRel); |
|
|
|
return sprintf($filtro, $this->___tipoRel, $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); |
|
$duracao = $this->___tempoDuracao; |
|
$tipoRel = $this->___tipoRel; |
|
|
|
$query = sprintf("SELECT a.uniqueid, a.calldate, a.src, a.dst, |
|
CASE WHEN(d.evento = 'ABANDON')THEN strtoint(d.param3) ELSE a.billsec END AS tempo_atendimento, d.evento, |
|
CASE WHEN(tplg_codigo in(23,24))THEN 'MÓVEL' ELSE c.nome_municipio END AS nome_municipio, c.uf, b.tplg_descricao |
|
FROM pbx_bilhetes a |
|
INNER JOIN pbx_tipo_ligacao b ON b.tplg_codigo = a.tipo_chamada |
|
INNER JOIN pbx_municipios c ON c.id = a.id_municipio |
|
LEFT JOIN pbx_eventos_dacs d ON d.uid2 = a.uniqueid AND d.evento IN('COMPLETEAGENT','COMPLETECALLER','ABANDON') |
|
LEFT JOIN pbx_usuarios e ON e.matricula = SUBSTRING(d.agente,7,4) |
|
WHERE b.tplg_tipo = 2 |
|
AND a.calldate::timestamp >= '%s' |
|
AND a.calldate::timestamp <= '%s' |
|
AND a.lastapp <> 'Transferred Call' |
|
AND b.tplg_descricao = '%s'", $dataIni, $dataFim, $tipoRel); |
|
|
|
if ($duracao == 2) { |
|
$query .= " AND a.billsec > 0 "; |
|
} |
|
if ($duracao == 3) { |
|
$query .= " AND a.billsec = 0 "; |
|
} |
|
$query .= " ORDER BY a.calldate"; |
|
// if (IsAdmin()) { echo $query; exit; } |
|
$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( |
|
'UF' => 'align="center"', |
|
'Cidade' => 'align="left"', |
|
'Numero' => 'align="center"', |
|
'Duracao' => 'align="center"', |
|
); |
|
$dadosField = array( |
|
'uf' => 'align="center"', |
|
'nome_municipio' => 'align="left"', |
|
'src' => 'align="center"', |
|
'tempo' => 'align="center"', |
|
); |
|
|
|
$dataRel[] = GenerateCsvFromArray(array_keys($dadosCabecalio)); |
|
|
|
$somaTempo = 0; |
|
$somaQuantidade = 0; |
|
/* |
|
* Linhas de dados. |
|
*/ |
|
foreach ($this->GetData()[0] as $row) { |
|
$row['uf'] = $row['uf']; |
|
$row['nome_municipio'] = RemoveAcentos($row['nome_municipio']); |
|
$row['src'] = ocultarTelefone($row['src']); |
|
$row['tempo'] = SecondToStrTime($row['tempo_atendimento']); |
|
$somaTempo += $row["tempo_atendimento"]; |
|
$row["tempo_atendimento"] = SecondToStrTime($row["tempo_atendimento"]); |
|
$somaQuantidade ++; |
|
|
|
// Formata linha de dados. |
|
$linha = array(); |
|
foreach ($dadosField as $key => $value) { |
|
$linha[] = $row["$key"]; |
|
} |
|
$dataRel[] = GenerateCsvFromArray($linha); |
|
} |
|
|
|
$linha = array('Total:', '','Registros: ' . $somaQuantidade, 'Duracao: ' . SecondToStrTime($somaTempo)); |
|
$dataRel[] = GenerateCsvFromArray($linha); |
|
|
|
$this->___dataRel[] = $dataRel; |
|
} |
|
|
|
protected function ___PreparaExcel() { |
|
$dataRel = array(); |
|
$dataAgrup = 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('UF', 'Cidade', 'Numero', 'Duracao'); |
|
$dadosField = array('uf', 'nome_municipio', 'src', 'tempo'); |
|
|
|
/* |
|
* Monta a linha de cabecalio. |
|
*/ |
|
$linha = array('LABEL'); |
|
foreach ($dadosCabecalio as $value) { |
|
$linha[] = $value; |
|
} |
|
$dataRel[] = $linha; |
|
|
|
$somaTempo = 0; |
|
$somaQuantidade = 0; |
|
/* |
|
* Linhas de dados. |
|
*/ |
|
foreach ($this->GetData()[0] as $row) { |
|
|
|
$row['uf'] = $row['uf']; |
|
$row['nome_municipio'] = RemoveAcentos($row['nome_municipio']); |
|
$row['src'] = ocultarTelefone($row['src']); |
|
$row['tempo'] = SecondToStrTime($row['tempo_atendimento']); |
|
$somaTempo += $row["tempo_atendimento"]; |
|
$row["tempo_atendimento"] = SecondToStrTime($row["tempo_atendimento"]); |
|
$somaQuantidade ++; |
|
|
|
// Formata linha de dados. |
|
$linha = array('DADOS'); |
|
foreach ($dadosField as $key) { |
|
$linha[] = $row["$key"]; |
|
} |
|
$dataRel[] = $linha; |
|
} |
|
|
|
$linha = array('LABEL', 'Total', '', 'Registros: ' . $somaQuantidade, 'Duracao: ' . SecondToStrTime($somaTempo)); |
|
|
|
$dataRel[] = $linha; |
|
|
|
$this->___dataRel[] = $dataRel; |
|
} |
|
|
|
protected function ___PreparaGrid() { |
|
|
|
$dadosCabecalio = array( |
|
'UF' => 'align="center"', |
|
'Cidade' => 'align="left"', |
|
'Número' => 'align="center"', |
|
'Duração' => 'align="center"' |
|
); |
|
/* |
|
* Inicia o relat�rio. |
|
*/ |
|
$dataRel[] = '<table width="100%" cellpadding="2" class="grid">'; |
|
|
|
/* |
|
* Monta a linha de cabecalio. |
|
*/ |
|
$linhaH = '<tr>'; |
|
foreach ($dadosCabecalio as $key => $value) { |
|
$linhaH .= sprintf("<th %s>%s</th>", $value, $key); |
|
} |
|
$linhaH .= "</tr>"; |
|
$dataRel[] = $linhaH; |
|
|
|
$somaTempo = 0; |
|
$somaQuantidade = 0; |
|
/* |
|
* Linhas de dados. |
|
*/ |
|
|
|
foreach ($this->GetData()[0] as $row) { |
|
$somaTempo += $row["tempo_atendimento"]; |
|
$row['src'] = ocultarTelefone($row['src']); |
|
$linha .= "<tr>"; |
|
$linha .= sprintf("<td align=\"center\">%s</td>" |
|
. "<td align=\"left\">%s</td>" |
|
. "<td align=\"center\">%s</td>" |
|
. "<td align=\"center\">%s</td>", $row['uf'], $row['nome_municipio'], $row['src'], SecondToStrTime($row['tempo_atendimento'])); |
|
|
|
$somaQuantidade ++; |
|
$linha .= "</tr>"; |
|
} |
|
|
|
|
|
$dataRel[] = $linha; |
|
/* |
|
* Linha de totalizacao. |
|
*/ |
|
$linha = '<tr><th colspan="2" align="left">Total:</th><th align="right">Registros: %s</th><th align="right">Duração: %s</th></tr>'; |
|
$dataRel[] = sprintf($linha, $somaQuantidade, SecondToStrTime($somaTempo)); |
|
|
|
/* |
|
* Fecha relatorio. |
|
*/ |
|
$dataRel[] = '</table>'; |
|
$this->___dataRel[] = $dataRel; |
|
} |
|
|
|
protected function ___PreparaHtml() { |
|
|
|
} |
|
|
|
protected function ___PreparaPdf() { |
|
list($this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"]; |
|
$somaTempo = 0; |
|
$somaQuantidade = 0; |
|
$x = 1; |
|
$dadosField = array(); |
|
|
|
$header = array( |
|
'UF' => 'C', |
|
'Cidade' => 'L', |
|
'Número' => 'C', |
|
'Duração' => 'C' |
|
); |
|
$dataHeader = array( |
|
'uf' => 'C', |
|
'cidade' => 'L', |
|
'numero' => 'C', |
|
'tempo' => 'C' |
|
); |
|
$widthHeader = array(45, 45, 45, 45); |
|
|
|
foreach ($this->GetData()[0] as $row) { |
|
$somaTempo += $row['tempo_atendimento']; |
|
$dadosField[$x]['uf'] = $row['uf']; |
|
$dadosField[$x]['cidade'] = $row['nome_municipio']; |
|
$dadosField[$x]['numero'] = ocultarTelefone($row['src']); |
|
$dadosField[$x]['tempo'] = SecondToStrTime($row['tempo_atendimento']); |
|
|
|
$somaQuantidade ++; |
|
$x++; |
|
} |
|
|
|
$totaliza = array('Total', '', "Registros: " . $somaQuantidade, "Duração: " . SecondToStrTime($somaTempo)); |
|
$table1 = array($header, $dataHeader, $dadosField, $widthHeader, $totaliza, 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'); |
|
} |
|
|
|
} |
|
|
|
$relChmEntG = new EntrantesTipoLigacaoCompl($idProg, $dbcon, null); |
|
$relChmEntG->ExecutaRelatorio(); |
|
?>
|
|
|