mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-20 09:44:26 +08:00
fix percent is wrong when some amount of category is negative
This commit is contained in:
@@ -315,7 +315,16 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data = combinedData.items[id];
|
const data = combinedData.items[id];
|
||||||
data.percent = data.totalAmount * 100 / combinedData.totalAmount;
|
|
||||||
|
if (data.totalAmount > 0) {
|
||||||
|
data.percent = data.totalAmount * 100 / combinedData.totalNonNegativeAmount;
|
||||||
|
} else {
|
||||||
|
data.percent = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.percent < 0) {
|
||||||
|
data.percent = 0;
|
||||||
|
}
|
||||||
|
|
||||||
allStatisticsItems.push(data);
|
allStatisticsItems.push(data);
|
||||||
}
|
}
|
||||||
@@ -550,7 +559,8 @@ export default {
|
|||||||
},
|
},
|
||||||
getDataItemsByTransactions(transactionStatistics) {
|
getDataItemsByTransactions(transactionStatistics) {
|
||||||
const allDataItems = {};
|
const allDataItems = {};
|
||||||
let allAmount = 0;
|
let totalAmount = 0;
|
||||||
|
let totalNonNegativeAmount = 0;
|
||||||
|
|
||||||
for (let i = 0; i < transactionStatistics.items.length; i++) {
|
for (let i = 0; i < transactionStatistics.items.length; i++) {
|
||||||
const item = transactionStatistics.items[i];
|
const item = transactionStatistics.items[i];
|
||||||
@@ -602,7 +612,12 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allAmount += item.amountInDefaultCurrency;
|
totalAmount += item.amountInDefaultCurrency;
|
||||||
|
|
||||||
|
if (item.amountInDefaultCurrency > 0) {
|
||||||
|
totalNonNegativeAmount += item.amountInDefaultCurrency;
|
||||||
|
}
|
||||||
|
|
||||||
allDataItems[item.account.id] = data;
|
allDataItems[item.account.id] = data;
|
||||||
}
|
}
|
||||||
} else if (this.query.chartDataType === this.$constants.statistics.allChartDataTypes.ExpenseByPrimaryCategory.type ||
|
} else if (this.query.chartDataType === this.$constants.statistics.allChartDataTypes.ExpenseByPrimaryCategory.type ||
|
||||||
@@ -624,7 +639,12 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allAmount += item.amountInDefaultCurrency;
|
totalAmount += item.amountInDefaultCurrency;
|
||||||
|
|
||||||
|
if (item.amountInDefaultCurrency > 0) {
|
||||||
|
totalNonNegativeAmount += item.amountInDefaultCurrency;
|
||||||
|
}
|
||||||
|
|
||||||
allDataItems[item.primaryCategory.id] = data;
|
allDataItems[item.primaryCategory.id] = data;
|
||||||
}
|
}
|
||||||
} else if (this.query.chartDataType === this.$constants.statistics.allChartDataTypes.ExpenseBySecondaryCategory.type ||
|
} else if (this.query.chartDataType === this.$constants.statistics.allChartDataTypes.ExpenseBySecondaryCategory.type ||
|
||||||
@@ -646,20 +666,27 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allAmount += item.amountInDefaultCurrency;
|
totalAmount += item.amountInDefaultCurrency;
|
||||||
|
|
||||||
|
if (item.amountInDefaultCurrency > 0) {
|
||||||
|
totalNonNegativeAmount += item.amountInDefaultCurrency;
|
||||||
|
}
|
||||||
|
|
||||||
allDataItems[item.category.id] = data;
|
allDataItems[item.category.id] = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
totalAmount: allAmount,
|
totalAmount: totalAmount,
|
||||||
|
totalNonNegativeAmount: totalNonNegativeAmount,
|
||||||
items: allDataItems
|
items: allDataItems
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getDataItemsByAccounts(accounts) {
|
getDataItemsByAccounts(accounts) {
|
||||||
const allDataItems = {};
|
const allDataItems = {};
|
||||||
let allAmount = 0;
|
let totalAmount = 0;
|
||||||
|
let totalNonNegativeAmount = 0;
|
||||||
|
|
||||||
for (let i = 0; i < accounts.length; i++) {
|
for (let i = 0; i < accounts.length; i++) {
|
||||||
const account = accounts[i];
|
const account = accounts[i];
|
||||||
@@ -708,12 +735,18 @@ export default {
|
|||||||
totalAmount: amount
|
totalAmount: amount
|
||||||
};
|
};
|
||||||
|
|
||||||
allAmount += amount;
|
totalAmount += amount;
|
||||||
|
|
||||||
|
if (amount > 0) {
|
||||||
|
totalNonNegativeAmount += amount;
|
||||||
|
}
|
||||||
|
|
||||||
allDataItems[account.id] = data;
|
allDataItems[account.id] = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
totalAmount: allAmount,
|
totalAmount: totalAmount,
|
||||||
|
totalNonNegativeAmount: totalNonNegativeAmount,
|
||||||
items: allDataItems
|
items: allDataItems
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user