<?php
include_once 'util/relatoriosBase.php';
class RelRechamadas extends Relatorios {
private $___origem;
private $___servico;
public function __construct($idProg, $dbcon, $incDac) {
parent::__construct($idProg, $dbcon, $incDac);
$this->___dac = isset($_POST['listaDacs']) ? $_POST['listaDacs'] : 0;
$this->___origem = isset($_POST["origem"]) ? $_POST["origem"] : '';
$this->___servico = isset($_POST["listaServico"]) ? $_POST["listaServico"] : 0;
}
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->___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<EFBFBD> tico' : 'Sint<EFBFBD> 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"';
/*
* Personalise esta fun<EFBFBD> <EFBFBD> o se necessitar de outras op<EFBFBD> <EFBFBD> es de filtro.
*/
$filtro = '< table border = "0" cellspacing = "1" cellpadding = "1" > ';
/*
* Rotulos.
*/
$filtro .= '< tr > ';
if ($this->GetIncDac()) {
$filtro .= '< td > Fila< / td > ';
}
if (GetUsoServico()) {
$filtro .= '< td > Servi<EFBFBD> o< / td > ';
}
$filtro .= '< td > Data Inicial< / td > ';
$filtro .= '< td > Data Final < / td > ';
$filtro .= '< td > Origem< / td > ';
$filtro .= '< td align = "center" valign = "middle" > < / td > ';
$filtro .= '< / tr > ';
/*
* Valores.
*/
$filtro .= '< tr > ';
if ($this->GetIncDac()) {
$filtro .= 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 .= sprintf('< td > < input name = "origem" id = "origem" type = "text" size = "15" value = "%s" / > < / td > ', $this->___origem);
$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<EFBFBD> ios para impress<EFBFBD> o.
*/
$_SESSION["SSstorageFiltros"] = array($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio, $this->___agente);
return sprintf($filtro, $this->___dataIni, $this->___dataFim, $lkPrint);
}
protected function ___GetDadosDb() {
$dataIni = FormatDtMssql($this->___dataIni);
$dataFim = FormatDtHoraBD($this->___dataFim);
$dac = $this->___dac;
$srv = $this->___servico;
$origem = soNumero($this->___origem);
$mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA;
$query = "SELECT fila, origem ,COUNT(qtde) AS qtde ,SUM (tempo_atende) AS tempo_atende ,SUM (tempo_transf) AS tempo_transf";
if ($mostraColunaServicos) {
$query .= "\n ,serv_id";
}
$query .= "\nFROM (
select b.fila, case when(coalesce(a.src, '') = '')then 'NI*' else a.src end as origem, a.uniqueid as qtde,
(case when(b.evento in('COMPLETEAGENT','COMPLETECALLER', 'COMPLETAAGENT','COMPLETACALLER'))then strtoint(param2) else 0 end) as tempo_atende,
(case when(exists(select * from pbx_bilhetes where data_bilhete = a.data_bilhete and accountcode = a.uniqueid ))then a.billsec else 0 end) as tempo_transf";
if ($mostraColunaServicos) {
$query .= "\n ,coalesce(serv_id, 'SERV. N<EFBFBD> O ASSOCIADO') as serv_id";
}
$query .= "\n from pbx_bilhetes a
inner join pbx_eventos_dacs b on b.uid2 = a.uniqueid ";
if (GetUsoServico()) {
$query .= "\nleft join pbx_servicos_registra c on c.uniqueid = a.uniqueid";
}
$query .= "\nwhere a.id_bilhetes = (select max (l.id_bilhetes) from pbx_bilhetes l where l.uniqueid = a.uniqueid and l.lastapp < > 'Transferred Call' )
and b.evento in('COMPLETEAGENT','COMPLETECALLER', 'COMPLETAAGENT','COMPLETACALLER', 'TRANSFER', 'TRANSFERORIG')\n";
if (GetUsoServico() & & $srv) {
$query .= "\nand c.serv_id = '{$srv}'";
}
$query .= "\nand a.lastapp < > 'Transferred Call'
and a.data_bilhete >= '$dataIni'
and a.data_bilhete < = '$dataFim'
and b.fila = (select nome from pbx_dacs where id = '$dac')\n";
if ($origem) {
$query .= "\nand a.src like '%$origem%' \n";
}
if ($mostraColunaServicos) {
$query .= " ) AS RECHAMADAS GROUP BY fila, serv_id, origem having count(*) > 1 ORDER BY serv_id, qtde desc";
} else {
$query .= " ) AS RECHAMADAS GROUP BY fila, origem having count(*) > 1 ORDER BY qtde 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);
$mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA;
$dadosCabecalio = array('Origem', 'Quantidade', 'TMA', 'Tempo');
$dadosField = array('origem', 'qtde', 'tma', 'tempo_atende');
if ($mostraColunaServicos) {
$dadosCabecalio = array_merge(['Servico'], $dadosCabecalio);
$dadosField = array_merge(['serv_id'], $dadosField);
}
$dataRel[] = GenerateCsvFromArray($dadosCabecalio);
foreach ($this->GetData()[0] as $row) {
$row['tma'] = SecondToStrTime(round($row['tempo_atende'] / $row['qtde']));
$row['tempo_atende'] = SecondToStrTime($row['tempo_atende']);
$linha = array();
foreach ($dadosField as $key) {
$linha[] = $row["$key"];
}
$dataRel[] = GenerateCsvFromArray($linha);
}
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaExcel() {
$dataRel = array();
$filtro = $this->___FiltrosRelatorio();
$mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA;
/*
* 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('Origem', 'Quantidade', 'TMA', 'Tempo');
$dadosField = array('origem', 'qtde', 'tma', 'tempo_atende');
if ($mostraColunaServicos) {
$dadosCabecalio = array_merge(['Servico'], $dadosCabecalio);
$dadosField = array_merge(['serv_id'], $dadosField);
}
$linha = array('LABEL');
foreach ($dadosCabecalio as $value) {
$linha[] = $value;
}
$dataRel[] = $linha;
foreach ($this->GetData()[0] as $row) {
$row['tma'] = SecondToStrTime(round($row['tempo_atende'] / $row['qtde']));
$row['tempo_atende'] = SecondToStrTime($row['tempo_atende']);
$linha = array('DADOS');
foreach ($dadosField as $key) {
$linha[] = $row["$key"];
}
$dataRel[] = $linha;
}
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaGrid() {
$dataRel = array();
$mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA;
$dadosCabecalio = array(
'Origem' => 'align="center"',
'Quantidade' => 'align="center"',
'TMA' => 'align="center"',
'Tempo' => 'align="center"'
);
$dadosField = array(
'origem' => 'align="center"',
'qtde' => 'align="center"',
'tma' => 'align="center"',
'tempo_atende' => 'align="center"'
);
if ($mostraColunaServicos) {
$dadosCabecalio = array_merge(['Servi<EFBFBD> o' => 'align="center"'], $dadosCabecalio);
$dadosField = array_merge(['serv_id' => 'align="left"'], $dadosField);
}
/*
* Inicia o relat<EFBFBD> rio.
*/
$dataRel[] = '< table width = "70%" cellpadding = "2" class = "grid" > ';
/*
* Monta a linha de cabecalio.
*/
$linha = '< tr > ';
$linha .= "< th align = \"center\" colspan = \"5\" > Rechamadas< / th > ";
$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(1) - 1, (!IsPostBack() ? 'Informe os parametros e clique em consultar!' : 'Nenhum registro encontado!'));
$this->___dataRel[] = $dataRel;
return;
}
$linhaC = "< tr > ";
foreach ($dadosCabecalio as $key => $value) {
$linhaC .= sprintf("< th % s > %s< / th > ", $value, $key);
}
$linhaC .= "< / tr > ";
$dataRel[] = $linhaC;
$somaRechamada = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$row['origem'] = ocultarTelefone($row['origem']);
$row['tma'] = SecondToStrTime(round($row['tempo_atende'] / $row['qtde']));
$row['tempo_atende'] = SecondToStrTime($row['tempo_atende']);
$linha = "< tr > ";
foreach ($dadosField as $key => $value) {
$linha .= sprintf("< td % s > %s< / td > ", $value, $row["$key"]);
}
$linha .= "< / tr > ";
$dataRel[] = $linha;
}
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaHtml() {
}
protected function ___PreparaPdf() {
list($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio) = $_SESSION["SSstorageFiltros"];
$mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA;
$dadosCabecalio = array(
'Origem' => 'C',
'Quantidade' => 'C',
'TMA' => 'C',
'Tempo' => 'C'
);
$dadosField = array(
'origem' => 'C',
'qtde' => 'C',
'tma' => 'C',
'tempo_atende' => 'C'
);
if ($mostraColunaServicos) {
$dadosCabecalio = array_merge(['Servi<EFBFBD> o' => 'C'], $dadosCabecalio);
$dadosField = array_merge(['serv_id' => 'C'], $dadosField);
}
$x = 0;
$dados = $this->GetData()[0];
/*
* Linhas de dados.
*/
foreach ($dados as $row) {
$dados[$x]['tma'] = SecondToStrTime(round($row['tempo_atende'] / $row['qtde']));
$dados[$x]['tempo_atende'] = SecondToStrTime($row['tempo_atende']);
$x++;
}
if ($mostraColunaServicos) {
$widthHeader = array(40, 45, 25, 35, 35);
} else {
$widthHeader = array(45, 45, 45, 45);
}
$table = array($dadosCabecalio, $dadosField, $dados, $widthHeader, 0, 0);
$this->___dataRel = array($table);
}
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');
}
}
$relRechamadas = new RelRechamadas($idProg, $dbcon, 1);
$relRechamadas->ExecutaRelatorio();
?>