This commit is contained in:
Lizandro Guarnizo
2026-05-12 18:34:20 -05:00
parent ee31ac978f
commit 387485e65b
5 changed files with 212 additions and 76 deletions
+16
View File
@@ -88,6 +88,22 @@ func GetContratosProximosVencer(diasAntes int) ([]Contrato, error) {
return items, nil
}
// GetContratosYaVencidos retorna contratos cuya fecha de vencimiento es hoy o anterior
// y su estado sigue siendo 'activo' (aún no han sido marcados como vencidos)
func GetContratosYaVencidos() ([]Contrato, error) {
var items []Contrato
hoy := time.Now().UTC()
startOfDay := time.Date(hoy.Year(), hoy.Month(), hoy.Day(), 0, 0, 0, 0, time.UTC)
if err := app.Http.Database.DB.Preload("Cliente").Preload("Servicios").
Where("estado = 'activo' AND fecha_vencimiento < ?", startOfDay).
Find(&items).Error; err != nil {
log.Printf("Error getting contratos vencidos: %v", err)
return nil, err
}
return items, nil
}
// syncContratoServicios sincroniza la tabla join contrato_servicios usando SQL directo
// para evitar que GORM intente hacer upsert de los servicios existentes.
func syncContratoServicios(contratoID uint, servicioIDs []uint) error {