Private
Public Access
quedaria testear los 4 tipos de email
Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
1 parent
0160ba90d4
commit
a9ec514687
6 files changed
+483
-106
No files matched your search
@@ -0,0 +1,99 @@
|
||||
package dto_builders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
htmlutil "html"
|
||||
|
||||
dto_email "repuestera_back/dto/Email"
|
||||
"repuestera_back/models"
|
||||
)
|
||||
|
||||
// StockBajoEmailBuilder arma el aviso de stock por debajo del mínimo. El
|
||||
// cálculo del faltante y el armado de los ítems son propios de este email.
|
||||
type StockBajoEmailBuilder struct {
|
||||
stock *models.Stock
|
||||
repuesto *models.Repuesto
|
||||
saldoAnterior float64
|
||||
destinatarios []string
|
||||
usuarioID uint
|
||||
err error
|
||||
}
|
||||
|
||||
var _ IBuilder[dto_email.MensajeEmail] = (*StockBajoEmailBuilder)(nil)
|
||||
|
||||
func NewStockBajoEmailBuilder() *StockBajoEmailBuilder {
|
||||
return &StockBajoEmailBuilder{}
|
||||
}
|
||||
|
||||
func (b *StockBajoEmailBuilder) ConStock(stock *models.Stock) *StockBajoEmailBuilder {
|
||||
if stock == nil {
|
||||
AcumularError(&b.err, "el stock no puede ser nulo")
|
||||
}
|
||||
b.stock = stock
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *StockBajoEmailBuilder) ConRepuesto(repuesto *models.Repuesto) *StockBajoEmailBuilder {
|
||||
if repuesto == nil {
|
||||
AcumularError(&b.err, "el repuesto no puede ser nulo")
|
||||
}
|
||||
b.repuesto = repuesto
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *StockBajoEmailBuilder) ConSaldoAnterior(saldoAnterior float64) *StockBajoEmailBuilder {
|
||||
b.saldoAnterior = saldoAnterior
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *StockBajoEmailBuilder) ConDestinatarios(destinatarios []string) *StockBajoEmailBuilder {
|
||||
b.destinatarios = destinatarios
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *StockBajoEmailBuilder) ConUsuarioID(usuarioID uint) *StockBajoEmailBuilder {
|
||||
b.usuarioID = usuarioID
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *StockBajoEmailBuilder) Build() (*dto_email.MensajeEmail, error) {
|
||||
if b.stock == nil && b.err == nil {
|
||||
AcumularError(&b.err, "falta el stock")
|
||||
}
|
||||
if b.repuesto == nil && b.err == nil {
|
||||
AcumularError(&b.err, "falta el repuesto")
|
||||
}
|
||||
if b.err != nil {
|
||||
return nil, b.err
|
||||
}
|
||||
|
||||
almacen := fmt.Sprintf("%d", b.stock.AlmacenID)
|
||||
if b.stock.Almacen.Codigo != "" {
|
||||
almacen = b.stock.Almacen.Codigo
|
||||
}
|
||||
minimo := float64(b.repuesto.StockMinimo)
|
||||
nombre := htmlutil.EscapeString(b.repuesto.Nombre)
|
||||
|
||||
descripcion := fmt.Sprintf(
|
||||
"<p>El ajuste de stock dejó <strong>%s</strong> por debajo del mínimo "+
|
||||
"configurado en el almacén <strong>%s</strong>.</p>"+
|
||||
"<p>Usuario responsable: %d</p>",
|
||||
nombre, htmlutil.EscapeString(almacen), b.usuarioID,
|
||||
)
|
||||
|
||||
items := []string{
|
||||
fmt.Sprintf("Repuesto: %s", b.repuesto.Nombre),
|
||||
fmt.Sprintf("Almacén: %s", almacen),
|
||||
fmt.Sprintf("Stock anterior: %.3f", b.saldoAnterior),
|
||||
fmt.Sprintf("Stock actual: %.3f", b.stock.Cantidad),
|
||||
fmt.Sprintf("Stock mínimo: %.3f", minimo),
|
||||
fmt.Sprintf("Faltante para el mínimo: %.3f", minimo-b.stock.Cantidad),
|
||||
}
|
||||
|
||||
return NewMensajeEmailBuilder().
|
||||
ConTitulo(fmt.Sprintf("Stock bajo mínimo: %s", b.repuesto.Nombre)).
|
||||
ConDescripcion(descripcion).
|
||||
ConItems(items).
|
||||
ConDestinatarios(b.destinatarios).
|
||||
Build()
|
||||
}
|
||||
Reference in new issue
Block a user