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:
@@ -11,6 +11,7 @@ import {
|
||||
import prisma from "../../config/database";
|
||||
import {
|
||||
listOffers,
|
||||
getOfferTotals,
|
||||
getOffer,
|
||||
createOffer,
|
||||
updateOffer,
|
||||
@@ -52,6 +53,24 @@ export default async function quotationsRoutes(
|
||||
},
|
||||
);
|
||||
|
||||
// GET /api/admin/offers/stats — per-currency total (incl. VAT) summed over the
|
||||
// WHOLE filtered set (not one page). Offers have NO month/year filter; the
|
||||
// list filters by search + status + customer_id, so the totals use the same.
|
||||
// Registered BEFORE "/:id" so the literal "stats" path isn't captured as an id.
|
||||
fastify.get(
|
||||
"/stats",
|
||||
{ preHandler: requirePermission("offers.view") },
|
||||
async (request, reply) => {
|
||||
const query = request.query as Record<string, unknown>;
|
||||
const result = await getOfferTotals({
|
||||
search: query.search ? String(query.search) : undefined,
|
||||
status: query.status ? String(query.status) : undefined,
|
||||
customer_id: query.customer_id ? Number(query.customer_id) : undefined,
|
||||
});
|
||||
return success(reply, { totals: result.totals });
|
||||
},
|
||||
);
|
||||
|
||||
// GET /api/admin/offers/next-number
|
||||
fastify.get(
|
||||
"/next-number",
|
||||
|
||||
Reference in New Issue
Block a user