<?php
include_once 'util/relatoriosBase.php';
class RelOriginadasAgente extends Relatorios {
private $___tipoAtendimento;
private $___agente;
public function __construct($idProg, $dbcon, $incDac) {
parent::__construct($idProg, $dbcon, $incDac);
$this->___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<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 > Tipo Atendimento< / 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 > < div class = "geral" > ';
$filtro .= sprintf('< input name = "tipoAtendimento" class = "clean" type = "radio" id = "tipoAtendimento" value = "1" % s > Ambas'
. '< input name = "tipoAtendimento" class = "clean" type = "radio" id = "tipoAtendimento" value = "2" % s > Atendidas'
. '< input name = "tipoAtendimento" class = "clean" type = "radio" id = "tipoAtendimento" value = "3" % s > N<EFBFBD> o Atendidas', $this->___tipoAtendimento == 1 ? 'checked' : '', $this->___tipoAtendimento == 2 ? 'checked' : '', $this->___tipoAtendimento == 3 ? 'checked' : '');
$filtro .= '< / div > < / 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 = 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<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', '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<EFBFBD> rio.
*/
$dataRel[] = '< table width = "90%" cellpadding = "2" class = "grid" > ';
/*
* Monta a linha de cabecalio.
*/
$linha = '< tr > ';
foreach ($dadosCabecalio as $key => $value) {
$linha .= sprintf("< th % s > %s< / th > ", $value, $key);
}
$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;
}
$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<EFBFBD> o Atendida";
// Formata linha de dados.
$linha = "< tr > ";
foreach ($dadosField as $key => $value) {
$linha .= sprintf("< td % s > %s< / td > ", $value, $row["$key"]);
}
$linha .= "< / tr > ";
$dataRel[] = $linha;
}
/*
* Linha de totalizacao.
*/
$linha = '< tr > < th align = "left" colspan = "6" > TMO: %s < / th > < / tr > ';
$dataRel[] = sprintf($linha, SecondToStrTime(round($somaDuracao / $somaReg)));
/*
* Fecha relatorio.
*/
$dataRel[] = '< / table > ';
$dataRel[] = '< br > < table width = "20%" cellpadding = "2" class = "grid" > ';
$dataRel[] = sprintf('< tr > < th colspan = "2" > Totaliza<EFBFBD> <EFBFBD> o Geral< / th > < / tr > '
. '< tr > < th align = "left" > Atendidas< / th > < td > %s< / td > < / tr > '
. '< tr > < th align = "left" > N<EFBFBD> o Atendidas< / th > < td > %s< / td > < / tr > '
. '< tr > < th align = "left" > Geral< / th > < td > %s< / td > < / tr > ', $somaAtendida, $somaNAtendida, $somaReg);
$dataRel[] = '< / table > ';
$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<EFBFBD> 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<EFBFBD> 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 = "< select name = \"listaAgente\" id = \"listaAgente\" size = \"1\" > ";
$row .= "< option value = \"0\" $ sel > Todos< / option > ";
foreach ($fltAgentes as $agts) {
$selected = $agts == $this->___agente ? "selected" : '';
$row .= sprintf("< option value = \"%s\" % s > %s< / option > ", $agts, $selected, $agts);
}
$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');
}
}
$relOriginadasAgente = new RelOriginadasAgente($idProg, $dbcon, 1);
$relOriginadasAgente->ExecutaRelatorio();
?>