From e7ded2df800094608e6ef50cd462a119e2456bdc Mon Sep 17 00:00:00 2001 From: Sidney Date: Thu, 14 May 2026 22:11:26 -0300 Subject: [PATCH] Fix: cast json amount to Number in portal logic to ensure strict equality comparison works for recovering corrupted double discount --- portal/server.js | 4 ++-- portal/server.selfhosted.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/portal/server.js b/portal/server.js index 1cffeb6..ca6d7d3 100644 --- a/portal/server.js +++ b/portal/server.js @@ -275,8 +275,8 @@ app.get('/api/portal/financeiro', authMiddleware, async (req, res) => { } } - let amountOriginal = jsonP.amount || Number(db.valor) || 0; - const discount = jsonP.amount ? (jsonP.discount || 0) : 0; + let amountOriginal = Number(jsonP.amount) || Number(db.valor) || 0; + const discount = jsonP.amount ? Number(jsonP.discount || 0) : 0; // [Bugfix]: Recupera o valor bruto corrompido pelo webhook antigo if (amountOriginal === Number(db.valor) && discount > 0) { diff --git a/portal/server.selfhosted.js b/portal/server.selfhosted.js index 1cbf63a..13700a4 100644 --- a/portal/server.selfhosted.js +++ b/portal/server.selfhosted.js @@ -279,8 +279,8 @@ app.get('/api/portal/financeiro', authMiddleware, async (req, res) => { } // amount_original = valor bruto (ex: 170), db.valor = valor líquido Asaas (ex: 150) - let amountOriginal = Number(db.amount_original) || jsonP.amount || Number(db.valor) || 0; - const discount = Number(db.discount) || (jsonP.amount ? (jsonP.discount || 0) : 0); + let amountOriginal = Number(db.amount_original) || Number(jsonP.amount) || Number(db.valor) || 0; + const discount = Number(db.discount) || (jsonP.amount ? Number(jsonP.discount || 0) : 0); // [Bugfix]: Se o amountOriginal for igual ao valor líquido (db.valor) e houver desconto, // significa que o webhook antigo sobrescreveu o valor bruto pelo líquido no JSON.