Skip to content

Commit

Permalink
feat: amount null check when change currency and calculate finance fo…
Browse files Browse the repository at this point in the history
…r the period
  • Loading branch information
habibi03336 committed May 9, 2024
1 parent c58aaf7 commit f652f48
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main/java/com/finance/service/finance/Finance.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public void changeCurrency(String toCurrency, ExchangeOffice ex){
double finalRatio = ex.getFinalRate(year, quarter, currency, toCurrency);
currency = toCurrency;
for(Account acc : accounts){
if(acc.amount == null){
continue;
}
if(acc.type.isIncome()){
acc.amount = (long)(acc.amount * averageRatio);
} else {
Expand All @@ -57,7 +60,11 @@ public static Finance generateIncomeDiffFinance(Finance operand1, Finance operan
if(acc.type.isIncome()){
for(Account acc2: accounts2){
if(acc.type.equals(acc2.type)){
newFinance.addAccount(acc.type, acc.amount - acc2.amount);
if(acc.amount == null || acc2.amount == null) {
newFinance.addAccount(acc.type, null);
} else {
newFinance.addAccount(acc.type, acc.amount - acc2.amount);
}
break;
}
}
Expand Down

0 comments on commit f652f48

Please sign in to comment.