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[] customerBranchCitizen CustomerBranchCitizen[] customerBranchHouseRegis CustomerBranchHouseRegis[] } 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[] CustomerBranchCitizen CustomerBranchCitizen[] CustomerBranchHouseRegis CustomerBranchHouseRegis[] } 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[] CustomerBranchCitizen CustomerBranchCitizen[] CustomerBranchHouseRegis CustomerBranchHouseRegis[] } 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? remark 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[] quotation Quotation[] } 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[] workflowTemplateStepUser WorkflowTemplateStepUser[] requestWork RequestWork[] 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") flowCreated WorkflowTemplate[] @relation("FlowCreatedByUser") flowUpdated WorkflowTemplate[] @relation("FlowUpdatedByUser") } 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[] } model CustomerBranch { id String @id @default(cuid()) customer Customer @relation(fields: [customerId], references: [id], onDelete: Cascade) customerId String customerName 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[] citizen CustomerBranchCitizen[] poa CustomerBranchPoa[] houseRegis CustomerBranchHouseRegis[] commercialRegis CustomerBranchCommercialRegis[] vatRegis CustomerBranchVatRegis[] } model CustomerBranchCitizen { id String @id @default(cuid()) citizenId String birthDate DateTime? @db.Date 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 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? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt customerBranchId String customerBranch CustomerBranch @relation(fields: [customerBranchId], references: [id], onDelete: Cascade) } model CustomerBranchPoa { id String @id @default(cuid()) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt customerBranchId String customerBranch CustomerBranch @relation(fields: [customerBranchId], references: [id], onDelete: Cascade) } 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? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt customerBranchId String customerBranch CustomerBranch @relation(fields: [customerBranchId], references: [id], onDelete: Cascade) } 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? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt customerBranchId String customerBranch CustomerBranch @relation(fields: [customerBranchId], references: [id], onDelete: Cascade) } model CustomerBranchVatRegis { id String @id @default(cuid()) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt customerBranchId String customerBranch CustomerBranch @relation(fields: [customerBranchId], references: [id], onDelete: Cascade) } 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[] quotationProductServiceWorker QuotationProductServiceWorker[] requestData RequestData[] } 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], onDelete: Cascade) 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], onDelete: Cascade) 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], onDelete: Cascade) 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 WorkflowTemplate { id String @id @default(cuid()) name String step WorkflowTemplateStep[] 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? service Service[] } model WorkflowTemplateStep { id String @id @default(cuid()) order Int name String type String? value WorkflowTemplateStepValue[] // NOTE: For enum or options type responsiblePerson WorkflowTemplateStepUser[] workflowTemplate WorkflowTemplate? @relation(fields: [workflowTemplateId], references: [id]) 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]) workflowTemplateStep WorkflowTemplateStep @relation(fields: [workflowTemplateStepId], references: [id]) workflowTemplateStepId String @@id([userId, workflowTemplateStepId]) } 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? calcVat Boolean @default(true) 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[] quotationProductServiceList QuotationProductServiceList[] 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) workflowTemplateId String? workflowTemplate WorkflowTemplate? @relation(fields: [workflowTemplateId], references: [id]) shared Boolean @default(false) selectedImage String? 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 { 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 { 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 QuotationStatus { PaymentPending PaymentInProcess // For Installments / Split Payment PaymentSuccess ProcessComplete Canceled } enum PayCondition { Full Split BillFull BillSplit } model Quotation { id String @id @default(cuid()) registeredBranch Branch @relation(fields: [registeredBranchId], references: [id]) registeredBranchId String customerBranchId String customerBranch CustomerBranch @relation(fields: [customerBranchId], references: [id]) status Status @default(CREATED) statusOrder Int @default(0) quotationStatus QuotationStatus @default(PaymentPending) quotationPaymentData QuotationPayment[] code String workName String contactName String contactTel String documentReceivePoint String dueDate DateTime @db.Date date DateTime @default(now()) payCondition PayCondition paySplitCount Int? paySplit QuotationPaySplit[] payBillDate DateTime? @db.Date worker QuotationWorker[] urgent Boolean @default(false) productServiceList QuotationProductServiceList[] agentPrice Boolean @default(false) totalPrice Float totalDiscount Float vat Float vatExcluded Float @default(0) discount Float @default(0) finalPrice Float requestData RequestData[] 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? } enum PaymentStatus { PaymentWait PaymentSuccess } model QuotationPayment { id String @id @default(cuid()) paymentStatus PaymentStatus date DateTime amount Float remark String? quotation Quotation @relation(fields: [quotationId], references: [id], onDelete: Cascade) quotationId String } model QuotationPaySplit { id String @id @default(cuid()) no Int date DateTime @db.Date amount Float quotation Quotation? @relation(fields: [quotationId], references: [id], onDelete: Cascade) 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], onDelete: Cascade) quotationId String } model QuotationProductServiceList { id String @id @default(cuid()) quotationId String quotation Quotation @relation(fields: [quotationId], references: [id], onDelete: Cascade) order Int vat Float amount Int discount Float pricePerUnit Float 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]) worker QuotationProductServiceWorker[] requestWork RequestWork[] } 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]) } model RequestData { id String @id @default(cuid()) employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade) employeeId String quotation Quotation @relation(fields: [quotationId], references: [id], onDelete: Cascade) quotationId String flow Json? requestWork RequestWork[] } enum RequestWorkStatus { Pending InProgress Completed } model RequestWork { id String @id @default(cuid()) request RequestData @relation(fields: [requestDataId], references: [id]) requestDataId String productService QuotationProductServiceList @relation(fields: [productServiceId], references: [id]) productServiceId String workStatus RequestWorkStatus @default(Pending) processByUser User? @relation(fields: [processByUserId], references: [id]) processByUserId String? }