Fix percentage call.

This commit is contained in:
James Cole
2021-04-03 07:32:48 +02:00
parent 0dc3068f7f
commit f377c92d8a
3 changed files with 9 additions and 8 deletions

View File

@@ -203,25 +203,26 @@ export default {
let budgetId = parseInt(current.attributes.budget_id); let budgetId = parseInt(current.attributes.budget_id);
let currencyId = parseInt(current.attributes.currency_id); let currencyId = parseInt(current.attributes.currency_id);
let spentFloat = parseFloat(current.attributes.spent); let spentFloat = parseFloat(current.attributes.spent);
let spentFloatPos = parseFloat(current.attributes.spent) * -1;
let amount = parseFloat(current.attributes.amount); let amount = parseFloat(current.attributes.amount);
let period = current.attributes.period ?? 'other'; let period = current.attributes.period ?? 'other';
let pctGreen = 0; let pctGreen = 0;
let pctOrange = 0; let pctOrange = 0;
let pctRed = 0; let pctRed = 0;
console.log('Collected "' + period + '" budget limit #' + currentId + ' (part of budget #' + budgetId + ')'); //console.log('Collected "' + period + '" budget limit #' + currentId + ' (part of budget #' + budgetId + ')');
console.log('Spent ' + spentFloat + ' of ' + amount); //console.log('Spent ' + spentFloat + ' of ' + amount);
// remove budget info from rawBudgets if it's there: // remove budget info from rawBudgets if it's there:
this.filterBudgets(budgetId, currencyId); this.filterBudgets(budgetId, currencyId);
// spent within budget: // spent within budget:
if (0.0 !== spentFloat && spentFloat * -1 < amount) { if (0.0 !== spentFloat && spentFloatPos < amount) {
pctGreen = (spentFloat * -1) / (amount * 100); pctGreen = (spentFloatPos / amount) * 100;
} }
// spent over budget // spent over budget
if (0.0 !== spentFloat && (spentFloat * -1) > amount) { if (0.0 !== spentFloatPos && spentFloatPos > amount) {
pctOrange = (amount / (spentFloat * -1)) * 100; pctOrange = (spentFloatPos / amount) * 100;
pctRed = 100 - pctOrange; pctRed = 100 - pctOrange;
} }
let obj = { let obj = {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long