Correctly display API-generated transactions when quantity_ascost not set
This commit is contained in:
parent
60fcc51d4f
commit
a66f90e0c9
11
src/db.ts
11
src/db.ts
@ -326,6 +326,17 @@ export interface JoinedTransactionPosting {
|
|||||||
running_balance?: number
|
running_balance?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function postingQuantityAsCost(posting: Posting | JoinedTransactionPosting) {
|
||||||
|
// Convert the posting amount to cost price in the reporting commodity
|
||||||
|
|
||||||
|
if (posting.quantity_ascost) {
|
||||||
|
return posting.quantity_ascost;
|
||||||
|
} else {
|
||||||
|
// NB: This branch is rarely taken - most conversions are performed in SQL via the transactions_with_quantity_ascost view
|
||||||
|
return asCost(posting.quantity, posting.commodity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export interface StatementLine {
|
export interface StatementLine {
|
||||||
id: number | null,
|
id: number | null,
|
||||||
source_account: string,
|
source_account: string,
|
||||||
|
@ -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
|
||||||
@ -66,7 +66,7 @@
|
|||||||
import { UnlistenFn, listen } from '@tauri-apps/api/event';
|
import { UnlistenFn, listen } from '@tauri-apps/api/event';
|
||||||
import { onUnmounted, ref, watch } from 'vue';
|
import { onUnmounted, ref, watch } from 'vue';
|
||||||
|
|
||||||
import { Transaction } from '../db.ts';
|
import { Transaction, postingQuantityAsCost } from '../db.ts';
|
||||||
import { pp, ppWithCommodity } from '../display.ts';
|
import { pp, ppWithCommodity } from '../display.ts';
|
||||||
import { renderComponent } from '../webutil.ts';
|
import { renderComponent } from '../webutil.ts';
|
||||||
|
|
||||||
@ -124,10 +124,10 @@
|
|||||||
<td class="py-0.5 px-1 text-gray-900 text-end"><i>${ posting.quantity >= 0 ? 'Dr' : 'Cr' }</i></td>
|
<td class="py-0.5 px-1 text-gray-900 text-end"><i>${ posting.quantity >= 0 ? 'Dr' : 'Cr' }</i></td>
|
||||||
<td class="py-0.5 px-1 text-gray-900 lg:w-[30%]"><a href="/transactions/${ encodeURIComponent(posting.account) }" class="text-gray-900 hover:text-blue-700 hover:underline">${ posting.account }</a></td>
|
<td class="py-0.5 px-1 text-gray-900 lg:w-[30%]"><a href="/transactions/${ encodeURIComponent(posting.account) }" class="text-gray-900 hover:text-blue-700 hover:underline">${ posting.account }</a></td>
|
||||||
<td class="py-0.5 px-1 text-gray-900 lg:w-[12ex] text-end">
|
<td class="py-0.5 px-1 text-gray-900 lg:w-[12ex] text-end">
|
||||||
${ posting.quantity >= 0 ? pp(posting.quantity_ascost!) : '' }
|
${ posting.quantity >= 0 ? pp(postingQuantityAsCost(posting)) : '' }
|
||||||
</td>
|
</td>
|
||||||
<td class="py-0.5 pl-1 text-gray-900 lg:w-[12ex] text-end">
|
<td class="py-0.5 pl-1 text-gray-900 lg:w-[12ex] text-end">
|
||||||
${ posting.quantity < 0 ? pp(-posting.quantity_ascost!) : '' }
|
${ posting.quantity < 0 ? pp(-postingQuantityAsCost(posting)) : '' }
|
||||||
</td>
|
</td>
|
||||||
</tr>`
|
</tr>`
|
||||||
);
|
);
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
import { onMounted, onUnmounted, watch } from 'vue';
|
import { onMounted, onUnmounted, watch } from 'vue';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
|
|
||||||
import { Transaction } from '../db.ts';
|
import { Transaction, postingQuantityAsCost } from '../db.ts';
|
||||||
import { pp } from '../display.ts';
|
import { pp } from '../display.ts';
|
||||||
import { renderComponent } from '../webutil.ts';
|
import { renderComponent } from '../webutil.ts';
|
||||||
|
|
||||||
@ -66,7 +66,7 @@
|
|||||||
const transaction = transactions[i];
|
const transaction = transactions[i];
|
||||||
for (const posting of transaction.postings) {
|
for (const posting of transaction.postings) {
|
||||||
if (posting.account === route.params.account) {
|
if (posting.account === route.params.account) {
|
||||||
balance += posting.quantity_ascost!;
|
balance += postingQuantityAsCost(posting);
|
||||||
posting.running_balance = balance;
|
posting.running_balance = balance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,8 +100,8 @@
|
|||||||
<td class="py-0.5 pr-1 text-gray-900 lg:w-[12ex]">${ dayjs(transaction.dt).format('YYYY-MM-DD') }</td>
|
<td class="py-0.5 pr-1 text-gray-900 lg:w-[12ex]">${ dayjs(transaction.dt).format('YYYY-MM-DD') }</td>
|
||||||
<td class="py-0.5 px-1 text-gray-900">${ transaction.description } ${ editLink }</td>
|
<td class="py-0.5 px-1 text-gray-900">${ transaction.description } ${ editLink }</td>
|
||||||
<td class="py-0.5 px-1 text-gray-900"><a href="/transactions/${ encodeURIComponent(otherAccountPosting!.account) }" class="text-gray-900 hover:text-blue-700 hover:underline">${ otherAccountPosting!.account }</a></td>
|
<td class="py-0.5 px-1 text-gray-900"><a href="/transactions/${ encodeURIComponent(otherAccountPosting!.account) }" class="text-gray-900 hover:text-blue-700 hover:underline">${ otherAccountPosting!.account }</a></td>
|
||||||
<td class="py-0.5 px-1 text-gray-900 lg:w-[12ex] text-end">${ thisAccountPosting!.quantity >= 0 ? pp(thisAccountPosting!.quantity_ascost!) : '' }</td>
|
<td class="py-0.5 px-1 text-gray-900 lg:w-[12ex] text-end">${ thisAccountPosting!.quantity >= 0 ? pp(postingQuantityAsCost(thisAccountPosting!)) : '' }</td>
|
||||||
<td class="py-0.5 px-1 text-gray-900 lg:w-[12ex] text-end">${ thisAccountPosting!.quantity < 0 ? pp(-thisAccountPosting!.quantity_ascost!) : '' }</td>
|
<td class="py-0.5 px-1 text-gray-900 lg:w-[12ex] text-end">${ thisAccountPosting!.quantity < 0 ? pp(-postingQuantityAsCost(thisAccountPosting!)) : '' }</td>
|
||||||
<td class="py-0.5 px-1 text-gray-900 lg:w-[12ex] text-end">${ pp(Math.abs(thisAccountPosting!.running_balance!)) }</td>
|
<td class="py-0.5 px-1 text-gray-900 lg:w-[12ex] text-end">${ pp(Math.abs(thisAccountPosting!.running_balance!)) }</td>
|
||||||
<td class="py-0.5 text-gray-900">${ thisAccountPosting!.running_balance! >= 0 ? 'Dr' : 'Cr' }</td>
|
<td class="py-0.5 text-gray-900">${ thisAccountPosting!.running_balance! >= 0 ? 'Dr' : 'Cr' }</td>
|
||||||
</tr>`
|
</tr>`
|
||||||
@ -125,8 +125,8 @@
|
|||||||
<td></td>
|
<td></td>
|
||||||
<td class="py-0.5 px-1 text-gray-900 text-end"><i>${ posting.quantity >= 0 ? 'Dr' : 'Cr' }</i></td>
|
<td class="py-0.5 px-1 text-gray-900 text-end"><i>${ posting.quantity >= 0 ? 'Dr' : 'Cr' }</i></td>
|
||||||
<td class="py-0.5 px-1 text-gray-900"><a href="/transactions/${ encodeURIComponent(posting.account) }" class="text-gray-900 hover:text-blue-700 hover:underline">${ posting.account }</a></td>
|
<td class="py-0.5 px-1 text-gray-900"><a href="/transactions/${ encodeURIComponent(posting.account) }" class="text-gray-900 hover:text-blue-700 hover:underline">${ posting.account }</a></td>
|
||||||
<td class="py-0.5 px-1 text-gray-900 lg:w-[12ex] text-end">${ posting.quantity >= 0 ? pp(posting.quantity_ascost!) : '' }</td>
|
<td class="py-0.5 px-1 text-gray-900 lg:w-[12ex] text-end">${ posting.quantity >= 0 ? pp(postingQuantityAsCost(posting)) : '' }</td>
|
||||||
<td class="py-0.5 px-1 text-gray-900 lg:w-[12ex] text-end">${ posting.quantity < 0 ? pp(-posting.quantity_ascost!) : '' }</td>
|
<td class="py-0.5 px-1 text-gray-900 lg:w-[12ex] text-end">${ posting.quantity < 0 ? pp(-postingQuantityAsCost(posting)) : '' }</td>
|
||||||
<td class="py-0.5 px-1 text-gray-900 lg:w-[12ex] text-end">${ posting.account === route.params.account ? pp(Math.abs(posting.running_balance!)) : '' }</td>
|
<td class="py-0.5 px-1 text-gray-900 lg:w-[12ex] text-end">${ posting.account === route.params.account ? pp(Math.abs(posting.running_balance!)) : '' }</td>
|
||||||
<td class="py-0.5 text-gray-900">${ posting.account === route.params.account ? (posting.running_balance! >= 0 ? 'Dr' : 'Cr') : '' }</td>
|
<td class="py-0.5 text-gray-900">${ posting.account === route.params.account ? (posting.running_balance! >= 0 ? 'Dr' : 'Cr') : '' }</td>
|
||||||
</tr>`
|
</tr>`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user