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.

195 lines
7.1 KiB

<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* carregar controles prepara relat<EFBFBD>rio
*/
//variaveis para manter o estado
$inRel = 0;
if ($_POST["btConsulta"]) {
//print "listaAgente: " . $_SESSION["listaSites"] ." - ". $_POST["listaSites"];
$trocaDac = $_SESSION["listaSites"] != $_POST["listaSites"];
$_SESSION["listaSites"] = $_POST["listaSites"];
$_SESSION["dataIni"] = $_POST["dataIni"] ? $_POST["dataIni"] : date('d/m/Y');
$_SESSION["dataFim"] = $_POST["dataFim"] ? $_POST["dataFim"] : date('d/m/Y');
$_SESSION["ramal"] = $_POST["ramal"];
$_SESSION["conta"] = $_POST["conta"];
$_SESSION["usuario"] = $_POST["usuario"];
$_SESSION["gpConta"] = $_POST["gpConta"];
$_SESSION["gpRamal"] = $_POST["gpRamal"];
$_SESSION["gpCentroCusto"] = $_POST["gpCentroCusto"];
$inRel = 1;
} else {
$_SESSION["listaSites"] = GetDefaultSite();
;
$_SESSION["dataIni"] = date('d/m/Y');
$_SESSION["dataFim"] = date('d/m/Y');
$_SESSION["ramal"] = "";
}
$isValid = 1;
if ($inRel && !is_date($_SESSION["dataIni"])) {
$isValid = 0;
$msg = "Data inicial inv<EFBFBD>lida!";
} else if ($inRel && !is_date($_SESSION["dataFim"])) {
$isValid = 0;
$msg = "Data final inv<EFBFBD>lida!";
} else if ($inRel && empty($_SESSION["ramal"])) {
$isValid = 0;
$msg = "Informe o ramal!";
} else if ($inRel && empty($_SESSION["listaSites"])) {
$isValid = 0;
$msg = "Informe um Site!";
}
//carrega sites
$sites = GetSites($dbcon, $_SESSION["listaSites"]);
//carrega contas de usuarios
$conta = GetContas($dbcon, $_SESSION["conta"]);
//carrea usuarios
$usuario = GetTodosAgentes($dbcon, $_SESSION["usuario"]);
//carrega grupo de ramais
$gpRamal = GetGrupoRamais($dbcon, $_SESSION["gpRamal"]);
//carrega grupo de contas
$gpConta = GetGrupoContas($dbcon, $_SESSION["gpConta"]);
//carrega centro de custos
$gpCentroCusto = GetCentroCusto($dbcon, $_SESSION["gpCentroCusto"]);
$imp = 0;
$linha = "";
$linhaTmp = "";
$somaDuration = 0;
$somaValor = 0;
$linhas = array();
//executa consulta somente com post
if ($inRel && $isValid) {
$result = pg_query(GetDbFromHost($_SESSION["listaSites"]), GetQuery());
while ($row = @pg_fetch_array($result)) {
$apelido = $row["apelido"];
$conta = $row["conta"];
$src = $row["src"];
$data = FormataDBDataHora($row["calldate"]);
$duration = $row["billsec"];
$valor = $row["valor"];
$somaValor += $valor;
$somaDuration += $duration;
//formata dura<EFBFBD><EFBFBD>o
$duration = SecondToStrTime($duration);
$linhaTmp = " <tr>
<td align=\"left\" class=\"headData\">$conta</td>
<td align=\"left\" class=\"headData\">$apelido</td>
<td align=\"center\" class=\"headData\">$src</td>
<td align=\"center\" class=\"headData\">$data</td>
<td align=\"center\" class=\"headData\">$duration</td>
<td align=\"right\" nowrap class=\"headData\">$valor</td>
</tr>";
//$linhas[$imp] = $linhaTmp;
$linha .= $linhaTmp;
$imp++;
}
}
if (empty($linha)) {
if ($isValid && pg_last_error($dbcon))
$noData = "Erro ao realizar a consulta. Erro: " . pg_last_error($dbcon);
else
$noData = $inRel ? ($isValid ? "Nenhum registro encontrado!" : $msg) : "Informa as datas inicial,final, ramal e clique em consultar!";
$linha = " <tr><td colspan=\"6\" align=\"left\" class=\"headData\">$noData</td>";
}
else {
$_SESSION["SSsiteDesc"] = GetSiteDesc($dbcon, $_SESSION["listaSites"]);
}
$somaDuration = SecondToStrTime($somaDuration);
$linha .= " <tr>
<th colspan=\"3\" align=\"left\" class=\"headColun\">Total chamadas: $imp</th>
<th align=\"center\" class=\"headColun\">Totais</th>
<th align=\"center\" class=\"headColun\">$somaDuration</th>
<th align=\"right\" nowrap class=\"headColun\">$somaValor</th>
</tr>";
if (!$isValid)
$jsStartup[] = "alert('$msg');";
$jsJQuery[] = "\$('#dataIni').keypress(function(){formataDataHora(this);}) ";
$jsJQuery[] = "\$('#dataFim').keypress(function(){formataDataHora(this);}) ";
$_SESSION["SSlinhas"] = $linha;
$smarty->assign('imp', $imp);
$smarty->assign('dtIni', $_SESSION["dataIni"]);
$smarty->assign('dtFim', $_SESSION["dataFim"]);
$smarty->assign('ramal', $_SESSION["ramal"]);
$smarty->assign('sites', $sites);
$smarty->assign('linhas', $linha);
$smarty->assign('conta', $conta);
$smarty->assign('usuario', $usuario);
$smarty->assign('gpRamal', $gpRamal);
$smarty->assign('gpConta', $gpConta);
$smarty->assign('gpCentroCusto', $gpCentroCusto);
GetTemplate($smarty, 'relChamadasSaintes.tpl');
function GetQuery() {
$dataIin = FormatDtMssql($_SESSION["dataIni"]);
$dataFim = FormatDtMssql($_SESSION["dataFim"]);
$ramal = $_SESSION["ramal"];
$site = $_SESSION["listaSites"];
return "select distinct src, substring(dst,1,4) as conta, split_part(userfield, '-', 2) as dst, calldate, billsec, 0.0 as valor, b.apelido
from pbx_bilhetes a, pbx_usuarios b
where b.matricula::integer = substring(a.dst,1,4)::integer
and data >= '$dataIin'
and data <= '$dataFim'
and site = '$site'
and src = '$ramal'
and dcontext = 'saida-conta-senha'
and userfield <> ''
and lastapp <> 'Transferred Call'
union all
select distinct src, '-' as conta, dst, calldate, billsec, 0.0 as valor, '-' as apelido
from pbx_bilhetes
where data >= '$dataIin'
and data <= '$dataFim'
and data <= '2009-07-29'
and site = '$site'
and src = '$ramal'
and dcontext = 'default'
and dst = case when((dst >= '5050') and (dst <= '5099'))then '0' else dst end
and length(dst) <> 7
and lastapp <> 'Transferred Call' order by 4, 2";
}
function GetTopRel() {
return "<table cellpadding=\"2\" width=\"800\" class=\"grid\">
<tr >
<th colspan=\"6\" align=\"center\">Agentes&nbsp;em&nbsp; Opera&ccedil;&atilde;o</th>
</tr>
<tr>
<th align=\"left\" class=\"headColun\">Transf.</th>
<th align=\"center\" class=\"headColun\">Conta</th>
<th align=\"center\" class=\"headColun\">N&uacute;mero</th>
<th align=\"center\" class=\"headColun\">Data</th>
<th align=\"center\" class=\"headColun\">Dura&ccedil;&atilde;o</th>
<th align=\"right\" nowrap class=\"headColun\">Valor</th>
</tr>";
}
function GetFootRel() {
return "</table>";
}
?>