feat: implement bank accounts, branches, and banks modules with CRUD operations

- Added BankAccountsController, BankAccountsService, and related DTOs for managing bank accounts.
- Implemented BankBranchesController, BankBranchesService, and related DTOs for managing bank branches.
- Created BanksController and BanksService for retrieving bank information.
- Integrated Prisma for database operations across all modules.
- Added response mapping for consistent API responses.
This commit is contained in:
2025-12-24 21:24:59 +03:30
parent 89c57a69c1
commit cbe51b9343
105 changed files with 18512 additions and 11840 deletions
+54
View File
@@ -0,0 +1,54 @@
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")
}
+35
View File
@@ -0,0 +1,35 @@
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? @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])
inventories Inventory[] @relation("Bank_Accounts_inventoryId_fkey")
purchaseReceiptPayments PurchaseReceiptPayments[]
posAccounts PosAccount[]
inventoryBankAccounts InventoryBankAccount[] @relation("Inventory_Bank_Accounts_bankAccountId_fkey")
@@map("Bank_Accounts")
}
+33
View File
@@ -0,0 +1,33 @@
enum OrderStatus {
PENDING
REJECT
DONE
}
enum MovementType {
IN
OUT
ADJUST
}
enum MovementReferenceType {
PURCHASE
SALES
ADJUSTMENT
INVENTORY_TRANSFER
}
enum payment_method_type {
CASH
CARD
BANK
CHECK
OTHER
}
enum ledgerSourceType {
PURCHASE
PAYMENT
ADJUSTMENT
REFUND
}
+1
View File
@@ -0,0 +1 @@
+85
View File
@@ -0,0 +1,85 @@
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")
// 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")
bankAccountId Int?
bankAccounts BankAccount[] @relation("Bank_Accounts_inventoryId_fkey")
posAccounts PosAccount[] @relation("Inventory_PosAccounts")
inventoryBankAccounts InventoryBankAccount[] @relation("Inventory_Bank_Accounts_inventoryId_fkey")
@@map("Inventories")
}
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 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")
}
+12
View File
@@ -0,0 +1,12 @@
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")
}
+118
View File
@@ -0,0 +1,118 @@
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)
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")
stockMovements StockMovement[] @relation("StockMovement_Customer")
@@map("Customers")
}
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)
customerId Int
customer Customer @relation("Customer_Orders", fields: [customerId], references: [id], onUpdate: NoAction)
@@index([customerId], map: "Orders_customerId_fkey")
@@map("Orders")
}
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 TriggerLog {
id Int @id @default(autoincrement())
message String @db.Text
createdAt DateTime @default(now()) @db.Timestamp(0)
name String @db.Text
@@map("Trigger_Logs")
}
+76
View File
@@ -0,0 +1,76 @@
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)
brandId Int?
categoryId Int?
salePrice Decimal @default(0.00) @db.Decimal(10, 2)
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")
stockBalances StockBalance[] @relation("StockBalance_Product")
stockMovements StockMovement[] @relation("StockMovement_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")
}
+55
View File
@@ -0,0 +1,55 @@
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[]
@@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
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(10, 2)
paymentMethod payment_method_type
bankAccountId Int?
description String? @db.Text
payedAt DateTime @db.Timestamp(0)
receiptId Int
createdAt DateTime @default(now()) @db.Timestamp(0)
purchaseReceipt PurchaseReceipt @relation(fields: [receiptId], references: [id])
bankAccount BankAccount? @relation(fields: [bankAccountId], references: [id])
@@index([receiptId], map: "Purchase_Receipt_Payments_receiptId_fkey")
@@index([bankAccountId], map: "Purchase_Receipt_Payments_bankAccountId_fkey")
@@map("Purchase_Receipt_Payments")
}
+9
View File
@@ -0,0 +1,9 @@
generator client {
provider = "prisma-client"
output = "../../src/generated/prisma"
moduleFormat = "cjs"
}
datasource db {
provider = "mysql"
}
+61
View File
@@ -0,0 +1,61 @@
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)
supplierId Int?
remainedInStock Decimal @default(0.00) @db.Decimal(10, 2)
counterInventoryId Int?
customerId Int?
counterInventory Inventory? @relation("StockMovement_CounterInventory", fields: [counterInventoryId], references: [id])
customer Customer? @relation("StockMovement_Customer", 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, 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")
}