Add HMRC tax reporting to accounts
- Add new HMRC Report tab to accounts reports - Show total turnover (web + manual sales) - Calculate cost of goods sold from purchases - Display gross profit and profit margin - Show operating expenses breakdown - Calculate net profit before tax - Estimate tax liability (19% corporation tax) - Include HMRC checklist of what needs to be reported - Help admin prepare for Self Assessment submission Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 4.5
parent
d596cbe836
commit
53dd963090
@@ -7,7 +7,7 @@ export async function getReportData() {
|
||||
const isAuthenticated = await isAdminAuthenticated();
|
||||
if (!isAuthenticated) throw new Error('Unauthorized');
|
||||
|
||||
const [orders, manualSales, expenses] = await Promise.all([
|
||||
const [orders, manualSales, expenses, purchases] = await Promise.all([
|
||||
prisma.order.findMany({
|
||||
select: { id: true, total: true, createdAt: true },
|
||||
orderBy: { createdAt: 'asc' },
|
||||
@@ -20,7 +20,11 @@ export async function getReportData() {
|
||||
select: { id: true, amount: true, date: true, category: true },
|
||||
orderBy: { date: 'desc' },
|
||||
}),
|
||||
prisma.purchase.findMany({
|
||||
select: { id: true, total: true, purchasedAt: true },
|
||||
orderBy: { purchasedAt: 'desc' },
|
||||
}),
|
||||
]);
|
||||
|
||||
return { orders, manualSales, expenses };
|
||||
return { orders, manualSales, expenses, purchases };
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ interface ReportData {
|
||||
orders: Array<{ id: string; total: number; createdAt: Date }>;
|
||||
manualSales: Array<{ id: string; total: number; soldAt: Date; createdAt: Date }>;
|
||||
expenses: Array<{ id: string; amount: number; date: Date; category: string }>;
|
||||
purchases: Array<{ id: string; total: number; purchasedAt: Date }>;
|
||||
}
|
||||
|
||||
export default function ReportsPageClient({ data }: { data: ReportData }) {
|
||||
@@ -29,6 +30,10 @@ export default function ReportsPageClient({ data }: { data: ReportData }) {
|
||||
...e,
|
||||
date: typeof e.date === 'string' ? new Date(e.date) : e.date,
|
||||
})),
|
||||
purchases: data.purchases.map(p => ({
|
||||
...p,
|
||||
purchasedAt: typeof p.purchasedAt === 'string' ? new Date(p.purchasedAt) : p.purchasedAt,
|
||||
})),
|
||||
};
|
||||
|
||||
const monthlyProfit = useMemo(() => {
|
||||
@@ -98,6 +103,30 @@ export default function ReportsPageClient({ data }: { data: ReportData }) {
|
||||
});
|
||||
}, [normalizedData]);
|
||||
|
||||
const hmrcReport = useMemo(() => {
|
||||
const totalRevenue = [...normalizedData.orders, ...normalizedData.manualSales].reduce((sum, s: any) => sum + s.total, 0);
|
||||
const costOfGoodsSold = normalizedData.purchases.reduce((sum, p) => sum + p.total, 0);
|
||||
const grossProfit = totalRevenue - costOfGoodsSold;
|
||||
const totalExpenses = normalizedData.expenses.reduce((sum, e) => sum + e.amount, 0);
|
||||
const netProfit = grossProfit - totalExpenses;
|
||||
|
||||
// UK tax estimation: 19% corporation tax for profits (simplified)
|
||||
// Self-employed allowance is £1,000
|
||||
const taxableProfit = Math.max(0, netProfit - 100000); // Simplified threshold
|
||||
const estimatedTax = Math.max(0, Math.round(taxableProfit * 0.19));
|
||||
|
||||
return {
|
||||
totalRevenue,
|
||||
costOfGoodsSold,
|
||||
grossProfit,
|
||||
grossMargin: totalRevenue > 0 ? (grossProfit / totalRevenue * 100) : 0,
|
||||
totalExpenses,
|
||||
netProfit,
|
||||
profitMargin: totalRevenue > 0 ? (netProfit / totalRevenue * 100) : 0,
|
||||
estimatedTax,
|
||||
};
|
||||
}, [normalizedData]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="mt-6 inline-flex border border-line">
|
||||
@@ -105,6 +134,7 @@ export default function ReportsPageClient({ data }: { data: ReportData }) {
|
||||
{ id: 'monthly-profit', label: 'Monthly Profit' },
|
||||
{ id: 'expense-breakdown', label: 'Expenses' },
|
||||
{ id: 'cash-flow', label: 'Cash Flow' },
|
||||
{ id: 'hmrc', label: 'HMRC Report' },
|
||||
].map((t) => (
|
||||
<button
|
||||
key={t.id}
|
||||
@@ -195,6 +225,74 @@ export default function ReportsPageClient({ data }: { data: ReportData }) {
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{tab === 'hmrc' && (
|
||||
<div className="space-y-6">
|
||||
<div className="border border-splash-blue/40 bg-splash-blue/5 px-4 py-3 text-sm text-splash-blue">
|
||||
ⓘ Summary for HMRC Self Assessment. Keep invoices and receipts as evidence.
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<div className="border border-line p-4">
|
||||
<p className="tag-label">Total Turnover</p>
|
||||
<p className="mt-2 font-mono text-2xl">
|
||||
<Price cents={hmrcReport.totalRevenue} />
|
||||
</p>
|
||||
</div>
|
||||
<div className="border border-line p-4">
|
||||
<p className="tag-label">Cost of Goods Sold</p>
|
||||
<p className="mt-2 font-mono text-2xl">
|
||||
<Price cents={hmrcReport.costOfGoodsSold} />
|
||||
</p>
|
||||
</div>
|
||||
<div className="border border-line p-4">
|
||||
<p className="tag-label">Gross Profit</p>
|
||||
<p className="mt-2 font-mono text-2xl">
|
||||
<Price cents={hmrcReport.grossProfit} />
|
||||
</p>
|
||||
<p className="mt-1 text-xs text-muted">{hmrcReport.grossMargin.toFixed(1)}% margin</p>
|
||||
</div>
|
||||
<div className="border border-line p-4">
|
||||
<p className="tag-label">Operating Expenses</p>
|
||||
<p className="mt-2 font-mono text-2xl">
|
||||
<Price cents={hmrcReport.totalExpenses} />
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="border-2 border-line p-6">
|
||||
<div className="flex items-baseline justify-between">
|
||||
<p className="font-display text-lg">Net Profit (before tax)</p>
|
||||
<p className={`font-mono text-3xl font-medium ${hmrcReport.netProfit >= 0 ? 'text-green-600' : 'text-splash-pink'}`}>
|
||||
<Price cents={hmrcReport.netProfit} />
|
||||
</p>
|
||||
</div>
|
||||
<p className="mt-2 text-xs text-muted">{hmrcReport.profitMargin.toFixed(1)}% of revenue</p>
|
||||
</div>
|
||||
|
||||
<div className="border-2 border-splash-pink p-6">
|
||||
<div className="flex items-baseline justify-between">
|
||||
<p className="font-display text-lg">Estimated Tax Liability</p>
|
||||
<p className="font-mono text-3xl font-medium text-splash-pink">
|
||||
<Price cents={hmrcReport.estimatedTax} />
|
||||
</p>
|
||||
</div>
|
||||
<p className="mt-3 text-xs text-muted">
|
||||
Based on 19% corporation tax on profits. Self-employed? Your actual rate may differ. Consult an accountant for accurate figures.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="text-xs text-muted space-y-2">
|
||||
<p><strong>What to report to HMRC:</strong></p>
|
||||
<ul className="list-disc pl-5 space-y-1">
|
||||
<li>Total turnover: <span className="font-mono"><Price cents={hmrcReport.totalRevenue} /></span></li>
|
||||
<li>Cost of sales (purchases): <span className="font-mono"><Price cents={hmrcReport.costOfGoodsSold} /></span></li>
|
||||
<li>Running expenses: <span className="font-mono"><Price cents={hmrcReport.totalExpenses} /></span></li>
|
||||
<li>Profit before tax: <span className="font-mono"><Price cents={hmrcReport.netProfit} /></span></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user