Compare commits

...

3 Commits

10 changed files with 145 additions and 18 deletions

View File

@ -14,6 +14,8 @@
-- You should have received a copy of the GNU Affero General Public License
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
-- Current version: 3 (see db.ts)
---------
-- Tables
@ -93,7 +95,7 @@ CREATE TABLE austax_cgt_cost_adjustments (
description VARCHAR,
cost_adjustment INTEGER,
PRIMARY KEY (id)
)
);
--------
-- Views

View File

@ -67,6 +67,7 @@ pub fn run() {
let store = app.store("store.json")?;
let db_filename = match store.get("db_filename") {
None => None,
Some(serde_json::Value::Null) => None,
Some(serde_json::Value::String(s)) => {
if fs::exists(&s)? {
Some(s)
@ -74,7 +75,7 @@ pub fn run() {
None
}
}
_ => panic!("Unexpected db_filename in store"),
_ => panic!("Unexpected db_filename in store: {:?}", store.get("db_filename")),
};
app.manage(Mutex::new(AppState {

View File

@ -28,7 +28,8 @@
"icons/icon.png"
],
"resources": {
"../libdrcr/plugins/": "plugins/"
"../libdrcr/plugins/": "plugins/",
"../schema.sql": "schema.sql"
}
}
}

View File

@ -1,6 +1,6 @@
<!--
DrCr: Web-based double-entry bookkeeping framework
Copyright (C) 20222024 Lee Yingtong Li (RunasSudo)
Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo)
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
@ -22,8 +22,8 @@
<div class="py-8">
<main>
<div class="mx-auto max-w-7xl px-6 lg:px-8">
<NoFileView v-if="db.filename === null" />
<RouterView v-if="db.filename !== null" />
<NoFileView v-if="!(db.filename !== null || route.name === 'new-file')" />
<RouterView v-if="db.filename !== null || route.name === 'new-file'" />
</div>
</main>
</div>
@ -31,8 +31,11 @@
</template>
<script setup lang="ts">
import { useRoute } from 'vue-router';
import HeaderBar from './components/HeaderBar.vue';
import { db } from './db.js';
import NoFileView from './pages/NoFileView.vue';
import { db } from './db.js';
const route = useRoute();
</script>

View File

@ -18,8 +18,8 @@
<template>
<div class="relative">
<!-- WebKit bug: Does not align baseline correctly unless some text or placeholder is present -->
<input type="text" class="bordered-field peer" :class="inputClass" id="account" v-model="selectedValue" placeholder=" " autocomplete="off" ref="inputField">
<!-- WebKit bug https://bugs.webkit.org/show_bug.cgi?id=142968: Does not align baseline correctly unless some text or placeholder is present -->
<input type="text" class="bordered-field peer pr-7" :class="inputClass" id="account" v-model="selectedValue" placeholder=" " autocomplete="off" ref="inputField">
<button type="button" class="absolute inset-y-0 right-0 flex items-center px-2 focus:outline-none" @click="inputField!.focus()">
<ChevronUpDownIcon class="h-5 w-5 text-gray-400" />
</button>
@ -33,9 +33,7 @@
>
<span class="block truncate group-data-[selected=selected]:font-semibold">{{ value }}</span>
<span class="hidden group-data-[selected=selected]:flex absolute inset-y-0 right-0 items-center pr-4 text-emerald-600 group-hover:text-white">
<svg class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z" clip-rule="evenodd" />
</svg>
<CheckIcon class="w-5 h-5" />
</span>
</li>
</ul>
@ -43,6 +41,7 @@
</template>
<script setup lang="ts">
import { CheckIcon } from '@heroicons/vue/20/solid';
import { ChevronUpDownIcon } from '@heroicons/vue/24/outline';
import { useTemplateRef } from 'vue';

View File

@ -49,7 +49,7 @@
<option value="cr">Cr</option>
</select>
</div>
<ComboBoxAccounts v-model="posting.account" class="w-full" inputClass="pl-16" />
<ComboBoxAccounts v-model="posting.account" class="w-full" inputClass="pl-14" />
</div>
<button class="relative -ml-px px-2 py-2 text-gray-500 hover:text-gray-700" @click="addPosting(posting)">
<PlusIcon class="w-4 h-4" />
@ -57,7 +57,7 @@
</div>
</td>
<template v-if="posting.sign == 'dr'">
<td class="amount-dr has-amount py-1 px-1">
<td class="amount-dr has-amount py-1 px-1 w-[8rem]">
<div class="relative shadow-sm">
<div class="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3">
<span class="text-gray-500">{{ db.metadata.reporting_commodity }}</span>
@ -69,7 +69,7 @@
</template>
<template v-if="posting.sign == 'cr'">
<td class="amount-dr py-1 px-1"></td>
<td class="amount-cr has-amount py-1 pl-1">
<td class="amount-cr has-amount py-1 pl-1 w-[8rem]">
<div class="relative shadow-sm">
<div class="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3">
<span class="text-gray-500">{{ db.metadata.reporting_commodity }}</span>

View File

@ -17,14 +17,16 @@
*/
import { invoke } from '@tauri-apps/api/core';
import { resolveResource } from '@tauri-apps/api/path';
import { getCurrentWindow } from '@tauri-apps/api/window';
import { readTextFile } from '@tauri-apps/plugin-fs';
import Database from '@tauri-apps/plugin-sql';
import { reactive } from 'vue';
import { Balance } from './amounts.ts';
import { ExtendedDatabase } from './dbutil.ts';
export const DB_VERSION = 3; // Should match schema.sql
export const DT_FORMAT = 'YYYY-MM-DD HH:mm:ss.SSS000';
export const db = reactive({
@ -60,6 +62,8 @@ export const db = reactive({
this.metadata.reporting_commodity = metadataObject.reporting_commodity;
this.metadata.dps = parseInt(metadataObject.amount_dps);
}
// TODO: Validate database version
},
load: async function(): Promise<ExtendedDatabase> {
@ -67,6 +71,39 @@ export const db = reactive({
},
});
export async function createNewDatabase(filename: string, eofy_date: string, reporting_commodity: string, dps: number) {
// Open new SQLite database
const session = new ExtendedDatabase(await Database.load('sqlite:' + filename));
// Read SQL schema
const schemaPath = await resolveResource('schema.sql');
const schemaSql = await readTextFile(schemaPath);
// Execute SQL
const transaction = await session.begin();
await transaction.execute(schemaSql);
// Init metadata
await transaction.execute(
`INSERT INTO metadata (key, value) VALUES (?, ?)`,
['version', DB_VERSION.toString()] // Manually call .toString() to format as int, otherwise sqlx formats as float
);
await transaction.execute(
`INSERT INTO metadata (key, value) VALUES (?, ?)`,
['eofy_date', eofy_date]
);
await transaction.execute(
`INSERT INTO metadata (key, value) VALUES (?, ?)`,
['reporting_commodity', reporting_commodity]
);
await transaction.execute(
`INSERT INTO metadata (key, value) VALUES (?, ?)`,
['amount_dps', dps.toString()] // Manually call .toString() to format as int, otherwise sqlx formats as float
);
await transaction.commit();
}
export function joinedToTransactions(joinedTransactionPostings: JoinedTransactionPosting[]): Transaction[] {
// Group postings into transactions
const transactions: Transaction[] = [];

View File

@ -40,6 +40,7 @@ async function initApp() {
{ path: '/journal', name: 'journal', component: () => import('./pages/JournalView.vue') },
{ path: '/journal/edit/:id', name: 'journal-edit-transaction', component: () => import('./pages/EditTransactionView.vue') },
{ path: '/journal/new', name: 'journal-new-transaction', component: () => import('./pages/NewTransactionView.vue') },
{ path: '/new-file', name: 'new-file', component: () => import('./pages/NewFileView.vue') },
{ path: '/statement-lines', name: 'statement-lines', component: () => import('./pages/StatementLinesView.vue') },
{ path: '/statement-lines/import', name: 'import-statement', component: () => import('./pages/ImportStatementView.vue') },
{ path: '/transactions/:account', name: 'transactions', component: () => import('./pages/TransactionsView.vue') },

80
src/pages/NewFileView.vue Normal file
View File

@ -0,0 +1,80 @@
<!--
DrCr: Web-based double-entry bookkeeping framework
Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo)
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<template>
<h1 class="page-heading mb-4">
New file
</h1>
<div class="grid grid-cols-[max-content_1fr] space-y-2 mb-4 items-baseline">
<label for="eofy_date" class="block text-gray-900 pr-4">End of financial year</label>
<div>
<input type="date" class="bordered-field" id="eofy_date" v-model="eofy_date">
</div>
<label for="reporting_commodity" class="block text-gray-900 pr-4">Reporting currency</label>
<div>
<input type="text" class="bordered-field text-gray-500" id="reporting_commodity" v-model="reporting_commodity" disabled>
</div>
<label for="amount_dps" class="block text-gray-900 pr-4">Decimal places</label>
<div>
<input type="number" class="bordered-field text-gray-500" id="amount_dps" v-model="amount_dps" disabled>
</div>
</div>
<div class="flex justify-end mt-4 space-x-2">
<button class="btn-primary" @click="createNewFile">OK</button>
</div>
</template>
<script setup type="ts">
import dayjs from 'dayjs';
import { save } from '@tauri-apps/plugin-dialog';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { createNewDatabase, db } from '../db.ts';
// Get initial EOFY date
let eofy_dayjs = dayjs().set('month', 5).set('date', 30);
if (eofy_dayjs.isBefore(dayjs())) {
eofy_dayjs.set('year', eofy_dayjs.year() + 1);
}
const eofy_date = ref(eofy_dayjs.format('YYYY-MM-DD'));
const reporting_commodity = ref('$');
const amount_dps = ref(2);
const router = useRouter();
async function createNewFile() {
const file = await save({
filters: [
{ name: 'DrCr database (SQLite)', extensions: ['db'] }
],
});
if (file !== null) {
// Create new database
await createNewDatabase(file, dayjs(eofy_date.value).format('YYYY-MM-DD'), reporting_commodity.value, amount_dps.value);
// Load the database
await db.init(file);
router.push({ name: 'index' });
}
}
</script>

View File

@ -1,6 +1,6 @@
<!--
DrCr: Web-based double-entry bookkeeping framework
Copyright (C) 20222024 Lee Yingtong Li (RunasSudo)
Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo)
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
@ -19,7 +19,7 @@
<template>
<p class="text-gray-900 mb-4">Welcome to DrCr. No file is currently open.</p>
<ul class="list-disc ml-6">
<!--<li><a href="#" class="text-gray-900 hover:text-blue-700 hover:underline">New file</a></li>-->
<li><RouterLink :to="{name: 'new-file'}" class="text-gray-900 hover:text-blue-700 hover:underline">New file</RouterLink></li>
<li><a href="#" @click="openFile" class="text-gray-900 hover:text-blue-700 hover:underline">Open file</a></li>
</ul>
</template>
@ -33,6 +33,9 @@
const file = await open({
multiple: false,
directory: false,
filters: [
{ name: 'DrCr database (SQLite)', extensions: ['db'] }
],
});
if (file !== null) {