<?php
include_once "../header.php";
include_once("../php/config.php");
$id_prestamo =$_GET["id_prestamo"];
$id_cobro=$_GET["id_cobro"];
$sql_pago= mysql_query("select * from cobros where id_cobro='$id_cobro'") or die(mysql_error());


while($r0=mysql_fetch_array($sql_pago)){
    $capital+=$r0["capital"];
    $interes+=$r0["interes"];
    $total+=$r0["total"];
    $cliente=$r0["cliente"];
    $fecha=fecha($r0["fecha"]);
    $hora=$r0["hora"];
    $ncf=$r0["ncf"];
    $tipo_ncf=$r0["tipo_ncf"];
	
}


?>

<div class="container">
<form id="frm" name="frm" action="grabar_pago.php" method="POST" onSubmit="desabilita()">
    <div class="row">
        <div class="col-md-12">
                <div class="row">
                    <div class="col-md-2 mt-2">
                        <label># Prestamo</label>
                        <input type="number" id="numero" name="numero" class="form-control"  readonly value="<?php echo $_GET['id_prestamo']?>">
                    </div>

                     <div class="col-md-2 mt-2">
                        <label>Coprobante fiscal</label>
                        <input type="text" id="ncf" name="ncf" class="form-control"  readonly value="<?php echo $ncf?>">
                    </div>

                      <div class="col-md-2 mt-2">
                        <label>Tipo Coprobante fiscal</label>
                        <input type="text" id="tipo_ncf" name="tipo_ncf" class="form-control"  readonly value="<?php echo $tipo_ncf?>">
                    </div>
                    
       
  
            </div>
                 
                                          
           
                 <div class="row">
                <div class="col-md-1 mt-2">
                    <b>TOTAL:</b> 
                </div>
                <div class="col-md-1 mt-2">
                    <?php echo "<b class='text-primary'>".decimal($total)."</b>" ?>
                </div>
                <div class="col-md-1 mt-2">
                    <b>Capital:</b> 
                </div>
                <div class="col-md-1 mt-2">
                    <?php echo decimal($capital) ?>
                </div>
                <div class="col-md-1 mt-2">
                    <b>Interes:</b> 
                </div>
                <div class="col-md-1 mt-2">
                    <?php echo decimal($interes) ?>
                </div>
                <input type="hidden" name="total" value="<?php echo $total?>">
            </div>
            
            <div class="row">
                <div class="col-md-12 mt-2">
				  <a class="btn btn-danger" name="btnAnular" id="btnAnular" href="#" onClick="anular()"></button>
                    
                    <a class="btn btn-default" name="btnImprimir" id="btnImprimir" href="ticket_pago_prestamo.php?id_prestamo=<?php echo $id_prestamo?>&total=<?php echo $total?>&interes=<?php echo $interes?>&capital=<?php echo $capital?>&ncf=<?php echo $ncf?>&tipo_ncf=<?php echo $tipo_ncf?>">Reimprimir pago</button>
                    
                    <a class="btn btn-default ml-2" id='btnAtras' href="prestamos.php"> Ir atras</a>
                </div>
            </div>
           
            <div class="text-primary" id="mensaje">
               <?php
               echo $_POST["cuotas"];
               ?>
            </div>
            
        </div>
    </div>
</form>
</div>

<?php


include_once "../footer.php";


?>

<script>
function nuevo_cliente(){
window.open("../clientes/clientes.php", "_blank", "toolbar=yes,scrollbars=yes,resizable=no,top=50,left=100,width=600,height=600");
}

function desabilita(){
    document.getElementById('btnGrabar').disabled = 'true';
    document.getElementById('btnAtras').style.display = 'none';
    $("#mensaje").html("Grabando datos, favor espere...");
}

function sumar(c){
	document.getElementById('btnGrabar').style.display = 'none';
    var id_prestamo="<?php echo $id_prestamo?>";
    window.location.href="cobrar.php?id_prestamo="+id_prestamo+"&id_cuota="+c;
	document.getElementById('btnGrabar').style.display = 'true';
}
var id_cuota = "<?php echo $id_cuota?>";
$("#cuotas option[value='"+id_cuota+"']").prop('selected', true);

function anular(){
	var id_cobro="<?php echo $id_cobro?>";
	
     if(id_cobro==""){alert('Seleccione un registro'); return}
     if(!confirm("Seguro(a) que desea eliminar este registro?")){return;}
    

}
</script>