feat(bank-accounts): add transaction retrieval and update service logic

- Implemented a new endpoint to fetch transactions for a specific bank account.
- Refactored the bank account service to streamline transaction handling and balance calculations.
- Removed the bank account balance table and adjusted related logic in workflows and services.
- Enhanced transaction mapping to include references to sales and purchase records.
This commit is contained in:
2026-01-05 18:35:08 +03:30
parent fda190f902
commit b05048e62f
14 changed files with 147 additions and 1525 deletions
-5
View File
@@ -52,11 +52,6 @@ export type BankAccount = Prisma.BankAccountModel
*
*/
export type BankAccountTransaction = Prisma.BankAccountTransactionModel
/**
* Model BankAccountBalance
*
*/
export type BankAccountBalance = Prisma.BankAccountBalanceModel
/**
* Model Inventory
*
-5
View File
@@ -72,11 +72,6 @@ export type BankAccount = Prisma.BankAccountModel
*
*/
export type BankAccountTransaction = Prisma.BankAccountTransactionModel
/**
* Model BankAccountBalance
*
*/
export type BankAccountBalance = Prisma.BankAccountBalanceModel
/**
* Model Inventory
*
File diff suppressed because one or more lines are too long
@@ -391,7 +391,6 @@ export const ModelName = {
BankBranch: 'BankBranch',
BankAccount: 'BankAccount',
BankAccountTransaction: 'BankAccountTransaction',
BankAccountBalance: 'BankAccountBalance',
Inventory: 'Inventory',
InventoryBankAccount: 'InventoryBankAccount',
PosAccount: 'PosAccount',
@@ -433,7 +432,7 @@ export type TypeMap<ExtArgs extends runtime.Types.Extensions.InternalArgs = runt
omit: GlobalOmitOptions
}
meta: {
modelProps: "user" | "role" | "otpCode" | "refreshToken" | "bankBranch" | "bankAccount" | "bankAccountTransaction" | "bankAccountBalance" | "inventory" | "inventoryBankAccount" | "posAccount" | "inventoryTransfer" | "inventoryTransferItem" | "bank" | "order" | "orderItem" | "customer" | "triggerLog" | "productVariant" | "product" | "productBrand" | "productCategory" | "purchaseReceipt" | "purchaseReceiptItem" | "purchaseReceiptPayments" | "salesInvoice" | "salesInvoiceItem" | "salesInvoicePayment" | "stockMovement" | "stockBalance" | "stockAdjustment" | "stockReservation" | "supplier" | "supplierLedger"
modelProps: "user" | "role" | "otpCode" | "refreshToken" | "bankBranch" | "bankAccount" | "bankAccountTransaction" | "inventory" | "inventoryBankAccount" | "posAccount" | "inventoryTransfer" | "inventoryTransferItem" | "bank" | "order" | "orderItem" | "customer" | "triggerLog" | "productVariant" | "product" | "productBrand" | "productCategory" | "purchaseReceipt" | "purchaseReceiptItem" | "purchaseReceiptPayments" | "salesInvoice" | "salesInvoiceItem" | "salesInvoicePayment" | "stockMovement" | "stockBalance" | "stockAdjustment" | "stockReservation" | "supplier" | "supplierLedger"
txIsolationLevel: TransactionIsolationLevel
}
model: {
@@ -899,72 +898,6 @@ export type TypeMap<ExtArgs extends runtime.Types.Extensions.InternalArgs = runt
}
}
}
BankAccountBalance: {
payload: Prisma.$BankAccountBalancePayload<ExtArgs>
fields: Prisma.BankAccountBalanceFieldRefs
operations: {
findUnique: {
args: Prisma.BankAccountBalanceFindUniqueArgs<ExtArgs>
result: runtime.Types.Utils.PayloadToResult<Prisma.$BankAccountBalancePayload> | null
}
findUniqueOrThrow: {
args: Prisma.BankAccountBalanceFindUniqueOrThrowArgs<ExtArgs>
result: runtime.Types.Utils.PayloadToResult<Prisma.$BankAccountBalancePayload>
}
findFirst: {
args: Prisma.BankAccountBalanceFindFirstArgs<ExtArgs>
result: runtime.Types.Utils.PayloadToResult<Prisma.$BankAccountBalancePayload> | null
}
findFirstOrThrow: {
args: Prisma.BankAccountBalanceFindFirstOrThrowArgs<ExtArgs>
result: runtime.Types.Utils.PayloadToResult<Prisma.$BankAccountBalancePayload>
}
findMany: {
args: Prisma.BankAccountBalanceFindManyArgs<ExtArgs>
result: runtime.Types.Utils.PayloadToResult<Prisma.$BankAccountBalancePayload>[]
}
create: {
args: Prisma.BankAccountBalanceCreateArgs<ExtArgs>
result: runtime.Types.Utils.PayloadToResult<Prisma.$BankAccountBalancePayload>
}
createMany: {
args: Prisma.BankAccountBalanceCreateManyArgs<ExtArgs>
result: BatchPayload
}
delete: {
args: Prisma.BankAccountBalanceDeleteArgs<ExtArgs>
result: runtime.Types.Utils.PayloadToResult<Prisma.$BankAccountBalancePayload>
}
update: {
args: Prisma.BankAccountBalanceUpdateArgs<ExtArgs>
result: runtime.Types.Utils.PayloadToResult<Prisma.$BankAccountBalancePayload>
}
deleteMany: {
args: Prisma.BankAccountBalanceDeleteManyArgs<ExtArgs>
result: BatchPayload
}
updateMany: {
args: Prisma.BankAccountBalanceUpdateManyArgs<ExtArgs>
result: BatchPayload
}
upsert: {
args: Prisma.BankAccountBalanceUpsertArgs<ExtArgs>
result: runtime.Types.Utils.PayloadToResult<Prisma.$BankAccountBalancePayload>
}
aggregate: {
args: Prisma.BankAccountBalanceAggregateArgs<ExtArgs>
result: runtime.Types.Utils.Optional<Prisma.AggregateBankAccountBalance>
}
groupBy: {
args: Prisma.BankAccountBalanceGroupByArgs<ExtArgs>
result: runtime.Types.Utils.Optional<Prisma.BankAccountBalanceGroupByOutputType>[]
}
count: {
args: Prisma.BankAccountBalanceCountArgs<ExtArgs>
result: runtime.Types.Utils.Optional<Prisma.BankAccountBalanceCountAggregateOutputType> | number
}
}
}
Inventory: {
payload: Prisma.$InventoryPayload<ExtArgs>
fields: Prisma.InventoryFieldRefs
@@ -2816,15 +2749,6 @@ export const BankAccountTransactionScalarFieldEnum = {
export type BankAccountTransactionScalarFieldEnum = (typeof BankAccountTransactionScalarFieldEnum)[keyof typeof BankAccountTransactionScalarFieldEnum]
export const BankAccountBalanceScalarFieldEnum = {
bankAccountId: 'bankAccountId',
balance: 'balance',
updatedAt: 'updatedAt'
} as const
export type BankAccountBalanceScalarFieldEnum = (typeof BankAccountBalanceScalarFieldEnum)[keyof typeof BankAccountBalanceScalarFieldEnum]
export const InventoryScalarFieldEnum = {
id: 'id',
name: 'name',
@@ -3684,7 +3608,6 @@ export type GlobalOmitConfig = {
bankBranch?: Prisma.BankBranchOmit
bankAccount?: Prisma.BankAccountOmit
bankAccountTransaction?: Prisma.BankAccountTransactionOmit
bankAccountBalance?: Prisma.BankAccountBalanceOmit
inventory?: Prisma.InventoryOmit
inventoryBankAccount?: Prisma.InventoryBankAccountOmit
posAccount?: Prisma.PosAccountOmit
@@ -58,7 +58,6 @@ export const ModelName = {
BankBranch: 'BankBranch',
BankAccount: 'BankAccount',
BankAccountTransaction: 'BankAccountTransaction',
BankAccountBalance: 'BankAccountBalance',
Inventory: 'Inventory',
InventoryBankAccount: 'InventoryBankAccount',
PosAccount: 'PosAccount',
@@ -199,15 +198,6 @@ export const BankAccountTransactionScalarFieldEnum = {
export type BankAccountTransactionScalarFieldEnum = (typeof BankAccountTransactionScalarFieldEnum)[keyof typeof BankAccountTransactionScalarFieldEnum]
export const BankAccountBalanceScalarFieldEnum = {
bankAccountId: 'bankAccountId',
balance: 'balance',
updatedAt: 'updatedAt'
} as const
export type BankAccountBalanceScalarFieldEnum = (typeof BankAccountBalanceScalarFieldEnum)[keyof typeof BankAccountBalanceScalarFieldEnum]
export const InventoryScalarFieldEnum = {
id: 'id',
name: 'name',
-1
View File
@@ -15,7 +15,6 @@ export type * from './models/RefreshToken.js'
export type * from './models/BankBranch.js'
export type * from './models/BankAccount.js'
export type * from './models/BankAccountTransaction.js'
export type * from './models/BankAccountBalance.js'
export type * from './models/Inventory.js'
export type * from './models/InventoryBankAccount.js'
export type * from './models/PosAccount.js'
-148
View File
@@ -256,7 +256,6 @@ export type BankAccountWhereInput = {
inventoryBankAccounts?: Prisma.InventoryBankAccountListRelationFilter
purchaseReceiptPayments?: Prisma.PurchaseReceiptPaymentsListRelationFilter
bankAccountTransactions?: Prisma.BankAccountTransactionListRelationFilter
bankAccountBalances?: Prisma.BankAccountBalanceListRelationFilter
}
export type BankAccountOrderByWithRelationInput = {
@@ -273,7 +272,6 @@ export type BankAccountOrderByWithRelationInput = {
inventoryBankAccounts?: Prisma.InventoryBankAccountOrderByRelationAggregateInput
purchaseReceiptPayments?: Prisma.PurchaseReceiptPaymentsOrderByRelationAggregateInput
bankAccountTransactions?: Prisma.BankAccountTransactionOrderByRelationAggregateInput
bankAccountBalances?: Prisma.BankAccountBalanceOrderByRelationAggregateInput
_relevance?: Prisma.BankAccountOrderByRelevanceInput
}
@@ -294,7 +292,6 @@ export type BankAccountWhereUniqueInput = Prisma.AtLeast<{
inventoryBankAccounts?: Prisma.InventoryBankAccountListRelationFilter
purchaseReceiptPayments?: Prisma.PurchaseReceiptPaymentsListRelationFilter
bankAccountTransactions?: Prisma.BankAccountTransactionListRelationFilter
bankAccountBalances?: Prisma.BankAccountBalanceListRelationFilter
}, "id" | "accountNumber" | "cardNumber" | "iban">
export type BankAccountOrderByWithAggregationInput = {
@@ -341,7 +338,6 @@ export type BankAccountCreateInput = {
inventoryBankAccounts?: Prisma.InventoryBankAccountCreateNestedManyWithoutBankAccountInput
purchaseReceiptPayments?: Prisma.PurchaseReceiptPaymentsCreateNestedManyWithoutBankAccountInput
bankAccountTransactions?: Prisma.BankAccountTransactionCreateNestedManyWithoutBankAccountInput
bankAccountBalances?: Prisma.BankAccountBalanceCreateNestedManyWithoutBankAccountInput
}
export type BankAccountUncheckedCreateInput = {
@@ -357,7 +353,6 @@ export type BankAccountUncheckedCreateInput = {
inventoryBankAccounts?: Prisma.InventoryBankAccountUncheckedCreateNestedManyWithoutBankAccountInput
purchaseReceiptPayments?: Prisma.PurchaseReceiptPaymentsUncheckedCreateNestedManyWithoutBankAccountInput
bankAccountTransactions?: Prisma.BankAccountTransactionUncheckedCreateNestedManyWithoutBankAccountInput
bankAccountBalances?: Prisma.BankAccountBalanceUncheckedCreateNestedManyWithoutBankAccountInput
}
export type BankAccountUpdateInput = {
@@ -372,7 +367,6 @@ export type BankAccountUpdateInput = {
inventoryBankAccounts?: Prisma.InventoryBankAccountUpdateManyWithoutBankAccountNestedInput
purchaseReceiptPayments?: Prisma.PurchaseReceiptPaymentsUpdateManyWithoutBankAccountNestedInput
bankAccountTransactions?: Prisma.BankAccountTransactionUpdateManyWithoutBankAccountNestedInput
bankAccountBalances?: Prisma.BankAccountBalanceUpdateManyWithoutBankAccountNestedInput
}
export type BankAccountUncheckedUpdateInput = {
@@ -388,7 +382,6 @@ export type BankAccountUncheckedUpdateInput = {
inventoryBankAccounts?: Prisma.InventoryBankAccountUncheckedUpdateManyWithoutBankAccountNestedInput
purchaseReceiptPayments?: Prisma.PurchaseReceiptPaymentsUncheckedUpdateManyWithoutBankAccountNestedInput
bankAccountTransactions?: Prisma.BankAccountTransactionUncheckedUpdateManyWithoutBankAccountNestedInput
bankAccountBalances?: Prisma.BankAccountBalanceUncheckedUpdateManyWithoutBankAccountNestedInput
}
export type BankAccountCreateManyInput = {
@@ -548,20 +541,6 @@ export type BankAccountUpdateOneRequiredWithoutBankAccountTransactionsNestedInpu
update?: Prisma.XOR<Prisma.XOR<Prisma.BankAccountUpdateToOneWithWhereWithoutBankAccountTransactionsInput, Prisma.BankAccountUpdateWithoutBankAccountTransactionsInput>, Prisma.BankAccountUncheckedUpdateWithoutBankAccountTransactionsInput>
}
export type BankAccountCreateNestedOneWithoutBankAccountBalancesInput = {
create?: Prisma.XOR<Prisma.BankAccountCreateWithoutBankAccountBalancesInput, Prisma.BankAccountUncheckedCreateWithoutBankAccountBalancesInput>
connectOrCreate?: Prisma.BankAccountCreateOrConnectWithoutBankAccountBalancesInput
connect?: Prisma.BankAccountWhereUniqueInput
}
export type BankAccountUpdateOneRequiredWithoutBankAccountBalancesNestedInput = {
create?: Prisma.XOR<Prisma.BankAccountCreateWithoutBankAccountBalancesInput, Prisma.BankAccountUncheckedCreateWithoutBankAccountBalancesInput>
connectOrCreate?: Prisma.BankAccountCreateOrConnectWithoutBankAccountBalancesInput
upsert?: Prisma.BankAccountUpsertWithoutBankAccountBalancesInput
connect?: Prisma.BankAccountWhereUniqueInput
update?: Prisma.XOR<Prisma.XOR<Prisma.BankAccountUpdateToOneWithWhereWithoutBankAccountBalancesInput, Prisma.BankAccountUpdateWithoutBankAccountBalancesInput>, Prisma.BankAccountUncheckedUpdateWithoutBankAccountBalancesInput>
}
export type BankAccountCreateNestedOneWithoutInventoryBankAccountsInput = {
create?: Prisma.XOR<Prisma.BankAccountCreateWithoutInventoryBankAccountsInput, Prisma.BankAccountUncheckedCreateWithoutInventoryBankAccountsInput>
connectOrCreate?: Prisma.BankAccountCreateOrConnectWithoutInventoryBankAccountsInput
@@ -601,7 +580,6 @@ export type BankAccountCreateWithoutBranchInput = {
inventoryBankAccounts?: Prisma.InventoryBankAccountCreateNestedManyWithoutBankAccountInput
purchaseReceiptPayments?: Prisma.PurchaseReceiptPaymentsCreateNestedManyWithoutBankAccountInput
bankAccountTransactions?: Prisma.BankAccountTransactionCreateNestedManyWithoutBankAccountInput
bankAccountBalances?: Prisma.BankAccountBalanceCreateNestedManyWithoutBankAccountInput
}
export type BankAccountUncheckedCreateWithoutBranchInput = {
@@ -616,7 +594,6 @@ export type BankAccountUncheckedCreateWithoutBranchInput = {
inventoryBankAccounts?: Prisma.InventoryBankAccountUncheckedCreateNestedManyWithoutBankAccountInput
purchaseReceiptPayments?: Prisma.PurchaseReceiptPaymentsUncheckedCreateNestedManyWithoutBankAccountInput
bankAccountTransactions?: Prisma.BankAccountTransactionUncheckedCreateNestedManyWithoutBankAccountInput
bankAccountBalances?: Prisma.BankAccountBalanceUncheckedCreateNestedManyWithoutBankAccountInput
}
export type BankAccountCreateOrConnectWithoutBranchInput = {
@@ -671,7 +648,6 @@ export type BankAccountCreateWithoutBankAccountTransactionsInput = {
branch: Prisma.BankBranchCreateNestedOneWithoutBankAccountsInput
inventoryBankAccounts?: Prisma.InventoryBankAccountCreateNestedManyWithoutBankAccountInput
purchaseReceiptPayments?: Prisma.PurchaseReceiptPaymentsCreateNestedManyWithoutBankAccountInput
bankAccountBalances?: Prisma.BankAccountBalanceCreateNestedManyWithoutBankAccountInput
}
export type BankAccountUncheckedCreateWithoutBankAccountTransactionsInput = {
@@ -686,7 +662,6 @@ export type BankAccountUncheckedCreateWithoutBankAccountTransactionsInput = {
deletedAt?: Date | string | null
inventoryBankAccounts?: Prisma.InventoryBankAccountUncheckedCreateNestedManyWithoutBankAccountInput
purchaseReceiptPayments?: Prisma.PurchaseReceiptPaymentsUncheckedCreateNestedManyWithoutBankAccountInput
bankAccountBalances?: Prisma.BankAccountBalanceUncheckedCreateNestedManyWithoutBankAccountInput
}
export type BankAccountCreateOrConnectWithoutBankAccountTransactionsInput = {
@@ -716,7 +691,6 @@ export type BankAccountUpdateWithoutBankAccountTransactionsInput = {
branch?: Prisma.BankBranchUpdateOneRequiredWithoutBankAccountsNestedInput
inventoryBankAccounts?: Prisma.InventoryBankAccountUpdateManyWithoutBankAccountNestedInput
purchaseReceiptPayments?: Prisma.PurchaseReceiptPaymentsUpdateManyWithoutBankAccountNestedInput
bankAccountBalances?: Prisma.BankAccountBalanceUpdateManyWithoutBankAccountNestedInput
}
export type BankAccountUncheckedUpdateWithoutBankAccountTransactionsInput = {
@@ -731,81 +705,6 @@ export type BankAccountUncheckedUpdateWithoutBankAccountTransactionsInput = {
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
inventoryBankAccounts?: Prisma.InventoryBankAccountUncheckedUpdateManyWithoutBankAccountNestedInput
purchaseReceiptPayments?: Prisma.PurchaseReceiptPaymentsUncheckedUpdateManyWithoutBankAccountNestedInput
bankAccountBalances?: Prisma.BankAccountBalanceUncheckedUpdateManyWithoutBankAccountNestedInput
}
export type BankAccountCreateWithoutBankAccountBalancesInput = {
accountNumber?: string | null
cardNumber?: string | null
name: string
iban?: string | null
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
branch: Prisma.BankBranchCreateNestedOneWithoutBankAccountsInput
inventoryBankAccounts?: Prisma.InventoryBankAccountCreateNestedManyWithoutBankAccountInput
purchaseReceiptPayments?: Prisma.PurchaseReceiptPaymentsCreateNestedManyWithoutBankAccountInput
bankAccountTransactions?: Prisma.BankAccountTransactionCreateNestedManyWithoutBankAccountInput
}
export type BankAccountUncheckedCreateWithoutBankAccountBalancesInput = {
id?: number
accountNumber?: string | null
cardNumber?: string | null
name: string
iban?: string | null
branchId: number
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
inventoryBankAccounts?: Prisma.InventoryBankAccountUncheckedCreateNestedManyWithoutBankAccountInput
purchaseReceiptPayments?: Prisma.PurchaseReceiptPaymentsUncheckedCreateNestedManyWithoutBankAccountInput
bankAccountTransactions?: Prisma.BankAccountTransactionUncheckedCreateNestedManyWithoutBankAccountInput
}
export type BankAccountCreateOrConnectWithoutBankAccountBalancesInput = {
where: Prisma.BankAccountWhereUniqueInput
create: Prisma.XOR<Prisma.BankAccountCreateWithoutBankAccountBalancesInput, Prisma.BankAccountUncheckedCreateWithoutBankAccountBalancesInput>
}
export type BankAccountUpsertWithoutBankAccountBalancesInput = {
update: Prisma.XOR<Prisma.BankAccountUpdateWithoutBankAccountBalancesInput, Prisma.BankAccountUncheckedUpdateWithoutBankAccountBalancesInput>
create: Prisma.XOR<Prisma.BankAccountCreateWithoutBankAccountBalancesInput, Prisma.BankAccountUncheckedCreateWithoutBankAccountBalancesInput>
where?: Prisma.BankAccountWhereInput
}
export type BankAccountUpdateToOneWithWhereWithoutBankAccountBalancesInput = {
where?: Prisma.BankAccountWhereInput
data: Prisma.XOR<Prisma.BankAccountUpdateWithoutBankAccountBalancesInput, Prisma.BankAccountUncheckedUpdateWithoutBankAccountBalancesInput>
}
export type BankAccountUpdateWithoutBankAccountBalancesInput = {
accountNumber?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
cardNumber?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
name?: Prisma.StringFieldUpdateOperationsInput | string
iban?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
branch?: Prisma.BankBranchUpdateOneRequiredWithoutBankAccountsNestedInput
inventoryBankAccounts?: Prisma.InventoryBankAccountUpdateManyWithoutBankAccountNestedInput
purchaseReceiptPayments?: Prisma.PurchaseReceiptPaymentsUpdateManyWithoutBankAccountNestedInput
bankAccountTransactions?: Prisma.BankAccountTransactionUpdateManyWithoutBankAccountNestedInput
}
export type BankAccountUncheckedUpdateWithoutBankAccountBalancesInput = {
id?: Prisma.IntFieldUpdateOperationsInput | number
accountNumber?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
cardNumber?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
name?: Prisma.StringFieldUpdateOperationsInput | string
iban?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
branchId?: Prisma.IntFieldUpdateOperationsInput | number
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
inventoryBankAccounts?: Prisma.InventoryBankAccountUncheckedUpdateManyWithoutBankAccountNestedInput
purchaseReceiptPayments?: Prisma.PurchaseReceiptPaymentsUncheckedUpdateManyWithoutBankAccountNestedInput
bankAccountTransactions?: Prisma.BankAccountTransactionUncheckedUpdateManyWithoutBankAccountNestedInput
}
export type BankAccountCreateWithoutInventoryBankAccountsInput = {
@@ -819,7 +718,6 @@ export type BankAccountCreateWithoutInventoryBankAccountsInput = {
branch: Prisma.BankBranchCreateNestedOneWithoutBankAccountsInput
purchaseReceiptPayments?: Prisma.PurchaseReceiptPaymentsCreateNestedManyWithoutBankAccountInput
bankAccountTransactions?: Prisma.BankAccountTransactionCreateNestedManyWithoutBankAccountInput
bankAccountBalances?: Prisma.BankAccountBalanceCreateNestedManyWithoutBankAccountInput
}
export type BankAccountUncheckedCreateWithoutInventoryBankAccountsInput = {
@@ -834,7 +732,6 @@ export type BankAccountUncheckedCreateWithoutInventoryBankAccountsInput = {
deletedAt?: Date | string | null
purchaseReceiptPayments?: Prisma.PurchaseReceiptPaymentsUncheckedCreateNestedManyWithoutBankAccountInput
bankAccountTransactions?: Prisma.BankAccountTransactionUncheckedCreateNestedManyWithoutBankAccountInput
bankAccountBalances?: Prisma.BankAccountBalanceUncheckedCreateNestedManyWithoutBankAccountInput
}
export type BankAccountCreateOrConnectWithoutInventoryBankAccountsInput = {
@@ -864,7 +761,6 @@ export type BankAccountUpdateWithoutInventoryBankAccountsInput = {
branch?: Prisma.BankBranchUpdateOneRequiredWithoutBankAccountsNestedInput
purchaseReceiptPayments?: Prisma.PurchaseReceiptPaymentsUpdateManyWithoutBankAccountNestedInput
bankAccountTransactions?: Prisma.BankAccountTransactionUpdateManyWithoutBankAccountNestedInput
bankAccountBalances?: Prisma.BankAccountBalanceUpdateManyWithoutBankAccountNestedInput
}
export type BankAccountUncheckedUpdateWithoutInventoryBankAccountsInput = {
@@ -879,7 +775,6 @@ export type BankAccountUncheckedUpdateWithoutInventoryBankAccountsInput = {
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
purchaseReceiptPayments?: Prisma.PurchaseReceiptPaymentsUncheckedUpdateManyWithoutBankAccountNestedInput
bankAccountTransactions?: Prisma.BankAccountTransactionUncheckedUpdateManyWithoutBankAccountNestedInput
bankAccountBalances?: Prisma.BankAccountBalanceUncheckedUpdateManyWithoutBankAccountNestedInput
}
export type BankAccountCreateWithoutPurchaseReceiptPaymentsInput = {
@@ -893,7 +788,6 @@ export type BankAccountCreateWithoutPurchaseReceiptPaymentsInput = {
branch: Prisma.BankBranchCreateNestedOneWithoutBankAccountsInput
inventoryBankAccounts?: Prisma.InventoryBankAccountCreateNestedManyWithoutBankAccountInput
bankAccountTransactions?: Prisma.BankAccountTransactionCreateNestedManyWithoutBankAccountInput
bankAccountBalances?: Prisma.BankAccountBalanceCreateNestedManyWithoutBankAccountInput
}
export type BankAccountUncheckedCreateWithoutPurchaseReceiptPaymentsInput = {
@@ -908,7 +802,6 @@ export type BankAccountUncheckedCreateWithoutPurchaseReceiptPaymentsInput = {
deletedAt?: Date | string | null
inventoryBankAccounts?: Prisma.InventoryBankAccountUncheckedCreateNestedManyWithoutBankAccountInput
bankAccountTransactions?: Prisma.BankAccountTransactionUncheckedCreateNestedManyWithoutBankAccountInput
bankAccountBalances?: Prisma.BankAccountBalanceUncheckedCreateNestedManyWithoutBankAccountInput
}
export type BankAccountCreateOrConnectWithoutPurchaseReceiptPaymentsInput = {
@@ -938,7 +831,6 @@ export type BankAccountUpdateWithoutPurchaseReceiptPaymentsInput = {
branch?: Prisma.BankBranchUpdateOneRequiredWithoutBankAccountsNestedInput
inventoryBankAccounts?: Prisma.InventoryBankAccountUpdateManyWithoutBankAccountNestedInput
bankAccountTransactions?: Prisma.BankAccountTransactionUpdateManyWithoutBankAccountNestedInput
bankAccountBalances?: Prisma.BankAccountBalanceUpdateManyWithoutBankAccountNestedInput
}
export type BankAccountUncheckedUpdateWithoutPurchaseReceiptPaymentsInput = {
@@ -953,7 +845,6 @@ export type BankAccountUncheckedUpdateWithoutPurchaseReceiptPaymentsInput = {
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
inventoryBankAccounts?: Prisma.InventoryBankAccountUncheckedUpdateManyWithoutBankAccountNestedInput
bankAccountTransactions?: Prisma.BankAccountTransactionUncheckedUpdateManyWithoutBankAccountNestedInput
bankAccountBalances?: Prisma.BankAccountBalanceUncheckedUpdateManyWithoutBankAccountNestedInput
}
export type BankAccountCreateManyBranchInput = {
@@ -978,7 +869,6 @@ export type BankAccountUpdateWithoutBranchInput = {
inventoryBankAccounts?: Prisma.InventoryBankAccountUpdateManyWithoutBankAccountNestedInput
purchaseReceiptPayments?: Prisma.PurchaseReceiptPaymentsUpdateManyWithoutBankAccountNestedInput
bankAccountTransactions?: Prisma.BankAccountTransactionUpdateManyWithoutBankAccountNestedInput
bankAccountBalances?: Prisma.BankAccountBalanceUpdateManyWithoutBankAccountNestedInput
}
export type BankAccountUncheckedUpdateWithoutBranchInput = {
@@ -993,7 +883,6 @@ export type BankAccountUncheckedUpdateWithoutBranchInput = {
inventoryBankAccounts?: Prisma.InventoryBankAccountUncheckedUpdateManyWithoutBankAccountNestedInput
purchaseReceiptPayments?: Prisma.PurchaseReceiptPaymentsUncheckedUpdateManyWithoutBankAccountNestedInput
bankAccountTransactions?: Prisma.BankAccountTransactionUncheckedUpdateManyWithoutBankAccountNestedInput
bankAccountBalances?: Prisma.BankAccountBalanceUncheckedUpdateManyWithoutBankAccountNestedInput
}
export type BankAccountUncheckedUpdateManyWithoutBranchInput = {
@@ -1016,14 +905,12 @@ export type BankAccountCountOutputType = {
inventoryBankAccounts: number
purchaseReceiptPayments: number
bankAccountTransactions: number
bankAccountBalances: number
}
export type BankAccountCountOutputTypeSelect<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = {
inventoryBankAccounts?: boolean | BankAccountCountOutputTypeCountInventoryBankAccountsArgs
purchaseReceiptPayments?: boolean | BankAccountCountOutputTypeCountPurchaseReceiptPaymentsArgs
bankAccountTransactions?: boolean | BankAccountCountOutputTypeCountBankAccountTransactionsArgs
bankAccountBalances?: boolean | BankAccountCountOutputTypeCountBankAccountBalancesArgs
}
/**
@@ -1057,13 +944,6 @@ export type BankAccountCountOutputTypeCountBankAccountTransactionsArgs<ExtArgs e
where?: Prisma.BankAccountTransactionWhereInput
}
/**
* BankAccountCountOutputType without action
*/
export type BankAccountCountOutputTypeCountBankAccountBalancesArgs<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = {
where?: Prisma.BankAccountBalanceWhereInput
}
export type BankAccountSelect<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetSelect<{
id?: boolean
@@ -1079,7 +959,6 @@ export type BankAccountSelect<ExtArgs extends runtime.Types.Extensions.InternalA
inventoryBankAccounts?: boolean | Prisma.BankAccount$inventoryBankAccountsArgs<ExtArgs>
purchaseReceiptPayments?: boolean | Prisma.BankAccount$purchaseReceiptPaymentsArgs<ExtArgs>
bankAccountTransactions?: boolean | Prisma.BankAccount$bankAccountTransactionsArgs<ExtArgs>
bankAccountBalances?: boolean | Prisma.BankAccount$bankAccountBalancesArgs<ExtArgs>
_count?: boolean | Prisma.BankAccountCountOutputTypeDefaultArgs<ExtArgs>
}, ExtArgs["result"]["bankAccount"]>
@@ -1103,7 +982,6 @@ export type BankAccountInclude<ExtArgs extends runtime.Types.Extensions.Internal
inventoryBankAccounts?: boolean | Prisma.BankAccount$inventoryBankAccountsArgs<ExtArgs>
purchaseReceiptPayments?: boolean | Prisma.BankAccount$purchaseReceiptPaymentsArgs<ExtArgs>
bankAccountTransactions?: boolean | Prisma.BankAccount$bankAccountTransactionsArgs<ExtArgs>
bankAccountBalances?: boolean | Prisma.BankAccount$bankAccountBalancesArgs<ExtArgs>
_count?: boolean | Prisma.BankAccountCountOutputTypeDefaultArgs<ExtArgs>
}
@@ -1114,7 +992,6 @@ export type $BankAccountPayload<ExtArgs extends runtime.Types.Extensions.Interna
inventoryBankAccounts: Prisma.$InventoryBankAccountPayload<ExtArgs>[]
purchaseReceiptPayments: Prisma.$PurchaseReceiptPaymentsPayload<ExtArgs>[]
bankAccountTransactions: Prisma.$BankAccountTransactionPayload<ExtArgs>[]
bankAccountBalances: Prisma.$BankAccountBalancePayload<ExtArgs>[]
}
scalars: runtime.Types.Extensions.GetPayloadResult<{
id: number
@@ -1470,7 +1347,6 @@ export interface Prisma__BankAccountClient<T, Null = never, ExtArgs extends runt
inventoryBankAccounts<T extends Prisma.BankAccount$inventoryBankAccountsArgs<ExtArgs> = {}>(args?: Prisma.Subset<T, Prisma.BankAccount$inventoryBankAccountsArgs<ExtArgs>>): Prisma.PrismaPromise<runtime.Types.Result.GetResult<Prisma.$InventoryBankAccountPayload<ExtArgs>, T, "findMany", GlobalOmitOptions> | Null>
purchaseReceiptPayments<T extends Prisma.BankAccount$purchaseReceiptPaymentsArgs<ExtArgs> = {}>(args?: Prisma.Subset<T, Prisma.BankAccount$purchaseReceiptPaymentsArgs<ExtArgs>>): Prisma.PrismaPromise<runtime.Types.Result.GetResult<Prisma.$PurchaseReceiptPaymentsPayload<ExtArgs>, T, "findMany", GlobalOmitOptions> | Null>
bankAccountTransactions<T extends Prisma.BankAccount$bankAccountTransactionsArgs<ExtArgs> = {}>(args?: Prisma.Subset<T, Prisma.BankAccount$bankAccountTransactionsArgs<ExtArgs>>): Prisma.PrismaPromise<runtime.Types.Result.GetResult<Prisma.$BankAccountTransactionPayload<ExtArgs>, T, "findMany", GlobalOmitOptions> | Null>
bankAccountBalances<T extends Prisma.BankAccount$bankAccountBalancesArgs<ExtArgs> = {}>(args?: Prisma.Subset<T, Prisma.BankAccount$bankAccountBalancesArgs<ExtArgs>>): Prisma.PrismaPromise<runtime.Types.Result.GetResult<Prisma.$BankAccountBalancePayload<ExtArgs>, T, "findMany", GlobalOmitOptions> | Null>
/**
* Attaches callbacks for the resolution and/or rejection of the Promise.
* @param onfulfilled The callback to execute when the Promise is resolved.
@@ -1923,30 +1799,6 @@ export type BankAccount$bankAccountTransactionsArgs<ExtArgs extends runtime.Type
distinct?: Prisma.BankAccountTransactionScalarFieldEnum | Prisma.BankAccountTransactionScalarFieldEnum[]
}
/**
* BankAccount.bankAccountBalances
*/
export type BankAccount$bankAccountBalancesArgs<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = {
/**
* Select specific fields to fetch from the BankAccountBalance
*/
select?: Prisma.BankAccountBalanceSelect<ExtArgs> | null
/**
* Omit specific fields from the BankAccountBalance
*/
omit?: Prisma.BankAccountBalanceOmit<ExtArgs> | null
/**
* Choose, which related nodes to fetch as well
*/
include?: Prisma.BankAccountBalanceInclude<ExtArgs> | null
where?: Prisma.BankAccountBalanceWhereInput
orderBy?: Prisma.BankAccountBalanceOrderByWithRelationInput | Prisma.BankAccountBalanceOrderByWithRelationInput[]
cursor?: Prisma.BankAccountBalanceWhereUniqueInput
take?: number
skip?: number
distinct?: Prisma.BankAccountBalanceScalarFieldEnum | Prisma.BankAccountBalanceScalarFieldEnum[]
}
/**
* BankAccount without action
*/
File diff suppressed because it is too large Load Diff
@@ -31,4 +31,9 @@ export class BankAccountsController {
remove(@Param('id') id: string) {
return this.bankAccountsService.remove(Number(id))
}
@Get(':id/transactions')
getTransactions(@Param('id') id: string) {
return this.bankAccountsService.getTransactions(Number(id))
}
}
@@ -1,49 +1,61 @@
import { Injectable } from '@nestjs/common'
import { withTransaction } from '../../common/database/transaction.helper'
import { ResponseMapper } from '../../common/response/response-mapper'
import { BankTransactionRefType } from '../../generated/prisma/enums'
import { PrismaService } from '../../prisma/prisma.service'
@Injectable()
export class BankAccountsService {
constructor(private prisma: PrismaService) {}
async create(data: any) {
return withTransaction(this.prisma, async tx => {
const item = await tx.bankAccount.create({ data })
await tx.bankAccountBalance.create({
data: {
bankAccountId: item.id,
balance: 0,
},
})
return ResponseMapper.create(item)
})
}
async findAll() {
const items = await this.prisma.bankAccount.findMany({
include: {
branch: {
select: {
id: true,
name: true,
code: true,
bank: {
select: { id: true, name: true, shortName: true },
},
private readonly bankAccountQuery = {
include: {
branch: {
select: {
id: true,
name: true,
code: true,
bank: {
select: { id: true, name: true, shortName: true },
},
},
},
omit: {
branchId: true,
bankAccountTransactions: {
take: 1,
select: { id: true, createdAt: true, balanceAfter: true },
orderBy: { createdAt: 'desc' as const },
},
})
return ResponseMapper.list(items)
},
omit: {
branchId: true,
},
}
async create(data: any) {
const item = await this.prisma.bankAccount.create({ data })
return ResponseMapper.create(item)
}
async findAll() {
const items = await this.prisma.bankAccount.findMany(this.bankAccountQuery)
const mappedData = items.map(({ bankAccountTransactions, ...rest }) => ({
...rest,
currentBalance: Number(bankAccountTransactions[0]?.balanceAfter || 0),
}))
return ResponseMapper.list(mappedData)
}
async findOne(id: number) {
const item = await this.prisma.bankAccount.findUnique({ where: { id } })
if (!item) return null
return ResponseMapper.single(item)
const item = await this.prisma.bankAccount.findUniqueOrThrow({
...this.bankAccountQuery,
where: { id },
})
const { bankAccountTransactions, ...rest } = item
return ResponseMapper.single({
...rest,
currentBalance: Number(bankAccountTransactions[0]?.balanceAfter || 0),
})
}
async update(id: number, data: any) {
@@ -55,4 +67,87 @@ export class BankAccountsService {
const item = await this.prisma.bankAccount.delete({ where: { id } })
return ResponseMapper.single(item)
}
async getTransactions(bankAccountId: number, page = 1, pageSize = 50) {
const query = {
where: { bankAccountId },
orderBy: { createdAt: 'desc' as const },
skip: (page - 1) * pageSize,
take: pageSize,
}
const [items, count] = await this.prisma.$transaction([
this.prisma.bankAccountTransaction.findMany({
...query,
omit: { bankAccountId: true },
}),
this.prisma.bankAccountTransaction.count({ where: { bankAccountId } }),
])
const PosReferenceIds = [] as number[]
const purchaseReferenceIds = [] as number[]
items.forEach(({ referenceType, referenceId }) => {
if (referenceId && referenceType) {
if (
referenceType === BankTransactionRefType.POS_SALE ||
referenceType === BankTransactionRefType.POS_REFUND
) {
PosReferenceIds.push(referenceId)
} else if (
referenceType === BankTransactionRefType.PURCHASE_PAYMENT ||
referenceType === BankTransactionRefType.PURCHASE_REFUND
) {
purchaseReferenceIds.push(referenceId)
}
}
})
const posRecords = await this.prisma.salesInvoice.findMany({
where: { id: { in: PosReferenceIds } },
select: {
id: true,
code: true,
totalAmount: true,
posAccount: {
select: { id: true, name: true },
},
customer: {
select: { id: true, firstName: true, lastName: true },
},
},
})
const purchaseRecords = await this.prisma.purchaseReceipt.findMany({
where: { id: { in: purchaseReferenceIds } },
select: {
id: true,
code: true,
totalAmount: true,
supplier: {
select: { id: true, firstName: true, lastName: true },
},
},
})
const mappedItems = items.map(tx => {
let reference = null as any
if (tx.referenceId && tx.referenceType) {
if (
tx.referenceType === BankTransactionRefType.POS_SALE ||
tx.referenceType === BankTransactionRefType.POS_REFUND
) {
reference = posRecords.find(r => r.id === tx.referenceId) || null
} else if (
tx.referenceType === BankTransactionRefType.PURCHASE_PAYMENT ||
tx.referenceType === BankTransactionRefType.PURCHASE_REFUND
) {
reference = purchaseRecords.find(r => r.id === tx.referenceId) || null
}
}
return { ...tx, reference }
})
return ResponseMapper.paginate(mappedItems, count, page, pageSize)
}
}
@@ -8,13 +8,13 @@ export class BankAccountsWorkflow {
tx: Prisma.TransactionClient,
payload: AddTransactionToBankAccountDto,
) {
const item = await tx.bankAccountBalance.findUnique({
const item = await tx.bankAccountTransaction.findFirst({
where: {
bankAccountId: payload.bankAccountId,
},
})
const balance = item ? Number(item.balance) : 0
const balance = item ? Number(item?.balanceAfter) : 0
const newBalance = item
? payload.type === 'DEPOSIT'
@@ -35,31 +35,5 @@ export class BankAccountsWorkflow {
referenceType: payload.referenceType,
},
})
console.log('first')
const bankAccountBalanceItem = await tx.bankAccountBalance.findUnique({
where: {
bankAccountId: payload.bankAccountId,
},
})
if (!bankAccountBalanceItem) {
return await tx.bankAccountBalance.create({
data: {
bankAccount: { connect: { id: payload.bankAccountId } },
balance: newBalance,
},
})
}
return await tx.bankAccountBalance.update({
where: {
bankAccountId: payload.bankAccountId,
},
data: {
balance: newBalance,
},
})
}
}
@@ -89,7 +89,6 @@ export class InventoriesService {
},
})
let info = null as any
console.log(movements)
const mapped = movements.map(movement => {
const { id, quantity, unitPrice, totalCost, avgCost, product } = movement