___dac = isset($_POST['listaDacs']) ? $_POST['listaDacs'] : 0; $this->___tipoAtendimento = isset($_POST['tipoAtendimento']) ? $_POST['tipoAtendimento'] : 1; $this->___agente = isset($_POST["listaAgente"]) ? $_POST["listaAgente"] : ''; } public function ___ValidaForm() { parent::___ValidaForm(); if (!IsPostBack()) { return; } if ($this->___agente < 0) { GeraExcept('Informe um agente!'); } if ($this->___tipoAtendimento < 1 && $this->___tipoAtendimento > 3) { GeraExcept('Informe o tipo de atendimento!'); } } 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 .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; /* * Valores. */ $filtro .= ''; if ($this->GetIncDac()) $filtro .= sprintf('', $dacs); $filtro .= ''; $filtro .= ''; $filtro .= sprintf('', $agente); $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= '
FilaData InicialData Final AgenteTipo Atendimento 
%s%s
'; $filtro .= sprintf('Ambas' . 'Atendidas' . 'Não Atendidas', $this->___tipoAtendimento == 1 ? 'checked' : '', $this->___tipoAtendimento == 2 ? 'checked' : '', $this->___tipoAtendimento == 3 ? 'checked' : ''); $filtro .= '
%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; $billsec = $this->___tipoAtendimento; $agente = $this->___agente; $query = "SELECT a.calldate::timestamp AS data, a.dst AS destino,c.apelido AS agente,'' AS desligado, b.fila, CASE WHEN(b.evento = 'TRANSFERORIG')THEN strtoint(b.param4) ELSE a.duration END AS tmo, CASE WHEN((b.evento IN('BUSYS','NOANSWERS')))THEN 0 ELSE 1 END AS status 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) INNER JOIN pbx_dacs e ON e.nome = b.fila WHERE a.data_bilhete >= '$dataIni' AND a.data_bilhete <= '$dataFim' AND e.id = '$dac'"; switch ($billsec) { case $billsec == 2: $query .= " AND b.evento IN('COMPLETAAGENT','COMPLETACALLER', 'TRANSFERORIG')"; break; case $billsec == 3: $query .= " AND b.evento IN('BUSYS','NOANSWERS')"; break; default : $query .= " AND b.evento IN('COMPLETAAGENT','COMPLETACALLER', 'TRANSFERORIG','BUSYS','NOANSWERS')"; } $queryAgente .= $agente ? " AND c.apelido = '$agente' ORDER BY c.apelido" : ' ORDER BY a.calldate'; //if(IsAdmin()){echo $query . $queryAgente; exit; } $result = $this->___GetQuery($query . $queryAgente); $row = pg_fetch_all($result); $this->SetData($row ? $row : array()); $result1 = $this->___GetQuery($query. " ORDER BY a.calldate"); $row1 = pg_fetch_all($result1); $this->SetData($row1 ? $row1 : array()); } protected function ___PreparaCsv() { $dataRel = array(); $filtro = $this->___FiltrosRelatorio(); $dataRel[] = GenerateCsvFromArray($filtro); $dadosCabecalio = array("Data", 'Hora', 'Destino', 'TMO', 'Agente', 'Status'); $dadosField = array('data', 'hora', 'destino', 'tmo', 'agente', 'status'); $dataRel[] = GenerateCsvFromArray($dadosCabecalio); $somaDuracao = 0; $somaReg = 0; $somaAtendida = 0; $somaNAtendida = 0; foreach ($this->GetData()[0] as $row) { $somaDuracao += $row['tmo']; $somaReg++; $row['status'] == 1 ? $somaAtendida++ : $somaNAtendida++; $row['destino'] = ocultarTelefone($row['destino']); $row['hora'] = date('H:i', strtotime($row['data'])); $row['data'] = date('d/m/Y', strtotime($row['data'])); $row['tmo'] = SecondToStrTime($row['tmo']); $row['status'] = $row['status'] == 1 ? "Atendida" : "Nao Atendida"; // Formata linha de dados. $linha = array(); foreach ($dadosField as $value) { $linha[] = $row["$value"]; } $dataRel[] = GenerateCsvFromArray($linha); } $dataRel[] = GenerateCsvFromArray(array('TMO: ', SecondToStrTime(round($somaDuracao/$somaReg)))); $dataRel[] = GenerateCsvFromArray(array('')); $dataRel[] = GenerateCsvFromArray(array('Atendidas', 'Nao Atendidas', 'Geral')); $dataRel[] = GenerateCsvFromArray(array($somaAtendida, $somaNAtendida, $somaReg)); $this->___dataRel[] = $dataRel; } protected function ___PreparaExcel() { $dataRel = 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('Data', 'Hora', 'Destino', 'TMO', 'Agente', 'Status'); $dadosField = array('data', 'hora', 'destino', 'tmo', 'agente', 'status'); $linha = array('LABEL'); foreach ($dadosCabecalio as $value) { $linha[] = $value; } $dataRel[] = $linha; $somaDuracao = 0; $somaReg = 0; $somaAtendida = 0; $somaNAtendida = 0; foreach ($this->GetData()[0] as $row) { $somaDuracao += $row['tmo']; $somaReg++; $row['status'] == 1 ? $somaAtendida++ : $somaNAtendida++; $row['destino'] = ocultarTelefone($row['destino']); $row['hora'] = date('H:i', strtotime($row['data'])); $row['data'] = date('d/m/Y', strtotime($row['data'])); $row['tmo'] = SecondToStrTime($row['tmo']); $row['status'] = $row['status'] == 1 ? "Atendida" : "Nao Atendida"; $linha = array('DADOS'); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = $linha; } $dataRel[] = array('LABEL', 'TMO: ', SecondToStrTime(round($somaDuracao / $somaReg))); $dataRel[] = array('DADOS', ''); $dataRel[] = array('LABEL', 'Atendidas', 'Nao Atendidas', 'Geral'); $dataRel[] = array('DADOS', $somaAtendida, $somaNAtendida, $somaReg); $this->___dataRel[] = $dataRel; } protected function ___PreparaGrid() { $dataRel = array(); $dadosCabecalio = array( 'Data' => 'align="center"', 'Hora' => 'align="center"', 'Destino' => 'align="center"', 'TMO' => 'align="center"', 'Agente' => 'align="center"', 'Status' => 'align="center"' ); $dadosField = array( 'data' => 'align="center"', 'hora' => 'align="center"', 'destino' => 'align="center"', 'tmo' => 'align="center"', 'agente' => 'align="center"', 'status' => 'align="center"' ); /* * Inicia o relatório. */ $dataRel[] = ''; /* * Monta a linha de cabecalio. */ $linha = ''; foreach ($dadosCabecalio as $key => $value) { $linha .= sprintf("", $value, $key); } $linha .= ""; $dataRel[] = $linha; /* * Verifica se retornou dados */ if (!IsPostBack() || !count($this->GetData()[0])) { $dataRel[] = sprintf("
%s
%s
", count($dadosCabecalio) - 1, (!IsPostBack() ? 'Informe os parametros e clique em consultar!' : 'Nenhum registro encontado!')); $this->___dataRel[] = $dataRel; return; } $somaDuracao = 0; $somaReg = 0; $somaAtendida = 0; $somaNAtendida = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $somaDuracao += $row['tmo']; $somaReg++; $row['status'] == 1 ? $somaAtendida++ : $somaNAtendida++; $row['destino'] = ocultarTelefone($row['destino']); $row['hora'] = date('H:i', 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"; // Formata linha de dados. $linha = ""; foreach ($dadosField as $key => $value) { $linha .= sprintf("%s", $value, $row["$key"]); } $linha .= ""; $dataRel[] = $linha; } /* * Linha de totalizacao. */ $linha = 'TMO: %s '; $dataRel[] = sprintf($linha, SecondToStrTime(round($somaDuracao / $somaReg))); /* * Fecha relatorio. */ $dataRel[] = ''; $dataRel[] = '
'; $dataRel[] = sprintf('' . '' . '' . '', $somaAtendida, $somaNAtendida, $somaReg); $dataRel[] = '
Totalização Geral
Atendidas%s
Não Atendidas%s
Geral%s
'; $this->___dataRel[] = $dataRel; } protected function ___PreparaHtml() { } protected function ___PreparaPdf() { list($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio) = $_SESSION["SSstorageFiltros"]; $dadosCabecalio = array( "Data" => 'C', 'Hora' => 'C', 'Destino' => 'C', 'TMO' => 'C', 'Agente' => 'C', 'Status' => 'C' ); $dadosField = array( 'data' => 'C', 'hora' => 'C', 'destino' => 'C', 'tmo' => 'C', 'agente' => 'C', 'status' => 'C' ); $somaDuracao = 0; $somaReg = 0; $somaAtendida = 0; $somaNAtendida = 0; $dados = $this->GetData()[0]; $x = 0; foreach ($dados as $row) { $somaDuracao += $row['tmo']; $somaReg++; $row['status'] == 1 ? $somaAtendida++ : $somaNAtendida++; $dados[$x]['destino'] = ocultarTelefone($row['destino']); $dados[$x]['hora'] = date('H:i', strtotime($row['data'])); $dados[$x]['data'] = date('d/m/Y', strtotime($row['data'])); $dados[$x]['tmo'] = SecondToStrTime($row['tmo']); $dados[$x]['status'] = $row['status'] == 1 ? "Atendida" : "Não Atendida"; $x++; } $widthHeader = array(35, 25, 35, 35, 28, 35); $totaliza = array('TMO: ', SecondToStrTime(round($somaDuracao / $somaReg)), '', '', '', ''); $table = array($dadosCabecalio, $dadosField, $dados, $widthHeader, $totaliza, 0); $legendaCabecalio = array( "Atendidas" => 'C', "Não Atendidas" => 'C', 'Geral' => 'C' ); $legendaField = array( 1 => 'C', 2 => 'C', 3 => 'C' ); $legDadosField = array(array( 1 => $somaAtendida, 2 => $somaNAtendida, 3 => $somaReg) ); $legendaHeader = array(64, 64, 65); $table3 = array($legendaCabecalio, $legendaField, $legDadosField, $legendaHeader, 0, 1); $this->___dataRel = array($table, $table3); } protected function ___GetAgente() { $agentes = array(); foreach ($this->GetData()[1] as $agente) { array_push($agentes, $agente['agente']); } $fltAgentes = array_unique($agentes); $sel = !$this->___agente ? "selected" : ""; $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(); } /* * 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'); } } $relOriginadasAgente = new RelOriginadasAgente($idProg, $dbcon, 1); $relOriginadasAgente->ExecutaRelatorio(); ?>