Skip to content

Commit

Permalink
Fix total calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
grgia committed Nov 3, 2023
1 parent b049999 commit c975ed9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1487,15 +1487,18 @@ function getMoneyRequestSpendBreakdown(report, allReportsDict = null) {
}
if (moneyRequestReport) {
let nonReimbursableSpend = lodashGet(moneyRequestReport, 'nonReimbursableTotal', 0);
let reimbursableSpend = lodashGet(moneyRequestReport, 'total', 0);
let totalSpend = lodashGet(moneyRequestReport, 'total', 0);

if (nonReimbursableSpend + reimbursableSpend !== 0) {
if (nonReimbursableSpend + totalSpend !== 0) {
// There is a possibility that if the Expense report has a negative total.
// This is because there are instances where you can get a credit back on your card,
// or you enter a negative expense to “offset” future expenses
nonReimbursableSpend = isExpenseReport(moneyRequestReport) ? nonReimbursableSpend * -1 : Math.abs(nonReimbursableSpend);
reimbursableSpend = isExpenseReport(moneyRequestReport) ? reimbursableSpend * -1 : Math.abs(reimbursableSpend);
const totalDisplaySpend = nonReimbursableSpend + reimbursableSpend;
totalSpend = isExpenseReport(moneyRequestReport) ? totalSpend * -1 : Math.abs(totalSpend);

const totalDisplaySpend = totalSpend;
const reimbursableSpend = totalDisplaySpend - nonReimbursableSpend;

return {
nonReimbursableSpend,
reimbursableSpend,
Expand Down

0 comments on commit c975ed9

Please sign in to comment.