Skip to content

Commit

Permalink
[#181][#182] Fix income gap calculation on chart n show income gap
Browse files Browse the repository at this point in the history
outcome
  • Loading branch information
wayangalihpratama committed Dec 22, 2023
1 parent a32999a commit 7810061
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion frontend/src/pages/cases/components/Scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ const Scenario = ({
// newFocusCommodityIncome = parseFloat(newFocusCommodityIncome);
const additionalValue = newTotalIncome - currentTotalIncome;

let gapValue = incomeTarget - (newTotalIncome + additionalValue);
let gapValue = incomeTarget - newTotalIncome;
gapValue = gapValue < 0 ? 0 : gapValue;

return {
Expand Down Expand Up @@ -895,6 +895,27 @@ const Scenario = ({
};
});
}

if (ind.key === "income_gap") {
const currentGap = current.target - current.total_current_income;
res = {
...res,
current: currentGap <= 0 ? "-" : currentGap?.toFixed(2),
};
// scenario data
scenarioData.forEach((sd) => {
const scenarioKey = `scenario-${sd.key}`;
const segment =
sd.scenarioValues.find((sv) => sv.segmentId === selectedSegment) ||
{};
const segmentValue = segment?.value ? segment.value : current.target;
const segmentGap = current.target - segmentValue;
res = {
...res,
[scenarioKey]: segmentGap <= 0 ? "-" : segmentGap?.toFixed(2),
};
});
}
return res;
});
return data;
Expand Down

0 comments on commit 7810061

Please # to comment.