<?php
session_start();
require_once ("../conexion.php");
require_once('../include/sesiones.php');
$vena_id=$_GET['id']; 
$sql=mysqli_query($con,"SELECT * from ventas_apartadas where vena_id='$vena_id' and empresa='$empresa'");
$reg=mysqli_fetch_array($sql);

$total=0;
$sql=mysqli_query($con,"SELECT * from venta_apartadas_detalle where ventas_apartadas_vena_id='$vena_id' and empresa='$empresa'");
while ($row=mysqli_fetch_array($sql))
{
    $venad_cantidad=$row["venad_cantidad"];
    $venad_precio=$row["venad_precio"];
    $venad_desc=$row["venad_desc"];
    $precio_total=$venad_precio*$venad_cantidad;
    $descuento=($venad_desc/100)*$precio_total;
    $total+=$precio_total-$descuento;//Sumador
}
$sql=mysqli_query($con,"SELECT sum(veaa_abono) as abono from venta_apartada_abonos va where ventas_apartadas_vena_id='$vena_id' and empresa='$empresa'");
$sql=mysqli_fetch_array($sql);
$abono=$sql['abono'];
$saldo=$total-$abono;

?>
<form method="post" action="" id="abonar_apar" >
    <div class="form-group">
        <input type="hidden" name="clie_id" value="<?php echo $reg['Cliente_clie_id']; ?>" >
        <input type="hidden" name="cliente" value="<?php echo $reg['vena_nombre']; ?>" class="form-control name_list" autocomplete="off" required readonly>
        <input type="hidden" name="vena_id" value="<?php echo $reg['vena_id']; ?>">
        <input type="hidden" name="detalle" class="form-control" value="Abono a la venta apartada N <?php  echo $reg['vena_n_venta']; ?>de <?php echo  $reg['vena_nombre'];?>">
        <input type="hidden" name="total" value="<?php echo $total; ?>">
        <input type="hidden" name="saldo" value="<?php echo $total-$abono; ?>" class="form-control name_list" autocomplete="off" required readonly >

        <div class="alert alert-info alert-dismissable">
            <strong>Abono a la Venta apartada N <?php  echo $reg['vena_n_venta']; ?></strong>&nbsp; de <?php echo  $reg['vena_nombre']; ?>
        </div>
        <pre style="font-size:24px;text-align:center"><strong class="text-danger">$<?php echo number_format($saldo,0); ?></strong></pre>

        <div class="middle" id="ventana2">
            <label>
                <input type="radio" name="forma_pago" id="forma_pago" value="efectivo" checked onChange="medio_pago1(this)"/>
                <div class="front-end box"><span>EFECTIVO</span></div>
            </label>
            <label>
                <input type="radio" name="forma_pago" id="forma_pago" value="transferencia" onChange="medio_pago1(this)"/>
                <div class="back-end box"><span>TRANSFERENCIA</span></div>
            </label>
            <label>
                <input type="radio" name="forma_pago" id="forma_pago" value="tarjeta" onChange="medio_pago1(this)"/>
                <div class="back-end box"><span>TARJETA</span></div>
            </label>
            <?php //if($cli['clie_nota_credito']>0){ ?>
            <!--<label>
                <input type="radio" name="forma_pago" id="forma_pago" value="nota credito" onChange="medio_pago1(this)"/>
                <div class="back-end box"><span>CRUCE</span></div>
            </label>-->
             <?php //} ?>
        </div> 

        <div id="div_efectivo" style="display: "> </div>

        <div id="div_nota" style="display: none">
            <label>Nota Credito Disponible</label>
            <input type="text" name="nota_credito" id="nota_credito" value="" class="form-control name_list" autocomplete="off" readonly >
        </div>

        <div id="div_medio_pago" style="display: none">
            <label>PLATAFORMA DE PAGO</label>
            <section id="intro" >
                <select name="medio_pago" id="medio_pago" class="form-control name_list input-sm" required>
                    <?php
                        $datos = mysqli_query($con,"SELECT * FROM banco WHERE empresa='$empresa' order by ban_nombre asc") ;
                        while( $fila = mysqli_fetch_array( $datos ) )
                        {
                            echo' <option value="'.$fila['ban_nombre'].'">'.$fila['ban_nombre'].'</option>';
                        }
                    ?>
                </select>
            </section>
        </div>

        <label>Valor</label>
        <input type="number" min="1" name="valor" max="<?php  echo $total-$abono; ?>" value="" class="form-control name_list" autocomplete="off" required >
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
        <button type="submit" class="btn btn-success" name="btn_abonar" value="btn_abonar" id="btn_abonar">Abonar</button>
    </div>
</form>

<script>
$( "#abonar_apar" ).submit(function( event ) {
$('#btn_abonar').attr("disabled", true);
var parametros = $(this).serialize();
   $.ajax({
      type: "POST",
      url: "php_apartados/abonar.php",
      data: parametros,
        beforeSend: function(objeto){
         $('#resultados').html('<center><img src="./img/ajax-loader.gif"> CARGANDO...</center>');
        },
        success: function(datos){
        $("#resultados").html(datos);
        $('#btn_abonar').attr("disabled", false);

        $('#abonar').modal('hide');
        $('body').removeClass('modal-open');
        $('.modal-backdrop').remove();
        load(1);
      }
  });
  event.preventDefault();
})
</script>
<script>
function medio_pago1(sel) {
    if (sel.value=="efectivo")
    {
        divC = document.getElementById("div_nota");
        divC.style.display = "none";
        divT = document.getElementById("div_medio_pago");
        divT.style.display = "none";
        divT = document.getElementById("div_efectivo");
        divT.style.display = "block";
    } 
    else if (sel.value=="nota credito")
    {
        divC = document.getElementById("div_nota");
        divC.style.display = "";
        divT = document.getElementById("div_medio_pago");
        divT.style.display = "none";
        divT = document.getElementById("div_efectivo");
        divT.style.display = "none";
    } 
    else 
    {
        divC = document.getElementById("div_nota");
        divC.style.display="none";
        divT = document.getElementById("div_medio_pago");
        divT.style.display = "";
        divT = document.getElementById("div_efectivo");
        divT.style.display = "none";
    }
}
</script>
<style>
.middle {
  width: 100%;
  text-align: center;
  /* Made by */
}
.middle h1 {
  font-family: "Dax", sans-serif;
  color: #ccc;
}
.middle input[type="radio"] {
  display: none;
}
.middle input[type="radio"]:checked + .box {
  background-color: #009e90;
}
.middle input[type="radio"]:checked + .box span {
  color: white;
  transform: translateY(70px);
}
.middle input[type="radio"]:checked + .box span:before {
  transform: translateY(0px);
  opacity: 1;
}
.middle .box {
  width: 131px;
  height: 60px;
  background-color: #ccc;
  transition: all 250ms ease;
  will-change: transition;
  display: inline-block;
  text-align: center;
  cursor: pointer;
  position: relative;
  font-family: "Dax", sans-serif;
  font-weight: 900;
  padding-top: 19px;
}
.middle .box span {
  left: 0;
  right: 0;
}
</style>