___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 * 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') 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 order by 2"; //echo $query; $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['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['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(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; $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) { $row['status'] == 'ATENDIDA' ? $somaChm++ : ''; $row['billsec'] = SecondToStrTime($row['billsec']); $row['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); $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(); /* * Relatório mostra a produtividade de um agente require_once("bd.php"); //variaveis para manter o estado if ($_POST["btConsulta"]) { $_SESSION["listaDacs"] = $_POST["listaDacs"]; $_SESSION["listaAgente"] = $_POST["listaAgente"]; $_SESSION["dataIni"] = $_POST["dataIni"]; $_SESSION["dataFim"] = $_POST["dataFim"]; $_SESSION["ramal"] = $_POST["ramal"]; $_SESSION["lstStatus"] = $_POST["lstStatus"]; } else { $_SESSION["listaAgente"] = 0; $_SESSION["listaDacs"] = !IsAjax() ? GetIdDacPadrao($dbcon, $_SESSION["SSidUser"]) : $_GET["listaDacs"]; $_SESSION["dataIni"] = !IsAjax() ? date('d/m/Y') . " 00:00" : $_GET["dataIni"]; $_SESSION["dataFim"] = !IsAjax() ? date('d/m/Y') . " 23:59" : $_GET["dataFim"]; $_SESSION["lstStatus"] = ""; } //Verifica se � o primeiro acesso a pagia $isPostBack = isset($_GET["idProg"]) ? 0 : 1; $codSel = $_SESSION["listaDacs"]; //carrega dacs if (!IsAjax()) $dacs = GetDac($dbcon, $codSel, "", 0); //carrega Atendente if (!IsAjax()) $codSel = ((!$_SESSION["listaAgente"]) || ($trocaDac)) ? 0 : $_SESSION["listaAgente"]; else $codSel = !empty($_GET["codAgt"]) ? $_GET["codAgt"] : 0; $sel = !$codSel ? "selected" : ""; $agentes = ""; if (!$numAgt) $agentes = str_replace('Todos', '------', $agentes); //relatorio if (IsAjax()) { echo $agentes; } else { $imp = 0; $linhas = ""; //valida data inicial $hora = array(); $valDate = substr($_SESSION["dataIni"], 0, 10); $hora = split(":", substr($_SESSION["dataIni"], 11, 5)); $hora[0] = (int) $hora[0]; $hora[1] = (int) $hora[1]; $valIni = is_date($valDate); if ($valIni) $valIni = !$hora[0] && !$hora[1] ? true : (($hora[0] > 23) || ($hora[1] > 59) ? false : true); //valida data final $hora = array(); $valDate = substr($_SESSION["dataFim"], 0, 10); $hora = split(":", substr($_SESSION["dataFim"], 11, 5)); $hora[0] = (int) $hora[0]; $hora[1] = (int) $hora[1]; $valFim = is_date($valDate); if ($valFim) $valFim = (!$hora[0] && !$hora[1]) ? true : (($hora[0] > 23) || ($hora[1] > 59) ? false : true); if (IsPostBack() && !$_SESSION["listaDacs"]) { $jsStartup[] = "alert('Selecione um DAC!');"; $msg = "Selecione um DAC!"; } else if (!$valIni) { $jsStartup[] = "alert('Data inicial inv�lida!');"; $msg = "Data inicial inv�lida!"; } else if (!$valFim) { $jsStartup[] = "alert('Data final inv�lida!');"; $msg = "Data final inv�lida!"; } else { if ($isPostBack) { $setQuery = ""; $setQuery = utf8_encode(GetQuery($trocaDac)); $result = @pg_query($dbcon, $setQuery); $resumo = array(); $total = 0; $buffDados = array();tempo_atende $dacSel = ""; $totais = array(); while ($dados = @pg_fetch_array($result)) { $dados["dac"] = $dados["fila"]; $dados["data"] = $dados["calldate"]; $dados["agente"] = $dados["apelido"]; $dados["destino"] = $dados["dst"]; $dados["fone"] = $dados["src"]; // fila, calldate, src, dst, apelido, disposition, billsec, duration $buffDados[] = $dados; $data = FormataDBDataHora($dados["data"]); $fone = FormataFone($dados["fone"]); $agente = $dados["agente"]; $destino = $dados["destino"]; // == 200 ? $dados["dac"] : $dados["destino"]; $status = $dados["status"]; $dacSel = $dados["dac"]; $tipo = SecondToStrTime($dados["billsec"]); $totais[$dados["status"]] ++; //Ramal, Origem, Data/Hora, Tipo, Status if (!array_key_exists($dados["destino"], $resumo)) $resumo[$dados["destino"]] = 1; else $resumo[$dados["destino"]] ++; $linhas .= " $destino $fone $data $tipo $status "; $total++; } ksort($resumo); $totalRes = 0; $akey = array(); $totalResumo = 0; foreach ($resumo as $key => $value) { $akey[] = array($key, $value); $linhaResumo .= " $key$value"; $totalRes += $value; $totalResumo++; } } //dados para relatorio $_SESSION["dadosRelTrans"] = $buffDados; $_SESSION["relTransTotal"] = $total; $_SESSION["dacSel"] = $dacSel; $_SESSION["dadosRelResumo"] = $akey; $_SESSION["relTransResumoTotal"] = $totalResumo; } $jsJQuery[] = "\$('#listaDacs').change(function(){GetAgtFromTransfer();}) "; $jsJQuery[] = "\$('#dataIni').keypress(function(){formataDataHora(this);}) "; $jsJQuery[] = "\$('#dataIni').change(function(){GetAgtFromTransfer();}) "; $jsJQuery[] = "\$('#dataFim').keypress(function(){formataDataHora(this);}) "; $jsJQuery[] = "\$('#dataFim').change(function(){GetAgtFromTransfer();}) "; //totalizacao if ($total) { $linhaTotal = ""; foreach ($totais as $key => $value) $linhaTotal .= "Total de $key$value"; $linhaTotal .= "Total Geral$total"; } if ($isPostBack) { $erro = ""; if (pg_last_error($dbcon)) $erro = "Ocorreram erros durante a opera��o. Erro: " . pg_last_error($dbcon); } $smarty->assign('imp', $total); $smarty->assign('dtIni', $_SESSION["dataIni"]); $smarty->assign('dtFim', $_SESSION["dataFim"]); $smarty->assign('ramal', $_SESSION["ramal"]); $smarty->assign('dacs', $dacs); $smarty->assign('agentes', $agentes); $smarty->assign('status', GetStatus($_SESSION["lstStatus"])); $smarty->assign('linhas', $linhas); $smarty->assign('totais', $linhaTotal); $smarty->assign('linhaResumo', $linhaResumo); $smarty->assign('totalRes', $totalRes); $smarty->assign('erro', $erro); DispRel($smarty); } function DispRel($smarty) { $smarty->display('transferenciaGrid.tpl'); } function GetQuery($trocaDac) { $dac = trim($_SESSION["listaDacs"]); $agente = trim($_SESSION["agente"]); $dt = trim($_SESSION["dataIni"]); $dtFim = trim($_SESSION["dataFim"]); $ramal = trim($_SESSION["ramal"]); $status = trim($_SESSION["lstStatus"]); $dataInicial = FormatDtMssql(substr($_SESSION["dataIni"], 0, 10)); $dataFinal = FormatDtMssql(substr($_SESSION["dataFim"], 0, 10)); $dt = soNumero($dt) <= 8 ? '' : FormatDtHoraBD($dt); $dtFim = soNumero($dtFim) <= 8 ? '' : FormatDtHoraBD($dtFim); $dataCorte = GetDataRelatorio(); $query = " select * 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') -- entrada else(select q.destino from pbx_bilhetes_complemento q where q.uniqueid2 = a.uniqueid order by data_registro limit 1) -- sa�da 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 >= '$dataCorte' and a.data_bilhete >= '$dataInicial' and a.data_bilhete <= '$dataFinal' and exists(select '' from pbx_bilhetes where data_bilhete = a.data_bilhete and accountcode = a.uniqueid)\n"; if ($dt) $query .= " and date_trunc('minute', a.calldate) >= '$dt'\n"; if ($dtFim) $query .= " and date_trunc('minute', a.calldate) <= '$dtFim'\n"; if ($ramal) $query .= " and a.dst = '$ramal'\n"; if ($agente) $query .= " and c.matricula = '$agente'\n"; if ($status) $query .= " and a.disposition = '$status'\n"; if ($dac) $query .= " and e.id = '$dac' \n"; $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 < '$dataCorte' and a.data_bilhete >= '$dataInicial' and a.data_bilhete <= '$dataFinal' \n"; if ($dt) $query .= " and date_trunc('minute', a.calldate) >= '$dt'\n"; if ($dtFim) $query .= " and date_trunc('minute', a.calldate) <= '$dtFim'\n"; if ($ramal) $query .= " and a.dst = '$ramal'\n"; if ($agente) $query .= " and c.matricula = '$agente'\n"; if ($status) $query .= " and a.disposition = '$status'\n"; if ($dac) $query .= " and e.id = '$dac' "; $query .= ")as transferencia order by 2 \n"; //if(IsAdmin()) echo $query; return $query; } function HoraZero($h) { $hora = split(":", $h); if (((int) $hora[0] == true) || ((int) $hora[1] == true)) return false; else return true; } function GetStatus($st) { $status = ""; return $status; } */ ?>