Merge branch 'development' into 'master'

Development

See merge request empatnusabangsa/ppob/ppob-backend!185
This commit is contained in:
ilham dwi pratama 2022-06-28 08:16:49 +00:00
commit 2596c6fb1b
2 changed files with 72 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') @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,

View File

@ -1302,6 +1302,68 @@ export class TransactionService {
return res; return res;
} }
async rollbackJurnal(trxId: string) {
const dataTransaction = await this.transactionRepository.findOne({
where: {
id: trxId,
},
relations: ['product_price'],
});
let dataTransactionJurnal;
if (dataTransaction.type == typeTransaction.ORDER) {
dataTransactionJurnal = await this.transactionJournalRepository.find({
where: {
transaction_head: trxId,
},
relations: ['coa'],
skip: 4,
order: {
createdAt: 'ASC',
},
});
} else {
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);
});
if (dataRollbackJurnal.length > 0) {
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);