Private
Public Access
correjido un error que no permitia buscar por usuario y añadido soporte
de busqueda por estado Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
1 parent
fe5b5d7a00
commit
837fd8fa44
9 files changed
+112
-22
No files matched your search
@@ -15,6 +15,7 @@ func ObtenerFacturas(c *gin.Context) {
|
|||||||
filtros := r.FiltrosFactura{
|
filtros := r.FiltrosFactura{
|
||||||
Numero: c.Query("numero"),
|
Numero: c.Query("numero"),
|
||||||
Cliente: c.Query("cliente"),
|
Cliente: c.Query("cliente"),
|
||||||
|
Estado: c.Query("estado"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if raw := c.Query("clienteId"); raw != "" {
|
if raw := c.Query("clienteId"); raw != "" {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ type DecoradorCliente struct {
|
|||||||
func (d DecoradorCliente) Aplicar(db *gorm.DB) *gorm.DB {
|
func (d DecoradorCliente) Aplicar(db *gorm.DB) *gorm.DB {
|
||||||
consulta := d.envuelto.Aplicar(db)
|
consulta := d.envuelto.Aplicar(db)
|
||||||
if d.cliente != "" {
|
if d.cliente != "" {
|
||||||
consulta = consulta.Joins("JOIN clientes ON clientes.id = factura.`ClienteID`").
|
consulta = consulta.Joins("JOIN clientes ON clientes.id = factura.`ClienteID` AND clientes.deleted_at IS NULL").
|
||||||
Where("clientes.nombre LIKE ?", "%"+d.cliente+"%")
|
Where("clientes.nombre LIKE ?", "%"+d.cliente+"%")
|
||||||
}
|
}
|
||||||
return consulta
|
return consulta
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ type DecoradorClienteID struct {
|
|||||||
func (d DecoradorClienteID) Aplicar(db *gorm.DB) *gorm.DB {
|
func (d DecoradorClienteID) Aplicar(db *gorm.DB) *gorm.DB {
|
||||||
consulta := d.envuelto.Aplicar(db)
|
consulta := d.envuelto.Aplicar(db)
|
||||||
if d.clienteID > 0 {
|
if d.clienteID > 0 {
|
||||||
consulta = consulta.Where("`ClienteID` = ?", d.clienteID)
|
consulta = consulta.Where("factura.`ClienteID` = ?", d.clienteID)
|
||||||
}
|
}
|
||||||
return consulta
|
return consulta
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package repositorios_decorator
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DecoradorEstado struct {
|
||||||
|
envuelto IFacturaQuery
|
||||||
|
estado string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d DecoradorEstado) Aplicar(db *gorm.DB) *gorm.DB {
|
||||||
|
consulta := d.envuelto.Aplicar(db)
|
||||||
|
// El estado se guarda en mayúsculas; normalizar evita que un valor en
|
||||||
|
// minúsculas filtre de más.
|
||||||
|
estado := strings.ToUpper(strings.TrimSpace(d.estado))
|
||||||
|
if estado != "" {
|
||||||
|
consulta = consulta.Where("factura.estado = ?", estado)
|
||||||
|
}
|
||||||
|
return consulta
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ type DecoradorNumero struct {
|
|||||||
func (d DecoradorNumero) Aplicar(db *gorm.DB) *gorm.DB {
|
func (d DecoradorNumero) Aplicar(db *gorm.DB) *gorm.DB {
|
||||||
consulta := d.envuelto.Aplicar(db)
|
consulta := d.envuelto.Aplicar(db)
|
||||||
if d.numero != "" {
|
if d.numero != "" {
|
||||||
consulta = consulta.Where("numero LIKE ?", "%"+d.numero+"%")
|
consulta = consulta.Where("factura.numero LIKE ?", "%"+d.numero+"%")
|
||||||
}
|
}
|
||||||
return consulta
|
return consulta
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ type FiltrosFactura struct {
|
|||||||
Numero string
|
Numero string
|
||||||
ClienteID uint
|
ClienteID uint
|
||||||
Cliente string
|
Cliente string
|
||||||
|
Estado string
|
||||||
Desde *time.Time
|
Desde *time.Time
|
||||||
Hasta *time.Time
|
Hasta *time.Time
|
||||||
Pagina int
|
Pagina int
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ func NuevaQueryFacturas(filtros FiltrosFactura, preload bool, paginar bool) IFac
|
|||||||
actual = DecoradorNumero{envuelto: actual, numero: filtros.Numero}
|
actual = DecoradorNumero{envuelto: actual, numero: filtros.Numero}
|
||||||
actual = DecoradorClienteID{envuelto: actual, clienteID: filtros.ClienteID}
|
actual = DecoradorClienteID{envuelto: actual, clienteID: filtros.ClienteID}
|
||||||
actual = DecoradorCliente{envuelto: actual, cliente: filtros.Cliente}
|
actual = DecoradorCliente{envuelto: actual, cliente: filtros.Cliente}
|
||||||
|
actual = DecoradorEstado{envuelto: actual, estado: filtros.Estado}
|
||||||
actual = DecoradorDesde{envuelto: actual, desde: filtros.Desde}
|
actual = DecoradorDesde{envuelto: actual, desde: filtros.Desde}
|
||||||
actual = DecoradorHasta{envuelto: actual, hasta: filtros.Hasta}
|
actual = DecoradorHasta{envuelto: actual, hasta: filtros.Hasta}
|
||||||
if paginar {
|
if paginar {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ type FiltrosFactura = decorator.FiltrosFactura
|
|||||||
type repositorioFactura struct {
|
type repositorioFactura struct {
|
||||||
*RepositorioBase[models.Factura]
|
*RepositorioBase[models.Factura]
|
||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
|
dbRaw *gorm.DB
|
||||||
empresaID uint
|
empresaID uint
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@ func NuevoRepositorioFactura(db *gorm.DB, empresaID uint) RepositorioFactura {
|
|||||||
return &repositorioFactura{
|
return &repositorioFactura{
|
||||||
RepositorioBase: NewRepositorioBase[models.Factura](db, empresaID),
|
RepositorioBase: NewRepositorioBase[models.Factura](db, empresaID),
|
||||||
db: dbConEmpresa(db, empresaID),
|
db: dbConEmpresa(db, empresaID),
|
||||||
|
dbRaw: db,
|
||||||
empresaID: empresaID,
|
empresaID: empresaID,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -38,7 +40,13 @@ func (r *repositorioFactura) Listar(filtros decorator.FiltrosFactura) ([]models.
|
|||||||
var facturas []models.Factura
|
var facturas []models.Factura
|
||||||
|
|
||||||
paginar := filtros.Pagina > 0 || filtros.PorPagina > 0
|
paginar := filtros.Pagina > 0 || filtros.PorPagina > 0
|
||||||
query := decorator.NuevaQueryFacturas(filtros, true, paginar).Aplicar(r.db)
|
// Los decoradores pueden agregar joins (por ejemplo, al filtrar por nombre
|
||||||
|
// de cliente). Por eso el filtro de empresa se aplica acá, calificado con
|
||||||
|
// el alias de la tabla principal, en vez de usar el dbConEmpresa global.
|
||||||
|
query := decorator.NuevaQueryFacturas(filtros, true, paginar).Aplicar(r.dbRaw)
|
||||||
|
if r.empresaID > 0 {
|
||||||
|
query = query.Where("factura.empresa_id = ?", r.empresaID)
|
||||||
|
}
|
||||||
|
|
||||||
if err := query.Find(&facturas).Error; err != nil {
|
if err := query.Find(&facturas).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
DataTableSkeleton,
|
DataTableSkeleton,
|
||||||
|
DatePicker,
|
||||||
|
DatePickerInput,
|
||||||
InlineNotification,
|
InlineNotification,
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
@@ -31,7 +33,9 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
let facturas = $derived<Factura[]>(Array.isArray(data.facturas) ? data.facturas : []);
|
let facturas = $derived<Factura[]>(Array.isArray(data.facturas) ? data.facturas : []);
|
||||||
let filtros = $derived(data.filtros ?? { numero: '', cliente: '', estado: '', desde: '', hasta: '' });
|
let filtros = $derived(
|
||||||
|
data.filtros ?? { numero: '', cliente: '', estado: '', desde: '', hasta: '' }
|
||||||
|
);
|
||||||
let cargando = $derived(data.facturas === undefined || data.facturas === null);
|
let cargando = $derived(data.facturas === undefined || data.facturas === null);
|
||||||
|
|
||||||
let puedeVentas = $derived(getPermissions().includes(13));
|
let puedeVentas = $derived(getPermissions().includes(13));
|
||||||
@@ -104,16 +108,25 @@
|
|||||||
<div class="mb-4 flex flex-wrap items-center justify-between gap-2">
|
<div class="mb-4 flex flex-wrap items-center justify-between gap-2">
|
||||||
<h1 class="page-title">Gestión de Facturas</h1>
|
<h1 class="page-title">Gestión de Facturas</h1>
|
||||||
{#if puedeVentas}
|
{#if puedeVentas}
|
||||||
<Button icon={Add} onclick={() => goto('/facturas/nueva')}>
|
<Button icon={Add} onclick={() => goto('/facturas/nueva')}>Nueva Factura</Button>
|
||||||
Nueva Factura
|
|
||||||
</Button>
|
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if !puedeVentas}
|
{#if !puedeVentas}
|
||||||
<InlineNotification kind="warning" title="Sin permisos" subtitle="No tenés permiso para gestionar ventas y facturación." hideCloseButton />
|
<InlineNotification
|
||||||
|
kind="warning"
|
||||||
|
title="Sin permisos"
|
||||||
|
subtitle="No tenés permiso para gestionar ventas y facturación."
|
||||||
|
hideCloseButton
|
||||||
|
/>
|
||||||
{:else}
|
{:else}
|
||||||
<form class="mb-6 flex flex-wrap items-end gap-4" onsubmit={(e) => { e.preventDefault(); buscar(); }}>
|
<form
|
||||||
|
class="mb-6 flex flex-wrap items-end gap-4"
|
||||||
|
onsubmit={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
buscar();
|
||||||
|
}}
|
||||||
|
>
|
||||||
<div class="min-w-56 flex-1">
|
<div class="min-w-56 flex-1">
|
||||||
<TextInput labelText="Buscar" placeholder="N° factura o cliente" bind:value={numero} />
|
<TextInput labelText="Buscar" placeholder="N° factura o cliente" bind:value={numero} />
|
||||||
</div>
|
</div>
|
||||||
@@ -127,12 +140,15 @@
|
|||||||
<SelectItem value="PAGADA" text="Pagada" />
|
<SelectItem value="PAGADA" text="Pagada" />
|
||||||
<SelectItem value="CANCELADA" text="Cancelada" />
|
<SelectItem value="CANCELADA" text="Cancelada" />
|
||||||
</Select>
|
</Select>
|
||||||
<div class="min-w-36">
|
<DatePicker
|
||||||
<TextInput labelText="Desde" placeholder="YYYY-MM-DD" bind:value={desde} />
|
datePickerType="range"
|
||||||
</div>
|
dateFormat="Y-m-d"
|
||||||
<div class="min-w-36">
|
bind:valueFrom={desde}
|
||||||
<TextInput labelText="Hasta" placeholder="YYYY-MM-DD" bind:value={hasta} />
|
bind:valueTo={hasta}
|
||||||
</div>
|
>
|
||||||
|
<DatePickerInput labelText="Desde" placeholder="yyyy-mm-dd" />
|
||||||
|
<DatePickerInput labelText="Hasta" placeholder="yyyy-mm-dd" />
|
||||||
|
</DatePicker>
|
||||||
<div class="flex gap-2">
|
<div class="flex gap-2">
|
||||||
<Button type="submit" icon={Search}>Buscar</Button>
|
<Button type="submit" icon={Search}>Buscar</Button>
|
||||||
<Button kind="ghost" icon={Close} onclick={limpiar}>Limpiar</Button>
|
<Button kind="ghost" icon={Close} onclick={limpiar}>Limpiar</Button>
|
||||||
@@ -147,7 +163,19 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if cargando}
|
{#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} />
|
<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}
|
{:else if facturas.length === 0}
|
||||||
<TableContainer title="Facturas">
|
<TableContainer title="Facturas">
|
||||||
<Table>
|
<Table>
|
||||||
@@ -193,10 +221,34 @@
|
|||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<div class="flex flex-wrap gap-1">
|
<div class="flex flex-wrap gap-1">
|
||||||
<Button kind="ghost" size="small" icon={View} onclick={() => { facturaVer = f; openVer = true; }}>Ver</Button>
|
<Button
|
||||||
<Button kind="ghost" size="small" icon={Edit} disabled={f.estado === 'CANCELADA' || f.estado === 'PAGADA'}>Modificar</Button>
|
kind="ghost"
|
||||||
<Button kind="ghost" size="small" icon={Money} disabled={f.estado === 'CANCELADA' || f.estado === 'PAGADA'}>Registrar Pago</Button>
|
size="small"
|
||||||
<Button kind="danger-ghost" size="small" icon={Close} disabled={f.estado === 'CANCELADA'}>Cancelar</Button>
|
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>
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
@@ -221,7 +273,11 @@
|
|||||||
<p class="mb-2 font-semibold">Ítems</p>
|
<p class="mb-2 font-semibold">Ítems</p>
|
||||||
<ul class="list-disc pl-5">
|
<ul class="list-disc pl-5">
|
||||||
{#each facturaVer.detalles as d (d.repuestoId)}
|
{#each facturaVer.detalles as d (d.repuestoId)}
|
||||||
<li>Repuesto {d.repuestoId} — cant. {d.cantidad} × {formatMonto(d.precioUnitario)} = {formatMonto(d.subtotal)}</li>
|
<li>
|
||||||
|
Repuesto {d.repuestoId} — cant. {d.cantidad} × {formatMonto(d.precioUnitario)} = {formatMonto(
|
||||||
|
d.subtotal
|
||||||
|
)}
|
||||||
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in new issue
Block a user