<?php
	$usuario = $_COOKIE["usuario"];
$nivel = $_COOKIE["nivel"];
if($nivel=="administrador"){$usuario="";}

	include_once("../header.php");
        include_once("../php/config.php");
        $sql = mysql_query("select * from rentas order by cliente asc") or die(mysql_error());
	?>

    <div class="container" id="pg">
        
        
		<div class="row">
			<div class="col-md-12">
			  
				<a class="btn  btn-primary mt-2 ml-2" href="nueva_renta.php"><i class="fa fa-plus"></i> Registrar un nuevo alquiler</a>
				<a class="btn  btn-default mt-2" href="catalogo_renta.php"><i class="fa fa-plus"></i> Productos</a>
				 <a class="btn  btn-default mt-2" href="menu_renta.php"><i class="fa fa-pencil"></i> Salir</a>
				<hr>
				<div class="table-responsive">
					<table class="table table-sm table-borderred table-striped" data-page-length='8'>
						<thead>
							<th># Renta</th>
                             <th>Nombre</th>
							<th>Fecha</th>
                            
							<th>Fecha entrega</th>
								
                                <th>Monto pago</th>
                            <th>Accion</th>
						</thead>
						<tbody>
                                                        <?php while($r=mysql_fetch_array($sql)){
                                          $idrentas = $r["idrentas"]; 
                                          $c++;
                                          
                                          $total+=$r["monto"];
                                          
                                                        
                                          
                                          
                                                        ?>
							<tr>
								<td><?php echo $r["idrentas"]?></td>
								<td><?php echo $r["cliente"]?></td>
								<td><?php echo fecha($r["fecha"])?></td>
							
								<td><?php echo fecha($r["vence"])?></td>
								<td><?php echo decimal($r["monto"])?></td>
								
								
								<td><?php echo "<a  href='datos_renta.php?idrentas=$idrentas'><i class='fa fa-edit'></i> Ver</a>"?>
							    	
							</tr>
                                                        <?php }?>
						</tbody>
						<tfoot>
						     <th>Cant. alquileres </th>
						    <th>Total</th>
						    
						    <th></th>
						    <tr>
						         <td><?php echo decimal($c)?></td>
						        <td><?php echo decimal($total)?></td>
						       
						         
						        <td></td>
						    </tr>
						</tfoot>
					</table>
				</div>
			</div>
		</div>
		
        </div>

      


          
</div>
    </div>



	<?php
	include_once("../footer.php");
	?>
	
	<script>
$(".table").DataTable({
	 "language": {
            "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Spanish.json"
        }
});

/*
$('.table').DataTable( {
				dom: 'Bfrtip',
				buttons: [
            'copy', 'csv', 'excel', 'pdf', 'print'
			]
		} );
*/

</script>

