up
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user