Group transactions by date to simplify grouping in UI
This commit is contained in:
@ -201,10 +201,9 @@ export const useAccountStore = defineStore("budget/account", {
|
||||
);
|
||||
const response = await result.json();
|
||||
const transactionsStore = useTransactionsStore();
|
||||
const transactions = transactionsStore.AddTransactions(
|
||||
transactionsStore.AddTransactions(
|
||||
response.Transactions
|
||||
);
|
||||
account.Transactions = transactions;
|
||||
},
|
||||
async FetchMonthBudget(budgetid: string, year: number, month: number) {
|
||||
const result = await GET(
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { POST } from "../api";
|
||||
import { formatDate, groupBy } from "../date";
|
||||
import { useAccountStore } from "./budget-account";
|
||||
|
||||
interface State {
|
||||
@ -21,6 +22,7 @@ export interface Transaction {
|
||||
PayeeID: string | undefined;
|
||||
Amount: number;
|
||||
Reconciled: boolean;
|
||||
AccountID: string;
|
||||
}
|
||||
|
||||
export const useTransactionsStore = defineStore("budget/transactions", {
|
||||
@ -39,24 +41,27 @@ export const useTransactionsStore = defineStore("budget/transactions", {
|
||||
}
|
||||
return reconciledBalance;
|
||||
},
|
||||
TransactionsList(state): Transaction[] {
|
||||
TransactionsByDate(state) : Record<string, Transaction[]> {
|
||||
const accountsStore = useAccountStore();
|
||||
return accountsStore.CurrentAccount!.Transactions.map((x) => {
|
||||
return this.Transactions.get(x)!;
|
||||
});
|
||||
const accountID = accountsStore.CurrentAccountID;
|
||||
const allTransactions = [...this.Transactions.values()];
|
||||
return groupBy(allTransactions.filter(x => x.AccountID == accountID), x => formatDate(x.Date));
|
||||
},
|
||||
TransactionsList(state) : Transaction[] {
|
||||
const accountsStore = useAccountStore();
|
||||
const accountID = accountsStore.CurrentAccountID;
|
||||
const allTransactions = [...this.Transactions.values()];
|
||||
return allTransactions.filter(x => x.AccountID == accountID);
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
AddTransactions(transactions: Array<Transaction>) {
|
||||
const transactionIds = [] as Array<string>;
|
||||
this.$patch(() => {
|
||||
for (const transaction of transactions) {
|
||||
transaction.Date = new Date(transaction.Date);
|
||||
this.Transactions.set(transaction.ID, transaction);
|
||||
transactionIds.push(transaction.ID);
|
||||
}
|
||||
});
|
||||
return transactionIds;
|
||||
},
|
||||
SetReconciledForAllTransactions(value: boolean) {
|
||||
for (const transaction of this.TransactionsList) {
|
||||
|
Reference in New Issue
Block a user