Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created March 13, 2018 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/4093c0913c5423c386bd0fb0f9f1d029 to your computer and use it in GitHub Desktop.
Save parzibyte/4093c0913c5423c386bd0fb0f9f1d029 to your computer and use it in GitHub Desktop.
<?php include_once "encabezado.php" ?>
<?php
include_once "base_de_datos.php";
$sentencia = $base_de_datos->query("SELECT ventas.total, ventas.fecha, ventas.id, GROUP_CONCAT( productos.codigo, '..', productos.descripcion, '..', productos_vendidos.cantidad SEPARATOR '__') AS productos FROM ventas INNER JOIN productos_vendidos ON productos_vendidos.id_venta = ventas.id INNER JOIN productos ON productos.id = productos_vendidos.id_producto GROUP BY ventas.id ORDER BY ventas.id;");
$ventas = $sentencia->fetchAll(PDO::FETCH_OBJ);
?>
<div class="col-xs-12">
<h1>Ventas</h1>
<div>
<a class="btn btn-success" href="./vender.php">Nueva <i class="fa fa-plus"></i></a>
</div>
<br>
<table class="table table-bordered">
<thead>
<tr>
<th>Número</th>
<th>Fecha</th>
<th>Productos vendidos</th>
<th>Total</th>
<th>Eliminar</th>
</tr>
</thead>
<tbody>
<?php foreach($ventas as $venta){ ?>
<tr>
<td><?php echo $venta->id ?></td>
<td><?php echo $venta->fecha ?></td>
<td>
<table class="table table-bordered">
<thead>
<tr>
<th>Código</th>
<th>Descripción</th>
<th>Cantidad</th>
</tr>
</thead>
<tbody>
<?php foreach(explode("__", $venta->productos) as $productosConcatenados){
$producto = explode("..", $productosConcatenados)
?>
<tr>
<td><?php echo $producto[0] ?></td>
<td><?php echo $producto[1] ?></td>
<td><?php echo $producto[2] ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</td>
<td><?php echo $venta->total ?></td>
<td><a class="btn btn-danger" href="<?php echo "eliminarVenta.php?id=" . $venta->id?>"><i class="fa fa-trash"></i></a></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<?php include_once "pie.php" ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment