fix: update SupplierLedger model to use correct enum casing and adjust types
feat: enhance PosAccountsService to include inventoryBankAccount details in responses refactor: modify PosService to return structured inventory and bank account data chore: remove isSettled field from CreatePurchaseReceiptDto and adjust related logic feat: add payments selection in SuppliersService for better payment tracking chore: apply database migrations to adjust decimal types and enforce constraints chore: create index on Pos_Accounts for improved query performance feat: define Supplier and SupplierLedger models in Prisma schema for better data management
This commit is contained in:
@@ -26,9 +26,7 @@ model BankAccount {
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
|
||||
branch BankBranch @relation("Bank_Accounts_branchId_fkey", fields: [branchId], references: [id])
|
||||
purchaseReceiptPayments PurchaseReceiptPayments[]
|
||||
posAccounts PosAccount[]
|
||||
inventoryBankAccounts InventoryBankAccount[] @relation("Inventory_Bank_Accounts_bankAccountId_fkey")
|
||||
inventoryBankAccounts InventoryBankAccount[]
|
||||
|
||||
@@map("Bank_Accounts")
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ enum MovementReferenceType {
|
||||
INVENTORY_TRANSFER
|
||||
}
|
||||
|
||||
enum payment_method_type {
|
||||
enum PaymentMethodType {
|
||||
CASH
|
||||
CARD
|
||||
BANK
|
||||
@@ -25,9 +25,20 @@ enum payment_method_type {
|
||||
OTHER
|
||||
}
|
||||
|
||||
enum ledgerSourceType {
|
||||
enum LedgerSourceType {
|
||||
PURCHASE
|
||||
PAYMENT
|
||||
ADJUSTMENT
|
||||
REFUND
|
||||
}
|
||||
|
||||
enum PaymentType {
|
||||
PAYMENT
|
||||
REFUND
|
||||
}
|
||||
|
||||
enum PurchaseReceiptStatus {
|
||||
UNPAID
|
||||
PARTIALLY_PAID
|
||||
PAID
|
||||
}
|
||||
|
||||
@@ -9,19 +9,48 @@ model Inventory {
|
||||
isPointOfSale Boolean @default(false)
|
||||
inventoryTransfersFrom InventoryTransfer[] @relation("Inventory_From")
|
||||
inventoryTransfersTo InventoryTransfer[] @relation("Inventory_To")
|
||||
// productCharges ProductCharge[] @relation("Inventory_Product_Charges")
|
||||
purchaseReceipts PurchaseReceipt[]
|
||||
salesInvoices SalesInvoice[] @relation("Inventory_SalesInvoices")
|
||||
stockAdjustments StockAdjustment[] @relation("Inventory_Stock_Adjustments")
|
||||
stockBalances StockBalance[] @relation("StockBalance_inventory")
|
||||
counterStockMovements StockMovement[] @relation("StockMovement_CounterInventory")
|
||||
stockMovements StockMovement[] @relation("StockMovement_Inventory")
|
||||
posAccounts PosAccount[] @relation("Inventory_PosAccounts")
|
||||
inventoryBankAccounts InventoryBankAccount[] @relation("Inventory_Bank_Accounts_inventoryId_fkey")
|
||||
inventoryBankAccounts InventoryBankAccount[]
|
||||
|
||||
@@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])
|
||||
|
||||
@@index([inventoryId])
|
||||
@@map("Pos_Accounts")
|
||||
}
|
||||
|
||||
model InventoryTransfer {
|
||||
id Int @id @default(autoincrement())
|
||||
code String @unique @db.VarChar(100)
|
||||
@@ -40,7 +69,7 @@ model InventoryTransfer {
|
||||
|
||||
model InventoryTransferItem {
|
||||
id Int @id @default(autoincrement())
|
||||
count Decimal @db.Decimal(10, 2)
|
||||
count Decimal @db.Decimal(10, 0)
|
||||
productId Int
|
||||
transferId Int
|
||||
product Product @relation("InventoryTransferItem_Product", fields: [productId], references: [id])
|
||||
@@ -50,34 +79,3 @@ model InventoryTransferItem {
|
||||
@@index([transferId], map: "Inventory_Transfer_Items_transferId_fkey")
|
||||
@@map("Inventory_Transfer_Items")
|
||||
}
|
||||
|
||||
model InventoryBankAccount {
|
||||
inventoryId Int
|
||||
bankAccountId Int
|
||||
|
||||
inventory Inventory @relation("Inventory_Bank_Accounts_inventoryId_fkey", fields: [inventoryId], references: [id])
|
||||
bankAccount BankAccount @relation("Inventory_Bank_Accounts_bankAccountId_fkey", fields: [bankAccountId], references: [id])
|
||||
posAccounts PosAccount[] @relation("Pos_Accounts_inventoryBankAccountId_fkey")
|
||||
|
||||
@@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)
|
||||
|
||||
inventory Inventory @relation("Inventory_PosAccounts", fields: [inventoryId], references: [id])
|
||||
inventoryBankAccount InventoryBankAccount? @relation("Pos_Accounts_inventoryBankAccountId_fkey", fields: [bankAccountId, inventoryId], references: [bankAccountId, inventoryId])
|
||||
bankAccount BankAccount? @relation(fields: [bankAccountId], references: [id])
|
||||
|
||||
@@map("Pos_Accounts")
|
||||
}
|
||||
|
||||
+14
-52
@@ -1,41 +1,3 @@
|
||||
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)
|
||||
purchaseReceipts PurchaseReceipt[]
|
||||
stockMovements StockMovement[] @relation("StockMovement_Supplier")
|
||||
supplierLedgers SupplierLedger[]
|
||||
|
||||
@@map("Suppliers")
|
||||
}
|
||||
|
||||
model SupplierLedger {
|
||||
id Int @id @default(autoincrement())
|
||||
description String? @db.Text
|
||||
debit Decimal @db.Decimal(10, 2)
|
||||
credit Decimal @db.Decimal(10, 2)
|
||||
balance Decimal @db.Decimal(10, 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_supplierId_fkey")
|
||||
@@map("Supplier_Ledger")
|
||||
}
|
||||
|
||||
model Customer {
|
||||
id Int @id @default(autoincrement())
|
||||
firstName String @db.VarChar(255)
|
||||
@@ -58,17 +20,17 @@ model Customer {
|
||||
}
|
||||
|
||||
model Order {
|
||||
id Int @id @default(autoincrement())
|
||||
orderNumber String @unique @db.VarChar(100)
|
||||
status OrderStatus @default(PENDING)
|
||||
paymentMethod payment_method_type @default(CARD)
|
||||
totalAmount Decimal @db.Decimal(10, 2)
|
||||
description String? @db.Text
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
id Int @id @default(autoincrement())
|
||||
orderNumber String @unique @db.VarChar(100)
|
||||
status OrderStatus @default(PENDING)
|
||||
paymentMethod PaymentMethodType @default(CARD)
|
||||
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
|
||||
customer Customer @relation("Customer_Orders", fields: [customerId], references: [id], onUpdate: NoAction)
|
||||
customer Customer @relation("Customer_Orders", fields: [customerId], references: [id], onUpdate: NoAction)
|
||||
|
||||
@@index([customerId], map: "Orders_customerId_fkey")
|
||||
@@map("Orders")
|
||||
@@ -77,7 +39,7 @@ model Order {
|
||||
model SalesInvoice {
|
||||
id Int @id @default(autoincrement())
|
||||
code String @unique @db.VarChar(100)
|
||||
totalAmount Decimal @db.Decimal(10, 2)
|
||||
totalAmount Decimal @db.Decimal(15, 2)
|
||||
description String? @db.Text
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
@@ -94,9 +56,9 @@ model SalesInvoice {
|
||||
|
||||
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)
|
||||
count Decimal @db.Decimal(10, 0)
|
||||
fee Decimal @db.Decimal(15, 2)
|
||||
total Decimal @db.Decimal(15, 2)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
invoiceId Int
|
||||
productId Int
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
model ProductVariant {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @db.VarChar(255)
|
||||
basePrice Decimal @db.Decimal(10, 2)
|
||||
salePrice Decimal @db.Decimal(10, 2)
|
||||
basePrice Decimal @db.Decimal(15, 2)
|
||||
salePrice Decimal @db.Decimal(15, 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)
|
||||
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)
|
||||
@@ -32,7 +32,7 @@ model Product {
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
brandId Int?
|
||||
categoryId Int?
|
||||
salePrice Decimal @default(0.00) @db.Decimal(10, 2)
|
||||
salePrice Decimal @default(0.00) @db.Decimal(15, 0)
|
||||
inventoryTransferItems InventoryTransferItem[] @relation("InventoryTransferItem_Product")
|
||||
// productCharges ProductCharge[] @relation("Product_Charges")
|
||||
variants ProductVariant[] @relation("Product_Variant")
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
model PurchaseReceipt {
|
||||
id Int @id @default(autoincrement())
|
||||
code String @unique @db.VarChar(100)
|
||||
totalAmount Decimal @db.Decimal(10, 2)
|
||||
paidAmount Decimal @default(0.00) @db.Decimal(10, 2)
|
||||
isSettled Boolean @default(false)
|
||||
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])
|
||||
purchaseReceiptPayments PurchaseReceiptPayments[]
|
||||
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")
|
||||
@@ -21,9 +21,9 @@ model PurchaseReceipt {
|
||||
|
||||
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)
|
||||
count Decimal @db.Decimal(10, 0)
|
||||
fee Decimal @db.Decimal(15, 2)
|
||||
total Decimal @db.Decimal(15, 2)
|
||||
description String? @db.Text
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
receiptId Int
|
||||
@@ -37,19 +37,20 @@ model PurchaseReceiptItem {
|
||||
}
|
||||
|
||||
model PurchaseReceiptPayments {
|
||||
id Int @id @default(autoincrement())
|
||||
amount Decimal @db.Decimal(10, 2)
|
||||
paymentMethod payment_method_type
|
||||
bankAccountId Int?
|
||||
description String? @db.Text
|
||||
payedAt DateTime @db.Timestamp(0)
|
||||
id Int @id @default(autoincrement())
|
||||
amount Decimal @db.Decimal(15, 2)
|
||||
paymentMethod PaymentMethodType
|
||||
type PaymentType
|
||||
bankAccountId Int
|
||||
inventoryId Int
|
||||
description String? @db.Text
|
||||
payedAt DateTime @db.Timestamp(0)
|
||||
receiptId Int
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
|
||||
purchaseReceipt PurchaseReceipt @relation(fields: [receiptId], references: [id])
|
||||
bankAccount BankAccount? @relation(fields: [bankAccountId], references: [id])
|
||||
purchaseReceipt PurchaseReceipt @relation(fields: [receiptId], references: [id])
|
||||
inventoryBankAccount InventoryBankAccount @relation(fields: [inventoryId, bankAccountId], references: [inventoryId, bankAccountId])
|
||||
|
||||
@@index([receiptId], map: "Purchase_Receipt_Payments_receiptId_fkey")
|
||||
@@index([bankAccountId], map: "Purchase_Receipt_Payments_bankAccountId_fkey")
|
||||
@@map("Purchase_Receipt_Payments")
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
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)
|
||||
quantity Decimal @db.Decimal(10, 0)
|
||||
fee 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(10, 2)
|
||||
avgCost Decimal @db.Decimal(15, 2)
|
||||
supplierId Int?
|
||||
remainedInStock Decimal @default(0.00) @db.Decimal(10, 2)
|
||||
remainedInStock Decimal @default(0.00) @db.Decimal(10, 0)
|
||||
counterInventoryId Int?
|
||||
customerId Int?
|
||||
counterInventory Inventory? @relation("StockMovement_CounterInventory", fields: [counterInventoryId], references: [id])
|
||||
@@ -48,7 +48,7 @@ model StockBalance {
|
||||
|
||||
model StockAdjustment {
|
||||
id Int @id @default(autoincrement())
|
||||
adjustedQuantity Decimal @db.Decimal(10, 2)
|
||||
adjustedQuantity Decimal @db.Decimal(10, 0)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
productId Int
|
||||
inventoryId Int
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
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