feat: generate quotation code

This commit is contained in:
Methapon2001 2024-07-31 09:45:11 +07:00
parent f88e149318
commit 88559480b7

View file

@ -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({ const quotation = await tx.quotation.create({
data: { data: {
...rest, ...rest,
statusOrder: +(rest.status === "INACTIVE"), 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: { worker: {
createMany: { createMany: {
data: sortedEmployeeId.map((v, i) => ({ data: sortedEmployeeId.map((v, i) => ({