<?php



include_once("../../php/config.php");

$id = $_GET["idrentas"];

    $sql = mysql_query("select * from rentas where idrentas='$id'") or die(mysql_error());

    

?>



<div class="container">

    

                <form action="datos_renta.php?idrentas=<?php echo $id?>" method="POST" onSubmit="$('.btn').prop('disabled', true); $('.btn').hide();">

                <div class="row mt-2">

                    <div class="col-md-1 mt-2">

                        <label># Alquiler</label>

                    </div>

                      <div class="col-md-11">

                        <input type="text" class="form-control" id="idrentas" name="idrentas" value="<?php echo  mysql_result($sql,0,'idrentas')?>">

                     </div>

                    

                </div>

                

                  <div class="row mt-2">

                    <div class="col-md-1 mt-2">

                        <label>Fecha</label>

                    </div>

                      <div class="col-md-11">

                        <input type="text" class="form-control" id="fecha" name="fecha" value="<?php echo  fecha(mysql_result($sql,0,'fecha'))?>">

                     </div>

                    

                </div>

                

                <div class="row mt-2">

                    <div class="col-md-1 mt-2">

                        <label>Cliente</label>

                    </div>

                      <div class="col-md-11">

                        <input type="text" class="form-control" id="cliente" name="cliente" value="<?php echo  mysql_result($sql,0,'cliente')?>">

                     </div>

                    

                </div>

                

                

                <div class="row mt-2">

                    <div class="col-md-1 mt-2">

                        <label>Monto</label>

                    </div>

                      <div class="col-md-11">

                        <input type="text" class="form-control" id="monto" name="monto" value="<?php echo  mysql_result($sql,0,'monto')?>">

                     </div>

                    

                </div>

                

                

                <div class="row mt-2">

                    <div class="col-md-1 mt-2">

                        <label>Adelanto</label>

                    </div>

                      <div class="col-md-11">

                        <input type="text" class="form-control" id="pagado" name="pagado" value="<?php echo  mysql_result($sql,0,'pagado')?>">

                     </div>

                    

                </div>

                <div class="row mt-2">

                    <div class="col-md-1 mt-2">

                        <label>Pagar</label>

                    </div>

                      <div class="col-md-11">

                        <input type="number" class="form-control" id="pagado" name="pagado" value="<?php echo  mysql_result($sql,0,'monto')?>">

                     </div>

                    

                </div>



                <hr>

                <div class="row mt-2">

                    <div class="col-md-1 mt-2">

                        <label>Productos</label>

                    </div>

                      <div class="col-md-4">

                          <select id="producto" class="form-control" name="producto">

                            

                          <?php

                            

                            $sql2 = mysql_query("select * from detalle_renta where cliente='$id'") or die(mysql_error());

                            while($r0 = mysql_fetch_array($sql2)){

                           ?>

                            <option value="<?php echo $r0['iddetalle_renta']?>"><?php echo $r0['producto']?></option>

                            <?php }?>

                           

                           

                       </select>

                     </div>

                    

                </div>

                

                 <div class="row mt-2">

                    <div class="col-md-1 mt-2">

                        <label>Proximo pago</label>

                    </div>

                      <div class="col-md-2">

                        <input type="Date" class="form-control" id="proximo" name="proximo">

                     </div>

                    

                </div>

                

                <div class="row mt-2">

                    <div class="col-md-12 mt-2">

                        <button class="btn btn-success" ><i class="fa fa-copy"></i>  Cobrar</button>

                        <a class="btn btn-info" href="historial_cobros_renta.php?idrenta=<?php echo $id?>"><i class="fa fa-list"></i>  Ver historial de pagos</a>

                        <a class="btn btn-default" href="rentas.php?idrenta=<?php echo $id?>"><i class="fa fa-undo"></i>  Ir atras</a>



                      </div>

                </div>

                

                <div class="row mt-2">

                <div class="col-md-12">

                     <?php 

                        $pagado = $_POST["pagado"];

                        $id = $_POST["idrentas"];

                        if($_POST["idrentas"]=="0" or $_POST["pagado"]=="0" or $_POST["pagado"]=="" or $_POST["cliente"]=="" or $_POST["proximo"]==""){

                           echo "<h3>faltan datos...</h3>";

                        

                        }else{
                           echo "<script>$('.btn').hide()</script>";
                            mysql_query("insert into cobros_renta set cliente='".$_POST['cliente']."', fecha='$hoy()', monto='".$_POST['pagado']."', idrenta='".$_POST['idrentas']."', hora=NOW()",$con) or die(mysql_error());

                            mysql_query("update rentas set vence='".$_POST["proximo"]."' where idrentas='$id'",$con) or die(mysql_error());

                           

                            echo "<h3 class='text-primary'>Datos grabados...</h3>";

                            sleep(2);

                            echo "<script>window.location.href='ticket_pago_renta.php?idrenta=$id&pagado=$pagado'</script>";

                            

                        }

                    ?>

                </div>

            </div>

                

                

                

         </form>  

        </div>

    </div>

</div>





<?php

include_once "../footer.php";



?>

