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
}