fix: rollback jurnal

This commit is contained in:
ilham 2022-06-28 14:58:05 +07:00
parent 4befb8d9fd
commit c2b4b5ec30
2 changed files with 56 additions and 1 deletions

View File

@ -132,10 +132,19 @@ export class TransactionController {
};
}
@Get('rollback-jurnal/:trxId')
async rollbackJurnal(@Request() req, @Param('trxId') trxId: string) {
const data = await this.transactionService.rollbackJurnal(trxId);
return {
data,
statusCode: HttpStatus.OK,
message: 'success',
};
}
@Get('resend-partner/success/:code')
async resendSuccess(@Request() req, @Param('code') code: string) {
const data = await this.transactionService.resendOrderToPartner(code, true);
return {
data,
statusCode: HttpStatus.OK,

View File

@ -1302,6 +1302,52 @@ export class TransactionService {
return res;
}
async rollbackJurnal(trxId: string) {
const dataTransaction = await this.transactionRepository.findOne({
where: {
id: trxId,
},
relations: ['product_price'],
});
const dataTransactionJurnal = await this.transactionJournalRepository.find({
where: {
transaction_head: trxId,
},
relations: ['coa'],
});
let dataRollbackJurnal = [];
dataTransactionJurnal.map((it) => {
let data = {
coa_id: it.coa.id,
};
if (it.type == 0) {
data['credit'] = it.amount;
} else {
data['debit'] = it.amount;
}
dataRollbackJurnal.push(data);
});
try {
await this.connection.transaction(async (manager) => {
await this.accountingTransaction({
createTransaction: false,
transactionalEntityManager: manager,
transaction: dataTransaction,
amount: dataTransaction.amount,
journals: dataRollbackJurnal,
});
});
} catch (e) {
throw e;
}
}
async withdrawBenefit(user) {
const userData = await this.userService.findExist(user);