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(uuid()) 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(uuid()) 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(uuid()) 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(uuid()) 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(uuid()) 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(uuid()) 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(uuid()) 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(uuid()) 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(uuid()) 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(uuid()) code String taxNo String name String nameEN String address String addressEN String telephoneNo 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? zipCode String email String contactName String? lineId String? latitude String longitude String isHeadOffice Boolean @default(false) headOffice Branch? @relation(name: "HeadOfficeRelation", fields: [headOfficeId], references: [id]) headOfficeId 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[] productRegistration Product[] serviceRegistration Service[] customerRegistration Customer[] } model BranchBank { id String @id @default(uuid()) 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(uuid()) telephoneNo String branch Branch @relation(fields: [branchId], references: [id], onDelete: Cascade) branchId String createdAt DateTime @default(now()) createdBy User? @relation(name: "BranchContactCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull) createdByUserId String? updatedAt DateTime @updatedAt updatedBy User? @relation(name: "BranchContactUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull) updatedByUserId String? } model BranchUser { id String @id @default(uuid()) 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(uuid()) code String? namePrefix String? firstName String firstNameEN String middleName String? middleNameEN String? lastName String lastNameEN String username String gender String address String addressEN 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? zipCode String email String telephoneNo String registrationNo String? startDate DateTime? retireDate DateTime? checkpoint String? checkpointEN String? userType UserType userRole String discountCondition String? licenseNo String? licenseIssueDate DateTime? licenseExpireDate DateTime? sourceNationality String? importNationality String? trainingPlace String? responsibleArea String? birthDate DateTime? 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") branchContactCreated BranchContact[] @relation("BranchContactCreatedByUser") branchContactUpdated BranchContact[] @relation("BranchContactUpdatedByUser") 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") productTypeCreated ProductType[] @relation("ProductTypeCreatedByUser") productTypeUpdated ProductType[] @relation("ProductTypeUpdatedByUser") 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(uuid()) code String personName String personNameEN String? customerType CustomerType customerName String customerNameEN String taxNo 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: "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(uuid()) branchNo Int code String legalPersonNo String name String nameEN String customer Customer @relation(fields: [customerId], references: [id], onDelete: Cascade) customerId String taxNo String? registerName String registerDate DateTime authorizedCapital String address String addressEN 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? zipCode String email String telephoneNo String employmentOffice String bussinessType String bussinessTypeEN String jobPosition String jobPositionEN String jobDescription String saleEmployee String payDate DateTime wageRate Int 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(uuid()) code String nrcNo String? firstName String firstNameEN String lastName String lastNameEN String dateOfBirth DateTime gender String nationality String address String? addressEN 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? zipCode String passportType String passportNumber String passportIssueDate DateTime passportExpiryDate DateTime passportIssuingCountry String passportIssuingPlace String previousPassportReference String? visaType String? visaNumber String? visaIssueDate DateTime? visaExpiryDate DateTime? visaIssuingPlace String? visaStayUntilDate DateTime? tm6Number String? entryDate DateTime? workerStatus String? customerBranch CustomerBranch? @relation(fields: [customerBranchId], references: [id], onDelete: SetNull) customerBranchId String? status Status @default(CREATED) statusOrder Int @default(0) 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? employeeCheckup EmployeeCheckup[] employeeWork EmployeeWork[] employeeOtherInfo EmployeeOtherInfo? editHistory EmployeeHistory[] quotationWorker QuotationWorker[] } model EmployeeHistory { id String @id @default(uuid()) 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 EmployeeCheckup { id String @id @default(uuid()) 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? coverageExpireDate DateTime? 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(uuid()) employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade) employeeId String ownerName String? positionName String? jobType String? workplace String? workPermitNo String? workPermitIssuDate DateTime? workPermitExpireDate DateTime? workEndDate DateTime? 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(uuid()) 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(uuid()) code String name String detail String remark String status Status @default(CREATED) statusOrder Int @default(0) 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? type ProductType[] } model ProductType { id String @id @default(uuid()) code String name String detail String remark String status Status @default(CREATED) statusOrder Int @default(0) createdAt DateTime @default(now()) createdBy User? @relation(name: "ProductTypeCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull) createdByUserId String? updatedAt DateTime @updatedAt updatedBy User? @relation(name: "ProductTypeUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull) updatedByUserId String? productGroup ProductGroup @relation(fields: [productGroupId], references: [id], onDelete: Cascade) productGroupId String product Product[] service Service[] } model Product { id String @id @default(uuid()) code String name String detail String process Int price Float agentPrice Float serviceCharge Float status Status @default(CREATED) statusOrder Int @default(0) remark String? productType ProductType? @relation(fields: [productTypeId], references: [id], onDelete: SetNull) productTypeId String? registeredBranchId String? registeredBranch Branch? @relation(fields: [registeredBranchId], references: [id]) 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(uuid()) code String name String detail String attributes Json? status Status @default(CREATED) statusOrder Int @default(0) work Work[] quotationService QuotationService[] productType ProductType? @relation(fields: [productTypeId], references: [id], onDelete: SetNull) productTypeId String? registeredBranchId String? registeredBranch Branch? @relation(fields: [registeredBranchId], references: [id]) 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(uuid()) 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(uuid()) 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? 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(uuid()) no Int date DateTime quotation Quotation? @relation(fields: [quotationId], references: [id]) quotationId String? } model QuotationWorker { id String @id @default(uuid()) 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(uuid()) 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(uuid()) 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]) }