Private
Public Access
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package repositorios
|
|
|
|
import (
|
|
"repuestera_back/models"
|
|
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/clause"
|
|
)
|
|
|
|
// RepositorioNotaDebito persiste las notas de débito emitidas por los
|
|
// ajustes de factura y las expone para el comprobante.
|
|
type RepositorioNotaDebito interface {
|
|
Crear(tx *gorm.DB, nota *models.NotaDebito) error
|
|
ListarPorFactura(facturaID uint) ([]models.NotaDebito, error)
|
|
}
|
|
|
|
type repositorioNotaDebito struct {
|
|
db *gorm.DB
|
|
empresaID uint
|
|
}
|
|
|
|
func NuevoRepositorioNotaDebito(db *gorm.DB, empresaID uint) RepositorioNotaDebito {
|
|
return &repositorioNotaDebito{
|
|
db: dbConEmpresa(db, empresaID),
|
|
empresaID: empresaID,
|
|
}
|
|
}
|
|
|
|
func (r *repositorioNotaDebito) Crear(tx *gorm.DB, nota *models.NotaDebito) error {
|
|
if nota == nil {
|
|
return gorm.ErrInvalidValue
|
|
}
|
|
if r.empresaID > 0 {
|
|
nota.EmpresaID = r.empresaID
|
|
}
|
|
return tx.Omit(clause.Associations).Create(nota).Error
|
|
}
|
|
|
|
func (r *repositorioNotaDebito) ListarPorFactura(facturaID uint) ([]models.NotaDebito, error) {
|
|
var notas []models.NotaDebito
|
|
if err := r.db.Where("facturaID = ?", facturaID).Order("created_at ASC").Find(¬as).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return notas, nil
|
|
}
|