Merge branch 'development' into 'devops-staging'

Development

See merge request empatnusabangsa/ppob/ppob-backend!186
This commit is contained in:
ilham dwi pratama 2022-06-28 08:40:57 +00:00
commit 62cc5bdb15
2 changed files with 74 additions and 2 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

@ -1180,7 +1180,8 @@ export class TransactionService {
const coaExpense = await this.coaService.findByName(
`${coaType[coaType.EXPENSE]}-SYSTEM`,
);
if (userData.partner != null) {
if (userData.partner == null) {
//GET SALES
supervisorData = await this.calculateCommission(
supervisorData,
@ -1302,6 +1303,68 @@ export class TransactionService {
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) {
const userData = await this.userService.findExist(user);