Adição das casas decimais

This commit is contained in:
2026-06-22 19:24:30 -03:00
parent 56b3e146bf
commit 74391d5a0c
6 changed files with 23 additions and 9 deletions

View File

@@ -17,9 +17,9 @@ module ApplicationHelper
link_to label, path, class: css
end
# Formata moeda BR
# Formata moeda BR (milhar com ".", decimais com ","): R$ 1.234,56
def moeda(valor)
"R$ #{"%.2f" % valor.to_f}".gsub('.', ',')
number_to_currency(valor.to_f, unit: 'R$ ', separator: ',', delimiter: '.', precision: 2)
end
# Badge de status de consolidação

View File

@@ -180,7 +180,7 @@ export default class extends Controller {
const valor = dados.valor_total || 0
this.valorTotalTarget.textContent =
"R$ " + valor.toFixed(2).replace(".", ",")
"R$ " + valor.toLocaleString("pt-BR", { minimumFractionDigits: 2, maximumFractionDigits: 2 })
const classificadas = dados.classificadas || 0
this.contadorClassificadasTarget.textContent = classificadas

View File

@@ -99,7 +99,11 @@ class Configuracao < ApplicationRecord
end
def valor_formatado
return "R$ #{format('%.2f', valor.to_f).gsub('.', ',')}" if moeda?
if moeda?
inteiro, decimais = format('%.2f', valor.to_f).split('.')
inteiro = inteiro.reverse.gsub(/(\d{3})(?=\d)/, '\1.').reverse
return "R$ #{inteiro},#{decimais}"
end
valor
end
end

View File

@@ -47,8 +47,15 @@ class NotificacaoService
Configuracao.valor('notificacao_email') == 'true'
end
# Moeda BR com separador de milhar: R$ 1.234,56
def moeda(v)
inteiro, decimais = format('%.2f', v.to_f).split('.')
inteiro = inteiro.reverse.gsub(/(\d{3})(?=\d)/, '\1.').reverse
"R$ #{inteiro},#{decimais}"
end
def mensagem(user, cm)
valor = "R$ #{format('%.2f', cm.valor_total)}".gsub('.', ',')
valor = moeda(cm.valor_total)
"Olá #{user.nome.split.first}! 🚚\n" \
"Seu pagamento de entregas foi fechado.\n" \
"📋 #{@consolidacao.nome}\n" \
@@ -81,7 +88,7 @@ class NotificacaoService
# ── Aviso de pagamento efetuado ─────────────────────────────
def mensagem_pagamento(user, cm)
valor = "R$ #{format('%.2f', cm.valor_total)}".gsub('.', ',')
valor = moeda(cm.valor_total)
"Olá #{user.nome.split.first}! ✅\n" \
"Seu pagamento foi efetuado.\n" \
"📋 #{@consolidacao.nome}\n" \

View File

@@ -82,8 +82,11 @@ module Pdf
end
end
# Moeda BR com separador de milhar: R$ 1.234,56
def moeda(v)
"R$ #{format('%.2f', v.to_f)}".gsub('.', ',')
inteiro, decimais = format('%.2f', v.to_f).split('.')
inteiro = inteiro.reverse.gsub(/(\d{3})(?=\d)/, '\1.').reverse
"R$ #{inteiro},#{decimais}"
end
# Bloco de assinaturas lado a lado: motorista (esquerda) e administrador

View File

@@ -530,7 +530,7 @@
label: (ctx) => {
const idx = ctx.dataIndex;
return [
` Valor: R$ ${ctx.parsed.y.toFixed(2).replace('.', ',')}`,
` Valor: R$ ${ctx.parsed.y.toLocaleString('pt-BR', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`,
` Entregas: ${qtds[idx]}`
];
}
@@ -591,7 +591,7 @@
bodyColor: '#ffffff',
padding: 12,
callbacks: {
label: (c) => ` ${c.label}: R$ ${c.parsed.toFixed(2).replace('.', ',')}`
label: (c) => ` ${c.label}: R$ ${c.parsed.toLocaleString('pt-BR', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`
}
}
}