feat: contrato soporta múltiples servicios (many2many) con precio sugerido
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user