fix: rollback jurnal

This commit is contained in:
ilham 2022-06-28 15:14:51 +07:00
parent c2b4b5ec30
commit 953161c4b2

View File

@ -1310,12 +1310,26 @@ export class TransactionService {
relations: ['product_price'],
});
const dataTransactionJurnal = await this.transactionJournalRepository.find({
where: {
transaction_head: trxId,
},
relations: ['coa'],
});
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 = [];
@ -1333,18 +1347,20 @@ export class TransactionService {
dataRollbackJurnal.push(data);
});
try {
await this.connection.transaction(async (manager) => {
await this.accountingTransaction({
createTransaction: false,
transactionalEntityManager: manager,
transaction: dataTransaction,
amount: dataTransaction.amount,
journals: dataRollbackJurnal,
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;
} catch (e) {
throw e;
}
}
}