<?php
session_start();
require_once ("../conexion.php");
require_once('../include/sesiones.php');

$Cliente_clie_id=$_POST['cliente'];
$cli1=mysqli_query($con, "SELECT * from cliente where clie_id='$Cliente_clie_id' and empresa='$empresa' ");
$cli1=mysqli_fetch_array($cli1);
$clie_id=$cli1['clie_id'];
$clie_nombre=$cli1['clie_nombre'];
$registros=mysqli_query($con,"SELECT * FROM ventas where Cliente_clie_id='$Cliente_clie_id' and ven_estado='sin pagar' and empresa='$empresa'") or die(mysqli_error($con));

 
?>  
<script>
    $('#ventanacxc').hide(); 
</script>
<form method="post" action="" id="form_pago_cxc" name="form_pago_cxc">
    <div  class="col-md-12">
        <div class="form-group">
            <div class="alert alert-info alert-dismissable">
                <strong>Abono de <?php echo $clie_nombre; ?>
            </div>
            <?php
            $totalpagar=0;  
            while ($reg=mysqli_fetch_array($registros))
            {   $ven_id=$reg['ven_id'];
                $ven_estado=$reg['ven_estado'];
                $ven_forma_de_pago=$reg['ven_forma_de_pago'];
                include('../php_pos/saldodeventas.php');
                $totalpagar+=$saldo;?>
            <input type="hidden" name="ven_id[]" value="<?php echo $reg['ven_id']; ?>" class="form-control name_list" autocomplete="off" required readonly>
            <?php }  ?>  

            <pre style="font-size:24px;text-align:center"><strong class="text-danger">$<?php echo number_format($totalpagar,0); ?></strong></pre>
            <input type="hidden" name="clie_id" value="<?php echo $clie_id; ?>" class="form-control name_list" autocomplete="off" required readonly>

            <div class="middle" id="ventana2">
                <label>
                    <input type="radio" name="forma_pago" id="forma_pago" value="efectivo" checked onChange="pago(this)"/>
                    <div class="front-end box"><span>EFECTIVO</span></div>
                </label>
                <label>
                    <input type="radio" name="forma_pago" id="forma_pago" value="transferencia" onChange="pago(this)"/>
                    <div class="back-end box"><span>TRANSFERENCIA</span></div>
                </label>
                <label>
                    <input type="radio" name="forma_pago" id="forma_pago" value="tarjeta" onChange="pago(this)"/>
                    <div class="back-end box"><span>TARJETA</span></div>
                </label>
            </div> 
            <div id="div_efectiv" style="display: "> </div>

            <div id="div_not" 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_pag" style="display: none">
                <label>PLATAFORMA DE PAGO</label>
                <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>
            </div>

            <input type="hidden" name="saldo" value="<?php echo $totalpagar; ?>" class="form-control name_list" autocomplete="off" required readonly >
         </div>
    </div> <!-- /.form-group -->
    <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
        <button type="submit" class="btn btn-success" name="pago_cxc" value="pago_cxc" id="pago_cxc">PAGAR TODO</button>
    </div>
</form>  
<script>
function pago(sel) {
    if (sel.value=="efectivo")
    {
        divC = document.getElementById("div_not");
        divC.style.display = "none";
        divT = document.getElementById("div_medio_pag");
        divT.style.display = "none";
        divT = document.getElementById("div_efectiv");
        divT.style.display = "block";
    } 
    else if (sel.value=="nota credito")
    {
        divC = document.getElementById("div_not");
        divC.style.display = "";
        divT = document.getElementById("div_medio_pag");
        divT.style.display = "none";
        divT = document.getElementById("div_efectiv");
        divT.style.display = "none";
    } 
    else 
    {
        divC = document.getElementById("div_not");
        divC.style.display="none";
        divT = document.getElementById("div_medio_pag");
        divT.style.display = "";
        divT = document.getElementById("div_efectiv");
        divT.style.display = "none";
    }
}
</script>                  
<script>
$("#form_pago_cxc" ).submit(function( event ) {
$('#pago_cxc').attr("disabled", true);
var parametros = $(this).serialize();
   $.ajax({
      type: "POST",
      url: "php_movimientos/registrar_cxc_todo.php",
      data: parametros,
        beforeSend: function(objeto){
         $('#resultados').html('<center><img src="./img/ajax-loader.gif"> CARGANDO...</center>');
        },
      success: function(datos){
      $("#resultados").html(datos);
      $('#pago_cxc').attr("disabled", false);
      $('#buscarcxc').modal('hide');
      $('body').removeClass('modal-open');
      $('.modal-backdrop').remove();
      load(1);
      loadmodal();
      }
  });
    event.preventDefault();
})
</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>