austax: Implement creating, editing, deleting CGT adjustments
This commit is contained in:
parent
bade02d780
commit
23beda32e6
@ -46,6 +46,8 @@ async function initApp() {
|
||||
{ path: '/trial-balance', name: 'trial-balance', component: () => import('./reports/TrialBalanceReport.vue') },
|
||||
// TODO: Generate this list dynamically
|
||||
{ path: '/austax/cgt-adjustments', name: 'cgt-adjustments', component: () => import('./plugins/austax/CGTAdjustmentsView.vue') },
|
||||
{ path: '/austax/cgt-adjustments/new', name: 'cgt-adjustments-new', component: () => import('./plugins/austax/NewCGTAdjustmentView.vue') },
|
||||
{ path: '/austax/cgt-adjustments/edit/:id', name: 'cgt-adjustments-edit', component: () => import('./plugins/austax/EditCGTAdjustmentView.vue') },
|
||||
{ path: '/austax/cgt-assets', name: 'cgt-assets', component: () => import('./plugins/austax/CGTAssetsView.vue') },
|
||||
{ path: '/austax/tax-summary', name: 'tax-summary', component: () => import('./plugins/austax/TaxSummaryReport.vue') },
|
||||
];
|
||||
|
127
src/plugins/austax/CGTAdjustmentEditor.vue
Normal file
127
src/plugins/austax/CGTAdjustmentEditor.vue
Normal file
@ -0,0 +1,127 @@
|
||||
<!--
|
||||
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>
|
||||
<div class="grid grid-cols-[max-content_1fr] space-y-2 mb-4 items-baseline">
|
||||
<h2 class="col-span-2 text-xl text-gray-900 font-semibold">CGT asset</h2>
|
||||
|
||||
<label for="acquisition_date" class="block text-gray-900 pr-4">Acquisition date</label>
|
||||
<div>
|
||||
<input type="date" class="bordered-field" name="acquisition_date" id="acquisition_date" v-model="adjustment.acquisition_dt">
|
||||
</div>
|
||||
<label for="account" class="block text-gray-900 pr-4">Account</label>
|
||||
<ComboBoxAccounts v-model="adjustment.account" />
|
||||
<label for="asset" class="block text-gray-900 pr-4">Asset</label>
|
||||
<div>
|
||||
<input type="text" class="bordered-field" name="asset" id="asset" placeholder=" " v-model="adjustment.asset">
|
||||
</div>
|
||||
|
||||
<h2 class="col-span-2 text-xl text-gray-900 font-semibold pt-4">CGT adjustment</h2>
|
||||
|
||||
<label for="dt" class="block text-gray-900 pr-4">Adjustment date</label>
|
||||
<div>
|
||||
<input type="date" class="bordered-field" name="dt" id="dt" v-model="adjustment.dt">
|
||||
</div>
|
||||
<label for="description" class="block text-gray-900 pr-4">Description</label>
|
||||
<div>
|
||||
<input type="text" class="bordered-field" name="description" id="description" placeholder=" " v-model="adjustment.description">
|
||||
</div>
|
||||
<label for="cost_adjustment" class="block text-gray-900 pr-4">Cost adjustment</label>
|
||||
<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>
|
||||
</div>
|
||||
<input type="number" class="bordered-field pl-7 pr-16" step="0.01" v-model="adjustment.cost_adjustment_abs" placeholder="0.00">
|
||||
<div class="absolute inset-y-0 right-0 flex items-center">
|
||||
<select class="h-full border-0 bg-transparent py-0 pl-2 pr-8 text-gray-900 focus:ring-2 focus:ring-inset focus:ring-indigo-600" v-model="adjustment.sign">
|
||||
<option value="dr">Dr</option>
|
||||
<option value="cr">Cr</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end mt-4 space-x-2">
|
||||
<button class="btn-secondary text-red-600 ring-red-500" @click="deleteAdjustment" v-if="adjustment.id !== null">Delete</button>
|
||||
<button class="btn-primary" @click="saveAdjustment">Save</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import dayjs from 'dayjs';
|
||||
import { getCurrentWindow } from '@tauri-apps/api/window';
|
||||
|
||||
import ComboBoxAccounts from '../../components/ComboBoxAccounts.vue';
|
||||
import { DT_FORMAT, db, deserialiseAmount } from '../../db.ts';
|
||||
|
||||
export interface EditingCGTAdjustment {
|
||||
id: number | null,
|
||||
asset: string,
|
||||
account: string,
|
||||
acquisition_dt: string,
|
||||
dt: string,
|
||||
description: string,
|
||||
sign: string,
|
||||
cost_adjustment_abs: string,
|
||||
}
|
||||
|
||||
const { adjustment } = defineProps<{ adjustment: EditingCGTAdjustment }>();
|
||||
|
||||
async function saveAdjustment() {
|
||||
// Save changes to the CGT adjustment
|
||||
const asset = deserialiseAmount('' + adjustment.asset);
|
||||
const cost_adjustment_abs = deserialiseAmount('' + adjustment.cost_adjustment_abs);
|
||||
const cost_adjustment = adjustment.sign === 'dr' ? cost_adjustment_abs.quantity : -cost_adjustment_abs.quantity;
|
||||
|
||||
const session = await db.load();
|
||||
|
||||
if (adjustment.id === null) {
|
||||
await session.execute(
|
||||
`INSERT INTO austax_cgt_cost_adjustments (quantity, commodity, account, acquisition_dt, dt, description, cost_adjustment)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)`,
|
||||
[asset.quantity, asset.commodity, adjustment.account, dayjs(adjustment.acquisition_dt).format(DT_FORMAT), dayjs(adjustment.dt).format(DT_FORMAT), adjustment.description, cost_adjustment]
|
||||
);
|
||||
} else {
|
||||
await session.execute(
|
||||
`UPDATE austax_cgt_cost_adjustments
|
||||
SET quantity = $1, commodity = $2, account = $3, acquisition_dt = $4, dt = $5, description = $6, cost_adjustment = $7
|
||||
WHERE id = $8`,
|
||||
[asset.quantity, asset.commodity, adjustment.account, dayjs(adjustment.acquisition_dt).format(DT_FORMAT), dayjs(adjustment.dt).format(DT_FORMAT), adjustment.description, cost_adjustment, adjustment.id]
|
||||
);
|
||||
}
|
||||
|
||||
await getCurrentWindow().close();
|
||||
}
|
||||
|
||||
async function deleteAdjustment() {
|
||||
// Delete the current CGT adjustment
|
||||
if (!await confirm('Are you sure you want to delete this CGT adjustment? This operation is irreversible.')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const session = await db.load();
|
||||
|
||||
await session.execute(
|
||||
`DELETE FROM austax_cgt_cost_adjustments
|
||||
WHERE id = $1`,
|
||||
[adjustment.id]
|
||||
);
|
||||
|
||||
await getCurrentWindow().close();
|
||||
}
|
||||
</script>
|
@ -22,10 +22,10 @@
|
||||
</h1>
|
||||
|
||||
<div class="my-4 flex gap-x-2">
|
||||
<!--<a :href="$router.resolve({name: 'cgt-adjustments-new'}).fullPath" class="btn-primary pl-2" onclick="return openLinkInNewWindow(this);">
|
||||
<a :href="$router.resolve({name: 'cgt-adjustments-new'}).fullPath" class="btn-primary pl-2" onclick="return openLinkInNewWindow(this);">
|
||||
<PlusIcon class="w-4 h-4" />
|
||||
New CGT adjustment
|
||||
</a>-->
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<table class="min-w-full">
|
||||
@ -53,11 +53,9 @@
|
||||
<td class="py-0.5 px-1 text-gray-900">{{ cgt_adjustment.description }}</td>
|
||||
<td class="py-0.5 px-1 text-gray-900 text-end" v-html="ppBracketed(cgt_adjustment.cost_adjustment)"></td>
|
||||
<td class="py-0.5 pl-1 text-end">
|
||||
<!--<a href="#" class="text-gray-500 hover:text-gray-700">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4 inline align-middle -mt-0.5">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L6.832 19.82a4.5 4.5 0 0 1-1.897 1.13l-2.685.8.8-2.685a4.5 4.5 0 0 1 1.13-1.897L16.863 4.487Zm0 0L19.5 7.125" />
|
||||
</svg>
|
||||
</a>-->
|
||||
<a :href="$router.resolve({name: 'cgt-adjustments-edit', params: {id: cgt_adjustment.id}}).fullPath" class="text-gray-500 hover:text-gray-700" onclick="return openLinkInNewWindow(this);">
|
||||
<PencilIcon class="w-4 h-4" />
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@ -66,6 +64,8 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import dayjs from 'dayjs';
|
||||
import { PencilIcon } from '@heroicons/vue/24/outline';
|
||||
import { PlusIcon } from '@heroicons/vue/16/solid';
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { CGTAdjustment, cgtAssetCommodityName } from './cgt.ts';
|
||||
|
70
src/plugins/austax/EditCGTAdjustmentView.vue
Normal file
70
src/plugins/austax/EditCGTAdjustmentView.vue
Normal file
@ -0,0 +1,70 @@
|
||||
<!--
|
||||
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">
|
||||
Edit CGT adjustment
|
||||
</h1>
|
||||
|
||||
<CGTAdjustmentEditor :adjustment="adjustment" />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import dayjs from 'dayjs';
|
||||
import { ref } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
|
||||
import CGTAdjustmentEditor, { EditingCGTAdjustment } from './CGTAdjustmentEditor.vue';
|
||||
import { db, serialiseAmount } from '../../db.ts';
|
||||
|
||||
const route = useRoute();
|
||||
|
||||
const adjustment = ref({
|
||||
id: null,
|
||||
asset: null!,
|
||||
account: null!,
|
||||
acquisition_dt: null!,
|
||||
dt: null!,
|
||||
description: null!,
|
||||
sign: null!,
|
||||
cost_adjustment_abs: null!,
|
||||
} as EditingCGTAdjustment);
|
||||
|
||||
async function load() {
|
||||
const session = await db.load();
|
||||
|
||||
const rawAdjustments: any[] = await session.select(
|
||||
`SELECT id, quantity, commodity, account, acquisition_dt, dt, description, cost_adjustment
|
||||
FROM austax_cgt_cost_adjustments
|
||||
WHERE id = $1`,
|
||||
[route.params.id]
|
||||
);
|
||||
const rawAdjustment = rawAdjustments[0];
|
||||
|
||||
// Format parameters for display
|
||||
rawAdjustment.asset = serialiseAmount(rawAdjustment.quantity, rawAdjustment.commodity);
|
||||
rawAdjustment.acquisition_dt = dayjs(rawAdjustment.acquisition_dt).format('YYYY-MM-DD');
|
||||
rawAdjustment.dt = dayjs(rawAdjustment.dt).format('YYYY-MM-DD');
|
||||
rawAdjustment.sign = rawAdjustment.cost_adjustment >= 0 ? 'dr' : 'cr';
|
||||
rawAdjustment.cost_adjustment_abs = serialiseAmount(Math.abs(rawAdjustment.cost_adjustment), db.metadata.reporting_commodity);
|
||||
|
||||
adjustment.value = rawAdjustment as EditingCGTAdjustment;
|
||||
}
|
||||
|
||||
load();
|
||||
</script>
|
43
src/plugins/austax/NewCGTAdjustmentView.vue
Normal file
43
src/plugins/austax/NewCGTAdjustmentView.vue
Normal file
@ -0,0 +1,43 @@
|
||||
<!--
|
||||
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 CGT adjustment
|
||||
</h1>
|
||||
|
||||
<CGTAdjustmentEditor :adjustment="adjustment" />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import dayjs from 'dayjs';
|
||||
import { ref } from 'vue';
|
||||
|
||||
import CGTAdjustmentEditor, { EditingCGTAdjustment } from './CGTAdjustmentEditor.vue';
|
||||
|
||||
const adjustment = ref({
|
||||
id: null,
|
||||
asset: '',
|
||||
account: '',
|
||||
acquisition_dt: dayjs().format('YYYY-MM-DD'),
|
||||
dt: dayjs().format('YYYY-MM-DD'),
|
||||
description: '',
|
||||
sign: 'dr',
|
||||
cost_adjustment_abs: '',
|
||||
} as EditingCGTAdjustment);
|
||||
</script>
|
Loading…
x
Reference in New Issue
Block a user