From 88559480b7f6a285ef6657836d9f976405bf4763 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 31 Jul 2024 09:45:11 +0700 Subject: [PATCH] feat: generate quotation code --- src/controllers/quotation-controller.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/controllers/quotation-controller.ts b/src/controllers/quotation-controller.ts index 3679852..d3e551d 100644 --- a/src/controllers/quotation-controller.ts +++ b/src/controllers/quotation-controller.ts @@ -391,11 +391,26 @@ export class QuotationController extends Controller { }; }); + const currentYear = new Date().getFullYear(); + const currentMonth = new Date().getMonth() + 1; + const currentDate = new Date().getDate(); + + const lastQuotation = await tx.runningNo.upsert({ + where: { + key: `QUOTATION_${currentYear.toString().padStart(2, "0")}${currentMonth.toString().padStart(2, "0")}${currentDate.toString().padStart(2, "0")}`, + }, + create: { + key: `QUOTATION_${currentYear.toString().padStart(2, "0")}${currentMonth.toString().padStart(2, "0")}${currentDate.toString().padStart(2, "0")}`, + value: 1, + }, + update: { value: { increment: 1 } }, + }); + const quotation = await tx.quotation.create({ data: { ...rest, statusOrder: +(rest.status === "INACTIVE"), - code: "", + code: `${currentYear.toString().padStart(2, "0")}${currentMonth.toString().padStart(2, "0")}${currentDate.toString().padStart(2, "0")}${lastQuotation.value.toString().padStart(4, "0")}`, worker: { createMany: { data: sortedEmployeeId.map((v, i) => ({