Look up eofy_date in libdrcr_bridge itself

This commit is contained in:
RunasSudo 2025-05-27 00:54:22 +10:00
parent 807316a090
commit 42ba33c45c
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
3 changed files with 12 additions and 28 deletions

View File

@ -35,7 +35,6 @@ use crate::AppState;
#[tauri::command] #[tauri::command]
pub(crate) async fn get_balance_sheet( pub(crate) async fn get_balance_sheet(
state: State<'_, Mutex<AppState>>, state: State<'_, Mutex<AppState>>,
eofy_date: String,
dates: Vec<String>, dates: Vec<String>,
) -> Result<String, ()> { ) -> Result<String, ()> {
let state = state.lock().await; let state = state.lock().await;
@ -47,11 +46,8 @@ pub(crate) async fn get_balance_sheet(
DbConnection::connect(format!("sqlite:{}", db_filename.as_str()).as_str()); DbConnection::connect(format!("sqlite:{}", db_filename.as_str()).as_str());
// Initialise ReportingContext // Initialise ReportingContext
let mut context = ReportingContext::new( let eofy_date = db_connection.metadata().eofy_date;
db_connection, let mut context = ReportingContext::new(db_connection, eofy_date, "$".to_string());
NaiveDate::parse_from_str(eofy_date.as_str(), "%Y-%m-%d").unwrap(),
"$".to_string(),
);
register_lookup_fns(&mut context); register_lookup_fns(&mut context);
register_dynamic_builders(&mut context); register_dynamic_builders(&mut context);
@ -98,7 +94,6 @@ pub(crate) async fn get_balance_sheet(
#[tauri::command] #[tauri::command]
pub(crate) async fn get_income_statement( pub(crate) async fn get_income_statement(
state: State<'_, Mutex<AppState>>, state: State<'_, Mutex<AppState>>,
eofy_date: String,
dates: Vec<(String, String)>, dates: Vec<(String, String)>,
) -> Result<String, ()> { ) -> Result<String, ()> {
let state = state.lock().await; let state = state.lock().await;
@ -110,11 +105,8 @@ pub(crate) async fn get_income_statement(
DbConnection::connect(format!("sqlite:{}", db_filename.as_str()).as_str()); DbConnection::connect(format!("sqlite:{}", db_filename.as_str()).as_str());
// Initialise ReportingContext // Initialise ReportingContext
let mut context = ReportingContext::new( let eofy_date = db_connection.metadata().eofy_date;
db_connection, let mut context = ReportingContext::new(db_connection, eofy_date, "$".to_string());
NaiveDate::parse_from_str(eofy_date.as_str(), "%Y-%m-%d").unwrap(),
"$".to_string(),
);
register_lookup_fns(&mut context); register_lookup_fns(&mut context);
register_dynamic_builders(&mut context); register_dynamic_builders(&mut context);

View File

@ -56,7 +56,6 @@
import { DynamicReport, reportEntryById } from './base.ts'; import { DynamicReport, reportEntryById } from './base.ts';
import { db } from '../db.ts'; import { db } from '../db.ts';
import { ExtendedDatabase } from '../dbutil.ts';
import DynamicReportComponent from '../components/DynamicReportComponent.vue'; import DynamicReportComponent from '../components/DynamicReportComponent.vue';
const report = ref(null as DynamicReport | null); const report = ref(null as DynamicReport | null);
@ -70,18 +69,15 @@
dt.value = db.metadata.eofy_date; dt.value = db.metadata.eofy_date;
await updateReport(session); await updateReport();
// Update report when dates etc. changed // Update report when dates etc. changed
// We initialise the watcher here only after dt is initialised above // We initialise the watcher here only after dt is initialised above
watch([dt, comparePeriods, compareUnit], async () => { watch([dt, comparePeriods, compareUnit], updateReport);
const session = await db.load();
await updateReport(session);
});
} }
load(); load();
async function updateReport(session: ExtendedDatabase) { async function updateReport() {
const reportDates = []; const reportDates = [];
for (let i = 0; i < comparePeriods.value; i++) { for (let i = 0; i < comparePeriods.value; i++) {
let thisReportDt; let thisReportDt;
@ -103,7 +99,7 @@
reportDates.push(thisReportDt.format('YYYY-MM-DD')); reportDates.push(thisReportDt.format('YYYY-MM-DD'));
} }
report.value = JSON.parse(await invoke('get_balance_sheet', { eofyDate: db.metadata.eofy_date, dates: reportDates })); report.value = JSON.parse(await invoke('get_balance_sheet', { dates: reportDates }));
} }
const doesBalance = computed(function() { const doesBalance = computed(function() {

View File

@ -45,7 +45,6 @@
import { DynamicReport } from './base.ts'; import { DynamicReport } from './base.ts';
import { db } from '../db.ts'; import { db } from '../db.ts';
import { ExtendedDatabase } from '../dbutil.ts';
import DynamicReportComponent from '../components/DynamicReportComponent.vue'; import DynamicReportComponent from '../components/DynamicReportComponent.vue';
const report = ref(null as DynamicReport | null); const report = ref(null as DynamicReport | null);
@ -62,17 +61,14 @@
dt.value = db.metadata.eofy_date; dt.value = db.metadata.eofy_date;
dtStart.value = dayjs(db.metadata.eofy_date).subtract(1, 'year').add(1, 'day').format('YYYY-MM-DD'); dtStart.value = dayjs(db.metadata.eofy_date).subtract(1, 'year').add(1, 'day').format('YYYY-MM-DD');
await updateReport(session); await updateReport();
// Update report when dates etc. changed // Update report when dates etc. changed
// We initialise the watcher here only after dt and dtStart are initialised above // We initialise the watcher here only after dt and dtStart are initialised above
watch([dt, dtStart, comparePeriods, compareUnit], async () => { watch([dt, dtStart, comparePeriods, compareUnit], updateReport);
const session = await db.load();
await updateReport(session);
});
} }
async function updateReport(session: ExtendedDatabase) { async function updateReport() {
const reportDates = []; const reportDates = [];
for (let i = 0; i < comparePeriods.value; i++) { for (let i = 0; i < comparePeriods.value; i++) {
let thisReportDt, thisReportDtStart; let thisReportDt, thisReportDtStart;
@ -97,7 +93,7 @@
reportDates.push([thisReportDtStart.format('YYYY-MM-DD'), thisReportDt.format('YYYY-MM-DD')]); reportDates.push([thisReportDtStart.format('YYYY-MM-DD'), thisReportDt.format('YYYY-MM-DD')]);
} }
report.value = JSON.parse(await invoke('get_income_statement', { eofyDate: db.metadata.eofy_date, dates: reportDates })); report.value = JSON.parse(await invoke('get_income_statement', { dates: reportDates }));
} }
load(); load();