<?php

include_once "../header.php";
include_once("../php/config.php");
$sql_cliente= mysql_query("select * from clientes") or die(mysql_error());

$q= mysql_query("select idrentas from rentas order by idrentas desc limit 1") or die(mysql_error());
$last_id =mysql_result($q,0,"idrentas")+1; 




?>

<div class="container">
<form id="frm" name="frm" action="nueva_renta.php" method="POST" onSubmit="$('.btn').hide()">
    <div class="row">
        <div class="col-md-12">
               <a class="mt-2" href="#" onClick="nuevo_cliente()"><i class="fa fa-user"></i> Nuevo Cliente</a>
             |
              <a class="mt-2" href="nueva_renta.php" ><i class="fa fa-undo"></i> Refrescar</a>
             
                <div class="row">
                    <div class="col-md-1 mt-2">
                        <label># Alquiler</label>
                        <input type="number" id="idrentas" name="idrenta" class="form-control" value="<?php echo $last_id;?>"  readonly value="<?php echo $_GET['numero']?>">
                    </div>
                    
                  <div class="col-md-3 mt-2">
                         <label>Cliente</label>
                            <select  class="form-control  mb-2" id="cliente"      name="cliente" value="<?php echo $_GET['cliente']?>">
                                 <option value="" selected>Sel. cliente</option>
                                <?php while ($r3 = mysql_fetch_array($sql_cliente)) { ?>
                                    <option value="<?php echo $r3['nombre'] ?>"><?php echo $r3['nombre'] ?></option>
                                <?php } ?>
                                
                            </select>
                </div> 
                
                
           
                <div class="col-md-2 mt-2">
                    <label>Fecha</label>
                    <input type="Date" id="fecha" name="fecha" class="form-control" value="<?php echo $hoy?>">
                </div>
				
				 <div class="col-md-2 mt-2">
                    <label>Entrega</label>
                    <input type="Date" id="fecha2" name="fecha2" class="form-control" value="<?php echo $_GET['vence']?>">
                </div>
                
                <div class="col-md-2 mt-2">
                    <label>Monto</label>
                    <input type="number" id="monto" name="monto" class="form-control" value="<?php echo $_GET['monto']?>">
                </div>
                
                 <div class="col-md-2 mt-2">
                    <label>Adelanto</label>
                    <input type="number" id="pagado" name="pagado" class="form-control" value="<?php echo $_GET['monto']?>">
                </div>
                
            
                  
              
               
                
                 
                
            </div>
     
            
            <div class="row">
                      <div class="col-md-3 mt-2">
                       
                        <button class="btn btn-success" > Crear alquiler</button>
                        <a class="btn btn-default ml-2" href="rentas.php"> Salir</a>
                       </div>
                 
  
            </div>
            
            <div class="row mt-2">
                <div class="col-md-12">
                     <?php 
                      
                        $balance = $_POST['monto'] - $_POST['pagado'];
                        
                        if($_POST["cliente"]=="" or $_POST["monto"]=="" or $_POST["fecha"]=="" or $_POST["fecha2"]==""){
                           echo "<h3>faltan datos...</h3>";
                        
                        }else{
                            mysql_query("insert into rentas set cliente='".$_POST['cliente']."', fecha='".$_POST['fecha']."', vence='".$_POST['fecha2']."', monto='".$_POST['monto']."', idrentas='".$_POST['idrenta']."', pagado='".$_POST['pagado']."', balance='$balance'",$con) or die(mysql_error());
                            echo "<h3 class='text-primary'>Asignar producto...</h3>";
                            sleep(2);
                            echo "<script>window.location.href='catalogo_renta.php'</script>";
                            
                        }
                    ?>
                </div>
            </div>
        </div>
    </div>
</form>
</div>

<?php

include_once "../footer.php";
?>


