jws-backend/prisma/schema.prisma

924 lines
26 KiB
Text
Raw Normal View History

2024-04-01 13:28:43 +07:00
generator client {
provider = "prisma-client-js"
}
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"
url = env("DATABASE_URL")
}
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
district District[]
branch Branch[]
user User[]
customerBranch CustomerBranch[]
employee Employee[]
employeeCheckup EmployeeCheckup[]
}
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
subDistrict SubDistrict[]
branch Branch[]
user User[]
customerBranch CustomerBranch[]
employee Employee[]
}
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
branch Branch[]
user User[]
customerBranch CustomerBranch[]
employee Employee[]
}
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-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?
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[]
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
}
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?
firstName String
firstNameEN String
middleName String?
middleNameEN String?
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?
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
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-11 15:06:27 +07:00
// citizenId String?
// citizenIssue DateTime? @db.Date
// citizenExpire DateTime? @db.Date
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 String?
2024-04-01 13:28:43 +07:00
2024-04-10 11:37:12 +07:00
trainingPlace String?
responsibleArea String?
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-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")
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")
2024-07-18 17:23:41 +07:00
quotationCreated Quotation[] @relation("QuotationCreatedByUser")
quotationUpdated Quotation[] @relation("QuotationUpdatedByUser")
2024-04-01 13:28:43 +07:00
}
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
namePrefix String?
firstName String
firstNameEN String?
lastName String
lastNameEN String?
gender String
birthDate DateTime @db.Date
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
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-07-18 17:23:41 +07:00
branch CustomerBranch[]
quotation Quotation[]
2024-04-01 13:28:43 +07:00
}
model CustomerBranch {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-04-01 13:28:43 +07:00
customer Customer @relation(fields: [customerId], references: [id], onDelete: Cascade)
customerId String
2024-08-23 10:33:53 +07:00
code String
codeCustomer String
2024-04-01 13:28:43 +07:00
// NOTE: About (Natural Person)
citizenId String?
// NOTE: About (Legal Entity)
legalPersonNo String?
registerName String?
registerNameEN String?
registerDate DateTime? @db.Date
authorizedCapital String?
workplace String
workplaceEN 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?
email String
2024-08-21 16:52:59 +07:00
contactName String
2024-04-01 13:28:43 +07:00
telephoneNo String
2024-04-23 18:09:08 +07:00
employmentOffice String
businessType String
businessTypeEN String
2024-04-23 18:09:08 +07:00
jobPosition String
2024-04-24 10:01:24 +07:00
jobPositionEN String
2024-04-23 18:09:08 +07:00
jobDescription String
saleEmployee String
payDate DateTime @db.Date
2024-06-07 14:02:31 +07:00
wageRate Int
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-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
firstNameEN String
middleName String?
middleNameEN String?
lastName String
lastNameEN String
2024-04-04 17:42:52 +07:00
dateOfBirth DateTime @db.Date
2024-04-01 13:28:43 +07:00
gender String
nationality String
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-06-10 16:50:17 +07:00
passportType String
passportNumber String
passportIssueDate DateTime @db.Date
passportExpiryDate DateTime @db.Date
2024-06-10 16:50:17 +07:00
passportIssuingCountry String
passportIssuingPlace String
previousPassportReference String?
2024-06-12 17:01:42 +07:00
visaType String?
visaNumber String?
visaIssueDate DateTime? @db.Date
visaExpiryDate DateTime? @db.Date
2024-06-12 17:01:42 +07:00
visaIssuingPlace String?
visaStayUntilDate DateTime? @db.Date
2024-06-12 17:01:42 +07:00
tm6Number String?
entryDate DateTime? @db.Date
2024-06-12 17:01:42 +07:00
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
employeeCheckup EmployeeCheckup[]
employeeWork EmployeeWork[]
2024-08-05 10:59:44 +07:00
employeeOtherInfo EmployeeOtherInfo?
2024-06-28 08:57:53 +07:00
2024-07-18 17:23:41 +07:00
editHistory EmployeeHistory[]
quotationWorker QuotationWorker[]
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
}
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?
workPermitNo String?
workPermitIssuDate DateTime? @db.Date
workPermitExpireDate DateTime? @db.Date
workEndDate DateTime? @db.Date
2024-06-10 16:06:33 +07:00
remark 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-06-11 11:27:00 +07:00
citizenId String?
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
}
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-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 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
vatIncluded Boolean?
expenseType 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-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
productGroup ProductGroup @relation(fields: [productGroupId], references: [id], onDelete: Cascade)
productGroupId String
2024-07-18 17:23:41 +07:00
workProduct WorkProduct[]
quotationServiceWorkProduct QuotationServiceWorkProduct[]
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())
code String
name String
detail String
attributes Json?
status Status @default(CREATED)
statusOrder Int @default(0)
2024-09-10 15:51:22 +07:00
shared Boolean @default(false)
selectedImage String?
2024-09-10 13:33:44 +07:00
2024-07-23 15:43:06 +07:00
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 {
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[]
}
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])
}
2024-07-18 17:23:41 +07:00
enum PayCondition {
Full
Split
BillFull
BillSplit
}
model Quotation {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-07-18 17:23:41 +07:00
customerId String
customer Customer @relation(fields: [customerId], references: [id])
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-07-18 17:23:41 +07:00
code String
date DateTime @default(now())
payCondition PayCondition
paySplitCount Int?
paySplit QuotationPaySplit[]
payBillDate DateTime? @db.Date
2024-07-18 17:23:41 +07:00
workerCount Int
worker QuotationWorker[]
service QuotationService[]
urgent Boolean @default(false)
totalPrice Float
totalDiscount Float
2024-07-19 17:59:44 +07:00
vat Float
vatExcluded Float
finalPrice Float
2024-07-18 17:23:41 +07:00
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 {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-07-18 17:23:41 +07:00
no Int
date DateTime @db.Date
2024-07-18 17:23:41 +07:00
quotation Quotation? @relation(fields: [quotationId], references: [id])
quotationId String?
}
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
code String
employee Employee @relation(fields: [employeeId], references: [id])
employeeId String
quotation Quotation @relation(fields: [quotationId], references: [id])
quotationId String
}
model QuotationService {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-07-18 17:23:41 +07:00
code String
name String
detail String
attributes Json?
work QuotationServiceWork[]
2024-07-23 15:43:06 +07:00
refServiceId String
refService Service @relation(fields: [refServiceId], references: [id])
2024-07-24 14:19:45 +07:00
quotation Quotation @relation(fields: [quotationId], references: [id], onDelete: Cascade)
2024-07-18 17:23:41 +07:00
quotationId String
}
model QuotationServiceWork {
2024-08-27 14:28:14 +07:00
id String @id @default(cuid())
2024-07-18 17:23:41 +07:00
order Int
name String
attributes Json?
2024-07-24 14:19:45 +07:00
service QuotationService @relation(fields: [serviceId], references: [id], onDelete: Cascade)
2024-07-18 17:23:41 +07:00
serviceId String
productOnWork QuotationServiceWorkProduct[]
}
model QuotationServiceWorkProduct {
order Int
2024-07-24 14:19:45 +07:00
work QuotationServiceWork @relation(fields: [workId], references: [id], onDelete: Cascade)
2024-07-18 17:23:41 +07:00
workId String
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
productId String
vat Float
2024-07-18 17:23:41 +07:00
amount Int
discount Float
pricePerUnit Float
@@id([workId, productId])
}