fix: recap transaction
parent
07d2ec3b46
commit
3eee8d73f4
|
@ -4,9 +4,8 @@ import { EventTopics } from 'src/core/strings/constants/interface.constants';
|
|||
import { TransactionType } from 'src/modules/transaction/transaction/constants';
|
||||
import { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model';
|
||||
import { TransactionEntity } from 'src/modules/transaction/transaction/domain/entities/transaction.entity';
|
||||
import { Between, IsNull, MoreThan, Not } from 'typeorm';
|
||||
import { Brackets, DeleteQueryBuilder, IsNull, MoreThan, Not } from 'typeorm';
|
||||
import * as _ from 'lodash';
|
||||
import * as moment from 'moment';
|
||||
import { EMPTY_UUID, STATUS } from 'src/core/strings/constants/base.constants';
|
||||
import { RecapReconciliationDto } from '../../../infrastructure/dto/recap.dto';
|
||||
|
||||
|
@ -58,11 +57,11 @@ export class RecapReconciliationManager extends BaseCustomManager<TransactionEnt
|
|||
} = transaction;
|
||||
const group_by =
|
||||
creator_counter_no +
|
||||
'-' +
|
||||
'|' +
|
||||
payment_type_counter +
|
||||
'-' +
|
||||
'|' +
|
||||
payment_type_method_id +
|
||||
'_' +
|
||||
'|' +
|
||||
payment_date;
|
||||
|
||||
if (!this.recapTransactions[group_by]) {
|
||||
|
@ -77,6 +76,38 @@ export class RecapReconciliationManager extends BaseCustomManager<TransactionEnt
|
|||
async process(): Promise<void> {
|
||||
const total_recap = Object.keys(this.recapTransactions);
|
||||
|
||||
const deleteQuery: DeleteQueryBuilder<TransactionEntity> = this.dataService
|
||||
.getRepository()
|
||||
.createQueryBuilder(this.tableName)
|
||||
.delete();
|
||||
deleteQuery.where(
|
||||
`payment_date = :payment_date and is_recap_transaction = true`,
|
||||
{
|
||||
payment_date: this.paymentDate,
|
||||
},
|
||||
);
|
||||
deleteQuery.andWhere(
|
||||
new Brackets((qb) => {
|
||||
for (const condition of total_recap) {
|
||||
const [
|
||||
creator_counter_no,
|
||||
payment_type_counter,
|
||||
payment_type_method_id,
|
||||
] = condition.split('|');
|
||||
|
||||
const whereMethodId =
|
||||
payment_type_method_id == 'null'
|
||||
? 'IS NULL'
|
||||
: `= '${payment_type_method_id}'`;
|
||||
qb.andWhere(
|
||||
`NOT (creator_counter_no = '${creator_counter_no}' AND payment_type_counter = '${payment_type_counter}' AND payment_type_method_id ${whereMethodId})`,
|
||||
);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
await deleteQuery.execute();
|
||||
|
||||
for (const recap of total_recap) {
|
||||
const first_transaction = this.recapTransactions[recap][0];
|
||||
|
||||
|
|
|
@ -126,6 +126,9 @@ export class PriceCalculator {
|
|||
let result = null;
|
||||
|
||||
try {
|
||||
if (!formula) {
|
||||
break;
|
||||
}
|
||||
result = math.evaluate(formula.formula_string, values);
|
||||
calledVariable = [];
|
||||
} catch (error) {
|
||||
|
|
|
@ -191,7 +191,7 @@ export function mappingRevertTransaction(data, type) {
|
|||
|
||||
const bundlingTotalPrice =
|
||||
(item.item?.bundling_items?.reduce(
|
||||
(a, b) => a + Number(b.item_rates ?? b.base_price),
|
||||
(a, b) => a + Number(b.item_rates || b.base_price),
|
||||
0,
|
||||
) ?? 0) * +item.qty;
|
||||
const totalAndBundlingRatio = total_price / bundlingTotalPrice;
|
||||
|
@ -199,7 +199,7 @@ export function mappingRevertTransaction(data, type) {
|
|||
if (bundling.total_net_price) return bundling;
|
||||
|
||||
const basePrice =
|
||||
(bundling.item_rates ?? bundling.base_price) *
|
||||
(bundling.item_rates || bundling.base_price) *
|
||||
+item.qty *
|
||||
totalAndBundlingRatio;
|
||||
const discount = discountPercent * basePrice;
|
||||
|
|
Loading…
Reference in New Issue