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.

626 lines
26 KiB

<?php
include_once 'util/relatoriosBase.php';
class RelForaHorario extends Relatorios {
private $___tipoRelatorio;
2 years ago
private $___atendimento;
public function __construct($idProg, $dbcon, $incDac) {
parent::__construct($idProg, $dbcon, $incDac);
$this->___tipoRelatorio = isset($_REQUEST['relTipo']) ? $_REQUEST['relTipo'] : 0;
2 years ago
$this->___atendimento = isset($_REQUEST['atendimento']) ? $_REQUEST['atendimento'] : 0;
}
function ___FiltrosRelatorio() {
if ($this->___media != MEDIA_PRINT_GRID) {
/*
* Recupera os filtros da sess<EFBFBD>o do usu<EFBFBD>rio.
*/
list($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 opera<EFBFBD><EFBFBD>es de filtro.
*/
$filtro = '<table border="0" cellspacing="1" cellpadding="1">';
/*
* Rotulos.
*/
$filtro .= '<tr>';
$filtro .= '<td>Data Inicial</td>';
$filtro .= '<td>Data Final </td>';
2 years ago
$filtro .= $this->___tipoRelatorio ? '<td>Op<EFBFBD><EFBFBD>o</td>' : '';
$filtro .= '<td> <input name="relTipo" type="checkbox" id="relTipo" value="1" %s />Anal&iacute;tico</td>';
$filtro .= '<td align="center" valign="middle">&nbsp;</td>';
$filtro .= '</tr>';
/*
* Valores.
*/
$filtro .= '<tr>';
$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>';
2 years ago
$filtro .= $this->___tipoRelatorio ? sprintf('<td>%s</td>', $this->getAtendimento()) : '';
$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, $this->___tipoRelatorio);
return sprintf($filtro, $tipoRel, $this->___dataIni, $this->___dataFim, $lkPrint);
}
protected function ___GetDadosDb() {
$dataIni = FormatDtMssql($this->___dataIni);
$dataFim = FormatDtMssql($this->___dataFim);
$tipoRel = $this->___tipoRelatorio;
if ($tipoRel) {
2 years ago
$query = "select b.calldate as data, b.src as origem, dest.destino as destino,
coalesce(opcs.name, RetornaOpcao(atend.direcao)) as servico,
coalesce( opc.descricao || case when( opc.descricao = atend.destino)then '' else '-' || case when(RetornaOpcao(atend.direcao) = 'ura')then sonumero(atend.direcao) else atend.destino end end, atend.destino) as atendimento,
2 years ago
b.duration as duracao, atend.destino as opcao
from pbx_bilhetes b
left outer join pbx_bilhetes_complemento dest on dest.id = (select min(id) from pbx_bilhetes_complemento where uniqueid2 = b.uniqueid)
left outer join pbx_bilhetes_complemento atend on atend.id = (select max(id) from pbx_bilhetes_complemento where uniqueid2 = b.uniqueid)
left outer join pbx_opcao_acao opc on opc.opcao = RetornaOpcao(atend.direcao) and opc.id::text = sonumero(case when(RetornaOpcao(atend.direcao) = 'ura')then atend.direcao else atend.destino end)
left outer join pbx_opcoes opcs on opcs.value = RetornaOpcao(atend.direcao)
where b.fora_horario = '1'
2 years ago
and b.data_bilhete >= '$dataIni'
and b.data_bilhete <= '$dataFim'
and b.tipo_chamada not in (1) ";
2 years ago
$query .= $this->___atendimento ? " and atend.destino = '{$this->___atendimento}'" : '';
$query .= " group by 1, 2, 3, 4, 5, 6, 7
order by b.calldate desc";
} else {
$query = sprintf("select b.src as origem, data_bilhete as data,count(*) as qtde,
sum(b.duration) as duracao
from pbx_bilhetes b
where b.fora_horario = '1'
and b.data_bilhete >= '%s'
and b.data_bilhete <= '%s'
and b.tipo_chamada not in (1)
group by b.src, b.data_bilhete
order by 2", $dataIni, $dataFim);
}
$result = $this->___GetQuery($query);
$row = pg_fetch_all($result);
$this->SetData($row ? $row : array());
}
protected function ___PreparaCsv() {
$dataRel = array();
$filtro = $this->___FiltrosRelatorio();
/*
* Inicia o relat<EFBFBD>rio.
*/
$dataRel[] = GenerateCsvFromArray($filtro);
if (!$this->___tipoRelatorio) {
$dadosCabecalio = array('Data' => 'align="center"', 'Origem' => 'align="left"', 'Quantidade' => 'align="right"', 'Duracao' => 'align="center"');
$dadosField = array('data' => 'align="center"', 'origem' => 'align="left"', 'qtde' => 'align="right"', 'duracao' => 'align="center"');
/*
* Monta a linha de cabecalio.
*/
$dataRel[] = GenerateCsvFromArray(array_keys($dadosCabecalio));
$somaTempo = 0;
$somaReg = 0;
$somaQtde = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$somaTempo += $row["duracao"];
$somaQtde ++;
$somaReg += $row['qtde'];
$row["data"] = date('d/m/Y', strtotime($row["data"]));
$row["duracao"] = SecondToStrTime($row["duracao"]);
// Formata linha de dados.
$linha = array();
foreach ($dadosField as $key => $value) {
$linha[] = $row["$key"];
}
$dataRel[] = GenerateCsvFromArray($linha);
}
$dataRel[] = GenerateCsvFromArray(array('Total: '.$somaQtde,'','Registros: '.$somaReg,'Duracao: '.SecondToStrTime($somaTempo)));
$this->___dataRel[] = $dataRel;
}else{
$dadosCabecalio = array('Data', 'Origem', 'Destino', 'Servico','Atendimento','Duracao');
$dadosField = array('data', 'origem', 'destino', 'servico', 'atendimento','duracao');
/*
* Monta a linha de cabecalio.
*/
$dataRel[] = GenerateCsvFromArray($dadosCabecalio);
$somaTempo = 0;
$somaReg = 0;
$somaQtde = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$somaTempo += $row["duracao"];
$somaQtde ++;
$row["data"] = date('d/m/Y', strtotime($row["data"]));
$row["duracao"] = SecondToStrTime($row["duracao"]);
// Formata linha de dados.
$linha = array();
foreach ($dadosField as $value) {
$linha[] = $row["$value"];
}
$dataRel[] = GenerateCsvFromArray($linha);
}
$dataRel[] = GenerateCsvFromArray(array('Total: '.$somaQtde,'','','','','Duracao: '.SecondToStrTime($somaTempo)));
$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;
if (!$this->___tipoRelatorio) {
$dadosCabecalio = array('Data', 'Origem', 'Quantidade', 'Duracao');
$dadosField = array('data', 'origem', 'qtde', 'duracao');
/*
* Monta a linha de cabecalio.
*/
$linha = array('LABEL');
foreach ($dadosCabecalio as $value) {
$linha[] = $value;
}
$dataRel[] = $linha;
$somaTempo = 0;
$somaReg = 0;
$somaQtde = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$somaTempo += $row["duracao"];
$somaReg += $row["qtde"];
$somaQtde ++;
$row["data"] = date('d/m/Y', strtotime($row["data"]));
$row["duracao"] = SecondToStrTime($row["duracao"]);
// Formata linha de dados.
$linha = array('DADOS');
foreach ($dadosField as $key) {
$linha[] = $row["$key"];
}
$dataRel[] = $linha;
}
$linha = array('LABEL', 'Total: ' . $somaQtde, '', 'Registro: ' . $somaReg, 'Duracao: ' . SecondToStrTime($somaTempo));
$dataRel[] = $linha;
$this->___dataRel[] = $dataRel;
}else{
$dadosCabecalio = array('Data', 'Origem', 'Destino', 'Servico','Atendimento','Duracao');
$dadosField = array('data', 'origem', 'destino', 'servico','atendimento','duracao');
/*
* Monta a linha de cabecalio.
*/
$linha = array('LABEL');
foreach ($dadosCabecalio as $value) {
$linha[] = $value;
}
$dataRel[] = $linha;
$somaTempo = 0;
$somaReg = 0;
$somaQtde = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$somaTempo += $row["duracao"];
$somaQtde ++;
$row["data"] = date('d/m/Y H:i:s', strtotime($row["data"]));
$row["duracao"] = SecondToStrTime($row["duracao"]);
// Formata linha de dados.
$linha = array('DADOS');
foreach ($dadosField as $key) {
$linha[] = $row["$key"];
}
$dataRel[] = $linha;
}
$linha = array('LABEL', 'Total: ' . $somaQtde, '','','','', 'Duracao: ' . SecondToStrTime($somaTempo));
$dataRel[] = $linha;
$this->___dataRel[] = $dataRel;
}
}
protected function ___PreparaGrid() {
$dataRel = array();
if (!$this->___tipoRelatorio) {
$dadosCabecalio = array(
'Data' => 'align="left"',
'Origem' => 'align="left"',
'Quantidade' => 'align="right"',
'Dura<EFBFBD><EFBFBD>o' => 'align="center"'
);
$dadosField = array(
'data' => 'align="left"',
'origem' => 'align="left"',
'qtde' => 'align="right"',
'duracao' => 'align="center"'
);
/*
* Inicia o relat<EFBFBD>rio.
*/
$dataRel[] = '<table width="800" 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;
}
$somaTempo = 0;
$somaReg = 0;
$somaQtde = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$somaTempo += $row["duracao"];
$somaQtde++;
$somaReg += $row['qtde'];
$row['origem'] = ocultarTelefone($row['origem']);
$row["data"] = date('d/m/Y', strtotime($row["data"]));
$row["duracao"] = SecondToStrTime($row["duracao"]);
// 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">Total: %s</th><th colspan="2" align="right">Registros: %s</th><th align="center">Dura<EFBFBD><EFBFBD>o: %s</th></tr>';
$dataRel[] = sprintf($linha, $somaQtde, $somaReg, SecondToStrTime($somaTempo));
/*
* Fecha relatorio.
*/
$dataRel[] = '</table>';
$this->___dataRel[] = $dataRel;
}else{
$dadosCabecalio = array(
'Data' => 'align="left"',
'Origem' => 'align="left"',
'Destino' => 'align="left"',
'Servi<EFBFBD>o' => 'align="left"',
'Atendimento' => 'align="left"',
'Dura<EFBFBD><EFBFBD>o' => 'align="center"'
);
$dadosField = array(
'data' => 'align="left"',
'origem' => 'align="left"',
'destino' => 'align="left"',
'servico' => 'align="left"',
'atendimento' => 'align="left"',
'duracao' => 'align="center"'
);
/*
* Inicia o relat<EFBFBD>rio.
*/
$dataRel[] = '<table width="800" 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;
}
$somaTempo = 0;
$somaQtde = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$somaTempo += $row["duracao"];
$somaQtde++;
$row['origem'] = ocultarTelefone($row['origem']);
$row['destino'] = ocultarTelefone($row['destino']);
$row["data"] = date('d/m/Y H:i:s', strtotime($row["data"]));
$row["duracao"] = SecondToStrTime($row["duracao"]);
// 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">Total: %s</th><th colspan="4" align="left"></th><th align="center">Dura<EFBFBD><EFBFBD>o: %s</th></tr>';
$dataRel[] = sprintf($linha, $somaQtde, SecondToStrTime($somaTempo));
/*
* Fecha relatorio.
*/
$dataRel[] = '</table>';
$this->___dataRel[] = $dataRel;
}
}
protected function ___PreparaHtml() {
}
protected function ___PreparaPdf() {
list($this->___dataIni, $this->___dataFim, $this->___tipoRelatorio) = $_SESSION["SSstorageFiltros"];
/**
* TABELA DADOS PRINCIPAIS
*/
$somaQtd = 0;
$somaTempo = 0;
$somaReg = 0;
$dados = array();
$x = 0;
if (!$this->___tipoRelatorio) {
foreach ($this->GetData()[0] as $row) {
$somaQtd ++;
$somaReg += $row['qtde'];
$somaTempo += $row["duracao"];
$dados[$x]['data'] = date('d/m/Y', strtotime($row["data"]));
$dados[$x]['duracao'] = SecondToStrTime($row["duracao"]);
$dados[$x]['qtde'] = $row["qtde"];
$dados[$x]['origem'] = $row["origem"];
$x++;
}
//HEADER DA TABELA DO PDF -> DADOS EM ARRAY
$header = array(
'Data' => 'L',
'Origem' => 'L',
'Quantidade' => 'C',
'Dura<EFBFBD><EFBFBD>o' => 'C'
);
$dataHeader = array(
'data' => 'L',
'origem' => 'L',
'qtde' => 'C',
'duracao' => 'C'
);
$widthHeader = array(50, 50, 40, 50);
$totaliza = array(
"Total: $somaQtd", '', 'Registros: ' . $somaReg, "Dura<EFBFBD><EFBFBD>o: " . SecondToStrTime($somaTempo));
//Monta o array para passar para o prepara; Necess<EFBFBD>rio passar 6 parametros
$table1 = array($header, $dataHeader, $dados, $widthHeader, $totaliza, 0);
$this->___dataRel = array($table1);
}else{
foreach ($this->GetData()[0] as $row) {
$somaQtd ++;
$somaTempo += $row["duracao"];
$dados[$x]['data'] = date('d/m/Y H:i:s', strtotime($row["data"]));
$dados[$x]['duracao'] = SecondToStrTime($row["duracao"]);
$dados[$x]['atendimento'] = $row["atendimento"];
$dados[$x]['origem'] = $row["origem"];
$dados[$x]['servico'] = $row["servico"];
$dados[$x]['destino'] = $row["destino"];
$x++;
}
//HEADER DA TABELA DO PDF -> DADOS EM ARRAY
$header = array(
'Data' => 'C',
'Origem' => 'C',
'Destino' => 'C',
'Servi<EFBFBD>o' => 'C',
'Atendimento' => 'C',
'Dura<EFBFBD><EFBFBD>o' => 'C'
);
$dataHeader = array(
'data' => 'C',
'origem' => 'C',
'destino' => 'C',
'servico' => 'C',
'atendimento' => 'C',
'duracao' => 'C'
);
$widthHeader = array(40, 35, 35, 25, 25, 30);
$totaliza = array(
"Total: $somaQtd", '','','','', "Dura<EFBFBD><EFBFBD>o: " . SecondToStrTime($somaTempo));
//Monta o array para passar para o prepara; Necess<EFBFBD>rio passar 6 parametros
$table1 = array($header, $dataHeader, $dados, $widthHeader, $totaliza, 0);
$this->___dataRel = array($table1);
}
}
2 years ago
public function getAtendimento(){
if($this->___tipoRelatorio){
if(!$this->___atendimento){
unset($_SESSION['SSOpcaoForaHor']);
$_SESSION['SSOpcaoForaHor'] = $this->GetData()[0];
}
$vst = [];
$select = "<select name='atendimento' id='atendimento' size='1'>";
$select .= "<option value='0'>-----------</option>";
foreach($_SESSION['SSOpcaoForaHor'] as $v){
$slc = null;
if(!in_array($v['opcao'], $vst)){
if($this->___atendimento == $v['opcao']){
$slc = 'selected';
}
$select .= "<option value='{$v['opcao']}' $slc>{$v['opcao']}</option>";
$vst[] = $v['opcao'];
}
}
$select .= "</select>";
return $select;
}
}
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');
}
}
$relForaHorario = new RelForaHorario($idProg, $dbcon, 0);
$relForaHorario->ExecutaRelatorio();
?>