___ramal = isset($_POST["ramal"]) ? $_POST["ramal"] : ''; $this->___agente = isset($_POST["listaAgente"]) ? $_POST["listaAgente"] : ''; $this->___status = isset($_POST["lstStatus"]) ? $_POST["lstStatus"] : ''; } function ___FiltrosRelatorio() { $agente = $this->___GetAgente(); if ($this->___media != MEDIA_PRINT_GRID) { /* * Recupera os filtros da sessão do usuá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ítico' : 'Sinté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 = 'Clique aqui para imprimir!'; $prtHtml = "\"Clique"; $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ção se necessitar de outras opnioes de filtro. */ $filtro = ''; /* * Rotulos. */ $filtro .= ''; if ($this->GetIncDac()) $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; /* * Valores. */ $filtro .= ''; if ($this->GetIncDac()) $filtro .= sprintf('', $dacs); $filtro .= ''; $filtro .= ''; $filtro .= sprintf('', $this->___ramal); $filtro .= sprintf('', $agente); $filtro .= sprintf('', $this->___GetStatus($this->___status)); $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= '
FilaData InicialData Final RamalAgenteStatus 
%s%s%s%s
'; /* * Guarda os filtros passados para recuperar na emiss�o dos relat�ios para impress�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 = FormatDtMssql($this->___dataFim); $dac = $this->___dac; $dataCorte = GetDataRelatorio(); $ramal = $this->___ramal; $agente = $this->___agente; $status = $this->___status; $query = "SELECT transferencia.fila, calldate, transferencia.src, transferencia.dst, apelido, billsec, duration, status from( select d.fila, a.calldate, a.src, case when(d.evento in('COMPLETECALLER','COMPLETEAGENT')) then(select q.destino from pbx_bilhetes_complemento q where q.uniqueid2 = a.uniqueid and q.direcao = 'fila-ramal' limit 1) else(select q.destino from pbx_bilhetes_complemento q where q.uniqueid2 = a.uniqueid order by data_registro limit 1) end as dst, c.apelido, a.billsec, a.duration, case when(a.disposition = 'ANSWERED')then 'ATENDIDA' else 'ABANDONADA' end as status from pbx_bilhetes a,pbx_usuarios c, pbx_eventos_dacs d, pbx_dacs e where c.matricula = substring(d.agente, 7, 4) and d.uid2 = a.uniqueid and e.nome = d.fila and d.evento in('COMPLETEAGENT','COMPLETECALLER','COMPLETAAGENT','COMPLETACALLER') and a.lastapp <> 'Transferred Call' and a.data_bilhete >= '$dataIni' and a.data_bilhete <= '$dataFim' and exists(select '' from pbx_bilhetes where data_bilhete = a.data_bilhete and accountcode = a.uniqueid) "; $dataIni ? $query .= " and a.calldate::date >= '$dataIni' " : ''; $dataFim ? $query .= " and a.calldate::date <= '$dataFim' " : ''; $ramal ? $query .= " and a.dst = '$ramal' " : ''; $agente ? $query .= " and c.matricula = '$agente' " : ''; $status ? $query .= " and a.disposition = '$status' " : ''; $dac ? $query .= " and e.id = '$dac' " : ''; $query .= " UNION ALL SELECT d.fila, a.calldate, a.src, (select q.destino from pbx_bilhetes_complemento q where q.uniqueid2 = a.uniqueid order by data_registro desc limit 1)as dst, c.apelido, d.param4::bigint as billsec, a.duration, case when(a.disposition = 'ANSWERED' or d.param4 > '0')then 'ATENDIDA' else 'ABANDONADA' end as status from pbx_bilhetes a,pbx_usuarios c, pbx_eventos_dacs d, pbx_dacs e where c.matricula = substring(d.agente, 7, 4) and d.uid2 = a.uniqueid and e.nome = d.fila and d.param4 <> '' and d.evento in('TRANSFER','TRANSFERORIG') and a.lastapp <> 'Transferred Call' and a.data_bilhete >= '$dataIni' and a.data_bilhete <= '$dataFim' "; $dataIni ? $query .= " and a.calldate::date >= '$dataIni' " : ''; $dataFim ? $query .= " and a.calldate::date <= '$dataFim' " : ''; $ramal ? $query .= " and a.dst = '$ramal' " : ''; $agente ? $query .= " and c.matricula = '$agente' " : ''; $status ? $query .= " and a.disposition = '$status' " : ''; $dac ? $query .= " and e.id = '$dac' " : ''; $query .= ")as transferencia group by transferencia.fila, calldate, transferencia.src, transferencia.dst, apelido, billsec, duration, status order by 2"; $result = $this->___GetQuery($query); $row = pg_fetch_all($result); $this->SetData($row ? $row : array()); } protected function ___PreparaCsv() { $dataRel = array(); $chmTotal = array(); $filtro = $this->___FiltrosRelatorio(); $dataRel[] = GenerateCsvFromArray($filtro); $dadosCabecalio = array('Ramal', 'Origem', 'Data/Hora', 'Tempo', 'Status'); $dadosField = array('dst', 'src', 'calldate', 'billsec', 'status'); $dataRel[] = GenerateCsvFromArray($dadosCabecalio); $somaReg = 0; $somaChm = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $somaReg++; $row['status'] == 'ATENDIDA' ? $somaChm++ : ''; $row['dst'] = ocultarTelefone($row['dst']); $row['src'] = ocultarTelefone($row['src']); $row['billsec'] = SecondToStrTime($row['billsec']); $row['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate'])); $chmTotal[$row['dst']] += 1; $linha = array(); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = GenerateCsvFromArray($linha); } $dataRel[] = GenerateCsvFromArray(array('Total Atendidadas:', '', '', '', $somaChm)); $dataRel[] = GenerateCsvFromArray(array('Total Chamadas:', '', '', '', $somaReg)); $dataRel[] = GenerateCsvFromArray(array('')); $dataRel[] = GenerateCsvFromArray(array('Ramal', 'Quantidade')); foreach ($chmTotal as $k => $v) { $dataRel[] = GenerateCsvFromArray(array($k, $v)); } $this->___dataRel[] = $dataRel; } protected function ___PreparaExcel() { $dataRel = array(); $chmTotal = 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('Ramal', 'Origem', 'Data/Hora', 'Tempo', 'Status'); $dadosField = array('dst', 'src', 'calldate', 'billsec', 'status'); $linha = array('LABEL'); foreach ($dadosCabecalio as $value) { $linha[] = $value; } $dataRel[] = $linha; $somaReg = 0; $somaChm = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $somaReg++; $row['status'] == 'ATENDIDA' ? $somaChm++ : ''; $row['dst'] = ocultarTelefone($row['dst']); $row['src'] = ocultarTelefone($row['src']); $row['billsec'] = SecondToStrTime($row['billsec']); $row['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate'])); $chmTotal[$row['dst']] += 1; $linha = array('DADOS'); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = $linha; } $dataRel[] = array('LABEL', 'Chamadas Atendidas: ', '', '', '', $somaChm); $dataRel[] = array('LABEL', 'Total Chamadas: ', '', '', '', $somaReg); $dataRel[] = array('LABEL', ''); $dataRel[] = array('LABEL', 'Ramal ', 'Quantidade'); foreach ($chmTotal as $k => $v) { $dataRel[] = array('DADOS', $k, $v); } $this->___dataRel[] = $dataRel; } protected function ___PreparaGrid() { $dataRel = array(); $chmTotal = array(); $dadosCabecalio = array( 'Ramal' => 'align="center"', 'Origem' => 'align="center"', 'Data/Hora' => 'align="center"', 'Tempo' => 'align="center"', 'Status' => 'align="center"' ); $dadosField = array( 'dst' => 'align="center"', 'src' => 'align="center"', 'calldate' => 'align="center"', 'billsec' => 'align="center"', 'status' => 'align="center"' ); /* * Inicia o relat�rio. */ $dataRel[] = ''; /* * Monta a linha de cabecalio. */ $linha = ''; $linha .= ""; $linha .= ""; $dataRel[] = $linha; /* * Verifica se retornou dados */ if (!IsPostBack() || !count($this->GetData()[0])) { $dataRel[] = sprintf("
Transferência de chamada
%s
", count($dadosCabecalio) - 1, (!IsPostBack() ? 'Informe os parametros e clique em consultar!' : 'Nenhum registro encontado!')); $this->___dataRel[] = $dataRel; return; } $linhaC = ""; foreach ($dadosCabecalio as $key => $value) { $linhaC .= sprintf("%s", $value, $key); } $linhaC .= ""; $dataRel[] = $linhaC; $somaReg = 0; $somaChm = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $somaReg++; $row['status'] == 'ATENDIDA' ? $somaChm++ : ''; $row['dst'] = ocultarTelefone($row['dst']); $row['src'] = ocultarTelefone($row['src']); $row['billsec'] = SecondToStrTime($row['billsec']); $row['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate'])); $chmTotal[$row['dst']] += 1; $linha = ""; foreach ($dadosField as $key => $value) { $linha .= sprintf("%s", $value, $row["$key"]); } $linha .= ""; $dataRel[] = $linha; } $dataRel[] = "Chamadas Atendidas: $somaChm"; $dataRel[] = "Total de chamadas: $somaReg"; $dataRel[] = "
"; $tabletotal = ""; $tabletotal .= ""; foreach ($chmTotal as $chave => $valores) { $tabletotal .= ""; } $tabletotal .= "
Resumo de chamadas:
RamalQuantidade
$chave $valores
"; $dataRel[] = $tabletotal; $this->___dataRel[] = $dataRel; } protected function ___PreparaHtml() { } protected function ___PreparaPdf() { list($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio) = $_SESSION["SSstorageFiltros"]; $chmTotal = array(); $dadosCabecalio = array( 'Ramal' => 'C', 'Origem' => 'C', 'Data/Hora' => 'C', 'Tempo' => 'C', 'Status' => 'C' ); $dadosField = array( 'dst' => 'C', 'src' => 'C', 'calldate' => 'C', 'billsec' => 'C', 'status' => 'C' ); $somaChm = 0; $x = 0; $dados = $this->GetData()[0]; $chave = ''; /* * Linhas de dados. */ foreach ($dados as $row) { $dados[$x]['status'] == 'ATENDIDA' ? $somaChm++ : ''; $dados[$x]['dst'] = ocultarTelefone($row['dst']); $dados[$x]['src'] = ocultarTelefone($row['src']); $dados[$x]['billsec'] = SecondToStrTime($row['billsec']); $dados[$x]['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate'])); foreach ($chmTotal as $key => $v) { if ($v['ramal'] == $row['dst']) { $chave = $key; break; } } $x++; if ($chave) { $chmTotal[$chave]['quantidade']++; $chave = ''; } else { $chmTotal[$x]['ramal'] = $row['dst']; $chmTotal[$x]['quantidade'] = 1; } } $widthHeader = array(38, 38, 38, 38, 38); $totaliza = array("Total Chamadas: $x", '', '', '', "Total Atendidas: $somaChm"); $table = array($dadosCabecalio, $dadosField, $dados, $widthHeader, $totaliza, 0); $table1 = array(array('Ramal' => 'C', 'Quantidade' => 'C'), array('ramal' => 'C', 'quantidade' => 'C'), $chmTotal, array(38, 38), 0, 1); $this->___dataRel = array($table, $table1); } protected function ___GetAgente() { global $dbcon; $query = sprintf("SELECT DISTINCT c.matricula, c.apelido as nome FROM pbx_bilhetes a, pbx_eventos_dacs b, pbx_usuarios c WHERE b.uid2 = a.uniqueid AND c.matricula = substring(b.agente, 7, 4) AND a.calldate::date >= '%s' AND a.calldate::date <= '%s' AND b.fila = case when(%s = 0)then b.fila else (select nome from pbx_dacs where id = %s) end ORDER BY 2", FormatDtMssql($this->___dataIni), FormatDtMssql($this->___dataFim), $this->___dac, $this->___dac); $resp = pg_query($dbcon, $query); if (!$resp) { return ""; } $result = pg_fetch_all($resp); $row = ""; return $row; } protected function ___GetStatus($st) { $status = ""; return $status; } 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'); } } $relTransfer = new RelTransfer($idProg, $dbcon, 1); $relTransfer->ExecutaRelatorio();