- 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>
31 lines
961 B
TypeScript
31 lines
961 B
TypeScript
'use server';
|
|
|
|
import { prisma } from '@/lib/prisma';
|
|
import { isAdminAuthenticated } from '@/lib/adminAuth';
|
|
|
|
export async function getReportData() {
|
|
const isAuthenticated = await isAdminAuthenticated();
|
|
if (!isAuthenticated) throw new Error('Unauthorized');
|
|
|
|
const [orders, manualSales, expenses, purchases] = await Promise.all([
|
|
prisma.order.findMany({
|
|
select: { id: true, total: true, createdAt: true },
|
|
orderBy: { createdAt: 'asc' },
|
|
}),
|
|
prisma.manualSale.findMany({
|
|
select: { id: true, total: true, soldAt: true, createdAt: true },
|
|
orderBy: { soldAt: 'desc' },
|
|
}),
|
|
prisma.expense.findMany({
|
|
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, purchases };
|
|
}
|