fix(financeiro): sincroniza calculo de juros com as configuracoes do curso do aluno
Build and Deploy (Gitea) / build-and-deploy (push) Failing after 0s
Details
Build and Deploy (Gitea) / build-and-deploy (push) Failing after 0s
Details
This commit is contained in:
parent
7baafee2b1
commit
be7ce85a2f
|
|
@ -1197,8 +1197,15 @@ const Finance: React.FC<FinanceProps> = ({ data, updateData }) => {
|
|||
if (tt > dd) {
|
||||
const baseA = payment.amount - discount;
|
||||
const dDays = Math.ceil((tt.getTime() - dd.getTime()) / 86400000);
|
||||
const fineAmt = baseA * ((Number(payment.lateFee) || 2) / 100);
|
||||
const intAmt = baseA * (((Number(payment.interest) || 1) / 30) / 100) * dDays;
|
||||
|
||||
const student = data.students.find(s => s.id === payment.studentId);
|
||||
const studentClass = data.classes.find(c => c.id === student?.classId);
|
||||
const course = data.courses.find(c => c.id === studentClass?.courseId);
|
||||
const pLateFee = Number(payment.lateFee) || Number(course?.finePercentage) || 2;
|
||||
const pInterest = Number(payment.interest) || Number(course?.interestPercentage) || 1;
|
||||
|
||||
const fineAmt = baseA * (pLateFee / 100);
|
||||
const intAmt = baseA * ((pInterest / 30) / 100) * dDays;
|
||||
additions = fineAmt + intAmt;
|
||||
}
|
||||
}
|
||||
|
|
@ -1314,8 +1321,15 @@ const Finance: React.FC<FinanceProps> = ({ data, updateData }) => {
|
|||
if (tt > dd) {
|
||||
const baseA = payment.amount - discount;
|
||||
const dDays = Math.ceil((tt.getTime() - dd.getTime()) / 86400000);
|
||||
const fineAmt = baseA * ((Number(payment.lateFee) || 2) / 100);
|
||||
const intAmt = baseA * (((Number(payment.interest) || 1) / 30) / 100) * dDays;
|
||||
|
||||
const student = data.students.find(s => s.id === payment.studentId);
|
||||
const studentClass = data.classes.find(c => c.id === student?.classId);
|
||||
const course = data.courses.find(c => c.id === studentClass?.courseId);
|
||||
const pLateFee = Number(payment.lateFee) || Number(course?.finePercentage) || 2;
|
||||
const pInterest = Number(payment.interest) || Number(course?.interestPercentage) || 1;
|
||||
|
||||
const fineAmt = baseA * (pLateFee / 100);
|
||||
const intAmt = baseA * ((pInterest / 30) / 100) * dDays;
|
||||
additions = fineAmt + intAmt;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -317,6 +317,25 @@ app.get('/api/portal/financeiro', authMiddleware, async (req, res) => {
|
|||
return res.status(500).json({ error: 'Erro no SQL: ' + dbErr.message, studentId: req.user.studentId });
|
||||
}
|
||||
|
||||
// Buscar configurações de juros do curso do aluno
|
||||
let defaultLateFee = 2;
|
||||
let defaultInterest = 1;
|
||||
try {
|
||||
const { rows: studentRows } = await pool.query('SELECT turma_id FROM alunos WHERE id = $1', [req.user.studentId]);
|
||||
if (studentRows.length > 0 && studentRows[0].turma_id) {
|
||||
const { rows: tRows } = await pool.query('SELECT curso_id FROM turmas WHERE id = $1', [studentRows[0].turma_id]);
|
||||
if (tRows.length > 0 && tRows[0].curso_id) {
|
||||
const { rows: cRows } = await pool.query('SELECT multa_percentual, juros_percentual FROM cursos WHERE id = $1', [tRows[0].curso_id]);
|
||||
if (cRows.length > 0) {
|
||||
defaultLateFee = Number(cRows[0].multa_percentual) || 2;
|
||||
defaultInterest = Number(cRows[0].juros_percentual) || 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (courseErr) {
|
||||
console.error('Financeiro: erro ao buscar curso -', courseErr.message);
|
||||
}
|
||||
|
||||
// 2. CONSTRUIR LISTA FINAL: Apenas registros do SQL (fonte única da verdade)
|
||||
const finalPayments = [];
|
||||
|
||||
|
|
@ -370,6 +389,8 @@ app.get('/api/portal/financeiro', authMiddleware, async (req, res) => {
|
|||
totalInstallments,
|
||||
link_boleto: db.link_boleto || null,
|
||||
transactionReceiptUrl: db.transaction_receipt_url || null,
|
||||
lateFee: defaultLateFee,
|
||||
interest: defaultInterest,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue