fix: transaction partner
This commit is contained in:
parent
1bfd132a2e
commit
18525e6b41
|
@ -319,25 +319,8 @@ export class TransactionService {
|
|||
);
|
||||
|
||||
let supervisorData = [];
|
||||
|
||||
let profit = product_price.mark_up_price;
|
||||
|
||||
if (!userData.partner) {
|
||||
//GET SALES
|
||||
supervisorData = await this.calculateCommission(
|
||||
supervisorData,
|
||||
profit,
|
||||
userData,
|
||||
);
|
||||
profit = supervisorData
|
||||
.map((item) => {
|
||||
return item.credit;
|
||||
})
|
||||
.reduce((prev, curr) => {
|
||||
return prev + curr;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
//GET COA
|
||||
const coaAccount = await this.coaService.findByUser(
|
||||
userData.id,
|
||||
|
@ -360,6 +343,29 @@ export class TransactionService {
|
|||
`${coaType[coaType.EXPENSE]}-SYSTEM`,
|
||||
);
|
||||
|
||||
if (!userData.partner) {
|
||||
//GET SALES
|
||||
supervisorData = await this.calculateCommission(
|
||||
supervisorData,
|
||||
profit,
|
||||
userData,
|
||||
);
|
||||
profit = supervisorData
|
||||
.map((item) => {
|
||||
return item.credit;
|
||||
})
|
||||
.reduce((prev, curr) => {
|
||||
return prev + curr;
|
||||
}, 0);
|
||||
|
||||
supervisorData = supervisorData.concat([
|
||||
{
|
||||
coa_id: coaExpense.id,
|
||||
debit: profit,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
if (coaAccount.amount <= product.price) {
|
||||
throw new HttpException(
|
||||
{
|
||||
|
@ -406,10 +412,6 @@ export class TransactionService {
|
|||
coa_id: coaSales.id,
|
||||
credit: product_price.mark_up_price + product_price.price,
|
||||
},
|
||||
{
|
||||
coa_id: coaExpense.id,
|
||||
debit: userData.partner ? 0 : profit,
|
||||
},
|
||||
].concat(supervisorData),
|
||||
});
|
||||
});
|
||||
|
@ -678,22 +680,6 @@ export class TransactionService {
|
|||
|
||||
let profit = product_price.mark_up_price;
|
||||
|
||||
if (!userData.partner) {
|
||||
//GET SALES
|
||||
supervisorData = await this.calculateCommission(
|
||||
supervisorData,
|
||||
profit,
|
||||
userData,
|
||||
);
|
||||
profit = supervisorData
|
||||
.map((item) => {
|
||||
return item.credit;
|
||||
})
|
||||
.reduce((prev, curr) => {
|
||||
return prev + curr;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
//GET COA
|
||||
const coaAccount = await this.coaService.findByUser(
|
||||
userData.id,
|
||||
|
@ -716,6 +702,29 @@ export class TransactionService {
|
|||
`${coaType[coaType.EXPENSE]}-SYSTEM`,
|
||||
);
|
||||
|
||||
if (!userData.partner) {
|
||||
//GET SALES
|
||||
supervisorData = await this.calculateCommission(
|
||||
supervisorData,
|
||||
profit,
|
||||
userData,
|
||||
);
|
||||
profit = supervisorData
|
||||
.map((item) => {
|
||||
return item.credit;
|
||||
})
|
||||
.reduce((prev, curr) => {
|
||||
return prev + curr;
|
||||
}, 0);
|
||||
|
||||
supervisorData = supervisorData.concat([
|
||||
{
|
||||
coa_id: coaExpense.id,
|
||||
debit: profit,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
try {
|
||||
await this.connection.transaction(async (manager) => {
|
||||
await manager.save(dataTransaction);
|
||||
|
@ -742,10 +751,6 @@ export class TransactionService {
|
|||
coa_id: coaSales.id,
|
||||
credit: product_price.mark_up_price + product_price.price,
|
||||
},
|
||||
{
|
||||
coa_id: coaExpense.id,
|
||||
debit: userData.partner ? 0 : profit,
|
||||
},
|
||||
].concat(supervisorData),
|
||||
});
|
||||
});
|
||||
|
@ -1119,3 +1124,4 @@ export class TransactionService {
|
|||
return transaction;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user