Display single-letter commodity before quantity
This commit is contained in:
parent
6174a7ce57
commit
5439632fc6
@ -177,7 +177,7 @@ function parseFloatStrict(quantity: string): number {
|
|||||||
return parseFloat(quantity);
|
return parseFloat(quantity);
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateCommodity(commodity: string) {
|
export function validateCommodity(commodity: string) {
|
||||||
// Validate that the commodity is correctly formed
|
// Validate that the commodity is correctly formed
|
||||||
const commodityParts = commodity.split(' ');
|
const commodityParts = commodity.split(' ');
|
||||||
if (commodityParts.length > 2) {
|
if (commodityParts.length > 2) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
DrCr: Web-based double-entry bookkeeping framework
|
DrCr: Web-based 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
|
||||||
it under the terms of the GNU Affero General Public License as published by
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
@ -16,7 +16,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { db } from './db.ts';
|
import { db, validateCommodity } from './db.ts';
|
||||||
|
|
||||||
export function pp(quantity: number): string {
|
export function pp(quantity: number): string {
|
||||||
// Pretty print the quantity
|
// Pretty print the quantity
|
||||||
@ -33,8 +33,16 @@ export function pp(quantity: number): string {
|
|||||||
|
|
||||||
export function ppWithCommodity(quantity: number, commodity: string): string {
|
export function ppWithCommodity(quantity: number, commodity: string): string {
|
||||||
// Pretty print the amount including commodity
|
// Pretty print the amount including commodity
|
||||||
if (commodity.length === 1) {
|
validateCommodity(commodity);
|
||||||
return commodity + pp(quantity);
|
|
||||||
|
const commodityParts = commodity.split(' ');
|
||||||
|
|
||||||
|
if (commodityParts[0].length === 1) {
|
||||||
|
if (commodityParts.length === 1) {
|
||||||
|
return commodityParts[0] + pp(quantity);
|
||||||
|
} else {
|
||||||
|
return commodityParts[0] + pp(quantity) + ' ' + commodityParts[1];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return pp(quantity) + ' ' + commodity;
|
return pp(quantity) + ' ' + commodity;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user