<?php
require '../conexion.php';

$query = mysqli_query($conection, "SELECT p.idproducto,p.descripcion,p.precio,p.existencia,pr.proveedor,p.foto,
             p.date_add
             FROM producto p 
             INNER JOIN proveedor pr
             ON p.proveedor = pr.idproveedor                    
             WHERE p.estatus = 1 ORDER BY p.idproducto 
				");

mysqli_close($conection);

$docu = "productos.xls";
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename=' . $docu);
header('Pragma: no-cache');
header('Expires: 0');
echo '<table border = 1>';
echo '<tr>';
echo '<th colspan = 6>Lista de productos</th>';
echo '</tr>';
echo '<tr><th>ID</th><th>DESCRIPCION</th><th>PRECIO</th><th>CANT.</th><th>PROVEEDOR</th><th>FECHA DE INGRESO</th></tr>';

while ($data = mysqli_fetch_array($query)) {
    $formato = 'Y-m-d H:i:s';
    $fecha = DateTime::createFromFormat($formato, $data["date_add"]);

    echo '<tr>';
    echo '<td>' . $data["idproducto"] . '</td>';
    echo '<td>' . $data["descripcion"] . '</td>';
    echo '<td>' . '$/. ' . $data["precio"] . '</td>';
    echo '<td>' . $data["existencia"] . '</td>';
    echo '<td>' . $data["proveedor"] . '</td>';
    echo '<td>' . $fecha->format('d-m-Y') . '</td>';
    echo '</tr>';
}

echo '</table>';
