feat: contrato soporta múltiples servicios (many2many) con precio sugerido

This commit is contained in:
Lizandro Guarnizo
2026-04-30 22:15:31 -05:00
parent 1b0374204c
commit e751a9f894
5 changed files with 157 additions and 76 deletions
+10 -4
View File
@@ -56,12 +56,18 @@ func ProcesarVencimientos() {
for _, c := range contratos {
switch regla.AplicaA {
case "renovable":
if c.Servicio.Tipo == "renovable" {
filtrados = append(filtrados, c)
for _, s := range c.Servicios {
if s.Tipo == "renovable" {
filtrados = append(filtrados, c)
break
}
}
case "unico":
if c.Servicio.Tipo == "unico" {
filtrados = append(filtrados, c)
for _, s := range c.Servicios {
if s.Tipo == "unico" {
filtrados = append(filtrados, c)
break
}
}
default:
filtrados = append(filtrados, c)
+18 -12
View File
@@ -82,6 +82,15 @@ func EnviarCorreoManual(contrato *models.Contrato) error {
return err
}
dias := int(contrato.FechaVencimiento.Sub(time.Now()).Hours() / 24)
var items []ItemServicio
for _, s := range contrato.Servicios {
items = append(items, ItemServicio{
Nombre: s.Nombre,
Precio: s.Precio,
Moneda: s.Moneda,
FechaVenc: contrato.FechaVencimiento.Format("02/01/2006"),
})
}
datos := DatosPlantilla{
ClienteNombre: contrato.Cliente.Nombre,
ClienteEmpresa: contrato.Cliente.Empresa,
@@ -89,12 +98,7 @@ func EnviarCorreoManual(contrato *models.Contrato) error {
FechaVencimiento: contrato.FechaVencimiento.Format("02/01/2006"),
DiasRestantes: dias,
Total: contrato.PrecioAcordado,
Servicios: []ItemServicio{{
Nombre: contrato.Servicio.Nombre,
Precio: contrato.PrecioAcordado,
Moneda: contrato.Servicio.Moneda,
FechaVenc: contrato.FechaVencimiento.Format("02/01/2006"),
}},
Servicios: items,
}
html, err := RenderPlantilla(p, datos)
if err != nil {
@@ -115,12 +119,14 @@ func EnviarNotificacionGrupo(regla *models.NotificacionRegla, cliente *models.Cl
var fechaVenc time.Time
for _, c := range contratos {
items = append(items, ItemServicio{
Nombre: c.Servicio.Nombre,
Precio: c.PrecioAcordado,
Moneda: c.Servicio.Moneda,
FechaVenc: c.FechaVencimiento.Format("02/01/2006"),
})
for _, s := range c.Servicios {
items = append(items, ItemServicio{
Nombre: s.Nombre,
Precio: s.Precio,
Moneda: s.Moneda,
FechaVenc: c.FechaVencimiento.Format("02/01/2006"),
})
}
total += c.PrecioAcordado
if fechaVenc.IsZero() || c.FechaVencimiento.Before(fechaVenc) {
fechaVenc = c.FechaVencimiento