P&L: Cost lines with tax categories (advertising, player rewards, software, other), outside-wallet source, duplicate-tx guard; Tax summary (income vs advertising/promotion, own sales excluded, CSV)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+35
-4
@@ -753,15 +753,16 @@
|
||||
// The ledger: hand-entered movements the chain index cannot see, plus the reconciliation that
|
||||
// makes "earned" and "on hand" agree. A drift that will not go to zero is a transfer nobody
|
||||
// wrote down (Marty, 2026-09-23).
|
||||
const LD_KIND = { revenue: 'Revenue', draw: 'Draw', transfer: 'Transfer' };
|
||||
const LD_WALLET = { feeA: 'Receiver A', feeB: 'Receiver B', engine: 'Engine', hunt: 'PolHunter' };
|
||||
const LD_KIND = { revenue: 'Revenue', draw: 'Draw', transfer: 'Transfer', cost: 'Cost' };
|
||||
const LD_CAT = { advertising: 'Advertising', rewards: 'Player rewards', software: 'Software and hosting', other: 'Other cost' };
|
||||
const LD_WALLET = { feeA: 'Receiver A', feeB: 'Receiver B', engine: 'Engine', hunt: 'PolHunter', outside: 'Outside wallet' };
|
||||
const pol4 = n => Number(n || 0).toLocaleString(undefined, { maximumFractionDigits: 4 });
|
||||
function renderLedger(r) {
|
||||
const L = (r && r.ledger) || {}, rows = L.entries || [], t = L.totals || {}, rec = L.reconcile || {};
|
||||
if ($('pnlLedger')) {
|
||||
$('pnlLedger').innerHTML = '<tr><th>Date</th><th>Wallet</th><th>Kind</th><th>POL</th><th>What for</th><th></th></tr>'
|
||||
+ (rows.length ? rows.map(e => '<tr><td>' + e.date + '</td><td>' + (LD_WALLET[e.wallet] || e.wallet) + '</td>'
|
||||
+ '<td>' + (LD_KIND[e.kind] || e.kind) + '</td>'
|
||||
+ '<td>' + (LD_KIND[e.kind] || e.kind) + (e.kind === 'cost' ? ' <span class="muted">(' + (LD_CAT[e.category] || e.category || 'other') + ')</span>' : '') + '</td>'
|
||||
+ '<td' + (e.dir === 'out' ? ' style="color:var(--bad)"' : '') + '>' + (e.dir === 'out' ? '-' : '+') + pol4(e.amount)
|
||||
+ (e.usd ? ' <span class="muted">($' + Number(e.usd).toFixed(2) + ')</span>' : '') + '</td>'
|
||||
+ '<td>' + esc(e.note || '') + '</td>'
|
||||
@@ -788,7 +789,7 @@
|
||||
}
|
||||
}
|
||||
if ($('ldAdd')) $('ldAdd').addEventListener('click', async () => {
|
||||
const body = { dir: $('ldDir').value, kind: $('ldKind').value, wallet: $('ldWallet').value,
|
||||
const body = { dir: $('ldDir').value, kind: $('ldKind').value, category: $('ldCat') ? $('ldCat').value : '', wallet: $('ldWallet').value,
|
||||
amount: Number($('ldAmount').value) || 0, usd: Number($('ldUsd').value) || 0,
|
||||
date: $('ldDate').value, note: $('ldNote').value };
|
||||
try {
|
||||
@@ -1013,3 +1014,33 @@
|
||||
|
||||
render();
|
||||
})();
|
||||
// ---- tax summary (2026-10-04) + the cost category picker
|
||||
(function () {
|
||||
const $ = id => document.getElementById(id);
|
||||
if ($('ldKind') && $('ldCat')) { const sync = () => { $('ldCat').hidden = $('ldKind').value !== 'cost'; }; $('ldKind').addEventListener('change', sync); sync(); }
|
||||
if (!$('taxYear')) return;
|
||||
const y = new Date().getFullYear(); for (let v = y; v >= 2025; v--) { const o = document.createElement('option'); o.value = v; o.textContent = v; $('taxYear').appendChild(o); }
|
||||
const money = n => '$' + Number(n || 0).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
||||
$('taxRun').addEventListener('click', async () => {
|
||||
$('taxOut').textContent = 'Working it out...';
|
||||
try {
|
||||
const r = await (await fetch('/api/admin/tax?year=' + $('taxYear').value, { credentials: 'same-origin' })).json();
|
||||
if (r.error) throw new Error(r.error);
|
||||
const cats = Object.entries(r.expenses.byCategory || {}).map(([k, v]) => '<tr><td>' + (r.expenses.labels[k] || k) + '</td><td class="num">' + money(v) + '</td></tr>').join('');
|
||||
$('taxOut').innerHTML = '<table class="adm-table"><tr><th colspan="2">' + r.year + '</th></tr>'
|
||||
+ '<tr><td><b>Income</b>: platform share of ' + r.income.sales + ' package sales</td><td class="num">' + money(r.income.platformUsd) + '</td></tr>'
|
||||
+ (r.income.outsideUsd ? '<tr><td>Outside revenue</td><td class="num">' + money(r.income.outsideUsd) + '</td></tr>' : '')
|
||||
+ '<tr><td><b>Total income</b></td><td class="num"><b>' + money(r.income.totalUsd) + '</b></td></tr>'
|
||||
+ (cats || '<tr><td>No costs recorded yet</td><td></td></tr>')
|
||||
+ '<tr><td><b>Advertising and promotion</b> (advertising + player rewards)</td><td class="num"><b>' + money(r.expenses.advertisingAndPromotionUsd) + '</b></td></tr>'
|
||||
+ '<tr><td><b>Total costs</b></td><td class="num"><b>' + money(r.expenses.totalUsd) + '</b></td></tr>'
|
||||
+ '<tr><td><b>Net</b></td><td class="num"><b>' + money(r.netUsd) + '</b></td></tr></table>'
|
||||
+ '<p class="muted">Left out: ' + money(r.income.ownSalesExcludedUsd) + ' of sales to your own positions (' + r.ownMemberIds.join(', ') + '); ' + r.draws + ' draws and ' + r.transfers + ' transfers (your money, not expenses).</p>';
|
||||
$('taxCsvText').value = r.csv; $('taxCsv').hidden = false;
|
||||
} catch (e) { $('taxOut').textContent = 'Could not build the summary: ' + e.message; }
|
||||
});
|
||||
$('taxCsv').addEventListener('click', async () => {
|
||||
try { await navigator.clipboard.writeText($('taxCsvText').value); IAP.status('CSV copied. Paste it into a spreadsheet.', 'good'); }
|
||||
catch (e) { $('taxCsvText').hidden = false; $('taxCsvText').select(); IAP.status('Selected. Copy it with your keyboard.', 'good'); }
|
||||
});
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user