___tipoRelatorio = isset($_REQUEST['relTipo']) ? $_REQUEST['relTipo'] : 0; $this->___dac = isset($_POST['listaDacs']) ? $_POST['listaDacs'] : 0; $this->___agente = isset($_POST["listaAgente"]) ? $_POST["listaAgente"] : null; } function ___FiltrosRelatorio() { 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"'; if ($this->___dataIni && $this->___dataFim) { $agentes = $this->retornaAgente(); } /* * Personalise esta função se necessitar de outras operaçõ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 .= ""; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= '
FilaData InicialData Final Agente Analítico 
%s$agentes%s
'; /* * Guarda os filtros passados para recuperar na emissão dos relatórios para impressão. */ $_SESSION["SSstorageFiltros"] = array($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio); return sprintf($filtro, $tipoRel, $this->___dataIni, $this->___dataFim, $lkPrint); } protected function ___GetDadosDb() { $dt = FormatDtMssql($this->___dataIni); $dtFim = FormatDtMssql($this->___dataFim); $dac = $this->___dac; $agente = $this->___agente ? QuotedStr($this->___agente) : "null"; $query = "CREATE TEMPORARY TABLE agente_operacao_Ciosp ( id_dac int, fila varchar(50) not null, apelido varchar(30), matricula varchar(4) not null, data date not null, login timestamp, logoff timestamp, tempoLogin int, num_pausa int, tempo_pausa int, num_pausa_prod int, tempo_pausa_prod int, CONSTRAINT \"pkAgtOpera\" PRIMARY KEY( fila, matricula, data )); insert into agente_operacao_Ciosp select c.id as id_dac, c.nome as fila, b.apelido, a.matricula, cast(a.login as date) as data, min(login) as login, max(logoff) as logoff, sum(EXTRACT(epoch from ((logoff) - (login)))) as tempoLogin, 0 as num_pausa, 0 as tempo_pausa, 0 as num_pausa_prod, 0 as tempo_pausa_prod from pbx_eventos_agentes a, pbx_usuarios b, pbx_dacs c where b.matricula = a.matricula and c.id = a.id_dac and a.id_dac = coalesce('$dac', a.id_dac) and cast(a.login as date) >= '$dt' and cast(a.login as date) <= '$dtFim' and b.matricula = coalesce($agente, b.matricula) group by 1, 2, 3, 4, 5; CREATE TEMPORARY TABLE agente_pausa_Ciosp AS select a.id_dac, b.apelido, cast(a.entrada_pausa as date) as data, sum(case when(a.pausa_produtiva = 0)then 1 else 0 end) as num_pausa, sum(case when(a.pausa_produtiva = 1)then 1 else 0 end) as num_pausa_prod, sum(EXTRACT(epoch from ( case when(a.pausa_produtiva = 0)then saida_pausa - entrada_pausa else '00:00:00' end ))) as tempo_pausa, sum(EXTRACT(epoch from ( case when(a.pausa_produtiva = 1)then saida_pausa - entrada_pausa else '00:00:00' end ))) as tempo_pausa_prod from pbx_eventos_agentes a, pbx_usuarios b where b.matricula = a.matricula and a.id_dac = coalesce('$dac', a.id_dac) and cast(a.entrada_pausa as date) >= '$dt' and cast(a.entrada_pausa as date) <= '$dtFim' and b.matricula = coalesce($agente, b.matricula) group by a.id_dac, b.apelido, cast(a.entrada_pausa as date); update agente_operacao_Ciosp set num_pausa = b.num_pausa, tempo_pausa = b.tempo_pausa, num_pausa_prod = b.num_pausa_prod, tempo_pausa_prod = b.tempo_pausa_prod from agente_pausa_Ciosp as b where agente_operacao_Ciosp.apelido = b.apelido and agente_operacao_Ciosp.data = b.data and agente_operacao_Ciosp.id_dac = b.id_dac;"; if ($this->___tipoRelatorio) { $query .= "select id_dac, fila, apelido, matricula, data, login, logoff, tempologin, num_pausa, tempo_pausa,num_pausa_prod, tempo_pausa_prod from agente_operacao_Ciosp order by apelido, data"; } else { $query .= "select id_dac, fila, apelido, matricula, sum(tempologin) as tempologin from agente_operacao_Ciosp group by 1,2,3,4 order by apelido"; } $result = $this->___GetQuery($query); $row = pg_fetch_all($result); $this->SetData($row ? $row : array()); $this->SetData($this->___agente ? $this->___agente : 0); } protected function ___PreparaCsv() { $dataRel = array(); $filtro = $this->___FiltrosRelatorio(); /* * Inicia o relatório. */ $dataRel[] = GenerateCsvFromArray($filtro); if (!$this->___tipoRelatorio) { $dadosCabecalio = array('Agente' => 'align="center"', 'Duracao' => 'align="center"'); $dadosField = array('apelido' => 'align="center"', 'tempologin' => 'align="center"'); /* * Monta a linha de cabecalio. */ $dataRel[] = GenerateCsvFromArray(array_keys($dadosCabecalio)); $somaTempo = 0; $somaQuantidade = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $somaTempo += $row["tempologin"]; $somaQuantidade ++; $row["tempologin"] = SecondToStrTime($row["tempologin"]); // Formata linha de dados. $linha = array(); foreach ($dadosField as $key => $value) { $linha[] = $row["$key"]; } $dataRel[] = GenerateCsvFromArray($linha); } $this->___dataRel[] = $dataRel; $linhaTotal = array(); $linhaTotal[] = 'Total: ' . $somaQuantidade; $linhaTotal[] = 'Duracao: ' . SecondToStrTime($somaTempo); $dataRelTotal[] = GenerateCsvFromArray($linhaTotal); $this->___dataRel[] = $dataRelTotal; } else { $dadosCabecalio = array('Agente' => 'align="center"', 'Inicio' => 'align="center"', 'Termino' => 'align="center"', 'Duracao' => 'align="center"'); $dadosField = array('apelido' => 'align="center"', 'login' => 'align="center"', 'logoff' => 'align="center"', 'tempologin' => 'align="center"'); $linhaTotal = array(); $dataRel[] = GenerateCsvFromArray(array_keys($dadosCabecalio)); $ultApelido = ''; $somaTempo = 0; $somaQuantidade = 0; foreach ($this->GetData()[0] as $row) { $count++; if ($count != 1) { if ($ultApelido != $row['apelido']) { $linhaTotal = array('Total: ' . $somaQuantidade, '', '', 'Duracao: ' . SecondToStrTime($somaTempo)); $dataRel[] = GenerateCsvFromArray($linhaTotal); unset($linhaTotal); unset($somaTempo); unset($somaQuantidade); $linhaVoid = array('', '', '', ''); $dataRel[] = GenerateCsvFromArray($linhaVoid); unset($linhaVoid); $dataRel[] = GenerateCsvFromArray(array_keys($dadosCabecalio)); } } $somaTempo += $row["tempologin"]; $somaQuantidade ++; $row["tempologin"] = SecondToStrTime($row["tempologin"]); $row["login"] = date('d/m/Y H:i:s', strtotime($row["login"])); $row["logoff"] = date('d/m/Y H:i:s', strtotime($row["logoff"])); // Formata linha de dados. $linha = array(); foreach ($dadosField as $key => $value) { $linha[] = $row["$key"]; } $dataRel[] = GenerateCsvFromArray($linha); $ultApelido = $row['apelido']; if (count($this->GetData()[0]) == $count) { $linhaTotal = array('Total: ' . $somaQuantidade, '', '', 'Duracao: ' . SecondToStrTime($somaTempo)); $dataRel[] = GenerateCsvFromArray($linhaTotal); } } $this->___dataRel[] = $dataRel; } } protected function ___PreparaExcel() { $nomeDac = ""; $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; if (!$this->___tipoRelatorio) { $dadosCabecalio = array('Agente', 'Duracao'); $dadosField = array('apelido', 'tempologin'); /* * 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) { $somaTempo += $row["tempologin"]; $somaQuantidade ++; $row["tempologin"] = SecondToStrTime($row['tempologin']); // Formata linha de dados. $linha = array('DADOS'); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = $linha; } $linha = array('LABEL', 'Total: ' . $somaQuantidade, SecondToStrTime($somaTempo)); $dataRel[] = $linha; $this->___dataRel[] = $dataRel; } else { $dadosCabecalio = array('Agente', 'Inicio', 'Termino', 'Duracao'); $dadosField = array('apelido', 'login', 'logoff', 'tempologin'); $ultApelido = ''; /* * 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) { $count++; if ($count != 1) { if ($ultApelido != $row['apelido']) { $linha1 = array('LABEL', 'Total: ' . $somaQuantidade, '', '', 'Duracao: ' . SecondToStrTime($somaTempo)); $dataRel[] = $linha1; $linha2 = array('LABEL', '', '', '', ''); $dataRel[] = $linha2; $linha = array('LABEL'); foreach ($dadosCabecalio as $value) { $linha[] = $value; } $dataRel[] = $linha; unset($somaTempo); unset($somaQuantidade); } } $somaTempo += $row["tempologin"]; $somaQuantidade ++; $row["tempologin"] = SecondToStrTime($row['tempologin']); $row["login"] = date('d/m/Y H:i:s', strtotime($row["login"])); $row["logoff"] = date('d/m/Y H:i:s', strtotime($row["logoff"])); $linha = array('DADOS'); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = $linha; $ultApelido = $row['apelido']; if (count($this->GetData()[0]) == $count) { $linha1 = array('LABEL', 'Total: ' . $somaQuantidade, '', '', 'Duracao: ' . SecondToStrTime($somaTempo)); $dataRel[] = $linha1; } } $this->___dataRel[] = $dataRel; } } protected function ___PreparaGrid() { if (!$this->___tipoRelatorio) { $dadosCabecalio = array( 'Agente' => 'align="left"', 'Duração' => 'align="center"' ); $dadosField = array( 'apelido' => 'align="left"', 'tempologin' => 'align="center"' ); $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; } $somaTempo = 0; $somaQuantidade = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $somaTempo += $row["tempologin"]; $somaQuantidade ++; $row["tempologin"] = SecondToStrTime($row["tempologin"]); // Formata linha de dados. $linha = ""; foreach ($dadosField as $key => $value) { $linha .= sprintf("%s", $value, $row["$key"]); } $linha .= ""; $dataRel[] = $linha; } /* * Linha de totalizacao. */ $linha = 'Total: %sDuração: %s'; $dataRel[] = sprintf($linha, $somaQuantidade, SecondToStrTime($somaTempo)); /* * Fecha relatorio. */ $dataRel[] = ''; $this->___dataRel[] = $dataRel; } else { /* * ************************************************************ * ************************************************************* * IMPRESSÃO DE RELÁTÓRIO AGENTES HORAS TIPO ANÁLITICO * ************************************************************* * ************************************************************* */ $dadosCabecalio = array( 'Agente' => 'align="left"', 'Início' => 'align="center"', 'Término' => 'align="center"', 'Duração' => 'align="center"' ); $dadosField = array( 'apelido' => 'align="left"', 'login' => 'align="center"', 'logoff' => 'align="center"', 'tempologin' => 'align="center"' ); $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; } $somaTempo = 0; $somaQuantidade = 0; $ultApelido = ''; $z = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $tempo = $row["tempologin"]; $row["tempologin"] = SecondToStrTime($row["tempologin"]); $row["login"] = date('d/m/Y H:i:s', strtotime($row["login"])); $row["logoff"] = date('d/m/Y H:i:s', strtotime($row["logoff"])); // Formata linha de dados. $linha = ""; if ($row['apelido'] != $ultApelido) { if ($z != 0) { $linhaTotal = 'Total %s: %sDuração: %s'; $dataRel[] = sprintf($linhaTotal, $ultApelido, $somaQuantidade, SecondToStrTime($somaTempo)); unset($somaQuantidade); unset($somaTempo); $linha .= sprintf(" ", count($dadosField)); $linha .= ""; } } $somaTempo += $tempo; $somaQuantidade ++; foreach ($dadosField as $key => $value) { $linha .= sprintf("%s", $value, $row["$key"]); } if (count($this->GetData()[0]) == $z + 1) { $linha .= ""; $linha .= sprintf('Total %s: %sDuração: %s', $row['apelido'], $somaQuantidade, SecondToStrTime($somaTempo)); } $linha .= ""; $ultApelido = $row['apelido']; $z++; $dataRel[] = $linha; } /* * Fecha relatorio. */ $dataRel[] = ''; $this->___dataRel[] = $dataRel; } } protected function ___PreparaHtml() { } protected function ___PreparaPdf() { $nomeDac = ""; list($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio) = $_SESSION["SSstorageFiltros"]; /** * TABELA DADOS PRINCIPAIS */ $somaQtd = 0; $somaTempo = 0; $dados = array(); $ultApelido = ''; $x = 0; if (!$this->___tipoRelatorio) { foreach ($this->GetData()[0] as $row) { $somaQtd ++; $somaTempo += $row["tempologin"]; $dados[$x]['apelido'] = $row["apelido"]; $dados[$x]['tempologin'] = SecondToStrTime($row["tempologin"]); $x++; } //HEADER DA TABELA DO PDF -> DADOS EM ARRAY $header = array( 'Agente' => 'C', 'Duração' => 'C' ); $dataHeader = array( 'apelido' => 'C', 'tempologin' => 'C' ); $widthHeader = array(100, 80); $totaliza = array( "Total: $somaQtd", "Duração: " . SecondToStrTime($somaTempo)); //Monta o array para passar para o prepara; Necessário passar 6 parametros $table1 = array($header, $dataHeader, $dados, $widthHeader, $totaliza, 0); $this->___dataRel = array($table1); } else { $pass = 0; $t = 0; $tables = array(); //HEADER DA TABELA DO PDF -> DADOS EM ARRAY $header = array( 'Agente' => 'L', 'Início' => 'C', 'Término' => 'C', 'Duração' => 'C' ); $dataHeader = array( 'apelido' => 'L', 'login' => 'C', 'logoff' => 'C', 'tempologin' => 'C' ); $widthHeader = array(45, 45, 45, 45); foreach ($this->GetData()[0] as $row) { if ($x != 0) { if ($row['apelido'] != $ultApelido) { $totaliza = array("Total: $somaQtd", '', '', "Duração: " . SecondToStrTime($somaTempo)); ${"table" . $t} = array($header, $dataHeader, $dados, $widthHeader, $totaliza, 0); array_push($tables, ${"table" . $t}); $t++; unset($somaQtd); unset($somaTempo); unset($x); unset($dados); } } $somaTempo += $row["tempologin"]; $somaQtd++; $dados[$x]["tempologin"] = SecondToStrTime($row["tempologin"]); $dados[$x]["login"] = date('d/m/Y H:i:s', strtotime($row["login"])); $dados[$x]["logoff"] = date('d/m/Y H:i:s', strtotime($row["logoff"])); $dados[$x]["apelido"] = $row['apelido']; $ultApelido = $row['apelido']; $x++; $arQtd ++; //PREENCHE OS DADOS DA ULTIMA LINHA DO ARRAY DO BANCO DE DADOS if (count($this->GetData()[0]) == $arQtd) { $totaliza = array("Total: $somaQtd", '', '', "Duração: " . SecondToStrTime($somaTempo)); ${"table" . $t} = array($header, $dataHeader, $dados, $widthHeader, $totaliza, 0); array_push($tables, ${"table" . $t}); } } $this->___dataRel = $tables; } } 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'); } protected function retornaAgente() { global $dbcon; $codSel = $this->GetData()[1] ? $this->GetData()[1] : ''; $agentes = "'; } while ($dados = pg_fetch_row($result)) { if ($codSel == $dados[0]) { $sel = "selected"; $i = 1; } else { $sel = ""; } $agentes .= ""; } $agentes .= ""; return $agentes; } } $relAgtHoras = new RelAgenteHoras($idProg, $dbcon, 1); $relAgtHoras->ExecutaRelatorio();