From 236ee48eab8e79d3dae2861be14706cd7e2dc2c8 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 16 Jul 2025 09:38:30 +0700 Subject: [PATCH 1/8] feat: foreign address --- prisma/schema.prisma | 19 +++++++++++++------ src/controllers/02-user-controller.ts | 8 ++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index e444ae1..db3ea95 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -398,14 +398,21 @@ model User { street String? streetEN String? - province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull) - provinceId String? + addressForeign Boolean @default(false) - district District? @relation(fields: [districtId], references: [id], onDelete: SetNull) - districtId String? + provinceText String? + province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull) + provinceId String? - subDistrict SubDistrict? @relation(fields: [subDistrictId], references: [id], onDelete: SetNull) - subDistrictId String? + districtText String? + district District? @relation(fields: [districtId], references: [id], onDelete: SetNull) + districtId String? + + subDistrictText String? + subDistrict SubDistrict? @relation(fields: [subDistrictId], references: [id], onDelete: SetNull) + subDistrictId String? + + zipCodeText String? email String telephoneNo String diff --git a/src/controllers/02-user-controller.ts b/src/controllers/02-user-controller.ts index 143eb71..b00f650 100644 --- a/src/controllers/02-user-controller.ts +++ b/src/controllers/02-user-controller.ts @@ -111,6 +111,7 @@ type UserCreate = { responsibleArea?: string[] | null; birthDate?: Date | null; + addressForeign?: boolean; address: string; addressEN: string; soi?: string | null; @@ -122,8 +123,11 @@ type UserCreate = { email: string; telephoneNo: string; + subDistrictText?: string | null; subDistrictId?: string | null; + districtText?: string | null; districtId?: string | null; + provinceText?: string | null; provinceId?: string | null; selectedImage?: string; @@ -173,6 +177,7 @@ type UserUpdate = { responsibleArea?: string[] | null; birthDate?: Date | null; + addressForeign?: boolean; address?: string; addressEN?: string; soi?: string | null; @@ -186,8 +191,11 @@ type UserUpdate = { selectedImage?: string; + subDistrictText?: string | null; subDistrictId?: string | null; + districtText?: string | null; districtId?: string | null; + provinceText?: string | null; provinceId?: string | null; branchId?: string | string[]; From 2ee0e97953c9ac747ed7fb758bcfe261b96bfb24 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 16 Jul 2025 09:38:34 +0700 Subject: [PATCH 2/8] chore: migration --- .../20250716023822_allow_foreign_address/migration.sql | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 prisma/migrations/20250716023822_allow_foreign_address/migration.sql diff --git a/prisma/migrations/20250716023822_allow_foreign_address/migration.sql b/prisma/migrations/20250716023822_allow_foreign_address/migration.sql new file mode 100644 index 0000000..a255d89 --- /dev/null +++ b/prisma/migrations/20250716023822_allow_foreign_address/migration.sql @@ -0,0 +1,6 @@ +-- AlterTable +ALTER TABLE "User" ADD COLUMN "addressForeign" BOOLEAN NOT NULL DEFAULT false, +ADD COLUMN "districtText" TEXT, +ADD COLUMN "provinceText" TEXT, +ADD COLUMN "subDistrictText" TEXT, +ADD COLUMN "zipCodeText" TEXT; From f90ee41a56f17a07d2edb6c1a9a5af2d9b0e1fa9 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 16 Jul 2025 09:44:46 +0700 Subject: [PATCH 3/8] feat: add address text en --- prisma/schema.prisma | 21 ++++++++++++--------- src/controllers/02-user-controller.ts | 6 ++++++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index db3ea95..9cf97fd 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -400,17 +400,20 @@ model User { addressForeign Boolean @default(false) - provinceText String? - province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull) - provinceId String? + provinceText String? + provinceTextEN String? + province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull) + provinceId String? - districtText String? - district District? @relation(fields: [districtId], references: [id], onDelete: SetNull) - districtId String? + districtText String? + districtTextEN String? + district District? @relation(fields: [districtId], references: [id], onDelete: SetNull) + districtId String? - subDistrictText String? - subDistrict SubDistrict? @relation(fields: [subDistrictId], references: [id], onDelete: SetNull) - subDistrictId String? + subDistrictText String? + subDistrictTextEN String? + subDistrict SubDistrict? @relation(fields: [subDistrictId], references: [id], onDelete: SetNull) + subDistrictId String? zipCodeText String? diff --git a/src/controllers/02-user-controller.ts b/src/controllers/02-user-controller.ts index b00f650..c663b74 100644 --- a/src/controllers/02-user-controller.ts +++ b/src/controllers/02-user-controller.ts @@ -124,10 +124,13 @@ type UserCreate = { telephoneNo: string; subDistrictText?: string | null; + subDistrictTextEN?: string | null; subDistrictId?: string | null; districtText?: string | null; + districtTextEN?: string | null; districtId?: string | null; provinceText?: string | null; + provinceTextEN?: string | null; provinceId?: string | null; selectedImage?: string; @@ -192,10 +195,13 @@ type UserUpdate = { selectedImage?: string; subDistrictText?: string | null; + subDistrictTextEN?: string | null; subDistrictId?: string | null; districtText?: string | null; + districtTextEN?: string | null; districtId?: string | null; provinceText?: string | null; + provinceTextEN?: string | null; provinceId?: string | null; branchId?: string | string[]; From 5aa8b06cf2d1a848a2eb036d6e514b52eca24b88 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 16 Jul 2025 09:44:50 +0700 Subject: [PATCH 4/8] chore: migration --- .../20250716024423_add_address_text_en/migration.sql | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 prisma/migrations/20250716024423_add_address_text_en/migration.sql diff --git a/prisma/migrations/20250716024423_add_address_text_en/migration.sql b/prisma/migrations/20250716024423_add_address_text_en/migration.sql new file mode 100644 index 0000000..e55a4d0 --- /dev/null +++ b/prisma/migrations/20250716024423_add_address_text_en/migration.sql @@ -0,0 +1,4 @@ +-- AlterTable +ALTER TABLE "User" ADD COLUMN "districtTextEN" TEXT, +ADD COLUMN "provinceTextEN" TEXT, +ADD COLUMN "subDistrictTextEN" TEXT; From b7a13b2d7a44ad4af780463dcfe67f182314c2d3 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 16 Jul 2025 09:51:27 +0700 Subject: [PATCH 5/8] feat: handle foreign address --- src/controllers/00-doc-template-controller.ts | 47 +++++++++++++++---- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/src/controllers/00-doc-template-controller.ts b/src/controllers/00-doc-template-controller.ts index bda7956..da5dc9d 100644 --- a/src/controllers/00-doc-template-controller.ts +++ b/src/controllers/00-doc-template-controller.ts @@ -288,6 +288,7 @@ function replaceEmptyField(data: T): T { } type FullAddress = { + addressForeign?: boolean; address: string; addressEN: string; moo?: string; @@ -296,8 +297,14 @@ type FullAddress = { soiEN?: string; street?: string; streetEN?: string; + provinceText?: string | null; + provinceTextEN?: string | null; province?: Province | null; + districtText?: string | null; + districtTextEN?: string | null; district?: District | null; + subDistrictText?: string | null; + subDistrictTextEN?: string | null; subDistrict?: SubDistrict | null; en?: boolean; }; @@ -331,13 +338,22 @@ function addressFull(addr: FullAddress, lang: "th" | "en" = "en") { if (addr.soi) fragments.push(`ซอย ${addr.soi},`); if (addr.street) fragments.push(`ถนน${addr.street},`); - if (addr.subDistrict) { - fragments.push(`${addr.province?.id === "10" ? "แขวง" : "ตำบล"}${addr.subDistrict.name},`); + if (!addr.addressForeign && addr.subDistrict) { + fragments.push(`${addr.province?.id === "10" ? "แขวง" : "ตำบล"}${addr.subDistrict.name}`); } - if (addr.district) { - fragments.push(`${addr.province?.id === "10" ? "เขต" : "อำเภอ"}${addr.district.name},`); + if (addr.addressForeign && addr.subDistrictText) { + fragments.push(`ตำบล${addr.subDistrictText}`); } - if (addr.province) fragments.push(`จังหวัด${addr.province.name},`); + + if (!addr.addressForeign && addr.district) { + fragments.push(`${addr.province?.id === "10" ? "เขต" : "อำเภอ"}${addr.district.name}`); + } + if (addr.addressForeign && addr.districtText) { + fragments.push(`อำเภอ${addr.districtText}`); + } + + if (!addr.addressForeign && addr.province) fragments.push(`จังหวัด${addr.province.name}`); + if (addr.addressForeign && addr.provinceText) fragments.push(`จังหวัด${addr.provinceText}`); break; default: @@ -346,11 +362,26 @@ function addressFull(addr: FullAddress, lang: "th" | "en" = "en") { if (addr.soiEN) fragments.push(`Soi ${addr.soiEN},`); if (addr.streetEN) fragments.push(`${addr.streetEN} Rd.`); - if (addr.subDistrict) { + if (!addr.addressForeign && addr.subDistrict) { fragments.push(`${addr.subDistrict.nameEN} sub-district,`); } - if (addr.district) fragments.push(`${addr.district.nameEN} district,`); - if (addr.province) fragments.push(`${addr.province.nameEN},`); + if (addr.addressForeign && addr.subDistrictTextEN) { + fragments.push(`${addr.subDistrictTextEN} sub-district,`); + } + + if (!addr.addressForeign && addr.district) { + fragments.push(`${addr.district.nameEN} district,`); + } + if (addr.addressForeign && addr.districtTextEN) { + fragments.push(`${addr.districtTextEN} district,`); + } + + if (!addr.addressForeign && addr.province) { + fragments.push(`${addr.province.nameEN},`); + } + if (addr.addressForeign && addr.provinceTextEN) { + fragments.push(`${addr.provinceTextEN} district,`); + } break; } From 46ba857e2892fb2107a353566bedd8831c69f5ed Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 16 Jul 2025 11:38:11 +0700 Subject: [PATCH 6/8] fix: missing type --- src/controllers/02-user-controller.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/controllers/02-user-controller.ts b/src/controllers/02-user-controller.ts index c663b74..e05fcd1 100644 --- a/src/controllers/02-user-controller.ts +++ b/src/controllers/02-user-controller.ts @@ -132,6 +132,7 @@ type UserCreate = { provinceText?: string | null; provinceTextEN?: string | null; provinceId?: string | null; + zipCodeText?: string | null; selectedImage?: string; @@ -203,6 +204,7 @@ type UserUpdate = { provinceText?: string | null; provinceTextEN?: string | null; provinceId?: string | null; + zipCodeText?: string | null; branchId?: string | string[]; From e4caeaa7809af10c1b08581f4e556a62b066d3de Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 16 Jul 2025 12:54:52 +0700 Subject: [PATCH 7/8] fix: new request does not trigger noti --- src/controllers/05-payment-controller.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/05-payment-controller.ts b/src/controllers/05-payment-controller.ts index 196054f..5f530d0 100644 --- a/src/controllers/05-payment-controller.ts +++ b/src/controllers/05-payment-controller.ts @@ -249,7 +249,7 @@ export class QuotationPayment extends Controller { }, }); - if (quotation.quotationStatus === "PaymentPending") { + if (quotation.quotationStatus === "PaymentInProcess") { await prisma.notification.create({ data: { title: "รายการคำขอใหม่ / New Request", From 5c824a738aac25d81aa0406f98bf797d2d55fdf6 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 16 Jul 2025 12:59:15 +0700 Subject: [PATCH 8/8] feat: notify more group when create new quotation --- src/controllers/05-quotation-controller.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/controllers/05-quotation-controller.ts b/src/controllers/05-quotation-controller.ts index 04353bb..29face5 100644 --- a/src/controllers/05-quotation-controller.ts +++ b/src/controllers/05-quotation-controller.ts @@ -664,7 +664,14 @@ export class QuotationController extends Controller { title: "ใบเสนอราคาใหม่ / New Quotation", detail: "รหัส / code : " + ret.code, registeredBranchId: ret.registeredBranchId, - groupReceiver: { create: [{ name: "sale" }, { name: "head_of_sale" }] }, + groupReceiver: { + create: [ + { name: "sale" }, + { name: "head_of_sale" }, + { name: "accountant" }, + { name: "branch_accountant" }, + ], + }, }, });