<?php 
// error_reporting(0);
// ini_set(“display_errors”, 0 );
include "protege_professor.php";

date_default_timezone_set('America/Sao_Paulo');
$hoje = date('d-m-Y');

if(isset($_POST["quantidade_recarga"])){
$quantidade_recarga = $_POST["quantidade_recarga"];
$cliente_cod 		= $_POST["cliente_cod"];

$cliente 	 = explode("recarga_scpc.php", $cliente_cod); 
$url_cliente = $cliente[0]; // url do cliente
$valor_total = $quantidade_recarga * 9; // valor total da parcela
$data_vencimento = date('d-m-Y', strtotime("+1 days", strtotime($hoje))); // data de vencimento



$hostname2 ='50.116.87.204';
$username2 ='immob049_immobil';
$senha2 ='si171156';
$banco2 ='immob049_immobile';


$db2 = mysqli_connect($hostname2,$username2,$senha2,$banco2) or die (mysqli_error());
mysqli_select_db($banco2, $db2);

$busca_idvenda = "SELECT idvenda, cliente_idcliente
				  FROM venda 
				  WHERE suporte like '%$url_cliente%'";

//echo $busca_idvenda;
$executa_busca = mysqli_query($db2, $busca_idvenda);

while ($buscar_venda = mysqli_fetch_assoc($executa_busca)) {
		$venda_id 	= $buscar_venda["idvenda"];
		$cliente_id = $buscar_venda["cliente_idcliente"];
	}

$insere_parcela = "INSERT INTO parcelas (venda_idvenda, valor_parcelas, data_vencimento_parcela, situacao, descricao, remessa, tipo_venda, numero_sequencia, fluxo, empreendimento_id_novo, cliente_id_novo) values ('$venda_id', '$valor_total', '$data_vencimento', 'Em Aberto', 'RecargaSCPC', '0', '2', '001/001', '0', '1', '$cliente_id')";

//echo $insere_parcela;

// die();

$executa_inserir = mysqli_query($db2, $insere_parcela);
$ultimo_id = mysqli_insert_id($db2);

$ch = curl_init("https://immobilebusiness.com.br/admin/cron_registra_boleto_sicredi.php");



    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    $retorno = curl_exec($ch);


    curl_close($ch);
	// var_dump($retorno);

	// die();


	// Inicia o envio do boleto
	$dados["antecipar"] = [];
	$dados["antecipar"][] = $ultimo_id;
	$dados["tipo"] = '2';


	$geracao = date('d-m-Y H:i:s');
	include "conexao.php";
	$insere = "INSERT INTO recarga (parcela_id, data_recarga, situacao, quantidade, valor_total) values ('$ultimo_id', '$geracao', '0', '$quantidade_recarga', '$valor_total')";
	$executa = mysqli_query($db, $insere);






?>
  <form action="https://immobilebusiness.com.br/admin/prepara_boleto.php?envio=2" method="POST" id="nome" name="nome">
                        <input type="hidden" name="idvenda" value="<?php echo $venda_id; ?>">
                        <input type="hidden" name="tipo" value="2">


<!-- inicio dos dados para geração dos boleto pela API -->
                        
                     


    <input type="hidden" name="antecipar[]" value="<?php echo $ultimo_id; ?>">



<!-- Fim dos dados para geração dos boleto pela API -->


</form>
<script type="text/javascript">
  document.nome.submit();
</script> 
<?php } ?>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en">
<!--<![endif]-->


<head>
	<meta charset="utf-8" />
	<title>Immobile | Business</title>
	<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport" />
	<meta content="" name="description" />
	<meta content="" name="author" />
	
	<!-- ================== BEGIN BASE CSS STYLE ================== -->
	<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700" rel="stylesheet">
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/jquery-ui/themes/base/minified/jquery-ui.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/css/animate.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/css/style.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/css/style-responsive.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/css/theme/default.css" rel="stylesheet" id="theme" />
	<!-- ================== END BASE CSS STYLE ================== -->
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-datepicker/css/datepicker.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-datepicker/css/datepicker3.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/ionRangeSlider/css/ion.rangeSlider.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/ionRangeSlider/css/ion.rangeSlider.skinNice.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-colorpicker/css/bootstrap-colorpicker.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-timepicker/css/bootstrap-timepicker.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/password-indicator/css/password-indicator.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-combobox/css/bootstrap-combobox.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-select/bootstrap-select.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-tagsinput/bootstrap-tagsinput.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/jquery-tag-it/css/jquery.tagit.css" rel="stylesheet" />
    <link href="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-daterangepicker/daterangepicker-bs3.css" rel="stylesheet" />
    <link href="https://immobilebusiness.com.br/admin/assets/plugins/select2/dist/css/select2.min.css" rel="stylesheet" />
    <link href="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-eonasdan-datetimepicker/build/css/bootstrap-datetimepicker.min.css" rel="stylesheet" />
	<!-- ================== BEGIN BASE JS ================== -->
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/pace/pace.min.js"></script>
	<!-- ================== END BASE JS ================== -->
    <script type="text/javascript">
        function calcula(){

         var qtd = document.form_wizard.quantidade_recarga.value;
         //alert(qtd);

         var div = document.getElementById("total");

         var total = (qtd) * 9;

         var total = total.toLocaleString('pt-br',{style: 'currency', currency: 'BRL'});

         div.innerHTML = "<h1>" + total +"</h1>";

        }
    </script>
</head>
<body>
	<!-- begin #page-loader -->
	<div id="page-loader" class="fade in"><span class="spinner"></span></div>
	<!-- end #page-loader -->
	
	<!-- begin #page-container -->
	<div id="page-container" class="fade page-sidebar-fixed page-header-fixed">
		<!-- begin #header -->
	<?php include "topo.php" ?>
		<!-- end #sidebar -->
		
		<!-- begin #content -->
		<div id="content" class="content">
			<?php

           $imobiliaria_idimobiliaria = $_SESSION["id_usuario"];

           // echo "<pre>";
           // echo($_SERVER["SCRIPT_URI"]);
           // echo "</pre>";


             ?>
			<!-- begin page-header -->
			<h1 class="page-header">Recarga SCPC</h1>
			<!-- end page-header -->
	

           <div class="panel panel-inverse" data-sortable-id="form-plugins-11">
            <div class="panel-heading">
                <div class="panel-heading-btn">
                    <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-default" data-click="panel-expand"><i class="fa fa-expand"></i></a>
                    <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-success" data-click="panel-reload"><i class="fa fa-repeat"></i></a>
                    <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-warning" data-click="panel-collapse"><i class="fa fa-minus"></i></a>
                    <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-danger" data-click="panel-remove"><i class="fa fa-times"></i></a>
                </div>
                <h4 class="panel-title">Informações:</h4>
            </div><br>
            <div class="panel-body panel-form">
                <form  action="recarga_scpc.php" method="POST" name="form_wizard" id="form_wizard">
                    <div class="form-group col-md-6">
                        <label class="control-label">Quantidade de Recargas</label>
                        <input type="number" class="form-control" value="" id="quantidade_recarga" onchange="calcula()" name="quantidade_recarga"  />
                        <input type="hidden" name="cliente_cod" value='<?php echo $_SERVER["SCRIPT_URI"]; ?>'>
                    </div>

                    <div class="form-group col-md-6">
                        <label class="control-label">Valor Total: </label>
                        <div id="total"></div>
                    </div>

                    

                   
                 
    	
                    <!-- <div class="form-group col-md-6"> -->
                     <!-- begin panel -->
                    <!--  <div class="panel panel-inverse" data-sortable-id="form-stuff-1">
                        <div class="panel-heading">


                        </div>
                        <div class="panel-body"> -->
                          <div class="form-group col-md-6">
                             <input type="submit" class="btn btn-success m-r-5 m-b-5" value="Gerar Boleto" />
                         </div>

                     </div>
                     <!-- end panel -->

                 </form>
             </div>


           

            </div>
            <!-- end row -->
       
		</div>
	
     
		
		<!-- begin scroll to top btn -->
		<a href="javascript:;" class="btn btn-icon btn-circle btn-success btn-scroll-to-top fade" data-click="scroll-top"><i class="fa fa-angle-up"></i></a>
		<!-- end scroll to top btn -->
	</div>
	<!-- end page container -->
	
<script src="https://immobilebusiness.com.br/admin/assets/plugins/jquery/jquery-1.9.1.min.js"></script>
<script src="https://immobilebusiness.com.br/admin/assets/js/jquery.maskMoney.js" type="text/javascript"></script>

 <script type="text/javascript">
$(function(){

$("#entrada").maskMoney({symbol:'', 
showSymbol:true, thousands:'', decimal:'.', symbolStay: true});
 

$("#entrada2").maskMoney({symbol:'R$ ', 
showSymbol:true, thousands:'.', decimal:',', symbolStay: true});

$("#entrada3").maskMoney({symbol:'', 
showSymbol:true, decimal:'.', symbolStay: true});
 })

</script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/jquery/jquery-migrate-1.1.0.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/jquery-ui/ui/minified/jquery-ui.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap/js/bootstrap.min.js"></script>
	<!--[if lt IE 9]>
		<script src="https://immobilebusiness.com.br/admin/assets/crossbrowserjs/html5shiv.js"></script>
		<script src="https://immobilebusiness.com.br/admin/assets/crossbrowserjs/respond.min.js"></script>
		<script src="https://immobilebusiness.com.br/admin/assets/crossbrowserjs/excanvas.min.js"></script>
	<![endif]-->
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/slimscroll/jquery.slimscroll.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/jquery-cookie/jquery.cookie.js"></script>
	<!-- ================== END BASE JS ================== -->
	
	<!-- ================== BEGIN PAGE LEVEL JS ================== -->
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/ionRangeSlider/js/ion-rangeSlider/ion.rangeSlider.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-colorpicker/js/bootstrap-colorpicker.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/masked-input/masked-input.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-timepicker/js/bootstrap-timepicker.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/password-indicator/js/password-indicator.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-combobox/js/bootstrap-combobox.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-select/bootstrap-select.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-tagsinput/bootstrap-tagsinput.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-tagsinput/bootstrap-tagsinput-typeahead.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/jquery-tag-it/js/tag-it.min.js"></script>
    <script src="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-daterangepicker/moment.js"></script>
    <script src="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-daterangepicker/daterangepicker.js"></script>
    <script src="https://immobilebusiness.com.br/admin/assets/plugins/select2/dist/js/select2.min.js"></script>
    <script src="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-eonasdan-datetimepicker/build/js/bootstrap-datetimepicker.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/js/form-plugins.demo.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/js/apps.min.js"></script>

	
	<script>
		$(document).ready(function() {
			App.init();
			FormPlugins.init();
		});
	</script>

</body>


</html>
