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{
|
||||
Numero: c.Query("numero"),
|
||||
Cliente: c.Query("cliente"),
|
||||
Estado: c.Query("estado"),
|
||||
}
|
||||
|
||||
if raw := c.Query("clienteId"); raw != "" {
|
||||
|
||||
@@ -10,7 +10,7 @@ type DecoradorCliente struct {
|
||||
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`").
|
||||
consulta = consulta.Joins("JOIN clientes ON clientes.id = factura.`ClienteID` AND clientes.deleted_at IS NULL").
|
||||
Where("clientes.nombre LIKE ?", "%"+d.cliente+"%")
|
||||
}
|
||||
return consulta
|
||||
|
||||
@@ -10,7 +10,7 @@ type DecoradorClienteID struct {
|
||||
func (d DecoradorClienteID) Aplicar(db *gorm.DB) *gorm.DB {
|
||||
consulta := d.envuelto.Aplicar(db)
|
||||
if d.clienteID > 0 {
|
||||
consulta = consulta.Where("`ClienteID` = ?", d.clienteID)
|
||||
consulta = consulta.Where("factura.`ClienteID` = ?", d.clienteID)
|
||||
}
|
||||
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 {
|
||||
consulta := d.envuelto.Aplicar(db)
|
||||
if d.numero != "" {
|
||||
consulta = consulta.Where("numero LIKE ?", "%"+d.numero+"%")
|
||||
consulta = consulta.Where("factura.numero LIKE ?", "%"+d.numero+"%")
|
||||
}
|
||||
return consulta
|
||||
}
|
||||
@@ -7,6 +7,7 @@ type FiltrosFactura struct {
|
||||
Numero string
|
||||
ClienteID uint
|
||||
Cliente string
|
||||
Estado string
|
||||
Desde *time.Time
|
||||
Hasta *time.Time
|
||||
Pagina int
|
||||
|
||||
@@ -7,6 +7,7 @@ func NuevaQueryFacturas(filtros FiltrosFactura, preload bool, paginar bool) IFac
|
||||
actual = DecoradorNumero{envuelto: actual, numero: filtros.Numero}
|
||||
actual = DecoradorClienteID{envuelto: actual, clienteID: filtros.ClienteID}
|
||||
actual = DecoradorCliente{envuelto: actual, cliente: filtros.Cliente}
|
||||
actual = DecoradorEstado{envuelto: actual, estado: filtros.Estado}
|
||||
actual = DecoradorDesde{envuelto: actual, desde: filtros.Desde}
|
||||
actual = DecoradorHasta{envuelto: actual, hasta: filtros.Hasta}
|
||||
if paginar {
|
||||
|
||||
@@ -23,6 +23,7 @@ type FiltrosFactura = decorator.FiltrosFactura
|
||||
type repositorioFactura struct {
|
||||
*RepositorioBase[models.Factura]
|
||||
db *gorm.DB
|
||||
dbRaw *gorm.DB
|
||||
empresaID uint
|
||||
}
|
||||
|
||||
@@ -30,6 +31,7 @@ func NuevoRepositorioFactura(db *gorm.DB, empresaID uint) RepositorioFactura {
|
||||
return &repositorioFactura{
|
||||
RepositorioBase: NewRepositorioBase[models.Factura](db, empresaID),
|
||||
db: dbConEmpresa(db, empresaID),
|
||||
dbRaw: db,
|
||||
empresaID: empresaID,
|
||||
}
|
||||
}
|
||||
@@ -38,7 +40,13 @@ func (r *repositorioFactura) Listar(filtros decorator.FiltrosFactura) ([]models.
|
||||
var facturas []models.Factura
|
||||
|
||||
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 {
|
||||
return nil, err
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
import {
|
||||
Button,
|
||||
DataTableSkeleton,
|
||||
DatePicker,
|
||||
DatePickerInput,
|
||||
InlineNotification,
|
||||
Table,
|
||||
TableBody,
|
||||
@@ -31,7 +33,9 @@
|
||||
});
|
||||
|
||||
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 puedeVentas = $derived(getPermissions().includes(13));
|
||||
@@ -104,16 +108,25 @@
|
||||
<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={() => goto('/facturas/nueva')}>
|
||||
Nueva Factura
|
||||
</Button>
|
||||
<Button icon={Add} onclick={() => goto('/facturas/nueva')}>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 />
|
||||
<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(); }}>
|
||||
<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>
|
||||
@@ -127,12 +140,15 @@
|
||||
<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>
|
||||
<DatePicker
|
||||
datePickerType="range"
|
||||
dateFormat="Y-m-d"
|
||||
bind:valueFrom={desde}
|
||||
bind:valueTo={hasta}
|
||||
>
|
||||
<DatePickerInput labelText="Desde" placeholder="yyyy-mm-dd" />
|
||||
<DatePickerInput labelText="Hasta" placeholder="yyyy-mm-dd" />
|
||||
</DatePicker>
|
||||
<div class="flex gap-2">
|
||||
<Button type="submit" icon={Search}>Buscar</Button>
|
||||
<Button kind="ghost" icon={Close} onclick={limpiar}>Limpiar</Button>
|
||||
@@ -147,7 +163,19 @@
|
||||
{/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} />
|
||||
<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>
|
||||
@@ -193,10 +221,34 @@
|
||||
</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>
|
||||
<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>
|
||||
@@ -221,7 +273,11 @@
|
||||
<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>
|
||||
<li>
|
||||
Repuesto {d.repuestoId} — cant. {d.cantidad} × {formatMonto(d.precioUnitario)} = {formatMonto(
|
||||
d.subtotal
|
||||
)}
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user