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


$idusuario                 = $_SESSION['id_usuario'];



function DadosParcela($idparcelas)
{
	include "conexao.php";
    $query_amigo = "SELECT * FROM parcelas where idparcelas = $idparcelas";
    $executa_query = mysqli_query ($db,$query_amigo);
   	$buscar_amigo = mysqli_fetch_assoc($executa_query);
   	
    return $buscar_amigo;
}


if(isset($_POST["desconto"])){
	
	// echo "<pre>";
	// print_r($_POST);
	// echo "</pre>";
	// die();
	
$ids = $_POST["ids"];

$idvenda = $_POST["idvenda"];
$tipo    = $_POST["tipo"];
	
	// var_dump($antecipar);
	// die();

	include "conexao.php";
	 foreach ($ids as $id ) {
	
	$valor_desconto  = $_POST[$id];
  	$valor_desconto = str_replace("R$","", $valor_desconto);
  	$valor_desconto = str_replace(".","", $valor_desconto);
  	$valor_desconto = str_replace(",",".", $valor_desconto);


	$inserir = "UPDATE parcelas set 
	desc_parcela = '$valor_desconto'
		
		WHERE idparcelas = $id";

	//echo $inserir; die();
	$executa = mysqli_query($db, $inserir);


	}

?>

<script type="text/javascript">window.location="parcelas.php?idvenda=<?php echo $idvenda ?>&tipo=<?php echo $tipo ?>&desconto=ok";</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 ================== -->
	
	<!-- ================== BEGIN BASE JS ================== -->
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/pace/pace.min.js"></script>
	<!-- ================== END BASE JS ================== -->

</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">
	

	<?php include "topo.php" ?>



		<!-- begin #content -->
		<div id="content" class="content">
			
			<!-- end breadcrumb -->
			<!-- begin page-header -->
			<h1 class="page-header">Alterar Descrição das parcelas</h1>
			<!-- end page-header -->
			
			<!-- begin row -->
			<div class="row">

		
   <div class="col-md-12">
			        <!-- begin panel -->
                    <div class="panel panel-inverse" data-sortable-id="table-basic-4">
                        <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">Parcelas</h4>
                        </div>
                        <div class="panel-body">
                <?php 
	              $idvenda = $_POST["idvenda"];
	              $tipo = $_POST["tipo"];
				  $teste = $_POST["antecipar"];

				?>
                       <form action="altera_desconto.php" method="POST">
                       	<input type="hidden" name="desconto" value="1">
                       	<input type="hidden" name="idvenda" value="<?php echo $idvenda ?>">
                       	<input type="hidden" name="tipo" value="<?php echo $tipo ?>">
                            <table class="table table-striped">
                    <?php foreach ($teste as $id) { 
                    	$Dados = DadosParcela($id);
                    ?>
                                <tr>

          <td>
          	<input type="hidden" name="ids[]" value="<?php echo $Dados["idparcelas"]; ?>">
          	<?php echo $Dados["idparcelas"]; ?></td>
          <td><?php echo $Dados["numero_sequencia"]; ?></td>
          <td><?php echo $Dados["valor_parcelas"]; ?></td>
          <td><?php echo $Dados["data_vencimento_parcela"]; ?></td>
          <td><input type="text" name="<?php echo $Dados["idparcelas"]; ?>" class="form_control" value="<?php echo $Dados["desc_parcela"]; ?>"></td>
        </tr>
        			<?php } ?>
        			<tr>
        				<td colspan="5"><input type="submit" name="Confirmar" value="Confirmar Desconto" class="btn btn-success"></td>
        			</tr>

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



			</div>
		
			
		</div>
		<!-- end #content -->
		
     
		
		<!-- 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 -->
	
	<!-- ================== BEGIN BASE JS ================== -->
	<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/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/js/apps.min.js"></script>
	<!-- ================== END PAGE LEVEL JS ================== -->
	<script src="https://immobilebusiness.com.br/admin/assets/js/jquery.maskMoney.js" type="text/javascript"></script>

<script type="text/javascript">

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

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

</body>

</html>
