253 lines
6.5 KiB
Plaintext
253 lines
6.5 KiB
Plaintext
// use prisma-8
|
|
|
|
model Supplier {
|
|
id Int @id @default(autoincrement())
|
|
name String
|
|
phone String?
|
|
email String?
|
|
address String?
|
|
taxId String?
|
|
lastSupply TimestamptzString?
|
|
createdAt TimestamptzString @default(now())
|
|
|
|
products Product[]
|
|
|
|
@@map("supplier")
|
|
}
|
|
|
|
model Product {
|
|
id Int @id @default(autoincrement())
|
|
name String
|
|
description String?
|
|
sku String @unique
|
|
barcode String? @unique
|
|
unit String @default("pza")
|
|
status String @default("active")
|
|
minStock Int @default(0)
|
|
imageUrl String?
|
|
createdAt TimestamptzString @default(now())
|
|
updatedAt temporal.updatedAtString()
|
|
|
|
supplierId Int?
|
|
supplier Supplier? @relation(fields: [supplierId], references: [id])
|
|
|
|
categories ProductCategory[]
|
|
warehouses Warehouse[]
|
|
history ProductHistory[]
|
|
movements InventoryMovement[]
|
|
|
|
@@map("product")
|
|
}
|
|
|
|
model Category {
|
|
id Int @id @default(autoincrement())
|
|
name String
|
|
createdAt TimestamptzString @default(now())
|
|
|
|
products ProductCategory[]
|
|
|
|
@@map("category")
|
|
}
|
|
|
|
model ProductCategory {
|
|
productId Int
|
|
categoryId Int
|
|
|
|
product Product @relation(fields: [productId], references: [id])
|
|
category Category @relation(fields: [categoryId], references: [id])
|
|
|
|
@@id([productId, categoryId])
|
|
@@map("product_category")
|
|
}
|
|
|
|
model Inventory {
|
|
id Int @id @default(autoincrement())
|
|
name String
|
|
address String?
|
|
|
|
warehouses Warehouse[]
|
|
movements InventoryMovement[]
|
|
sessions CashRegisterSession[]
|
|
|
|
@@map("inventory")
|
|
}
|
|
|
|
model Warehouse {
|
|
inventoryId Int
|
|
productId Int
|
|
stock Int @default(0)
|
|
|
|
inventory Inventory @relation(fields: [inventoryId], references: [id])
|
|
product Product @relation(fields: [productId], references: [id])
|
|
|
|
@@id([inventoryId, productId])
|
|
@@map("warehouse")
|
|
}
|
|
|
|
model InventoryMovement {
|
|
id Int @id @default(autoincrement())
|
|
productId Int
|
|
inventoryId Int
|
|
type String
|
|
quantity Int
|
|
reason String?
|
|
createdAt TimestamptzString @default(now())
|
|
|
|
userId Int?
|
|
user User? @relation(fields: [userId], references: [id])
|
|
|
|
product Product @relation(fields: [productId], references: [id])
|
|
inventory Inventory @relation(fields: [inventoryId], references: [id])
|
|
|
|
@@map("inventory_movement")
|
|
}
|
|
|
|
model ProductHistory {
|
|
id Int @id @default(autoincrement())
|
|
productId Int
|
|
unitPrice Decimal
|
|
costUnit Decimal
|
|
status String
|
|
createdAt TimestamptzString @default(now())
|
|
soldAt TimestamptzString?
|
|
|
|
product Product @relation(fields: [productId], references: [id])
|
|
cartProducts CartProduct[]
|
|
|
|
@@map("product_history")
|
|
}
|
|
|
|
model ShopCart {
|
|
id Int @id @default(autoincrement())
|
|
totalPrice Decimal
|
|
discount Decimal @default(0)
|
|
status String @default("open")
|
|
createdAt TimestamptzString @default(now())
|
|
|
|
userId Int?
|
|
user User? @relation(fields: [userId], references: [id])
|
|
customerId Int?
|
|
customer Customer? @relation(fields: [customerId], references: [id])
|
|
|
|
items CartProduct[]
|
|
payments Payment[]
|
|
|
|
@@map("shop_cart")
|
|
}
|
|
|
|
model Customer {
|
|
id Int @id @default(autoincrement())
|
|
name String
|
|
phone String?
|
|
email String?
|
|
taxId String?
|
|
createdAt TimestamptzString @default(now())
|
|
|
|
carts ShopCart[]
|
|
|
|
@@map("customer")
|
|
}
|
|
|
|
model CashRegisterSession {
|
|
id Int @id @default(autoincrement())
|
|
inventoryId Int
|
|
openedById Int
|
|
closedById Int?
|
|
openingCash Decimal
|
|
closingCash Decimal?
|
|
expectedCash Decimal?
|
|
status String @default("open")
|
|
openedAt TimestamptzString @default(now())
|
|
closedAt TimestamptzString?
|
|
|
|
inventory Inventory @relation(fields: [inventoryId], references: [id])
|
|
openedBy User @relation("SessionOpenedBy", fields: [openedById], references: [id])
|
|
closedBy User? @relation("SessionClosedBy", fields: [closedById], references: [id])
|
|
movements CashMovement[]
|
|
|
|
@@map("cash_register_session")
|
|
}
|
|
|
|
model CashMovement {
|
|
id Int @id @default(autoincrement())
|
|
sessionId Int
|
|
type String
|
|
amount Decimal
|
|
reason String?
|
|
createdAt TimestamptzString @default(now())
|
|
|
|
userId Int?
|
|
user User? @relation(fields: [userId], references: [id])
|
|
|
|
session CashRegisterSession @relation(fields: [sessionId], references: [id])
|
|
|
|
@@map("cash_movement")
|
|
}
|
|
|
|
model CartProduct {
|
|
cartId Int
|
|
historyId Int
|
|
quantity Int
|
|
|
|
cart ShopCart @relation(fields: [cartId], references: [id])
|
|
history ProductHistory @relation(fields: [historyId], references: [id])
|
|
|
|
@@id([cartId, historyId])
|
|
@@map("cart_products")
|
|
}
|
|
|
|
model User {
|
|
id Int @id @default(autoincrement())
|
|
name String
|
|
email String @unique
|
|
role String
|
|
password String
|
|
createdAt TimestamptzString @default(now())
|
|
updatedAt temporal.updatedAtString()
|
|
|
|
carts ShopCart[]
|
|
payments Payment[]
|
|
inventoryMovements InventoryMovement[]
|
|
openedSessions CashRegisterSession[] @relation("SessionOpenedBy")
|
|
closedSessions CashRegisterSession[] @relation("SessionClosedBy")
|
|
cashMovements CashMovement[]
|
|
openedOperatingDays OperatingDay[] @relation("OperatingDayOpenedBy")
|
|
closedOperatingDays OperatingDay[] @relation("OperatingDayClosedBy")
|
|
|
|
@@map("user")
|
|
}
|
|
|
|
model OperatingDay {
|
|
id Int @id @default(autoincrement())
|
|
date TimestamptzString @default(now())
|
|
status String @default("open")
|
|
openedById Int
|
|
closedById Int?
|
|
openedAt TimestamptzString @default(now())
|
|
closedAt TimestamptzString?
|
|
|
|
openedBy User @relation("OperatingDayOpenedBy", fields: [openedById], references: [id])
|
|
closedBy User? @relation("OperatingDayClosedBy", fields: [closedById], references: [id])
|
|
|
|
@@map("operating_day")
|
|
}
|
|
|
|
model Payment {
|
|
id Int @id @default(autoincrement())
|
|
cartId Int
|
|
userId Int
|
|
amount Decimal
|
|
orderId Int?
|
|
terminalId Int?
|
|
status String
|
|
paid Boolean @default(false)
|
|
paymentMethod String
|
|
paidAt TimestamptzString?
|
|
createdAt TimestamptzString @default(now())
|
|
|
|
cart ShopCart @relation(fields: [cartId], references: [id])
|
|
user User @relation(fields: [userId], references: [id])
|
|
|
|
@@map("payment")
|
|
}
|