289 lines
8.4 KiB
Plaintext
289 lines
8.4 KiB
Plaintext
datasource db {
|
|
provider = "sqlite"
|
|
url = "file:./dev.db"
|
|
}
|
|
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
model User {
|
|
id String @id @default(uuid())
|
|
email String @unique
|
|
name String
|
|
password String
|
|
role String @default("SALES")
|
|
telegramChatId String?
|
|
notifyEmail Boolean @default(true)
|
|
notifyTelegram Boolean @default(false)
|
|
|
|
// Divisional topic subscriptions
|
|
notifStockIn Boolean @default(true)
|
|
notifStockOut Boolean @default(true)
|
|
notifMoneyIn Boolean @default(true)
|
|
notifMoneyOut Boolean @default(true)
|
|
|
|
// Multi-Factor Authentication (MFA / 2FA)
|
|
mfaEnabled Boolean @default(false)
|
|
mfaSecret String?
|
|
mfaMethod String @default("TOTP")
|
|
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
auditLogs AuditLog[]
|
|
}
|
|
|
|
model SystemSetting {
|
|
id String @id @default(uuid())
|
|
key String @unique
|
|
value String
|
|
category String @default("GENERAL") // TELEGRAM, EMAIL, NOTIFICATION
|
|
updatedAt DateTime @updatedAt
|
|
}
|
|
|
|
model NotificationLog {
|
|
id String @id @default(uuid())
|
|
recipient String
|
|
channel String // EMAIL, TELEGRAM
|
|
type String // STOCK_IN, STOCK_OUT, MONEY_IN, MONEY_OUT, SYSTEM
|
|
title String
|
|
message String
|
|
status String @default("SENT") // SENT, FAILED, SIMULATED
|
|
createdAt DateTime @default(now())
|
|
}
|
|
|
|
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
|
|
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")
|
|
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 String // IN, OUT, ADJUSTMENT, TRANSFER
|
|
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
|
|
invoiceNumber String?
|
|
customerPoNumber String?
|
|
customerId String
|
|
orderDate DateTime @default(now())
|
|
status String @default("DRAFT") // DRAFT, CONFIRMED, SHIPPED, COMPLETED, CANCELLED
|
|
paymentStatus String @default("UNPAID") // UNPAID, PARTIAL, PAID
|
|
totalAmount Float @default(0)
|
|
totalHpp 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
|
|
costPrice Float @default(0)
|
|
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 String @default("DRAFT") // DRAFT, ORDERED, RECEIVED, COMPLETED, CANCELLED
|
|
currency String @default("IDR") // IDR, USD
|
|
exchangeRate Float @default(1)
|
|
totalAmountUsd Float?
|
|
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
|
|
unitCostUsd Float?
|
|
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 String // ASSET, LIABILITY, EQUITY, REVENUE, EXPENSE
|
|
companyName String @default("PT EnterpriseCore Utama")
|
|
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?
|
|
createdAt DateTime @default(now())
|
|
|
|
lines JournalLine[]
|
|
}
|
|
|
|
model JournalLine {
|
|
id String @id @default(uuid())
|
|
journalEntryId String
|
|
accountId String
|
|
type String // DEBIT, CREDIT
|
|
amount Float
|
|
|
|
journalEntry JournalEntry @relation(fields: [journalEntryId], references: [id], onDelete: Cascade)
|
|
account Account @relation(fields: [accountId], references: [id], onDelete: Restrict)
|
|
}
|
|
|
|
model PayrollRecord {
|
|
id String @id @default(uuid())
|
|
payrollNumber String @unique
|
|
companyName String @default("PT EnterpriseCore Utama")
|
|
employeeName String
|
|
role String
|
|
period String
|
|
workDays Int @default(22)
|
|
absentDays Int @default(0)
|
|
lateCount Int @default(0)
|
|
baseSalary Float @default(0)
|
|
dailyMealRate Float @default(0)
|
|
totalMealAllowance Float @default(0)
|
|
transportAllowance Float @default(0)
|
|
absenceDeduction Float @default(0)
|
|
netSalary Float @default(0)
|
|
paymentAccountName String?
|
|
status String @default("PAID")
|
|
notes String?
|
|
createdAt DateTime @default(now())
|
|
}
|
|
|
|
model PayrollEmployee {
|
|
id String @id @default(uuid())
|
|
name String @unique
|
|
companyName String @default("PT EnterpriseCore Utama")
|
|
position String
|
|
baseSalary Float @default(0)
|
|
dailyMealRate Float @default(35000)
|
|
createdAt DateTime @default(now())
|
|
}
|