Account transactions view using libdrcr
This commit is contained in:
parent
ffef2d16dc
commit
a40e2f81ba
@ -91,6 +91,7 @@ pub fn run() {
|
|||||||
get_open_filename,
|
get_open_filename,
|
||||||
set_open_filename,
|
set_open_filename,
|
||||||
libdrcr_bridge::get_all_transactions_except_earnings_to_equity,
|
libdrcr_bridge::get_all_transactions_except_earnings_to_equity,
|
||||||
|
libdrcr_bridge::get_all_transactions_except_earnings_to_equity_for_account,
|
||||||
libdrcr_bridge::get_balance_sheet,
|
libdrcr_bridge::get_balance_sheet,
|
||||||
libdrcr_bridge::get_income_statement,
|
libdrcr_bridge::get_income_statement,
|
||||||
libdrcr_bridge::get_trial_balance,
|
libdrcr_bridge::get_trial_balance,
|
||||||
|
@ -73,7 +73,7 @@ async fn get_report(
|
|||||||
pub(crate) async fn get_all_transactions_except_earnings_to_equity(
|
pub(crate) async fn get_all_transactions_except_earnings_to_equity(
|
||||||
state: State<'_, Mutex<AppState>>,
|
state: State<'_, Mutex<AppState>>,
|
||||||
) -> Result<String, ()> {
|
) -> Result<String, ()> {
|
||||||
Ok(get_report(
|
let transactions = get_report(
|
||||||
state,
|
state,
|
||||||
&ReportingProductId {
|
&ReportingProductId {
|
||||||
name: "AllTransactionsExceptEarningsToEquity",
|
name: "AllTransactionsExceptEarningsToEquity",
|
||||||
@ -84,9 +84,40 @@ pub(crate) async fn get_all_transactions_except_earnings_to_equity(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.downcast_ref::<Transactions>()
|
.downcast::<Transactions>()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_json())
|
.transactions;
|
||||||
|
|
||||||
|
Ok(serde_json::to_string(&transactions).unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub(crate) async fn get_all_transactions_except_earnings_to_equity_for_account(
|
||||||
|
state: State<'_, Mutex<AppState>>,
|
||||||
|
account: String,
|
||||||
|
) -> Result<String, ()> {
|
||||||
|
let transactions = get_report(
|
||||||
|
state,
|
||||||
|
&ReportingProductId {
|
||||||
|
name: "AllTransactionsExceptEarningsToEquity",
|
||||||
|
kind: ReportingProductKind::Transactions,
|
||||||
|
args: Box::new(DateArgs {
|
||||||
|
date: NaiveDate::from_ymd_opt(9999, 12, 31).unwrap(),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.downcast::<Transactions>()
|
||||||
|
.unwrap()
|
||||||
|
.transactions;
|
||||||
|
|
||||||
|
// Filter only transactions affecting this account
|
||||||
|
let filtered_transactions = transactions
|
||||||
|
.into_iter()
|
||||||
|
.filter(|t| t.postings.iter().any(|p| p.account == account))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
Ok(serde_json::to_string(&filtered_transactions).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<!--
|
<!--
|
||||||
DrCr: Web-based double-entry bookkeeping framework
|
DrCr: Web-based double-entry bookkeeping framework
|
||||||
Copyright (C) 2022–2025 Lee Yingtong Li (RunasSudo)
|
Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo)
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Affero General Public License as published by
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
@ -38,15 +38,13 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { PlusIcon } from '@heroicons/vue/24/outline';
|
import { PlusIcon } from '@heroicons/vue/24/outline';
|
||||||
|
import { invoke } from '@tauri-apps/api/core';
|
||||||
import { UnlistenFn, listen } from '@tauri-apps/api/event';
|
import { UnlistenFn, listen } from '@tauri-apps/api/event';
|
||||||
|
|
||||||
import { onUnmounted, ref } from 'vue';
|
import { onUnmounted, ref } from 'vue';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
|
|
||||||
import { Transaction, db } from '../db.ts';
|
import { Transaction } from '../db.ts';
|
||||||
import { ReportingStage, ReportingWorkflow } from '../reporting.ts';
|
|
||||||
import TransactionsWithCommodityView from './TransactionsWithCommodityView.vue';
|
import TransactionsWithCommodityView from './TransactionsWithCommodityView.vue';
|
||||||
import TransactionsWithoutCommodityView from './TransactionsWithoutCommodityView.vue';
|
import TransactionsWithoutCommodityView from './TransactionsWithoutCommodityView.vue';
|
||||||
|
|
||||||
@ -56,24 +54,20 @@
|
|||||||
const transactions = ref([] as Transaction[]);
|
const transactions = ref([] as Transaction[]);
|
||||||
|
|
||||||
async function load() {
|
async function load() {
|
||||||
const session = await db.load();
|
const transactionsRaw = JSON.parse(await invoke(
|
||||||
const reportingWorkflow = new ReportingWorkflow();
|
'get_all_transactions_except_earnings_to_equity_for_account',
|
||||||
await reportingWorkflow.generate(session); // This also ensures running balances are up to date
|
{ account: route.params.account }
|
||||||
|
)) as Transaction[];
|
||||||
const transactionsRaw = reportingWorkflow.getTransactionsAtStage(ReportingStage.FINAL_STAGE);
|
|
||||||
|
|
||||||
// Filter only transactions affecting this account
|
|
||||||
const filteredTransactions = transactionsRaw.filter((t) => t.postings.some((p) => p.account === route.params.account));
|
|
||||||
|
|
||||||
// In order to correctly sort API transactions, we need to remember their indexes
|
// In order to correctly sort API transactions, we need to remember their indexes
|
||||||
const filteredTxnsWithIndexes = filteredTransactions.map((t, index) => [t, index] as [Transaction, number]);
|
const transactionsRawWithIndexes = transactionsRaw.map((t, index) => [t, index] as [Transaction, number]);
|
||||||
|
|
||||||
// Sort transactions in reverse chronological order
|
// Sort transactions in reverse chronological order
|
||||||
// We must sort here because they are returned by reportingWorkflow in order of ReportingStage
|
// We must sort here because they are returned by reportingWorkflow in order of ReportingStage
|
||||||
// Use Number.MAX_SAFE_INTEGER as ID for API transactions
|
// Use Number.MAX_SAFE_INTEGER as ID for API transactions
|
||||||
filteredTxnsWithIndexes.sort(([t1, i1], [t2, i2]) => (t2.dt.localeCompare(t1.dt)) || ((t2.id ?? Number.MAX_SAFE_INTEGER) - (t1.id ?? Number.MAX_SAFE_INTEGER) || (i2 - i1)));
|
transactionsRawWithIndexes.sort(([t1, i1], [t2, i2]) => (t2.dt.localeCompare(t1.dt)) || ((t2.id ?? Number.MAX_SAFE_INTEGER) - (t1.id ?? Number.MAX_SAFE_INTEGER) || (i2 - i1)));
|
||||||
|
|
||||||
transactions.value = filteredTxnsWithIndexes.map(([t, _idx]) => t);
|
transactions.value = transactionsRawWithIndexes.map(([t, _idx]) => t);
|
||||||
}
|
}
|
||||||
load();
|
load();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user