jws-backend/prisma/schema.prisma

1791 lines
49 KiB
Text
Raw Permalink Normal View History

2024-04-01 13:28:43 +07:00
generator client {
2024-11-13 13:43:09 +07:00
provider = "prisma-client-js"
previewFeatures = ["relationJoins"]
2024-04-01 13:28:43 +07:00
}
2024-06-26 11:22:48 +07:00
generator kysely {
provider = "prisma-kysely"
2024-06-26 11:53:25 +07:00
output = "../src/generated/kysely"
2024-06-26 11:22:48 +07:00
}
2024-04-01 13:28:43 +07:00
datasource db {
provider = "postgresql"
2026-01-12 13:48:10 +07:00
url = env("DATABASE_URL")
2024-04-01 13:28:43 +07:00
}
model Notification {
id String @id @default(cuid())
title String
detail String
groupReceiver NotificationGroup[]
2025-03-05 11:16:18 +07:00
registeredBranchId String?
registeredBranch Branch? @relation(fields: [registeredBranchId], references: [id])
receiver User? @relation(name: "NotificationReceiver", fields: [receiverId], references: [id], onDelete: Cascade)
receiverId String?
createdAt DateTime @default(now())
2025-03-05 17:18:25 +07:00
readByUser User[] @relation(name: "NotificationRead")
deleteByUser User[] @relation(name: "NotificationDelete")
}
model NotificationGroup {
id String @id @default(cuid())
name String
notification Notification[]
}
2024-04-17 13:42:01 +07:00
model Menu {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-04-17 13:42:01 +07:00
caption String
captionEN String
menuType String
url String
createdBy String?
createdAt DateTime @default(now())
2024-07-01 13:24:02 +07:00
updatedBy String?
2024-04-17 13:42:01 +07:00
updatedAt DateTime @updatedAt
parent Menu? @relation(name: "MenuRelation", fields: [parentId], references: [id])
parentId String?
children Menu[] @relation(name: "MenuRelation")
roleMenuPermission RoleMenuPermission[]
userMenuPermission UserMenuPermission[]
userComponent MenuComponent[]
}
model RoleMenuPermission {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-04-17 13:42:01 +07:00
userRole String
permission String
menu Menu @relation(fields: [menuId], references: [id])
menuId String
createdBy String?
createdAt DateTime @default(now())
2024-07-01 13:24:02 +07:00
updatedBy String?
2024-04-17 13:42:01 +07:00
updatedAt DateTime @updatedAt
}
model UserMenuPermission {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-04-17 13:42:01 +07:00
permission String
menu Menu @relation(fields: [menuId], references: [id])
menuId String
user User @relation(fields: [userId], references: [id])
userId String
createdBy String?
createdAt DateTime @default(now())
2024-07-01 13:24:02 +07:00
updatedBy String?
2024-04-17 13:42:01 +07:00
updatedAt DateTime @updatedAt
}
model MenuComponent {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-04-17 13:42:01 +07:00
componentId String
componentTag String
menu Menu @relation(fields: [menuId], references: [id])
menuId String
createdBy String?
createdAt DateTime @default(now())
2024-07-01 13:24:02 +07:00
updatedBy String?
2024-04-17 13:42:01 +07:00
updatedAt DateTime @updatedAt
roleMenuComponentPermission RoleMenuComponentPermission[]
userMennuComponentPermission UserMenuComponentPermission[]
}
model RoleMenuComponentPermission {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-04-17 13:42:01 +07:00
2024-04-18 13:09:14 +07:00
userRole String
permission String
2024-04-17 13:42:01 +07:00
menuComponent MenuComponent @relation(fields: [menuComponentId], references: [id])
menuComponentId String
createdBy String?
createdAt DateTime @default(now())
2024-07-01 13:24:02 +07:00
updatedBy String?
2024-04-17 13:42:01 +07:00
updatedAt DateTime @updatedAt
}
2024-04-22 16:20:45 +07:00
model RunningNo {
key String @id @unique
value Int
}
2024-04-17 13:42:01 +07:00
model UserMenuComponentPermission {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-04-17 13:42:01 +07:00
userId String
user User @relation(fields: [userId], references: [id])
menuComponent MenuComponent @relation(fields: [menuComponentId], references: [id])
menuComponentId String
permission String
createdBy String?
createdAt DateTime @default(now())
2024-07-01 13:24:02 +07:00
updatedBy String?
2024-04-17 13:42:01 +07:00
updatedAt DateTime @updatedAt
}
2024-04-01 13:28:43 +07:00
model Province {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
name String
2024-04-01 13:28:43 +07:00
nameEN String
createdBy String?
createdAt DateTime @default(now())
2024-07-01 13:24:02 +07:00
updatedBy String?
2024-04-01 13:28:43 +07:00
updatedAt DateTime @updatedAt
2024-09-17 10:39:22 +07:00
district District[]
branch Branch[]
user User[]
customerBranch CustomerBranch[]
employee Employee[]
employeeCheckup EmployeeCheckup[]
customerBranchCitizen CustomerBranchCitizen[]
customerBranchHouseRegis CustomerBranchHouseRegis[]
2024-11-05 09:36:01 +07:00
institution Institution[]
employmentOffice EmploymentOffice[]
2024-04-01 13:28:43 +07:00
}
model District {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
name String
2024-04-01 13:28:43 +07:00
nameEN String
provinceId String
province Province @relation(fields: [provinceId], references: [id], onDelete: Cascade)
createdBy String?
createdAt DateTime @default(now())
2024-07-01 13:24:02 +07:00
updatedBy String?
2024-04-01 13:28:43 +07:00
updatedAt DateTime @updatedAt
2024-09-17 10:39:22 +07:00
subDistrict SubDistrict[]
branch Branch[]
user User[]
customerBranch CustomerBranch[]
employee Employee[]
2024-11-14 09:37:22 +07:00
customerBranchCitizen CustomerBranchCitizen[]
customerBranchHouseRegis CustomerBranchHouseRegis[]
2024-11-05 09:36:01 +07:00
institution Institution[]
employmentOffice EmploymentOfficeDistrict[]
2024-04-01 13:28:43 +07:00
}
model SubDistrict {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
name String
2024-04-01 13:28:43 +07:00
nameEN String
zipCode String
district District @relation(fields: [districtId], references: [id], onDelete: Cascade)
districtId String
createdBy String?
createdAt DateTime @default(now())
2024-07-01 13:24:02 +07:00
updatedBy String?
2024-04-01 13:28:43 +07:00
updatedAt DateTime @updatedAt
2024-09-17 10:39:22 +07:00
branch Branch[]
user User[]
customerBranch CustomerBranch[]
employee Employee[]
2024-11-05 09:35:05 +07:00
customerBranchCitizen CustomerBranchCitizen[]
customerBranchHouseRegis CustomerBranchHouseRegis[]
2024-11-05 09:36:01 +07:00
institution Institution[]
2024-04-01 13:28:43 +07:00
}
model EmploymentOffice {
id String @id @default(cuid())
name String
nameEN String
provinceId String
province Province @relation(fields: [provinceId], references: [id])
district EmploymentOfficeDistrict[]
}
model EmploymentOfficeDistrict {
areaId String
area EmploymentOffice @relation(fields: [areaId], references: [id])
districtId String
district District @relation(fields: [districtId], references: [id])
@@id([areaId, districtId])
}
2024-04-02 10:48:35 +07:00
enum Status {
CREATED
2024-04-05 10:41:03 +07:00
ACTIVE
INACTIVE
2024-04-02 10:48:35 +07:00
}
2024-04-01 13:28:43 +07:00
model Branch {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-04-18 13:09:14 +07:00
code String
taxNo String
name String
nameEN String
2024-04-18 13:21:37 +07:00
telephoneNo String
2024-04-01 13:28:43 +07:00
2024-09-12 09:48:56 +07:00
permitNo String
2024-12-11 09:04:48 +07:00
permitIssueDate DateTime? @db.Date
permitExpireDate DateTime? @db.Date
2024-09-12 09:48:56 +07:00
2024-09-11 15:06:27 +07:00
address String
addressEN String
soi String?
soiEN String?
moo String?
mooEN String?
street String?
streetEN String?
2024-04-01 13:28:43 +07:00
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
provinceId String?
district District? @relation(fields: [districtId], references: [id], onDelete: SetNull)
districtId String?
subDistrict SubDistrict? @relation(fields: [subDistrictId], references: [id], onDelete: SetNull)
subDistrictId String?
email String
2024-04-17 13:42:01 +07:00
contactName String?
2024-04-17 11:22:12 +07:00
lineId String?
2024-08-29 11:53:00 +07:00
webUrl String?
2024-04-01 13:28:43 +07:00
latitude String
longitude String
isHeadOffice Boolean @default(false)
headOffice Branch? @relation(name: "HeadOfficeRelation", fields: [headOfficeId], references: [id])
headOfficeId String?
2024-09-03 16:54:52 +07:00
virtual Boolean?
2024-09-09 14:58:42 +07:00
selectedImage String?
2024-09-24 09:56:05 +07:00
remark String?
bank BranchBank[]
2024-06-24 13:14:44 +07:00
status Status @default(CREATED)
statusOrder Int @default(0)
2024-04-01 13:28:43 +07:00
2024-07-01 13:24:02 +07:00
createdAt DateTime @default(now())
createdBy User? @relation(name: "BranchCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
createdByUserId String?
updatedAt DateTime @updatedAt
updatedBy User? @relation(name: "BranchUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
updatedByUserId String?
2024-04-01 13:28:43 +07:00
branch Branch[] @relation(name: "HeadOfficeRelation")
contact BranchContact[]
user BranchUser[]
customerRegistration Customer[]
2024-09-10 13:33:44 +07:00
productGroup ProductGroup[]
quotation Quotation[]
2024-10-24 15:56:03 +07:00
workflowTemplate WorkflowTemplate[]
2024-12-03 17:11:44 +07:00
taskOrder TaskOrder[]
2025-03-05 11:16:18 +07:00
notification Notification[]
2025-03-10 15:12:30 +07:00
property Property[]
2024-04-01 13:28:43 +07:00
}
model BranchBank {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
bankName String
2024-08-02 17:30:29 +07:00
bankBranch String
accountName String
accountNumber String
2024-08-02 17:30:29 +07:00
accountType String
currentlyUse Boolean
2024-08-02 17:30:29 +07:00
branch Branch @relation(fields: [branchId], references: [id], onDelete: Cascade)
branchId String
}
2024-04-01 13:28:43 +07:00
model BranchContact {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-04-02 10:48:35 +07:00
telephoneNo String
2024-04-01 13:28:43 +07:00
branch Branch @relation(fields: [branchId], references: [id], onDelete: Cascade)
branchId String
}
model BranchUser {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-04-01 13:28:43 +07:00
branch Branch @relation(fields: [branchId], references: [id], onDelete: Cascade)
branchId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
2024-07-01 13:24:02 +07:00
createdAt DateTime @default(now())
createdBy User? @relation(name: "BranchUserCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
createdByUserId String?
updatedAt DateTime @updatedAt
updatedBy User? @relation(name: "BranchUserUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
updatedByUserId String?
2024-04-01 13:28:43 +07:00
}
2024-04-09 13:05:49 +07:00
enum UserType {
USER
MESSENGER
DELEGATE
AGENCY
}
model UserImportNationality {
id String @id @default(cuid())
name String
2025-06-30 16:13:57 +07:00
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
}
2024-04-01 13:28:43 +07:00
model User {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-04-01 13:28:43 +07:00
code String?
namePrefix String?
2025-04-11 11:28:24 +07:00
firstName String?
firstNameEN String
middleName String?
middleNameEN String?
2025-04-11 11:28:24 +07:00
lastName String?
lastNameEN String
username String
gender String
2024-04-01 13:28:43 +07:00
2024-04-04 15:27:57 +07:00
address String
2024-04-01 13:28:43 +07:00
addressEN String
2024-09-11 15:06:27 +07:00
soi String?
soiEN String?
moo String?
mooEN String?
street String?
streetEN String?
2025-07-16 09:38:30 +07:00
addressForeign Boolean @default(false)
2024-04-01 13:28:43 +07:00
2025-07-16 09:44:46 +07:00
provinceText String?
provinceTextEN String?
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
provinceId 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?
2025-07-16 09:38:30 +07:00
zipCodeText String?
2024-04-01 13:28:43 +07:00
email String
telephoneNo String
registrationNo String?
2024-04-01 13:28:43 +07:00
startDate DateTime? @db.Date
retireDate DateTime? @db.Date
2024-04-01 13:28:43 +07:00
2024-04-17 16:21:53 +07:00
checkpoint String?
checkpointEN String?
2024-04-09 13:05:49 +07:00
userType UserType
2024-04-01 13:28:43 +07:00
userRole String
2024-09-12 09:48:56 +07:00
citizenId String
citizenIssue DateTime @db.Date
citizenExpire DateTime? @db.Date
2024-09-11 15:06:27 +07:00
discountCondition String?
2024-04-01 13:28:43 +07:00
licenseNo String?
licenseIssueDate DateTime? @db.Date
licenseExpireDate DateTime? @db.Date
2024-04-01 13:28:43 +07:00
sourceNationality String?
importNationality UserImportNationality[]
2024-04-01 13:28:43 +07:00
2024-04-10 11:37:12 +07:00
trainingPlace String?
responsibleArea UserResponsibleArea[]
2024-04-10 11:37:12 +07:00
birthDate DateTime? @db.Date
2024-04-01 13:28:43 +07:00
selectedImage String?
2024-06-24 13:14:44 +07:00
status Status @default(CREATED)
statusOrder Int @default(0)
2024-04-01 13:28:43 +07:00
2024-07-01 13:24:02 +07:00
createdAt DateTime @default(now())
createdBy User? @relation(name: "UserCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
createdByUserId String?
updatedAt DateTime @updatedAt
updatedBy User? @relation(name: "UserUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
updatedByUserId String?
2024-04-01 13:28:43 +07:00
2024-04-17 13:42:01 +07:00
branch BranchUser[]
userMenuPermission UserMenuPermission[]
userMenuComponentPermission UserMenuComponentPermission[]
2024-10-07 11:58:43 +07:00
workflowTemplateStepUser WorkflowTemplateStepUser[]
requestWork RequestWork[]
2024-10-28 10:51:51 +07:00
customerBranch CustomerBranch[]
2024-07-01 13:24:02 +07:00
userCreated User[] @relation("UserCreatedByUser")
userUpdated User[] @relation("UserUpdatedByUser")
branchCreated Branch[] @relation("BranchCreatedByUser")
branchUpdated Branch[] @relation("BranchUpdatedByUser")
branchUserCreated BranchUser[] @relation("BranchUserCreatedByUser")
branchUserUpdated BranchUser[] @relation("BranchUserUpdatedByUser")
customerCreated Customer[] @relation("CustomerCreatedByUser")
customerUpdated Customer[] @relation("CustomerUpdatedByUser")
customerBranchCreated CustomerBranch[] @relation("CustomerBranchCreatedByUser")
customerBranchUpdated CustomerBranch[] @relation("CustomerBranchUpdatedByUser")
2024-10-29 14:52:51 +07:00
employeeCreated Employee[] @relation("EmployeeCreatedByUser")
2024-11-11 14:38:10 +07:00
employeeUpdated Employee[] @relation("EmployeeUpdatedByUser")
2024-07-01 13:24:02 +07:00
employeeHistoryUpdated EmployeeHistory[] @relation("EmployeeHistoryUpdatedByUser")
employeeCheckupCreated EmployeeCheckup[] @relation("EmployeeCheckupCreatedByUser")
employeeCheckupUpdated EmployeeCheckup[] @relation("EmployeeCheckupUpdatedByUser")
employeeWorkCreated EmployeeWork[] @relation("EmployeeWorkCreatedByUser")
employeeWorkUpdated EmployeeWork[] @relation("EmployeeWorkUpdatedByUser")
employeeOtherInfoCreated EmployeeOtherInfo[] @relation("EmployeeOtherInfoCreatedByUser")
employeeOtherInfoUpdated EmployeeOtherInfo[] @relation("EmployeeOtherInfoUpdatedByUser")
serviceCreated Service[] @relation("ServiceCreatedByUser")
serviceUpdated Service[] @relation("ServiceUpdatedByUser")
workCreated Work[] @relation("WorkCreatedByUser")
workUpdated Work[] @relation("WorkUpdatedByUser")
workProductCreated WorkProduct[] @relation("WorkProductCreatedByUser")
workProductUpdated WorkProduct[] @relation("WorkProductUpdatedByUser")
productGroupCreated ProductGroup[] @relation("ProductGroupCreatedByUser")
productGroupUpdated ProductGroup[] @relation("ProductGroupUpdatedByUser")
productCreated Product[] @relation("ProductCreatedByUser")
productUpdated Product[] @relation("ProductUpdatedByUser")
2024-07-18 17:23:41 +07:00
quotationCreated Quotation[] @relation("QuotationCreatedByUser")
quotationUpdated Quotation[] @relation("QuotationUpdatedByUser")
2024-10-07 11:58:43 +07:00
flowCreated WorkflowTemplate[] @relation("FlowCreatedByUser")
flowUpdated WorkflowTemplate[] @relation("FlowUpdatedByUser")
2024-10-25 13:58:29 +07:00
invoiceCreated Invoice[]
paymentCreated Payment[] @relation("PaymentCreatedByUser")
paymentUpdated Payment[] @relation("PaymentUpdatedByUser")
notificationReceive Notification[] @relation("NotificationReceiver")
2025-03-05 17:18:25 +07:00
notificationRead Notification[] @relation("NotificationRead")
notificationDelete Notification[] @relation("NotificationDelete")
taskOrderCreated TaskOrder[] @relation("TaskOrderCreatedByUser")
2025-01-07 15:56:18 +07:00
creditNoteCreated CreditNote[] @relation("CreditNoteCreatedByUser")
institutionCreated Institution[] @relation("InstitutionCreatedByUser")
institutionUpdated Institution[] @relation("InstitutionUpdatedByUser")
2025-07-09 15:21:00 +07:00
businessTypeCreated BusinessType[] @relation("BusinessTypeCreatedByUser")
businessTypeUpdated BusinessType[] @relation("BusinessTypeUpdatedByUser")
2024-12-03 09:56:33 +07:00
requestWorkStepStatus RequestWorkStepStatus[]
2024-12-11 14:44:09 +07:00
userTask UserTask[]
2025-04-04 14:46:51 +07:00
requestData RequestData[]
remark String?
agencyStatus String?
2025-04-11 11:28:24 +07:00
contactName String?
contactTel String?
2025-07-04 14:08:24 +07:00
quotation Quotation[]
2024-04-01 13:28:43 +07:00
}
model UserResponsibleArea {
id String @id @default(cuid())
area String
user User[]
}
2024-04-09 13:56:15 +07:00
enum CustomerType {
CORP
PERS
}
2024-04-01 13:28:43 +07:00
model Customer {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
customerType CustomerType
2024-04-01 13:28:43 +07:00
2024-06-24 13:14:44 +07:00
status Status @default(CREATED)
statusOrder Int @default(0)
2024-04-01 13:28:43 +07:00
2024-09-12 15:08:07 +07:00
registeredBranchId String
registeredBranch Branch @relation(fields: [registeredBranchId], references: [id])
2024-09-10 09:56:46 +07:00
selectedImage String?
2024-07-01 13:24:02 +07:00
createdAt DateTime @default(now())
createdBy User? @relation(name: "CustomerCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
createdByUserId String?
updatedAt DateTime @updatedAt
updatedBy User? @relation(name: "CustomerUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
updatedByUserId String?
2024-04-01 13:28:43 +07:00
2024-09-30 09:48:35 +07:00
branch CustomerBranch[]
2024-04-01 13:28:43 +07:00
}
model CustomerBranch {
2025-07-09 15:21:00 +07:00
id String @id @default(cuid())
customer Customer @relation(fields: [customerId], references: [id], onDelete: Cascade)
customerId String
2024-04-01 13:28:43 +07:00
2024-08-23 10:33:53 +07:00
code String
codeCustomer String
2024-04-01 13:28:43 +07:00
2024-09-13 13:27:12 +07:00
telephoneNo String
feat: line (#13) * add wedhook line * text message * add router get employee, request, quotation * move code * do not crash application when not set line token This feature is opt-in * dot not crash when not set line client id Main auth method is keycloak * change dotenv * fix: wrong env * refactor: change to get instead of post * refactor: remove body for employee get endpoint * feat: add work relation include * feat: include customer relation in employee * feat: add line file controller * add detail flex message and get date requestWork * chore: update deps lock * fix: error line token * fix: redirect head instead if response with body * feat: add response relation * fix: route casing * add userId in customerBranch verifyOTP * delete consile log * add is registered endpoint placeholder * feat: quotation list * fix: wrong endpoint name * feat: include relation in get by id request data * add where userId line * refactor: adjust parameter for liff app * delete code * refactor: remove post quotation endpoint * refactor: add where userId line for quotation * feat: add pending only parameter * refactor: more condition for inProgressOnly * refactor: update condition * feat: add line quotation attachment endpoint * feat: include product in request work line endpoint * refactor: pending only now cover more condition * feat: include invoice with payment relation * chore: update api docs tag * chore: clean * feat: check for registered user * fix: wrong file location * feat: add email client for sending an otp * chore: move some deps to dev deps * add otpCode otpExpires * add send-otp and verify-otp --------- Co-authored-by: Kanjana <kanjana@chamomind.com> Co-authored-by: chamomind <chamomind@localhost> Co-authored-by: Methapon2001 <61303214+Methapon2001@users.noreply.github.com>
2025-02-20 16:07:16 +07:00
userId String?
otpCode String?
otpExpires DateTime?
// NOTE: About (Natural Person)
2024-09-13 13:27:12 +07:00
namePrefix String?
firstName String?
firstNameEN String?
lastName String?
lastNameEN String?
gender String?
birthDate DateTime? @db.Date
citizenId String?
// NOTE: About (Legal Entity)
legalPersonNo String?
registerName String?
registerNameEN String?
registerDate DateTime? @db.Date
authorizedCapital String?
2024-09-16 11:03:34 +07:00
authorizedName String?
authorizedNameEN String?
2024-09-16 11:03:34 +07:00
// NOTE: Address
homeCode String
employmentOffice String
employmentOfficeEN String
address String
addressEN String
2024-04-01 13:28:43 +07:00
2024-09-11 15:06:27 +07:00
soi String?
soiEN String?
moo String?
mooEN String?
street String?
streetEN String?
2024-04-01 13:28:43 +07:00
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
provinceId String?
district District? @relation(fields: [districtId], references: [id], onDelete: SetNull)
districtId String?
subDistrict SubDistrict? @relation(fields: [subDistrictId], references: [id], onDelete: SetNull)
subDistrictId String?
2024-09-16 11:03:34 +07:00
// NOTE: contact
2024-04-01 13:28:43 +07:00
email String
2024-09-16 11:03:34 +07:00
contactTel String
officeTel String
2024-08-21 16:52:59 +07:00
contactName String
2024-10-28 10:51:51 +07:00
agentUserId String?
agentUser User? @relation(fields: [agentUserId], references: [id], onDelete: SetNull)
2024-09-16 11:03:34 +07:00
// NOTE: Business
2025-07-09 15:21:00 +07:00
businessTypeId String?
businessType BusinessType? @relation(fields: [businessTypeId], references: [id], onDelete: SetNull)
2024-09-16 11:03:34 +07:00
jobPosition String
jobDescription String
payDate String
payDateEN String
wageRate Int
wageRateText String
2024-04-01 13:28:43 +07:00
2024-06-24 13:14:44 +07:00
status Status @default(CREATED)
statusOrder Int @default(0)
2024-04-04 17:42:52 +07:00
2024-07-01 13:24:02 +07:00
createdAt DateTime @default(now())
createdBy User? @relation(name: "CustomerBranchCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
createdByUserId String?
updatedAt DateTime @updatedAt
updatedBy User? @relation(name: "CustomerBranchUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
updatedByUserId String?
2024-04-01 13:28:43 +07:00
2024-07-18 17:23:41 +07:00
employee Employee[]
quotation Quotation[]
2024-09-17 10:57:42 +07:00
citizen CustomerBranchCitizen[]
poa CustomerBranchPoa[]
houseRegis CustomerBranchHouseRegis[]
commercialRegis CustomerBranchCommercialRegis[]
vatRegis CustomerBranchVatRegis[]
2024-04-01 13:28:43 +07:00
}
2024-09-17 10:39:22 +07:00
model CustomerBranchCitizen {
2024-09-19 14:06:36 +07:00
id String @id @default(cuid())
citizenId String
birthDate DateTime? @db.Date
2024-09-17 10:39:22 +07:00
namePrefix String?
firstName String
firstNameEN String?
middleName String?
middleNameEN String?
lastName String
lastNameEN String?
2024-09-19 14:06:36 +07:00
issueDate DateTime @db.Date
expireDate DateTime @db.Date
2024-09-17 10:39:22 +07:00
nationality String
religion String
gender String
address String?
addressEN String?
soi String?
soiEN String?
moo String?
mooEN String?
street String?
streetEN String?
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
provinceId String?
district District? @relation(fields: [districtId], references: [id], onDelete: SetNull)
districtId String?
subDistrict SubDistrict? @relation(fields: [subDistrictId], references: [id], onDelete: SetNull)
subDistrictId String?
2024-09-17 10:45:21 +07:00
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
2024-09-17 10:57:42 +07:00
customerBranchId String
2024-09-25 16:42:02 +07:00
customerBranch CustomerBranch @relation(fields: [customerBranchId], references: [id], onDelete: Cascade)
2024-09-17 10:39:22 +07:00
}
model CustomerBranchPoa {
2024-09-17 10:45:21 +07:00
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
2024-09-17 10:57:42 +07:00
customerBranchId String
2024-09-25 16:42:02 +07:00
customerBranch CustomerBranch @relation(fields: [customerBranchId], references: [id], onDelete: Cascade)
2024-09-17 10:39:22 +07:00
}
model CustomerBranchHouseRegis {
id String @id @default(cuid())
registrationOffice String
houseId String
houseNo String
villageNo String
address String?
addressEN String?
soi String?
soiEN String?
moo String?
mooEN String?
street String?
streetEN String?
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
provinceId String?
district District? @relation(fields: [districtId], references: [id], onDelete: SetNull)
districtId String?
subDistrict SubDistrict? @relation(fields: [subDistrictId], references: [id], onDelete: SetNull)
subDistrictId String?
namePrefix String?
firstName String
firstNameEN String?
middleName String?
middleNameEN String?
lastName String
lastNameEN String?
issueDate DateTime @db.Date
expireDate DateTime @db.Date
nationality String
religion String
gender String
marriageStatus String
citizenId String
birthDate DateTime @db.Date
motherFullName String
motherFullNameEN String?
motherCitizenId String
motherNationality String?
fatherFullName String
fatherFullNameEN String?
fatherCitizenId String
fatherNationality String?
2024-09-17 10:45:21 +07:00
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
2024-09-17 10:57:42 +07:00
customerBranchId String
2024-09-25 16:42:02 +07:00
customerBranch CustomerBranch @relation(fields: [customerBranchId], references: [id], onDelete: Cascade)
2024-09-17 10:39:22 +07:00
}
enum CommercialType {
CORP
PERS
}
model CustomerBranchCommercialRegis {
id String @id @default(cuid())
registrationNo String
registrationType CommercialType
requestNo String? // NOTE: CORP only
namePrefix String? // NOTE: PERS only
fullName String
fullNameEN String
registrationDate String
romanLetter String?
2024-09-17 10:45:21 +07:00
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
2024-09-17 10:57:42 +07:00
customerBranchId String
2024-09-25 16:42:02 +07:00
customerBranch CustomerBranch @relation(fields: [customerBranchId], references: [id], onDelete: Cascade)
2024-09-17 10:39:22 +07:00
}
model CustomerBranchVatRegis {
2024-09-17 10:45:21 +07:00
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
2024-09-17 10:57:42 +07:00
customerBranchId String
2024-09-25 16:42:02 +07:00
customerBranch CustomerBranch @relation(fields: [customerBranchId], references: [id], onDelete: Cascade)
2024-09-17 10:39:22 +07:00
}
2025-07-09 15:21:00 +07:00
model BusinessType {
id String @id @default(cuid())
name String
nameEN String
createdAt DateTime @default(now())
createdBy User? @relation(name: "BusinessTypeCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
createdByUserId String?
updatedAt DateTime @updatedAt
updatedBy User? @relation(name: "BusinessTypeUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
updatedByUserId String?
customerBranch CustomerBranch[]
}
2024-04-01 13:28:43 +07:00
model Employee {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-04-01 13:28:43 +07:00
2024-08-27 14:27:39 +07:00
code String
nrcNo String?
namePrefix String?
firstName String?
2024-08-27 14:27:39 +07:00
firstNameEN String
middleName String?
middleNameEN String?
lastName String?
2025-04-22 09:47:17 +07:00
lastNameEN String?
2024-04-04 17:42:52 +07:00
dateOfBirth DateTime? @db.Date
gender String
nationality String
otherNationality String?
2024-04-01 13:28:43 +07:00
2024-06-12 17:01:42 +07:00
address String?
addressEN String?
2024-04-01 13:28:43 +07:00
2024-09-11 15:06:27 +07:00
soi String?
soiEN String?
moo String?
mooEN String?
street String?
streetEN String?
2024-04-01 13:28:43 +07:00
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
provinceId String?
district District? @relation(fields: [districtId], references: [id], onDelete: SetNull)
districtId String?
subDistrict SubDistrict? @relation(fields: [subDistrictId], references: [id], onDelete: SetNull)
subDistrictId String?
2024-09-13 17:39:12 +07:00
workerType String?
workerStatus String?
2024-04-01 13:28:43 +07:00
2024-09-06 11:56:37 +07:00
customerBranch CustomerBranch @relation(fields: [customerBranchId], references: [id], onDelete: Cascade)
customerBranchId String
2024-04-01 13:28:43 +07:00
2024-09-11 13:30:56 +07:00
status Status @default(CREATED)
statusOrder Int @default(0)
selectedImage String?
2024-04-01 13:28:43 +07:00
2024-07-01 13:24:02 +07:00
createdAt DateTime @default(now())
createdBy User? @relation(name: "EmployeeCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
createdByUserId String?
updatedAt DateTime @updatedAt
updatedBy User? @relation(name: "EmployeeUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
updatedByUserId String?
2024-04-01 13:28:43 +07:00
2024-11-11 13:47:41 +07:00
employeePassport EmployeePassport[]
employeeVisa EmployeeVisa[]
employeeCheckup EmployeeCheckup[]
employeeWork EmployeeWork[]
employeeOtherInfo EmployeeOtherInfo?
2024-06-28 08:57:53 +07:00
2024-10-04 16:39:37 +07:00
editHistory EmployeeHistory[]
quotationWorker QuotationWorker[]
quotationProductServiceWorker QuotationProductServiceWorker[]
2024-10-09 15:04:59 +07:00
requestData RequestData[]
2024-06-28 08:57:53 +07:00
}
model EmployeeHistory {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-06-28 08:57:53 +07:00
field String
valueBefore Json
valueAfter Json
2024-07-01 13:24:02 +07:00
updatedAt DateTime @updatedAt
updatedBy User? @relation(name: "EmployeeHistoryUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
2024-06-28 09:31:17 +07:00
updatedByUserId String?
2024-06-28 08:57:53 +07:00
masterId String
master Employee @relation(fields: [masterId], references: [id], onDelete: Cascade)
2024-04-01 13:28:43 +07:00
}
2024-09-13 17:39:12 +07:00
model EmployeePassport {
id String @id @default(cuid())
number String
type String
issueDate DateTime @db.Date
expireDate DateTime @db.Date
issueCountry String
issuePlace String
previousPassportRef String?
workerStatus String?
nationality String?
otherNationality String?
namePrefix String?
firstName String?
firstNameEN String?
middleName String?
middleNameEN String?
lastName String?
lastNameEN String?
gender String?
birthDate String?
birthCountry String?
2024-11-11 13:25:04 +07:00
2024-09-18 09:25:19 +07:00
employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade)
2024-09-13 17:39:12 +07:00
employeeId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model EmployeeVisa {
id String @id @default(cuid())
number String
type String
entryCount Int
issueCountry String
issuePlace String
2025-07-09 15:21:00 +07:00
issueDate DateTime @db.Date
expireDate DateTime @db.Date
reportDate DateTime? @db.Date
2024-09-13 17:39:12 +07:00
mrz String?
remark String?
2024-11-11 13:38:28 +07:00
arrivalTM String?
arrivalTMNo String?
arrivalAt String?
workerType String?
2024-09-18 09:25:19 +07:00
employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade)
2024-09-13 17:39:12 +07:00
employeeId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
2024-04-01 13:28:43 +07:00
model EmployeeCheckup {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-04-01 13:28:43 +07:00
employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade)
employeeId String
2024-06-11 11:27:00 +07:00
checkupResult String?
checkupType String?
2024-04-01 13:28:43 +07:00
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
provinceId String?
2024-06-11 11:27:00 +07:00
hospitalName String?
remark String?
medicalBenefitScheme String?
insuranceCompany String?
coverageStartDate DateTime? @db.Date
coverageExpireDate DateTime? @db.Date
2024-04-01 13:28:43 +07:00
2024-07-01 13:24:02 +07:00
createdAt DateTime @default(now())
createdBy User? @relation(name: "EmployeeCheckupCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
createdByUserId String?
updatedAt DateTime @updatedAt
updatedBy User? @relation(name: "EmployeeCheckupUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
updatedByUserId String?
2024-04-01 13:28:43 +07:00
}
model EmployeeWork {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-04-01 13:28:43 +07:00
employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade)
employeeId String
2024-06-11 11:27:00 +07:00
ownerName String?
positionName String?
jobType String?
workplace String?
2024-11-11 13:54:47 +07:00
identityNo String?
2024-06-11 11:27:00 +07:00
workPermitNo String?
2024-10-30 09:02:29 +07:00
workPermitIssueDate DateTime? @db.Date
workPermitExpireDate DateTime? @db.Date
2024-11-12 11:02:44 +07:00
workPermitAt String?
2024-04-01 13:28:43 +07:00
2024-07-01 13:24:02 +07:00
createdAt DateTime @default(now())
createdBy User? @relation(name: "EmployeeWorkCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
createdByUserId String?
updatedAt DateTime @updatedAt
updatedBy User? @relation(name: "EmployeeWorkUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
updatedByUserId String?
2024-04-01 13:28:43 +07:00
}
model EmployeeOtherInfo {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-04-01 13:28:43 +07:00
employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade)
2024-08-05 10:59:44 +07:00
employeeId String @unique
2024-04-01 13:28:43 +07:00
2024-11-11 14:32:06 +07:00
telephoneNo String?
citizenId String?
2024-06-11 11:27:00 +07:00
fatherBirthPlace String?
fatherFirstName String?
fatherLastName String?
motherBirthPlace String?
motherFirstName String?
motherLastName String?
fatherFirstNameEN String?
fatherLastNameEN String?
motherFirstNameEN String?
motherLastNameEN String?
2024-04-01 13:28:43 +07:00
2024-07-01 13:24:02 +07:00
createdAt DateTime @default(now())
createdBy User? @relation(name: "EmployeeOtherInfoCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
createdByUserId String?
updatedAt DateTime @updatedAt
updatedBy User? @relation(name: "EmployeeOtherInfoUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
updatedByUserId String?
2024-04-01 13:28:43 +07:00
}
2024-11-05 09:36:01 +07:00
model Institution {
2024-11-07 16:59:26 +07:00
id String @id @default(cuid())
code String
group String // Use for grouping, but not use relation
name String
nameEN String
2024-11-05 09:36:01 +07:00
address String
addressEN String
soi String?
soiEN String?
moo String?
mooEN String?
street String?
streetEN String?
province Province @relation(fields: [provinceId], references: [id], onDelete: Cascade)
provinceId String
district District @relation(fields: [districtId], references: [id], onDelete: Cascade)
districtId String
subDistrict SubDistrict @relation(fields: [subDistrictId], references: [id], onDelete: Cascade)
subDistrictId String
2024-11-08 14:23:13 +07:00
2025-02-10 10:03:32 +07:00
status Status @default(CREATED)
statusOrder Int @default(0)
2024-11-08 14:23:13 +07:00
selectedImage String?
taskOrder TaskOrder[]
contactName String?
contactEmail String?
contactTel String?
createdAt DateTime @default(now())
createdBy User? @relation(name: "InstitutionCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
createdByUserId String?
updatedAt DateTime @default(now()) @updatedAt
updatedBy User? @relation(name: "InstitutionUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
updatedByUserId String?
bank InstitutionBank[]
}
model InstitutionBank {
id String @id @default(cuid())
bankName String
bankBranch String
accountName String
accountNumber String
accountType String
currentlyUse Boolean
institution Institution @relation(fields: [institutionId], references: [id], onDelete: Cascade)
institutionId String
2024-11-05 09:36:01 +07:00
}
2025-03-10 15:12:30 +07:00
model Property {
id String @id @default(cuid())
registeredBranch Branch @relation(fields: [registeredBranchId], references: [id])
registeredBranchId String
name String
nameEN String
type Json
status Status @default(CREATED)
statusOrder Int @default(0)
createdAt DateTime @default(now())
}
2024-10-07 11:58:43 +07:00
model WorkflowTemplate {
id String @id @default(cuid())
name String
step WorkflowTemplateStep[]
2024-10-24 15:56:03 +07:00
registeredBranch Branch @relation(fields: [registeredBranchId], references: [id])
registeredBranchId String
2024-10-07 11:58:43 +07:00
status Status @default(CREATED)
statusOrder Int @default(0)
createdAt DateTime @default(now())
createdBy User? @relation(name: "FlowCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
createdByUserId String?
updatedAt DateTime @updatedAt
updatedBy User? @relation(name: "FlowUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
updatedByUserId String?
2024-10-10 12:03:40 +07:00
service Service[]
2024-10-07 11:58:43 +07:00
}
model WorkflowTemplateStepInstitution {
id String @id @default(cuid())
group String
2024-11-07 14:00:05 +07:00
workflowTemplateStep WorkflowTemplateStep @relation(fields: [workflowTemplateStepId], references: [id], onDelete: Cascade)
workflowTemplateStepId String
}
2025-04-24 11:40:02 +07:00
model WorkflowTemplateStepGroup {
id String @id @default(cuid())
group String
workflowTemplateStep WorkflowTemplateStep @relation(fields: [workflowTemplateStepId], references: [id], onDelete: Cascade)
workflowTemplateStepId String
}
2024-10-07 11:58:43 +07:00
model WorkflowTemplateStep {
id String @id @default(cuid())
order Int
name String
detail String?
type String?
value WorkflowTemplateStepValue[] // NOTE: For enum or options type
responsiblePerson WorkflowTemplateStepUser[]
responsibleInstitution WorkflowTemplateStepInstitution[]
2025-04-24 11:40:02 +07:00
responsibleGroup WorkflowTemplateStepGroup[]
messengerByArea Boolean @default(false)
2024-10-07 11:58:43 +07:00
attributes Json?
2024-11-07 14:00:05 +07:00
workflowTemplate WorkflowTemplate? @relation(fields: [workflowTemplateId], references: [id], onDelete: Cascade)
2024-10-07 11:58:43 +07:00
workflowTemplateId String?
}
model WorkflowTemplateStepValue {
id String @id @default(cuid())
value String
workflowTemplateStep WorkflowTemplateStep @relation(fields: [workflowTemplateStepId], references: [id])
workflowTemplateStepId String
}
model WorkflowTemplateStepUser {
userId String
user User @relation(fields: [userId], references: [id])
2024-10-28 10:34:00 +07:00
workflowTemplateStep WorkflowTemplateStep @relation(fields: [workflowTemplateStepId], references: [id], onDelete: Cascade)
2024-10-07 11:58:43 +07:00
workflowTemplateStepId String
@@id([userId, workflowTemplateStepId])
}
2024-04-01 13:28:43 +07:00
model ProductGroup {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-04-01 13:28:43 +07:00
code String
name String
detail String
remark String
2024-10-28 10:51:51 +07:00
shared Boolean @default(false)
2024-06-24 13:14:44 +07:00
status Status @default(CREATED)
statusOrder Int @default(0)
2024-04-01 13:28:43 +07:00
registeredBranchId String
registeredBranch Branch @relation(fields: [registeredBranchId], references: [id])
2024-09-06 11:56:37 +07:00
2024-07-01 13:24:02 +07:00
createdAt DateTime @default(now())
createdBy User? @relation(name: "ProductGroupCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
createdByUserId String?
updatedAt DateTime @updatedAt
updatedBy User? @relation(name: "ProductGroupUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
updatedByUserId String?
2024-06-11 13:01:20 +07:00
service Service[]
2024-09-03 14:06:02 +07:00
product Product[]
2024-04-01 13:28:43 +07:00
}
model ProductDocument {
id String @id @default(cuid())
name String
product Product? @relation(fields: [productId], references: [id])
productId String?
}
2024-04-01 13:28:43 +07:00
model Product {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-04-01 13:28:43 +07:00
code String
name String
detail String
2024-06-14 16:53:48 +07:00
process Int
2024-06-26 11:22:48 +07:00
price Float
agentPrice Float
serviceCharge Float
2024-09-03 14:06:02 +07:00
expenseType String?
2025-01-27 11:50:16 +07:00
vatIncluded Boolean @default(true)
calcVat Boolean @default(true)
agentPriceVatIncluded Boolean? @default(true)
agentPriceCalcVat Boolean? @default(true)
serviceChargeVatIncluded Boolean? @default(true)
serviceChargeCalcVat Boolean? @default(true)
2024-10-15 09:42:16 +07:00
2024-06-24 13:14:44 +07:00
status Status @default(CREATED)
statusOrder Int @default(0)
2024-04-01 13:28:43 +07:00
2024-09-10 13:33:44 +07:00
shared Boolean @default(false)
2024-09-10 15:51:22 +07:00
remark String?
selectedImage String?
2024-06-14 16:53:48 +07:00
document ProductDocument[]
productGroup ProductGroup @relation(fields: [productGroupId], references: [id], onDelete: Cascade)
productGroupId String
2025-09-12 11:56:40 +07:00
flowAccountProductIdSellPrice String?
flowAccountProductIdAgentPrice String?
2024-07-18 17:23:41 +07:00
workProduct WorkProduct[]
quotationProductServiceList QuotationProductServiceList[]
2024-12-24 18:11:40 +07:00
taskProduct TaskProduct[]
2024-04-01 13:28:43 +07:00
2024-07-01 13:24:02 +07:00
createdAt DateTime @default(now())
createdBy User? @relation(name: "ProductCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
createdByUserId String?
updatedAt DateTime @updatedAt
updatedBy User? @relation(name: "ProductUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
updatedByUserId String?
2024-04-01 13:28:43 +07:00
}
model Service {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-10-21 17:26:35 +07:00
code String
name String
detail String
attributes Json?
installments Int @default(0)
status Status @default(CREATED)
statusOrder Int @default(0)
workflowId String?
workflow WorkflowTemplate? @relation(fields: [workflowId], references: [id])
2024-10-10 12:03:40 +07:00
2024-09-10 15:51:22 +07:00
shared Boolean @default(false)
selectedImage String?
2024-09-10 13:33:44 +07:00
work Work[]
quotationProductServiceList QuotationProductServiceList[]
productGroup ProductGroup @relation(fields: [productGroupId], references: [id], onDelete: Cascade)
productGroupId String
createdAt DateTime @default(now())
createdBy User? @relation(name: "ServiceCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
createdByUserId String?
updatedAt DateTime @updatedAt
updatedBy User? @relation(name: "ServiceUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
updatedByUserId String?
}
model Work {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
order Int
name String
attributes Json?
status Status @default(CREATED)
statusOrder Int @default(0)
service Service? @relation(fields: [serviceId], references: [id], onDelete: Cascade)
serviceId String?
createdAt DateTime @default(now())
createdBy User? @relation(name: "WorkCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
createdByUserId String?
updatedAt DateTime @updatedAt
updatedBy User? @relation(name: "WorkUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
updatedByUserId String?
productOnWork WorkProduct[]
quotationProductServiceList QuotationProductServiceList[]
}
model WorkProduct {
2024-10-21 17:26:35 +07:00
order Int
work Work @relation(fields: [workId], references: [id], onDelete: Cascade)
workId String
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
productId String
installmentNo Int @default(0)
2024-12-03 13:36:31 +07:00
stepCount Int @default(0)
attributes Json?
createdAt DateTime @default(now())
createdBy User? @relation(name: "WorkProductCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
createdByUserId String?
updatedAt DateTime @updatedAt
updatedBy User? @relation(name: "WorkProductUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
updatedByUserId String?
@@id([workId, productId])
}
2024-07-18 17:23:41 +07:00
2024-10-04 09:22:52 +07:00
enum QuotationStatus {
2024-10-25 16:42:34 +07:00
Issued
2024-10-25 16:37:59 +07:00
Accepted
2024-10-04 15:17:24 +07:00
PaymentPending
2024-10-15 13:29:40 +07:00
PaymentInProcess // For Installments / Split Payment
2024-10-04 09:22:52 +07:00
PaymentSuccess
2024-10-04 13:29:38 +07:00
ProcessComplete
2024-10-15 13:29:40 +07:00
Canceled
Expired
2024-10-04 09:22:52 +07:00
}
2024-07-18 17:23:41 +07:00
enum PayCondition {
Full
Split
2024-10-29 10:05:25 +07:00
SplitCustom
2024-07-18 17:23:41 +07:00
BillFull
BillSplit
2024-10-29 10:05:25 +07:00
BillSplitCustom
2024-07-18 17:23:41 +07:00
}
model Quotation {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-07-18 17:23:41 +07:00
registeredBranch Branch @relation(fields: [registeredBranchId], references: [id])
registeredBranchId String
2024-07-18 17:23:41 +07:00
customerBranchId String
customerBranch CustomerBranch @relation(fields: [customerBranchId], references: [id])
2024-07-19 10:49:38 +07:00
status Status @default(CREATED)
statusOrder Int @default(0)
2024-10-25 16:42:34 +07:00
quotationStatus QuotationStatus @default(Issued)
2024-10-04 09:22:52 +07:00
2024-10-18 11:03:29 +07:00
remark String?
code String
workName String
contactName String
contactTel String
dueDate DateTime @db.Date
2024-07-18 17:23:41 +07:00
date DateTime @default(now())
payCondition PayCondition
paySplitCount Int?
paySplit QuotationPaySplit[]
payBillDate DateTime? @db.Date
2024-07-18 17:23:41 +07:00
2024-10-04 09:22:52 +07:00
worker QuotationWorker[]
2024-07-18 17:23:41 +07:00
2024-10-18 14:48:50 +07:00
workerMax Int?
2024-07-18 17:23:41 +07:00
urgent Boolean @default(false)
productServiceList QuotationProductServiceList[]
2024-10-04 13:29:38 +07:00
agentPrice Boolean @default(false)
2024-07-18 17:23:41 +07:00
totalPrice Float
totalDiscount Float
2024-07-19 17:59:44 +07:00
vat Float
2024-10-17 13:04:42 +07:00
vatExcluded Float @default(0)
2024-10-04 13:29:38 +07:00
discount Float @default(0)
2024-07-19 17:59:44 +07:00
finalPrice Float
2024-07-18 17:23:41 +07:00
isDebitNote Boolean @default(false)
debitNoteQuotationId String?
debitNoteQuotation Quotation? @relation(name: "QuotationDebitNote", fields: [debitNoteQuotationId], references: [id])
debitNote Quotation[] @relation(name: "QuotationDebitNote")
2024-10-09 15:04:59 +07:00
requestData RequestData[]
2024-09-30 09:48:35 +07:00
createdAt DateTime @default(now())
createdBy User? @relation(name: "QuotationCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
2024-07-18 17:23:41 +07:00
createdByUserId String?
2024-09-30 09:48:35 +07:00
updatedAt DateTime @updatedAt
updatedBy User? @relation(name: "QuotationUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
2024-07-18 17:23:41 +07:00
updatedByUserId String?
2024-10-15 13:29:40 +07:00
invoice Invoice[]
creditNote CreditNote[]
2025-07-04 14:08:24 +07:00
seller User? @relation(fields: [sellerId], references: [id], onDelete: Cascade)
sellerId String?
2024-10-15 13:29:40 +07:00
}
2024-07-18 17:23:41 +07:00
model QuotationPaySplit {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-07-18 17:23:41 +07:00
no Int
name String?
amount Float
2024-07-18 17:23:41 +07:00
2024-10-18 09:56:06 +07:00
quotation Quotation? @relation(fields: [quotationId], references: [id], onDelete: Cascade)
2024-07-18 17:23:41 +07:00
quotationId String?
invoice Invoice? @relation(fields: [invoiceId], references: [id])
invoiceId String?
2024-07-18 17:23:41 +07:00
}
model QuotationWorker {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-07-18 17:23:41 +07:00
no Int
employee Employee @relation(fields: [employeeId], references: [id])
employeeId String
2024-10-01 15:41:23 +07:00
quotation Quotation @relation(fields: [quotationId], references: [id], onDelete: Cascade)
2024-07-18 17:23:41 +07:00
quotationId String
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
2024-07-18 17:23:41 +07:00
}
model QuotationProductServiceList {
id String @id @default(cuid())
2024-07-18 17:23:41 +07:00
quotationId String
2024-10-01 15:41:23 +07:00
quotation Quotation @relation(fields: [quotationId], references: [id], onDelete: Cascade)
2024-07-18 17:23:41 +07:00
order Int
2024-07-18 17:23:41 +07:00
vat Float
2024-07-18 17:23:41 +07:00
amount Int
discount Float
pricePerUnit Float
installmentNo Int?
productId String
product Product @relation(fields: [productId], references: [id])
workId String?
work Work? @relation(fields: [workId], references: [id])
serviceId String?
service Service? @relation(fields: [serviceId], references: [id])
2024-10-04 16:39:37 +07:00
2024-11-18 09:18:00 +07:00
attributes Json?
2024-10-09 15:04:59 +07:00
worker QuotationProductServiceWorker[]
2024-10-10 11:56:52 +07:00
requestWork RequestWork[]
2024-10-04 16:39:37 +07:00
}
model QuotationProductServiceWorker {
productService QuotationProductServiceList @relation(fields: [productServiceId], references: [id], onDelete: Cascade)
productServiceId String
employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade)
employeeId String
@@id([productServiceId, employeeId])
2024-07-18 17:23:41 +07:00
}
2024-10-09 15:04:59 +07:00
2024-10-25 13:58:29 +07:00
model Invoice {
id String @id @default(cuid())
code String
2024-11-01 10:27:26 +07:00
quotation Quotation @relation(fields: [quotationId], references: [id], onDelete: Cascade)
2024-10-25 13:58:29 +07:00
quotationId String
installments QuotationPaySplit[]
2024-10-25 13:58:29 +07:00
amount Float?
payment Payment?
flowAccountRecordId String?
2024-10-25 13:58:29 +07:00
createdAt DateTime @default(now())
createdBy User @relation(fields: [createdByUserId], references: [id])
createdByUserId String
}
enum PaymentStatus {
PaymentWait
PaymentInProcess
PaymentRetry
PaymentSuccess
}
model Payment {
id String @id @default(cuid())
code String?
2024-11-01 10:27:26 +07:00
invoice Invoice @relation(fields: [invoiceId], references: [id], onDelete: Cascade)
2024-10-25 13:58:29 +07:00
invoiceId String @unique
paymentStatus PaymentStatus
2025-09-11 09:17:23 +07:00
amount Float
date DateTime?
channel String?
account String?
reference String?
2024-10-25 13:58:29 +07:00
createdAt DateTime @default(now())
createdBy User? @relation(name: "PaymentCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
2024-10-25 13:58:29 +07:00
createdByUserId String?
updatedAt DateTime @default(now()) @updatedAt
updatedBy User? @relation(name: "PaymentUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
updatedByUserId String?
2024-10-25 13:58:29 +07:00
}
2024-11-14 13:09:42 +07:00
enum RequestDataStatus {
Pending
2025-01-22 13:31:59 +07:00
Ready
2024-11-14 13:09:42 +07:00
InProgress
Completed
Canceled
2024-11-14 13:09:42 +07:00
}
2024-10-09 15:04:59 +07:00
model RequestData {
id String @id @default(cuid())
2024-11-15 09:27:58 +07:00
code String
2024-10-18 09:56:06 +07:00
employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade)
2024-10-09 15:04:59 +07:00
employeeId String
2024-10-18 09:56:06 +07:00
quotation Quotation @relation(fields: [quotationId], references: [id], onDelete: Cascade)
2024-10-09 15:04:59 +07:00
quotationId String
2024-11-14 13:09:42 +07:00
requestDataStatus RequestDataStatus @default(Pending)
2025-03-05 09:33:06 +07:00
customerRequestCancel Boolean?
customerRequestCancelReason String?
rejectRequestCancel Boolean?
rejectRequestCancelReason String?
2025-03-05 09:33:06 +07:00
2024-10-10 16:43:09 +07:00
flow Json?
defaultMessenger User? @relation(fields: [defaultMessengerId], references: [id])
defaultMessengerId String?
2024-10-09 15:04:59 +07:00
requestWork RequestWork[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
2024-10-09 15:04:59 +07:00
}
enum RequestWorkStatus {
Pending
2024-11-18 09:18:00 +07:00
Ready
Waiting
InProgress
Validate
2024-11-18 09:18:00 +07:00
Ended
Completed
2024-12-04 14:24:27 +07:00
Canceled
}
2024-10-09 15:04:59 +07:00
model RequestWork {
id String @id @default(cuid())
2024-11-15 10:51:33 +07:00
request RequestData @relation(fields: [requestDataId], references: [id], onDelete: Cascade)
2024-10-09 15:04:59 +07:00
requestDataId String
2024-11-15 10:51:33 +07:00
productService QuotationProductServiceList @relation(fields: [productServiceId], references: [id], onDelete: Cascade)
2024-10-09 15:04:59 +07:00
productServiceId String
processByUser User? @relation(fields: [processByUserId], references: [id])
processByUserId String?
2024-10-21 17:26:35 +07:00
attributes Json?
2024-11-19 13:48:45 +07:00
stepStatus RequestWorkStepStatus[]
2025-03-05 09:33:06 +07:00
customerRequestCancel Boolean?
customerRequestCancelReason String?
rejectRequestCancel Boolean?
rejectRequestCancelReason String?
2025-03-05 09:33:06 +07:00
2024-12-27 09:31:45 +07:00
creditNote CreditNote? @relation(fields: [creditNoteId], references: [id], onDelete: SetNull)
creditNoteId String?
2024-11-19 13:48:45 +07:00
}
model RequestWorkStepStatus {
step Int
workStatus RequestWorkStatus @default(Pending)
2025-08-14 13:10:44 +07:00
updatedAt DateTime @default(now()) @updatedAt
2024-11-19 13:48:45 +07:00
2024-12-27 09:31:45 +07:00
requestWork RequestWork @relation(fields: [requestWorkId], references: [id], onDelete: Cascade)
2024-11-19 13:48:45 +07:00
requestWorkId String
2024-11-22 11:02:13 +07:00
attributes Json?
2024-12-03 09:56:33 +07:00
customerDuty Boolean?
customerDutyCost Float?
companyDuty Boolean?
companyDutyCost Float?
individualDuty Boolean?
individualDutyCost Float?
2024-12-03 10:26:09 +07:00
responsibleUserLocal Boolean?
responsibleUserId String?
2024-12-27 09:31:45 +07:00
responsibleUser User? @relation(fields: [responsibleUserId], references: [id], onDelete: SetNull)
2024-12-03 09:56:33 +07:00
2024-12-10 10:03:51 +07:00
task Task[]
2024-11-19 13:48:45 +07:00
@@id([step, requestWorkId])
2024-10-09 15:04:59 +07:00
}
2024-12-10 10:03:51 +07:00
enum TaskOrderStatus {
Pending
InProgress
Validate
Complete
Canceled
}
enum TaskStatus {
Pending
InProgress
2024-12-11 09:56:38 +07:00
Success
Failed
2025-01-08 11:24:00 +07:00
Restart
Redo
2024-12-11 09:56:38 +07:00
Validate
2024-12-11 09:56:38 +07:00
Complete
2024-12-04 11:30:36 +07:00
Canceled
}
2024-12-10 10:03:51 +07:00
model Task {
id String @id @default(cuid())
taskStatus TaskStatus @default(Pending)
step Int
requestWorkId String
requestWorkStep RequestWorkStepStatus @relation(fields: [step, requestWorkId], references: [step, requestWorkId])
2024-12-11 11:42:21 +07:00
failedType String?
failedComment String?
2024-12-27 09:31:45 +07:00
taskOrder TaskOrder @relation(fields: [taskOrderId], references: [id], onDelete: Cascade)
2024-12-10 10:03:51 +07:00
taskOrderId String
}
2024-12-24 18:11:40 +07:00
model TaskProduct {
taskOrderId String
2024-12-27 09:31:45 +07:00
taskOrder TaskOrder @relation(fields: [taskOrderId], references: [id], onDelete: Cascade)
2024-12-24 18:11:40 +07:00
productId String
product Product @relation(fields: [productId], references: [id])
discount Float?
@@id([taskOrderId, productId])
}
model TaskOrder {
id String @id @default(cuid())
code String
codeProductReceived String?
2024-12-10 10:03:51 +07:00
taskName String
taskOrderStatus TaskOrderStatus @default(Pending)
taskList Task[]
2025-01-23 14:12:15 +07:00
remark String?
contactName String
contactTel String
2025-01-24 09:40:54 +07:00
urgent Boolean @default(false)
institution Institution @relation(fields: [institutionId], references: [id])
institutionId String
2024-12-03 17:11:44 +07:00
registeredBranch Branch @relation(fields: [registeredBranchId], references: [id])
registeredBranchId String
createdAt DateTime @default(now())
2024-12-27 09:31:45 +07:00
createdBy User? @relation(name: "TaskOrderCreatedByUser", fields: [createdByUserId], references: [id])
createdByUserId String?
2024-12-11 14:44:09 +07:00
2024-12-24 18:11:40 +07:00
userTask UserTask[]
taskProduct TaskProduct[]
2024-12-11 14:44:09 +07:00
}
enum UserTaskStatus {
Pending // Should not be use but define here for type
2025-01-08 11:26:15 +07:00
Restart
2024-12-11 14:44:09 +07:00
Accept
Submit
}
model UserTask {
id String @id @default(cuid())
userTaskStatus UserTaskStatus
2024-12-27 09:31:45 +07:00
taskOrder TaskOrder @relation(fields: [taskOrderId], references: [id], onDelete: Cascade)
2024-12-11 14:44:09 +07:00
taskOrderId String
2024-12-27 09:31:45 +07:00
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
2024-12-11 14:44:09 +07:00
userId String
acceptedAt DateTime?
submittedAt DateTime?
}
enum CreditNoteStatus {
2025-02-24 11:26:43 +07:00
Waiting
Pending
Success
}
2025-01-09 13:37:01 +07:00
enum CreditNotePaybackType {
Cash
BankTransfer
}
2025-01-09 17:03:43 +07:00
enum PaybackStatus {
Pending
Verify
Done
}
model CreditNote {
id String @id @default(cuid())
2025-01-07 09:39:21 +07:00
code String
creditNoteStatus CreditNoteStatus @default(Waiting)
2025-01-09 13:37:01 +07:00
value Float @default(0)
reason String?
detail String?
2025-01-14 09:46:49 +07:00
remark String?
2025-01-09 13:37:01 +07:00
paybackType CreditNotePaybackType?
paybackBank String?
paybackAccount String?
paybackAccountName String?
2025-01-09 17:03:43 +07:00
paybackStatus PaybackStatus @default(Pending)
2025-01-13 13:54:41 +07:00
paybackDate DateTime?
quotation Quotation @relation(fields: [quotationId], references: [id], onDelete: Cascade)
quotationId String
// NOTE: only status cancel
requestWork RequestWork[]
2025-01-07 15:56:18 +07:00
createdAt DateTime @default(now())
createdBy User? @relation(name: "CreditNoteCreatedByUser", fields: [createdByUserId], references: [id])
createdByUserId String?
}