init
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
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)
|
||||
refreshTokens RefreshToken[]
|
||||
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 @unique @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 OtpCode {
|
||||
id Int @id @default(autoincrement())
|
||||
mobileNumber String @db.VarChar(20)
|
||||
code String @db.VarChar(10)
|
||||
used Boolean @default(false)
|
||||
expiresAt DateTime @db.Timestamp(0)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
|
||||
@@index([mobileNumber])
|
||||
@@map("Otp_Codes")
|
||||
}
|
||||
|
||||
model RefreshToken {
|
||||
id Int @id @default(autoincrement())
|
||||
tokenHash String @db.VarChar(255)
|
||||
userId Int
|
||||
revoked Boolean @default(false)
|
||||
expiresAt DateTime @db.Timestamp(0)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
|
||||
@@index([userId])
|
||||
@@map("Refresh_Tokens")
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
model BankBranch {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @db.VarChar(255)
|
||||
code String @unique() @db.VarChar(10)
|
||||
address String? @db.VarChar(500)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
bankId Int
|
||||
|
||||
bank Bank @relation("bank_branches", fields: [bankId], references: [id])
|
||||
bankAccounts BankAccount[] @relation("Bank_Accounts_branchId_fkey")
|
||||
|
||||
@@map("Bank_Branches")
|
||||
}
|
||||
|
||||
model BankAccount {
|
||||
id Int @id @default(autoincrement())
|
||||
accountNumber String? @unique @db.VarChar(20)
|
||||
cardNumber String? @unique @db.VarChar(16)
|
||||
name String @db.VarChar(255)
|
||||
iban String? @unique @db.VarChar(34)
|
||||
branchId Int
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
|
||||
branch BankBranch @relation("Bank_Accounts_branchId_fkey", fields: [branchId], references: [id])
|
||||
inventoryBankAccounts InventoryBankAccount[]
|
||||
purchaseReceiptPayments PurchaseReceiptPayments[]
|
||||
bankAccountTransactions BankAccountTransaction[]
|
||||
|
||||
@@map("Bank_Accounts")
|
||||
}
|
||||
|
||||
model BankAccountTransaction {
|
||||
id Int @id @default(autoincrement())
|
||||
bankAccountId Int
|
||||
type BankAccountTransactionType
|
||||
amount Decimal @db.Decimal(15, 2)
|
||||
balanceAfter Decimal @db.Decimal(15, 2)
|
||||
referenceId Int
|
||||
referenceType BankTransactionRefType
|
||||
description String? @db.Text
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
|
||||
bankAccount BankAccount @relation(fields: [bankAccountId], references: [id])
|
||||
|
||||
@@index([bankAccountId])
|
||||
@@map("Bank_Account_Transactions")
|
||||
}
|
||||
@@ -1,23 +1,3 @@
|
||||
enum OrderStatus {
|
||||
PENDING
|
||||
REJECTED
|
||||
CANCELED
|
||||
DONE
|
||||
}
|
||||
|
||||
enum MovementType {
|
||||
IN
|
||||
OUT
|
||||
ADJUST
|
||||
}
|
||||
|
||||
enum MovementReferenceType {
|
||||
PURCHASE
|
||||
SALES
|
||||
ADJUSTMENT
|
||||
INVENTORY_TRANSFER
|
||||
}
|
||||
|
||||
enum PaymentMethodType {
|
||||
CASH
|
||||
CARD
|
||||
@@ -26,34 +6,8 @@ enum PaymentMethodType {
|
||||
OTHER
|
||||
}
|
||||
|
||||
enum LedgerSourceType {
|
||||
PURCHASE
|
||||
PAYMENT
|
||||
ADJUSTMENT
|
||||
REFUND
|
||||
}
|
||||
|
||||
enum PaymentType {
|
||||
PAYMENT
|
||||
REFUND
|
||||
}
|
||||
|
||||
enum PurchaseReceiptStatus {
|
||||
UNPAID
|
||||
PARTIALLY_PAID
|
||||
PAID
|
||||
}
|
||||
|
||||
enum BankAccountTransactionType {
|
||||
DEPOSIT
|
||||
WITHDRAWAL
|
||||
}
|
||||
|
||||
enum BankTransactionRefType {
|
||||
PURCHASE_PAYMENT
|
||||
PURCHASE_REFUND
|
||||
POS_SALE
|
||||
POS_REFUND
|
||||
BANK_TRANSFER
|
||||
MANUAL_ADJUSTMENT
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
model Good {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @db.VarChar(255)
|
||||
description String? @db.Text
|
||||
sku String @db.VarChar(100)
|
||||
localSku String @unique() @db.VarChar(100)
|
||||
barcode String? @unique() @db.VarChar(100)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
categoryId Int?
|
||||
baseSalePrice Decimal @default(0.00) @db.Decimal(15, 0)
|
||||
category GoodCategory? @relation(fields: [categoryId], references: [id])
|
||||
salesInvoiceItems SalesInvoiceItem[]
|
||||
|
||||
@@index([categoryId])
|
||||
@@map("Goods")
|
||||
}
|
||||
|
||||
model GoodCategory {
|
||||
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)
|
||||
goods Good[]
|
||||
|
||||
@@map("Good_categories")
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
model Inventory {
|
||||
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)
|
||||
isPointOfSale Boolean @default(false)
|
||||
inventoryTransfersFrom InventoryTransfer[] @relation("Inventory_From")
|
||||
inventoryTransfersTo InventoryTransfer[] @relation("Inventory_To")
|
||||
purchaseReceipts PurchaseReceipt[]
|
||||
stockAdjustments StockAdjustment[] @relation("Inventory_Stock_Adjustments")
|
||||
stockBalances StockBalance[] @relation("StockBalance_inventory")
|
||||
counterStockMovements StockMovement[] @relation("StockMovement_CounterInventory")
|
||||
stockMovements StockMovement[] @relation("StockMovement_Inventory")
|
||||
inventoryBankAccounts InventoryBankAccount[]
|
||||
stockReservations StockReservation[]
|
||||
|
||||
@@map("Inventories")
|
||||
}
|
||||
|
||||
model InventoryBankAccount {
|
||||
inventoryId Int
|
||||
bankAccountId Int
|
||||
|
||||
inventory Inventory @relation(fields: [inventoryId], references: [id])
|
||||
bankAccount BankAccount @relation(fields: [bankAccountId], references: [id])
|
||||
posAccounts PosAccount[]
|
||||
purchaseReceiptPayments PurchaseReceiptPayments[]
|
||||
|
||||
@@id([inventoryId, bankAccountId])
|
||||
@@index([bankAccountId])
|
||||
@@map("Inventory_Bank_Accounts")
|
||||
}
|
||||
|
||||
model PosAccount {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @db.VarChar(255)
|
||||
code String @unique() @db.VarChar(10)
|
||||
description String? @db.VarChar(500)
|
||||
bankAccountId Int
|
||||
inventoryId Int
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
|
||||
inventoryBankAccount InventoryBankAccount @relation(fields: [inventoryId, bankAccountId], references: [inventoryId, bankAccountId])
|
||||
salesInvoices SalesInvoice[]
|
||||
orders Order[]
|
||||
|
||||
@@index([inventoryId])
|
||||
@@map("Pos_Accounts")
|
||||
}
|
||||
|
||||
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, 0)
|
||||
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")
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
model Bank {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @db.VarChar(255)
|
||||
shortName String @unique() @db.VarChar(3)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
|
||||
bankBranches BankBranch[] @relation("bank_branches")
|
||||
|
||||
@@map("Banks")
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
model Order {
|
||||
id Int @id @default(autoincrement())
|
||||
orderNumber String @unique @db.VarChar(100)
|
||||
status OrderStatus @default(PENDING)
|
||||
totalAmount Decimal @db.Decimal(15, 2)
|
||||
description String? @db.Text
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
customerId Int?
|
||||
posAccountId Int
|
||||
|
||||
customer Customer? @relation(fields: [customerId], references: [id], onUpdate: NoAction)
|
||||
posAccount PosAccount @relation(fields: [posAccountId], references: [id], onUpdate: NoAction)
|
||||
|
||||
orderItems OrderItem[]
|
||||
stockReservations StockReservation[]
|
||||
|
||||
@@index([posAccountId])
|
||||
@@index([customerId])
|
||||
@@map("Orders")
|
||||
}
|
||||
|
||||
model OrderItem {
|
||||
id Int @id @default(autoincrement())
|
||||
quantity Decimal @db.Decimal(10, 0)
|
||||
unitPrice Decimal @db.Decimal(15, 2)
|
||||
totalAmount Decimal @db.Decimal(15, 2)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
orderId Int
|
||||
productId Int
|
||||
|
||||
order Order @relation(fields: [orderId], references: [id], onUpdate: NoAction)
|
||||
product Product @relation(fields: [productId], references: [id], onUpdate: NoAction)
|
||||
|
||||
@@index([orderId])
|
||||
@@index([productId])
|
||||
@@map("Order_Items")
|
||||
}
|
||||
+11
-16
@@ -1,20 +1,15 @@
|
||||
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()
|
||||
stockMovements StockMovement[] @relation()
|
||||
salesInvoices SalesInvoice[]
|
||||
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
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
salesInvoices SalesInvoice[]
|
||||
|
||||
@@map("Customers")
|
||||
}
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
model ProductVariant {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @db.VarChar(255)
|
||||
basePrice Decimal @db.Decimal(15, 2)
|
||||
salePrice Decimal @db.Decimal(15, 2)
|
||||
description String? @db.Text
|
||||
barcode String? @unique() @db.VarChar(100)
|
||||
imageUrl String? @db.VarChar(255)
|
||||
unit String? @db.VarChar(10)
|
||||
quantity Decimal? @default(0.00) @db.Decimal(10, 0)
|
||||
alertQuantity Decimal? @default(5.00) @db.Decimal(10, 0)
|
||||
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() @db.VarChar(100)
|
||||
barcode String? @unique() @db.VarChar(100)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
brandId Int?
|
||||
categoryId Int?
|
||||
salePrice Decimal @default(0.00) @db.Decimal(15, 0)
|
||||
minimumStockAlertLevel Decimal @default(1.00) @db.Decimal(10, 0)
|
||||
inventoryTransferItems InventoryTransferItem[] @relation("InventoryTransferItem_Product")
|
||||
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")
|
||||
stockAdjustments StockAdjustment[] @relation("Product_Stock_Adjustments")
|
||||
stockBalances StockBalance[] @relation("StockBalance_Product")
|
||||
stockMovements StockMovement[] @relation("StockMovement_Product")
|
||||
salesInvoiceItems SalesInvoiceItem[]
|
||||
stockReservations StockReservation[]
|
||||
orderItems OrderItem[]
|
||||
|
||||
@@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")
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
model PurchaseReceipt {
|
||||
id Int @id @default(autoincrement())
|
||||
code String @unique @db.VarChar(100)
|
||||
totalAmount Decimal @db.Decimal(15, 2)
|
||||
paidAmount Decimal @default(0.00) @db.Decimal(15, 2)
|
||||
description String? @db.Text
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
status PurchaseReceiptStatus @default(UNPAID)
|
||||
supplierId Int
|
||||
inventoryId Int
|
||||
items PurchaseReceiptItem[] @relation("PurchaseReceipt_Items")
|
||||
inventory Inventory @relation(fields: [inventoryId], references: [id])
|
||||
supplier Supplier @relation(fields: [supplierId], references: [id])
|
||||
payments PurchaseReceiptPayments[]
|
||||
|
||||
@@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, 0)
|
||||
unitPrice Decimal @db.Decimal(15, 2)
|
||||
totalAmount Decimal @db.Decimal(15, 2)
|
||||
receiptId Int
|
||||
productId Int
|
||||
description String? @db.Text
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
product Product @relation("Product_PurchaseReceiptItems", fields: [productId], references: [id])
|
||||
receipt PurchaseReceipt @relation("PurchaseReceipt_Items", fields: [receiptId], references: [id])
|
||||
|
||||
@@index([productId], map: "Purchase_Receipt_Items_productId_fkey")
|
||||
@@index([receiptId], map: "Purchase_Receipt_Items_receiptId_fkey")
|
||||
@@map("Purchase_Receipt_Items")
|
||||
}
|
||||
|
||||
model PurchaseReceiptPayments {
|
||||
id Int @id @default(autoincrement())
|
||||
amount Decimal @db.Decimal(15, 2)
|
||||
paymentMethod PaymentMethodType
|
||||
type PaymentType
|
||||
bankAccountId Int
|
||||
receiptId Int
|
||||
payedAt DateTime @db.Timestamp(0)
|
||||
description String? @db.Text
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
|
||||
receipt PurchaseReceipt @relation(fields: [receiptId], references: [id])
|
||||
bankAccount BankAccount @relation(fields: [bankAccountId], references: [id])
|
||||
inventoryBankAccount InventoryBankAccount? @relation(fields: [inventoryBankAccountInventoryId, inventoryBankAccountBankAccountId], references: [inventoryId, bankAccountId])
|
||||
inventoryBankAccountInventoryId Int?
|
||||
inventoryBankAccountBankAccountId Int?
|
||||
|
||||
@@index([receiptId], map: "Purchase_Receipt_Payments_receiptId_fkey")
|
||||
@@map("Purchase_Receipt_Payments")
|
||||
}
|
||||
@@ -6,14 +6,11 @@ model SalesInvoice {
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
customerId Int?
|
||||
posAccountId Int
|
||||
customer Customer? @relation(fields: [customerId], references: [id])
|
||||
posAccount PosAccount @relation(fields: [posAccountId], references: [id])
|
||||
items SalesInvoiceItem[]
|
||||
salesInvoicePayments SalesInvoicePayment[]
|
||||
|
||||
@@index([customerId])
|
||||
@@index([posAccountId])
|
||||
@@map("Sales_Invoices")
|
||||
}
|
||||
|
||||
@@ -24,12 +21,13 @@ model SalesInvoiceItem {
|
||||
totalAmount Decimal @default(0.00) @db.Decimal(15, 2)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
invoiceId Int
|
||||
productId Int
|
||||
goodId Int
|
||||
serviceId Int
|
||||
invoice SalesInvoice @relation(fields: [invoiceId], references: [id])
|
||||
product Product @relation(fields: [productId], references: [id])
|
||||
good Good? @relation(fields: [goodId], references: [id])
|
||||
service Service? @relation(fields: [serviceId], references: [id])
|
||||
|
||||
@@index([invoiceId])
|
||||
@@index([productId])
|
||||
@@index([invoiceId, goodId])
|
||||
@@map("Sales_Invoice_Items")
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
model Service {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @db.VarChar(255)
|
||||
description String? @db.Text
|
||||
sku String @unique() @db.VarChar(100)
|
||||
barcode String? @unique() @db.VarChar(100)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
categoryId Int?
|
||||
baseSalePrice Decimal @default(0.00) @db.Decimal(15, 0)
|
||||
category ServiceCategory? @relation(fields: [categoryId], references: [id])
|
||||
salesInvoiceItems SalesInvoiceItem[]
|
||||
|
||||
@@index([categoryId])
|
||||
@@map("Services")
|
||||
}
|
||||
|
||||
model ServiceCategory {
|
||||
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)
|
||||
services Service[]
|
||||
|
||||
@@map("Service_categories")
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
model StockMovement {
|
||||
id Int @id @default(autoincrement())
|
||||
type MovementType
|
||||
quantity Decimal @db.Decimal(10, 0)
|
||||
unitPrice Decimal @db.Decimal(15, 2)
|
||||
totalCost Decimal @db.Decimal(15, 2)
|
||||
referenceType MovementReferenceType
|
||||
referenceId String
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
productId Int
|
||||
inventoryId Int
|
||||
avgCost Decimal @db.Decimal(15, 2)
|
||||
supplierId Int?
|
||||
remainedInStock Decimal @default(0.00) @db.Decimal(10, 0)
|
||||
counterInventoryId Int?
|
||||
customerId Int?
|
||||
counterInventory Inventory? @relation("StockMovement_CounterInventory", fields: [counterInventoryId], references: [id])
|
||||
customer Customer? @relation(fields: [customerId], references: [id])
|
||||
inventory Inventory @relation("StockMovement_Inventory", fields: [inventoryId], references: [id])
|
||||
product Product @relation("StockMovement_Product", fields: [productId], references: [id])
|
||||
supplier Supplier? @relation("StockMovement_Supplier", fields: [supplierId], references: [id])
|
||||
|
||||
@@index([inventoryId], map: "Stock_Movements_inventoryId_fkey")
|
||||
@@index([productId], map: "Stock_Movements_productId_fkey")
|
||||
@@index([counterInventoryId], map: "Stock_Movements_counterInventoryId_fkey")
|
||||
@@index([customerId], map: "Stock_Movements_customerId_fkey")
|
||||
@@index([supplierId], map: "Stock_Movements_supplierId_fkey")
|
||||
@@map("Stock_Movements")
|
||||
}
|
||||
|
||||
model StockBalance {
|
||||
quantity Decimal @default(0.000) @db.Decimal(14, 3)
|
||||
totalCost Decimal @default(0.00) @db.Decimal(14, 2)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
avgCost Decimal @default(0.00) @db.Decimal(14, 2)
|
||||
inventoryId Int
|
||||
productId Int
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
id Int @id @default(autoincrement())
|
||||
inventory Inventory @relation("StockBalance_inventory", fields: [inventoryId], references: [id])
|
||||
product Product @relation("StockBalance_Product", fields: [productId], references: [id])
|
||||
|
||||
@@unique([productId, inventoryId])
|
||||
@@index([productId])
|
||||
@@index([inventoryId])
|
||||
@@map("Stock_Balance")
|
||||
}
|
||||
|
||||
model StockAdjustment {
|
||||
id Int @id @default(autoincrement())
|
||||
adjustedQuantity Decimal @db.Decimal(10, 0)
|
||||
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")
|
||||
}
|
||||
|
||||
model StockReservation {
|
||||
id Int @id @default(autoincrement())
|
||||
quantity Decimal @db.Decimal(10, 0)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
productId Int
|
||||
inventoryId Int
|
||||
orderId Int
|
||||
inventory Inventory @relation(fields: [inventoryId], references: [id])
|
||||
product Product @relation(fields: [productId], references: [id])
|
||||
order Order @relation(fields: [orderId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([inventoryId])
|
||||
@@index([productId])
|
||||
@@map("Stock_Reservations")
|
||||
}
|
||||
|
||||
view StockAvailableView {
|
||||
productId Int
|
||||
inventoryId Int
|
||||
physicalQuantity Decimal @db.Decimal(10, 0)
|
||||
reservedQuantity Decimal @db.Decimal(10, 0)
|
||||
availableQuantity Decimal @db.Decimal(10, 0)
|
||||
|
||||
@@map("Stock_Available_View")
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
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)
|
||||
stockMovements StockMovement[] @relation("StockMovement_Supplier")
|
||||
receipts PurchaseReceipt[]
|
||||
ledger SupplierLedger[]
|
||||
|
||||
@@map("Suppliers")
|
||||
}
|
||||
|
||||
model SupplierLedger {
|
||||
id Int @id @default(autoincrement())
|
||||
description String? @db.Text
|
||||
debit Decimal @default(0) @db.Decimal(15, 2)
|
||||
credit Decimal @default(0) @db.Decimal(15, 2)
|
||||
balance Decimal @db.Decimal(15, 2)
|
||||
sourceType LedgerSourceType
|
||||
sourceId Int
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
|
||||
supplierId Int
|
||||
supplier Supplier @relation(fields: [supplierId], references: [id])
|
||||
|
||||
@@index([supplierId])
|
||||
@@map("Supplier_Ledger")
|
||||
}
|
||||
Reference in New Issue
Block a user