forked from SimplesIP/pabx-app
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.
158 lines
6.6 KiB
158 lines
6.6 KiB
<?php |
|
$org_id = GetOrganizacao(); |
|
$nomeTpl = 'cadastros/tarifacao/prePagoConta.htm'; |
|
$msgErro = ''; |
|
$linha = '<tr> |
|
<td align="center">%s</td> |
|
<td align="center">%s</td> |
|
<td align="center">%s</td> |
|
<td align="center">%s</td> |
|
<td align="right">%s</td> |
|
<td align="center">%s</td> |
|
<td align="center">%s</td> |
|
</tr>'; |
|
|
|
|
|
$query = "SELECT id, matricula, nome, apelido, saldo_prepago, habilita_prepago FROM pbx_cs_usuarios WHERE status = 'A' AND org_id = $org_id"; |
|
|
|
if (IsPostBack()) { |
|
$contasSel = false; |
|
if (isset($_POST['btLancamento'])) { |
|
$contas = isset($_POST['conta']) ? $_POST['conta'] : false; |
|
$contasSel = false; |
|
|
|
if ($contas !== false) { |
|
$contasSel = array(); |
|
foreach ($contas as $value) { |
|
$ramalPost = explode(";", $value); |
|
$contasSel[] = $ramalPost[0]; |
|
} |
|
} |
|
|
|
if ($contas === false) { |
|
$jsStartup[] = "alert('Para realizar esta operação é necessário selecionar pelo menos uma conta!');"; |
|
$contasSel = false; |
|
} else if (!$_POST['operacao_ramal']) { |
|
$jsStartup[] = "alert('Selecione um tipo de operação!');"; |
|
} else { |
|
$habConta = $_POST['operacao_ramal'] == 1; |
|
$valor = isset($_POST['credito_ramal']) ? $_POST['credito_ramal'] : 0.0; |
|
$valor = FormataValorBd($valor); |
|
$usuario = GetLogin(); |
|
|
|
if ((!$habConta) && ((!$valor) || ($valor <= 0))) { |
|
$jsStartup[] = "alert('Para realizar esta operação é necessário informar um valor!');"; |
|
} else { |
|
$msg = ''; |
|
$queryRamal = 'begin'; |
|
$result = pg_query($dbcon, $queryRamal); |
|
foreach ($contas as $value) { |
|
$ramalPost = explode(";", $value); |
|
$numConta = $ramalPost[0]; |
|
$hab = $ramalPost[1]; |
|
|
|
if ($habConta) { |
|
$queryRamal = sprintf("UPDATE pbx_cs_usuarios SET habilita_prepago = '%s' WHERE matricula = '%s' \n", ($hab ? '0' : '1'), $numConta); |
|
|
|
if ($result) { |
|
$result = pg_query($dbcon, $queryRamal); |
|
} |
|
|
|
if (!$result) { |
|
break; |
|
} |
|
} else { |
|
if (!$hab) { |
|
$msg = 'Não é permitido realizar lançamentos para "Contas Desabilitadas"!'; |
|
$result = false; |
|
break; |
|
} |
|
$queryRamal = "INSERT INTO pbx_prepago_movimento (prm_ramal_conta, prm_conta_senha, trr_id, prm_valor_minuto, prm_tempo, prm_destino, prm_valor, prm_data, prm_data_lanc, prm_tipo_lancamento, prm_historico, usuario, org_id) |
|
VALUES('$numConta', '1', '0', '0', '0', '0', '$valor', NOW()::date, NOW(), 'C', 'Inclusao de Credito', '$usuario', $org_id)"; |
|
|
|
if ($result) { |
|
$result = pg_query($dbcon, $queryRamal); |
|
} |
|
|
|
if (!$result) { |
|
break; |
|
} |
|
} |
|
} |
|
|
|
if ($result) { |
|
$queryRamal = 'commit'; |
|
pg_query($dbcon, $queryRamal); |
|
$jsStartup[] = "alert('Operação realizada com sucesso!');"; |
|
} else { |
|
$queryRamal = 'rollback'; |
|
pg_query($dbcon, $queryRamal); |
|
$msg = $msg ? $msg : 'Não foi possível realizar a operação!'; |
|
$jsStartup[] = "alert('$msg');"; |
|
} |
|
} |
|
} |
|
} |
|
|
|
$numero_conta = strtoupper($_POST['numero_conta']); |
|
} |
|
|
|
if ($numero_conta) { |
|
if ((strpos($numero_conta, ",") !== false) || (strpos($numero_conta, ";") !== false)) { |
|
$numero_conta = str_replace(";", ",", $numero_conta); |
|
$numero_conta = str_replace("-", ",", $numero_conta); |
|
$numSel = ''; |
|
$numeros = explode(",", $numero_conta); |
|
foreach ($numeros as $numero) { |
|
$numSel .= !$numSel ? "'$numero'" : ",'$numero'"; |
|
} |
|
$query .= "AND matricula IN($numSel)"; |
|
} else if (strpos($numero_conta, "-") !== false) { |
|
$numSel = ''; |
|
$numeros = explode("-", $numero_conta); |
|
$query .= sprintf("AND matricula >= '%s' AND matricula <= '%s'", $numeros[0], $numeros[1]); |
|
} else { |
|
$query .= "AND matricula::text LIKE '%$numero_conta%'"; |
|
} |
|
} |
|
|
|
$query .= " ORDER BY 3"; |
|
|
|
$result = pg_query($dbcon, $query); |
|
|
|
$linhas = ''; |
|
$linhaTemp = ''; |
|
$imp = 0; |
|
while ($dados = pg_fetch_array($result)) { |
|
$matricula = $dados['matricula']; |
|
|
|
if ($contasSel !== false && is_array($contasSel)) { |
|
$sel = (array_search($matricula, $contasSel) !== false) ? 'checked="checked"' : ""; |
|
} |
|
|
|
$sel = sprintf('<input type="checkbox" name="conta[]" id="nome_%s" value="%s;%s" %s>', $dados['id'], $dados['matricula'], $dados['habilita_prepago'], $sel); |
|
$nome = $dados['nome']; |
|
$apelido = $dados['apelido']; |
|
$saldo = FormataValor($dados['saldo_prepago']); |
|
$habConta = $dados['habilita_prepago']; |
|
$habilita = $dados['habilita_prepago'] ? '<img src="imgSite/button_ok16.png" alt="Habilitado!" width="16" height="16" border="0">' : '<img src="imgSite/fecha16.png" alt="Desabilitado!" width="16" height="16" border="0">'; |
|
$lanc = '<img src="imgSite/prepago16.png" alt="Lançamentos!" width="16" height="13" border="0">'; |
|
$linkLanc = "<a href=\"javaScript:NovaJanela('index.php?idProg=215&conta=$matricula&nome=$nome&saldo=$saldo&statusConta=$habConta', 'cadPrePagoConta', '700', '500', 'resizable=NO,scrollbars=YES');\">$lanc</a>"; |
|
$linhaTemp = sprintf($linha, $sel, $matricula, $nome, $apelido, $saldo, $habilita, $linkLanc); |
|
$linhas .= $linhaTemp; |
|
$imp++; |
|
} |
|
|
|
if (!IsPostBack()) { |
|
$linhas .= '<tr><td colspan="7">Informe os parametros e clique em consultar!</td></tr>'; |
|
} else if ($imp) { |
|
$linhas .= sprintf('<tr><td colspan="7">%s %s</td></tr>', $imp, ($imp > 1 ? 'Contas encontradas!' : 'Conta encotrada!')); |
|
} else { |
|
$linhas .= '<tr><td colspan="7">Nenhum registro encontrado!</td></tr>'; |
|
} |
|
|
|
$smarty->assign('numero_conta', $numero_conta); |
|
$smarty->assign('linhas', $linhas); |
|
$smarty->assign('msgErro', $msgErro); |
|
|
|
GetTemplate($smarty, $nomeTpl);
|
|
|