jws-backend/prisma/schema.prisma
2024-09-16 11:03:34 +07:00

980 lines
27 KiB
Text

generator client {
provider = "prisma-client-js"
}
generator kysely {
provider = "prisma-kysely"
output = "../src/generated/kysely"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Menu {
id String @id @default(cuid())
caption String
captionEN String
menuType String
url String
createdBy String?
createdAt DateTime @default(now())
updatedBy String?
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 {
id String @id @default(cuid())
userRole String
permission String
menu Menu @relation(fields: [menuId], references: [id])
menuId String
createdBy String?
createdAt DateTime @default(now())
updatedBy String?
updatedAt DateTime @updatedAt
}
model UserMenuPermission {
id String @id @default(cuid())
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())
updatedBy String?
updatedAt DateTime @updatedAt
}
model MenuComponent {
id String @id @default(cuid())
componentId String
componentTag String
menu Menu @relation(fields: [menuId], references: [id])
menuId String
createdBy String?
createdAt DateTime @default(now())
updatedBy String?
updatedAt DateTime @updatedAt
roleMenuComponentPermission RoleMenuComponentPermission[]
userMennuComponentPermission UserMenuComponentPermission[]
}
model RoleMenuComponentPermission {
id String @id @default(cuid())
userRole String
permission String
menuComponent MenuComponent @relation(fields: [menuComponentId], references: [id])
menuComponentId String
createdBy String?
createdAt DateTime @default(now())
updatedBy String?
updatedAt DateTime @updatedAt
}
model RunningNo {
key String @id @unique
value Int
}
model UserMenuComponentPermission {
id String @id @default(cuid())
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())
updatedBy String?
updatedAt DateTime @updatedAt
}
model Province {
id String @id @default(cuid())
name String
nameEN String
createdBy String?
createdAt DateTime @default(now())
updatedBy String?
updatedAt DateTime @updatedAt
district District[]
branch Branch[]
user User[]
customerBranch CustomerBranch[]
employee Employee[]
employeeCheckup EmployeeCheckup[]
}
model District {
id String @id @default(cuid())
name String
nameEN String
provinceId String
province Province @relation(fields: [provinceId], references: [id], onDelete: Cascade)
createdBy String?
createdAt DateTime @default(now())
updatedBy String?
updatedAt DateTime @updatedAt
subDistrict SubDistrict[]
branch Branch[]
user User[]
customerBranch CustomerBranch[]
employee Employee[]
}
model SubDistrict {
id String @id @default(cuid())
name String
nameEN String
zipCode String
district District @relation(fields: [districtId], references: [id], onDelete: Cascade)
districtId String
createdBy String?
createdAt DateTime @default(now())
updatedBy String?
updatedAt DateTime @updatedAt
branch Branch[]
user User[]
customerBranch CustomerBranch[]
employee Employee[]
}
enum Status {
CREATED
ACTIVE
INACTIVE
}
model Branch {
id String @id @default(cuid())
code String
taxNo String
name String
nameEN String
telephoneNo String
permitNo String
permitIssueDate DateTime @db.Date
permitExpireDate DateTime @db.Date
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?
email String
contactName String?
lineId String?
webUrl String?
latitude String
longitude String
isHeadOffice Boolean @default(false)
headOffice Branch? @relation(name: "HeadOfficeRelation", fields: [headOfficeId], references: [id])
headOfficeId String?
virtual Boolean?
selectedImage String?
bank BranchBank[]
status Status @default(CREATED)
statusOrder Int @default(0)
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?
branch Branch[] @relation(name: "HeadOfficeRelation")
contact BranchContact[]
user BranchUser[]
customerRegistration Customer[]
productGroup ProductGroup[]
}
model BranchBank {
id String @id @default(cuid())
bankName String
bankBranch String
accountName String
accountNumber String
accountType String
currentlyUse Boolean
branch Branch @relation(fields: [branchId], references: [id], onDelete: Cascade)
branchId String
}
model BranchContact {
id String @id @default(cuid())
telephoneNo String
branch Branch @relation(fields: [branchId], references: [id], onDelete: Cascade)
branchId String
}
model BranchUser {
id String @id @default(cuid())
branch Branch @relation(fields: [branchId], references: [id], onDelete: Cascade)
branchId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
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?
}
enum UserType {
USER
MESSENGER
DELEGATE
AGENCY
}
model User {
id String @id @default(cuid())
code String?
namePrefix String?
firstName String
firstNameEN String
middleName String?
middleNameEN String?
lastName String
lastNameEN String
username 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?
email String
telephoneNo String
registrationNo String?
startDate DateTime? @db.Date
retireDate DateTime? @db.Date
checkpoint String?
checkpointEN String?
userType UserType
userRole String
citizenId String
citizenIssue DateTime @db.Date
citizenExpire DateTime? @db.Date
discountCondition String?
licenseNo String?
licenseIssueDate DateTime? @db.Date
licenseExpireDate DateTime? @db.Date
sourceNationality String?
importNationality String?
trainingPlace String?
responsibleArea String?
birthDate DateTime? @db.Date
selectedImage String?
status Status @default(CREATED)
statusOrder Int @default(0)
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?
branch BranchUser[]
userMenuPermission UserMenuPermission[]
userMenuComponentPermission UserMenuComponentPermission[]
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")
emplyeeCreated Employee[] @relation("EmployeeCreatedByUser")
employeUpdated Employee[] @relation("EmployeeUpdatedByUser")
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")
quotationCreated Quotation[] @relation("QuotationCreatedByUser")
quotationUpdated Quotation[] @relation("QuotationUpdatedByUser")
}
enum CustomerType {
CORP
PERS
}
model Customer {
id String @id @default(cuid())
customerType CustomerType
status Status @default(CREATED)
statusOrder Int @default(0)
registeredBranchId String
registeredBranch Branch @relation(fields: [registeredBranchId], references: [id])
selectedImage String?
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?
branch CustomerBranch[]
quotation Quotation[]
}
model CustomerBranch {
id String @id @default(cuid())
customer Customer @relation(fields: [customerId], references: [id], onDelete: Cascade)
customerId String
code String
codeCustomer String
telephoneNo String
// NOTE: About (Natural Person)
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?
authorizedName String?
authorizedNameEN String?
// NOTE: Address
homeCode String
employmentOffice String
employmentOfficeEN 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?
// NOTE: contact
email String
contactTel String
officeTel String
contactName String
agent String
// NOTE: Business
businessType String
jobPosition String
jobDescription String
payDate String
payDateEN String
wageRate Int
wageRateText String
status Status @default(CREATED)
statusOrder Int @default(0)
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?
employee Employee[]
quotation Quotation[]
}
model Employee {
id String @id @default(cuid())
code String
nrcNo String?
namePrefix String?
firstName String
firstNameEN String
middleName String?
middleNameEN String?
lastName String
lastNameEN String
dateOfBirth DateTime @db.Date
gender String
nationality 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?
workerType String?
workerStatus String?
customerBranch CustomerBranch @relation(fields: [customerBranchId], references: [id], onDelete: Cascade)
customerBranchId String
status Status @default(CREATED)
statusOrder Int @default(0)
selectedImage String?
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?
employeePassport EmployeePassport[]
employeeVisa EmployeeVisa[]
employeeInCountryNotice EmployeeInCountryNotice[]
employeeCheckup EmployeeCheckup[]
employeeWork EmployeeWork[]
employeeOtherInfo EmployeeOtherInfo?
editHistory EmployeeHistory[]
quotationWorker QuotationWorker[]
}
model EmployeeHistory {
id String @id @default(cuid())
field String
valueBefore Json
valueAfter Json
updatedAt DateTime @updatedAt
updatedBy User? @relation(name: "EmployeeHistoryUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
updatedByUserId String?
masterId String
master Employee @relation(fields: [masterId], references: [id], onDelete: Cascade)
}
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?
employee Employee @relation(fields: [employeeId], references: [id])
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
issueDate DateTime @db.Date
expireDate DateTime @db.Date
mrz String?
remark String?
employee Employee @relation(fields: [employeeId], references: [id])
employeeId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model EmployeeInCountryNotice {
id String @id @default(cuid())
noticeNumber String
noticeDate String
nextNoticeDate DateTime @db.Date
tmNumber String
entryDate DateTime @db.Date
travelBy String
travelFrom String
employee Employee @relation(fields: [employeeId], references: [id])
employeeId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model EmployeeCheckup {
id String @id @default(cuid())
employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade)
employeeId String
checkupResult String?
checkupType String?
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
provinceId String?
hospitalName String?
remark String?
medicalBenefitScheme String?
insuranceCompany String?
coverageStartDate DateTime? @db.Date
coverageExpireDate DateTime? @db.Date
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?
}
model EmployeeWork {
id String @id @default(cuid())
employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade)
employeeId String
ownerName String?
positionName String?
jobType String?
workplace String?
workPermitNo String?
workPermitIssuDate DateTime? @db.Date
workPermitExpireDate DateTime? @db.Date
workEndDate DateTime? @db.Date
remark String?
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?
}
model EmployeeOtherInfo {
id String @id @default(cuid())
employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade)
employeeId String @unique
citizenId String?
fatherBirthPlace String?
fatherFirstName String?
fatherLastName String?
motherBirthPlace String?
motherFirstName String?
motherLastName String?
fatherFirstNameEN String?
fatherLastNameEN String?
motherFirstNameEN String?
motherLastNameEN String?
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?
}
model ProductGroup {
id String @id @default(cuid())
code String
name String
detail String
remark String
status Status @default(CREATED)
statusOrder Int @default(0)
registeredBranchId String
registeredBranch Branch @relation(fields: [registeredBranchId], references: [id])
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?
service Service[]
product Product[]
}
model Product {
id String @id @default(cuid())
code String
name String
detail String
process Int
price Float
agentPrice Float
serviceCharge Float
vatIncluded Boolean?
expenseType String?
status Status @default(CREATED)
statusOrder Int @default(0)
shared Boolean @default(false)
remark String?
selectedImage String?
productGroup ProductGroup @relation(fields: [productGroupId], references: [id], onDelete: Cascade)
productGroupId String
workProduct WorkProduct[]
quotationServiceWorkProduct QuotationServiceWorkProduct[]
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?
}
model Service {
id String @id @default(cuid())
code String
name String
detail String
attributes Json?
status Status @default(CREATED)
statusOrder Int @default(0)
shared Boolean @default(false)
selectedImage String?
work Work[]
quotationService QuotationService[]
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 {
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[]
}
model WorkProduct {
order Int
work Work @relation(fields: [workId], references: [id], onDelete: Cascade)
workId String
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
productId String
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])
}
enum PayCondition {
Full
Split
BillFull
BillSplit
}
model Quotation {
id String @id @default(cuid())
customerId String
customer Customer @relation(fields: [customerId], references: [id])
customerBranchId String
customerBranch CustomerBranch @relation(fields: [customerBranchId], references: [id])
status Status @default(CREATED)
statusOrder Int @default(0)
code String
date DateTime @default(now())
payCondition PayCondition
paySplitCount Int?
paySplit QuotationPaySplit[]
payBillDate DateTime? @db.Date
workerCount Int
worker QuotationWorker[]
service QuotationService[]
urgent Boolean @default(false)
totalPrice Float
totalDiscount Float
vat Float
vatExcluded Float
finalPrice Float
createdAt DateTime @default(now())
createdBy User? @relation(name: "QuotationCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
createdByUserId String?
updatedAt DateTime @updatedAt
updatedBy User? @relation(name: "QuotationUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
updatedByUserId String?
}
model QuotationPaySplit {
id String @id @default(cuid())
no Int
date DateTime @db.Date
quotation Quotation? @relation(fields: [quotationId], references: [id])
quotationId String?
}
model QuotationWorker {
id String @id @default(cuid())
no Int
code String
employee Employee @relation(fields: [employeeId], references: [id])
employeeId String
quotation Quotation @relation(fields: [quotationId], references: [id])
quotationId String
}
model QuotationService {
id String @id @default(cuid())
code String
name String
detail String
attributes Json?
work QuotationServiceWork[]
refServiceId String
refService Service @relation(fields: [refServiceId], references: [id])
quotation Quotation @relation(fields: [quotationId], references: [id], onDelete: Cascade)
quotationId String
}
model QuotationServiceWork {
id String @id @default(cuid())
order Int
name String
attributes Json?
service QuotationService @relation(fields: [serviceId], references: [id], onDelete: Cascade)
serviceId String
productOnWork QuotationServiceWorkProduct[]
}
model QuotationServiceWorkProduct {
order Int
work QuotationServiceWork @relation(fields: [workId], references: [id], onDelete: Cascade)
workId String
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
productId String
vat Float
amount Int
discount Float
pricePerUnit Float
@@id([workId, productId])
}