mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 17:24:26 +08:00
add total income / total expense / net income to value metric in insights explorer
This commit is contained in:
@@ -302,6 +302,9 @@ export class TransactionExplorerDataDimension implements NameValue {
|
|||||||
export enum TransactionExplorerValueMetricType {
|
export enum TransactionExplorerValueMetricType {
|
||||||
TransactionCount = 'transactionCount',
|
TransactionCount = 'transactionCount',
|
||||||
SourceAmountSum = 'sourceAmountSum',
|
SourceAmountSum = 'sourceAmountSum',
|
||||||
|
SourceIncomeAmountSum = 'sourceIncomeAmountSum',
|
||||||
|
SourceExpenseAmountSum = 'sourceExpenseAmountSum',
|
||||||
|
SourceNetIncomeAmountSum = 'sourceNetIncomeAmountSum',
|
||||||
SourceAmountAverage = 'sourceAmountAverage',
|
SourceAmountAverage = 'sourceAmountAverage',
|
||||||
SourceAmountMedian = 'sourceAmountMedian',
|
SourceAmountMedian = 'sourceAmountMedian',
|
||||||
SourceAmountQ1Amount = 'sourceQ1Amount',
|
SourceAmountQ1Amount = 'sourceQ1Amount',
|
||||||
@@ -325,6 +328,9 @@ export class TransactionExplorerValueMetric implements NameValue {
|
|||||||
private static readonly allInstancesByValue: Record<string, TransactionExplorerValueMetric> = {};
|
private static readonly allInstancesByValue: Record<string, TransactionExplorerValueMetric> = {};
|
||||||
|
|
||||||
public static readonly TransactionCount = new TransactionExplorerValueMetric('Transaction Count', TransactionExplorerValueMetricType.TransactionCount, false, true);
|
public static readonly TransactionCount = new TransactionExplorerValueMetric('Transaction Count', TransactionExplorerValueMetricType.TransactionCount, false, true);
|
||||||
|
public static readonly SourceIncomeAmountSum = new TransactionExplorerValueMetric('Total Income', TransactionExplorerValueMetricType.SourceIncomeAmountSum, true, true);
|
||||||
|
public static readonly SourceExpenseAmountSum = new TransactionExplorerValueMetric('Total Expense', TransactionExplorerValueMetricType.SourceExpenseAmountSum, true, true);
|
||||||
|
public static readonly SourceNetIncomeAmountSum = new TransactionExplorerValueMetric('Net Income', TransactionExplorerValueMetricType.SourceNetIncomeAmountSum, true, true);
|
||||||
public static readonly SourceAmountSum = new TransactionExplorerValueMetric('Total Amount', TransactionExplorerValueMetricType.SourceAmountSum, true, true);
|
public static readonly SourceAmountSum = new TransactionExplorerValueMetric('Total Amount', TransactionExplorerValueMetricType.SourceAmountSum, true, true);
|
||||||
public static readonly SourceAmountAverage = new TransactionExplorerValueMetric('Average Amount', TransactionExplorerValueMetricType.SourceAmountAverage, true, true);
|
public static readonly SourceAmountAverage = new TransactionExplorerValueMetric('Average Amount', TransactionExplorerValueMetricType.SourceAmountAverage, true, true);
|
||||||
public static readonly SourceAmountMedian = new TransactionExplorerValueMetric('Median Amount', TransactionExplorerValueMetricType.SourceAmountMedian, true, true);
|
public static readonly SourceAmountMedian = new TransactionExplorerValueMetric('Median Amount', TransactionExplorerValueMetricType.SourceAmountMedian, true, true);
|
||||||
|
|||||||
@@ -831,6 +831,8 @@ export const useExplorersStore = defineStore('explorers', () => {
|
|||||||
for (const seriesTransactions of values(allSeriesTransactions)) {
|
for (const seriesTransactions of values(allSeriesTransactions)) {
|
||||||
const allSourceAmountsInDefaultCurrency: number[] = [];
|
const allSourceAmountsInDefaultCurrency: number[] = [];
|
||||||
let totalSourceAmountSumInDefaultCurrency: number = 0;
|
let totalSourceAmountSumInDefaultCurrency: number = 0;
|
||||||
|
let totalSourceIncomeAmountSumInDefaultCurrency: number = 0;
|
||||||
|
let totalSourceExpenseAmountSumInDefaultCurrency: number = 0;
|
||||||
let minimumSourceAmountInDefaultCurrency: number = Number.MAX_SAFE_INTEGER;
|
let minimumSourceAmountInDefaultCurrency: number = Number.MAX_SAFE_INTEGER;
|
||||||
let maximumSourceAmountInDefaultCurrency: number = Number.MIN_SAFE_INTEGER;
|
let maximumSourceAmountInDefaultCurrency: number = Number.MIN_SAFE_INTEGER;
|
||||||
|
|
||||||
@@ -850,6 +852,12 @@ export const useExplorersStore = defineStore('explorers', () => {
|
|||||||
allSourceAmountsInDefaultCurrency.push(amountInDefaultCurrency);
|
allSourceAmountsInDefaultCurrency.push(amountInDefaultCurrency);
|
||||||
totalSourceAmountSumInDefaultCurrency += amountInDefaultCurrency;
|
totalSourceAmountSumInDefaultCurrency += amountInDefaultCurrency;
|
||||||
|
|
||||||
|
if (transaction.type === TransactionType.Income) {
|
||||||
|
totalSourceIncomeAmountSumInDefaultCurrency += amountInDefaultCurrency;
|
||||||
|
} else if (transaction.type === TransactionType.Expense) {
|
||||||
|
totalSourceExpenseAmountSumInDefaultCurrency += amountInDefaultCurrency;
|
||||||
|
}
|
||||||
|
|
||||||
if (amountInDefaultCurrency >= 0 && amountInDefaultCurrency < minimumSourceAmountInDefaultCurrency) {
|
if (amountInDefaultCurrency >= 0 && amountInDefaultCurrency < minimumSourceAmountInDefaultCurrency) {
|
||||||
minimumSourceAmountInDefaultCurrency = amountInDefaultCurrency;
|
minimumSourceAmountInDefaultCurrency = amountInDefaultCurrency;
|
||||||
}
|
}
|
||||||
@@ -865,6 +873,12 @@ export const useExplorersStore = defineStore('explorers', () => {
|
|||||||
value = allSourceAmountsInDefaultCurrency.length;
|
value = allSourceAmountsInDefaultCurrency.length;
|
||||||
} else if (valueMetric === TransactionExplorerValueMetric.SourceAmountSum) {
|
} else if (valueMetric === TransactionExplorerValueMetric.SourceAmountSum) {
|
||||||
value = totalSourceAmountSumInDefaultCurrency;
|
value = totalSourceAmountSumInDefaultCurrency;
|
||||||
|
} else if (valueMetric === TransactionExplorerValueMetric.SourceIncomeAmountSum) {
|
||||||
|
value = totalSourceIncomeAmountSumInDefaultCurrency;
|
||||||
|
} else if (valueMetric === TransactionExplorerValueMetric.SourceExpenseAmountSum) {
|
||||||
|
value = totalSourceExpenseAmountSumInDefaultCurrency;
|
||||||
|
} else if (valueMetric === TransactionExplorerValueMetric.SourceNetIncomeAmountSum) {
|
||||||
|
value = totalSourceIncomeAmountSumInDefaultCurrency - totalSourceExpenseAmountSumInDefaultCurrency;
|
||||||
} else if (valueMetric === TransactionExplorerValueMetric.SourceAmountAverage) {
|
} else if (valueMetric === TransactionExplorerValueMetric.SourceAmountAverage) {
|
||||||
value = allSourceAmountsInDefaultCurrency.length > 0 ? Math.trunc(totalSourceAmountSumInDefaultCurrency / allSourceAmountsInDefaultCurrency.length) : 0;
|
value = allSourceAmountsInDefaultCurrency.length > 0 ? Math.trunc(totalSourceAmountSumInDefaultCurrency / allSourceAmountsInDefaultCurrency.length) : 0;
|
||||||
} else if (valueMetric === TransactionExplorerValueMetric.SourceAmountMedian) {
|
} else if (valueMetric === TransactionExplorerValueMetric.SourceAmountMedian) {
|
||||||
|
|||||||
Reference in New Issue
Block a user