Refactor DynamicReport to TypeScript class
This commit is contained in:
parent
b445bfbca7
commit
50ef94dfee
@ -63,7 +63,7 @@
|
||||
import { drcrAccountKinds, getAccountKinds } from '../registry.ts';
|
||||
import { db } from '../db.ts';
|
||||
import DropdownBox from '../components/DropdownBox.vue';
|
||||
import { DynamicReport, reportEntryById, Row, Section } from '../reports/base.ts';
|
||||
import { DynamicReport, Row, Section } from '../reports/base.ts';
|
||||
|
||||
const accountKinds = ref([...drcrAccountKinds]);
|
||||
const accountKindsMap = computed(() => new Map(accountKinds.value));
|
||||
@ -77,8 +77,8 @@
|
||||
const session = await db.load();
|
||||
|
||||
// Get all accounts on the trial balance
|
||||
const trialBalance = JSON.parse(await invoke('get_trial_balance', { date: '9999-12-31' })) as DynamicReport;
|
||||
const trialBalanceAccounts = (reportEntryById(trialBalance, 'accounts') as { Section: Section }).Section.entries.map((e) => (e as { Row: Row }).Row.text);
|
||||
const trialBalance = DynamicReport.fromJSON(await invoke('get_trial_balance', { date: '9999-12-31' })) as DynamicReport;
|
||||
const trialBalanceAccounts = (trialBalance.byId('accounts') as { Section: Section }).Section.entries.map((e) => (e as { Row: Row }).Row.text);
|
||||
|
||||
// Get all configured account kinds
|
||||
const accountKindsRaw: {account: string, kind: string}[] = await session.select(
|
||||
|
@ -37,7 +37,7 @@
|
||||
const report = ref(null as DynamicReport | null);
|
||||
|
||||
async function load() {
|
||||
report.value = JSON.parse(await invoke('get_tax_summary'));
|
||||
report.value = DynamicReport.fromJSON(await invoke('get_tax_summary'));
|
||||
}
|
||||
load();
|
||||
</script>
|
||||
|
@ -55,7 +55,7 @@
|
||||
|
||||
import { ExclamationCircleIcon } from '@heroicons/vue/20/solid';
|
||||
|
||||
import { DynamicReport, Row, reportEntryById } from './base.ts';
|
||||
import { DynamicReport, Row } from './base.ts';
|
||||
import { db } from '../db.ts';
|
||||
import DynamicReportComponent from '../components/DynamicReportComponent.vue';
|
||||
import DynamicReportMenu from '../components/DynamicReportMenu.vue';
|
||||
@ -111,7 +111,7 @@
|
||||
newReportColumns = ['$'];
|
||||
}
|
||||
|
||||
report.value = JSON.parse(await invoke('get_balance_sheet', { dates: reportDates }));
|
||||
report.value = DynamicReport.fromJSON(await invoke('get_balance_sheet', { dates: reportDates }));
|
||||
reportColumns.value = newReportColumns; // Wait until report available to update this
|
||||
}
|
||||
|
||||
@ -120,9 +120,9 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
const totalAssets = (reportEntryById(report.value, 'total_assets') as { Row: Row }).Row.quantity;
|
||||
const totalLiabilities = (reportEntryById(report.value, 'total_liabilities') as { Row: Row }).Row.quantity;
|
||||
const totalEquity = (reportEntryById(report.value, 'total_equity') as { Row: Row }).Row.quantity;
|
||||
const totalAssets = (report.value.byId('total_assets') as { Row: Row }).Row.quantity;
|
||||
const totalLiabilities = (report.value.byId('total_liabilities') as { Row: Row }).Row.quantity;
|
||||
const totalEquity = (report.value.byId('total_equity') as { Row: Row }).Row.quantity;
|
||||
|
||||
let doesBalance = true;
|
||||
for (let column = 0; column < report.value.columns.length; column++) {
|
||||
|
@ -106,7 +106,7 @@
|
||||
newReportColumns = ['$'];
|
||||
}
|
||||
|
||||
report.value = JSON.parse(await invoke('get_income_statement', { dates: reportDates }));
|
||||
report.value = DynamicReport.fromJSON(await invoke('get_income_statement', { dates: reportDates }));
|
||||
reportColumns.value = newReportColumns; // Wait until report available to update this
|
||||
}
|
||||
|
||||
|
@ -55,6 +55,6 @@
|
||||
|
||||
async function updateReport() {
|
||||
const reportDate = dayjs(dt.value!).format('YYYY-MM-DD');
|
||||
report.value = JSON.parse(await invoke('get_trial_balance', { date: reportDate }));
|
||||
report.value = DynamicReport.fromJSON(await invoke('get_trial_balance', { date: reportDate }));
|
||||
}
|
||||
</script>
|
||||
|
@ -16,11 +16,18 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Cannot be a class as these are directly deserialised from JSON
|
||||
export interface DynamicReport {
|
||||
title: string;
|
||||
columns: string[];
|
||||
entries: DynamicReportEntry[];
|
||||
export class DynamicReport {
|
||||
title!: string;
|
||||
columns!: string[];
|
||||
entries!: DynamicReportEntry[];
|
||||
|
||||
static fromJSON(json: string): DynamicReport {
|
||||
return Object.assign(new DynamicReport(), JSON.parse(json));
|
||||
}
|
||||
|
||||
byId(id: string): DynamicReportEntry | null {
|
||||
return reportEntryById(this, id);
|
||||
}
|
||||
}
|
||||
|
||||
// serde_json serialises an enum like this
|
||||
|
Loading…
x
Reference in New Issue
Block a user