Now that we can assign custom themes to reports you can develop one similar to example below which was done with the aid from AI but with code checking and verification by myself.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Profit and Loss</title>
<style>
:root {
--bg: #f5f5f5;
--paper: #fff;
--ink: #222;
--muted: #606060;
--rule: #dadada;
--subtle: #f3f3f3;
}
* { box-sizing: border-box; }
body {
background-color: var(--bg); /* Match Manager's iframe background. */
color: var(--ink);
display: flex;
margin: 0;
padding: 0;
font: 12px/1.45 Arial, Helvetica, sans-serif;
}
main {
background-color: var(--paper);
margin: 1rem 1.5rem;
border: 1px solid #e5e5e5;
border-radius: 5px;
box-shadow: 0 4px 6px rgb(0 0 0 / 0.05);
padding: 2rem;
min-width: 80ch;
width: 100%;
}
.report-header { margin-bottom: 18px; }
.business-line { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.business-logo { display: block; max-height: 48px; max-width: 150px; object-fit: contain; }
.business-name { font-size: 15px; font-weight: bold; }
.business-details, .report-subtitle, .field { color: var(--muted); }
h1 { margin: 4px 0; font-size: 20px; line-height: 1.25; font-weight: bold; }
.report-subtitle { margin: 2px 0; }
.report-fields { display: flex; flex-wrap: wrap; gap: 4px 20px; margin-top: 9px; }
.field-label { font-weight: 600; }
.field img { max-height: 34px; max-width: 140px; vertical-align: middle; }
.table-description { margin: 0 0 10px; }
table.report-table { border-collapse: collapse; border-spacing: 0; table-layout: fixed; width: 100%; }
.report-table thead th {
border-bottom: 1px solid #888;
color: var(--muted);
font-weight: 600;
padding: 6px 7px;
vertical-align: bottom;
}
.report-table td {
overflow-wrap: break-word;
border-bottom: 1px solid #efefef;
padding: 5px 7px;
vertical-align: top;
}
.report-table th:first-child, .report-table td:first-child { padding-inline-start: 0; }
.report-table th:last-child, .report-table td:last-child { padding-inline-end: 0; }
.report-table a { color: inherit; }
.report-table { margin: 0 0 6px; }
.report-table thead { display: table-header-group; }
.report-table tbody { display: table-row-group; }
.report-table th, .report-table td { overflow-wrap: break-word; }
.report-table tr { break-inside: avoid-page; page-break-inside: avoid; }
.report-table tbody.protect { break-inside: avoid-page; page-break-inside: avoid; }
.report-table .num { font-variant-numeric: tabular-nums; }
/* These table headers repeat automatically if a group spans a print page. */
.report-table thead .group-context th {
color: var(--ink);
background: var(--subtle);
font-size: 12px;
line-height: 1.35;
text-align: start;
font-weight: 700;
padding: 8px 7px 5px;
border-bottom: 1px solid var(--rule);
}
.report-table .group-heading td {
background-color: var(--subtle);
border-bottom-color: var(--rule);
font-weight: 600;
padding-top: 9px;
padding-bottom: 6px;
}
.report-table .total-row td {
border-top: 1px solid var(--rule);
border-bottom: 1px solid var(--rule);
font-weight: 600;
padding-top: 6px;
padding-bottom: 7px;
}
.report-table .grand-total td { border-top: 2px solid #888; font-weight: 700; }
.indent { display: inline-block; }
.report-table img { max-height: 36px; max-width: 130px; vertical-align: middle; }
.summary-totals { margin-top: 12px; margin-inline-start: auto; width: max-content; min-width: 200px; max-width: 100%; }
.summary-total { display: flex; justify-content: space-between; gap: 32px; padding: 4px 0; }
.summary-total.emphasis { font-weight: bold; border-top: 1px solid #888; }
.footers { margin-top: 18px; color: var(--muted); font-size: 11px; }
.status { margin-top: 14px; font-weight: 600; }
.message { color: var(--muted); }
@media (prefers-color-scheme: dark) {
:root { --bg: #292524; --paper: #1c1917; --ink: #eee; --muted: #b6b6b6; --rule: #555; --subtle: #292929; }
main { border-color: #0c0a09; box-shadow: 0 4px 6px rgb(0 0 0 / 0.5); }
}
/* No explicit page construction: A4/Letter/orientation remain the printer's job. */
@page { margin: 10mm; }
@media print {
:root { --paper: #fff; --ink: #000; --muted: #444; --rule: #bbb; --subtle: #f3f3f3; }
html { color-scheme: light; }
body { display: block; background-color: transparent; color: #000; font-size: 10pt; }
main { margin: 0; padding: 0; border: 0; border-radius: 0; box-shadow: none;
min-width: 0; width: auto; }
.report-table { width: 100%; }
.report-table thead { display: table-header-group !important; }
.report-table tbody { display: table-row-group; }
.report-table tr { break-inside: avoid-page; page-break-inside: avoid; }
.report-table tbody.protect { break-inside: avoid-page; page-break-inside: avoid; }
/* Small groups are moved as a unit when space permits. */
.report-table.small-group { break-inside: avoid-page; page-break-inside: avoid; }
.report-header { break-after: avoid-page; page-break-after: avoid; }
.summary-totals, .footers { break-inside: avoid-page; page-break-inside: avoid; }
a { text-decoration: none; }
.report-table thead .group-context th,
.report-table .group-heading td, .report-table .total-row td {
-webkit-print-color-adjust: exact; print-color-adjust: exact;
}
}
</style>
</head>
<body>
<main id="report"><p class="message">Loading report...</p></main>
<script>
'use strict';
/* A group is its own table so Chromium repeats its <thead> whenever
that particular group continues onto another paper page.
No artificial A4 pages, page-numbering or page-height estimation. */
const SHORT_GROUP_MAX_ROWS = 4;
const TOTAL_CONTEXT_ROWS = 2;
function element(tag, className, text) {
const node = document.createElement(tag);
if (className) node.className = className;
if (text !== undefined && text !== null) node.textContent = String(text);
return node;
}
function appendText(parent, value, className) {
if (value === null || value === undefined || value === '') return;
parent.appendChild(element('span', className, value));
}
function safeUrl(url, forImage) {
if (typeof url !== 'string') return '';
const value = url.trim();
if (!value) return '';
if (/^(https?:|\/[^/]|\.\.?\/|\?)/i.test(value)) return value;
if (forImage && /^data:image\/(png|jpeg|gif|webp);base64,/i.test(value)) return value;
if (!/^[a-z][a-z0-9+.-]*:/i.test(value) && !value.startsWith('//')) return value;
return '';
}
function contentInto(parent, item) {
if (!item) return;
let child;
if (item.image && safeUrl(item.image.url, true)) {
child = element('img');
child.src = safeUrl(item.image.url, true);
child.alt = item.text || '';
if (Number(item.image.width) > 0) child.width = Number(item.image.width);
if (Number(item.image.height) > 0) child.height = Number(item.image.height);
} else {
child = document.createTextNode(item.text == null ? '' : String(item.text));
}
const url = item.link && safeUrl(item.link.url, false);
if (url) {
const a = element('a');
a.href = url;
a.target = '_top';
a.rel = 'noopener noreferrer';
a.appendChild(child);
parent.appendChild(a);
} else {
parent.appendChild(child);
}
}
function renderField(field, parent) {
if (!field) return;
const div = element('div', 'field');
if (field.label) {
div.appendChild(element('span', 'field-label', field.label + (field.text || field.image ? ': ' : '')));
}
if (field.text != null || field.image) contentInto(div, field);
parent.appendChild(div);
if (Array.isArray(field.fields)) field.fields.forEach(f => renderField(f, parent));
}
function leafColumns(columns) {
const result = [];
function visit(items) {
for (const col of (items || [])) {
if (Array.isArray(col.subcolumns) && col.subcolumns.length) visit(col.subcolumns);
else result.push(col);
}
}
visit(columns);
return result;
}
function columnDepth(columns) {
return Math.max(0, ...(columns || []).map(c => 1 + (c.subcolumns && c.subcolumns.length ? columnDepth(c.subcolumns) : 0)));
}
function columnLeaves(column) {
return column.subcolumns && column.subcolumns.length
? column.subcolumns.reduce((sum, sub) => sum + columnLeaves(sub), 0) : 1;
}
function alignment(column) {
if (!column) return 'start';
return ['start', 'center', 'end', 'right'].includes(column.align) ? column.align : 'start';
}
function renderTableHead(model, groupCell) {
const head = element('thead');
const roots = model.columns || [];
const leaves = leafColumns(roots);
/* The group title and column labels both belong to THEAD. They therefore
reappear together on a continuation page, not just on the first page. */
if (groupCell) {
const contextRow = element('tr', 'group-context');
const th = element('th');
th.colSpan = Math.max(1, leaves.length);
contentInto(th, groupCell);
contextRow.appendChild(th);
head.appendChild(contextRow);
}
const depth = Math.max(1, columnDepth(roots));
const rows = Array.from({ length: depth }, () => element('tr'));
function visit(items, level) {
for (const c of (items || [])) {
const th = element('th', c.emphasis ? 'emphasis' : '', c.label || '');
const hasChildren = Array.isArray(c.subcolumns) && c.subcolumns.length;
if (hasChildren) th.colSpan = columnLeaves(c);
else th.rowSpan = depth - level;
th.style.textAlign = alignment(c);
if (c.nowrap) th.style.whiteSpace = 'nowrap';
rows[level].appendChild(th);
if (hasChildren) visit(c.subcolumns, level + 1);
}
}
visit(roots, 0);
rows.forEach(row => head.appendChild(row));
return head;
}
function createColumnWidths(columns) {
const colgroup = element('colgroup');
const n = columns.length;
const first = n === 1 ? 100 : n === 2 ? 60 : n === 3 ? 48 : n <= 5 ? 43 : n <= 8 ? 34 : 27;
const other = n === 1 ? 0 : (100 - first) / (n - 1);
columns.forEach((col, index) => {
const elt = element('col');
elt.style.width = (index === 0 ? first : other).toFixed(5) + '%';
colgroup.appendChild(elt);
});
return colgroup;
}
function flattenRows(rows, depth) {
const flat = [];
for (const row of rows || []) {
if (!row) continue;
const isGroup = Array.isArray(row.rows);
flat.push({ row, depth, kind: isGroup ? 'heading' : row.isTotalRow ? 'total' : 'detail' });
if (isGroup) flat.push(...flattenRows(row.rows, depth + 1));
}
return flat;
}
function reportBlocks(rows) {
const blocks = [];
/* Each nested account group has its own repeating heading. A hierarchy
such as Expenses / Repairs therefore remains identifiable on page two. */
function walk(list, path) {
let pending = [];
const flush = () => {
if (pending.length) blocks.push({
title: path.length ? { text: path.map(c => c && c.text || '').filter(Boolean).join(' / ') } : null,
items: pending
});
pending = [];
};
for (let i = 0; i < (list || []).length; i++) {
const row = list[i];
if (!row) continue;
if (Array.isArray(row.rows)) {
flush();
const groupPath = path.concat([row.cells && row.cells[0] || { text: '' }]);
const before = blocks.length;
walk(row.rows, groupPath);
if (blocks.length === before) blocks.push({
title: { text: groupPath.map(c => c && c.text || '').filter(Boolean).join(' / ') }, items: []
});
/* The view-v1 schema represents totals as siblings of their group.
Attach following totals to its last part so they cannot be stranded
in a separate table with no preceding account lines. */
while (list[i+1] && list[i+1].isTotalRow && !Array.isArray(list[i+1].rows)) {
blocks[blocks.length-1].items.push(...flattenRows([list[++i]], 0));
}
} else {
pending.push(...flattenRows([row], 0));
}
}
flush();
}
walk(rows || [], []);
return blocks;
}
function makeRow(item, columns) {
const { row, depth, kind } = item;
const tr = element('tr', kind === 'heading' ? 'group-heading' : kind === 'total' ? 'total-row' : 'detail-row');
if (kind === 'total' && depth === 0) tr.classList.add('grand-total');
const cells = Array.isArray(row.cells) ? row.cells : [];
if (kind === 'heading') {
const td = element('td');
td.colSpan = Math.max(1, columns.length);
const indent = element('span', 'indent');
indent.style.paddingInlineStart = Math.min(depth, 7) * 1.1 + 'em';
contentInto(indent, cells[0]);
td.appendChild(indent);
tr.appendChild(td);
return tr;
}
columns.forEach((column, index) => {
const td = element('td');
td.style.textAlign = alignment(column);
if (column.nowrap) td.style.whiteSpace = 'nowrap';
if (column.emphasis) td.style.fontWeight = '600';
if (alignment(column) === 'right' || alignment(column) === 'end') td.classList.add('num');
if (index === 0 && depth > 0) {
const indent = element('span', 'indent');
indent.style.paddingInlineStart = Math.min(depth, 7) * 1.1 + 'em';
contentInto(indent, cells[index]);
td.appendChild(indent);
} else {
contentInto(td, cells[index]);
}
tr.appendChild(td);
});
return tr;
}
function appendBody(table, items, columns, className) {
if (!items.length) return;
const tbody = element('tbody', className);
items.forEach(item => tbody.appendChild(makeRow(item, columns)));
table.appendChild(tbody);
}
function renderBlock(table, items, columns) {
if (items.length <= SHORT_GROUP_MAX_ROWS) {
table.classList.add('small-group');
appendBody(table, items, columns, 'protect');
return;
}
/* Protect the final two account lines with each subtotal. This is a
preference, not a forced break: a section taller than a page can split. */
const ranges = [];
for (let i = 0; i < items.length; i++) {
if (items[i].kind === 'heading' && i + 1 < items.length) {
ranges.push({start: i, end: i + 1});
}
if (items[i].kind === 'total') {
let start = i;
for (let j = i - 1; j >= Math.max(0, i - TOTAL_CONTEXT_ROWS); j--) {
if (items[j].kind === 'heading') { start = j; break; }
start = j;
if (items[j].kind === 'total') break;
}
ranges.push({start, end: i});
}
}
ranges.sort((a,b) => a.start - b.start || a.end - b.end);
const merged = [];
for (const r of ranges) {
const prev = merged[merged.length - 1];
if (prev && r.start <= prev.end + 0) prev.end = Math.max(prev.end, r.end);
else merged.push({...r});
}
let pos = 0;
for (const range of merged) {
if (pos < range.start) appendBody(table, items.slice(pos,range.start), columns, 'flow');
appendBody(table, items.slice(range.start,range.end+1), columns, 'protect');
pos = range.end+1;
}
if (pos < items.length) appendBody(table, items.slice(pos), columns, 'flow');
}
function renderDocument(data) {
const main = document.getElementById('report');
main.replaceChildren();
if (!data || typeof data !== 'object') {
main.appendChild(element('p', 'message', 'The report contains no data.'));
return;
}
document.documentElement.lang = data.language || 'en';
document.documentElement.dir = data.direction === 'rtl' ? 'rtl' : 'ltr';
document.title = [data.businessName || (data.business && data.business.name), data.title, data.reference]
.filter(Boolean).join(' - ') || 'Report';
const header = element('header', 'report-header');
const business = data.business;
if (business || data.businessName) {
const brand = element('div', 'business-line');
if (business && business.logo && safeUrl(business.logo, true)) {
const logo = element('img', 'business-logo');
logo.src = safeUrl(business.logo, true);
logo.alt = business.name || data.businessName || 'Business logo';
brand.appendChild(logo);
}
const company = element('div');
appendText(company, (business && business.name) || data.businessName, 'business-name');
if (business && business.address) company.appendChild(element('div', 'business-details', business.address));
brand.appendChild(company);
header.appendChild(brand);
if (business && Array.isArray(business.fields) && business.fields.length) {
const group = element('div', 'report-fields');
business.fields.forEach(f => renderField(f, group));
header.appendChild(group);
}
}
header.appendChild(element('h1', '', data.title || 'Report'));
if (data.reference) header.appendChild(element('div', 'report-subtitle', data.reference));
(data.subtitles || []).forEach(s => header.appendChild(element('div', 'report-subtitle', s)));
if (Array.isArray(data.fields) && data.fields.length) {
const fields = element('div', 'report-fields');
data.fields.forEach(f => renderField(f, fields));
header.appendChild(fields);
}
main.appendChild(header);
const model = data.table;
if (model && Array.isArray(model.columns) && model.columns.length) {
if (model.description) main.appendChild(element('p', 'table-description', model.description));
const cols = leafColumns(model.columns);
const fragment = document.createDocumentFragment();
for (const block of reportBlocks(model.rows)) {
const table = element('table', 'report-table');
table.appendChild(createColumnWidths(cols));
table.appendChild(renderTableHead(model, block.title));
renderBlock(table, block.items, cols);
fragment.appendChild(table);
}
main.appendChild(fragment);
}
if (Array.isArray(data.totals) && data.totals.length) {
const summary = element('section', 'summary-totals');
data.totals.forEach(t => {
const row = element('div', 'summary-total' + (t.emphasis ? ' emphasis' : ''));
row.appendChild(element('span', '', t.label || ''));
row.appendChild(element('span', 'num', t.text || ''));
summary.appendChild(row);
});
main.appendChild(summary);
}
if (data.status && data.status.text) main.appendChild(element('div', 'status', data.status.text));
if (Array.isArray(data.footers) && data.footers.length) {
const footers = element('footer', 'footers');
// The API explicitly defines footers as pre-rendered HTML.
data.footers.forEach(html => {
const block = element('div');
block.innerHTML = html;
footers.appendChild(block);
});
main.appendChild(footers);
}
}
fetch('/api4/view-v1' + window.location.search, {
headers: { 'Accept': 'application/json' },
credentials: 'same-origin'
})
.then(response => {
if (!response.ok) throw new Error('HTTP ' + response.status);
return response.json();
})
.then(renderDocument)
.catch(error => {
const main = document.getElementById('report');
main.replaceChildren(element('p', 'message', 'Unable to load report (' + error.message + ').'));
});
</script>
</body>
</html>