fix(SPG-709) Data summary transaksi PoS tidak muncul di halaman rekonsiliasi setelah click button recap
parent
19386c336e
commit
e8deba2882
|
@ -48,6 +48,7 @@ export class IndexReconciliationManager extends BaseIndexManager<TransactionEnti
|
|||
`${this.tableName}.customer_name`,
|
||||
`${this.tableName}.creator_counter_no`,
|
||||
|
||||
`${this.tableName}.booking_date`,
|
||||
`${this.tableName}.payment_type`,
|
||||
`${this.tableName}.payment_type_method_id`,
|
||||
`${this.tableName}.payment_type_method_name`,
|
||||
|
|
|
@ -4,23 +4,23 @@ 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 } from 'typeorm';
|
||||
import { Between, ILike } from 'typeorm';
|
||||
import * as _ from 'lodash';
|
||||
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()
|
||||
export class RecapReconciliationManager extends BaseCustomManager<TransactionEntity> {
|
||||
private recapTransactions = {};
|
||||
private startOfDay = moment().startOf('day').unix();
|
||||
private endOfDay = moment().endOf('day').unix();
|
||||
private startOfDay = moment().startOf('day').valueOf();
|
||||
private endOfDay = moment().endOf('day').valueOf();
|
||||
|
||||
get entityTarget(): any {
|
||||
return TransactionModel;
|
||||
}
|
||||
|
||||
getResult() {
|
||||
return;
|
||||
return 'Berhasil recap data transaksi';
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
|
@ -36,22 +36,26 @@ export class RecapReconciliationManager extends BaseCustomManager<TransactionEnt
|
|||
where: {
|
||||
is_recap_transaction: false,
|
||||
type: TransactionType.COUNTER,
|
||||
status: STATUS.SETTLED,
|
||||
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) {
|
||||
const {
|
||||
creator_counter_no,
|
||||
payment_type_method_name,
|
||||
payment_type_method_number,
|
||||
} = transaction;
|
||||
const { creator_counter_no, payment_type, payment_type_method_id } =
|
||||
transaction;
|
||||
const group_by =
|
||||
creator_counter_no +
|
||||
'-' +
|
||||
payment_type_method_name +
|
||||
'-' +
|
||||
payment_type_method_number;
|
||||
creator_counter_no + '-' + payment_type + '-' + payment_type_method_id;
|
||||
if (!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);
|
||||
for (const recap of total_recap) {
|
||||
const first_transaction = this.recapTransactions[recap][0];
|
||||
const {
|
||||
creator_counter_no,
|
||||
payment_type_method_number,
|
||||
payment_type_method_name,
|
||||
} = first_transaction;
|
||||
const { creator_counter_no, payment_type, payment_type_method_id } =
|
||||
first_transaction;
|
||||
|
||||
const exist = await this.dataService.getOneByOptions({
|
||||
where: {
|
||||
is_recap_transaction: true,
|
||||
created_at: Between(this.startOfDay, this.endOfDay),
|
||||
creator_counter_no: creator_counter_no,
|
||||
payment_type_method_number: payment_type_method_number,
|
||||
payment_type_method_name: payment_type_method_name,
|
||||
payment_type: payment_type,
|
||||
payment_type_method_id: payment_type_method_id ?? EMPTY_UUID,
|
||||
},
|
||||
});
|
||||
|
||||
const new_recap = new TransactionModel();
|
||||
const total = _.sumBy(this.recapTransactions[recap], (recap) =>
|
||||
parseFloat(recap.payment_total),
|
||||
);
|
||||
|
||||
if (exist) {
|
||||
Object.assign(exist, {
|
||||
payment_total: _.sumBy(this.recapTransactions[recap], (recap) =>
|
||||
parseFloat(recap.payment_total),
|
||||
),
|
||||
payment_total_net_profit: _.sumBy(
|
||||
this.recapTransactions[recap],
|
||||
(recap) => parseFloat(recap.payment_total),
|
||||
),
|
||||
payment_total: Number(exist.payment_total) + total,
|
||||
payment_total_net_profit:
|
||||
Number(exist.payment_total_net_profit) + total,
|
||||
editor_id: this.user.id,
|
||||
editor_name: this.user.name,
|
||||
updated_at: new Date().getTime(),
|
||||
|
@ -98,17 +99,13 @@ export class RecapReconciliationManager extends BaseCustomManager<TransactionEnt
|
|||
} else {
|
||||
Object.assign(new_recap, {
|
||||
is_recap_transaction: true,
|
||||
payment_total: _.sumBy(this.recapTransactions[recap], (recap) =>
|
||||
parseFloat(recap.payment_total),
|
||||
),
|
||||
payment_total_net_profit: _.sumBy(
|
||||
this.recapTransactions[recap],
|
||||
(recap) => parseFloat(recap.payment_total),
|
||||
),
|
||||
payment_total: total,
|
||||
payment_total_net_profit: total,
|
||||
reconciliation_status: STATUS.PENDING,
|
||||
status: STATUS.SETTLED,
|
||||
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,
|
||||
payment_type: first_transaction.payment_type,
|
||||
payment_type_method_id: first_transaction.payment_type_method_id,
|
||||
|
|
Loading…
Reference in New Issue