refactor: update code gen when change employee branch

This commit is contained in:
Methapon Metanipat 2024-08-20 12:49:45 +07:00
parent c0e44d3efc
commit 8474a6c869

View file

@ -596,15 +596,15 @@ export class EmployeeController extends Controller {
) { ) {
const last = await tx.runningNo.upsert({ const last = await tx.runningNo.upsert({
where: { where: {
key: `EMPLOYEE_${customerBranch.customer.code}-${customerBranch.branchNo.toString().padStart(2, "0")}-${new Date().getFullYear().toString().slice(-2).padStart(2, "0")}`, key: `EMPLOYEE_${customerBranch.customer.code.slice(0, -6)}${`${new Date().getFullYear()}`.slice(-2).padStart(2, "0")}`,
}, },
create: { create: {
key: `EMPLOYEE_${customerBranch.customer.code}-${customerBranch.branchNo.toString().padStart(2, "0")}-${new Date().getFullYear().toString().slice(-2).padStart(2, "0")}`, key: `EMPLOYEE_${customerBranch.customer.code.slice(0, -6)}${`${new Date().getFullYear()}`.slice(-2).padStart(2, "0")}`,
value: 1, value: 1,
}, },
update: { value: { increment: 1 } }, update: { value: { increment: 1 } },
}); });
code = `${customerBranch.customer.code}-${customerBranch.branchNo.toString().padStart(2, "0")}-${new Date().getFullYear().toString().slice(-2).padStart(2, "0")}${last.value.toString().padStart(4, "0")}`; code = `${customerBranch.customer.code.slice(0, -6)}${`${new Date().getFullYear()}`.slice(-2).padStart(2, "0")}${`${last.value}`.padStart(7, "0")}`;
} }
return await prisma.employee.update({ return await prisma.employee.update({