This commit is contained in:
Lizandro Guarnizo
2026-05-13 22:05:20 -05:00
parent 381425b7e6
commit 9bcddcf1ea
4 changed files with 28 additions and 4 deletions
+5 -3
View File
@@ -21,6 +21,7 @@ type NotificacionLog struct {
Asunto string `json:"asunto" gorm:"column:asunto"`
PreviewHTML string `json:"preview_html" gorm:"column:preview_html;type:text"`
Pasarela string `json:"pasarela" gorm:"column:pasarela;type:varchar(20)"` // bold | dlocal | (vacío para correos de aviso)
EnlacePago string `json:"enlace_pago" gorm:"column:enlace_pago;type:text"` // URL del link de pago generado en este envío
}
func (NotificacionLog) TableName() string { return "notificaciones_log" }
@@ -74,9 +75,10 @@ func CreateNotificacionLog(n NotificacionLog) (*NotificacionLog, error) {
func UpdateNotificacionLog(n NotificacionLog) error {
return app.Http.Database.DB.Model(&n).Updates(map[string]interface{}{
"estado": n.Estado,
"error_msg": n.ErrorMsg,
"pasarela": n.Pasarela,
"estado": n.Estado,
"error_msg": n.ErrorMsg,
"pasarela": n.Pasarela,
"enlace_pago": n.EnlacePago,
}).Error
}
+1
View File
@@ -232,6 +232,7 @@ func EnviarNotificacionGrupo(regla *models.NotificacionRegla, cliente *models.Cl
Asunto: p.Asunto,
PreviewHTML: html,
Pasarela: pasarela,
EnlacePago: enlacePago,
}
savedLog, err := models.CreateNotificacionLog(logEntry)
if err != nil {
+8 -1
View File
@@ -229,7 +229,14 @@
<div class="ml-1">
<p class="text-sm font-medium text-gray-800" x-text="ev.titulo"></p>
<p class="text-xs text-gray-500 mt-0.5" x-text="ev.detalle"></p>
<time class="text-xs text-gray-400" x-text="fmtDatetime(ev.fecha)"></time>
<template x-if="ev.enlace">
<a :href="ev.enlace" target="_blank" rel="noopener"
class="inline-flex items-center gap-1 text-xs text-indigo-600 hover:underline mt-0.5 break-all">
<svg class="w-3 h-3 shrink-0" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M13.19 8.688a4.5 4.5 0 0 1 1.242 7.244l-4.5 4.5a4.5 4.5 0 0 1-6.364-6.364l1.757-1.757m13.35-.622 1.757-1.757a4.5 4.5 0 0 0-6.364-6.364l-4.5 4.5a4.5 4.5 0 0 0 1.242 7.244"/></svg>
<span x-text="ev.enlace.length > 50 ? ev.enlace.slice(0,50)+'…' : ev.enlace"></span>
</a>
</template>
<time class="block text-xs text-gray-400 mt-0.5" x-text="fmtDatetime(ev.fecha)"></time>
<span x-show="ev.estado==='error'" class="ml-2 text-xs text-red-500 font-medium">Fallido</span>
</div>
</li>
+14
View File
@@ -248,6 +248,7 @@ func GetHistorialContrato(c *fiber.Ctx) error {
Icono string `json:"icono"`
Titulo string `json:"titulo"`
Detalle string `json:"detalle"`
Enlace string `json:"enlace"` // URL de pago generada en este envío (opcional)
Estado string `json:"estado"` // ok | error | info
FechaISO string `json:"fecha"`
}
@@ -264,6 +265,18 @@ func GetHistorialContrato(c *fiber.Ctx) error {
FechaISO: contrato.CreatedAt.Format(time.RFC3339),
})
// Evento: pago confirmado (directo del contrato, siempre visible si se pagó)
if contrato.PagoConfirmado && contrato.FechaPago != nil {
timeline = append(timeline, Evento{
Tipo: "pago",
Icono: "currency",
Titulo: "Pago confirmado",
Detalle: "Nuevo vencimiento: " + contrato.FechaVencimiento.Format("02/01/2006"),
Estado: "ok",
FechaISO: contrato.FechaPago.Format(time.RFC3339),
})
}
// Evento: renovaciones (updated_at con estado renovado — heurístico por estado)
if contrato.Estado == "renovado" {
timeline = append(timeline, Evento{
@@ -297,6 +310,7 @@ func GetHistorialContrato(c *fiber.Ctx) error {
Icono: "mail",
Titulo: "Notificación enviada" + reglaLabel,
Detalle: detalle,
Enlace: n.EnlacePago,
Estado: estado,
FechaISO: n.CreatedAt.Format(time.RFC3339),
})