Fix sales breakdown Audit column — show all-groups total vs configured columns

Gross Total now sums only configured GL column gross amounts. Audit column
shows the all-groups earned revenue total (daily_gross_sales), with amber
variance highlight when they diverge — flags unconfigured GL groups the same
way the original WP plugin did.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-20 08:58:30 +00:00
parent dbef4b9f7a
commit fa62c7c44a

View file

@ -578,8 +578,12 @@ export function MultiDayReport() {
const map = Object.fromEntries(day.sales_breakdown.map(s => [s.gl_code, s]))
const totalNet = day.sales_breakdown.reduce((s, sb) => s + (sb.net_amount ?? 0), 0)
const totalVat = day.sales_breakdown.reduce((s, sb) => s + (sb.vat_amount ?? 0), 0)
const totalGross = dayGrossSales(day)
const auditStyle: React.CSSProperties = { background: '#d4edda', fontWeight: 700 }
const totalGross = day.sales_breakdown.reduce((s, sb) => s + (sb.gross_amount ?? 0), 0)
const audit = dayGrossSales(day)
const auditVar = audit - totalGross
const auditStyle: React.CSSProperties = Math.abs(auditVar) < 0.005
? { background: '#d4edda', fontWeight: 700 }
: { background: '#fff3cd', fontWeight: 700, color: '#856404' }
return (
<tr key={day.date} style={{ borderBottom: '1px solid #e0e0e0' }}>
<td style={{ ...td, ...cs('tbl-sales', ri + 1, 0) }}>{fmtDate(day.date)}</td>
@ -590,7 +594,14 @@ export function MultiDayReport() {
<td style={{ ...td, textAlign: 'right', fontWeight: 700, ...cs('tbl-sales', ri + 1, salesCols.length + 1) }}>{fmtGBP(totalNet)}</td>
<td style={{ ...td, textAlign: 'right', fontWeight: 700, ...cs('tbl-sales', ri + 1, salesCols.length + 2) }}>{fmtGBP(totalVat)}</td>
<td style={{ ...td, textAlign: 'right', fontWeight: 700, ...cs('tbl-sales', ri + 1, salesCols.length + 3) }}>{fmtGBP(totalGross)}</td>
<td style={{ ...td, textAlign: 'right', ...auditStyle, ...cs('tbl-sales', ri + 1, salesCols.length + 4) }}>{fmtGBP(totalGross)}</td>
<td style={{ ...td, textAlign: 'right', ...auditStyle, ...cs('tbl-sales', ri + 1, salesCols.length + 4) }}>
{fmtGBP(audit)}
{Math.abs(auditVar) >= 0.005 && (
<span style={{ display: 'block', fontSize: '0.7rem', marginTop: '1px' }}>
{auditVar > 0 ? '▲ +' : '▼ '}{fmtGBP(auditVar)}
</span>
)}
</td>
</tr>
)
})}
@ -604,8 +615,19 @@ export function MultiDayReport() {
})}
<th style={{ ...th, ...cs('tbl-sales', days.length + 1, salesCols.length + 1) }}>{fmtGBP(days.reduce((s, d) => s + d.sales_breakdown.reduce((ss, sb) => ss + (sb.net_amount ?? 0), 0), 0))}</th>
<th style={{ ...th, ...cs('tbl-sales', days.length + 1, salesCols.length + 2) }}>{fmtGBP(days.reduce((s, d) => s + d.sales_breakdown.reduce((ss, sb) => ss + (sb.vat_amount ?? 0), 0), 0))}</th>
<th style={{ ...th, ...cs('tbl-sales', days.length + 1, salesCols.length + 3) }}>{fmtGBP(days.reduce((s, d) => s + dayGrossSales(d), 0))}</th>
<th style={{ ...th, background: '#d4edda', ...cs('tbl-sales', days.length + 1, salesCols.length + 4) }}>{fmtGBP(days.reduce((s, d) => s + dayGrossSales(d), 0))}</th>
<th style={{ ...th, ...cs('tbl-sales', days.length + 1, salesCols.length + 3) }}>{fmtGBP(days.reduce((s, d) => s + d.sales_breakdown.reduce((ss, sb) => ss + (sb.gross_amount ?? 0), 0), 0))}</th>
{(() => {
const totGross = days.reduce((s, d) => s + d.sales_breakdown.reduce((ss, sb) => ss + (sb.gross_amount ?? 0), 0), 0)
const totAudit = days.reduce((s, d) => s + dayGrossSales(d), 0)
const v = totAudit - totGross
const vstyle: React.CSSProperties = Math.abs(v) < 0.005 ? { background: '#d4edda' } : { background: '#fff3cd', color: '#856404' }
return (
<th style={{ ...th, ...vstyle, ...cs('tbl-sales', days.length + 1, salesCols.length + 4) }}>
{fmtGBP(totAudit)}
{Math.abs(v) >= 0.005 && <span style={{ display: 'block', fontSize: '0.7rem', fontWeight: 400 }}>{v > 0 ? '▲ +' : '▼ '}{fmtGBP(v)}</span>}
</th>
)
})()}
</tr>
</tfoot>
</table>