feat(offers,invoices): per-currency 'Celkem' totals beneath the lists (consistent with orders)
Mirrors the orders totals exactly: /stats (offers) + /list-totals (issued + received invoices) endpoints sum each doc's total per currency across the active filter (reusing extracted where-builders so they stay in sync with the lists), rendered as the identical 'Celkem: …' block via the shared formatMultiCurrency. Existing invoice/received KPI stats untouched. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
||||
import {
|
||||
markOverdueInvoices,
|
||||
listInvoices,
|
||||
getInvoiceListTotals,
|
||||
getNextInvoiceNumberFormatted,
|
||||
getNextInvoiceNumberPreview,
|
||||
getInvoiceStats,
|
||||
@@ -77,7 +78,7 @@ export default async function invoicesRoutes(
|
||||
},
|
||||
);
|
||||
|
||||
// GET /api/admin/invoices/stats
|
||||
// GET /api/admin/invoices/stats — monthly KPI cards (paid/awaiting/overdue/VAT).
|
||||
fastify.get(
|
||||
"/stats",
|
||||
{ preHandler: requirePermission("invoices.view") },
|
||||
@@ -90,6 +91,27 @@ export default async function invoicesRoutes(
|
||||
},
|
||||
);
|
||||
|
||||
// GET /api/admin/invoices/list-totals — per-currency total (incl. VAT) summed
|
||||
// over the WHOLE filtered set (not one page), matching the issued-invoice
|
||||
// list's filters (search/status/month/year). Distinct path from "/stats" (the
|
||||
// KPI cards) to avoid colliding with that endpoint. Registered BEFORE "/:id"
|
||||
// so the literal path isn't captured as an invoice id.
|
||||
fastify.get(
|
||||
"/list-totals",
|
||||
{ preHandler: requirePermission("invoices.view") },
|
||||
async (request, reply) => {
|
||||
const query = request.query as Record<string, unknown>;
|
||||
const result = await getInvoiceListTotals({
|
||||
search: query.search ? String(query.search) : undefined,
|
||||
status: query.status ? String(query.status) : undefined,
|
||||
customer_id: query.customer_id ? Number(query.customer_id) : undefined,
|
||||
month: query.month ? Number(query.month) : undefined,
|
||||
year: query.year ? Number(query.year) : undefined,
|
||||
});
|
||||
return success(reply, { totals: result.totals });
|
||||
},
|
||||
);
|
||||
|
||||
// GET /api/admin/invoices/order-data/:id
|
||||
fastify.get<{ Params: { id: string } }>(
|
||||
"/order-data/:id",
|
||||
|
||||
Reference in New Issue
Block a user