2026-03-14 14:44:40 -05:00
|
|
|
generator client {
|
2026-03-14 15:36:03 -05:00
|
|
|
provider = "prisma-client-js"
|
|
|
|
|
binaryTargets = ["native", "debian-openssl-3.0.x"]
|
2026-03-14 14:44:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
datasource db {
|
|
|
|
|
provider = "sqlite"
|
|
|
|
|
url = env("DATABASE_URL")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model User {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
email String @unique
|
|
|
|
|
passwordHash String
|
|
|
|
|
firstName String
|
|
|
|
|
lastName String
|
|
|
|
|
isActive Boolean @default(true)
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
userRoles UserRole[]
|
2026-03-15 18:59:37 -05:00
|
|
|
authSessions AuthSession[] @relation("AuthSessionUser")
|
|
|
|
|
revokedAuthSessions AuthSession[] @relation("AuthSessionRevokedBy")
|
2026-03-14 16:50:03 -05:00
|
|
|
contactEntries CrmContactEntry[]
|
2026-03-14 22:37:09 -05:00
|
|
|
inventoryTransactions InventoryTransaction[]
|
2026-03-15 09:04:18 -05:00
|
|
|
purchaseReceipts PurchaseReceipt[]
|
2026-03-15 10:13:53 -05:00
|
|
|
ownedProjects Project[] @relation("ProjectOwner")
|
2026-03-15 11:12:58 -05:00
|
|
|
workOrderMaterialIssues WorkOrderMaterialIssue[]
|
|
|
|
|
workOrderCompletions WorkOrderCompletion[]
|
2026-03-18 06:22:37 -05:00
|
|
|
workOrderOperationLaborEntries WorkOrderOperationLaborEntry[]
|
2026-03-18 06:39:38 -05:00
|
|
|
assignedWorkOrderOperations WorkOrderOperation[]
|
2026-03-18 07:27:33 -05:00
|
|
|
shipmentPicks ShipmentPick[]
|
2026-03-18 11:24:59 -05:00
|
|
|
financeCustomerPayments FinanceCustomerPayment[]
|
2026-03-15 11:44:14 -05:00
|
|
|
approvedSalesQuotes SalesQuote[] @relation("SalesQuoteApprovedBy")
|
|
|
|
|
approvedSalesOrders SalesOrder[] @relation("SalesOrderApprovedBy")
|
|
|
|
|
salesQuoteRevisionsCreated SalesQuoteRevision[] @relation("SalesQuoteRevisionCreatedBy")
|
|
|
|
|
salesOrderRevisionsCreated SalesOrderRevision[] @relation("SalesOrderRevisionCreatedBy")
|
2026-03-15 21:07:28 -05:00
|
|
|
purchaseOrderRevisionsCreated PurchaseOrderRevision[]
|
2026-03-15 14:00:12 -05:00
|
|
|
inventoryTransfersCreated InventoryTransfer[] @relation("InventoryTransferCreatedBy")
|
2026-03-15 14:11:21 -05:00
|
|
|
auditEvents AuditEvent[]
|
2026-03-14 14:44:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model Role {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
name String @unique
|
|
|
|
|
description String
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
userRoles UserRole[]
|
|
|
|
|
rolePermissions RolePermission[]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model Permission {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
key String @unique
|
|
|
|
|
description String
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
rolePermissions RolePermission[]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model UserRole {
|
|
|
|
|
userId String
|
|
|
|
|
roleId String
|
|
|
|
|
assignedAt DateTime @default(now())
|
|
|
|
|
assignedBy String?
|
|
|
|
|
role Role @relation(fields: [roleId], references: [id], onDelete: Cascade)
|
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
|
|
|
|
|
|
@@id([userId, roleId])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model RolePermission {
|
|
|
|
|
roleId String
|
|
|
|
|
permissionId String
|
|
|
|
|
grantedAt DateTime @default(now())
|
|
|
|
|
permission Permission @relation(fields: [permissionId], references: [id], onDelete: Cascade)
|
|
|
|
|
role Role @relation(fields: [roleId], references: [id], onDelete: Cascade)
|
|
|
|
|
|
|
|
|
|
@@id([roleId, permissionId])
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-15 18:59:37 -05:00
|
|
|
model AuthSession {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
userId String
|
|
|
|
|
expiresAt DateTime
|
|
|
|
|
lastSeenAt DateTime @default(now())
|
|
|
|
|
ipAddress String?
|
|
|
|
|
userAgent String?
|
|
|
|
|
revokedAt DateTime?
|
|
|
|
|
revokedById String?
|
|
|
|
|
revokedReason String?
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
user User @relation("AuthSessionUser", fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
|
revokedBy User? @relation("AuthSessionRevokedBy", fields: [revokedById], references: [id], onDelete: SetNull)
|
|
|
|
|
|
|
|
|
|
@@index([userId, createdAt])
|
|
|
|
|
@@index([expiresAt])
|
|
|
|
|
@@index([revokedAt])
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-14 14:44:40 -05:00
|
|
|
model CompanyProfile {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
companyName String
|
|
|
|
|
legalName String
|
|
|
|
|
email String
|
|
|
|
|
phone String
|
|
|
|
|
website String
|
|
|
|
|
taxId String
|
|
|
|
|
addressLine1 String
|
|
|
|
|
addressLine2 String
|
|
|
|
|
city String
|
|
|
|
|
state String
|
|
|
|
|
postalCode String
|
|
|
|
|
country String
|
|
|
|
|
primaryColor String @default("#185ADB")
|
|
|
|
|
accentColor String @default("#00A6A6")
|
|
|
|
|
surfaceColor String @default("#F4F7FB")
|
|
|
|
|
fontFamily String @default("Manrope")
|
|
|
|
|
logoFileId String? @unique
|
|
|
|
|
isActive Boolean @default(true)
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
logoFile FileAttachment? @relation("CompanyLogo", fields: [logoFileId], references: [id], onDelete: SetNull)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model FileAttachment {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
originalName String
|
|
|
|
|
storedName String
|
|
|
|
|
mimeType String
|
|
|
|
|
sizeBytes Int
|
|
|
|
|
relativePath String
|
|
|
|
|
ownerType String
|
|
|
|
|
ownerId String
|
|
|
|
|
createdById String?
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
companyLogoFor CompanyProfile? @relation("CompanyLogo")
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-14 21:10:35 -05:00
|
|
|
model InventoryItem {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
sku String @unique
|
2026-03-15 22:17:58 -05:00
|
|
|
skuFamilyId String?
|
|
|
|
|
skuNodeId String?
|
|
|
|
|
skuSequenceNumber Int?
|
2026-03-14 21:10:35 -05:00
|
|
|
name String
|
|
|
|
|
description String
|
|
|
|
|
type String
|
|
|
|
|
status String
|
|
|
|
|
unitOfMeasure String
|
|
|
|
|
isSellable Boolean @default(true)
|
|
|
|
|
isPurchasable Boolean @default(true)
|
2026-03-15 16:40:25 -05:00
|
|
|
preferredVendorId String?
|
2026-03-14 21:10:35 -05:00
|
|
|
defaultCost Float?
|
2026-03-14 23:23:43 -05:00
|
|
|
defaultPrice Float?
|
2026-03-14 21:10:35 -05:00
|
|
|
notes String
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
bomLines InventoryBomLine[] @relation("InventoryBomParent")
|
|
|
|
|
usedInBomLines InventoryBomLine[] @relation("InventoryBomComponent")
|
2026-03-14 22:37:09 -05:00
|
|
|
inventoryTransactions InventoryTransaction[]
|
2026-03-14 23:03:17 -05:00
|
|
|
salesQuoteLines SalesQuoteLine[]
|
|
|
|
|
salesOrderLines SalesOrderLine[]
|
2026-03-15 00:29:41 -05:00
|
|
|
purchaseOrderLines PurchaseOrderLine[]
|
2026-03-15 11:12:58 -05:00
|
|
|
workOrders WorkOrder[]
|
|
|
|
|
workOrderMaterialIssues WorkOrderMaterialIssue[]
|
2026-03-18 07:27:33 -05:00
|
|
|
shipmentPicks ShipmentPick[]
|
2026-03-15 12:11:46 -05:00
|
|
|
operations InventoryItemOperation[]
|
2026-03-15 14:00:12 -05:00
|
|
|
reservations InventoryReservation[]
|
|
|
|
|
transfers InventoryTransfer[]
|
2026-03-15 16:40:25 -05:00
|
|
|
preferredVendor Vendor? @relation(fields: [preferredVendorId], references: [id], onDelete: SetNull)
|
2026-03-15 22:17:58 -05:00
|
|
|
skuFamily InventorySkuFamily? @relation(fields: [skuFamilyId], references: [id], onDelete: SetNull)
|
|
|
|
|
skuNode InventorySkuNode? @relation(fields: [skuNodeId], references: [id], onDelete: SetNull)
|
2026-03-15 16:40:25 -05:00
|
|
|
|
|
|
|
|
@@index([preferredVendorId])
|
2026-03-15 22:17:58 -05:00
|
|
|
@@index([skuFamilyId])
|
|
|
|
|
@@index([skuNodeId])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model InventorySkuFamily {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
code String @unique
|
|
|
|
|
sequenceCode String @unique
|
|
|
|
|
name String
|
|
|
|
|
description String
|
|
|
|
|
nextSequenceNumber Int @default(1)
|
|
|
|
|
isActive Boolean @default(true)
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
nodes InventorySkuNode[]
|
|
|
|
|
items InventoryItem[]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model InventorySkuNode {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
familyId String
|
|
|
|
|
parentNodeId String?
|
|
|
|
|
code String
|
|
|
|
|
label String
|
|
|
|
|
description String
|
|
|
|
|
path String
|
|
|
|
|
level Int
|
|
|
|
|
sortOrder Int @default(0)
|
|
|
|
|
isActive Boolean @default(true)
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
family InventorySkuFamily @relation(fields: [familyId], references: [id], onDelete: Cascade)
|
|
|
|
|
parentNode InventorySkuNode? @relation("InventorySkuNodeTree", fields: [parentNodeId], references: [id], onDelete: Cascade)
|
|
|
|
|
childNodes InventorySkuNode[] @relation("InventorySkuNodeTree")
|
|
|
|
|
items InventoryItem[]
|
|
|
|
|
|
|
|
|
|
@@unique([familyId, path])
|
|
|
|
|
@@index([familyId, parentNodeId, sortOrder])
|
2026-03-14 21:10:35 -05:00
|
|
|
}
|
|
|
|
|
|
2026-03-14 21:23:22 -05:00
|
|
|
model Warehouse {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
code String @unique
|
|
|
|
|
name String
|
|
|
|
|
notes String
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
locations WarehouseLocation[]
|
2026-03-14 22:37:09 -05:00
|
|
|
inventoryTransactions InventoryTransaction[]
|
2026-03-15 09:04:18 -05:00
|
|
|
purchaseReceipts PurchaseReceipt[]
|
2026-03-15 11:12:58 -05:00
|
|
|
workOrders WorkOrder[]
|
|
|
|
|
workOrderMaterialIssues WorkOrderMaterialIssue[]
|
2026-03-18 07:27:33 -05:00
|
|
|
shipmentPicks ShipmentPick[]
|
2026-03-15 14:00:12 -05:00
|
|
|
reservations InventoryReservation[]
|
|
|
|
|
transferSources InventoryTransfer[] @relation("InventoryTransferFromWarehouse")
|
|
|
|
|
transferDestinations InventoryTransfer[] @relation("InventoryTransferToWarehouse")
|
2026-03-14 21:23:22 -05:00
|
|
|
}
|
|
|
|
|
|
2026-03-14 14:44:40 -05:00
|
|
|
model Customer {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
name String
|
|
|
|
|
email String
|
|
|
|
|
phone String
|
|
|
|
|
addressLine1 String
|
|
|
|
|
addressLine2 String
|
|
|
|
|
city String
|
|
|
|
|
state String
|
|
|
|
|
postalCode String
|
|
|
|
|
country String
|
2026-03-14 16:08:29 -05:00
|
|
|
status String @default("ACTIVE")
|
2026-03-14 18:58:23 -05:00
|
|
|
lifecycleStage String @default("ACTIVE")
|
2026-03-14 18:46:06 -05:00
|
|
|
isReseller Boolean @default(false)
|
|
|
|
|
resellerDiscountPercent Float @default(0)
|
|
|
|
|
parentCustomerId String?
|
|
|
|
|
paymentTerms String?
|
|
|
|
|
currencyCode String? @default("USD")
|
|
|
|
|
taxExempt Boolean @default(false)
|
|
|
|
|
creditHold Boolean @default(false)
|
2026-03-14 18:58:23 -05:00
|
|
|
preferredAccount Boolean @default(false)
|
|
|
|
|
strategicAccount Boolean @default(false)
|
|
|
|
|
requiresApproval Boolean @default(false)
|
|
|
|
|
blockedAccount Boolean @default(false)
|
2026-03-14 14:44:40 -05:00
|
|
|
notes String
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
2026-03-14 16:50:03 -05:00
|
|
|
contactEntries CrmContactEntry[]
|
2026-03-14 18:46:06 -05:00
|
|
|
contacts CrmContact[]
|
|
|
|
|
parentCustomer Customer? @relation("CustomerHierarchy", fields: [parentCustomerId], references: [id], onDelete: SetNull)
|
|
|
|
|
childCustomers Customer[] @relation("CustomerHierarchy")
|
2026-03-14 23:03:17 -05:00
|
|
|
salesQuotes SalesQuote[]
|
|
|
|
|
salesOrders SalesOrder[]
|
2026-03-15 10:13:53 -05:00
|
|
|
projects Project[]
|
2026-03-14 14:44:40 -05:00
|
|
|
}
|
|
|
|
|
|
2026-03-14 21:10:35 -05:00
|
|
|
model InventoryBomLine {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
parentItemId String
|
|
|
|
|
componentItemId String
|
|
|
|
|
quantity Float
|
|
|
|
|
unitOfMeasure String
|
|
|
|
|
notes String
|
|
|
|
|
position Int @default(0)
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
parentItem InventoryItem @relation("InventoryBomParent", fields: [parentItemId], references: [id], onDelete: Cascade)
|
|
|
|
|
componentItem InventoryItem @relation("InventoryBomComponent", fields: [componentItemId], references: [id], onDelete: Restrict)
|
|
|
|
|
|
|
|
|
|
@@index([parentItemId, position])
|
|
|
|
|
@@index([componentItemId])
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-14 21:23:22 -05:00
|
|
|
model WarehouseLocation {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
warehouseId String
|
|
|
|
|
code String
|
|
|
|
|
name String
|
|
|
|
|
notes String
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
warehouse Warehouse @relation(fields: [warehouseId], references: [id], onDelete: Cascade)
|
2026-03-14 22:37:09 -05:00
|
|
|
inventoryTransactions InventoryTransaction[]
|
2026-03-15 09:04:18 -05:00
|
|
|
purchaseReceipts PurchaseReceipt[]
|
2026-03-15 11:12:58 -05:00
|
|
|
workOrders WorkOrder[]
|
|
|
|
|
workOrderMaterialIssues WorkOrderMaterialIssue[]
|
2026-03-18 07:27:33 -05:00
|
|
|
shipmentPicks ShipmentPick[]
|
2026-03-15 14:00:12 -05:00
|
|
|
reservations InventoryReservation[]
|
|
|
|
|
transferSourceLocations InventoryTransfer[] @relation("InventoryTransferFromLocation")
|
|
|
|
|
transferDestinationLocations InventoryTransfer[] @relation("InventoryTransferToLocation")
|
2026-03-14 21:23:22 -05:00
|
|
|
|
|
|
|
|
@@unique([warehouseId, code])
|
|
|
|
|
@@index([warehouseId])
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-14 22:37:09 -05:00
|
|
|
model InventoryTransaction {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
itemId String
|
|
|
|
|
warehouseId String
|
|
|
|
|
locationId String
|
|
|
|
|
transactionType String
|
|
|
|
|
quantity Int
|
|
|
|
|
reference String
|
|
|
|
|
notes String
|
|
|
|
|
createdById String?
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
item InventoryItem @relation(fields: [itemId], references: [id], onDelete: Cascade)
|
|
|
|
|
warehouse Warehouse @relation(fields: [warehouseId], references: [id], onDelete: Restrict)
|
|
|
|
|
location WarehouseLocation @relation(fields: [locationId], references: [id], onDelete: Restrict)
|
|
|
|
|
createdBy User? @relation(fields: [createdById], references: [id], onDelete: SetNull)
|
|
|
|
|
|
|
|
|
|
@@index([itemId, createdAt])
|
|
|
|
|
@@index([warehouseId, createdAt])
|
|
|
|
|
@@index([locationId, createdAt])
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-15 14:00:12 -05:00
|
|
|
model InventoryTransfer {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
itemId String
|
|
|
|
|
fromWarehouseId String
|
|
|
|
|
fromLocationId String
|
|
|
|
|
toWarehouseId String
|
|
|
|
|
toLocationId String
|
|
|
|
|
quantity Int
|
|
|
|
|
notes String
|
|
|
|
|
createdById String?
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
item InventoryItem @relation(fields: [itemId], references: [id], onDelete: Cascade)
|
|
|
|
|
fromWarehouse Warehouse @relation("InventoryTransferFromWarehouse", fields: [fromWarehouseId], references: [id], onDelete: Restrict)
|
|
|
|
|
fromLocation WarehouseLocation @relation("InventoryTransferFromLocation", fields: [fromLocationId], references: [id], onDelete: Restrict)
|
|
|
|
|
toWarehouse Warehouse @relation("InventoryTransferToWarehouse", fields: [toWarehouseId], references: [id], onDelete: Restrict)
|
|
|
|
|
toLocation WarehouseLocation @relation("InventoryTransferToLocation", fields: [toLocationId], references: [id], onDelete: Restrict)
|
|
|
|
|
createdBy User? @relation("InventoryTransferCreatedBy", fields: [createdById], references: [id], onDelete: SetNull)
|
|
|
|
|
|
|
|
|
|
@@index([itemId, createdAt])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model InventoryReservation {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
itemId String
|
|
|
|
|
warehouseId String?
|
|
|
|
|
locationId String?
|
|
|
|
|
workOrderId String?
|
|
|
|
|
sourceType String
|
|
|
|
|
sourceId String?
|
|
|
|
|
quantity Int
|
|
|
|
|
status String @default("ACTIVE")
|
|
|
|
|
notes String
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
item InventoryItem @relation(fields: [itemId], references: [id], onDelete: Cascade)
|
|
|
|
|
warehouse Warehouse? @relation(fields: [warehouseId], references: [id], onDelete: SetNull)
|
|
|
|
|
location WarehouseLocation? @relation(fields: [locationId], references: [id], onDelete: SetNull)
|
|
|
|
|
workOrder WorkOrder? @relation(fields: [workOrderId], references: [id], onDelete: Cascade)
|
|
|
|
|
|
|
|
|
|
@@index([itemId, status, createdAt])
|
|
|
|
|
@@index([warehouseId, locationId, status])
|
|
|
|
|
@@index([workOrderId, status])
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-14 14:44:40 -05:00
|
|
|
model Vendor {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
name String
|
|
|
|
|
email String
|
|
|
|
|
phone String
|
|
|
|
|
addressLine1 String
|
|
|
|
|
addressLine2 String
|
|
|
|
|
city String
|
|
|
|
|
state String
|
|
|
|
|
postalCode String
|
|
|
|
|
country String
|
2026-03-14 16:08:29 -05:00
|
|
|
status String @default("ACTIVE")
|
2026-03-14 18:58:23 -05:00
|
|
|
lifecycleStage String @default("ACTIVE")
|
2026-03-14 18:46:06 -05:00
|
|
|
paymentTerms String?
|
|
|
|
|
currencyCode String? @default("USD")
|
|
|
|
|
taxExempt Boolean @default(false)
|
|
|
|
|
creditHold Boolean @default(false)
|
2026-03-14 18:58:23 -05:00
|
|
|
preferredAccount Boolean @default(false)
|
|
|
|
|
strategicAccount Boolean @default(false)
|
|
|
|
|
requiresApproval Boolean @default(false)
|
|
|
|
|
blockedAccount Boolean @default(false)
|
2026-03-14 14:44:40 -05:00
|
|
|
notes String
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
2026-03-14 16:50:03 -05:00
|
|
|
contactEntries CrmContactEntry[]
|
2026-03-14 18:46:06 -05:00
|
|
|
contacts CrmContact[]
|
2026-03-15 00:29:41 -05:00
|
|
|
purchaseOrders PurchaseOrder[]
|
2026-03-18 11:24:59 -05:00
|
|
|
capexEntries CapexEntry[]
|
2026-03-15 16:40:25 -05:00
|
|
|
preferredSupplyItems InventoryItem[]
|
2026-03-14 16:50:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model CrmContactEntry {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
type String @default("NOTE")
|
|
|
|
|
summary String
|
|
|
|
|
body String
|
|
|
|
|
contactAt DateTime
|
|
|
|
|
customerId String?
|
|
|
|
|
vendorId String?
|
|
|
|
|
createdById String?
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
customer Customer? @relation(fields: [customerId], references: [id], onDelete: Cascade)
|
|
|
|
|
vendor Vendor? @relation(fields: [vendorId], references: [id], onDelete: Cascade)
|
|
|
|
|
createdBy User? @relation(fields: [createdById], references: [id], onDelete: SetNull)
|
2026-03-14 14:44:40 -05:00
|
|
|
}
|
2026-03-14 18:46:06 -05:00
|
|
|
|
|
|
|
|
model CrmContact {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
fullName String
|
|
|
|
|
role String @default("OTHER")
|
|
|
|
|
email String
|
|
|
|
|
phone String
|
|
|
|
|
isPrimary Boolean @default(false)
|
|
|
|
|
customerId String?
|
|
|
|
|
vendorId String?
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
customer Customer? @relation(fields: [customerId], references: [id], onDelete: Cascade)
|
|
|
|
|
vendor Vendor? @relation(fields: [vendorId], references: [id], onDelete: Cascade)
|
|
|
|
|
}
|
2026-03-14 23:03:17 -05:00
|
|
|
|
|
|
|
|
model SalesQuote {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
documentNumber String @unique
|
|
|
|
|
customerId String
|
|
|
|
|
status String
|
|
|
|
|
issueDate DateTime
|
|
|
|
|
expiresAt DateTime?
|
2026-03-15 11:44:14 -05:00
|
|
|
approvedAt DateTime?
|
|
|
|
|
approvedById String?
|
2026-03-14 23:39:51 -05:00
|
|
|
discountPercent Float @default(0)
|
|
|
|
|
taxPercent Float @default(0)
|
|
|
|
|
freightAmount Float @default(0)
|
2026-03-14 23:03:17 -05:00
|
|
|
notes String
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
customer Customer @relation(fields: [customerId], references: [id], onDelete: Restrict)
|
2026-03-15 11:44:14 -05:00
|
|
|
approvedBy User? @relation("SalesQuoteApprovedBy", fields: [approvedById], references: [id], onDelete: SetNull)
|
2026-03-14 23:03:17 -05:00
|
|
|
lines SalesQuoteLine[]
|
2026-03-15 10:13:53 -05:00
|
|
|
projects Project[]
|
2026-03-15 11:44:14 -05:00
|
|
|
revisions SalesQuoteRevision[]
|
2026-03-14 23:03:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model SalesQuoteLine {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
quoteId String
|
|
|
|
|
itemId String
|
|
|
|
|
description String
|
|
|
|
|
quantity Int
|
|
|
|
|
unitOfMeasure String
|
|
|
|
|
unitPrice Float
|
|
|
|
|
position Int @default(0)
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
quote SalesQuote @relation(fields: [quoteId], references: [id], onDelete: Cascade)
|
|
|
|
|
item InventoryItem @relation(fields: [itemId], references: [id], onDelete: Restrict)
|
|
|
|
|
|
|
|
|
|
@@index([quoteId, position])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model SalesOrder {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
documentNumber String @unique
|
|
|
|
|
customerId String
|
|
|
|
|
status String
|
|
|
|
|
issueDate DateTime
|
2026-03-15 11:44:14 -05:00
|
|
|
approvedAt DateTime?
|
|
|
|
|
approvedById String?
|
2026-03-14 23:39:51 -05:00
|
|
|
discountPercent Float @default(0)
|
|
|
|
|
taxPercent Float @default(0)
|
|
|
|
|
freightAmount Float @default(0)
|
2026-03-14 23:03:17 -05:00
|
|
|
notes String
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
customer Customer @relation(fields: [customerId], references: [id], onDelete: Restrict)
|
2026-03-15 11:44:14 -05:00
|
|
|
approvedBy User? @relation("SalesOrderApprovedBy", fields: [approvedById], references: [id], onDelete: SetNull)
|
2026-03-14 23:03:17 -05:00
|
|
|
lines SalesOrderLine[]
|
2026-03-14 23:48:27 -05:00
|
|
|
shipments Shipment[]
|
2026-03-15 10:13:53 -05:00
|
|
|
projects Project[]
|
2026-03-15 11:44:14 -05:00
|
|
|
revisions SalesOrderRevision[]
|
2026-03-15 16:40:25 -05:00
|
|
|
workOrders WorkOrder[]
|
|
|
|
|
purchaseOrderLines PurchaseOrderLine[]
|
2026-03-18 11:24:59 -05:00
|
|
|
customerPayments FinanceCustomerPayment[]
|
2026-03-14 23:03:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model SalesOrderLine {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
orderId String
|
|
|
|
|
itemId String
|
|
|
|
|
description String
|
|
|
|
|
quantity Int
|
|
|
|
|
unitOfMeasure String
|
|
|
|
|
unitPrice Float
|
|
|
|
|
position Int @default(0)
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
order SalesOrder @relation(fields: [orderId], references: [id], onDelete: Cascade)
|
|
|
|
|
item InventoryItem @relation(fields: [itemId], references: [id], onDelete: Restrict)
|
2026-03-15 16:40:25 -05:00
|
|
|
workOrders WorkOrder[]
|
|
|
|
|
purchaseOrderLines PurchaseOrderLine[]
|
2026-03-18 07:27:33 -05:00
|
|
|
shipmentPicks ShipmentPick[]
|
2026-03-14 23:03:17 -05:00
|
|
|
|
|
|
|
|
@@index([orderId, position])
|
|
|
|
|
}
|
2026-03-14 23:48:27 -05:00
|
|
|
|
2026-03-15 11:44:14 -05:00
|
|
|
model SalesQuoteRevision {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
quoteId String
|
|
|
|
|
revisionNumber Int
|
|
|
|
|
reason String
|
|
|
|
|
snapshot String
|
|
|
|
|
createdById String?
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
quote SalesQuote @relation(fields: [quoteId], references: [id], onDelete: Cascade)
|
|
|
|
|
createdBy User? @relation("SalesQuoteRevisionCreatedBy", fields: [createdById], references: [id], onDelete: SetNull)
|
|
|
|
|
|
|
|
|
|
@@unique([quoteId, revisionNumber])
|
|
|
|
|
@@index([quoteId, createdAt])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model SalesOrderRevision {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
orderId String
|
|
|
|
|
revisionNumber Int
|
|
|
|
|
reason String
|
|
|
|
|
snapshot String
|
|
|
|
|
createdById String?
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
order SalesOrder @relation(fields: [orderId], references: [id], onDelete: Cascade)
|
|
|
|
|
createdBy User? @relation("SalesOrderRevisionCreatedBy", fields: [createdById], references: [id], onDelete: SetNull)
|
|
|
|
|
|
|
|
|
|
@@unique([orderId, revisionNumber])
|
|
|
|
|
@@index([orderId, createdAt])
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-14 23:48:27 -05:00
|
|
|
model Shipment {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
shipmentNumber String @unique
|
|
|
|
|
salesOrderId String
|
|
|
|
|
status String
|
|
|
|
|
shipDate DateTime?
|
|
|
|
|
carrier String
|
|
|
|
|
serviceLevel String
|
|
|
|
|
trackingNumber String
|
|
|
|
|
packageCount Int @default(1)
|
|
|
|
|
notes String
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
salesOrder SalesOrder @relation(fields: [salesOrderId], references: [id], onDelete: Restrict)
|
2026-03-15 10:13:53 -05:00
|
|
|
projects Project[]
|
2026-03-18 07:27:33 -05:00
|
|
|
picks ShipmentPick[]
|
2026-03-14 23:48:27 -05:00
|
|
|
|
|
|
|
|
@@index([salesOrderId, createdAt])
|
|
|
|
|
}
|
2026-03-15 00:29:41 -05:00
|
|
|
|
2026-03-18 07:27:33 -05:00
|
|
|
model ShipmentPick {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
shipmentId String
|
|
|
|
|
salesOrderLineId String
|
|
|
|
|
itemId String
|
|
|
|
|
warehouseId String
|
|
|
|
|
locationId String
|
|
|
|
|
quantity Int
|
|
|
|
|
notes String
|
|
|
|
|
createdById String?
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
shipment Shipment @relation(fields: [shipmentId], references: [id], onDelete: Cascade)
|
|
|
|
|
salesOrderLine SalesOrderLine @relation(fields: [salesOrderLineId], references: [id], onDelete: Restrict)
|
|
|
|
|
item InventoryItem @relation(fields: [itemId], references: [id], onDelete: Restrict)
|
|
|
|
|
warehouse Warehouse @relation(fields: [warehouseId], references: [id], onDelete: Restrict)
|
|
|
|
|
location WarehouseLocation @relation(fields: [locationId], references: [id], onDelete: Restrict)
|
|
|
|
|
createdBy User? @relation(fields: [createdById], references: [id], onDelete: SetNull)
|
|
|
|
|
|
|
|
|
|
@@index([shipmentId, createdAt])
|
|
|
|
|
@@index([salesOrderLineId, createdAt])
|
|
|
|
|
@@index([warehouseId, locationId, createdAt])
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-15 10:13:53 -05:00
|
|
|
model Project {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
projectNumber String @unique
|
|
|
|
|
name String
|
|
|
|
|
status String
|
|
|
|
|
priority String
|
|
|
|
|
customerId String
|
|
|
|
|
salesQuoteId String?
|
|
|
|
|
salesOrderId String?
|
|
|
|
|
shipmentId String?
|
|
|
|
|
ownerId String?
|
|
|
|
|
dueDate DateTime?
|
|
|
|
|
notes String
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
customer Customer @relation(fields: [customerId], references: [id], onDelete: Restrict)
|
|
|
|
|
salesQuote SalesQuote? @relation(fields: [salesQuoteId], references: [id], onDelete: SetNull)
|
|
|
|
|
salesOrder SalesOrder? @relation(fields: [salesOrderId], references: [id], onDelete: SetNull)
|
|
|
|
|
shipment Shipment? @relation(fields: [shipmentId], references: [id], onDelete: SetNull)
|
|
|
|
|
owner User? @relation("ProjectOwner", fields: [ownerId], references: [id], onDelete: SetNull)
|
2026-03-15 11:12:58 -05:00
|
|
|
workOrders WorkOrder[]
|
2026-03-17 07:34:08 -05:00
|
|
|
milestones ProjectMilestone[]
|
2026-03-15 10:13:53 -05:00
|
|
|
|
|
|
|
|
@@index([customerId, createdAt])
|
|
|
|
|
@@index([ownerId, dueDate])
|
|
|
|
|
@@index([status, priority])
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-17 07:34:08 -05:00
|
|
|
model ProjectMilestone {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
projectId String
|
|
|
|
|
title String
|
|
|
|
|
status String
|
|
|
|
|
dueDate DateTime?
|
|
|
|
|
completedAt DateTime?
|
|
|
|
|
notes String
|
|
|
|
|
sortOrder Int @default(0)
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
|
|
|
|
|
|
|
|
|
|
@@index([projectId, sortOrder])
|
|
|
|
|
@@index([projectId, dueDate])
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-15 11:12:58 -05:00
|
|
|
model WorkOrder {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
workOrderNumber String @unique
|
|
|
|
|
itemId String
|
|
|
|
|
projectId String?
|
2026-03-15 16:40:25 -05:00
|
|
|
salesOrderId String?
|
|
|
|
|
salesOrderLineId String?
|
2026-03-15 11:12:58 -05:00
|
|
|
warehouseId String
|
|
|
|
|
locationId String
|
|
|
|
|
status String
|
|
|
|
|
quantity Int
|
|
|
|
|
completedQuantity Int @default(0)
|
|
|
|
|
dueDate DateTime?
|
|
|
|
|
notes String
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
item InventoryItem @relation(fields: [itemId], references: [id], onDelete: Restrict)
|
|
|
|
|
project Project? @relation(fields: [projectId], references: [id], onDelete: SetNull)
|
2026-03-15 16:40:25 -05:00
|
|
|
salesOrder SalesOrder? @relation(fields: [salesOrderId], references: [id], onDelete: SetNull)
|
|
|
|
|
salesOrderLine SalesOrderLine? @relation(fields: [salesOrderLineId], references: [id], onDelete: SetNull)
|
2026-03-15 11:12:58 -05:00
|
|
|
warehouse Warehouse @relation(fields: [warehouseId], references: [id], onDelete: Restrict)
|
|
|
|
|
location WarehouseLocation @relation(fields: [locationId], references: [id], onDelete: Restrict)
|
2026-03-15 12:11:46 -05:00
|
|
|
operations WorkOrderOperation[]
|
2026-03-15 11:12:58 -05:00
|
|
|
materialIssues WorkOrderMaterialIssue[]
|
|
|
|
|
completions WorkOrderCompletion[]
|
2026-03-15 14:00:12 -05:00
|
|
|
reservations InventoryReservation[]
|
2026-03-18 11:24:59 -05:00
|
|
|
financeCostSnapshot FinanceManufacturingCostSnapshot?
|
2026-03-15 11:12:58 -05:00
|
|
|
|
|
|
|
|
@@index([itemId, createdAt])
|
|
|
|
|
@@index([projectId, dueDate])
|
2026-03-15 16:40:25 -05:00
|
|
|
@@index([salesOrderId, dueDate])
|
|
|
|
|
@@index([salesOrderLineId, dueDate])
|
2026-03-15 11:12:58 -05:00
|
|
|
@@index([status, dueDate])
|
|
|
|
|
@@index([warehouseId, createdAt])
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-15 12:11:46 -05:00
|
|
|
model ManufacturingStation {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
code String @unique
|
|
|
|
|
name String
|
|
|
|
|
description String
|
|
|
|
|
queueDays Int @default(0)
|
2026-03-18 00:10:15 -05:00
|
|
|
dailyCapacityMinutes Int @default(480)
|
|
|
|
|
parallelCapacity Int @default(1)
|
|
|
|
|
workingDays String @default("1,2,3,4,5")
|
2026-03-15 12:11:46 -05:00
|
|
|
isActive Boolean @default(true)
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
itemOperations InventoryItemOperation[]
|
|
|
|
|
workOrderOperations WorkOrderOperation[]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model InventoryItemOperation {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
itemId String
|
|
|
|
|
stationId String
|
|
|
|
|
setupMinutes Int @default(0)
|
|
|
|
|
runMinutesPerUnit Int @default(0)
|
|
|
|
|
moveMinutes Int @default(0)
|
|
|
|
|
notes String
|
|
|
|
|
position Int @default(0)
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
item InventoryItem @relation(fields: [itemId], references: [id], onDelete: Cascade)
|
|
|
|
|
station ManufacturingStation @relation(fields: [stationId], references: [id], onDelete: Restrict)
|
|
|
|
|
|
|
|
|
|
@@index([itemId, position])
|
|
|
|
|
@@index([stationId])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model WorkOrderOperation {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
workOrderId String
|
|
|
|
|
stationId String
|
2026-03-18 06:39:38 -05:00
|
|
|
assignedOperatorId String?
|
2026-03-15 12:11:46 -05:00
|
|
|
sequence Int
|
|
|
|
|
setupMinutes Int @default(0)
|
|
|
|
|
runMinutesPerUnit Int @default(0)
|
|
|
|
|
moveMinutes Int @default(0)
|
|
|
|
|
plannedMinutes Int @default(0)
|
|
|
|
|
plannedStart DateTime
|
|
|
|
|
plannedEnd DateTime
|
|
|
|
|
notes String
|
2026-03-18 06:22:37 -05:00
|
|
|
status String @default("PENDING")
|
|
|
|
|
actualStart DateTime?
|
|
|
|
|
actualEnd DateTime?
|
|
|
|
|
actualMinutes Int @default(0)
|
2026-03-18 06:39:38 -05:00
|
|
|
activeTimerStartedAt DateTime?
|
2026-03-15 12:11:46 -05:00
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
workOrder WorkOrder @relation(fields: [workOrderId], references: [id], onDelete: Cascade)
|
|
|
|
|
station ManufacturingStation @relation(fields: [stationId], references: [id], onDelete: Restrict)
|
2026-03-18 06:39:38 -05:00
|
|
|
assignedOperator User? @relation(fields: [assignedOperatorId], references: [id], onDelete: SetNull)
|
2026-03-18 06:22:37 -05:00
|
|
|
laborEntries WorkOrderOperationLaborEntry[]
|
2026-03-15 12:11:46 -05:00
|
|
|
|
|
|
|
|
@@index([workOrderId, sequence])
|
|
|
|
|
@@index([stationId, plannedStart])
|
2026-03-18 06:39:38 -05:00
|
|
|
@@index([assignedOperatorId, plannedStart])
|
2026-03-15 12:11:46 -05:00
|
|
|
}
|
|
|
|
|
|
2026-03-18 06:22:37 -05:00
|
|
|
model WorkOrderOperationLaborEntry {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
operationId String
|
|
|
|
|
minutes Int
|
|
|
|
|
notes String
|
|
|
|
|
createdById String?
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
operation WorkOrderOperation @relation(fields: [operationId], references: [id], onDelete: Cascade)
|
|
|
|
|
createdBy User? @relation(fields: [createdById], references: [id], onDelete: SetNull)
|
|
|
|
|
|
|
|
|
|
@@index([operationId, createdAt])
|
|
|
|
|
@@index([createdById, createdAt])
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-15 11:12:58 -05:00
|
|
|
model WorkOrderMaterialIssue {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
workOrderId String
|
|
|
|
|
componentItemId String
|
|
|
|
|
warehouseId String
|
|
|
|
|
locationId String
|
|
|
|
|
quantity Int
|
|
|
|
|
notes String
|
|
|
|
|
createdById String?
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
workOrder WorkOrder @relation(fields: [workOrderId], references: [id], onDelete: Cascade)
|
|
|
|
|
componentItem InventoryItem @relation(fields: [componentItemId], references: [id], onDelete: Restrict)
|
|
|
|
|
warehouse Warehouse @relation(fields: [warehouseId], references: [id], onDelete: Restrict)
|
|
|
|
|
location WarehouseLocation @relation(fields: [locationId], references: [id], onDelete: Restrict)
|
|
|
|
|
createdBy User? @relation(fields: [createdById], references: [id], onDelete: SetNull)
|
|
|
|
|
|
|
|
|
|
@@index([workOrderId, createdAt])
|
|
|
|
|
@@index([componentItemId, createdAt])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model WorkOrderCompletion {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
workOrderId String
|
|
|
|
|
quantity Int
|
|
|
|
|
notes String
|
|
|
|
|
createdById String?
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
workOrder WorkOrder @relation(fields: [workOrderId], references: [id], onDelete: Cascade)
|
|
|
|
|
createdBy User? @relation(fields: [createdById], references: [id], onDelete: SetNull)
|
|
|
|
|
|
|
|
|
|
@@index([workOrderId, createdAt])
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-18 11:24:59 -05:00
|
|
|
model FinanceProfile {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
currencyCode String @default("USD")
|
|
|
|
|
standardLaborRatePerHour Float @default(45)
|
|
|
|
|
overheadRatePerHour Float @default(18)
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model FinanceCustomerPayment {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
salesOrderId String
|
|
|
|
|
paymentType String
|
|
|
|
|
paymentMethod String
|
|
|
|
|
paymentDate DateTime
|
|
|
|
|
amount Float
|
|
|
|
|
reference String
|
|
|
|
|
notes String
|
|
|
|
|
createdById String?
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
salesOrder SalesOrder @relation(fields: [salesOrderId], references: [id], onDelete: Cascade)
|
|
|
|
|
createdBy User? @relation(fields: [createdById], references: [id], onDelete: SetNull)
|
|
|
|
|
|
|
|
|
|
@@index([salesOrderId, paymentDate])
|
|
|
|
|
@@index([createdAt])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model FinanceManufacturingCostSnapshot {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
workOrderId String @unique
|
|
|
|
|
materialCost Float @default(0)
|
|
|
|
|
laborCost Float @default(0)
|
|
|
|
|
overheadCost Float @default(0)
|
|
|
|
|
totalCost Float @default(0)
|
|
|
|
|
materialIssueCount Int @default(0)
|
|
|
|
|
laborEntryCount Int @default(0)
|
|
|
|
|
calculatedAt DateTime @default(now())
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
workOrder WorkOrder @relation(fields: [workOrderId], references: [id], onDelete: Cascade)
|
|
|
|
|
|
|
|
|
|
@@index([calculatedAt])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model CapexEntry {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
title String
|
|
|
|
|
category String
|
|
|
|
|
status String
|
|
|
|
|
vendorId String?
|
|
|
|
|
purchaseOrderId String?
|
|
|
|
|
plannedAmount Float
|
|
|
|
|
actualAmount Float
|
|
|
|
|
requestDate DateTime
|
|
|
|
|
targetInServiceDate DateTime?
|
|
|
|
|
purchasedAt DateTime?
|
|
|
|
|
notes String
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
vendor Vendor? @relation(fields: [vendorId], references: [id], onDelete: SetNull)
|
|
|
|
|
purchaseOrder PurchaseOrder? @relation(fields: [purchaseOrderId], references: [id], onDelete: SetNull)
|
|
|
|
|
|
|
|
|
|
@@index([status, requestDate])
|
|
|
|
|
@@index([vendorId, createdAt])
|
|
|
|
|
@@index([purchaseOrderId, createdAt])
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-15 00:29:41 -05:00
|
|
|
model PurchaseOrder {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
documentNumber String @unique
|
|
|
|
|
vendorId String
|
|
|
|
|
status String
|
|
|
|
|
issueDate DateTime
|
|
|
|
|
taxPercent Float @default(0)
|
|
|
|
|
freightAmount Float @default(0)
|
|
|
|
|
notes String
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
vendor Vendor @relation(fields: [vendorId], references: [id], onDelete: Restrict)
|
|
|
|
|
lines PurchaseOrderLine[]
|
2026-03-15 09:04:18 -05:00
|
|
|
receipts PurchaseReceipt[]
|
2026-03-15 21:07:28 -05:00
|
|
|
revisions PurchaseOrderRevision[]
|
2026-03-18 11:24:59 -05:00
|
|
|
capexEntries CapexEntry[]
|
2026-03-15 00:29:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model PurchaseOrderLine {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
purchaseOrderId String
|
|
|
|
|
itemId String
|
2026-03-15 16:40:25 -05:00
|
|
|
salesOrderId String?
|
|
|
|
|
salesOrderLineId String?
|
2026-03-15 00:29:41 -05:00
|
|
|
description String
|
|
|
|
|
quantity Int
|
|
|
|
|
unitOfMeasure String
|
|
|
|
|
unitCost Float
|
|
|
|
|
position Int @default(0)
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
purchaseOrder PurchaseOrder @relation(fields: [purchaseOrderId], references: [id], onDelete: Cascade)
|
|
|
|
|
item InventoryItem @relation(fields: [itemId], references: [id], onDelete: Restrict)
|
2026-03-15 16:40:25 -05:00
|
|
|
salesOrder SalesOrder? @relation(fields: [salesOrderId], references: [id], onDelete: SetNull)
|
|
|
|
|
salesOrderLine SalesOrderLine? @relation(fields: [salesOrderLineId], references: [id], onDelete: SetNull)
|
2026-03-15 09:04:18 -05:00
|
|
|
receiptLines PurchaseReceiptLine[]
|
2026-03-15 00:29:41 -05:00
|
|
|
|
|
|
|
|
@@index([purchaseOrderId, position])
|
2026-03-15 16:40:25 -05:00
|
|
|
@@index([salesOrderId, position])
|
|
|
|
|
@@index([salesOrderLineId, position])
|
2026-03-15 00:29:41 -05:00
|
|
|
}
|
2026-03-15 09:04:18 -05:00
|
|
|
|
|
|
|
|
model PurchaseReceipt {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
receiptNumber String @unique
|
|
|
|
|
purchaseOrderId String
|
|
|
|
|
warehouseId String
|
|
|
|
|
locationId String
|
|
|
|
|
receivedAt DateTime
|
|
|
|
|
notes String
|
|
|
|
|
createdById String?
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
purchaseOrder PurchaseOrder @relation(fields: [purchaseOrderId], references: [id], onDelete: Cascade)
|
|
|
|
|
warehouse Warehouse @relation(fields: [warehouseId], references: [id], onDelete: Restrict)
|
|
|
|
|
location WarehouseLocation @relation(fields: [locationId], references: [id], onDelete: Restrict)
|
|
|
|
|
createdBy User? @relation(fields: [createdById], references: [id], onDelete: SetNull)
|
|
|
|
|
lines PurchaseReceiptLine[]
|
|
|
|
|
|
|
|
|
|
@@index([purchaseOrderId, createdAt])
|
|
|
|
|
@@index([warehouseId, createdAt])
|
|
|
|
|
@@index([locationId, createdAt])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model PurchaseReceiptLine {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
purchaseReceiptId String
|
|
|
|
|
purchaseOrderLineId String
|
|
|
|
|
quantity Int
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
purchaseReceipt PurchaseReceipt @relation(fields: [purchaseReceiptId], references: [id], onDelete: Cascade)
|
|
|
|
|
purchaseOrderLine PurchaseOrderLine @relation(fields: [purchaseOrderLineId], references: [id], onDelete: Restrict)
|
|
|
|
|
|
|
|
|
|
@@index([purchaseReceiptId])
|
|
|
|
|
@@index([purchaseOrderLineId])
|
|
|
|
|
}
|
2026-03-15 14:11:21 -05:00
|
|
|
|
2026-03-15 21:07:28 -05:00
|
|
|
model PurchaseOrderRevision {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
purchaseOrderId String
|
|
|
|
|
revisionNumber Int
|
|
|
|
|
reason String
|
|
|
|
|
snapshot String
|
|
|
|
|
createdById String?
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
updatedAt DateTime @updatedAt
|
|
|
|
|
purchaseOrder PurchaseOrder @relation(fields: [purchaseOrderId], references: [id], onDelete: Cascade)
|
|
|
|
|
createdBy User? @relation(fields: [createdById], references: [id], onDelete: SetNull)
|
|
|
|
|
|
|
|
|
|
@@unique([purchaseOrderId, revisionNumber])
|
|
|
|
|
@@index([purchaseOrderId, createdAt])
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-15 14:11:21 -05:00
|
|
|
model AuditEvent {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
actorId String?
|
|
|
|
|
entityType String
|
|
|
|
|
entityId String?
|
|
|
|
|
action String
|
|
|
|
|
summary String
|
|
|
|
|
metadataJson String
|
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
|
actor User? @relation(fields: [actorId], references: [id], onDelete: SetNull)
|
|
|
|
|
|
|
|
|
|
@@index([createdAt])
|
|
|
|
|
@@index([entityType, entityId, createdAt])
|
|
|
|
|
@@index([actorId, createdAt])
|
|
|
|
|
}
|