fix(drafts): exclude drafts from VAT/revenue/created aggregations + koncept audit labels
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -198,7 +198,11 @@ export default async function dashboardRoutes(
|
||||
prisma.quotations.count({ where: { status: "ordered" } }),
|
||||
prisma.quotations.count({ where: { status: "invalidated" } }),
|
||||
prisma.quotations.count({
|
||||
where: { created_at: { gte: monthStart, lt: monthEnd } },
|
||||
where: {
|
||||
// Drafts aren't real offers — keep them out of the count.
|
||||
status: { not: "draft" },
|
||||
created_at: { gte: monthStart, lt: monthEnd },
|
||||
},
|
||||
}),
|
||||
]);
|
||||
result.offers = {
|
||||
@@ -246,6 +250,7 @@ export default async function dashboardRoutes(
|
||||
FROM invoices i
|
||||
JOIN invoice_items ii ON i.id = ii.invoice_id
|
||||
WHERE i.issue_date >= ${monthStartStr} AND i.issue_date < ${monthEndStr}
|
||||
AND i.status <> 'draft'
|
||||
GROUP BY i.currency
|
||||
`,
|
||||
]);
|
||||
|
||||
@@ -127,13 +127,15 @@ export default async function invoicesRoutes(
|
||||
|
||||
const invoice = await createInvoice(body);
|
||||
|
||||
// A draft has no number yet — show "koncept" instead of "null".
|
||||
const isDraft = invoice.status === "draft";
|
||||
await logAudit({
|
||||
request,
|
||||
authData: request.authData,
|
||||
action: "create",
|
||||
entityType: "invoice",
|
||||
entityId: invoice.id,
|
||||
description: `Vytvořena faktura ${invoice.invoice_number}`,
|
||||
description: `Vytvořena faktura ${invoice.invoice_number ?? "koncept"}`,
|
||||
});
|
||||
// Return both invoice_id and id for frontend compatibility
|
||||
return success(
|
||||
@@ -144,7 +146,9 @@ export default async function invoicesRoutes(
|
||||
invoice_number: invoice.invoice_number,
|
||||
},
|
||||
201,
|
||||
"Faktura byla vystavena",
|
||||
isDraft
|
||||
? "Faktura byla uložena jako koncept"
|
||||
: "Faktura byla vystavena",
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -81,7 +81,7 @@ export default async function issuedOrdersRoutes(fastify: FastifyInstance) {
|
||||
action: "create",
|
||||
entityType: "issued_order",
|
||||
entityId: order.id,
|
||||
description: `Vytvořena vydaná objednávka ${order.po_number}`,
|
||||
description: `Vytvořena vydaná objednávka ${order.po_number ?? "koncept"}`,
|
||||
});
|
||||
return success(
|
||||
reply,
|
||||
|
||||
@@ -252,7 +252,7 @@ export default async function quotationsRoutes(
|
||||
action: "create",
|
||||
entityType: "quotation",
|
||||
entityId: quotation.id,
|
||||
description: `Vytvořena nabídka ${quotation.quotation_number}`,
|
||||
description: `Vytvořena nabídka ${quotation.quotation_number ?? "koncept"}`,
|
||||
});
|
||||
return success(
|
||||
reply,
|
||||
|
||||
Reference in New Issue
Block a user