From 68f5cf31df3ef4a23aa777c80e96395c5f67776f Mon Sep 17 00:00:00 2001 From: FranciscoBorja12 Date: Thu, 19 Dec 2024 22:48:16 -0600 Subject: [PATCH] =?UTF-8?q?dise=C3=B1o=20v2.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Inventario/templates/Base.html | 96 +++------ Inventario/templates/articulo_nuevo.html | 40 ++-- Inventario/templates/articulo_registro.html | 86 ++++---- Inventario/templates/articulo_update.html | 37 ++-- Inventario/templates/bodega_nuevo.html | 37 ++-- Inventario/templates/bodega_registro.html | 85 ++++---- Inventario/templates/bodega_update.html | 38 ++-- Inventario/templates/grafico_chartjs.html | 80 +++++++- Inventario/templates/index.html | 4 + Inventario/templates/inventario_nuevo.html | 41 ++-- Inventario/templates/inventario_registro.html | 81 ++++---- .../templates/mov_inventario_registro.html | 71 ++++--- Inventario/templates/nueva_venta.html | 35 ++-- Inventario/templates/pdf.html | 192 +++++++++++++++--- Inventario/templates/proveedor_nuevo.html | 40 ++-- Inventario/templates/proveedor_registro.html | 76 +++---- Inventario/templates/proveedor_update.html | 40 ++-- Inventario/templates/reporte_pdf.html | 46 +++++ Inventario/templates/signin.html | 45 ++-- Inventario/templates/tipo_articulo_nuevo.html | 39 ++-- .../templates/tipo_articulo_registro.html | 69 ++++--- .../templates/tipo_articulo_update.html | 38 ++-- Inventario/templates/ventas.html | 51 ++--- Inventario/views.py | 1 + Inventario/viewspdf.py | 81 +++++++- TiendAlfa/urls.py | 4 +- 26 files changed, 877 insertions(+), 576 deletions(-) create mode 100644 Inventario/templates/reporte_pdf.html diff --git a/Inventario/templates/Base.html b/Inventario/templates/Base.html index ac73800..adbd397 100644 --- a/Inventario/templates/Base.html +++ b/Inventario/templates/Base.html @@ -4,114 +4,82 @@ Tienda Dany - - - + + + + -{% block content %} - -{% endblock %} - - - - + {% block content %} + {% endblock %} + \ No newline at end of file diff --git a/Inventario/templates/articulo_nuevo.html b/Inventario/templates/articulo_nuevo.html index 0e62345..5679f3c 100644 --- a/Inventario/templates/articulo_nuevo.html +++ b/Inventario/templates/articulo_nuevo.html @@ -2,25 +2,22 @@ {% block content %} -
-
-
-
-
-
-

Registrar nuevo articulo

- -
-
- {% csrf_token %} - {{form.as_p}} -
- +
+
+
+ + {% csrf_token %} +

Registrar Nuevo Artículo

+
+ {{ form.as_p }} +
+
+ + Cancelar + +
@@ -28,9 +25,10 @@
- -{% endblock %} \ No newline at end of file + +{% endblock %} \ No newline at end of file diff --git a/Inventario/templates/articulo_registro.html b/Inventario/templates/articulo_registro.html index ce7ed9d..cfccb18 100644 --- a/Inventario/templates/articulo_registro.html +++ b/Inventario/templates/articulo_registro.html @@ -1,56 +1,60 @@ {% extends "Base.html" %} {% block content %} -
+
-
-
-
-

Tabla de articulos

-
+
+
+
+

Gestión de Artículos

+
+
- - +
+ - - - - + + + + - - - - + + + - {% for articulo in persona %} - - - - - - - - - - - - {% endfor %} - -
#Nombre del articuloMedida del articuloDescripcionTipo del articuloNombreMedidaDescripciónTipo ProveedorPrecio de compraPrecio de ventaACTUALIZARPrecio CompraPrecio VentaAcción
{{ articulo.id }} {{ articulo.nombre_articulo }} {{ articulo.medida }} {{ articulo.descripcion }} {{ articulo.tipo_articulo.tipo_articulo }} {{ articulo.proveedor.nombre_proveedor }} {{ articulo.precio_compra }} {{ articulo.precio_venta }} 📝
+ {% for articulo in persona %} + + {{ articulo.id }} + {{ articulo.nombre_articulo }} + {{ articulo.medida }} + {{ articulo.descripcion }} + {{ articulo.tipo_articulo.tipo_articulo }} + {{ articulo.proveedor.nombre_proveedor }} + ${{ articulo.precio_compra|floatformat:2 }} + ${{ articulo.precio_venta|floatformat:2 }} + + + Editar + + + + {% empty %} + + No hay artículos registrados. + + {% endfor %} + + +
- -
-
-
- - 💾 -
-
+
+ + +
- -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/Inventario/templates/articulo_update.html b/Inventario/templates/articulo_update.html index af4cd6b..79a4128 100644 --- a/Inventario/templates/articulo_update.html +++ b/Inventario/templates/articulo_update.html @@ -1,30 +1,27 @@ {% extends "Base.html" %} {% block content %} -
-
-
-
-
-
-

Actualizar Articulo

-
-
- {% csrf_token %} - {{form.as_p}} - -
- +
+
+
+ + {% csrf_token %} +

Actualizar Artículo

+
+ {{ form.as_p }} +
+
+ + Cancelar + +
-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/Inventario/templates/bodega_nuevo.html b/Inventario/templates/bodega_nuevo.html index cb0f669..e6dd126 100644 --- a/Inventario/templates/bodega_nuevo.html +++ b/Inventario/templates/bodega_nuevo.html @@ -2,24 +2,22 @@ {% block content %} -
-
-
-
-
-
-

Registrar nueva bodega

-
-
- {% csrf_token %} - {{form}} -
- +
+
+
+ + {% csrf_token %} +

Registrar nueva bodega

+
+ {{ form }} +
+
+ + Cancelar + +
@@ -31,6 +29,5 @@ input.value = input.value.replace(/[^0-9]/g, ''); } - -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/Inventario/templates/bodega_registro.html b/Inventario/templates/bodega_registro.html index 5a7ca28..8481e3d 100644 --- a/Inventario/templates/bodega_registro.html +++ b/Inventario/templates/bodega_registro.html @@ -1,54 +1,61 @@ {% extends "Base.html" %} {% block content %} -
-
-
-
-
-

Tabla de Bodega

-
+
+
+
+
+
+

Tabla de Bodega

+
+
- - +
+ - - + + - - + + - {% for bodega in persona %} - - - - - {% if bodega.estado %} - - {% else %} - - {% endif %} - - - - {% endfor %} - -
#Codigo de la bodegaNombre la bodegaCódigo de la BodegaNombre de la Bodega EstadoDireccionACTUALIZARDirecciónActualizar
{{bodega.id}} {{bodega.codigo_bodega}} {{bodega.nombre_bodega}} activo inactivo {{bodega.direccion_bodega}} 📝
+ {% for bodega in persona %} + + {{ bodega.id }} + {{ bodega.codigo_bodega }} + {{ bodega.nombre_bodega }} + + {% if bodega.estado %} + Activo + {% else %} + Inactivo + {% endif %} + + {{ bodega.direccion_bodega }} + + + Editar + + + + {% empty %} + + No hay bodegas registradas. + + {% endfor %} + + +
- - -
-
-
- - 💾 -
-
+
+ + +
-{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/Inventario/templates/bodega_update.html b/Inventario/templates/bodega_update.html index eb486dd..088cfab 100644 --- a/Inventario/templates/bodega_update.html +++ b/Inventario/templates/bodega_update.html @@ -1,28 +1,26 @@ {% extends "Base.html" %} {% block content %} -
-
-
-
-
-
-

Actualizar Bodega

-
-
- {% csrf_token %} - {{form}} - -
- +
+
+
+ + {% csrf_token %} +

Actualizar Bodega

+
+ {{ form }} +
+
+ + Cancelar + +
-{% endblock %} \ No newline at end of file + +{% endblock %} \ No newline at end of file diff --git a/Inventario/templates/grafico_chartjs.html b/Inventario/templates/grafico_chartjs.html index 0016d87..14c5753 100644 --- a/Inventario/templates/grafico_chartjs.html +++ b/Inventario/templates/grafico_chartjs.html @@ -1,36 +1,94 @@ - + + + + Gráfico Interactivo + + + + + + + -

Gráfico de cantidad de productos

- + +
+

Gráfico de Cantidad de Productos

+ + + + + + Volver +
+ - volver + + \ No newline at end of file diff --git a/Inventario/templates/index.html b/Inventario/templates/index.html index f8118c9..2e4b6c1 100644 --- a/Inventario/templates/index.html +++ b/Inventario/templates/index.html @@ -166,6 +166,10 @@ }); {% else %} + + {% endif %} {% endblock %} diff --git a/Inventario/templates/inventario_nuevo.html b/Inventario/templates/inventario_nuevo.html index a85af18..6d53dc2 100644 --- a/Inventario/templates/inventario_nuevo.html +++ b/Inventario/templates/inventario_nuevo.html @@ -2,27 +2,22 @@ {% block content %} -
-
-
-
-
-
-

Registrar nuevo movimiento de inventario

- -
-
-
- {% csrf_token %} - {{form.as_p}} - -
- +
+
+
+ + {% csrf_token %} +

Registrar nuevo movimiento de inventario

+
+ {{ form.as_p }} +
+
+ + Cancelar + +
@@ -34,5 +29,5 @@ input.value = input.value.replace(/[^0-9]/g, ''); } - -{% endblock %} \ No newline at end of file + +{% endblock %} \ No newline at end of file diff --git a/Inventario/templates/inventario_registro.html b/Inventario/templates/inventario_registro.html index ade5552..c75ddb0 100644 --- a/Inventario/templates/inventario_registro.html +++ b/Inventario/templates/inventario_registro.html @@ -1,57 +1,60 @@ {% extends "Base.html" %} {% block content %} -
-
-
-
-
-

Inventario

-
+
+
+
+
+
+

Inventario

+
+
- - +
+ - - + + - {% for inventario in persona %} - - - - - - - - {% endfor %} - -
#ArticuloDescripcion de articuloArtículoDescripción de Artículo Bodega Cantidad
{{ inventario.id }} {{ inventario.articulo.nombre_articulo }} {{inventario.articulo.medida}} {{ inventario.articulo.descripcion }} {{ inventario.bodega.nombre_bodega }} {{ inventario.cantidad }}
+ {% for inventario in persona %} + + {{ inventario.id }} + {{ inventario.articulo.nombre_articulo }} {{ inventario.articulo.medida }} + {{ inventario.articulo.descripcion }} + {{ inventario.bodega.nombre_bodega }} + {{ inventario.cantidad }} + + {% empty %} + + No hay inventarios registrados. + + {% endfor %} + + +
- +
-
-{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/Inventario/templates/mov_inventario_registro.html b/Inventario/templates/mov_inventario_registro.html index 1aab8ab..fb0509f 100644 --- a/Inventario/templates/mov_inventario_registro.html +++ b/Inventario/templates/mov_inventario_registro.html @@ -1,47 +1,60 @@ {% extends "Base.html" %} {% block content %} -
-
-
-
-
-

Tabla de movimientos de inventario

-
+
+
+
+
+
+

Movimientos de Inventario

+
+
- - +
+ - + - + - {% for movimiento_inventario in persona %} - - - - - - - - {% endfor %} - -
# BodegaArticuloArtículo CantidadTipo de movimientoTipo de Movimiento
{{ movimiento_inventario.id }} {{ movimiento_inventario.articulo.nombre_articulo }} {{movimiento_inventario.articulo.medida}} {{ movimiento_inventario.bodega.nombre_bodega }} {{ movimiento_inventario.cantidad }} {{ movimiento_inventario.tipo_inventario }}
+ {% for movimiento_inventario in persona %} + + {{ movimiento_inventario.id }} + {{ movimiento_inventario.articulo.nombre_articulo }} {{ movimiento_inventario.articulo.medida }} + {{ movimiento_inventario.bodega.nombre_bodega }} + {{ movimiento_inventario.cantidad }} + {{ movimiento_inventario.tipo_inventario }} + + {% empty %} + + No hay movimientos registrados. + + {% endfor %} + + +
- +
-
-{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/Inventario/templates/nueva_venta.html b/Inventario/templates/nueva_venta.html index 200b670..df776de 100644 --- a/Inventario/templates/nueva_venta.html +++ b/Inventario/templates/nueva_venta.html @@ -2,25 +2,22 @@ {% block content %} -
-
-
-
-
-
-

Registrar nueva venta

- -
-
- {% csrf_token %} - {{form.as_p}} -
- +
+
+
+ + {% csrf_token %} +

Registrar nueva venta

+
+ {{ form.as_p }} +
+
+ + Cancelar + +
diff --git a/Inventario/templates/pdf.html b/Inventario/templates/pdf.html index 02d5c73..0b209d7 100644 --- a/Inventario/templates/pdf.html +++ b/Inventario/templates/pdf.html @@ -1,36 +1,172 @@ - + + + + Reporte de Inventario + -

Reporte de Inventario

- - - - - - - - - - - - {% for item in inventarios %} - - - - - - - - {% endfor %} - -
IDBodegaArtículoCantidadPrecio
{{ item.id }}{{ item.bodega.nombre_bodega }}{{ item.articulo.nombre_articulo }}{{ item.cantidad }}{{ item.precio }}
+ +
+

Reporte de Inventario

+ + + + + + + + + + + + + + + {% for item in inventarios %} + + + + + + + {% endfor %} + +
IDBodegaArtículoCantidad
{{ item.id }}{{ item.bodega.nombre_bodega }}{{ item.articulo.nombre_articulo }}{{ item.cantidad }}
+
+ + + \ No newline at end of file diff --git a/Inventario/templates/proveedor_nuevo.html b/Inventario/templates/proveedor_nuevo.html index 89711a8..00af689 100644 --- a/Inventario/templates/proveedor_nuevo.html +++ b/Inventario/templates/proveedor_nuevo.html @@ -1,32 +1,29 @@ - {% extends "Base.html" %} {% block content %} -
-
-
-
-
-
-

Registrar Nuevo Proveedor

-
-
- {% csrf_token %} - {{form}} - -
- +
+
+
+ + {% csrf_token %} +

Registrar Nuevo Proveedor

+
+ {{ form }} +
+
+ + Cancelar + +
+ -{% endblock %} \ No newline at end of file + +{% endblock %} \ No newline at end of file diff --git a/Inventario/templates/proveedor_registro.html b/Inventario/templates/proveedor_registro.html index 3e51286..2b1247b 100644 --- a/Inventario/templates/proveedor_registro.html +++ b/Inventario/templates/proveedor_registro.html @@ -1,53 +1,55 @@ {% extends "Base.html" %} {% block content %} -
-
-
-
-
-

Tabla de proveedores

-
+
+
+
+
+
+

Tabla de Proveedores

+
+
- - +
+ - - - + + + - {% for proveedor in persona %} - - - - - - - - - {% endfor %} - -
# Nombre EmailTelefonoDireccionACTUALIZARTeléfonoDirecciónActualizar
{{proveedor.id}} {{proveedor.nombre_proveedor}} {{proveedor.email}} {{proveedor.telefono}} {{proveedor.direccion}} 📝
+ {% for proveedor in persona %} + + {{ proveedor.id }} + {{ proveedor.nombre_proveedor }} + {{ proveedor.email }} + {{ proveedor.telefono }} + {{ proveedor.direccion }} + + + 📝 + + + + {% empty %} + + No hay proveedores registrados. + + {% endfor %} + + +
- - - -
- -
-
- - 💾 -
-
+
- + + +
-{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/Inventario/templates/proveedor_update.html b/Inventario/templates/proveedor_update.html index 2dc189c..80f591e 100644 --- a/Inventario/templates/proveedor_update.html +++ b/Inventario/templates/proveedor_update.html @@ -1,29 +1,27 @@ {% extends "Base.html" %} {% block content %} -
-
-
-
-
-
-

Actualizar proveedor

-
-
- - {% csrf_token %} - {{form}} - -
- + +
+
+
+ + {% csrf_token %} +

Actualizar Proveedor

+
+ {{ form }} +
+
+ + Cancelar + +
-{% endblock %} \ No newline at end of file + +{% endblock %} \ No newline at end of file diff --git a/Inventario/templates/reporte_pdf.html b/Inventario/templates/reporte_pdf.html new file mode 100644 index 0000000..3bfeb96 --- /dev/null +++ b/Inventario/templates/reporte_pdf.html @@ -0,0 +1,46 @@ + + + + + Reporte de Inventario + + + +

Reporte de Movimientos de Inventario

+ + + + + + + + + + + + {% for movimiento in movimientos %} + + + + + + + + {% endfor %} + +
FechaTipo de MovimientoBodegaArtículoCantidad
{{ movimiento.fecha }}{{ movimiento.tipo_inventario }}{{ movimiento.bodega }}{{ movimiento.articulo }}{{ movimiento.cantidad }}
+ + \ No newline at end of file diff --git a/Inventario/templates/signin.html b/Inventario/templates/signin.html index 8ac8644..ee94336 100644 --- a/Inventario/templates/signin.html +++ b/Inventario/templates/signin.html @@ -2,27 +2,32 @@ {% block content %} -
-
-
-
-

Login

- {% csrf_token %} -
- - -
-
- - -
- -
+
+
+
+
+
+

Iniciar Sesión

+
+ {% csrf_token %} + +
+ + +
+
+ + +
+
+ +
+
+ +
+
- -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/Inventario/templates/tipo_articulo_nuevo.html b/Inventario/templates/tipo_articulo_nuevo.html index 2a7721d..5fb8edc 100644 --- a/Inventario/templates/tipo_articulo_nuevo.html +++ b/Inventario/templates/tipo_articulo_nuevo.html @@ -2,29 +2,26 @@ {% block content %} -
-
-
-
-
-
-

Registrar nuevo tipo de articulo

- -
-
- {% csrf_token %} - {{form}} - -
- +
+
+
+ + {% csrf_token %} +

Registrar nuevo tipo de artículo

+
+ {{ form }} +
+
+ + Cancelar + +
-{% endblock %} \ No newline at end of file + +{% endblock %} \ No newline at end of file diff --git a/Inventario/templates/tipo_articulo_registro.html b/Inventario/templates/tipo_articulo_registro.html index 0e1c2bb..e5fe331 100644 --- a/Inventario/templates/tipo_articulo_registro.html +++ b/Inventario/templates/tipo_articulo_registro.html @@ -1,44 +1,53 @@ {% extends "Base.html" %} {% block content %} -
-
-
-
-
-

Tabla de tipos de articulos

-
+
+
+
+
+
+

Tabla de Tipos de Artículos

+
+
- - +
+ - - - + + + - {% for tipo_articulo in persona %} - - - - - - {% endfor %} - -
#tipo de articuloDescripcionACTUALIZARTipo de ArtículoDescripciónActualizar
{{tipo_articulo.id}} {{tipo_articulo.tipo_articulo}} {{tipo_articulo.descripcion}} 📝
+ {% for tipo_articulo in persona %} + + {{ tipo_articulo.id }} + {{ tipo_articulo.tipo_articulo }} + {{ tipo_articulo.descripcion }} + + + 📝 + + + + {% empty %} + + No hay tipos de artículos registrados. + + {% endfor %} + + +
- -
-
-
- - 💾 -
-
+
+ + + + +
-{% endblock %} \ No newline at end of file +{% endblock %} \ No newline at end of file diff --git a/Inventario/templates/tipo_articulo_update.html b/Inventario/templates/tipo_articulo_update.html index 04fbf48..50f1f61 100644 --- a/Inventario/templates/tipo_articulo_update.html +++ b/Inventario/templates/tipo_articulo_update.html @@ -1,29 +1,27 @@ {% extends "Base.html" %} {% block content %} -
-
-
-
-
-
-

Actualizar proveedor

-
-
- {% csrf_token %} - {{form}} - -
- +
+
+
+ + {% csrf_token %} +

Actualizar tipo de artículo

+
+ {{ form }} +
+
+ + Cancelar + +
-{% endblock %} \ No newline at end of file + +{% endblock %} \ No newline at end of file diff --git a/Inventario/templates/ventas.html b/Inventario/templates/ventas.html index 926e1c1..8266299 100644 --- a/Inventario/templates/ventas.html +++ b/Inventario/templates/ventas.html @@ -1,16 +1,17 @@ {% extends "Base.html" %} {% block content %} -
-
-
-
-
-

Tabla de ventas

-
+
+
+
+
+
+

Tabla de Ventas

+
+
- - +
+ @@ -24,8 +25,8 @@ {% for venta in ventas %} - - + + @@ -34,21 +35,23 @@ - {% endfor %} - -
# Fecha
{{venta.id}}
{{ venta.id }} {{ venta.fecha }} {{ venta.bodega }} {{ venta.articulo.nombre_articulo }}${{ venta.total }} {{ venta.observaciones }}
+ {% empty %} + + No hay ventas registradas. + + {% endfor %} + + +
- - -
-
-
- - 💾 -
-
+
+ + + + +
-{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/Inventario/views.py b/Inventario/views.py index ee91729..7251813 100644 --- a/Inventario/views.py +++ b/Inventario/views.py @@ -73,6 +73,7 @@ def graficos_view(request): } return render(request, "index.html", context) + def signin(request): if request.method == 'GET': return render ( request, 'signin.html',{ diff --git a/Inventario/viewspdf.py b/Inventario/viewspdf.py index 77b98ac..bb586ac 100644 --- a/Inventario/viewspdf.py +++ b/Inventario/viewspdf.py @@ -2,10 +2,10 @@ from django.contrib.auth.decorators import login_required from django.http import HttpResponse import openpyxl import csv -from django.template.loader import get_template +from django.template.loader import get_template, render_to_string from xhtml2pdf import pisa from django.shortcuts import render -from .models import inventario +from .models import inventario, movimiento_inventario @login_required def generar_reporte_pdf(request): @@ -39,12 +39,12 @@ def generar_reporte_excel(request): ws.title = 'Reporte de Inventario' # Encabezados - headers = ['ID', 'Bodega', 'Artículo', 'Cantidad', 'Precio'] + headers = ['ID', 'Bodega', 'Artículo', 'Cantidad'] ws.append(headers) # Datos del inventario for item in inventario.objects.all(): - ws.append([item.id, item.bodega.nombre_bodega, item.articulo.nombre_articulo, item.cantidad, item.precio]) + ws.append([item.id, item.bodega.nombre_bodega, item.articulo.nombre_articulo, item.cantidad]) # Configurar la respuesta HTTP response = HttpResponse(content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') @@ -63,21 +63,88 @@ def generar_reporte_csv(request): writer = csv.writer(response) # Encabezados - writer.writerow(['ID', 'Bodega', 'Artículo', 'Cantidad', 'Precio']) + writer.writerow(['ID', 'Bodega', 'Artículo', 'Cantidad']) # Datos del inventario for item in inventario.objects.all(): - writer.writerow([item.id, item.bodega.nombre_bodega, item.articulo.nombre_articulo, item.cantidad, item.precio]) + writer.writerow([item.id, item.bodega.nombre_bodega, item.articulo.nombre_articulo, item.cantidad]) return response @login_required def generar_grafico_chartjs(request): + # Obtener todos los inventarios inventarios = inventario.objects.all() + + # Extraer los productos, cantidades y medidas (suponiendo que cada producto tiene una medida asociada) productos = [item.articulo.nombre_articulo for item in inventarios] cantidades = [item.cantidad for item in inventarios] + medidas = [item.articulo.medida for item in inventarios] # Asumiendo que cada 'articulo' tiene un atributo 'medida' + # Pasar los datos a la plantilla return render(request, 'grafico_chartjs.html', { 'productos': productos, 'cantidades': cantidades, - }) \ No newline at end of file + 'medidas': medidas, # Pasar las medidas también + }) + +def reporte_excel(request): + # Obtener todos los movimientos de inventario + movimientos = movimiento_inventario.objects.all() + + # Crear la respuesta de archivo Excel + response = HttpResponse(content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') + response['Content-Disposition'] = 'attachment; filename="reporte_inventario.xlsx"' + + # Crear el libro de Excel + wb = openpyxl.Workbook() + ws = wb.active + ws.title = "Movimientos de Inventario" + + # Crear encabezados de columnas + ws.append(['Fecha', 'Tipo de Movimiento', 'Bodega', 'Artículo', 'Cantidad', 'Observaciones']) + + # Agregar los datos + for movimiento in movimientos: + ws.append([movimiento.fecha, movimiento.tipo_inventario, movimiento.bodega, movimiento.articulo, movimiento.cantidad, movimiento.observaciones]) + + # Guardar el archivo Excel + wb.save(response) + return response + +def reporte_pdf(request): + # Obtener todos los movimientos de inventario + movimientos = movimiento_inventario.objects.all() + + # Renderizar la plantilla HTML + html_string = render_to_string('reporte_pdf.html', {'movimientos': movimientos}) + + # Crear un objeto HttpResponse para el PDF + response = HttpResponse(content_type='application/pdf') + response['Content-Disposition'] = 'attachment; filename="reporte_inventario.pdf"' + + # Convertir HTML a PDF usando xhtml2pdf + pisa_status = pisa.CreatePDF(html_string, dest=response) + + if pisa_status.err: + return HttpResponse('Error generando el PDF', status=500) + + return response + +def reporte_csv(request): + # Obtener todos los movimientos de inventario + movimientos = movimiento_inventario.objects.all() + + # Crear la respuesta de archivo CSV + response = HttpResponse(content_type='text/csv') + response['Content-Disposition'] = 'attachment; filename="reporte_inventario.csv"' + + # Crear el escritor de CSV + writer = csv.writer(response) + writer.writerow(['Fecha', 'Tipo de Movimiento', 'Bodega', 'Artículo', 'Cantidad', 'Observaciones']) + + # Escribir los datos + for movimiento in movimientos: + writer.writerow([movimiento.fecha, movimiento.tipo_inventario, movimiento.bodega, movimiento.articulo, movimiento.cantidad, movimiento.observaciones]) + + return response diff --git a/TiendAlfa/urls.py b/TiendAlfa/urls.py index 0cda0c8..adc6b5c 100644 --- a/TiendAlfa/urls.py +++ b/TiendAlfa/urls.py @@ -45,7 +45,9 @@ urlpatterns = [ path('grafico/chartjs/',viewspdf.generar_grafico_chartjs, name ='generar_grafico_chartjs'), path('ventas/',views.lista_ventas, name ='lista_ventas'), path('ventas/nueva_venta/',views.nueva_venta, name ='nueva_venta'), - + path('reportes/pdf/',viewspdf.reporte_pdf, name ='reporte_pdf'), + path('reportes/excel/',viewspdf.reporte_excel, name ='reporte_excel'), + path('reportes/csv/',viewspdf.reporte_csv, name ='reporte_csv'),