Private
Public Access
cocinado cu-01
Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
1 parent
31f8b493d0
commit
3c4bc5c008
15 files changed
+510
-32
No files matched your search
@@ -30,6 +30,7 @@ var permisosSemilla = []permisoSemilla{
|
|||||||
{11, "Gestión de Proveedores", "proveedores", "Consultar y administrar los proveedores de la empresa."},
|
{11, "Gestión de Proveedores", "proveedores", "Consultar y administrar los proveedores de la empresa."},
|
||||||
{12, "Gestión de Clientes", "clientes", "Consultar y administrar los clientes de la empresa."},
|
{12, "Gestión de Clientes", "clientes", "Consultar y administrar los clientes de la empresa."},
|
||||||
{14, "Generar Reporte de Stock", "stock/reportes", "Generar y consultar reportes de stock."},
|
{14, "Generar Reporte de Stock", "stock/reportes", "Generar y consultar reportes de stock."},
|
||||||
|
{15, "Gestión de Ventas y Facturación", "facturas", "Consultar y operar la facturación y ventas de la empresa."},
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitPermisos crea el catálogo global de permisos y garantiza que cada
|
// InitPermisos crea el catálogo global de permisos y garantiza que cada
|
||||||
@@ -86,6 +87,8 @@ func AsegurarGruposEmpresa(db *gorm.DB, empresaID uint) (uint, uint, error) {
|
|||||||
10,
|
10,
|
||||||
11,
|
11,
|
||||||
12,
|
12,
|
||||||
|
13,
|
||||||
|
14,
|
||||||
}
|
}
|
||||||
if err := asignarPermisosFaltantes(db, admin.ID, permisosAdmin); err != nil {
|
if err := asignarPermisosFaltantes(db, admin.ID, permisosAdmin); err != nil {
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
@@ -98,6 +101,7 @@ func AsegurarGruposEmpresa(db *gorm.DB, empresaID uint) (uint, uint, error) {
|
|||||||
10,
|
10,
|
||||||
11,
|
11,
|
||||||
12,
|
12,
|
||||||
|
13,
|
||||||
}
|
}
|
||||||
if err := asignarPermisosFaltantes(db, usuario.ID, permisosUsuario); err != nil {
|
if err := asignarPermisosFaltantes(db, usuario.ID, permisosUsuario); err != nil {
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package repositorios_decorator
|
||||||
|
|
||||||
|
import "gorm.io/gorm"
|
||||||
|
|
||||||
|
type DecoradorCliente struct {
|
||||||
|
envuelto IFacturaQuery
|
||||||
|
cliente string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d DecoradorCliente) Aplicar(db *gorm.DB) *gorm.DB {
|
||||||
|
consulta := d.envuelto.Aplicar(db)
|
||||||
|
if d.cliente != "" {
|
||||||
|
consulta = consulta.Joins("JOIN clientes ON clientes.id = factura.`ClienteID`").
|
||||||
|
Where("clientes.nombre LIKE ?", "%"+d.cliente+"%")
|
||||||
|
}
|
||||||
|
return consulta
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package repositorios_decorator
|
||||||
|
|
||||||
|
import "gorm.io/gorm"
|
||||||
|
|
||||||
|
type DecoradorClienteID struct {
|
||||||
|
envuelto IFacturaQuery
|
||||||
|
clienteID uint
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d DecoradorClienteID) Aplicar(db *gorm.DB) *gorm.DB {
|
||||||
|
consulta := d.envuelto.Aplicar(db)
|
||||||
|
if d.clienteID > 0 {
|
||||||
|
consulta = consulta.Where("`ClienteID` = ?", d.clienteID)
|
||||||
|
}
|
||||||
|
return consulta
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package repositorios_decorator
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DecoradorDesde struct {
|
||||||
|
envuelto IFacturaQuery
|
||||||
|
desde *time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d DecoradorDesde) Aplicar(db *gorm.DB) *gorm.DB {
|
||||||
|
consulta := d.envuelto.Aplicar(db)
|
||||||
|
if d.desde != nil {
|
||||||
|
consulta = consulta.Where("factura.created_at >= ?", *d.desde)
|
||||||
|
}
|
||||||
|
return consulta
|
||||||
|
}
|
||||||
|
|
||||||
|
type DecoradorHasta struct {
|
||||||
|
envuelto IFacturaQuery
|
||||||
|
hasta *time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d DecoradorHasta) Aplicar(db *gorm.DB) *gorm.DB {
|
||||||
|
consulta := d.envuelto.Aplicar(db)
|
||||||
|
if d.hasta != nil {
|
||||||
|
consulta = consulta.Where("factura.created_at < ?", d.hasta.AddDate(0, 0, 1))
|
||||||
|
}
|
||||||
|
return consulta
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package repositorios_decorator
|
||||||
|
|
||||||
|
import "gorm.io/gorm"
|
||||||
|
|
||||||
|
type DecoradorNumero struct {
|
||||||
|
envuelto IFacturaQuery
|
||||||
|
numero string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d DecoradorNumero) Aplicar(db *gorm.DB) *gorm.DB {
|
||||||
|
consulta := d.envuelto.Aplicar(db)
|
||||||
|
if d.numero != "" {
|
||||||
|
consulta = consulta.Where("numero LIKE ?", "%"+d.numero+"%")
|
||||||
|
}
|
||||||
|
return consulta
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package repositorios_decorator
|
||||||
|
|
||||||
|
import "gorm.io/gorm"
|
||||||
|
|
||||||
|
type DecoradorPaginacion struct {
|
||||||
|
envuelto IFacturaQuery
|
||||||
|
pagina int
|
||||||
|
porPagina int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d DecoradorPaginacion) Aplicar(db *gorm.DB) *gorm.DB {
|
||||||
|
consulta := d.envuelto.Aplicar(db)
|
||||||
|
pagina, porPagina := NormalizarPagina(d.pagina, d.porPagina)
|
||||||
|
consulta = consulta.Order("factura.created_at DESC, factura.id DESC").
|
||||||
|
Offset((pagina - 1) * porPagina).
|
||||||
|
Limit(porPagina)
|
||||||
|
return consulta
|
||||||
|
}
|
||||||
|
|
||||||
|
func NormalizarPagina(pagina, porPagina int) (int, int) {
|
||||||
|
if pagina < 1 {
|
||||||
|
pagina = 1
|
||||||
|
}
|
||||||
|
if porPagina < 1 {
|
||||||
|
porPagina = 50
|
||||||
|
}
|
||||||
|
if porPagina > 200 {
|
||||||
|
porPagina = 200
|
||||||
|
}
|
||||||
|
return pagina, porPagina
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package repositorios_decorator
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
// FiltrosFactura acota la consulta del listado de facturas.
|
||||||
|
type FiltrosFactura struct {
|
||||||
|
Numero string
|
||||||
|
ClienteID uint
|
||||||
|
Cliente string
|
||||||
|
Desde *time.Time
|
||||||
|
Hasta *time.Time
|
||||||
|
Pagina int
|
||||||
|
PorPagina int
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package repositorios_decorator
|
||||||
|
|
||||||
|
import (
|
||||||
|
"repuestera_back/models"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IFacturaQuery es el componente base del patrón Decorator para facturas.
|
||||||
|
type IFacturaQuery interface {
|
||||||
|
Aplicar(db *gorm.DB) *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
// FacturaQueryBase es la implementación base de la cadena.
|
||||||
|
type FacturaQueryBase struct {
|
||||||
|
Preload bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q FacturaQueryBase) Aplicar(db *gorm.DB) *gorm.DB {
|
||||||
|
consulta := db.Model(&models.Factura{})
|
||||||
|
if q.Preload {
|
||||||
|
consulta = consulta.Preload("Cliente")
|
||||||
|
}
|
||||||
|
return consulta
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package repositorios_decorator
|
||||||
|
|
||||||
|
import "gorm.io/gorm"
|
||||||
|
|
||||||
|
// NuevaQueryFacturas arma la cadena de decoradores según los filtros.
|
||||||
|
func NuevaQueryFacturas(filtros FiltrosFactura, preload bool, paginar bool) IFacturaQuery {
|
||||||
|
var actual IFacturaQuery = FacturaQueryBase{Preload: preload}
|
||||||
|
|
||||||
|
actual = DecoradorNumero{envuelto: actual, numero: filtros.Numero}
|
||||||
|
actual = DecoradorClienteID{envuelto: actual, clienteID: filtros.ClienteID}
|
||||||
|
actual = DecoradorCliente{envuelto: actual, cliente: filtros.Cliente}
|
||||||
|
actual = DecoradorDesde{envuelto: actual, desde: filtros.Desde}
|
||||||
|
actual = DecoradorHasta{envuelto: actual, hasta: filtros.Hasta}
|
||||||
|
if paginar {
|
||||||
|
actual = DecoradorPaginacion{envuelto: actual, pagina: filtros.Pagina, porPagina: filtros.PorPagina}
|
||||||
|
} else {
|
||||||
|
actual = decoradorOrdenFacturas{envuelto: actual}
|
||||||
|
}
|
||||||
|
|
||||||
|
return actual
|
||||||
|
}
|
||||||
|
|
||||||
|
// decoradorOrdenFacturas aplica el orden por defecto cuando no se pagina.
|
||||||
|
type decoradorOrdenFacturas struct {
|
||||||
|
envuelto IFacturaQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d decoradorOrdenFacturas) Aplicar(db *gorm.DB) *gorm.DB {
|
||||||
|
consulta := d.envuelto.Aplicar(db)
|
||||||
|
return consulta.Order("factura.created_at DESC")
|
||||||
|
}
|
||||||
@@ -1,24 +1,15 @@
|
|||||||
package repositorios
|
package repositorios
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
|
|
||||||
"repuestera_back/models"
|
"repuestera_back/models"
|
||||||
|
decorator "repuestera_back/repositorios/Decorator/facturas"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FiltrosFactura struct {
|
|
||||||
Numero string
|
|
||||||
ClienteID uint
|
|
||||||
Cliente string
|
|
||||||
Desde *time.Time
|
|
||||||
Hasta *time.Time
|
|
||||||
}
|
|
||||||
|
|
||||||
type RepositorioFactura interface {
|
type RepositorioFactura interface {
|
||||||
IRepositorio[models.Factura]
|
IRepositorio[models.Factura]
|
||||||
Listar(filtros FiltrosFactura) ([]models.Factura, error)
|
Listar(filtros decorator.FiltrosFactura) ([]models.Factura, error)
|
||||||
ObtenerConRelaciones(id uint) (*models.Factura, error)
|
ObtenerConRelaciones(id uint) (*models.Factura, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,25 +30,10 @@ func NuevoRepositorioFactura(db *gorm.DB, empresaID uint) RepositorioFactura {
|
|||||||
func (r *repositorioFactura) Listar(filtros FiltrosFactura) ([]models.Factura, error) {
|
func (r *repositorioFactura) Listar(filtros FiltrosFactura) ([]models.Factura, error) {
|
||||||
var facturas []models.Factura
|
var facturas []models.Factura
|
||||||
|
|
||||||
query := r.db.Model(&models.Factura{}).Preload("Cliente")
|
paginar := filtros.Pagina > 0 || filtros.PorPagina > 0
|
||||||
if filtros.Numero != "" {
|
query := decorator.NuevaQueryFacturas(filtros, true, paginar).Aplicar(r.db)
|
||||||
query = query.Where("numero LIKE ?", "%"+filtros.Numero+"%")
|
|
||||||
}
|
|
||||||
if filtros.ClienteID > 0 {
|
|
||||||
query = query.Where("`ClienteID` = ?", filtros.ClienteID)
|
|
||||||
}
|
|
||||||
if filtros.Cliente != "" {
|
|
||||||
query = query.Joins("JOIN clientes ON clientes.id = factura.`ClienteID`").
|
|
||||||
Where("clientes.nombre LIKE ?", "%"+filtros.Cliente+"%")
|
|
||||||
}
|
|
||||||
if filtros.Desde != nil {
|
|
||||||
query = query.Where("factura.created_at >= ?", *filtros.Desde)
|
|
||||||
}
|
|
||||||
if filtros.Hasta != nil {
|
|
||||||
query = query.Where("factura.created_at < ?", filtros.Hasta.AddDate(0, 0, 1))
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := query.Order("factura.created_at DESC").Find(&facturas).Error; err != nil {
|
if err := query.Find(&facturas).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return facturas, nil
|
return facturas, nil
|
||||||
|
|||||||
@@ -8,10 +8,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func FacturaRoute(r *gin.Engine) {
|
func FacturaRoute(r *gin.Engine) {
|
||||||
|
// Lectura: accesible tanto por gestión de stock (para devoluciones) como
|
||||||
|
// por gestión de ventas.
|
||||||
grupo := r.Group("/facturas")
|
grupo := r.Group("/facturas")
|
||||||
grupo.Use(middleware.AuthMiddleware(9))
|
grupo.Use(middleware.AuthMiddleware(9, 15))
|
||||||
{
|
{
|
||||||
grupo.GET("/", factura.ObtenerFacturas)
|
grupo.GET("/", factura.ObtenerFacturas)
|
||||||
grupo.GET("/:id", factura.ObtenerFactura)
|
grupo.GET("/:id", factura.ObtenerFactura)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Escritura: solo gestión de ventas. Se agregan en CU-02, CU-05, CU-06,
|
||||||
|
// CU-07, CU-08 y CU-16.
|
||||||
|
escritura := r.Group("/facturas")
|
||||||
|
escritura.Use(middleware.AuthMiddleware(15))
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,34 @@
|
|||||||
import { API_URL } from '$lib/env';
|
import { API_URL } from '$lib/env';
|
||||||
import { getToken } from '../token';
|
import { getToken } from '../token';
|
||||||
|
|
||||||
export async function obtenerFacturas(fetch2?: Function) {
|
export interface FiltrosFactura {
|
||||||
|
numero?: string;
|
||||||
|
cliente?: string;
|
||||||
|
clienteId?: number;
|
||||||
|
estado?: string;
|
||||||
|
desde?: string;
|
||||||
|
hasta?: string;
|
||||||
|
pagina?: number;
|
||||||
|
porPagina?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function obtenerFacturas(fetch2?: Function, filtros?: FiltrosFactura) {
|
||||||
const fetchfn = fetch2 ? fetch2 : fetch;
|
const fetchfn = fetch2 ? fetch2 : fetch;
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
if (filtros) {
|
||||||
|
if (filtros.numero) params.set('numero', filtros.numero);
|
||||||
|
if (filtros.cliente) params.set('cliente', filtros.cliente);
|
||||||
|
if (filtros.clienteId) params.set('clienteId', String(filtros.clienteId));
|
||||||
|
if (filtros.estado) params.set('estado', filtros.estado);
|
||||||
|
if (filtros.desde) params.set('desde', filtros.desde);
|
||||||
|
if (filtros.hasta) params.set('hasta', filtros.hasta);
|
||||||
|
if (filtros.pagina) params.set('pagina', String(filtros.pagina));
|
||||||
|
if (filtros.porPagina) params.set('porPagina', String(filtros.porPagina));
|
||||||
|
}
|
||||||
|
const qs = params.toString();
|
||||||
|
const url = `${API_URL}/facturas/${qs ? `?${qs}` : ''}`;
|
||||||
try {
|
try {
|
||||||
const req = await fetchfn(`${API_URL}/facturas/`, {
|
const req = await fetchfn(url, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${getToken()}` }
|
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${getToken()}` }
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,231 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import Header from '$lib/components/Header.svelte';
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
DataTableSkeleton,
|
||||||
|
InlineNotification,
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableContainer,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
Tag,
|
||||||
|
TextInput,
|
||||||
|
Select,
|
||||||
|
SelectItem,
|
||||||
|
Modal
|
||||||
|
} from 'carbon-components-svelte';
|
||||||
|
import { Add, View, Edit, Money, Close, Search } from 'carbon-icons-svelte';
|
||||||
|
import { goto } from '$app/navigation';
|
||||||
|
import { getPermissions } from '$lib/hooks/token';
|
||||||
|
import type { Factura } from '../../types';
|
||||||
|
|
||||||
|
let { data } = $props();
|
||||||
|
|
||||||
|
let error = $state('');
|
||||||
|
let info = $state('');
|
||||||
|
$effect(() => {
|
||||||
|
if (data.error) error = data.error;
|
||||||
|
});
|
||||||
|
|
||||||
|
let facturas = $derived<Factura[]>(Array.isArray(data.facturas) ? data.facturas : []);
|
||||||
|
let filtros = $derived(data.filtros ?? { numero: '', cliente: '', estado: '', desde: '', hasta: '' });
|
||||||
|
let cargando = $derived(data.facturas === undefined || data.facturas === null);
|
||||||
|
|
||||||
|
let puedeVentas = $derived(getPermissions().includes(13));
|
||||||
|
|
||||||
|
let numero = $state('');
|
||||||
|
let cliente = $state('');
|
||||||
|
let estado = $state('');
|
||||||
|
let desde = $state('');
|
||||||
|
let hasta = $state('');
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
numero = filtros.numero ?? '';
|
||||||
|
cliente = filtros.cliente ?? '';
|
||||||
|
estado = filtros.estado ?? '';
|
||||||
|
desde = filtros.desde ?? '';
|
||||||
|
hasta = filtros.hasta ?? '';
|
||||||
|
});
|
||||||
|
|
||||||
|
let facturaVer: Factura | null = $state(null);
|
||||||
|
let openVer = $state(false);
|
||||||
|
|
||||||
|
function buscar() {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
if (numero) params.set('numero', numero);
|
||||||
|
if (cliente) params.set('cliente', cliente);
|
||||||
|
if (estado) params.set('estado', estado);
|
||||||
|
if (desde) params.set('desde', desde);
|
||||||
|
if (hasta) params.set('hasta', hasta);
|
||||||
|
const q = params.toString();
|
||||||
|
void goto(`/facturas${q ? `?${q}` : ''}`, { keepFocus: true, noScroll: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
function limpiar() {
|
||||||
|
void goto('/facturas', { keepFocus: true, noScroll: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
function estadoTagKind(estado: string): 'green' | 'blue' | 'red' | 'gray' | 'warm-gray' {
|
||||||
|
switch (estado) {
|
||||||
|
case 'PAGADA':
|
||||||
|
return 'green';
|
||||||
|
case 'PARCIAL':
|
||||||
|
return 'blue';
|
||||||
|
case 'CANCELADA':
|
||||||
|
return 'red';
|
||||||
|
case 'EMITIDA':
|
||||||
|
return 'warm-gray';
|
||||||
|
default:
|
||||||
|
return 'gray';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatFecha(iso?: string): string {
|
||||||
|
if (!iso) return '-';
|
||||||
|
try {
|
||||||
|
return new Date(iso).toLocaleDateString('es-AR');
|
||||||
|
} catch {
|
||||||
|
return iso;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatMonto(n?: number): string {
|
||||||
|
if (n === undefined || n === null) return '-';
|
||||||
|
return n.toLocaleString('es-AR', { style: 'currency', currency: 'ARS' });
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Header />
|
||||||
|
|
||||||
|
<div class="page-container">
|
||||||
|
<div class="mb-4 flex flex-wrap items-center justify-between gap-2">
|
||||||
|
<h1 class="page-title">Gestión de Facturas</h1>
|
||||||
|
{#if puedeVentas}
|
||||||
|
<Button icon={Add} onclick={() => (info = 'La creación de facturas se implementa en CU-02.')}>
|
||||||
|
Nueva Factura
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if !puedeVentas}
|
||||||
|
<InlineNotification kind="warning" title="Sin permisos" subtitle="No tenés permiso para gestionar ventas y facturación." hideCloseButton />
|
||||||
|
{:else}
|
||||||
|
<form class="mb-6 flex flex-wrap items-end gap-4" onsubmit={(e) => { e.preventDefault(); buscar(); }}>
|
||||||
|
<div class="min-w-56 flex-1">
|
||||||
|
<TextInput labelText="Buscar" placeholder="N° factura o cliente" bind:value={numero} />
|
||||||
|
</div>
|
||||||
|
<div class="min-w-40">
|
||||||
|
<TextInput labelText="Cliente" placeholder="Nombre del cliente" bind:value={cliente} />
|
||||||
|
</div>
|
||||||
|
<Select labelText="Estado" bind:selected={estado}>
|
||||||
|
<SelectItem value="" text="Todos" />
|
||||||
|
<SelectItem value="EMITIDA" text="Emitida" />
|
||||||
|
<SelectItem value="PARCIAL" text="Parcial" />
|
||||||
|
<SelectItem value="PAGADA" text="Pagada" />
|
||||||
|
<SelectItem value="CANCELADA" text="Cancelada" />
|
||||||
|
</Select>
|
||||||
|
<div class="min-w-36">
|
||||||
|
<TextInput labelText="Desde" placeholder="YYYY-MM-DD" bind:value={desde} />
|
||||||
|
</div>
|
||||||
|
<div class="min-w-36">
|
||||||
|
<TextInput labelText="Hasta" placeholder="YYYY-MM-DD" bind:value={hasta} />
|
||||||
|
</div>
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<Button type="submit" icon={Search}>Buscar</Button>
|
||||||
|
<Button kind="ghost" icon={Close} onclick={limpiar}>Limpiar</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{#if error}
|
||||||
|
<InlineNotification kind="error" title="Error" subtitle={error} hideCloseButton />
|
||||||
|
{/if}
|
||||||
|
{#if info}
|
||||||
|
<InlineNotification kind="info" title="Info" subtitle={info} hideCloseButton />
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if cargando}
|
||||||
|
<DataTableSkeleton headers={[{ key: 'numero', value: 'N° Factura' }, { key: 'cliente', value: 'Cliente' }, { key: 'fecha', value: 'Fecha' }, { key: 'total', value: 'Total' }, { key: 'estado', value: 'Estado' }]} rows={5} size="compact" showHeader={false} showToolbar={false} />
|
||||||
|
{:else if facturas.length === 0}
|
||||||
|
<TableContainer title="Facturas">
|
||||||
|
<Table>
|
||||||
|
<TableHead>
|
||||||
|
<TableRow>
|
||||||
|
<TableHeader>N° Factura</TableHeader>
|
||||||
|
<TableHeader>Cliente</TableHeader>
|
||||||
|
<TableHeader>Fecha</TableHeader>
|
||||||
|
<TableHeader>Total</TableHeader>
|
||||||
|
<TableHeader>Estado</TableHeader>
|
||||||
|
<TableHeader>Acciones</TableHeader>
|
||||||
|
</TableRow>
|
||||||
|
</TableHead>
|
||||||
|
<TableBody>
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colspan={6}>No existen facturas registradas</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</TableContainer>
|
||||||
|
{:else}
|
||||||
|
<TableContainer title="Listado de Facturas">
|
||||||
|
<Table>
|
||||||
|
<TableHead>
|
||||||
|
<TableRow>
|
||||||
|
<TableHeader>N° Factura</TableHeader>
|
||||||
|
<TableHeader>Cliente</TableHeader>
|
||||||
|
<TableHeader>Fecha</TableHeader>
|
||||||
|
<TableHeader>Total</TableHeader>
|
||||||
|
<TableHeader>Estado</TableHeader>
|
||||||
|
<TableHeader>Acciones</TableHeader>
|
||||||
|
</TableRow>
|
||||||
|
</TableHead>
|
||||||
|
<TableBody>
|
||||||
|
{#each facturas as f (f.ID)}
|
||||||
|
<TableRow>
|
||||||
|
<TableCell>{f.numero ?? `F-${f.ID}`}</TableCell>
|
||||||
|
<TableCell>{f.cliente?.nombre ?? '-'}</TableCell>
|
||||||
|
<TableCell>{formatFecha(f.CreatedAt)}</TableCell>
|
||||||
|
<TableCell>{formatMonto(f.total)}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Tag type={estadoTagKind(f.estado)}>{f.estado}</Tag>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<div class="flex flex-wrap gap-1">
|
||||||
|
<Button kind="ghost" size="small" icon={View} onclick={() => { facturaVer = f; openVer = true; }}>Ver</Button>
|
||||||
|
<Button kind="ghost" size="small" icon={Edit} disabled={f.estado === 'CANCELADA' || f.estado === 'PAGADA'}>Modificar</Button>
|
||||||
|
<Button kind="ghost" size="small" icon={Money} disabled={f.estado === 'CANCELADA' || f.estado === 'PAGADA'}>Registrar Pago</Button>
|
||||||
|
<Button kind="danger-ghost" size="small" icon={Close} disabled={f.estado === 'CANCELADA'}>Cancelar</Button>
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
{/each}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</TableContainer>
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Modal bind:open={openVer} modalHeading={`Comprobante ${facturaVer?.numero ?? ''}`} passiveModal>
|
||||||
|
{#if facturaVer}
|
||||||
|
<div class="space-y-2">
|
||||||
|
<p><strong>Cliente:</strong> {facturaVer.cliente?.nombre ?? '-'}</p>
|
||||||
|
<p><strong>CUIT:</strong> {facturaVer.cliente?.cuit ?? '-'}</p>
|
||||||
|
<p><strong>Fecha:</strong> {formatFecha(facturaVer.CreatedAt)}</p>
|
||||||
|
<p><strong>Total:</strong> {formatMonto(facturaVer.total)}</p>
|
||||||
|
<p><strong>Estado:</strong> {facturaVer.estado}</p>
|
||||||
|
{#if facturaVer.detalles && facturaVer.detalles.length > 0}
|
||||||
|
<div class="mt-4">
|
||||||
|
<p class="mb-2 font-semibold">Ítems</p>
|
||||||
|
<ul class="list-disc pl-5">
|
||||||
|
{#each facturaVer.detalles as d (d.repuestoId)}
|
||||||
|
<li>Repuesto {d.repuestoId} — cant. {d.cantidad} × {formatMonto(d.precioUnitario)} = {formatMonto(d.subtotal)}</li>
|
||||||
|
{/each}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</Modal>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { obtenerFacturas } from '$lib/hooks/facturas/obtenerFacturas';
|
||||||
|
|
||||||
|
export let ssr = false;
|
||||||
|
|
||||||
|
export async function load({ fetch, depends, url }) {
|
||||||
|
depends('facturas:load');
|
||||||
|
|
||||||
|
const filtros = {
|
||||||
|
numero: url.searchParams.get('numero') ?? '',
|
||||||
|
cliente: url.searchParams.get('cliente') ?? '',
|
||||||
|
estado: url.searchParams.get('estado') ?? '',
|
||||||
|
desde: url.searchParams.get('desde') ?? '',
|
||||||
|
hasta: url.searchParams.get('hasta') ?? ''
|
||||||
|
};
|
||||||
|
|
||||||
|
const facturas = await obtenerFacturas(fetch, filtros);
|
||||||
|
|
||||||
|
return {
|
||||||
|
facturas,
|
||||||
|
filtros,
|
||||||
|
error: typeof facturas === 'string' ? facturas : ''
|
||||||
|
};
|
||||||
|
}
|
||||||
Vendored
+28
@@ -276,6 +276,34 @@ export interface Proveedor {
|
|||||||
telefono?: string;
|
telefono?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface FacturaDetalle {
|
||||||
|
repuestoId: number;
|
||||||
|
cantidad: number;
|
||||||
|
descuentoId?: number;
|
||||||
|
descuento?: number;
|
||||||
|
precioUnitario: number;
|
||||||
|
subtotal: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Factura {
|
||||||
|
ID: number;
|
||||||
|
CreatedAt?: string;
|
||||||
|
UpdatedAt?: string;
|
||||||
|
DeletedAt?: string | null;
|
||||||
|
EmpresaID?: number;
|
||||||
|
numero?: string;
|
||||||
|
estado: string;
|
||||||
|
total: number;
|
||||||
|
ClienteID?: number;
|
||||||
|
cliente?: Cliente;
|
||||||
|
ProveedorID?: number | null;
|
||||||
|
proveedor?: Proveedor | null;
|
||||||
|
seAviso?: boolean;
|
||||||
|
detalles?: FacturaDetalle[];
|
||||||
|
ResponsableID?: number;
|
||||||
|
responsable?: Usuario | null;
|
||||||
|
}
|
||||||
|
|
||||||
export interface FacturaResumen {
|
export interface FacturaResumen {
|
||||||
ID: number;
|
ID: number;
|
||||||
numero?: string;
|
numero?: string;
|
||||||
|
|||||||
Reference in new issue
Block a user