diff --git a/src/controllers/04-invoice-controller.ts b/src/controllers/04-invoice-controller.ts index b4a4753..2338a97 100644 --- a/src/controllers/04-invoice-controller.ts +++ b/src/controllers/04-invoice-controller.ts @@ -40,6 +40,27 @@ const permissionCheck = createPermCheck(globalAllow); @Route("/api/v1/invoice") @Tags("Invoice") export class InvoiceController extends Controller { + @Get("stats") + @OperationId("getInvoiceStats") + @Security("keycloak") + async getInvoiceStats(@Request() req: RequestWithUser, @Query() quotationId?: string) { + const where = { + quotationId, + quotation: { + registeredBranch: { + OR: permissionCondCompany(req.user), + }, + }, + }; + + const [pay, notPay] = await prisma.$transaction([ + prisma.invoice.count({ where: { ...where, payment: { isNot: null } } }), + prisma.invoice.count({ where: { ...where, payment: null } }), + ]); + + return { pay, notPay }; + } + @Get() @OperationId("getInvoiceList") @Security("keycloak")