diff --git a/src/transaction/transaction.service.ts b/src/transaction/transaction.service.ts index 5204d80..1d6ae06 100644 --- a/src/transaction/transaction.service.ts +++ b/src/transaction/transaction.service.ts @@ -144,6 +144,21 @@ export class TransactionService { } // GET COA + const coaBudget = await this.coaService.findByName( + `${coaType[coaType.BUDGET]}-${supplier.code}`, + ); + if (coaBudget.amount < distributeTransactionDto.amount) { + throw new HttpException( + { + statusCode: HttpStatus.INTERNAL_SERVER_ERROR, + error: `Transaction Failed because saldo not enough`, + }, + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const coaContraBudget = await this.coaService.findByName( + `${coaType[coaType.CONTRA_BUDGET]}-${supplier.code}`, + ); const coaAR = await this.coaService.findByTwoUser( distributeTransactionDto.destination, currentUser.userId, @@ -153,13 +168,6 @@ export class TransactionService { distributeTransactionDto.destination, coaType.WALLET, ); - const coaBudget = await this.coaService.findByName( - `${coaType[coaType.BUDGET]}-${supplier.code}`, - ); - - const coaContraBudget = await this.coaService.findByName( - `${coaType[coaType.CONTRA_BUDGET]}-${supplier.code}`, - ); await this.connection.transaction(async (manager) => { //INSERT TRANSACTION @@ -238,6 +246,16 @@ export class TransactionService { coaType.ACCOUNT_RECEIVABLE, ); + if (coaSenderWallet.amount < distributeTransactionDto.amount) { + throw new HttpException( + { + statusCode: HttpStatus.INTERNAL_SERVER_ERROR, + error: `Transaction Failed because saldo not enough`, + }, + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + await this.connection.transaction(async (manager) => { const transactionData = new Transactions();