feat: open guard cancel recap recon and add new logic for recap recon cancel handler and change logic recap handler
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
539676aa30
commit
3720df31d8
|
@ -43,11 +43,20 @@ export class BatchCancelReconciliationManager extends BaseBatchUpdateStatusManag
|
|||
payment_date: this.data.payment_date,
|
||||
});
|
||||
|
||||
// FIXME => VALIDATION GUARD CANCEL FOR RECONCILIATION FROM CASHIER
|
||||
if (data.is_recap_transaction) {
|
||||
throw new UnprocessableEntityException({
|
||||
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
|
||||
message: `Gagagl! tidak dapat batalkan data rekap`,
|
||||
error: 'Unprocessable Entity',
|
||||
// throw new UnprocessableEntityException({
|
||||
// statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
|
||||
// message: `Gagagl! tidak dapat batalkan data rekap`,
|
||||
// error: 'Unprocessable Entity',
|
||||
// });
|
||||
|
||||
Object.assign(this.data, {
|
||||
reconciliation_confirm_by: null,
|
||||
reconciliation_confirm_date: null,
|
||||
reconciliation_status: STATUS.PENDING,
|
||||
payment_code: null,
|
||||
settlement_date: null,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -37,26 +37,39 @@ export class CancelReconciliationManager extends BaseUpdateStatusManager<Transac
|
|||
error: 'Unprocessable Entity',
|
||||
});
|
||||
} else if (this.data.is_recap_transaction) {
|
||||
throw new UnprocessableEntityException({
|
||||
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
|
||||
message: `Gagagl! tidak dapat batalkan data rekap`,
|
||||
error: 'Unprocessable Entity',
|
||||
});
|
||||
// FIXME => VALIDATION GUARD CANCEL FOR RECONCILIATION FROM CASHIER
|
||||
// throw new UnprocessableEntityException({
|
||||
// statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
|
||||
// message: `Gagagl! tidak dapat batalkan data rekap`,
|
||||
// error: 'Unprocessable Entity',
|
||||
// });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
Object.assign(this.data, {
|
||||
reconciliation_mdr: this.data.reconciliation_mdr ?? null,
|
||||
reconciliation_confirm_by: this.user.name,
|
||||
reconciliation_confirm_date: new Date().getTime(),
|
||||
status: this.dataStatus,
|
||||
reconciliation_status: this.dataStatus,
|
||||
payment_date: this.data.payment_date,
|
||||
settlement_date:
|
||||
this.dataStatus === STATUS.REJECTED ? null : this.data.settlement_date,
|
||||
});
|
||||
if (this.data.is_recap_transaction) {
|
||||
Object.assign(this.data, {
|
||||
reconciliation_confirm_by: null,
|
||||
reconciliation_confirm_date: null,
|
||||
reconciliation_status: STATUS.PENDING,
|
||||
payment_code: null,
|
||||
settlement_date: null,
|
||||
});
|
||||
} else {
|
||||
Object.assign(this.data, {
|
||||
reconciliation_mdr: this.data.reconciliation_mdr ?? null,
|
||||
reconciliation_confirm_by: this.user.name,
|
||||
reconciliation_confirm_date: new Date().getTime(),
|
||||
status: this.dataStatus,
|
||||
reconciliation_status: this.dataStatus,
|
||||
payment_date: this.data.payment_date,
|
||||
settlement_date:
|
||||
this.dataStatus === STATUS.REJECTED
|
||||
? null
|
||||
: this.data.settlement_date,
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,12 +8,18 @@ import { Between, 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';
|
||||
|
||||
@Injectable()
|
||||
export class RecapReconciliationManager extends BaseCustomManager<TransactionEntity> {
|
||||
private recapTransactions = {};
|
||||
private startOfDay = moment().startOf('day').valueOf();
|
||||
private endOfDay = moment().endOf('day').valueOf();
|
||||
private bodyFilter: any;
|
||||
private paymentDate: string;
|
||||
|
||||
setBodyFilter(body: RecapReconciliationDto) {
|
||||
this.bodyFilter = body;
|
||||
this.paymentDate = body.payment_date;
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return TransactionModel;
|
||||
|
@ -37,7 +43,7 @@ export class RecapReconciliationManager extends BaseCustomManager<TransactionEnt
|
|||
is_recap_transaction: false,
|
||||
payment_type: TransactionType.COUNTER,
|
||||
status: STATUS.SETTLED,
|
||||
created_at: Between(this.startOfDay, this.endOfDay),
|
||||
payment_date: this.paymentDate,
|
||||
payment_type_counter: Not(IsNull()),
|
||||
payment_total: MoreThan(0),
|
||||
},
|
||||
|
@ -48,13 +54,17 @@ export class RecapReconciliationManager extends BaseCustomManager<TransactionEnt
|
|||
creator_counter_no,
|
||||
payment_type_counter,
|
||||
payment_type_method_id,
|
||||
payment_date,
|
||||
} = transaction;
|
||||
const group_by =
|
||||
creator_counter_no +
|
||||
'-' +
|
||||
payment_type_counter +
|
||||
'-' +
|
||||
payment_type_method_id;
|
||||
payment_type_method_id +
|
||||
'_' +
|
||||
payment_date;
|
||||
|
||||
if (!this.recapTransactions[group_by]) {
|
||||
this.recapTransactions[group_by] = [];
|
||||
}
|
||||
|
@ -66,17 +76,20 @@ export class RecapReconciliationManager extends BaseCustomManager<TransactionEnt
|
|||
|
||||
async process(): Promise<void> {
|
||||
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_counter,
|
||||
payment_type_method_id,
|
||||
payment_date,
|
||||
} = first_transaction;
|
||||
|
||||
const query = {
|
||||
is_recap_transaction: true,
|
||||
created_at: Between(this.startOfDay, this.endOfDay),
|
||||
payment_date: payment_date,
|
||||
creator_counter_no: creator_counter_no,
|
||||
payment_type: payment_type_counter,
|
||||
};
|
||||
|
@ -94,9 +107,30 @@ export class RecapReconciliationManager extends BaseCustomManager<TransactionEnt
|
|||
);
|
||||
|
||||
if (exist) {
|
||||
if (parseFloat(exist.payment_total) !== total) {
|
||||
const newTotal = total;
|
||||
const newTotalNet =
|
||||
total - parseFloat(exist.reconciliation_mdr ?? '0');
|
||||
|
||||
Object.assign(exist, {
|
||||
payment_total: newTotal,
|
||||
payment_total_net_profit: newTotalNet,
|
||||
|
||||
//RESET STATUS TO PENDING
|
||||
reconciliation_confirm_by: null,
|
||||
reconciliation_confirm_date: null,
|
||||
reconciliation_status: STATUS.PENDING,
|
||||
payment_code: null,
|
||||
settlement_date: null,
|
||||
});
|
||||
} else {
|
||||
Object.assign(exist, {
|
||||
payment_total: total,
|
||||
payment_total_net_profit: total,
|
||||
});
|
||||
}
|
||||
|
||||
Object.assign(exist, {
|
||||
payment_total: total,
|
||||
payment_total_net_profit: total,
|
||||
editor_id: this.user.id,
|
||||
editor_name: this.user.name,
|
||||
updated_at: new Date().getTime(),
|
||||
|
@ -109,8 +143,8 @@ export class RecapReconciliationManager extends BaseCustomManager<TransactionEnt
|
|||
reconciliation_status: STATUS.PENDING,
|
||||
status: STATUS.SETTLED,
|
||||
type: TransactionType.COUNTER,
|
||||
booking_date: new Date(),
|
||||
payment_date: new Date(),
|
||||
booking_date: payment_date,
|
||||
payment_date: payment_date,
|
||||
creator_counter_no: first_transaction.creator_counter_no,
|
||||
payment_type: first_transaction.payment_type_counter,
|
||||
payment_type_counter: first_transaction.payment_type_counter,
|
||||
|
|
|
@ -11,6 +11,7 @@ import { TransactionEntity } from 'src/modules/transaction/transaction/domain/en
|
|||
import { TransactionDataService } from 'src/modules/transaction/transaction/data/services/transaction-data.service';
|
||||
import { RecapReconciliationManager } from './managers/recap-reconciliation.manager';
|
||||
import { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model';
|
||||
import { RecapReconciliationDto } from '../../infrastructure/dto/recap.dto';
|
||||
|
||||
@Injectable()
|
||||
export class ReconciliationDataOrchestrator {
|
||||
|
@ -31,9 +32,10 @@ export class ReconciliationDataOrchestrator {
|
|||
return this.updateManager.getResult();
|
||||
}
|
||||
|
||||
async recap() {
|
||||
async recap(body: RecapReconciliationDto) {
|
||||
const data = new TransactionModel();
|
||||
this.recapManager.setData(data);
|
||||
this.recapManager.setBodyFilter(body);
|
||||
this.recapManager.setService(this.serviceData, TABLE_NAME.TRANSACTION);
|
||||
await this.recapManager.execute();
|
||||
return this.recapManager.getResult();
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsString } from 'class-validator';
|
||||
|
||||
export class RecapReconciliationDto {
|
||||
@ApiProperty({ required: true, type: String })
|
||||
@IsString()
|
||||
payment_date: string;
|
||||
}
|
|
@ -15,6 +15,7 @@ import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto'
|
|||
import { Public } from 'src/core/guards';
|
||||
import { TransactionEntity } from '../../transaction/domain/entities/transaction.entity';
|
||||
import { UpdateReconciliationDto } from './dto/reconciliation.dto';
|
||||
import { RecapReconciliationDto } from './dto/recap.dto';
|
||||
|
||||
@ApiTags(`${MODULE_NAME.RECONCILIATION.split('-').join(' ')} - data`)
|
||||
@Controller(`v1/${MODULE_NAME.RECONCILIATION}`)
|
||||
|
@ -24,8 +25,8 @@ export class ReconciliationDataController {
|
|||
constructor(private orchestrator: ReconciliationDataOrchestrator) {}
|
||||
|
||||
@Post('/recap-transaction')
|
||||
async recap(): Promise<any> {
|
||||
return await this.orchestrator.recap();
|
||||
async recap(@Body() body: RecapReconciliationDto): Promise<any> {
|
||||
return await this.orchestrator.recap(body);
|
||||
}
|
||||
|
||||
@Put('/batch-confirm')
|
||||
|
|
Loading…
Reference in New Issue