Skip to content

Commit

Permalink
Download reports in Excel
Browse files Browse the repository at this point in the history
  • Loading branch information
Kev1nByte committed Jul 20, 2023
1 parent cae49c4 commit 035ac85
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
92 changes: 92 additions & 0 deletions controllers/ventas.controlador.php
Expand Up @@ -419,6 +419,98 @@ static public function ctrRangoFechasVentas($fechaInicial, $fechaFinal){

}

// DESCARGAR EXCEL

static public function ctrDescargarReporte(){

if(isset($_GET["reporte"])){

$tabla = "ventas";

if(isset($_GET["fechaInicial"]) && isset($_GET["fechaFinal"])){

$ventas = ModeloVentas::mdlRangoFechasVentas($tabla, $_GET["fechaInicial"], $_GET["fechaFinal"]);

}else{

$item = null;
$valor = null;

$ventas = ModeloVentas::mdlMostrarVentas($tabla, $item, $valor);

}

// CREAMOS EL ARCHIVO DE EXCEL

$Name = $_GET["reporte"].'.xls';

header('Expires: 0');
header('Cache-control: private');
header("Content-type: application/vnd.ms-excel"); // Archivo de Excel
header("Cache-Control: cache, must-revalidate");
header('Content-Description: File Transfer');
header('Last-Modified: '.date('D, d M Y H:i:s'));
header("Pragma: public");
header('Content-Disposition:; filename="'.$Name.'"');
header("Content-Transfer-Encoding: binary");

echo utf8_decode("<table border='0'>
<tr>
<td style='font-weight:bold; border:1px solid #eee;'>CÓDIGO</td>
<td style='font-weight:bold; border:1px solid #eee;'>CLIENTE</td>
<td style='font-weight:bold; border:1px solid #eee;'>VENDEDOR</td>
<td style='font-weight:bold; border:1px solid #eee;'>CANTIDAD</td>
<td style='font-weight:bold; border:1px solid #eee;'>PRODUCTOS</td>
<td style='font-weight:bold; border:1px solid #eee;'>IMPUESTO</td>
<td style='font-weight:bold; border:1px solid #eee;'>NETO</td>
<td style='font-weight:bold; border:1px solid #eee;'>TOTAL</td>
<td style='font-weight:bold; border:1px solid #eee;'>METODO DE PAGO</td
<td style='font-weight:bold; border:1px solid #eee;'>FECHA</td>
</tr>");

foreach ($ventas as $row => $item){

$cliente = ControladorClientes::ctrMostrarClientes("id", $item["id_cliente"]);
$vendedor = ControladorUsuarios::ctrMostrarUsuarios("id", $item["id_vendedor"]);

echo utf8_decode("<tr>
<td style='border:1px solid #eee;'>".$item["codigo"]."</td>
<td style='border:1px solid #eee;'>".$cliente["nombre"]."</td>
<td style='border:1px solid #eee;'>".$vendedor["nombre"]."</td>
<td style='border:1px solid #eee;'>");

$productos = json_decode($item["productos"], true);

foreach ($productos as $key => $valueProductos) {

echo utf8_decode($valueProductos["cantidad"]."<br>");
}

echo utf8_decode("</td><td style='border:1px solid #eee;'>");

foreach ($productos as $key => $valueProductos) {

echo utf8_decode($valueProductos["descripcion"]."<br>");

}

echo utf8_decode("</td>
<td style='border:1px solid #eee;'>S/ ".number_format($item["impuesto"],2)."</td>
<td style='border:1px solid #eee;'>S/ ".number_format($item["neto"],2)."</td>
<td style='border:1px solid #eee;'>S/ ".number_format($item["total"],2)."</td>
<td style='border:1px solid #eee;'>".$item["metodo_pago"]."</td>
<td style='border:1px solid #eee;'>".substr($item["fecha"],0,10)."</td>
</tr>");

}

echo "</table>";

}

}

}

?>
13 changes: 13 additions & 0 deletions views/modulos/descargar-reporte.php
@@ -0,0 +1,13 @@
<?php

require_once "../../controllers/ventas.controlador.php";
require_once "../../models/ventas.modelos.php";
require_once "../../controllers/clientes.controlador.php";
require_once "../../models/clientes.modelos.php";
require_once "../../controllers/usuarios.controlador.php";
require_once "../../models/usuarios.modelos.php";

$reporte = new ControladorVentas();
$reporte -> ctrDescargarReporte();

?>
16 changes: 16 additions & 0 deletions views/modulos/reportes.php
Expand Up @@ -40,7 +40,23 @@

<div class="box-tools pull-right">

<?php

if(isset($_GET["fechaInicial"])){

echo '<a href="views/modulos/descargar-reporte.php?reporte=reporte&fechaInicial='.$_GET["fechaInicial"].'&fechaFinal='.$_GET["fechaFinal"].'">';

}else{

echo '<a href="views/modulos/descargar-reporte.php?reporte=reporte">';

}

?>

<button class="btn btn-success" style="margin-top:5px">Descargar reporte en Excel</button>

</a>

</div>

Expand Down

0 comments on commit 035ac85

Please sign in to comment.