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; 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; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index e444ae1..9cf97fd 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -398,14 +398,24 @@ 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? + provinceTextEN 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? + districtTextEN String? + district District? @relation(fields: [districtId], references: [id], onDelete: SetNull) + districtId String? + + subDistrictText String? + subDistrictTextEN String? + subDistrict SubDistrict? @relation(fields: [subDistrictId], references: [id], onDelete: SetNull) + subDistrictId String? + + zipCodeText String? email String telephoneNo String 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; } diff --git a/src/controllers/02-user-controller.ts b/src/controllers/02-user-controller.ts index 143eb71..e05fcd1 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,9 +123,16 @@ type UserCreate = { email: string; 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; + zipCodeText?: string | null; selectedImage?: string; @@ -173,6 +181,7 @@ type UserUpdate = { responsibleArea?: string[] | null; birthDate?: Date | null; + addressForeign?: boolean; address?: string; addressEN?: string; soi?: string | null; @@ -186,9 +195,16 @@ 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; + zipCodeText?: string | null; branchId?: string | string[]; 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", 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" }, + ], + }, }, });