Add SQL query for average cost retrieval and generate TriggerLog model
This commit is contained in:
+49
-18
@@ -82,6 +82,8 @@ model Product {
|
||||
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")
|
||||
@@ -129,6 +131,7 @@ model Supplier {
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
productCharges ProductCharge[] @relation("Supplier_Product_Charges")
|
||||
purchaseReceipts PurchaseReceipt[]
|
||||
stockMovements StockMovement[] @relation("StockMovement_Supplier")
|
||||
|
||||
@@map("Suppliers")
|
||||
}
|
||||
@@ -158,6 +161,7 @@ model Inventory {
|
||||
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)
|
||||
@@ -167,6 +171,7 @@ model Inventory {
|
||||
purchaseReceipts PurchaseReceipt[]
|
||||
stockAdjustments StockAdjustment[] @relation("Inventory_Stock_Adjustments")
|
||||
stockMovements StockMovement[] @relation("StockMovement_Inventory")
|
||||
stockBalances StockBalance[] @relation("StockBalance_inventory")
|
||||
|
||||
@@map("Inventories")
|
||||
}
|
||||
@@ -290,19 +295,22 @@ model SalesInvoiceItem {
|
||||
}
|
||||
|
||||
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)
|
||||
inventory Inventory @relation("StockMovement_Inventory", fields: [inventoryId], references: [id])
|
||||
product Product @relation("StockMovement_Product", fields: [productId], references: [id])
|
||||
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")
|
||||
@@ -310,12 +318,25 @@ model StockMovement {
|
||||
}
|
||||
|
||||
model StockBalance {
|
||||
quantity Decimal
|
||||
totalCost Decimal
|
||||
updatedAt DateTime @default(now()) @updatedAt @db.Timestamp(0)
|
||||
ProductId Int @id
|
||||
avgCost Decimal
|
||||
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")
|
||||
}
|
||||
|
||||
@@ -432,6 +453,7 @@ enum MovementReferenceType {
|
||||
PURCHASE
|
||||
SALES
|
||||
ADJUSTMENT
|
||||
INVENTORY_TRANSFER
|
||||
}
|
||||
|
||||
enum stock_cardex_type {
|
||||
@@ -451,3 +473,12 @@ enum stock_movements_view_referenceType {
|
||||
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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user