From 152a40ca19039a47f600d286b58eb6e6eb6f1ef7 Mon Sep 17 00:00:00 2001 From: fede Date: Thu, 6 Aug 2026 02:12:51 -0300 Subject: [PATCH] feat: adapatadas entidades para que coinsidan con el modelo --- back/models/almacen.go | 5 ++--- back/models/cajon.go | 13 ------------- back/models/cliente.go | 12 ++++++++++++ back/models/comprobante.go | 16 ++++++++++++++++ back/models/estante.go | 13 ------------- back/models/factura.go | 17 ++++------------- back/models/formaPago.go | 11 +++++++++++ back/models/marca.go | 11 +++-------- back/models/notaCredito.go | 10 ++++++++++ back/models/notaDebito.go | 10 ++++++++++ back/models/orden_compra.go | 17 +++-------------- back/models/pago.go | 13 +++++++++++++ back/models/proveedor.go | 9 +++++++++ back/models/recibo.go | 10 ++++++++++ back/models/repuesto.go | 2 +- back/models/stock.go | 4 +--- 16 files changed, 105 insertions(+), 68 deletions(-) delete mode 100644 back/models/cajon.go create mode 100644 back/models/cliente.go create mode 100644 back/models/comprobante.go delete mode 100644 back/models/estante.go create mode 100644 back/models/formaPago.go create mode 100644 back/models/notaCredito.go create mode 100644 back/models/notaDebito.go create mode 100644 back/models/pago.go create mode 100644 back/models/proveedor.go create mode 100644 back/models/recibo.go diff --git a/back/models/almacen.go b/back/models/almacen.go index c0907f4..b348272 100644 --- a/back/models/almacen.go +++ b/back/models/almacen.go @@ -2,9 +2,8 @@ package models type Almacen struct { ID string `gorm:"primaryKey;type:varchar(5)" json:"id"` - Razon string `gorm:"uniqueIndex;not null;type:varchar(70)" json:"razon"` - EmpresaID string `gorm:"type:varchar(3);index;not null" json:"empresaId"` - Estantes []Estante `gorm:"foreignKey:AlmacenID" json:"estantes,omitempty"` + Ubicacion string `gorm:"type:varchar(40)" json:"ubicacion"` + Stocks []Stock `gorm:"foreignKey:RepuestoID" json:"stocks,omitempty"` } func (Almacen) TableName() string { diff --git a/back/models/cajon.go b/back/models/cajon.go deleted file mode 100644 index 71bf2b8..0000000 --- a/back/models/cajon.go +++ /dev/null @@ -1,13 +0,0 @@ -package models - -type Cajon struct { - ID string `gorm:"primaryKey;type:varchar(30)" json:"id"` - Razon string `gorm:"not null;type:varchar(70)" json:"razon"` - Codigo string `gorm:"not null;type:varchar(5)" json:"codigo"` - EstanteID string `gorm:"type:varchar(30);index;not null" json:"estanteId"` - Stocks []Stock `gorm:"foreignKey:CajonID" json:"stocks,omitempty"` -} - -func (Cajon) TableName() string { - return "cajon" -} diff --git a/back/models/cliente.go b/back/models/cliente.go new file mode 100644 index 0000000..9abae59 --- /dev/null +++ b/back/models/cliente.go @@ -0,0 +1,12 @@ +package models + +import ( + "gorm.io/gorm" +) + +type Cliente struct { + gorm.Model + Nombre string `gorm:"type:varchar(40)" json:"nombre"` + Facturas []Factura `gorm:"foreignKey:facturaID" json:"facturas,omitempty"` + Recibos []Recibo `gorm:"foreignKey:reciboID"` +} diff --git a/back/models/comprobante.go b/back/models/comprobante.go new file mode 100644 index 0000000..bfa26dd --- /dev/null +++ b/back/models/comprobante.go @@ -0,0 +1,16 @@ +package models + +import ( + models_seguridad "repuestera_back/models/seguridad" + + "gorm.io/gorm" +) + +// este lo uso de base para los distintos tipos de comprobantes +type Comprobante struct { + gorm.Model + Numero string `gorm:"size:50;not null" json:"numero"` + Estado string `gorm:"type:varchar(20);not null" json:"estado"` + Total float64 `gorm:"type:decimal(15,2);not null" json:"total"` + Responsable models_seguridad.Usuario `gorm:"foreignKey:UsuarioID" json:"usuario"` +} diff --git a/back/models/estante.go b/back/models/estante.go deleted file mode 100644 index 0b4a4e3..0000000 --- a/back/models/estante.go +++ /dev/null @@ -1,13 +0,0 @@ -package models - -type Estante struct { - ID string `gorm:"primaryKey;type:varchar(30)" json:"id"` - Razon string `gorm:"not null;type:varchar(70)" json:"razon"` - Codigo string `gorm:"not null;type:varchar(5)" json:"codigo"` - AlmacenID string `gorm:"type:varchar(5);index;not null" json:"almacenId"` - Cajones []Cajon `gorm:"foreignKey:EstanteID" json:"cajones,omitempty"` -} - -func (Estante) TableName() string { - return "estante" -} diff --git a/back/models/factura.go b/back/models/factura.go index dd8848a..c94eab2 100644 --- a/back/models/factura.go +++ b/back/models/factura.go @@ -1,20 +1,11 @@ package models -import ( - "time" - - models_seguridad "repuestera_back/models/seguridad" -) type Factura struct { - ID uint64 `gorm:"primaryKey" json:"id"` - EmpresaID string `gorm:"type:varchar(3);index;not null" json:"empresaId"` - UsuarioID uint64 `gorm:"index;not null" json:"usuarioId"` - Fecha time.Time `gorm:"not null" json:"fecha"` - Cliente string `gorm:"type:varchar(100)" json:"cliente"` - Total float64 `gorm:"not null;default:0" json:"total"` - Detalles []FacturaDetalle `gorm:"type:json" json:"detalles,omitempty"` - Usuario models_seguridad.Usuario `gorm:"foreignKey:UsuarioID" json:"usuario,omitempty"` + Comprobante + Cliente Cliente `gorm:"foreignKey:ClienteID" json:"cliente"` + Total float64 `gorm:"not null;default:0" json:"total"` + Detalles []FacturaDetalle `gorm:"type:json" json:"detalles,omitempty"` } func (Factura) TableName() string { diff --git a/back/models/formaPago.go b/back/models/formaPago.go new file mode 100644 index 0000000..0542a65 --- /dev/null +++ b/back/models/formaPago.go @@ -0,0 +1,11 @@ +package models + +import "gorm.io/gorm" + +type FormaDePago struct { + gorm.Model + Descripcion string `gorm:"type:varchar(20),not null" json:"desripcion" ` +} +func (FormaDePago) TableName() string { + return "forma_de_pago" +} diff --git a/back/models/marca.go b/back/models/marca.go index 071b735..8a948e7 100644 --- a/back/models/marca.go +++ b/back/models/marca.go @@ -1,18 +1,13 @@ package models import ( - "time" - "gorm.io/gorm" ) type Marca struct { - ID string `gorm:"primaryKey;type:varchar(3)" json:"id"` - Nombre string `gorm:"uniqueIndex;not null;type:varchar(70)" json:"nombre"` - Repuestos []Repuesto `gorm:"foreignKey:MarcaID"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` - DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` + gorm.Model + Nombre string `gorm:"uniqueIndex;not null;type:varchar(70)" json:"nombre"` + Repuestos []Repuesto `gorm:"foreignKey:MarcaID" json:"repuestos"` } func (Marca) TableName() string { diff --git a/back/models/notaCredito.go b/back/models/notaCredito.go new file mode 100644 index 0000000..5852ddd --- /dev/null +++ b/back/models/notaCredito.go @@ -0,0 +1,10 @@ +package models + +type NotaCredito struct { + Comprobante + Motivo string `gorm:"type:varchar(40),not null"` + FacturaOrigen Factura `gorm:"foreignKey:FacturaID" json:"factura"` +} +func (NotaCredito) TableName() string { + return "nota_credito" +} diff --git a/back/models/notaDebito.go b/back/models/notaDebito.go new file mode 100644 index 0000000..a731b1b --- /dev/null +++ b/back/models/notaDebito.go @@ -0,0 +1,10 @@ +package models + +type NotaDebito struct { + Comprobante + Motivo string `gorm:"type:varchar(40),not null"` + FacturaOrigen Factura `gorm:"foreignKey:FacturaID" json:"factura"` +} +func (NotaDebito) TableName() string { + return "nota_debito" +} diff --git a/back/models/orden_compra.go b/back/models/orden_compra.go index 16330a0..6af85cf 100644 --- a/back/models/orden_compra.go +++ b/back/models/orden_compra.go @@ -1,20 +1,9 @@ package models -import ( - "time" - - models_seguridad "repuestera_back/models/seguridad" -) - type OrdenCompra struct { - ID uint64 `gorm:"primaryKey" json:"id"` - EmpresaID string `gorm:"type:varchar(3);index;not null" json:"empresaId"` - UsuarioID uint64 `gorm:"index;not null" json:"usuarioId"` - Fecha time.Time `gorm:"not null" json:"fecha"` - Proveedor string `gorm:"type:varchar(100)" json:"proveedor"` - Total float64 `gorm:"not null;default:0" json:"total"` - Detalles []OrdenCompraDetalle `gorm:"type:json" json:"detalles,omitempty"` - Usuario models_seguridad.Usuario `gorm:"foreignKey:UsuarioID" json:"usuario,omitempty"` + Comprobante + Proveedor Proveedor `gorm:"foreignKey:ProveedorID" json:"Proveedor"` + Detalles []OrdenCompraDetalle `gorm:"type:json" json:"detalles,omitempty"` } func (OrdenCompra) TableName() string { diff --git a/back/models/pago.go b/back/models/pago.go new file mode 100644 index 0000000..0bb58a3 --- /dev/null +++ b/back/models/pago.go @@ -0,0 +1,13 @@ +package models + +import "gorm.io/gorm" + +type Pago struct { + gorm.Model + FormaDePago FormaDePago `gorm:"foreignKey:FormaDePagoID"` + Importe float64 `gorm:"type:decimal(10,2)"` +} + +func (Pago) TableName() string { + return "pago" +} diff --git a/back/models/proveedor.go b/back/models/proveedor.go new file mode 100644 index 0000000..e326d41 --- /dev/null +++ b/back/models/proveedor.go @@ -0,0 +1,9 @@ +package models + +import "gorm.io/gorm" + +type Proveedor struct { + gorm.Model + Nombre string `gorm:"type:varchar(40)" json:"nombre"` + Facturas []Factura `gorm:"foreignKey:FacturaID" json:"facturas,omitempty"` +} diff --git a/back/models/recibo.go b/back/models/recibo.go new file mode 100644 index 0000000..05001a8 --- /dev/null +++ b/back/models/recibo.go @@ -0,0 +1,10 @@ +package models + +type Recibo struct { + Comprobante + Pagos []Pago `gorm:"foreignKey:pagoId" json:"pagos"` +} + +func (Recibo) TableName() string { + return "recibo" +} diff --git a/back/models/repuesto.go b/back/models/repuesto.go index 16853f4..5b7ed60 100644 --- a/back/models/repuesto.go +++ b/back/models/repuesto.go @@ -13,7 +13,7 @@ type Repuesto struct { Precio float64 `gorm:"not null;type:decimal(10,2)" json:"precio" binding:"required"` StockMinimo int64 `gorm:"not null;type:bigint" json:"stockMinimo" binding:"required"` Descripcion string `gorm:"uniqueIndex;not null;type:varchar(70)" json:"descripcion" binding:"required"` - MarcaID string `gorm:"type:varchar(3);index" json:"marcaId" binding:"required"` + Marca Marca `gorm:"foreignKey:marcaId"` Aliases datatypes.JSONSlice[string] `gorm:"type:json" json:"aliases,omitempty"` Stocks []Stock `gorm:"foreignKey:RepuestoID" json:"stocks,omitempty"` CreatedAt time.Time `json:"created_at"` diff --git a/back/models/stock.go b/back/models/stock.go index 529231c..586f6ee 100644 --- a/back/models/stock.go +++ b/back/models/stock.go @@ -5,9 +5,7 @@ type Stock struct { RepuestoID uint64 `gorm:"index;not null" json:"repuestoId"` CajonID string `gorm:"type:varchar(30);index;not null" json:"cajonId"` Cantidad uint `gorm:"not null;default:0" json:"cantidad"` - - Repuesto Repuesto `gorm:"foreignKey:RepuestoID" json:"repuesto,omitempty"` - Cajon Cajon `gorm:"foreignKey:CajonID" json:"cajon,omitempty"` + Repuesto Repuesto `gorm:"foreignKey:RepuestoID" json:"repuesto"` } func (Stock) TableName() string {