Skip to content

Commit

Permalink
Fixed different month amount display bug
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Sep 23, 2018
1 parent 35b3031 commit 12502bd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
14 changes: 12 additions & 2 deletions webapp/src/pages/CFODashBoard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,23 @@ class CFODashboard extends Component {
departments: displayedDepartments,
applications: displayedApplications,
sysLmt: this.scaleAmount(configs.system_monthly_limit, token.precision),
sysUsed: this.scaleAmount(configs.system_limit_used, token.precision),
sysUsed: this.scaleAmount(this.actualUsed(configs.system_limit_used, configs.last_spend_time), token.precision),
tokenName: token.name,
tokenPrecision: token.precision,
tokenContract: configs.token.contract
});
}

actualUsed = (used, usedTime) => {
let spendDate = new Date(usedTime * 1000);
let nowDate = new Date();

if (spendDate.getUTCFullYear() == nowDate.getFullYear() && spendDate.getUTCMonth() == nowDate.getUTCMonth())
return used;

return 0;
}

formatAmount = (amount, token) => {
return this.scaleAmount(amount, token.precision) + " " + token.name;
}
Expand Down Expand Up @@ -214,7 +224,7 @@ class CFODashboard extends Component {
this.setState({
newDepartmentModalVisibility: false,
});

this.pageInit();
}

Expand Down
16 changes: 13 additions & 3 deletions webapp/src/pages/Dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ class Dashborad extends Component {
displayedExpenditures.push({
id: currentExpenditure.id,
name: currentExpenditure.name,
used: this.formatAmount(currentExpenditure.allowance_used, token),
used: this.formatAmount(this.actualUsed(currentExpenditure.allowance_used, currentExpenditure.last_spend_time), token),
total: this.formatAmount(currentExpenditure.monthly_allowance, token),
percent: Math.round(currentExpenditure.allowance_used / currentExpenditure.monthly_allowance * 100)
percent: Math.round(this.actualUsed(currentExpenditure.allowance_used, currentExpenditure.last_spend_time) / currentExpenditure.monthly_allowance * 100)
});
}

Expand All @@ -105,7 +105,7 @@ class Dashborad extends Component {
this.setState({
departmentName: department.name,
monthlyAllowance: this.scaleAmount(department.monthly_allowance, token.precision),
allowanceUsed: this.scaleAmount(department.allowance_used, token.precision),
allowanceUsed: this.scaleAmount(this.actualUsed(department.allowance_used, department.last_spend_time), token.precision),
allowanceAllocated: this.scaleAmount(department.allowance_allocated, token.precision),
expenditures: displayedExpenditures,
expenses: displayedExpenses,
Expand All @@ -116,6 +116,16 @@ class Dashborad extends Component {
});
}

actualUsed = (used, usedTime) => {
let spendDate = new Date(usedTime * 1000);
let nowDate = new Date();

if (spendDate.getUTCFullYear() == nowDate.getFullYear() && spendDate.getUTCMonth() == nowDate.getUTCMonth())
return used;

return 0;
}

formatAmount = (amount, token) => {
return this.scaleAmount(amount, token.precision) + " " + token.name;
}
Expand Down
14 changes: 12 additions & 2 deletions webapp/src/pages/ExpenditureDetailPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,24 @@ class ExpenditureDetailPage extends Component {
expenditureName: expenditure.name,
expenditureRecipient: expenditure.recipient,
expenditureAllowance: this.scaleAmount(expenditure.monthly_allowance, token.precision),
expenditureUsed: this.scaleAmount(expenditure.allowance_used, token.precision),
expenditureAllowanceLeft: this.scaleAmount(expenditure.monthly_allowance - expenditure.allowance_used, token.precision),
expenditureUsed: this.scaleAmount(this.actualUsed(expenditure.allowance_used, expenditure.last_spend_time), token.precision),
expenditureAllowanceLeft: this.scaleAmount(expenditure.monthly_allowance - this.actualUsed(expenditure.allowance_used, expenditure.last_spend_time), token.precision),
tokenName: token.name,
tokenPrecision: token.precision,
expenses: displayedExpenses
});
}

actualUsed = (used, usedTime) => {
let spendDate = new Date(usedTime * 1000);
let nowDate = new Date();

if (spendDate.getUTCFullYear() == nowDate.getFullYear() && spendDate.getUTCMonth() == nowDate.getUTCMonth())
return used;

return 0;
}

formatAmount = (amount, token) => {
return this.scaleAmount(amount, token.precision) + " " + token.name;
}
Expand Down

0 comments on commit 12502bd

Please sign in to comment.