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.
 
 
 
 
 
 

383 lines
14 KiB

<?php
include_once 'util/relatoriosBase.php';
class RelRealizaChamada extends Relatorios {
private $___empresa;
private $___telefone;
private $___quantidade;
public function __construct($idProg, $dbcon, $incDac) {
parent::__construct($idProg, $dbcon, $incDac);
$this->___empresa = isset($_POST['emp_id']) ? $_POST['emp_id'] : 0;
$this->___telefone = isset($_POST['telefone']) ? $_POST['telefone'] : '';
$this->___quantidade = isset($_POST['quantidade']) ? $_POST['quantidade'] : '';
}
function ___ValidaForm() {
}
function ___FiltrosRelatorio() {
if ($this->___media != MEDIA_PRINT_GRID) {
/*
* Recupera os filtros da sess�o do usu�rio.
*/
list($this->___empresa, $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();
$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>';
$filtro .= '<td>Data Inicial</td>';
$filtro .= '<td>Data Final </td>';
$filtro .= '<td>Empresa</td>';
$filtro .= '<td>Telefone</td>';
$filtro .= '<td>Quantidade </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>';
$filtro .= sprintf('<td>%s</td>', $this->getEmpresa($this->___empresa));
$filtro .= sprintf('<td><input name="telefone" id="telefone" type="text" size="15" value="%s" /></td>', $this->___telefone);
$filtro .= sprintf('<td>%s</td>', $this->getQuantidade($this->___quantidade));
$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 emissao dos relatorios para impressao.
*/
$_SESSION["SSstorageFiltros"] = array($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio);
return sprintf($filtro, $this->___dataIni, $this->___dataFim, $lkPrint);
}
protected function ___GetDadosDb() {
$dataIni = FormatDtMssql($this->___dataIni);
$dataFim = FormatDtMssql($this->___dataFim);
$query = "SELECT b.emp_id, emp_nome_fantasia, emp_razao_social, chm_data_bilhete, chm_dst, COUNT(chm_dst) AS chm_quantidade FROM vds_chamadas a
INNER JOIN vds_empresas b ON b.emp_id = a.emp_id
INNER JOIN vds_classificacoes c ON c.uid = a.uid
WHERE a.chm_data_bilhete >= '{$dataIni}'
AND a.chm_data_bilhete <= '{$dataFim}' ";
if (!$this->___empresa) {
$query .= " AND a.emp_id IN(SELECT emp_id FROM vds_empresas WHERE emp_status = 0) ";
} else {
$query .= " AND a.emp_id = {$this->___empresa} ";
}
if ($this->___telefone) {
$query .= " AND chm_dst = '{$this->___telefone}'";
}
$query .= " AND chm_evento IN ('COMPLETACALLER', 'COMPLETAAGENT')
AND clas_descricao = 'VENDA'
GROUP BY b.emp_id, emp_nome_fantasia, emp_razao_social,chm_data_bilhete, chm_dst
ORDER BY chm_data_bilhete, emp_id desc ";
$result = $this->___GetQuery($query);
$row = pg_fetch_all($result);
$this->SetData($row ? $row : array());
}
protected function ___PreparaCsv() {
$dataRel = array();
$filtro = $this->___FiltrosRelatorio();
$dataRel[] = GenerateCsvFromArray($filtro);
$dadosCabecalio = array('Data', 'Empresa', 'Destino', 'Chamadas');
$dadosField = array('chm_data_bilhete', 'emp_nome_fantasia', 'chm_dst', 'chm_quantidade');
$dataRel[] = GenerateCsvFromArray(array_keys($dadosCabecalio));
$somaReg = 0;
/*
* Inicia o relat�rio.
*/
foreach ($this->GetData()[0] as $row) {
if ($row['chm_quantidade'] >= $this->___quantidade) {
$somaReg++;
$row['chm_data_bilhete'] = date('d/m/Y', strtotime($row['chm_data_bilhete']));
$linha = array();
foreach ($dadosField as $key => $value) {
$linha[] = $row["$key"];
}
$dataRel[] = GenerateCsvFromArray($linha);
}
}
$dataRel[] = $linha;
$linha1 = array('Total', '', '', 'Registros: ' . $somaReg);
$dataRel[] = GenerateCsvFromArray($linha1);
$dataRel[] = $linha1;
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaExcel() {
$dataRel = array();
$filtro = $this->___FiltrosRelatorio();
/*
* 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', 'Empresa', 'Destino', 'Chamadas');
$dadosField = array('chm_data_bilhete', 'emp_nome_fantasia', 'chm_dst', 'chm_quantidade');
/*
* Monta a linha de cabecalio.
*/
$linha = array('LABEL');
foreach ($dadosCabecalio as $value) {
$linha[] = $value;
}
$dataRel[] = $linha;
$somaReg = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
if ($row['chm_quantidade'] >= $this->___quantidade) {
$somaReg++;
$row['chm_data_bilhete'] = date('d/m/Y', strtotime($row['chm_data_bilhete']));
// Formata linha de dados.
$linha = array('DADOS');
foreach ($dadosField as $key) {
$linha[] = $row["$key"];
}
$dataRel[] = $linha;
}
}
$linha = array('LABEL', 'Total', '', '', 'Registros: ' . $somaReg);
$dataRel[] = $linha;
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaGrid() {
$dataRel = array();
$dadosCabecalio = array(
'Data' => 'align="center"',
'Empresa' => 'align="center"',
'Destino' => 'align="center"',
'Chamadas' => 'align="center"'
);
$dadosField = array(
'chm_data_bilhete' => 'align="center"',
'emp_nome_fantasia' => 'align="center"',
'chm_dst' => 'align="center"',
'chm_quantidade' => 'align="center"'
);
/*
* Inicia o relat�rio.
*/
$dataRel[] = '<table width="60%" 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), (!IsPostBack() ? 'Informe os parametros e clique em consultar!' : 'Nenhum registro encontado!'));
$this->___dataRel[] = $dataRel;
return;
}
$somaReg = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
if ($row['chm_quantidade'] >= $this->___quantidade) {
$somaReg++;
$row['chm_data_bilhete'] = date('d/m/Y', strtotime($row['chm_data_bilhete']));
// 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 = '<tr><th colspan="2" align="left">Total</th><th align="left" colspan="2">Registros: %s</th></tr>';
$dataRel[] = sprintf($linha, $somaReg);
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaHtml() {
}
protected function ___PreparaPdf() {
list($this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"];
$dados = $this->GetData()[0];
$somaReg = 0;
foreach ($dados as $key => $row) {
if ($row['chm_quantidade'] >= $this->___quantidade) {
$somaReg++;
$dados[$key]["chm_data_bilhete"] = date('d/m/Y H', strtotime($row["chm_data_bilhete"]));
}
}
$header = array(
'Data' => 'C',
'Empresa' => 'C',
'Destino' => 'C',
'Chamadas' => 'C'
);
$dataHeader = array(
'chm_data_bilhete' => 'C',
'emp_nome_fantasia' => 'C',
'chm_dst' => 'C',
'chm_quantidade' => 'C'
);
$widthHeader = array(50, 50, 50, 50);
$totaliza = array('Total', "Registros: ", $somaReg, '', '');
//Monta o array para passar para o prepara; Necessário passar 6 parametros
$table1 = array($header, $dataHeader, $dados, $widthHeader, $totaliza, 0);
$this->___dataRel = array($table1);
}
private function getEmpresa($codEmpresa) {
$query = "SELECT emp_id, emp_nome_fantasia FROM vds_empresas WHERE emp_status = 0 ";
$query .= " order by emp_nome_fantasia";
$result = pg_query($query);
$data = pg_fetch_all($result);
$opt = "<select name='emp_id'>";
$opt .= sprintf("<option value='0'%s> --------------- </option>", (!$codEmpresa ? ' selected ' : ''));
foreach ($data as $value) {
$opt .= sprintf('<option value="%s"%s>%s</option>', $value['emp_id'], ($value['emp_id'] == $codEmpresa ? ' selected ' : ''), $value['emp_nome_fantasia']);
}
$opt .= "</select>";
return $opt;
return $data;
}
private function getQuantidade($select = false) {
$opt = "<select name='quantidade'>";
for ($x = 1; $x <= 15; $x++) {
$opt .= "<option value='$x' " . ($select == $x ? 'selected' : '') . "> >= $x</option>";
}
$opt .= "</select>";
return $opt;
}
public function ExecutaRelatorio() {
global $jsStartup, $jsJQuery, $smarty;
try {
/*
* Formata as linha da função date
*/
setlocale(LC_ALL, "pt_BR", "pt_BR.iso-8859-1", "pt_BR.utf-8", "portuguese");
/*
* 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();
}
/*
* 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('msg', $this->GetMsg());
GetTemplate($smarty, 'relatoriosGrid.tpl');
}
}
$relMetricasDiaria = new RelRealizaChamada($idProg, $dbcon, 1);
$relMetricasDiaria->ExecutaRelatorio();
?>