<?php
include_once 'util/relatoriosBase.php';
class RelTrasfAgente extends Relatorios{
function ___FiltrosRelatorio() {
if ($this->___media != MEDIA_PRINT_GRID) {
/*
* Recupera os filtros da sess<EFBFBD> o do usu<EFBFBD> rio.
*/
list($this->___dataIni, $this->___dataFim) = $_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<EFBFBD> tico' : 'Sint<EFBFBD> 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 = '< a href = "index.php?idProg=%s&media=%s&tipoRelatorio=%s" > < img src = "imgSite/%s" alt = "Clique aqui para imprimir!" width = "24" height = "24" border = "0" > < / a > ';
$prtHtml = "< a href = \"javaScript:NovaJanela('index.php?idProg=%s&media=%s&tipoRelatorio=%s', ' % s ' , ' 720 ' , ' 700 ' , ' scrollbars = YES');\" > < img src = \"imgSite/%s\" alt = \"Clique aqui para imprimir ! \ " width = \"24\" height = \"24\" border = \"0\" > < / a > ";
$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<EFBFBD> <EFBFBD> o se necessitar de outras opera<EFBFBD> <EFBFBD> es de filtro.
*/
$filtro = '< table border = "0" cellspacing = "1" cellpadding = "1" > ';
/*
* Rotulos.
*/
$filtro .= '< tr > ';
$this->GetIncDac() ? $filtro .= '< td > Fila< / td > ' : '';
$filtro .= '< td > Data Inicial< / td > ';
$filtro .= '< td > Data Final < / td > ';
$filtro .= '< td align = "center" valign = "middle" > < / td > ';
$filtro .= '< / tr > ';
/*
* Valores.
*/
$filtro .= '< tr > ';
$this->GetIncDac() ? $filtro .= sprintf('< td > %s< / td > ', $dacs) : '';
$filtro .= '< td > < input name = "dataIni" id = "dataIni" type = "text" size = "15" maxlength = "10" value = "%s" onkeyup = "formataData(this)" title = "dd/mm/aaaa" > < / td > ';
$filtro .= '< td > < input name = "dataFim" id = "dataFim" type = "text" size = "15" maxlength = "10" value = "%s" onkeyup = "formataData(this)" title = "dd/mm/aaaa" > < / td > ';
$filtro .= '< td > < input type = "submit" name = "btConsulta" id = "btConsulta" value = "Consultar" > < / td > ';
$filtro .= '< td > %s< / td > ';
$filtro .= '< / tr > ';
$filtro .= '< / table > ';
/*
* Guarda os filtros passados para recuperar na emiss<EFBFBD> o dos relat<EFBFBD> rios para impress<EFBFBD> o.
*/
$_SESSION["SSstorageFiltros"] = array($this->___dataIni, $this->___dataFim);
return sprintf($filtro, $this->___dataIni, $this->___dataFim, $lkPrint);
}
protected function ___GetDadosDb() {
$dataIni = FormatDtMssql($this->___dataIni);
$dataFim = FormatDtMssql($this->___dataFim);
$dataCorte = GetDataRelatorio();
$query = "select
agente,
matricula,
sum(tempo::bigint) as tempo,
count(*) as quant
from(select c.apelido as agente,c.matricula,a.billsec as tempo
from pbx_bilhetes a,pbx_usuarios c, pbx_eventos_dacs d
where c.matricula = substring(d.agente, 7, 4)
and d.uid2 = a.uniqueid
and d.evento in('COMPLETEAGENT','COMPLETECALLER','COMPLETAAGENT','COMPLETACALLER')
and a.lastapp < > 'Transferred Call'
--and a.data_bilhete >= '$dataCorte'
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)
union all
select c.apelido as agente,c.matricula,d.param4::bigint as tempo
from pbx_bilhetes a, pbx_usuarios c, pbx_eventos_dacs d
where c.matricula = substring(a.dstchannel, 7, 4)
and d.uid2 = a.uniqueid
and param4 < > ''
and d.evento in('TRANSFER', 'TRANSFERORIG')
and a.lastapp < > 'Transferred Call'
--and a.data_bilhete < '$dataCorte'
and a.data_bilhete >= '$dataIni'
and a.data_bilhete < = '$dataFim'
)as transf
group by 1,2
order by 1 ";
$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('Agente','Quantidade','TMA');
$dadosField = array('agente','quant','tma');
$dataRel[] = GenerateCsvFromArray($dadosCabecalio);
$somaReg = 0;
$somaTempo = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$somaReg += $row['quant'];
$somaTempo += $row['tempo'];
$row['tma'] = SecondToStrTime(round($row['tempo']/$row['quant']));
$linha = array();
foreach ($dadosField as $key) {
$linha[] = $row["$key"];
}
$dataRel[] = GenerateCsvFromArray($linha);
}
$dataRel[] = GenerateCsvFromArray(array('Geral:', $somaReg, SecondToStrTime(round($somaTempo/$somaReg))));
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaExcel() {
$dataRel = array();
$filtro = $this->___FiltrosRelatorio();
/*
* Inicia o relat<EFBFBD> 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('Agente','Quantidade','TMA');
$dadosField = array('agente','quant','tma');
/*
* Monta a linha de cabecalio.
*/
$linha = array('LABEL');
foreach ($dadosCabecalio as $value) {
$linha[] = $value;
}
$dataRel[] = $linha;
$somaReg = 0;
$somaTempo = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$somaReg += $row['quant'];
$somaTempo += $row['tempo'];
$row['tma'] = SecondToStrTime(round($row['tempo']/$row['quant']));
// Formata linha de dados.
$linha = array('DADOS');
foreach ($dadosField as $key) {
$linha[] = $row["$key"];
}
$dataRel[] = $linha;
}
$dataRel[] = array('LABEL', 'Geral: ', $somaReg, SecondToStrTime(round($somaTempo/$somaReg)));
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaGrid() {
$dataRel = array();
$dadosCabecalio = array(
'Agente' => 'align="left"',
'Quantidade' => 'align="right"',
'TMA' => 'align="right"'
);
$dadosField = array(
'agente' => 'align="left"',
'quant' => 'align="right"',
'tma' => 'align="right"'
);
/*
* Inicia o relat<EFBFBD> rio.
*/
$dataRel[] = '< table width = "70%" cellpadding = "2" class = "grid" > ';
/*
* Monta a linha de cabecalio.
*/
$linha = '< tr > ';
$linha .= "< th align = \"center\" colspan = \"3\" > Transfer<EFBFBD> ncia por Agente< / th > ";
$linha .= "< / tr > ";
$dataRel[] = $linha;
/*
* Verifica se retornou dados
*/
if (!IsPostBack() || !count($this->GetData()[0])) {
$dataRel[] = sprintf("< tr > < td align = \"center\" colspan = \"%s\" > %s< / td > < / tr > < / table > ", count($dadosCabecalio) - 1, (!IsPostBack() ? 'Informe os parametros e clique em consultar!' : 'Nenhum registro encontado!'));
$this->___dataRel[] = $dataRel;
return;
}
$linhaC = "< tr > ";
foreach ($dadosCabecalio as $key => $value) {
$linhaC .= sprintf("< th % s > %s< / th > ", $value, $key);
}
$linhaC .= "< / tr > ";
$dataRel[] = $linhaC;
$somaReg = 0;
$somaTempo = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$somaReg += $row['quant'];
$somaTempo += $row['tempo'];
$row['agente'] = sprintf("< a style = \"color: # 000 ; \ " href = \"javaScript:NovaJanela('index.php?idProg=25&mat=%s&dataIni=%s&dataFim=%s', ' transAgtDet ' , ' 500 ' , ' 400 ' , ' resizable = NO,scrollbars=1');\" > %s< / a > ",$row['matricula'], $this->___dataIni, $this->___dataFim,$row['agente']);
$row['tma'] = SecondToStrTime(round($row['tempo']/$row['quant']));
$linha = "< tr > ";
foreach ($dadosField as $key => $value) {
$linha .= sprintf("< td % s > %s< / td > ", $value, $row["$key"]);
}
$linha .= "< / tr > ";
$dataRel[] = $linha;
}
$dataRel[] = sprintf("< tr > < th align = \"left\" > Geral: < / th > < th align = \"right\" > $somaReg< / th > < th align = \"right\" > %s< / th > < / tr > ", SecondToStrTime(round($somaTempo/$somaReg)));
$dataRel[] = "< / table > ";
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaHtml() {
}
protected function ___PreparaPdf() {
list($this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"];
$dadosCabecalio = array(
'Agente' => 'C',
'Quantidade' => 'C',
'TMA' => 'C'
);
$dadosField = array(
'agente' => 'C',
'quant' => 'C',
'tma' => 'C'
);
$somaReg = 0;
$somaTempo = 0;
$x = 0;
$dados = $this->GetData()[0];
/*
* Linhas de dados.
*/
foreach ($dados as $row) {
$somaReg += $row['quant'];
$somaTempo += $row['tempo'];
$dados[$x]['tma'] = SecondToStrTime(round($row['tempo']/$row['quant']));
$x++;
}
$widthHeader = array(60, 60, 60);
$totaliza = array("Geral: ", $somaReg, SecondToStrTime(round($somaTempo/$somaReg)));
$table = array($dadosCabecalio, $dadosField, $dados, $widthHeader, $totaliza, 0);
$this->___dataRel = array($table);
}
public function ExecutaRelatorio() {
global $jsStartup, $jsJQuery, $smarty;
try {
/*
* Use esta fun<EFBFBD> <EFBFBD> o para validar dados do formul<EFBFBD> rio.
*/
$this->___ValidaForm();
/*
* Recupera os dados do banco.
*/
$this->___ConteudoRelatorio();
/*
* Imprime relat<EFBFBD> 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<EFBFBD> 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');
}
}
$relTransferAgente = new RelTrasfAgente($idProg, $dbcon, 0);
$relTransferAgente->ExecutaRelatorio();
?>