490 lines
18 KiB
Plaintext
490 lines
18 KiB
Plaintext
generator client {
|
|
provider = "prisma-client"
|
|
output = "../src/generated/prisma"
|
|
previewFeatures = ["views"]
|
|
moduleFormat = "cjs"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "mysql"
|
|
}
|
|
|
|
model User {
|
|
id Int @id @default(autoincrement())
|
|
mobileNumber String @unique @db.Char(11)
|
|
password String
|
|
firstName String
|
|
lastName String
|
|
roleId Int
|
|
createdAt DateTime @default(now()) @db.Timestamp(0)
|
|
deletedAt DateTime? @db.Timestamp(0)
|
|
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
|
role Role @relation("User_Role", fields: [roleId], references: [id], onUpdate: NoAction)
|
|
|
|
@@index([roleId], map: "Users_roleId_fkey")
|
|
@@map("Users")
|
|
}
|
|
|
|
model Role {
|
|
id Int @id @default(autoincrement())
|
|
name String @db.VarChar(100)
|
|
description String? @db.Text
|
|
permissions Json?
|
|
createdAt DateTime @default(now()) @db.Timestamp(0)
|
|
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
|
deletedAt DateTime? @db.Timestamp(0)
|
|
users User[] @relation("User_Role")
|
|
|
|
@@map("Roles")
|
|
}
|
|
|
|
model ProductVariant {
|
|
id Int @id @default(autoincrement())
|
|
name String @db.VarChar(255)
|
|
basePrice Decimal @db.Decimal(10, 2)
|
|
salePrice Decimal @db.Decimal(10, 2)
|
|
description String? @db.Text
|
|
barcode String? @unique(map: "products_barcode_unique") @db.VarChar(100)
|
|
imageUrl String? @db.VarChar(255)
|
|
unit String? @db.VarChar(10)
|
|
quantity Decimal? @default(0.00) @db.Decimal(10, 2)
|
|
alertQuantity Decimal? @default(5.00) @db.Decimal(10, 2)
|
|
isActive Boolean @default(true)
|
|
isFeatured Boolean @default(false)
|
|
createdAt DateTime @default(now()) @db.Timestamp(0)
|
|
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
|
deletedAt DateTime? @db.Timestamp(0)
|
|
productId Int
|
|
product Product @relation("Product_Variant", fields: [productId], references: [id], onUpdate: NoAction)
|
|
|
|
@@index([productId], map: "Product_Variants_productId_fkey")
|
|
@@map("Product_Variants")
|
|
}
|
|
|
|
model Product {
|
|
id Int @id @default(autoincrement())
|
|
name String @db.VarChar(255)
|
|
description String? @db.Text
|
|
sku String? @unique(map: "products_sku_unique") @db.VarChar(100)
|
|
barcode String? @unique(map: "products_barcode_unique") @db.VarChar(100)
|
|
createdAt DateTime @default(now()) @db.Timestamp(0)
|
|
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
|
deletedAt DateTime? @db.Timestamp(0)
|
|
salePrice Decimal @default(0.00) @db.Decimal(10, 2)
|
|
brandId Int?
|
|
categoryId Int?
|
|
inventoryTransferItems InventoryTransferItem[] @relation("InventoryTransferItem_Product")
|
|
productCharges ProductCharge[] @relation("Product_Charges")
|
|
variants ProductVariant[] @relation("Product_Variant")
|
|
brand ProductBrand? @relation("Product_Brand", fields: [brandId], references: [id], onUpdate: NoAction)
|
|
category ProductCategory? @relation("Product_Category", fields: [categoryId], references: [id], onUpdate: NoAction)
|
|
purchaseReceiptItems PurchaseReceiptItem[] @relation("Product_PurchaseReceiptItems")
|
|
salesInvoiceItems SalesInvoiceItem[] @relation("Product_SalesInvoiceItems")
|
|
stockAdjustments StockAdjustment[] @relation("Product_Stock_Adjustments")
|
|
stockMovements StockMovement[] @relation("StockMovement_Product")
|
|
|
|
stockBalances StockBalance[] @relation("StockBalance_Product")
|
|
|
|
@@index([brandId], map: "Products_brandId_fkey")
|
|
@@index([categoryId], map: "Products_categoryId_fkey")
|
|
@@map("Products")
|
|
}
|
|
|
|
model ProductBrand {
|
|
id Int @id @default(autoincrement())
|
|
name String @db.VarChar(100)
|
|
description String? @db.Text
|
|
imageUrl String? @db.VarChar(255)
|
|
createdAt DateTime @default(now()) @db.Timestamp(0)
|
|
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
|
deletedAt DateTime? @db.Timestamp(0)
|
|
products Product[] @relation("Product_Brand")
|
|
|
|
@@map("Product_brands")
|
|
}
|
|
|
|
model ProductCategory {
|
|
id Int @id @default(autoincrement())
|
|
name String @db.VarChar(100)
|
|
description String? @db.Text
|
|
imageUrl String? @db.VarChar(255)
|
|
createdAt DateTime @default(now()) @db.Timestamp(0)
|
|
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
|
deletedAt DateTime? @db.Timestamp(0)
|
|
products Product[] @relation("Product_Category")
|
|
|
|
@@map("Product_categories")
|
|
}
|
|
|
|
model Supplier {
|
|
id Int @id @default(autoincrement())
|
|
firstName String @db.VarChar(255)
|
|
lastName String @db.VarChar(255)
|
|
email String? @db.VarChar(255)
|
|
mobileNumber String @unique @db.Char(11)
|
|
address String? @db.Text
|
|
city String? @db.VarChar(100)
|
|
state String? @db.VarChar(100)
|
|
country String? @db.VarChar(100)
|
|
isActive Boolean @default(true)
|
|
createdAt DateTime @default(now()) @db.Timestamp(0)
|
|
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
|
deletedAt DateTime? @db.Timestamp(0)
|
|
productCharges ProductCharge[] @relation("Supplier_Product_Charges")
|
|
purchaseReceipts PurchaseReceipt[]
|
|
stockMovements StockMovement[] @relation("StockMovement_Supplier")
|
|
|
|
@@map("Suppliers")
|
|
}
|
|
|
|
model Customer {
|
|
id Int @id @default(autoincrement())
|
|
firstName String @db.VarChar(255)
|
|
lastName String @db.VarChar(255)
|
|
email String? @db.VarChar(255)
|
|
mobileNumber String @unique @db.Char(11)
|
|
address String? @db.Text
|
|
city String? @db.VarChar(100)
|
|
state String? @db.VarChar(100)
|
|
country String? @db.VarChar(100)
|
|
isActive Boolean @default(true)
|
|
createdAt DateTime @default(now()) @db.Timestamp(0)
|
|
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
|
deletedAt DateTime? @db.Timestamp(0)
|
|
orders Order[] @relation("Customer_Orders")
|
|
salesInvoices SalesInvoice[] @relation("Customer_Sales_Invoices")
|
|
|
|
@@map("Customers")
|
|
}
|
|
|
|
model Inventory {
|
|
id Int @id @default(autoincrement())
|
|
name String @db.VarChar(255)
|
|
location String? @db.VarChar(255)
|
|
isActive Boolean @default(true)
|
|
isPointOfSale Boolean @default(false)
|
|
createdAt DateTime @default(now()) @db.Timestamp(0)
|
|
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
|
deletedAt DateTime? @db.Timestamp(0)
|
|
inventoryTransfersFrom InventoryTransfer[] @relation("Inventory_From")
|
|
inventoryTransfersTo InventoryTransfer[] @relation("Inventory_To")
|
|
productCharges ProductCharge[] @relation("Inventory_Product_Charges")
|
|
purchaseReceipts PurchaseReceipt[]
|
|
stockAdjustments StockAdjustment[] @relation("Inventory_Stock_Adjustments")
|
|
stockMovements StockMovement[] @relation("StockMovement_Inventory")
|
|
stockBalances StockBalance[] @relation("StockBalance_inventory")
|
|
salesInvoices SalesInvoice[] @relation("Inventory_SalesInvoices")
|
|
|
|
@@map("Inventories")
|
|
}
|
|
|
|
model Store {
|
|
id Int @id @default(autoincrement())
|
|
name String @db.VarChar(255)
|
|
location String? @db.VarChar(255)
|
|
isActive Boolean @default(true)
|
|
createdAt DateTime @default(now()) @db.Timestamp(0)
|
|
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
|
deletedAt DateTime? @db.Timestamp(0)
|
|
|
|
@@map("Stores")
|
|
}
|
|
|
|
model ProductCharge {
|
|
id Int @id @default(autoincrement())
|
|
count Decimal @db.Decimal(10, 2)
|
|
fee Decimal @db.Decimal(10, 2)
|
|
totalAmount Decimal @db.Decimal(10, 2)
|
|
isSettled Boolean @default(false)
|
|
buyAt DateTime? @db.Timestamp(0)
|
|
description String? @db.Text
|
|
createdAt DateTime @default(now()) @db.Timestamp(0)
|
|
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
|
deletedAt DateTime? @db.Timestamp(0)
|
|
productId Int
|
|
inventoryId Int
|
|
supplierId Int
|
|
inventory Inventory @relation("Inventory_Product_Charges", fields: [inventoryId], references: [id], onUpdate: NoAction)
|
|
product Product @relation("Product_Charges", fields: [productId], references: [id], onUpdate: NoAction)
|
|
supplier Supplier @relation("Supplier_Product_Charges", fields: [supplierId], references: [id], onUpdate: NoAction)
|
|
|
|
@@index([inventoryId], map: "Product_Charges_inventoryId_fkey")
|
|
@@index([productId], map: "Product_Charges_productId_fkey")
|
|
@@index([supplierId], map: "Product_Charges_supplierId_fkey")
|
|
@@map("Product_Charges")
|
|
}
|
|
|
|
model Order {
|
|
id Int @id @default(autoincrement())
|
|
orderNumber String @unique @db.VarChar(100)
|
|
status OrderStatus @default(pending)
|
|
paymentMethod paymentMethod @default(card)
|
|
totalAmount Decimal @db.Decimal(10, 2)
|
|
createdAt DateTime @default(now()) @db.Timestamp(0)
|
|
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
|
deletedAt DateTime? @db.Timestamp(0)
|
|
customerId Int
|
|
customer Customer @relation("Customer_Orders", fields: [customerId], references: [id], onUpdate: NoAction)
|
|
|
|
@@index([customerId], map: "Orders_customerId_fkey")
|
|
@@map("Orders")
|
|
}
|
|
|
|
model PurchaseReceipt {
|
|
id Int @id @default(autoincrement())
|
|
code String @unique @db.VarChar(100)
|
|
totalAmount Decimal @db.Decimal(10, 2)
|
|
description String? @db.Text
|
|
createdAt DateTime @default(now()) @db.Timestamp(0)
|
|
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
|
supplierId Int
|
|
inventoryId Int
|
|
items PurchaseReceiptItem[] @relation("PurchaseReceipt_Items")
|
|
inventory Inventory @relation(fields: [inventoryId], references: [id])
|
|
supplier Supplier @relation(fields: [supplierId], references: [id])
|
|
|
|
@@index([inventoryId], map: "Purchase_Receipts_inventoryId_fkey")
|
|
@@index([supplierId], map: "Purchase_Receipts_supplierId_fkey")
|
|
@@map("Purchase_Receipts")
|
|
}
|
|
|
|
model PurchaseReceiptItem {
|
|
id Int @id @default(autoincrement())
|
|
count Decimal @db.Decimal(10, 2)
|
|
fee Decimal @db.Decimal(10, 2)
|
|
total Decimal @db.Decimal(10, 2)
|
|
description String? @db.Text
|
|
createdAt DateTime @default(now()) @db.Timestamp(0)
|
|
receiptId Int
|
|
productId Int
|
|
receipt PurchaseReceipt @relation("PurchaseReceipt_Items", fields: [receiptId], references: [id])
|
|
product Product @relation("Product_PurchaseReceiptItems", fields: [productId], references: [id])
|
|
|
|
@@index([productId], map: "Purchase_Receipt_Items_productId_fkey")
|
|
@@index([receiptId], map: "Purchase_Receipt_Items_receiptId_fkey")
|
|
@@map("Purchase_Receipt_Items")
|
|
}
|
|
|
|
model SalesInvoice {
|
|
id Int @id @default(autoincrement())
|
|
code String @unique @db.VarChar(100)
|
|
totalAmount Decimal @db.Decimal(10, 2)
|
|
description String? @db.Text
|
|
createdAt DateTime @default(now()) @db.Timestamp(0)
|
|
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
|
customerId Int?
|
|
inventoryId Int
|
|
items SalesInvoiceItem[] @relation("SalesInvoice_Items")
|
|
customer Customer? @relation("Customer_Sales_Invoices", fields: [customerId], references: [id])
|
|
inventory Inventory @relation("Inventory_SalesInvoices", fields: [inventoryId], references: [id])
|
|
|
|
@@index([inventoryId], map: "Sales_Invoices_inventoryId_fkey")
|
|
@@index([customerId], map: "Sales_Invoices_customerId_fkey")
|
|
@@map("Sales_Invoices")
|
|
}
|
|
|
|
model SalesInvoiceItem {
|
|
id Int @id @default(autoincrement())
|
|
count Decimal @db.Decimal(10, 2)
|
|
fee Decimal @db.Decimal(10, 2)
|
|
total Decimal @db.Decimal(10, 2)
|
|
createdAt DateTime @default(now()) @db.Timestamp(0)
|
|
invoiceId Int
|
|
productId Int
|
|
invoice SalesInvoice @relation("SalesInvoice_Items", fields: [invoiceId], references: [id])
|
|
product Product @relation("Product_SalesInvoiceItems", fields: [productId], references: [id])
|
|
|
|
@@index([invoiceId], map: "Sales_Invoice_Items_invoiceId_fkey")
|
|
@@index([productId], map: "Sales_Invoice_Items_productId_fkey")
|
|
@@map("Sales_Invoice_Items")
|
|
}
|
|
|
|
model StockMovement {
|
|
id Int @id @default(autoincrement())
|
|
type MovementType
|
|
quantity Decimal @db.Decimal(10, 2)
|
|
fee Decimal @db.Decimal(10, 2)
|
|
totalCost Decimal @db.Decimal(10, 2)
|
|
referenceType MovementReferenceType
|
|
referenceId String
|
|
createdAt DateTime @default(now()) @db.Timestamp(0)
|
|
productId Int
|
|
inventoryId Int
|
|
avgCost Decimal @db.Decimal(10, 2)
|
|
remainedInStock Decimal @default(0) @db.Decimal(10, 2)
|
|
inventory Inventory @relation("StockMovement_Inventory", fields: [inventoryId], references: [id])
|
|
product Product @relation("StockMovement_Product", fields: [productId], references: [id])
|
|
supplierId Int?
|
|
supplier Supplier? @relation("StockMovement_Supplier", fields: [supplierId], references: [id])
|
|
|
|
@@index([inventoryId], map: "Stock_Movements_inventoryId_fkey")
|
|
@@index([productId], map: "Stock_Movements_productId_fkey")
|
|
@@map("Stock_Movements")
|
|
}
|
|
|
|
model StockBalance {
|
|
id Int @id @default(autoincrement())
|
|
|
|
productId Int
|
|
inventoryId Int
|
|
|
|
quantity Decimal @default(0) @db.Decimal(14, 3)
|
|
|
|
avgCost Decimal @default(0) @db.Decimal(14, 2)
|
|
totalCost Decimal @default(0) @db.Decimal(14, 2)
|
|
|
|
createdAt DateTime @default(now()) @db.Timestamp(0)
|
|
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
|
|
|
product Product @relation("StockBalance_Product", fields: [productId], references: [id])
|
|
inventory Inventory @relation("StockBalance_inventory", fields: [inventoryId], references: [id])
|
|
|
|
@@unique([productId, inventoryId])
|
|
@@index([productId])
|
|
@@index([inventoryId])
|
|
@@map("Stock_Balance")
|
|
}
|
|
|
|
model InventoryTransfer {
|
|
id Int @id @default(autoincrement())
|
|
code String @unique @db.VarChar(100)
|
|
description String? @db.Text
|
|
createdAt DateTime @default(now()) @db.Timestamp(0)
|
|
fromInventoryId Int
|
|
toInventoryId Int
|
|
items InventoryTransferItem[] @relation("InventoryTransfer_Items")
|
|
fromInventory Inventory @relation("Inventory_From", fields: [fromInventoryId], references: [id])
|
|
toInventory Inventory @relation("Inventory_To", fields: [toInventoryId], references: [id])
|
|
|
|
@@index([fromInventoryId], map: "Inventory_Transfers_fromInventoryId_fkey")
|
|
@@index([toInventoryId], map: "Inventory_Transfers_toInventoryId_fkey")
|
|
@@map("Inventory_Transfers")
|
|
}
|
|
|
|
model InventoryTransferItem {
|
|
id Int @id @default(autoincrement())
|
|
count Decimal @db.Decimal(10, 2)
|
|
productId Int
|
|
transferId Int
|
|
product Product @relation("InventoryTransferItem_Product", fields: [productId], references: [id])
|
|
transfer InventoryTransfer @relation("InventoryTransfer_Items", fields: [transferId], references: [id])
|
|
|
|
@@index([productId], map: "Inventory_Transfer_Items_productId_fkey")
|
|
@@index([transferId], map: "Inventory_Transfer_Items_transferId_fkey")
|
|
@@map("Inventory_Transfer_Items")
|
|
}
|
|
|
|
model StockAdjustment {
|
|
id Int @id @default(autoincrement())
|
|
adjustedQuantity Decimal @db.Decimal(10, 2)
|
|
createdAt DateTime @default(now()) @db.Timestamp(0)
|
|
productId Int
|
|
inventoryId Int
|
|
inventory Inventory @relation("Inventory_Stock_Adjustments", fields: [inventoryId], references: [id])
|
|
product Product @relation("Product_Stock_Adjustments", fields: [productId], references: [id])
|
|
|
|
@@index([inventoryId], map: "Stock_Adjustments_inventoryId_fkey")
|
|
@@index([productId], map: "Stock_Adjustments_productId_fkey")
|
|
@@map("Stock_Adjustments")
|
|
}
|
|
|
|
view StockMovements_View {
|
|
id Int @default(0)
|
|
productId Int
|
|
type stock_movements_view_type
|
|
quantity Decimal @db.Decimal(10, 2)
|
|
fee Decimal @db.Decimal(10, 2)
|
|
totalCost Decimal @db.Decimal(10, 2)
|
|
referenceId String
|
|
referenceType stock_movements_view_referenceType
|
|
createdAt DateTime @default(now()) @db.Timestamp(0)
|
|
current_stock Decimal?
|
|
current_avg_cost Decimal?
|
|
|
|
@@map("Stock_Movements_View")
|
|
@@ignore
|
|
}
|
|
|
|
view inventory_overview {
|
|
ProductId Int
|
|
stock_quantity Decimal
|
|
avgCost Decimal
|
|
totalCost Decimal
|
|
updatedAt DateTime @default(now()) @db.Timestamp(0)
|
|
|
|
@@map("Inventory_Overview")
|
|
}
|
|
|
|
view stock_cardex {
|
|
productId Int
|
|
movement_id Int @default(0)
|
|
type stock_cardex_type
|
|
quantity Decimal @db.Decimal(10, 2)
|
|
fee Decimal @db.Decimal(10, 2)
|
|
totalCost Decimal @db.Decimal(10, 2)
|
|
balance_quantity Decimal?
|
|
balance_avg_cost Decimal?
|
|
createdAt DateTime @default(now()) @db.Timestamp(0)
|
|
|
|
@@map("Stock_Cardex")
|
|
}
|
|
|
|
view stock_view {
|
|
productId Int
|
|
inventoryId Int
|
|
stock Decimal? @db.Decimal(32, 2)
|
|
|
|
@@map("Stock_View")
|
|
}
|
|
|
|
enum OrderStatus {
|
|
pending
|
|
reject
|
|
done
|
|
}
|
|
|
|
enum paymentMethod {
|
|
cash
|
|
card
|
|
}
|
|
|
|
enum MovementType {
|
|
IN
|
|
OUT
|
|
ADJUST
|
|
}
|
|
|
|
enum MovementReferenceType {
|
|
PURCHASE
|
|
SALES
|
|
ADJUSTMENT
|
|
INVENTORY_TRANSFER
|
|
}
|
|
|
|
enum stock_cardex_type {
|
|
IN
|
|
OUT
|
|
ADJUST
|
|
}
|
|
|
|
enum stock_movements_view_type {
|
|
IN
|
|
OUT
|
|
ADJUST
|
|
}
|
|
|
|
enum stock_movements_view_referenceType {
|
|
PURCHASE
|
|
SALES
|
|
ADJUSTMENT
|
|
}
|
|
|
|
model TriggerLog {
|
|
id Int @id @default(autoincrement())
|
|
name String @db.Text
|
|
message String @db.Text
|
|
createdAt DateTime @default(now()) @db.Timestamp(0)
|
|
|
|
@@map("Trigger_Logs")
|
|
}
|