<?php
include_once 'util/relatoriosBase.php';
class RelRecebidasAgente extends Relatorios {
private $___agente;
private $___tempoAtendimento;
public function __construct($idProg, $dbcon, $incDac) {
parent::__construct($idProg, $dbcon, $incDac);
$this->___dac = isset($_POST['listaDacs']) ? $_POST['listaDacs'] : 0;
$this->___tempoAtendimento = isset($_POST['tempoAtendimento']) ? $_POST['tempoAtendimento'] : '';
$this->___agente = isset($_POST["listaAgente"]) ? $_POST["listaAgente"] : 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<EFBFBD> <EFBFBD> o maior que 10 segundos!');
}
}
function ___FiltrosRelatorio() {
$agente = $this->___GetAgente();
if ($this->___media != MEDIA_PRINT_GRID) {
/*
* Recupera os filtros da sess<EFBFBD> o do usu<EFBFBD> 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<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 op<EFBFBD> <EFBFBD> es de filtro.
*/
$filtro = '< table border = "0" cellspacing = "1" cellpadding = "1" > ';
/*
* Rotulos.
*/
$filtro .= '< tr > ';
if ($this->GetIncDac())
$filtro .= '< td > Fila< / td > ';
$filtro .= '< td > Data Inicial< / td > ';
$filtro .= '< td > Data Final < / td > ';
$filtro .= '< td > Agente< / td > ';
$filtro .= '< td > Dura<EFBFBD> <EFBFBD> o (Segundos)< / td > ';
$filtro .= '< td align = "center" valign = "middle" > < / td > ';
$filtro .= '< / tr > ';
/*
* Valores.
*/
$filtro .= '< tr > ';
if ($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 .= sprintf('< td > %s< / td > ', $agente);
$filtro .= "< td > < input name = \"tempoAtendimento\" type = \"text\" id = \"tempoAtendimento\" size = '10' value = '{$this->___tempoAtendimento}' / > < / 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> ios para impress<EFBFBD> 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);
$agente = $this->___agente;
$dac = $this->___dac;
$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";
$query2 = "SELECT DISTINCT c.matricula, c.apelido";
$query = " 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.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) {
$query .= "AND c.matricula = '$agente'";
}
$sqlTempo = $this->___tempoAtendimento & & $this->___tempoAtendimento > 10 ? " AND strtoint(b.param2) >= ".$this->___tempoAtendimento : '';
$result = $this->___GetQuery($query1 . $query . $sqlTempo ." ORDER BY 1 ");
$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);
$dadosCabecalio = array(
'Data', 'Hora', 'Origem', 'TMA', 'Agente', 'Status'
);
$dadosField = array(
'data', 'hora', 'origem', 'tmo', 'agente', 'status'
);
$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<EFBFBD> o Atendida";
$linha = array();
foreach ($dadosField as $key) {
$linha[] = $row["$key"];
}
$dataRel[] = GenerateCsvFromArray($linha);
}
$dataRel[] = GenerateCsvFromArray(array('TMO', 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();
/*
* 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(
'Data', 'Hora', 'Origem', 'TMA', 'Agente', 'Status'
);
$dadosField = array(
'data', 'hora', 'origem', 'tmo', 'agente', 'status'
);
$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<EFBFBD> o Atendida";
$linha = array('DADOS');
foreach ($dadosField as $key) {
$linha[] = $row["$key"];
}
$dataRel[] = $linha;
}
$dataRel[] = array('LABEL', 'TMO', 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();
$dadosCabecalio = array(
'Data' => 'align="center"',
'Hora' => 'align="center"',
'Origem' => 'align="center"',
'TMA' => '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"'
);
/*
* 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 = \"6\" > Chamadas Recebidas 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;
$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['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<EFBFBD> o Atendida";
$linha = "< tr > ";
foreach ($dadosField as $key => $value) {
$linha .= sprintf("< td % s > %s< / td > ", $value, $row["$key"]);
}
$linha .= "< / tr > ";
$dataRel[] = $linha;
}
$linhaGeral = '< tr > < th colspan = "2" align = "right" > TMO: < / th > < th colspan = "4" align = "left" > %s< / th > < / tr > ';
$dataRel[] = sprintf($linhaGeral, SecondToStrTime($somaDuracao));
/*
* Fecha relatorio.
*/
$dataRel[] = '< / table > ';
$linha = '< br > < table width = "30%" cellpadding = "2" class = "grid" > ';
$linha .= "< tr > < th colspan = \"2\" > Totalizador< / th > < / tr > ";
$linha .= "< tr > "
. "< th align = \"left\" > Atendida: < / th > "
. "< td > $somaAtendida< / td > "
. "< tr > < th align = \"left\" > N<EFBFBD> o Atendida:< / th > "
. "< td > $somaNAtendida< / td > < / tr > "
. "< tr > < th align = \"left\" > Geral:< / th > "
. "< td > $somaReg< / td > < / tr > "
. "< / tr > ";
$linha .= '< / table > ';
$dataRel[] = $linha;
$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',
'Origem' => 'C',
'TMA' => 'C',
'Agente' => 'C',
'Status' => 'C'
);
$dadosField = array(
'data' => 'C',
'hora' => 'C',
'origem' => 'C',
'tmo' => 'C',
'agente' => 'C',
'status' => 'C'
);
$dados = $this->GetData()[0];
$somaReg = 0;
$somaDuracao = 0;
$somaAtendida = 0;
$somaNAtendida = 0;
$x = 0;
/*
* Linhas de dados.
*/
foreach ($dados as $row) {
$somaReg ++;
$somaDuracao += $row['tmo'];
$dados[$x]['status'] == 1 ? $somaAtendida++ : $somaNAtendida++;
$dados[$x]['hora'] = date('H:i:s', 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<EFBFBD> o Atendida";
$x++;
}
$widthHeader = array(32, 32, 32, 32, 32, 32);
$totaliza = array('TMO', SecondToStrTime($somaDuracao), '', '', '', '');
$table = array($dadosCabecalio, $dadosField, $dados, $widthHeader, $totaliza, 0);
$legendaCabecalio = array(
"Atendida" => 'C',
"N<EFBFBD> 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 = "< select name = \"listaAgente\" > ";
!$result ? $row .= "< option value = \"0\" > ----- < / option > " : $row .= "< option value = \"0\" > Todos< / option > ";
foreach ($result as $agentes) {
$sel = $this->___agente == $agentes['matricula'] ? "selected" : '';
$row .= sprintf("< option value = \"%s\" $ sel > %s< / option > ", $agentes['matricula'], $agentes['apelido']);
}
$row .= "< / select > ";
return $row;
}
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');
}
}
$relRecebidasAgente = new RelRecebidasAgente($idProg, $dbcon, 1);
$relRecebidasAgente->ExecutaRelatorio();
?>