___dac = isset($_POST['listaDacs']) ? $_POST['listaDacs'] : 0; $this->___tempoAtendimento = isset($_POST['tempoAtendimento']) ? $_POST['tempoAtendimento'] : ''; $this->___agente = isset($_POST["listaAgente"]) ? $_POST["listaAgente"] : 0; $this->___servico = isset($_POST["listaServico"]) ? $_POST["listaServico"] : 0; } public function ___ValidaForm() { parent::___ValidaForm(); if (!IsPostBack()) { return; } if ($this->___agente < 0) { GeraExcept('Informe um agente!'); } if ($this->___tempoAtendimento && $this->___tempoAtendimento < 10) { GeraExcept('Por favor, informe a duração maior que 10 segundos!'); } } 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 op��es de filtro. */ $filtro = ''; /* * Rotulos. */ $filtro .= ''; if ($this->GetIncDac()) $filtro .= ''; $filtro .= ''; $filtro .= ''; if (GetUsoServico()) { $filtro .= ''; } $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; /* * Valores. */ $filtro .= ''; if ($this->GetIncDac()) $filtro .= sprintf('', $dacs); $filtro .= ''; $filtro .= ''; if (GetUsoServico()) { $filtro .= sprintf('', GetIdentRota(false, $this->___servico)); } $filtro .= sprintf('', $agente); $filtro .= ""; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= '
FilaData InicialData Final Serviço AgenteDuração (Segundos) 
%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 = FormatDtHoraBD($this->___dataFim); $srv = $this->___servico; $agente = $this->___agente; $dac = $this->___dac; $mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA; $query1 = "SELECT a.calldate AS data, a.src AS origem, CASE WHEN(b.evento IN('COMPLETECALLER', 'COMPLETEAGENT', 'COMPLETEAGENTRAMAL', 'COMPLETECALLERRAMAL'))THEN strtoint(b.param2) ELSE CASE WHEN(b.evento = 'TRANSFER')THEN strtoint(b.param4) ELSE 0 END END AS tmo, c.apelido AS agente, CASE WHEN(b.evento IN('BUSY','NOANSWER'))THEN 0 ELSE 1 END AS status,'' AS desligado, b.fila" . ($mostraColunaServicos ? ", s.serv_id" : ""); $query2 = "SELECT DISTINCT c.matricula, c.apelido"; $query = " FROM pbx_bilhetes a inner join pbx_eventos_dacs b on b.uid2 = a.uniqueid inner join pbx_usuarios c on c.matricula = SUBSTRING(b.agente,7 ,4)"; if (GetUsoServico()) { $query .= " left join pbx_servicos_registra s on s.uniqueid = a.uniqueid"; } $query .= " WHERE a.data_bilhete >= '$dataIni' AND a.data_bilhete <= '$dataFim' AND a.lastapp <> 'Transferred Call' AND b.evento IN('COMPLETEAGENT','COMPLETECALLER', 'TRANSFER','COMPLETEAGENTRAMAL','COMPLETECALLERRAMAL','BUSY','NOANSWER') AND b.fila = (SELECT nome FROM pbx_dacs WHERE id = '$dac') "; if ($agente) { $addAgente = "\nAND c.matricula = '$agente'"; } if (GetUsoServico() && $srv) { $query .= "\nAND s.serv_id = '{$srv}'"; } $sqlTempo = $this->___tempoAtendimento && $this->___tempoAtendimento > 10 ? "\nAND strtoint(b.param2) >= " . $this->___tempoAtendimento : ''; $query1 = ($query1 . $query . $addAgente . $sqlTempo . sprintf("\nORDER BY %s ", $mostraColunaServicos ? 's.serv_id, a.calldate' : 'a.calldate')); $result = $this->___GetQuery($query1); $row = pg_fetch_all($result); $this->SetData($row ? $row : array()); $result2 = $this->___GetQuery($query2 . $query . " ORDER BY 2 "); $row2 = pg_fetch_all($result2); $this->SetData($row2 ? $row2 : array()); } protected function ___PreparaCsv() { $dataRel = array(); $filtro = $this->___FiltrosRelatorio(); $dataRel[] = GenerateCsvFromArray($filtro); $mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA; $dadosCabecalio = array( 'Data', 'Hora', 'Origem', 'Tempo', 'Agente', 'Status' ); $dadosField = array( 'data', 'hora', 'origem', 'tmo', 'agente', 'status' ); if ($mostraColunaServicos) { $dadosCabecalio = array_merge(['Servico'], $dadosCabecalio); $dadosField = array_merge(['serv_id'], $dadosField); } $dataRel[] = GenerateCsvFromArray($dadosCabecalio); $somaReg = 0; $somaDuracao = 0; $somaAtendida = 0; $somaNAtendida = 0; foreach ($this->GetData()[0] as $row) { $somaReg ++; $somaDuracao += $row['tmo']; $row['status'] == 1 ? $somaAtendida++ : $somaNAtendida++; $row['hora'] = date('H:i:s', strtotime($row['data'])); $row['data'] = date('d/m/Y', strtotime($row['data'])); $row['tmo'] = SecondToStrTime($row['tmo']); $row['status'] = $row['status'] == 1 ? "Atendida" : "Não Atendida"; $linha = array(); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = GenerateCsvFromArray($linha); } $dataRel[] = GenerateCsvFromArray(array('DURAÇÃO', SecondToStrTime($somaDuracao), '')); $dataRel[] = GenerateCsvFromArray(array('')); $dataRel[] = GenerateCsvFromArray(array('Atendida', 'Nao Atendida', 'Geral')); $dataRel[] = GenerateCsvFromArray(array($somaAtendida, $somaNAtendida, $somaReg)); $this->___dataRel[] = $dataRel; } protected function ___PreparaExcel() { $dataRel = array(); $filtro = $this->___FiltrosRelatorio(); $mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA; /* * 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( 'Data', 'Hora', 'Origem', 'Tempo', 'Agente', 'Status' ); $dadosField = array( 'data', 'hora', 'origem', 'tmo', 'agente', 'status' ); if ($mostraColunaServicos) { $dadosCabecalio = array_merge(['Servico'], $dadosCabecalio); $dadosField = array_merge(['serv_id'], $dadosField); } $linha = array('LABEL'); foreach ($dadosCabecalio as $value) { $linha[] = $value; } $dataRel[] = $linha; $somaReg = 0; $somaDuracao = 0; $somaAtendida = 0; $somaNAtendida = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $somaReg ++; $somaDuracao += $row['tmo']; $row['status'] == 1 ? $somaAtendida++ : $somaNAtendida++; $row['hora'] = date('H:i:s', strtotime($row['data'])); $row['data'] = date('d/m/Y', strtotime($row['data'])); $row['tmo'] = SecondToStrTime($row['tmo']); $row['status'] = $row['status'] == 1 ? "Atendida" : "Não Atendida"; $linha = array('DADOS'); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = $linha; } $dataRel[] = array('LABEL', 'DURAÇÃO', SecondToStrTime($somaDuracao), ''); $dataRel[] = array('DADOS', ''); $dataRel[] = array('LABEL', 'Atendida', 'Nao Atendida', 'Geral'); $dataRel[] = array('DADOS', $somaAtendida, $somaNAtendida, $somaReg); $this->___dataRel[] = $dataRel; } protected function ___PreparaGrid() { $dataRel = array(); $mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA; $dadosCabecalio = array( 'Data' => 'align="center"', 'Hora' => 'align="center"', 'Origem' => 'align="center"', 'DURAÇÃO' => 'align="center"', 'Agente' => 'align="center"', 'Status' => 'align="center"' ); $dadosField = array( 'data' => 'align="center"', 'hora' => 'align="center"', 'origem' => 'align="center"', 'tmo' => 'align="center"', 'agente' => 'align="center"', 'status' => 'align="center"' ); if ($mostraColunaServicos) { $dadosCabecalio = array_merge(['Serviço' => 'align="center"'], $dadosCabecalio); $dadosField = array_merge(['serv_id' => 'align="left"'], $dadosField); } /* * Inicia o relatório. */ $dataRel[] = ''; /* * Monta a linha de cabecalio. */ $linha = ''; $linha .= sprintf("", ($mostraColunaServicos ? '7' : '6')); $linha .= ""; $dataRel[] = $linha; /* * Verifica se retornou dados */ if (!IsPostBack() || !count($this->GetData()[0])) { $dataRel[] = sprintf("
Chamadas Recebidas por Agente
%s
", count(1) - 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; $somaDuracao = 0; $somaAtendida = 0; $somaAtendidaServico = 0; $somaNAtendida = 0; $somaNAtendidaServico = 0; $somaDuracaoServico = 0; $srv = ""; $oldSrv = ""; $tmo = 0; $agrupaServico = function($row) use(&$somaDuracaoServico, &$somaAtendidaServico, &$somaNAtendidaServico, &$dataRel, &$srv, &$oldSrv) { $style = 'style="font-weight: bold; padding: 0; margin: 0; padding-left: 6px; padding-right: 6px; background-color: #4F71C0 !important"'; $srv = $row["serv_id"]; if (!$oldSrv) { $oldSrv = $srv; } if ((($srv != $oldSrv)) || !$row) { $dataRel[] = sprintf("Total [%s] DURAÇÃO%sATENDIDAS / NA%s / %s", $oldSrv, SecondToStrTime($somaDuracaoServico), $somaAtendidaServico, $somaNAtendidaServico); $oldSrv = $srv; $somaDuracaoServico = 0; $somaAtendidaServico = 0; $somaNAtendidaServico = 0; } $somaDuracaoServico += $row['tmo']; $row['status'] == 1 ? $somaAtendidaServico++ : $somaNAtendidaServico++; }; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { if ($mostraColunaServicos) { $agrupaServico($row); } $somaReg ++; $somaDuracao += $row['tmo']; $row['status'] == 1 ? $somaAtendida++ : $somaNAtendida++; $row['origem'] = ocultarTelefone($row['origem']); $row['hora'] = date('H:i:s', strtotime($row['data'])); $row['data'] = date('d/m/Y', strtotime($row['data'])); $row['tmo'] = SecondToStrTime($row['tmo']); $row['status'] = $row['status'] == 1 ? "Atendida" : "Não Atendida"; $linha = ""; foreach ($dadosField as $key => $value) { $linha .= sprintf("%s", $value, $row["$key"]); } $linha .= ""; $dataRel[] = $linha; } if ($mostraColunaServicos) { $agrupaServico(false); } $linhaGeral = 'TOTAL GERALDURAÇÃO%sATENDIDAS / NA%s / %s'; $dataRel[] = sprintf($linhaGeral, ($mostraColunaServicos ? '3' : '2'), SecondToStrTime($somaDuracao), $somaAtendida, $somaNAtendida); /* * Fecha relatorio. */ $dataRel[] = ''; $linha = '
'; $linha .= ""; $linha .= "" . "" . "" . "" . "" . "" . "" . ""; $linha .= '
Totalizador
Atendida: $somaAtendida
Não Atendida:$somaNAtendida
Geral:$somaReg
'; $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( 'Data' => 'C', 'Hora' => 'C', 'Origem' => 'C', 'Tempo' => 'C', 'Agente' => 'C', 'Status' => 'C' ); $dadosField = array( 'data' => 'C', 'hora' => 'C', 'origem' => 'C', 'tmo' => 'C', 'agente' => 'C', 'status' => 'C' ); if ($mostraColunaServicos) { $dadosCabecalio = array_merge(['Serviço' => 'C'], $dadosCabecalio); $dadosField = array_merge(['serv_id' => 'C'], $dadosField); } $dados = $this->GetData()[0]; $somaReg = 0; $somaDuracao = 0; $somaAtendida = 0; $somaNAtendida = 0; $x = 0; $somaAtendidaServico = 0; $somaNAtendidaServico = 0; $somaDuracaoServico = 0; $srv = ""; $oldSrv = ""; $dadosTable = []; $agrupaServico = function($row) use(&$somaDuracaoServico, &$somaAtendidaServico, &$somaNAtendidaServico, &$dadosTable, &$srv, &$oldSrv) { $srv = $row["serv_id"]; if (!$oldSrv) { $oldSrv = $srv; } if ((($srv != $oldSrv)) || !$row) { $data = []; $data['serv_id'] = ' '; $data['data'] = 'TOTAL'; $data['hora'] = ' '; $data['origem'] = 'Duração'; $data['tmo'] = SecondToStrTime($somaDuracaoServico); $data['agente'] = 'ATENDIDAS / NA'; $data['status'] = "$somaAtendidaServico / $somaNAtendidaServico"; $data['cor_linha_dados'] = "225"; $oldSrv = $srv; $somaDuracaoServico = 0; $somaAtendidaServico = 0; $somaNAtendidaServico = 0; $dadosTable[] = $data; } $somaDuracaoServico += $row['tmo']; $row['status'] == 1 ? $somaAtendidaServico++ : $somaNAtendidaServico++; }; /* * Linhas de dados. */ foreach ($dados as $row) { if ($mostraColunaServicos) { $agrupaServico($row); } $somaReg ++; $somaDuracao += $row['tmo']; $row['hora'] = date('H:i:s', strtotime($row['data'])); $row['data'] = date('d/m/Y', strtotime($row['data'])); $row['tmo'] = SecondToStrTime($row['tmo']); $row['status'] = $row['status'] == 1 ? "Atendida" : "Não Atendida"; $row['status'] == 1 ? $somaAtendida++ : $somaNAtendida++; $dadosTable[] = $row; } if ($mostraColunaServicos) { $agrupaServico(false); $widthHeader = array(26, 26, 26, 26, 26, 26, 26); } else { $widthHeader = array(26, 26, 26, 26, 26, 26); } $totaliza = $mostraColunaServicos ? array('DURAÇÃO', SecondToStrTime($somaDuracao), '', '', '', '', '') : array('DURAÇÃO', SecondToStrTime($somaDuracao), '', '', '', ''); $table = array($dadosCabecalio, $dadosField, $dadosTable, $widthHeader, $totaliza, 0); $legendaCabecalio = array( "Atendida" => 'C', "Não Atendida" => 'C', 'Geral' => 'C' ); $legendaField = array( 1 => 'C', 2 => 'C', 3 => 'C' ); $legDadosField = array(array( 1 => $somaAtendida, 2 => $somaNAtendida, 3 => $somaReg ) ); $legendaHeader = array(31, 31, 31); $table2 = array($legendaCabecalio, $legendaField, $legDadosField, $legendaHeader, 0, 1); $this->___dataRel = array($table, $table2); } protected function ___GetAgente() { $result = $this->GetData()[1]; $row = ""; return $row; } 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(); } $legendas = '* C.I.E.I.V: CHAMADAS INTERNAS/EMERGENCIA/INTERNACIONAL/VOIP.'; /* * 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('legendas', $legendas); $smarty->assign('msg', $this->GetMsg()); GetTemplate($smarty, 'relatoriosGrid.tpl'); } } $relRecebidasAgente = new RelRecebidasAgenteSrv($idProg, $dbcon, 1); $relRecebidasAgente->ExecutaRelatorio(); ?>