Private
Public Access
commit parcial con la parte de email y comprobante correjido
Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
1 parent
fcf16df5d3
commit
320cc9c241
13 files changed
+813
-36
No files matched your search
@@ -17,6 +17,7 @@ import (
|
||||
type ComprobanteVentaEmailBuilder struct {
|
||||
factura *models.Factura
|
||||
nombres map[uint64]string
|
||||
pagos []models.Pago
|
||||
destinatario string
|
||||
err error
|
||||
}
|
||||
@@ -40,6 +41,11 @@ func (b *ComprobanteVentaEmailBuilder) ConNombresRepuestos(nombres map[uint64]st
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *ComprobanteVentaEmailBuilder) ConPagos(pagos []models.Pago) *ComprobanteVentaEmailBuilder {
|
||||
b.pagos = pagos
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *ComprobanteVentaEmailBuilder) ConDestinatario(destinatario string) *ComprobanteVentaEmailBuilder {
|
||||
b.destinatario = strings.TrimSpace(destinatario)
|
||||
if b.destinatario == "" {
|
||||
@@ -58,7 +64,7 @@ func (b *ComprobanteVentaEmailBuilder) Build() (*dto_email.MensajeEmail, error)
|
||||
|
||||
return NewMensajeEmailBuilder().
|
||||
ConTitulo("Comprobante de venta " + b.factura.Numero).
|
||||
ConDescripcion(htmlComprobanteVenta(b.factura, b.nombres)).
|
||||
ConDescripcion(htmlComprobanteVenta(b.factura, b.nombres, b.pagos)).
|
||||
ConItems([]string{}).
|
||||
ConDestinatarios([]string{b.destinatario}).
|
||||
Build()
|
||||
@@ -75,7 +81,7 @@ const (
|
||||
// htmlComprobanteVenta genera el cuerpo HTML del comprobante. Usa tablas y
|
||||
// estilos inline porque los clientes de correo suelen ignorar las hojas de
|
||||
// estilo.
|
||||
func htmlComprobanteVenta(factura *models.Factura, nombres map[uint64]string) string {
|
||||
func htmlComprobanteVenta(factura *models.Factura, nombres map[uint64]string, pagos []models.Pago) string {
|
||||
var b strings.Builder
|
||||
|
||||
b.WriteString(`<div style="max-width:640px;margin:0 auto;font-family:Arial,Helvetica,sans-serif;color:` + comprobanteColorText + `;">`)
|
||||
@@ -112,13 +118,16 @@ func htmlComprobanteVenta(factura *models.Factura, nombres map[uint64]string) st
|
||||
b.WriteString(`<tr><td colspan="4" style="padding:12px 8px;color:` + comprobanteColorMuted + `;">Sin detalles</td></tr>`)
|
||||
}
|
||||
for _, detalle := range factura.Detalles {
|
||||
nombre := fmt.Sprintf("Repuesto %d", detalle.RepuestoID)
|
||||
nombre := detalle.RepuestoID // placeholder, se reemplaza abajo
|
||||
_ = nombre
|
||||
nombreRepuesto := fmt.Sprintf("Repuesto %d", detalle.RepuestoID)
|
||||
if n := strings.TrimSpace(nombres[detalle.RepuestoID]); n != "" {
|
||||
nombre = n
|
||||
nombreRepuesto = n
|
||||
}
|
||||
fmt.Fprintf(&b,
|
||||
`<tr style="border-bottom:1px solid %s;"><td style="padding:10px 8px;">%s</td><td align="right" style="padding:10px 8px;">%.3f</td><td align="right" style="padding:10px 8px;">%s</td><td align="right" style="padding:10px 8px;font-weight:600;">%s</td></tr>`,
|
||||
comprobanteColorBorder, htmlutil.EscapeString(nombre), detalle.Cantidad,
|
||||
`<tr style="border-bottom:1px solid %s;"><td style="padding:10px 8px;">%s</td><td align="right" style="padding:10px 8px;">%s</td><td align="right" style="padding:10px 8px;">%s</td><td align="right" style="padding:10px 8px;font-weight:600;">%s</td></tr>`,
|
||||
comprobanteColorBorder, htmlutil.EscapeString(nombreRepuesto),
|
||||
formatoCantidad(detalle.Cantidad),
|
||||
montoComprobante(detalle.PrecioUnitario), montoComprobante(detalle.Subtotal),
|
||||
)
|
||||
}
|
||||
@@ -143,6 +152,34 @@ func htmlComprobanteVenta(factura *models.Factura, nombres map[uint64]string) st
|
||||
}
|
||||
b.WriteString(`</table>`)
|
||||
|
||||
// Sección de pagos realizados
|
||||
if len(pagos) > 0 {
|
||||
b.WriteString(`<h2 style="margin:24px 0 10px;font-size:14px;letter-spacing:1px;text-transform:uppercase;color:` + comprobanteColorMuted + `;">Pagos realizados</h2>`)
|
||||
b.WriteString(`<table width="100%" cellpadding="0" cellspacing="0" style="border-collapse:collapse;font-size:13px;">`)
|
||||
b.WriteString(`<thead><tr style="background:` + comprobanteColorSoft + `;color:` + comprobanteColorMuted + `;text-align:left;">`)
|
||||
b.WriteString(`<th style="padding:10px 8px;">Fecha</th>`)
|
||||
b.WriteString(`<th align="right" style="padding:10px 8px;">Forma de pago</th>`)
|
||||
b.WriteString(`<th align="right" style="padding:10px 8px;">Importe</th>`)
|
||||
b.WriteString(`<th align="right" style="padding:10px 8px;">Observación</th>`)
|
||||
b.WriteString(`</tr></thead><tbody>`)
|
||||
for _, pago := range pagos {
|
||||
forma := "-"
|
||||
if pago.FormaDePago.ID != 0 {
|
||||
forma = pago.FormaDePago.Descripcion
|
||||
}
|
||||
fechaStr := pago.Fecha.Format("02/01/2006 15:04")
|
||||
obs := pago.Observacion
|
||||
if obs == "" {
|
||||
obs = "-"
|
||||
}
|
||||
fmt.Fprintf(&b,
|
||||
`<tr style="border-bottom:1px solid %s;"><td style="padding:10px 8px;">%s</td><td align="right" style="padding:10px 8px;">%s</td><td align="right" style="padding:10px 8px;font-weight:600;">%s</td><td style="padding:10px 8px;color:%s;">%s</td></tr>`,
|
||||
comprobanteColorBorder, fechaStr, htmlutil.EscapeString(forma), montoComprobante(pago.Importe), comprobanteColorMuted, htmlutil.EscapeString(obs),
|
||||
)
|
||||
}
|
||||
b.WriteString(`</tbody></table>`)
|
||||
}
|
||||
|
||||
if observacion := strings.TrimSpace(factura.Observacion); observacion != "" {
|
||||
fmt.Fprintf(&b, `<p style="margin:20px 0 0;font-size:12px;color:%s;"><strong>Observación:</strong> %s</p>`, comprobanteColorMuted, htmlutil.EscapeString(observacion))
|
||||
}
|
||||
@@ -153,6 +190,22 @@ func htmlComprobanteVenta(factura *models.Factura, nombres map[uint64]string) st
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// formatoCantidad devuelve la cantidad como número entero si no tiene decimales,
|
||||
// o con coma decimal si los tiene (formato AR).
|
||||
func formatoCantidad(cantidad float64) string {
|
||||
if cantidad == float64(int64(cantidad)) {
|
||||
return strconv.FormatInt(int64(cantidad), 10)
|
||||
}
|
||||
// Tiene decimales: mostrar con coma
|
||||
centavos := int64(math.Round(cantidad * 100))
|
||||
entero := centavos / 100
|
||||
dec := centavos % 100
|
||||
if dec == 0 {
|
||||
return strconv.FormatInt(entero, 10)
|
||||
}
|
||||
return fmt.Sprintf("%d,%02d", entero, dec)
|
||||
}
|
||||
|
||||
// montoComprobante formatea importes con separador de miles y coma decimal.
|
||||
func montoComprobante(valor float64) string {
|
||||
negativo := valor < 0
|
||||
|
||||
Reference in new issue
Block a user