PABX da Simples IP
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

624 lines
24 KiB

<?php
include_once 'util/relatoriosBase.php';
class RelRecebidasAgenteSrv extends Relatorios {
private $___agente;
private $___tempoAtendimento;
private $___servico;
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;
$this->___servico = isset($_POST["listaServico"]) ? $_POST["listaServico"] : 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ção maior que 10 segundos!');
}
}
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 = '<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ção se necessitar de outras op��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>';
if (GetUsoServico()) {
$filtro .= '<td>Serviço </td>';
}
$filtro .= '<td>Agente</td>';
$filtro .= '<td>Duração (Segundos)</td>';
$filtro .= '<td align="center" valign="middle">&nbsp;</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>';
if (GetUsoServico()) {
$filtro .= sprintf('<td>%s</td>', GetIdentRota(false, $this->___servico));
}
$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ã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 = FormatDtHoraBD($this->___dataFim);
$srv = $this->___servico;
$agente = $this->___agente;
$dac = $this->___dac;
$mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA;
$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" . ($mostraColunaServicos ? ", s.serv_id" : "");
$query2 = "SELECT DISTINCT c.matricula, c.apelido";
$query = " 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)";
if (GetUsoServico()) {
$query .= " left join pbx_servicos_registra s on s.uniqueid = a.uniqueid";
}
$query .= " WHERE 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) {
$addAgente = "\nAND c.matricula = '$agente'";
}
if (GetUsoServico() && $srv) {
$query .= "\nAND s.serv_id = '{$srv}'";
}
$sqlTempo = $this->___tempoAtendimento && $this->___tempoAtendimento > 10 ? "\nAND strtoint(b.param2) >= " . $this->___tempoAtendimento : '';
$query1 = ($query1 . $query . $addAgente . $sqlTempo . sprintf("\nORDER BY %s ", $mostraColunaServicos ? 's.serv_id, a.calldate' : 'a.calldate'));
$result = $this->___GetQuery($query1);
$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);
$mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA;
$dadosCabecalio = array(
'Data', 'Hora', 'Origem', 'Tempo', 'Agente', 'Status'
);
$dadosField = array(
'data', 'hora', 'origem', 'tmo', 'agente', 'status'
);
if ($mostraColunaServicos) {
$dadosCabecalio = array_merge(['Servico'], $dadosCabecalio);
$dadosField = array_merge(['serv_id'], $dadosField);
}
$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ão Atendida";
$linha = array();
foreach ($dadosField as $key) {
$linha[] = $row["$key"];
}
$dataRel[] = GenerateCsvFromArray($linha);
}
$dataRel[] = GenerateCsvFromArray(array('DURAÇÃO', 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();
$mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA;
/*
* 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(
'Data', 'Hora', 'Origem', 'Tempo', 'Agente', 'Status'
);
$dadosField = array(
'data', 'hora', 'origem', 'tmo', 'agente', 'status'
);
if ($mostraColunaServicos) {
$dadosCabecalio = array_merge(['Servico'], $dadosCabecalio);
$dadosField = array_merge(['serv_id'], $dadosField);
}
$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ão Atendida";
$linha = array('DADOS');
foreach ($dadosField as $key) {
$linha[] = $row["$key"];
}
$dataRel[] = $linha;
}
$dataRel[] = array('LABEL', 'DURAÇÃO', 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();
$mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA;
$dadosCabecalio = array(
'Data' => 'align="center"',
'Hora' => 'align="center"',
'Origem' => 'align="center"',
'DURAÇÃO' => '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"'
);
if ($mostraColunaServicos) {
$dadosCabecalio = array_merge(['Serviço' => 'align="center"'], $dadosCabecalio);
$dadosField = array_merge(['serv_id' => 'align="left"'], $dadosField);
}
/*
* Inicia o relatório.
*/
$dataRel[] = '<table width="70%" cellpadding="2" class="grid">';
/*
* Monta a linha de cabecalio.
*/
$linha = '<tr>';
$linha .= sprintf("<th align=\"center\" colspan=\"%s\">Chamadas Recebidas por Agente</th>", ($mostraColunaServicos ? '7' : '6'));
$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(1) - 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;
$somaAtendidaServico = 0;
$somaNAtendida = 0;
$somaNAtendidaServico = 0;
$somaDuracaoServico = 0;
$srv = "";
$oldSrv = "";
$tmo = 0;
$agrupaServico = function($row) use(&$somaDuracaoServico, &$somaAtendidaServico, &$somaNAtendidaServico, &$dataRel, &$srv, &$oldSrv) {
$style = 'style="font-weight: bold; padding: 0; margin: 0; padding-left: 6px; padding-right: 6px; background-color: #4F71C0 !important"';
$srv = $row["serv_id"];
if (!$oldSrv) {
$oldSrv = $srv;
}
if ((($srv != $oldSrv)) || !$row) {
$dataRel[] = sprintf("<tr><th colspan=\"3\" align=\"center\" {$style}>Total [%s] </th><th colspan=\"1\" align=\"center\" {$style}>DURAÇÃO</th><th colspan=\"1\" align=\"center\" {$style}>%s</th><th colspan=\"1\" align=\"center\" {$style}>ATENDIDAS / NA</th><th colspan=\"1\" align=\"center\" {$style}>%s / %s</th></tr>", $oldSrv, SecondToStrTime($somaDuracaoServico), $somaAtendidaServico, $somaNAtendidaServico);
$oldSrv = $srv;
$somaDuracaoServico = 0;
$somaAtendidaServico = 0;
$somaNAtendidaServico = 0;
}
$somaDuracaoServico += $row['tmo'];
$row['status'] == 1 ? $somaAtendidaServico++ : $somaNAtendidaServico++;
};
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
if ($mostraColunaServicos) {
$agrupaServico($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ão Atendida";
$linha = "<tr>";
foreach ($dadosField as $key => $value) {
$linha .= sprintf("<td %s>%s</td>", $value, $row["$key"]);
}
$linha .= "</tr>";
$dataRel[] = $linha;
}
if ($mostraColunaServicos) {
$agrupaServico(false);
}
$linhaGeral = '<tr><th colspan="%s" align="center">TOTAL GERAL</th><th colspan="1" align="center">DURAÇÃO</th><th colspan="1" align="center">%s</th><th colspan="1" align="center">ATENDIDAS / NA</th><th colspan="1" align="center">%s / %s</th></tr>';
$dataRel[] = sprintf($linhaGeral, ($mostraColunaServicos ? '3' : '2'), SecondToStrTime($somaDuracao), $somaAtendida, $somaNAtendida);
/*
* 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ã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"];
$mostraColunaServicos = GetUsoServico() == RELATORIO_SERVICOS_HABILITA;
$dadosCabecalio = array(
'Data' => 'C',
'Hora' => 'C',
'Origem' => 'C',
'Tempo' => 'C',
'Agente' => 'C',
'Status' => 'C'
);
$dadosField = array(
'data' => 'C',
'hora' => 'C',
'origem' => 'C',
'tmo' => 'C',
'agente' => 'C',
'status' => 'C'
);
if ($mostraColunaServicos) {
$dadosCabecalio = array_merge(['Serviço' => 'C'], $dadosCabecalio);
$dadosField = array_merge(['serv_id' => 'C'], $dadosField);
}
$dados = $this->GetData()[0];
$somaReg = 0;
$somaDuracao = 0;
$somaAtendida = 0;
$somaNAtendida = 0;
$x = 0;
$somaAtendidaServico = 0;
$somaNAtendidaServico = 0;
$somaDuracaoServico = 0;
$srv = "";
$oldSrv = "";
$dadosTable = [];
$agrupaServico = function($row) use(&$somaDuracaoServico, &$somaAtendidaServico, &$somaNAtendidaServico, &$dadosTable, &$srv, &$oldSrv) {
$srv = $row["serv_id"];
if (!$oldSrv) {
$oldSrv = $srv;
}
if ((($srv != $oldSrv)) || !$row) {
$data = [];
$data['serv_id'] = ' ';
$data['data'] = 'TOTAL';
$data['hora'] = ' ';
$data['origem'] = 'Duração';
$data['tmo'] = SecondToStrTime($somaDuracaoServico);
$data['agente'] = 'ATENDIDAS / NA';
$data['status'] = "$somaAtendidaServico / $somaNAtendidaServico";
$data['cor_linha_dados'] = "225";
$oldSrv = $srv;
$somaDuracaoServico = 0;
$somaAtendidaServico = 0;
$somaNAtendidaServico = 0;
$dadosTable[] = $data;
}
$somaDuracaoServico += $row['tmo'];
$row['status'] == 1 ? $somaAtendidaServico++ : $somaNAtendidaServico++;
};
/*
* Linhas de dados.
*/
foreach ($dados as $row) {
if ($mostraColunaServicos) {
$agrupaServico($row);
}
$somaReg ++;
$somaDuracao += $row['tmo'];
$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ão Atendida";
$row['status'] == 1 ? $somaAtendida++ : $somaNAtendida++;
$dadosTable[] = $row;
}
if ($mostraColunaServicos) {
$agrupaServico(false);
$widthHeader = array(26, 26, 26, 26, 26, 26, 26);
} else {
$widthHeader = array(26, 26, 26, 26, 26, 26);
}
$totaliza = $mostraColunaServicos ? array('DURAÇÃO', SecondToStrTime($somaDuracao), '', '', '', '', '') : array('DURAÇÃO', SecondToStrTime($somaDuracao), '', '', '', '');
$table = array($dadosCabecalio, $dadosField, $dadosTable, $widthHeader, $totaliza, 0);
$legendaCabecalio = array(
"Atendida" => 'C',
"Nã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çã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();
}
$legendas = '<strong>* C.I.E.I.V:</strong> CHAMADAS INTERNAS/EMERGENCIA/INTERNACIONAL/VOIP.';
/*
* 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('legendas', $legendas);
$smarty->assign('msg', $this->GetMsg());
GetTemplate($smarty, 'relatoriosGrid.tpl');
}
}
$relRecebidasAgente = new RelRecebidasAgenteSrv($idProg, $dbcon, 1);
$relRecebidasAgente->ExecutaRelatorio();
?>