diff --git a/src/controllers/customer-branch-controller.ts b/src/controllers/customer-branch-controller.ts index 9dfa0a6..c79502b 100644 --- a/src/controllers/customer-branch-controller.ts +++ b/src/controllers/customer-branch-controller.ts @@ -333,7 +333,8 @@ export class CustomerBranchController extends Controller { const record = await prisma.$transaction( async (tx) => { - const headofficeCode = customer.branch.at(0)?.code.slice(0, -3); + const headoffice = customer.branch.at(0); + const headofficeCode = headoffice?.code.slice(0, -3); let runningKey = ""; @@ -354,6 +355,16 @@ export class CustomerBranchController extends Controller { update: { value: { increment: 1 } }, }); + if (headoffice) { + await tx.customerBranch.updateMany({ + where: { + id: headoffice.id, + status: "CREATED", + }, + data: { status: "ACTIVE" }, + }); + } + return await tx.customerBranch.create({ include: { province: true,