hecha la parte del cu-02 falta test

Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
fede committed 2026-11-28 14:58:08 -03:00
1 parent 42bf987ffc
commit cc80dd1467
20 files changed
+940 -7

No files matched your search

@@ -0,0 +1,49 @@
package repositorios
import (
"repuestera_back/models"
"gorm.io/gorm"
)
type RepositorioComprobanteSecuencia interface {
Siguiente(tx *gorm.DB, empresaID uint, tipo string) (uint, error)
}
type repositorioComprobanteSecuencia struct {
db *gorm.DB
empresaID uint
}
func NuevoRepositorioComprobanteSecuencia(db *gorm.DB, empresaID uint) RepositorioComprobanteSecuencia {
return &repositorioComprobanteSecuencia{
db: dbConEmpresa(db, empresaID),
empresaID: empresaID,
}
}
func (r *repositorioComprobanteSecuencia) Siguiente(tx *gorm.DB, empresaID uint, tipo string) (uint, error) {
var seq models.ComprobanteSecuencia
db := tx
if empresaID > 0 {
db = db.Where("empresa_id = ?", empresaID)
}
if err := db.Where("tipo = ?", tipo).First(&seq).Error; err != nil {
if err != gorm.ErrRecordNotFound {
return 0, err
}
seq = models.ComprobanteSecuencia{
EmpresaID: empresaID,
Tipo: tipo,
UltimoNumero: 0,
}
if err := tx.Create(&seq).Error; err != nil {
return 0, err
}
}
seq.UltimoNumero++
if err := tx.Model(&seq).Update("ultimo_numero", seq.UltimoNumero).Error; err != nil {
return 0, err
}
return seq.UltimoNumero, nil
}
+34
View File
@@ -0,0 +1,34 @@
package repositorios
import (
"repuestera_back/models"
"gorm.io/gorm"
)
type RepositorioDescuento interface {
IRepositorio[models.Descuento]
ListarActivos() ([]models.Descuento, error)
}
type repositorioDescuento struct {
*RepositorioBase[models.Descuento]
db *gorm.DB
empresaID uint
}
func NuevoRepositorioDescuento(db *gorm.DB, empresaID uint) RepositorioDescuento {
return &repositorioDescuento{
RepositorioBase: NewRepositorioBase[models.Descuento](db, empresaID),
db: dbConEmpresa(db, empresaID),
empresaID: empresaID,
}
}
func (r *repositorioDescuento) ListarActivos() ([]models.Descuento, error) {
var ds []models.Descuento
if err := r.db.Unscoped().Where("activo = ?", true).Find(&ds).Error; err != nil {
return nil, err
}
return ds, nil
}
@@ -0,0 +1,25 @@
package repositorios
import (
"repuestera_back/models"
"gorm.io/gorm"
)
type RepositorioFormaDePago interface {
IRepositorio[models.FormaDePago]
}
type repositorioFormaDePago struct {
*RepositorioBase[models.FormaDePago]
db *gorm.DB
empresaID uint
}
func NuevoRepositorioFormaDePago(db *gorm.DB, empresaID uint) RepositorioFormaDePago {
return &repositorioFormaDePago{
RepositorioBase: NewRepositorioBase[models.FormaDePago](db, empresaID),
db: dbConEmpresa(db, empresaID),
empresaID: empresaID,
}
}
+55
View File
@@ -0,0 +1,55 @@
package repositorios
import (
"repuestera_back/models"
"gorm.io/gorm"
)
type RepositorioPago interface {
IRepositorio[models.Pago]
Registrar(tx *gorm.DB, pago *models.Pago) error
ListarPorFactura(facturaID uint) ([]models.Pago, error)
SumarPorFactura(facturaID uint) (float64, error)
}
type repositorioPago struct {
*RepositorioBase[models.Pago]
db *gorm.DB
empresaID uint
}
func NuevoRepositorioPago(db *gorm.DB, empresaID uint) RepositorioPago {
return &repositorioPago{
RepositorioBase: NewRepositorioBase[models.Pago](db, empresaID),
db: dbConEmpresa(db, empresaID),
empresaID: empresaID,
}
}
// Registrar persiste un pago dentro de una transacción y le asigna la empresa activa.
func (r *repositorioPago) Registrar(tx *gorm.DB, pago *models.Pago) error {
if pago == nil {
return gorm.ErrInvalidValue
}
if r.empresaID > 0 {
pago.EmpresaID = r.empresaID
}
return tx.Create(pago).Error
}
func (r *repositorioPago) ListarPorFactura(facturaID uint) ([]models.Pago, error) {
var pagos []models.Pago
if err := r.db.Where("factura_id = ?", facturaID).Find(&pagos).Error; err != nil {
return nil, err
}
return pagos, nil
}
func (r *repositorioPago) SumarPorFactura(facturaID uint) (float64, error) {
var total float64
if err := r.db.Model(&models.Pago{}).Where("factura_id = ?", facturaID).Select("COALESCE(SUM(importe),0)").Scan(&total).Error; err != nil {
return 0, err
}
return total, nil
}