feat: new gen branch code
This commit is contained in:
parent
2ed718ccd0
commit
c92ae50f82
1 changed files with 6 additions and 10 deletions
|
|
@ -28,6 +28,7 @@ const MINIO_BUCKET = process.env.MINIO_BUCKET;
|
||||||
|
|
||||||
type BranchCreate = {
|
type BranchCreate = {
|
||||||
status?: Status;
|
status?: Status;
|
||||||
|
code: string;
|
||||||
taxNo: string;
|
taxNo: string;
|
||||||
nameEN: string;
|
nameEN: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
|
@ -293,27 +294,22 @@ export class BranchController extends Controller {
|
||||||
"relationHQNotFound",
|
"relationHQNotFound",
|
||||||
);
|
);
|
||||||
|
|
||||||
const { provinceId, districtId, subDistrictId, headOfficeId, bank, contact, ...rest } = body;
|
const { provinceId, districtId, subDistrictId, headOfficeId, bank, contact, code, ...rest } =
|
||||||
|
body;
|
||||||
const year = new Date().getFullYear();
|
|
||||||
|
|
||||||
const record = await prisma.$transaction(
|
const record = await prisma.$transaction(
|
||||||
async (tx) => {
|
async (tx) => {
|
||||||
const last = await tx.runningNo.upsert({
|
const last = await tx.runningNo.upsert({
|
||||||
where: {
|
where: {
|
||||||
key: !headOfficeId ? `HQ${year.toString().slice(2)}` : `BR${head?.code.slice(2, 5)}`,
|
key: `MAIN_BRANCH_${code}`,
|
||||||
},
|
},
|
||||||
create: {
|
create: {
|
||||||
key: !headOfficeId ? `HQ${year.toString().slice(2)}` : `BR${head?.code.slice(2, 5)}`,
|
key: `MAIN_BRANCH_${code}`,
|
||||||
value: 1,
|
value: 1,
|
||||||
},
|
},
|
||||||
update: { value: { increment: 1 } },
|
update: { value: { increment: 1 } },
|
||||||
});
|
});
|
||||||
|
|
||||||
const code = !headOfficeId
|
|
||||||
? `HQ${year.toString().slice(2)}${last.value}`
|
|
||||||
: `BR${head?.code.slice(2, 5)}${last.value.toString().padStart(2, "0")}`;
|
|
||||||
|
|
||||||
return await tx.branch.create({
|
return await tx.branch.create({
|
||||||
include: {
|
include: {
|
||||||
province: true,
|
province: true,
|
||||||
|
|
@ -325,7 +321,7 @@ export class BranchController extends Controller {
|
||||||
data: {
|
data: {
|
||||||
...rest,
|
...rest,
|
||||||
statusOrder: +(rest.status === "INACTIVE"),
|
statusOrder: +(rest.status === "INACTIVE"),
|
||||||
code,
|
code: `${code?.toLocaleUpperCase()}${`${last.value - 1}`.padStart(6, "0")}`,
|
||||||
bank: bank ? { createMany: { data: bank } } : undefined,
|
bank: bank ? { createMany: { data: bank } } : undefined,
|
||||||
isHeadOffice: !headOfficeId,
|
isHeadOffice: !headOfficeId,
|
||||||
province: { connect: provinceId ? { id: provinceId } : undefined },
|
province: { connect: provinceId ? { id: provinceId } : undefined },
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue