Show API-generated accounts in chart of accounts view
This commit is contained in:
parent
bed32b0d54
commit
449ce80e35
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
DrCr: Web-based double-entry bookkeeping framework
|
DrCr: 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
|
||||||
@ -1519,7 +1519,7 @@ impl ReportingStep for TrialBalance {
|
|||||||
// Add entry for each account
|
// Add entry for each account
|
||||||
let mut section = Section {
|
let mut section = Section {
|
||||||
text: None,
|
text: None,
|
||||||
id: None,
|
id: Some("accounts".to_string()),
|
||||||
visible: true,
|
visible: true,
|
||||||
entries: Vec::new(),
|
entries: Vec::new(),
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
DrCr: Web-based double-entry bookkeeping framework
|
DrCr: 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
|
||||||
@ -57,11 +57,13 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { invoke } from '@tauri-apps/api/core';
|
||||||
import { computed, ref } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
|
|
||||||
import { drcrAccountKinds, getAccountKinds } from '../registry.ts';
|
import { drcrAccountKinds, getAccountKinds } from '../registry.ts';
|
||||||
import { db } from '../db.ts';
|
import { db } from '../db.ts';
|
||||||
import DropdownBox from '../components/DropdownBox.vue';
|
import DropdownBox from '../components/DropdownBox.vue';
|
||||||
|
import { DynamicReport, reportEntryById, Row, Section } from '../reports/base.ts';
|
||||||
|
|
||||||
const accountKinds = ref([...drcrAccountKinds]);
|
const accountKinds = ref([...drcrAccountKinds]);
|
||||||
const accountKindsMap = computed(() => new Map(accountKinds.value));
|
const accountKindsMap = computed(() => new Map(accountKinds.value));
|
||||||
@ -74,19 +76,26 @@
|
|||||||
async function loadAccountConfigurations() {
|
async function loadAccountConfigurations() {
|
||||||
const session = await db.load();
|
const session = await db.load();
|
||||||
|
|
||||||
const accountKindsRaw: {account: string, kind: string | null}[] = await session.select(
|
// Get all accounts on the trial balance
|
||||||
`SELECT q1.account, q2.kind FROM
|
const trialBalance = JSON.parse(await invoke('get_trial_balance', { date: '9999-12-31' })) as DynamicReport;
|
||||||
(SELECT account FROM account_configurations UNION SELECT account FROM postings ORDER BY account) q1
|
const trialBalanceAccounts = (reportEntryById(trialBalance, 'accounts') as { Section: Section }).Section.entries.map((e) => (e as { Row: Row }).Row.text);
|
||||||
LEFT JOIN account_configurations q2 ON q1.account = q2.account`
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const accountKindRaw of accountKindsRaw) {
|
// Get all configured account kinds
|
||||||
const kinds = accounts.value.get(accountKindRaw.account) ?? [];
|
const accountKindsRaw: {account: string, kind: string}[] = await session.select(
|
||||||
if (accountKindRaw.kind !== null) {
|
`SELECT account, kind FROM account_configurations`
|
||||||
kinds.push(accountKindRaw.kind);
|
);
|
||||||
}
|
const accountKindsMap = Map.groupBy(accountKindsRaw, (a) => a.account);
|
||||||
accounts.value.set(accountKindRaw.account, kinds);
|
|
||||||
|
// Include all accounts on the trial balance or which have configurations
|
||||||
|
const combinedAccountNames = [...new Set([...trialBalanceAccounts, ...accountKindsMap.keys()])];
|
||||||
|
combinedAccountNames.sort();
|
||||||
|
|
||||||
|
const accountKinds = new Map();
|
||||||
|
for (const accountName of combinedAccountNames) {
|
||||||
|
accountKinds.set(accountName, accountKindsMap.get(accountName)?.map((a) => a.kind) ?? []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
accounts.value = accountKinds;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadAccountKinds() {
|
async function loadAccountKinds() {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
DrCr: Web-based double-entry bookkeeping framework
|
DrCr: 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
|
||||||
@ -51,6 +51,9 @@ export interface Spacer {
|
|||||||
export function reportEntryById(report: DynamicReport | Section, id: string): DynamicReportEntry | null {
|
export function reportEntryById(report: DynamicReport | Section, id: string): DynamicReportEntry | null {
|
||||||
for (const entry of report.entries) {
|
for (const entry of report.entries) {
|
||||||
if ((entry as { Section: Section }).Section) {
|
if ((entry as { Section: Section }).Section) {
|
||||||
|
if ((entry as { Section: Section }).Section.id === id) {
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
const result = reportEntryById((entry as { Section: Section }).Section, id);
|
const result = reportEntryById((entry as { Section: Section }).Section, id);
|
||||||
if (result !== null) {
|
if (result !== null) {
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user