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 { TransactionType } from 'src/modules/transaction/transaction/constants';
|
||||||
import { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model';
|
import { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model';
|
||||||
import { TransactionEntity } from 'src/modules/transaction/transaction/domain/entities/transaction.entity';
|
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 _ from 'lodash';
|
||||||
import * as moment from 'moment';
|
|
||||||
import { EMPTY_UUID, STATUS } from 'src/core/strings/constants/base.constants';
|
import { EMPTY_UUID, STATUS } from 'src/core/strings/constants/base.constants';
|
||||||
import { RecapReconciliationDto } from '../../../infrastructure/dto/recap.dto';
|
import { RecapReconciliationDto } from '../../../infrastructure/dto/recap.dto';
|
||||||
|
|
||||||
|
@ -58,11 +57,11 @@ export class RecapReconciliationManager extends BaseCustomManager<TransactionEnt
|
||||||
} = transaction;
|
} = transaction;
|
||||||
const group_by =
|
const group_by =
|
||||||
creator_counter_no +
|
creator_counter_no +
|
||||||
'-' +
|
'|' +
|
||||||
payment_type_counter +
|
payment_type_counter +
|
||||||
'-' +
|
'|' +
|
||||||
payment_type_method_id +
|
payment_type_method_id +
|
||||||
'_' +
|
'|' +
|
||||||
payment_date;
|
payment_date;
|
||||||
|
|
||||||
if (!this.recapTransactions[group_by]) {
|
if (!this.recapTransactions[group_by]) {
|
||||||
|
@ -77,6 +76,38 @@ export class RecapReconciliationManager extends BaseCustomManager<TransactionEnt
|
||||||
async process(): Promise<void> {
|
async process(): Promise<void> {
|
||||||
const total_recap = Object.keys(this.recapTransactions);
|
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) {
|
for (const recap of total_recap) {
|
||||||
const first_transaction = this.recapTransactions[recap][0];
|
const first_transaction = this.recapTransactions[recap][0];
|
||||||
|
|
||||||
|
|
|
@ -126,6 +126,9 @@ export class PriceCalculator {
|
||||||
let result = null;
|
let result = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (!formula) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
result = math.evaluate(formula.formula_string, values);
|
result = math.evaluate(formula.formula_string, values);
|
||||||
calledVariable = [];
|
calledVariable = [];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -191,7 +191,7 @@ export function mappingRevertTransaction(data, type) {
|
||||||
|
|
||||||
const bundlingTotalPrice =
|
const bundlingTotalPrice =
|
||||||
(item.item?.bundling_items?.reduce(
|
(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,
|
||||||
) ?? 0) * +item.qty;
|
) ?? 0) * +item.qty;
|
||||||
const totalAndBundlingRatio = total_price / bundlingTotalPrice;
|
const totalAndBundlingRatio = total_price / bundlingTotalPrice;
|
||||||
|
@ -199,7 +199,7 @@ export function mappingRevertTransaction(data, type) {
|
||||||
if (bundling.total_net_price) return bundling;
|
if (bundling.total_net_price) return bundling;
|
||||||
|
|
||||||
const basePrice =
|
const basePrice =
|
||||||
(bundling.item_rates ?? bundling.base_price) *
|
(bundling.item_rates || bundling.base_price) *
|
||||||
+item.qty *
|
+item.qty *
|
||||||
totalAndBundlingRatio;
|
totalAndBundlingRatio;
|
||||||
const discount = discountPercent * basePrice;
|
const discount = discountPercent * basePrice;
|
||||||
|
|
Loading…
Reference in New Issue