fix(SPG-709) Data summary transaksi PoS tidak muncul di halaman rekonsiliasi setelah click button recap

pull/45/head
Aswin Ashar Abdullah 2024-07-31 17:58:33 +07:00
parent 19386c336e
commit e8deba2882
2 changed files with 35 additions and 37 deletions

View File

@ -48,6 +48,7 @@ export class IndexReconciliationManager extends BaseIndexManager<TransactionEnti
`${this.tableName}.customer_name`, `${this.tableName}.customer_name`,
`${this.tableName}.creator_counter_no`, `${this.tableName}.creator_counter_no`,
`${this.tableName}.booking_date`,
`${this.tableName}.payment_type`, `${this.tableName}.payment_type`,
`${this.tableName}.payment_type_method_id`, `${this.tableName}.payment_type_method_id`,
`${this.tableName}.payment_type_method_name`, `${this.tableName}.payment_type_method_name`,

View File

@ -4,23 +4,23 @@ 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 } from 'typeorm'; import { Between, ILike } from 'typeorm';
import * as _ from 'lodash'; import * as _ from 'lodash';
import * as moment from 'moment'; import * as moment from 'moment';
import { STATUS } from 'src/core/strings/constants/base.constants'; import { EMPTY_UUID, STATUS } from 'src/core/strings/constants/base.constants';
@Injectable() @Injectable()
export class RecapReconciliationManager extends BaseCustomManager<TransactionEntity> { export class RecapReconciliationManager extends BaseCustomManager<TransactionEntity> {
private recapTransactions = {}; private recapTransactions = {};
private startOfDay = moment().startOf('day').unix(); private startOfDay = moment().startOf('day').valueOf();
private endOfDay = moment().endOf('day').unix(); private endOfDay = moment().endOf('day').valueOf();
get entityTarget(): any { get entityTarget(): any {
return TransactionModel; return TransactionModel;
} }
getResult() { getResult() {
return; return 'Berhasil recap data transaksi';
} }
get eventTopics(): EventTopics[] { get eventTopics(): EventTopics[] {
@ -36,22 +36,26 @@ export class RecapReconciliationManager extends BaseCustomManager<TransactionEnt
where: { where: {
is_recap_transaction: false, is_recap_transaction: false,
type: TransactionType.COUNTER, type: TransactionType.COUNTER,
status: STATUS.SETTLED,
created_at: Between(this.startOfDay, this.endOfDay), created_at: Between(this.startOfDay, this.endOfDay),
}, },
}); });
const payCounserTransactions = await this.dataService.getManyByOptions({
where: {
is_recap_transaction: false,
payment_code: ILike('%SLS%'),
status: STATUS.SETTLED,
created_at: Between(this.startOfDay, this.endOfDay),
},
});
transactions.push(...payCounserTransactions);
for (const transaction of transactions) { for (const transaction of transactions) {
const { const { creator_counter_no, payment_type, payment_type_method_id } =
creator_counter_no, transaction;
payment_type_method_name,
payment_type_method_number,
} = transaction;
const group_by = const group_by =
creator_counter_no + creator_counter_no + '-' + payment_type + '-' + payment_type_method_id;
'-' +
payment_type_method_name +
'-' +
payment_type_method_number;
if (!this.recapTransactions[group_by]) { if (!this.recapTransactions[group_by]) {
this.recapTransactions[group_by] = []; this.recapTransactions[group_by] = [];
} }
@ -65,32 +69,29 @@ export class RecapReconciliationManager extends BaseCustomManager<TransactionEnt
const total_recap = Object.keys(this.recapTransactions); const total_recap = Object.keys(this.recapTransactions);
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];
const { const { creator_counter_no, payment_type, payment_type_method_id } =
creator_counter_no, first_transaction;
payment_type_method_number,
payment_type_method_name,
} = first_transaction;
const exist = await this.dataService.getOneByOptions({ const exist = await this.dataService.getOneByOptions({
where: { where: {
is_recap_transaction: true, is_recap_transaction: true,
created_at: Between(this.startOfDay, this.endOfDay), created_at: Between(this.startOfDay, this.endOfDay),
creator_counter_no: creator_counter_no, creator_counter_no: creator_counter_no,
payment_type_method_number: payment_type_method_number, payment_type: payment_type,
payment_type_method_name: payment_type_method_name, payment_type_method_id: payment_type_method_id ?? EMPTY_UUID,
}, },
}); });
const new_recap = new TransactionModel(); const new_recap = new TransactionModel();
const total = _.sumBy(this.recapTransactions[recap], (recap) =>
parseFloat(recap.payment_total),
);
if (exist) { if (exist) {
Object.assign(exist, { Object.assign(exist, {
payment_total: _.sumBy(this.recapTransactions[recap], (recap) => payment_total: Number(exist.payment_total) + total,
parseFloat(recap.payment_total), payment_total_net_profit:
), Number(exist.payment_total_net_profit) + total,
payment_total_net_profit: _.sumBy(
this.recapTransactions[recap],
(recap) => parseFloat(recap.payment_total),
),
editor_id: this.user.id, editor_id: this.user.id,
editor_name: this.user.name, editor_name: this.user.name,
updated_at: new Date().getTime(), updated_at: new Date().getTime(),
@ -98,17 +99,13 @@ export class RecapReconciliationManager extends BaseCustomManager<TransactionEnt
} else { } else {
Object.assign(new_recap, { Object.assign(new_recap, {
is_recap_transaction: true, is_recap_transaction: true,
payment_total: _.sumBy(this.recapTransactions[recap], (recap) => payment_total: total,
parseFloat(recap.payment_total), payment_total_net_profit: total,
),
payment_total_net_profit: _.sumBy(
this.recapTransactions[recap],
(recap) => parseFloat(recap.payment_total),
),
reconciliation_status: STATUS.PENDING, reconciliation_status: STATUS.PENDING,
status: STATUS.SETTLED, status: STATUS.SETTLED,
type: TransactionType.COUNTER, type: TransactionType.COUNTER,
booking_date: first_transaction.booking_date, booking_date: new Date(),
payment_date: new Date(),
creator_counter_no: first_transaction.creator_counter_no, creator_counter_no: first_transaction.creator_counter_no,
payment_type: first_transaction.payment_type, payment_type: first_transaction.payment_type,
payment_type_method_id: first_transaction.payment_type_method_id, payment_type_method_id: first_transaction.payment_type_method_id,