Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | 40x 40x 40x 768x 9x 768x 768x 8x 8x 25x 25x 25x 25x 25x 25x 25x 25x 8x 768x 768x 9x 9x 26x 26x 6x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 9x 9x 26x 26x 26x 26x 9x 9x 768x 40x | 'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
module.exports = ({ numeric: { decimal: { divideDecimalsHalfEven, formatDecimal, parseDecimal } } }) => ({
loadFormatData(journal) {
return journal.commodities({ usage: 'all' });
},
formatCsv(rows, _cliOptions, { csvField }) {
const lines = ['date,baseCommodity,quoteQuantity,quoteCommodity,comment'];
for (const row of rows) {
lines.push([
row.date,
row.baseCommodity,
row.quoteQuantity,
row.quoteCommodity,
row.comment ?? '',
].map(csvField).join(','));
}
return `${lines.join('\n')}\n`;
},
formatText(rows, _cliOptions, format, descriptions) {
const { commodityFormats, decimalScale, formatPriceQuantity, parseCommodityFormat } = format;
function ledgerPriceQuantity(row, formats) {
if (!row.ledgerPrice)
return row.quoteQuantity;
const { totalQuantity, baseQuantity, hasTransactionCost, baseScale, quoteScale } = row.ledgerPrice;
const commodityScale = parseCommodityFormat(formats.get(row.quoteCommodity))?.scale ?? quoteScale;
const amountScale = decimalScale(baseQuantity);
// Ledger 3.3.2 extends divisions by six digits. An inferred purchase
// divides the balancing totals, caps precision to the quote commodity + 6,
// then multiplies and divides by the posting quantity during exchange.
// An explicit @@ price only performs that final division.
const scale = hasTransactionCost
? decimalScale(totalQuantity) + amountScale + 6
: Math.min(quoteScale + baseScale + 6, commodityScale + 6) + 2 * amountScale + 6;
const amount = parseDecimal(baseQuantity);
return formatDecimal(divideDecimalsHalfEven(parseDecimal(totalQuantity), {
...amount,
coefficient: amount.coefficient < 0n ? -amount.coefficient : amount.coefficient,
}, Math.max(scale, commodityScale)));
}
const formats = commodityFormats(descriptions);
const lines = rows.map((row) => {
const quantity = formatPriceQuantity(ledgerPriceQuantity(row, formats), row.quoteCommodity, formats);
const amount = `${quantity} ${row.quoteCommodity}`;
return `${row.date} ${row.baseCommodity.padEnd(8)} ` +
amount.padStart(12);
});
return lines.length === 0 ? '' : `${lines.join('\n')}\n`;
},
});
|