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) => ({