Private
Public Access
hecha funcionalidad de modificacion/cancelacion de facturas
Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
1 parent
94a4e292c4
commit
6331e16dc5
39 files changed
+2283
-104
No files matched your search
@@ -16,6 +16,12 @@ func (d *FacturaDirector) Crear(datos dto_facturas.FacturaCalculada) (*models.Fa
|
||||
return builders.NewCrearFacturaBuilder().ConDatos(datos).Build()
|
||||
}
|
||||
|
||||
// AplicarAjuste actualiza una factura existente con los datos calculados de
|
||||
// una modificación o cancelación y agrega la entrada de historial.
|
||||
func (d *FacturaDirector) AplicarAjuste(factura *models.Factura, datos dto_facturas.FacturaAjusteDto) (*models.Factura, error) {
|
||||
return builders.NewFacturaAjusteBuilder().ConFactura(factura).ConDatos(datos).Build()
|
||||
}
|
||||
|
||||
func (d *FacturaDirector) DesdeFactura(factura *models.Factura) (*dto_facturas.FacturaResponse, error) {
|
||||
return builders.NewFacturaResponseBuilder().ConFactura(factura).Build()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package directors
|
||||
|
||||
import (
|
||||
builders "repuestera_back/dto/Builders"
|
||||
dto_stock "repuestera_back/dto/Stock"
|
||||
"repuestera_back/models"
|
||||
)
|
||||
|
||||
type MovimientoStockDirector struct{}
|
||||
|
||||
func NewMovimientoStockDirector() *MovimientoStockDirector {
|
||||
return &MovimientoStockDirector{}
|
||||
}
|
||||
|
||||
// Crear construye un movimiento de stock a partir de los datos recibidos.
|
||||
func (d *MovimientoStockDirector) Crear(datos dto_stock.MovimientoStockDto) (*models.MovimientoStock, error) {
|
||||
return builders.NewMovimientoStockBuilder().ConDatos(datos).Build()
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package directors
|
||||
|
||||
import (
|
||||
builders "repuestera_back/dto/Builders"
|
||||
dto_facturas "repuestera_back/dto/Facturas"
|
||||
"repuestera_back/models"
|
||||
)
|
||||
|
||||
type NotaDirector struct{}
|
||||
|
||||
func NewNotaDirector() *NotaDirector {
|
||||
return &NotaDirector{}
|
||||
}
|
||||
|
||||
// DesdeNotaCredito construye el resumen público de una nota de crédito.
|
||||
func (d *NotaDirector) DesdeNotaCredito(nota *models.NotaCredito) (*dto_facturas.NotaResumen, error) {
|
||||
if nota == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return builders.NewNotaCreditoResumenBuilder().ConNota(nota).Build()
|
||||
}
|
||||
|
||||
// DesdeNotaDebito construye el resumen público de una nota de débito.
|
||||
func (d *NotaDirector) DesdeNotaDebito(nota *models.NotaDebito) (*dto_facturas.NotaResumen, error) {
|
||||
if nota == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return builders.NewNotaDebitoResumenBuilder().ConNota(nota).Build()
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package dto_builders
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
dto "repuestera_back/dto/Facturas"
|
||||
"repuestera_back/models"
|
||||
)
|
||||
|
||||
// FacturaAjusteBuilder aplica sobre una factura existente los totales, el
|
||||
// estado y la entrada de historial resultantes de una modificación o
|
||||
// cancelación.
|
||||
type FacturaAjusteBuilder struct {
|
||||
factura *models.Factura
|
||||
datos *dto.FacturaAjusteDto
|
||||
err error
|
||||
}
|
||||
|
||||
var _ IBuilder[models.Factura] = (*FacturaAjusteBuilder)(nil)
|
||||
|
||||
func NewFacturaAjusteBuilder() *FacturaAjusteBuilder {
|
||||
return &FacturaAjusteBuilder{}
|
||||
}
|
||||
|
||||
func (b *FacturaAjusteBuilder) ConFactura(factura *models.Factura) *FacturaAjusteBuilder {
|
||||
if factura == nil {
|
||||
AcumularError(&b.err, "la factura no puede ser nula")
|
||||
return b
|
||||
}
|
||||
b.factura = factura
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *FacturaAjusteBuilder) ConDatos(datos dto.FacturaAjusteDto) *FacturaAjusteBuilder {
|
||||
b.datos = &datos
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *FacturaAjusteBuilder) Build() (*models.Factura, error) {
|
||||
if b.err != nil {
|
||||
return nil, b.err
|
||||
}
|
||||
if b.factura == nil {
|
||||
return nil, errors.New("falta la factura")
|
||||
}
|
||||
if b.datos == nil {
|
||||
return nil, errors.New("faltan los datos del ajuste")
|
||||
}
|
||||
|
||||
datos := b.datos
|
||||
if datos.UsuarioID == 0 {
|
||||
AcumularError(&b.err, "el usuario es obligatorio")
|
||||
}
|
||||
if strings.TrimSpace(datos.Estado) == "" {
|
||||
AcumularError(&b.err, "el estado de la factura es obligatorio")
|
||||
}
|
||||
if strings.TrimSpace(datos.Motivo) == "" {
|
||||
AcumularError(&b.err, "el motivo es obligatorio")
|
||||
}
|
||||
if b.err != nil {
|
||||
return nil, b.err
|
||||
}
|
||||
|
||||
fecha := datos.Fecha
|
||||
if fecha.IsZero() {
|
||||
fecha = time.Now()
|
||||
}
|
||||
usuarioID := datos.UsuarioID
|
||||
|
||||
factura := b.factura
|
||||
factura.Detalles = append([]models.FacturaDetalle{}, datos.Detalles...)
|
||||
factura.Subtotal = datos.Subtotal
|
||||
factura.DescuentoTotal = datos.DescuentoTotal
|
||||
factura.Impuestos = datos.Impuestos
|
||||
factura.Total = datos.Total
|
||||
factura.Saldo = datos.Saldo
|
||||
factura.Estado = datos.Estado
|
||||
factura.Version++
|
||||
factura.EditadaPorID = &usuarioID
|
||||
factura.EditadaAt = &fecha
|
||||
factura.MotivoUltimaEdicion = datos.Motivo
|
||||
factura.Historial = append(factura.Historial, models.FacturaCambio{
|
||||
Fecha: fecha,
|
||||
UsuarioID: usuarioID,
|
||||
Motivo: datos.Motivo,
|
||||
ItemsAnteriores: append([]models.FacturaDetalle{}, datos.ItemsAnteriores...),
|
||||
TotalAnterior: datos.TotalAnterior,
|
||||
ItemsNuevos: append([]models.FacturaDetalle{}, datos.ItemsNuevos...),
|
||||
TotalNuevo: datos.TotalNuevo,
|
||||
NotaTipo: datos.NotaTipo,
|
||||
NotaID: datos.NotaID,
|
||||
})
|
||||
|
||||
return factura, nil
|
||||
}
|
||||
@@ -92,30 +92,32 @@ func (b *FacturaResponseBuilder) Build() (*dto_facturas.FacturaResponse, error)
|
||||
}
|
||||
|
||||
return &dto_facturas.FacturaResponse{
|
||||
ID: b.factura.ID,
|
||||
CreatedAt: b.factura.CreatedAt,
|
||||
UpdatedAt: b.factura.UpdatedAt,
|
||||
DeletedAt: deletedAt,
|
||||
EmpresaID: b.factura.EmpresaID,
|
||||
Numero: b.factura.Numero,
|
||||
Estado: b.factura.Estado,
|
||||
Total: b.factura.Total,
|
||||
Subtotal: b.factura.Subtotal,
|
||||
DescuentoTotal: b.factura.DescuentoTotal,
|
||||
Impuestos: b.factura.Impuestos,
|
||||
AlicuotaIVA: b.factura.AlicuotaIVA,
|
||||
Saldo: b.factura.Saldo,
|
||||
AlmacenID: b.factura.AlmacenID,
|
||||
FechaEmision: b.factura.FechaEmision,
|
||||
Observacion: b.factura.Observacion,
|
||||
Version: b.factura.Version,
|
||||
ClienteID: b.factura.ClienteID,
|
||||
Cliente: cliente,
|
||||
ProveedorID: b.factura.ProveedorID,
|
||||
Proveedor: proveedor,
|
||||
SeAviso: b.factura.SeAviso,
|
||||
Detalles: append([]models.FacturaDetalle{}, b.factura.Detalles...),
|
||||
ResponsableID: b.factura.ResponsableID,
|
||||
Responsable: responsable,
|
||||
ID: b.factura.ID,
|
||||
CreatedAt: b.factura.CreatedAt,
|
||||
UpdatedAt: b.factura.UpdatedAt,
|
||||
DeletedAt: deletedAt,
|
||||
EmpresaID: b.factura.EmpresaID,
|
||||
Numero: b.factura.Numero,
|
||||
Estado: b.factura.Estado,
|
||||
Total: b.factura.Total,
|
||||
Subtotal: b.factura.Subtotal,
|
||||
DescuentoTotal: b.factura.DescuentoTotal,
|
||||
Impuestos: b.factura.Impuestos,
|
||||
AlicuotaIVA: b.factura.AlicuotaIVA,
|
||||
Saldo: b.factura.Saldo,
|
||||
AlmacenID: b.factura.AlmacenID,
|
||||
FechaEmision: b.factura.FechaEmision,
|
||||
Observacion: b.factura.Observacion,
|
||||
Version: b.factura.Version,
|
||||
ClienteID: b.factura.ClienteID,
|
||||
Cliente: cliente,
|
||||
ProveedorID: b.factura.ProveedorID,
|
||||
Proveedor: proveedor,
|
||||
SeAviso: b.factura.SeAviso,
|
||||
Detalles: append([]models.FacturaDetalle{}, b.factura.Detalles...),
|
||||
Historial: append([]models.FacturaCambio{}, b.factura.Historial...),
|
||||
MotivoUltimaEdicion: b.factura.MotivoUltimaEdicion,
|
||||
ResponsableID: b.factura.ResponsableID,
|
||||
Responsable: responsable,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package dto_builders
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
dto_stock "repuestera_back/dto/Stock"
|
||||
"repuestera_back/models"
|
||||
)
|
||||
|
||||
// MovimientoStockBuilder construye y valida el registro auditable de una
|
||||
// variación de stock.
|
||||
type MovimientoStockBuilder struct {
|
||||
datos *dto_stock.MovimientoStockDto
|
||||
err error
|
||||
}
|
||||
|
||||
var _ IBuilder[models.MovimientoStock] = (*MovimientoStockBuilder)(nil)
|
||||
|
||||
func NewMovimientoStockBuilder() *MovimientoStockBuilder {
|
||||
return &MovimientoStockBuilder{}
|
||||
}
|
||||
|
||||
func (b *MovimientoStockBuilder) ConDatos(datos dto_stock.MovimientoStockDto) *MovimientoStockBuilder {
|
||||
b.datos = &datos
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *MovimientoStockBuilder) Build() (*models.MovimientoStock, error) {
|
||||
if b.datos == nil {
|
||||
return nil, errors.New("faltan los datos del movimiento de stock")
|
||||
}
|
||||
|
||||
datos := b.datos
|
||||
if datos.StockID == 0 {
|
||||
AcumularError(&b.err, "el stock es obligatorio")
|
||||
}
|
||||
if datos.RepuestoID == 0 {
|
||||
AcumularError(&b.err, "el repuesto es obligatorio")
|
||||
}
|
||||
if datos.AlmacenID == 0 {
|
||||
AcumularError(&b.err, "el almacén es obligatorio")
|
||||
}
|
||||
if datos.Tipo == "" {
|
||||
AcumularError(&b.err, "el tipo de movimiento es obligatorio")
|
||||
}
|
||||
if datos.Cantidad <= 0 {
|
||||
AcumularError(&b.err, "la cantidad del movimiento debe ser mayor a cero")
|
||||
}
|
||||
if datos.SaldoAnterior < 0 {
|
||||
AcumularError(&b.err, "el saldo anterior no puede ser negativo")
|
||||
}
|
||||
if datos.SaldoPosterior < 0 {
|
||||
AcumularError(&b.err, "el saldo posterior no puede ser negativo")
|
||||
}
|
||||
if datos.UsuarioID == 0 {
|
||||
AcumularError(&b.err, "el usuario es obligatorio")
|
||||
}
|
||||
if b.err != nil {
|
||||
return nil, b.err
|
||||
}
|
||||
|
||||
referenciaTipo, _ := ValidarTexto(datos.ReferenciaTipo, "el tipo de referencia", &b.err)
|
||||
if b.err != nil {
|
||||
return nil, b.err
|
||||
}
|
||||
|
||||
fecha := datos.Fecha
|
||||
if fecha.IsZero() {
|
||||
fecha = time.Now()
|
||||
}
|
||||
|
||||
return &models.MovimientoStock{
|
||||
StockID: datos.StockID,
|
||||
RepuestoID: datos.RepuestoID,
|
||||
AlmacenID: datos.AlmacenID,
|
||||
Tipo: datos.Tipo,
|
||||
Cantidad: datos.Cantidad,
|
||||
SaldoAnterior: datos.SaldoAnterior,
|
||||
SaldoPosterior: datos.SaldoPosterior,
|
||||
ReferenciaTipo: referenciaTipo,
|
||||
ReferenciaID: datos.ReferenciaID,
|
||||
UsuarioID: datos.UsuarioID,
|
||||
Observacion: datos.Observacion,
|
||||
Fecha: fecha,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package dto_builders
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
dto "repuestera_back/dto/Facturas"
|
||||
"repuestera_back/models"
|
||||
)
|
||||
|
||||
// NotaCreditoResumenBuilder construye la representación pública de una nota
|
||||
// de crédito.
|
||||
type NotaCreditoResumenBuilder struct {
|
||||
nota *models.NotaCredito
|
||||
err error
|
||||
}
|
||||
|
||||
var _ IBuilder[dto.NotaResumen] = (*NotaCreditoResumenBuilder)(nil)
|
||||
|
||||
func NewNotaCreditoResumenBuilder() *NotaCreditoResumenBuilder {
|
||||
return &NotaCreditoResumenBuilder{}
|
||||
}
|
||||
|
||||
func (b *NotaCreditoResumenBuilder) ConNota(nota *models.NotaCredito) *NotaCreditoResumenBuilder {
|
||||
if nota == nil {
|
||||
AcumularError(&b.err, "la nota de crédito no puede ser nula")
|
||||
return b
|
||||
}
|
||||
b.nota = nota
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *NotaCreditoResumenBuilder) Build() (*dto.NotaResumen, error) {
|
||||
if b.err != nil {
|
||||
return nil, b.err
|
||||
}
|
||||
if b.nota == nil {
|
||||
return nil, errors.New("falta la nota de crédito")
|
||||
}
|
||||
|
||||
nota := b.nota
|
||||
return &dto.NotaResumen{
|
||||
ID: nota.ID,
|
||||
Tipo: "CREDITO",
|
||||
Numero: fmt.Sprintf("NC-%08d", nota.ID),
|
||||
Motivo: nota.Motivo,
|
||||
Importe: nota.Total,
|
||||
Fecha: nota.CreatedAt,
|
||||
FacturaID: nota.FacturaOrigenID,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package dto_builders
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
dto "repuestera_back/dto/Facturas"
|
||||
"repuestera_back/models"
|
||||
)
|
||||
|
||||
// NotaDebitoResumenBuilder construye la representación pública de una nota de
|
||||
// débito.
|
||||
type NotaDebitoResumenBuilder struct {
|
||||
nota *models.NotaDebito
|
||||
err error
|
||||
}
|
||||
|
||||
var _ IBuilder[dto.NotaResumen] = (*NotaDebitoResumenBuilder)(nil)
|
||||
|
||||
func NewNotaDebitoResumenBuilder() *NotaDebitoResumenBuilder {
|
||||
return &NotaDebitoResumenBuilder{}
|
||||
}
|
||||
|
||||
func (b *NotaDebitoResumenBuilder) ConNota(nota *models.NotaDebito) *NotaDebitoResumenBuilder {
|
||||
if nota == nil {
|
||||
AcumularError(&b.err, "la nota de débito no puede ser nula")
|
||||
return b
|
||||
}
|
||||
b.nota = nota
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *NotaDebitoResumenBuilder) Build() (*dto.NotaResumen, error) {
|
||||
if b.err != nil {
|
||||
return nil, b.err
|
||||
}
|
||||
if b.nota == nil {
|
||||
return nil, errors.New("falta la nota de débito")
|
||||
}
|
||||
|
||||
nota := b.nota
|
||||
return &dto.NotaResumen{
|
||||
ID: nota.ID,
|
||||
Tipo: "DEBITO",
|
||||
Numero: fmt.Sprintf("ND-%08d", nota.ID),
|
||||
Motivo: nota.Motivo,
|
||||
Importe: nota.Total,
|
||||
Fecha: nota.CreatedAt,
|
||||
FacturaID: nota.FacturaOrigenID,
|
||||
}, nil
|
||||
}
|
||||
Reference in new issue
Block a user