add: add validation if saldo not enough
This commit is contained in:
parent
6c24f6784d
commit
691035c394
|
@ -144,6 +144,21 @@ export class TransactionService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET COA
|
// 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(
|
const coaAR = await this.coaService.findByTwoUser(
|
||||||
distributeTransactionDto.destination,
|
distributeTransactionDto.destination,
|
||||||
currentUser.userId,
|
currentUser.userId,
|
||||||
|
@ -153,13 +168,6 @@ export class TransactionService {
|
||||||
distributeTransactionDto.destination,
|
distributeTransactionDto.destination,
|
||||||
coaType.WALLET,
|
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) => {
|
await this.connection.transaction(async (manager) => {
|
||||||
//INSERT TRANSACTION
|
//INSERT TRANSACTION
|
||||||
|
@ -238,6 +246,16 @@ export class TransactionService {
|
||||||
coaType.ACCOUNT_RECEIVABLE,
|
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) => {
|
await this.connection.transaction(async (manager) => {
|
||||||
const transactionData = new Transactions();
|
const transactionData = new Transactions();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user