264 lines
6.3 KiB
Plaintext
264 lines
6.3 KiB
Plaintext
datasource db {
|
|
provider = "postgresql"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
enum Role {
|
|
ADMIN
|
|
MANAGER
|
|
INVENTORY
|
|
SALES
|
|
PURCHASING
|
|
ACCOUNTANT
|
|
}
|
|
|
|
enum MovementType {
|
|
IN
|
|
OUT
|
|
ADJUSTMENT
|
|
TRANSFER
|
|
}
|
|
|
|
enum OrderStatus {
|
|
DRAFT
|
|
CONFIRMED
|
|
SHIPPED
|
|
COMPLETED
|
|
CANCELLED
|
|
}
|
|
|
|
enum PaymentStatus {
|
|
UNPAID
|
|
PARTIAL
|
|
PAID
|
|
}
|
|
|
|
enum POStatus {
|
|
DRAFT
|
|
ORDERED
|
|
RECEIVED
|
|
CANCELLED
|
|
}
|
|
|
|
enum AccountType {
|
|
ASSET
|
|
LIABILITY
|
|
EQUITY
|
|
REVENUE
|
|
EXPENSE
|
|
}
|
|
|
|
enum EntryType {
|
|
DEBIT
|
|
CREDIT
|
|
}
|
|
|
|
model User {
|
|
id String @id @default(uuid())
|
|
email String @unique
|
|
name String
|
|
password String
|
|
role Role @default(SALES)
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
auditLogs AuditLog[]
|
|
}
|
|
|
|
model AuditLog {
|
|
id String @id @default(uuid())
|
|
userId String?
|
|
userName String?
|
|
action String // CREATE, UPDATE, DELETE, LOGIN, APPROVE
|
|
module String // INVENTORY, SALES, PURCHASING, FINANCE, AUTH
|
|
description String
|
|
metadata String? // JSON string for extra payload
|
|
createdAt DateTime @default(now())
|
|
|
|
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
|
|
}
|
|
|
|
model Warehouse {
|
|
id String @id @default(uuid())
|
|
code String @unique
|
|
name String
|
|
address String?
|
|
createdAt DateTime @default(now())
|
|
|
|
stockItems StockItem[]
|
|
stockMovements StockMovement[]
|
|
}
|
|
|
|
model Category {
|
|
id String @id @default(uuid())
|
|
name String @unique
|
|
description String?
|
|
products Product[]
|
|
}
|
|
|
|
model Product {
|
|
id String @id @default(uuid())
|
|
sku String @unique
|
|
name String
|
|
description String?
|
|
unit String @default("PCS") // PCS, BOX, KG, LTR, MTR
|
|
purchasePrice Float @default(0)
|
|
sellingPrice Float @default(0)
|
|
minStock Int @default(5)
|
|
categoryId String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
category Category? @relation(fields: [categoryId], references: [id], onDelete: SetNull)
|
|
stockItems StockItem[]
|
|
stockMovements StockMovement[]
|
|
salesItems SalesOrderItem[]
|
|
purchaseItems PurchaseOrderItem[]
|
|
}
|
|
|
|
model StockItem {
|
|
id String @id @default(uuid())
|
|
productId String
|
|
warehouseId String
|
|
quantity Int @default(0)
|
|
updatedAt DateTime @updatedAt
|
|
|
|
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
|
|
warehouse Warehouse @relation(fields: [warehouseId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([productId, warehouseId])
|
|
}
|
|
|
|
model StockMovement {
|
|
id String @id @default(uuid())
|
|
productId String
|
|
warehouseId String
|
|
type MovementType
|
|
quantity Int
|
|
referenceType String? // SALES_ORDER, PURCHASE_ORDER, MANUAL_ADJUSTMENT
|
|
referenceId String?
|
|
notes String?
|
|
createdAt DateTime @default(now())
|
|
|
|
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
|
|
warehouse Warehouse @relation(fields: [warehouseId], references: [id], onDelete: Cascade)
|
|
}
|
|
|
|
model Customer {
|
|
id String @id @default(uuid())
|
|
code String @unique
|
|
name String
|
|
company String?
|
|
email String?
|
|
phone String?
|
|
address String?
|
|
createdAt DateTime @default(now())
|
|
|
|
salesOrders SalesOrder[]
|
|
}
|
|
|
|
model SalesOrder {
|
|
id String @id @default(uuid())
|
|
orderNumber String @unique
|
|
customerId String
|
|
orderDate DateTime @default(now())
|
|
status OrderStatus @default(DRAFT)
|
|
paymentStatus PaymentStatus @default(UNPAID)
|
|
totalAmount Float @default(0)
|
|
notes String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
customer Customer @relation(fields: [customerId], references: [id], onDelete: Restrict)
|
|
items SalesOrderItem[]
|
|
}
|
|
|
|
model SalesOrderItem {
|
|
id String @id @default(uuid())
|
|
salesOrderId String
|
|
productId String
|
|
quantity Int
|
|
unitPrice Float
|
|
subtotal Float
|
|
|
|
salesOrder SalesOrder @relation(fields: [salesOrderId], references: [id], onDelete: Cascade)
|
|
product Product @relation(fields: [productId], references: [id], onDelete: Restrict)
|
|
}
|
|
|
|
model Supplier {
|
|
id String @id @default(uuid())
|
|
code String @unique
|
|
name String
|
|
contactPerson String?
|
|
email String?
|
|
phone String?
|
|
address String?
|
|
createdAt DateTime @default(now())
|
|
|
|
purchaseOrders PurchaseOrder[]
|
|
}
|
|
|
|
model PurchaseOrder {
|
|
id String @id @default(uuid())
|
|
poNumber String @unique
|
|
supplierId String
|
|
orderDate DateTime @default(now())
|
|
status POStatus @default(DRAFT)
|
|
totalAmount Float @default(0)
|
|
notes String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
supplier Supplier @relation(fields: [supplierId], references: [id], onDelete: Restrict)
|
|
items PurchaseOrderItem[]
|
|
}
|
|
|
|
model PurchaseOrderItem {
|
|
id String @id @default(uuid())
|
|
purchaseOrderId String
|
|
productId String
|
|
quantity Int
|
|
unitCost Float
|
|
subtotal Float
|
|
|
|
purchaseOrder PurchaseOrder @relation(fields: [purchaseOrderId], references: [id], onDelete: Cascade)
|
|
product Product @relation(fields: [productId], references: [id], onDelete: Restrict)
|
|
}
|
|
|
|
model Account {
|
|
id String @id @default(uuid())
|
|
code String @unique
|
|
name String
|
|
type AccountType
|
|
balance Float @default(0)
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
lines JournalLine[]
|
|
}
|
|
|
|
model JournalEntry {
|
|
id String @id @default(uuid())
|
|
entryNumber String @unique
|
|
date DateTime @default(now())
|
|
description String
|
|
reference String? // Invoice #, PO #, etc.
|
|
createdAt DateTime @default(now())
|
|
|
|
lines JournalLine[]
|
|
}
|
|
|
|
model JournalLine {
|
|
id String @id @default(uuid())
|
|
journalEntryId String
|
|
accountId String
|
|
type EntryType
|
|
amount Float
|
|
|
|
journalEntry JournalEntry @relation(fields: [journalEntryId], references: [id], onDelete: Cascade)
|
|
account Account @relation(fields: [accountId], references: [id], onDelete: Restrict)
|
|
}
|