quotes.prisma 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. model Quote {
  2. id String @id @default(cuid())
  3. quoteNumber String?
  4. title String
  5. description String?
  6. status String @default("draft")
  7. validUntil DateTime?
  8. subtotal Float @default(0)
  9. taxRate Float @default(0)
  10. taxAmount Float @default(0)
  11. taxInclusive Boolean @default(false)
  12. /// See ServiceRecord.taxComponents.
  13. taxComponents Json?
  14. /// See ServiceRecord.taxableSubtotal.
  15. taxableSubtotal Float?
  16. discountType String?
  17. discountValue Float @default(0)
  18. discountAmount Float @default(0)
  19. totalAmount Float @default(0)
  20. notes String?
  21. /// The warranty the customer is being offered, stated before they accept.
  22. /// Same meaning as on ServiceRecord, and copied there on conversion. No
  23. /// expiry: the period starts with the work, which a quote has no date for.
  24. warrantyStatus String?
  25. warrantyMonths Int?
  26. warrantyMileage Int?
  27. warrantyNotes String?
  28. publicToken String?
  29. sharedAt DateTime?
  30. viewCount Int @default(0)
  31. lastViewedAt DateTime?
  32. /// See ServiceRecord: this document's own answer to when its share link
  33. /// stops working, and the last time the link was sent again or reopened.
  34. shareExpiresAt DateTime?
  35. shareNeverExpires Boolean @default(false)
  36. shareRenewedAt DateTime?
  37. customerMessage String?
  38. /// See ServiceRecord.customerReference. Copied to the job on conversion.
  39. customerReference String?
  40. convertedToId String?
  41. createdAt DateTime @default(now())
  42. updatedAt DateTime @updatedAt
  43. /// Most recent time this quote reached the customer, by email or share
  44. /// link. Exists so an unlock is spent when the quote is issued again; the
  45. /// status alone cannot show that, because re-sending an accepted quote does
  46. /// not change it.
  47. sentAt DateTime?
  48. /// When the workshop dismissed the customer's answer from its list of
  49. /// responses. An acceptance keeps its status when dismissed, because it is
  50. /// the customer's agreement and may be what holds the quote locked, so the
  51. /// list needs its own record of it. Cleared whenever the customer answers
  52. /// again.
  53. responseDismissedAt DateTime?
  54. /// See ServiceRecord.editUnlockedAt.
  55. editUnlockedAt DateTime?
  56. editUnlockedById String?
  57. userId String
  58. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  59. organizationId String?
  60. organization Organization? @relation(fields: [organizationId], references: [id], onDelete: Cascade)
  61. customerId String?
  62. customer Customer? @relation(fields: [customerId], references: [id], onDelete: SetNull)
  63. /// The stored set this quote is about, when it came out of the tire hotel.
  64. /// SetNull rather than Cascade: a quote already sent is a document the
  65. /// customer holds, and deleting the set must not erase it.
  66. tireSetId String?
  67. tireSet TireSet? @relation(fields: [tireSetId], references: [id], onDelete: SetNull)
  68. vehicleId String?
  69. vehicle Vehicle? @relation(fields: [vehicleId], references: [id], onDelete: SetNull)
  70. inspectionId String?
  71. inspection Inspection? @relation(fields: [inspectionId], references: [id], onDelete: SetNull)
  72. partItems QuotePart[]
  73. /// The equipment it is for, carried to the work order.
  74. equipment QuoteEquipment[]
  75. laborItems QuoteLabor[]
  76. attachments QuoteAttachment[]
  77. @@index([organizationId])
  78. @@map("quotes")
  79. }
  80. model QuoteAttachment {
  81. id String @id @default(cuid())
  82. fileName String
  83. fileUrl String
  84. fileType String
  85. fileSize Int
  86. category String @default("image")
  87. description String?
  88. includeInInvoice Boolean @default(true)
  89. createdAt DateTime @default(now())
  90. quoteId String
  91. quote Quote @relation(fields: [quoteId], references: [id], onDelete: Cascade)
  92. @@index([quoteId])
  93. @@map("quote_attachments")
  94. }
  95. model QuotePart {
  96. id String @id @default(cuid())
  97. partNumber String?
  98. name String
  99. quantity Float @default(1)
  100. /// Unit of measure snapshotted from InventoryPart at pick time; null for
  101. /// free-text lines and legacy rows.
  102. unit String?
  103. /// Category snapshotted from InventoryPart at pick time, or typed on a
  104. /// free-text line; carried into ServicePart on conversion. See there.
  105. category String?
  106. /// Internal purchase cost — never shown to customers (quote PDF/share
  107. /// render unitPrice only)
  108. unitCost Float @default(0)
  109. markupPercent Float @default(0)
  110. unitPrice Float @default(0)
  111. total Float @default(0)
  112. excluded Boolean @default(false)
  113. /// Carried into ServicePart on conversion. See there.
  114. taxable Boolean @default(true)
  115. /// Optional link to the stocked part this line was picked from. Carried into
  116. /// ServicePart on conversion so the job deducts the right inventory item.
  117. inventoryPartId String?
  118. /// Where the line sits on the quote, as the workshop dragged it. Rows are
  119. /// rewritten on every save, so this is the array index they were sent in.
  120. sortOrder Int @default(0)
  121. quoteId String
  122. quote Quote @relation(fields: [quoteId], references: [id], onDelete: Cascade)
  123. @@index([quoteId])
  124. @@map("quote_parts")
  125. }
  126. model QuoteLabor {
  127. id String @id @default(cuid())
  128. description String
  129. hours Float @default(0)
  130. rate Float @default(0)
  131. total Float @default(0)
  132. pricingType String @default("hourly")
  133. excluded Boolean @default(false)
  134. /// Carried into ServiceLabor on conversion. See there.
  135. taxable Boolean @default(true)
  136. /// Where the line sits on the quote. See QuotePart.sortOrder.
  137. sortOrder Int @default(0)
  138. quoteId String
  139. quote Quote @relation(fields: [quoteId], references: [id], onDelete: Cascade)
  140. @@index([quoteId])
  141. @@map("quote_labor")
  142. }