pos-be/src/modules/transaction/reconciliation/domain/usecases/managers/index-reconciliation.manage...

160 lines
4.4 KiB
TypeScript

import { Injectable } from '@nestjs/common';
import { BaseIndexManager } from 'src/core/modules/domain/usecase/managers/base-index.manager';
import { SelectQueryBuilder } from 'typeorm';
import {
Param,
RelationParam,
} from 'src/core/modules/domain/entities/base-filter.entity';
import { TransactionEntity } from 'src/modules/transaction/transaction/domain/entities/transaction.entity';
import { BetweenQueryHelper } from 'src/core/helpers/query/between-query.helper';
import { STATUS } from 'src/core/strings/constants/base.constants';
@Injectable()
export class IndexReconciliationManager extends BaseIndexManager<TransactionEntity> {
async prepareData(): Promise<void> {
return;
}
async beforeProcess(): Promise<void> {
return;
}
async afterProcess(): Promise<void> {
return;
}
get relations(): RelationParam {
return {
// relation only join (for query purpose)
joinRelations: [],
// relation join and select (relasi yang ingin ditampilkan),
selectRelations: [],
// relation yang hanya ingin dihitung (akan return number)
countRelations: [],
};
}
get selects(): string[] {
return [
`${this.tableName}.id`,
`${this.tableName}.type`,
`${this.tableName}.reconciliation_status`,
`${this.tableName}.reconciliation_mdr`,
`${this.tableName}.reconciliation_confirm_date`,
`${this.tableName}.reconciliation_confirm_by`,
`${this.tableName}.customer_name`,
`${this.tableName}.creator_counter_no`,
`${this.tableName}.invoice_code`,
`${this.tableName}.booking_date`,
`${this.tableName}.payment_type`,
`${this.tableName}.payment_type_method_id`,
`${this.tableName}.payment_type_method_name`,
`${this.tableName}.payment_type_method_number`,
`${this.tableName}.payment_code_reference`,
`${this.tableName}.payment_code`,
`${this.tableName}.payment_date`,
`${this.tableName}.payment_total`,
`${this.tableName}.payment_total_net_profit`,
];
}
get specificFilter(): Param[] {
return [
{
cols: `${this.tableName}.customer_name`,
data: this.filterParam.customer_names,
},
{
cols: `${this.tableName}.reconciliation_confirm_by`,
data: this.filterParam.confirm_by_names,
},
{
cols: `${this.tableName}.payment_type_method_name`,
data: this.filterParam.payment_banks,
},
{
cols: `${this.tableName}.payment_type_method_number`,
data: this.filterParam.payment_bank_numbers,
},
];
}
setQueryFilter(
queryBuilder: SelectQueryBuilder<TransactionEntity>,
): SelectQueryBuilder<TransactionEntity> {
if (this.filterParam.payment_date_from) {
new BetweenQueryHelper(
queryBuilder,
this.tableName,
'payment_date',
this.filterParam.payment_date_from,
this.filterParam.payment_date_to,
'payment_created',
).getQuery();
}
if (this.filterParam.transaction_type) {
queryBuilder.andWhere(`${this.tableName}.type In (:...types)`, {
types: [this.filterParam.transaction_type],
});
}
if (this.filterParam.couner_no) {
queryBuilder.andWhere(
`${this.tableName}.creator_counter_no In (:...counters)`,
{
counters: [this.filterParam.couner_no],
},
);
}
if (this.filterParam.payment_type) {
queryBuilder.andWhere(
`${this.tableName}.creator_counter_no In (:...counters)`,
{
counters: [this.filterParam.couner_no],
},
);
}
if (this.filterParam.payment_via) {
queryBuilder.andWhere(`${this.tableName}.payment_type In (:...type)`, {
type: [this.filterParam.payment_via],
});
}
if (this.filterParam.payment_bank) {
queryBuilder.andWhere(
`${this.tableName}.payment_type_method_name In (:...banks)`,
{
banks: [this.filterParam.payment_bank],
},
);
}
if (this.filterParam.confirmation_date_from) {
new BetweenQueryHelper(
queryBuilder,
this.tableName,
'payment_date',
this.filterParam.confirmation_date_from,
this.filterParam.confirmation_date_to,
'payment_created',
).getQuery();
}
queryBuilder.andWhere(
`${this.tableName}.reconciliation_status Not In (:...statuses)`,
{
statuses: [STATUS.DRAFT],
},
);
return queryBuilder;
}
}