fix: rollback jurnal
This commit is contained in:
parent
4befb8d9fd
commit
c2b4b5ec30
|
@ -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')
|
@Get('resend-partner/success/:code')
|
||||||
async resendSuccess(@Request() req, @Param('code') code: string) {
|
async resendSuccess(@Request() req, @Param('code') code: string) {
|
||||||
const data = await this.transactionService.resendOrderToPartner(code, true);
|
const data = await this.transactionService.resendOrderToPartner(code, true);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data,
|
data,
|
||||||
statusCode: HttpStatus.OK,
|
statusCode: HttpStatus.OK,
|
||||||
|
|
|
@ -1302,6 +1302,52 @@ export class TransactionService {
|
||||||
return res;
|
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) {
|
async withdrawBenefit(user) {
|
||||||
const userData = await this.userService.findExist(user);
|
const userData = await this.userService.findExist(user);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user