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:
+11
-3
@@ -453,8 +453,9 @@
|
||||
<div class="tablewrap"><table class="adm-table" id="pnlLedger"></table></div>
|
||||
<div class="grid" style="grid-template-columns:repeat(auto-fit,minmax(130px,1fr));gap:8px;margin-top:12px">
|
||||
<select id="ldDir"><option value="in">Money in</option><option value="out">Money out</option></select>
|
||||
<select id="ldKind"><option value="revenue">Revenue</option><option value="draw">Draw</option><option value="transfer">Transfer</option></select>
|
||||
<select id="ldWallet"><option value="feeA">Receiver A</option><option value="feeB">Receiver B</option><option value="engine">Engine</option><option value="hunt">PolHunter</option></select>
|
||||
<select id="ldKind"><option value="revenue">Revenue</option><option value="cost">Cost</option><option value="draw">Draw</option><option value="transfer">Transfer</option></select>
|
||||
<select id="ldCat" hidden><option value="advertising">Advertising</option><option value="rewards">Player rewards</option><option value="software">Software and hosting</option><option value="other">Other cost</option></select>
|
||||
<select id="ldWallet"><option value="feeA">Receiver A</option><option value="feeB">Receiver B</option><option value="engine">Engine</option><option value="hunt">PolHunter</option><option value="outside">Outside wallet</option></select>
|
||||
<input type="number" id="ldAmount" min="0" step="0.0001" placeholder="Amount in POL">
|
||||
<input type="number" id="ldUsd" min="0" step="0.01" placeholder="USD (optional)">
|
||||
<input type="date" id="ldDate">
|
||||
@@ -464,6 +465,13 @@
|
||||
<button class="btn small" type="button" id="ldAdd">Add line</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-head"><h3>Tax summary</h3><span class="sub">income versus advertising and other costs, for one year</span></div>
|
||||
<p class="small muted" style="margin:0 0 10px">Income is the platform's share of every package sale, valued at that sale's own dollar price, plus outside revenue. Sales to your own positions are left out. Costs are the ledger's Cost lines; game wallet top-ups are recorded there automatically as Player rewards. Draws and transfers are your money, not expenses, so they are listed apart.</p>
|
||||
<p><select id="taxYear"></select> <button class="btn small" type="button" id="taxRun">Show</button> <button class="btn small sec" type="button" id="taxCsv" hidden>Copy CSV for your accountant</button></p>
|
||||
<div id="taxOut" class="small"></div>
|
||||
<textarea id="taxCsvText" hidden rows="6" style="width:100%;margin-top:8px" readonly></textarea>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-head"><h3>Automatic credit burner</h3><span class="sub">settles pending campaign spend on-chain from the engine wallet</span></div>
|
||||
<p class="small" id="burnerLine">…</p>
|
||||
@@ -512,6 +520,6 @@
|
||||
</div>
|
||||
|
||||
<script src="/assets/common.js?v=20261003fr2"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/admin.js?v=20261002sd"></script>
|
||||
<script src="/assets/admin.js?v=20261004tax"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+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