Merge pull request 'fix/data' (#47) from fix/data into development

Reviewed-on: #47
pull/48/head
aswin 2024-08-01 10:37:35 +00:00
commit 971407612c
6 changed files with 55 additions and 44 deletions

View File

@ -20,7 +20,7 @@ export class BookingDeletedEvent
_id: event.data.id, _id: event.data.id,
...event.data.data, ...event.data.data,
}, },
'item', 'booking',
); );
} }
} }

View File

@ -23,10 +23,13 @@ export class BatchCancelReconciliationManager extends BaseBatchUpdateStatusManag
}, },
}); });
if ([STATUS.SETTLED, STATUS.WAITING].includes(transaction.status)) { if (
![STATUS.SETTLED, STATUS.WAITING].includes(transaction.status) &&
!data.is_recap_transaction
) {
throw new UnprocessableEntityException({ throw new UnprocessableEntityException({
statusCode: HttpStatus.UNPROCESSABLE_ENTITY, statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
message: `Gagal! tidak bisa batalkan, karena status transaksi tidak settled`, message: `Gagal! tidak bisa batalkan, karena status transaksi tidak settled atau waiting`,
error: 'Unprocessable Entity', error: 'Unprocessable Entity',
}); });
} }

View File

@ -27,10 +27,13 @@ export class CancelReconciliationManager extends BaseUpdateStatusManager<Transac
}, },
}); });
if ([STATUS.SETTLED, STATUS.WAITING].includes(transaction.status)) { if (
![STATUS.SETTLED, STATUS.WAITING].includes(transaction.status) &&
!this.data.is_recap_transaction
) {
throw new UnprocessableEntityException({ throw new UnprocessableEntityException({
statusCode: HttpStatus.UNPROCESSABLE_ENTITY, statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
message: `Gagal! tidak bisa batalkan, karena status transaksi tidak settled`, message: `Gagal! tidak bisa batalkan, karena status transaksi tidak settled atau waiting`,
error: 'Unprocessable Entity', error: 'Unprocessable Entity',
}); });
} else if (this.data.is_recap_transaction) { } else if (this.data.is_recap_transaction) {

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}.invoice_code`,
`${this.tableName}.booking_date`, `${this.tableName}.booking_date`,
`${this.tableName}.payment_type`, `${this.tableName}.payment_type`,
`${this.tableName}.payment_type_method_id`, `${this.tableName}.payment_type_method_id`,

View File

@ -72,16 +72,22 @@ export class RecapReconciliationManager extends BaseCustomManager<TransactionEnt
const { creator_counter_no, payment_type, payment_type_method_id } = const { creator_counter_no, payment_type, payment_type_method_id } =
first_transaction; first_transaction;
let query = {
is_recap_transaction: true,
created_at: Between(this.startOfDay, this.endOfDay),
creator_counter_no: creator_counter_no,
payment_type: payment_type,
};
if (payment_type != 'cash')
query['payment_type_method_id'] = payment_type_method_id ?? EMPTY_UUID;
const exist = await this.dataService.getOneByOptions({ const exist = await this.dataService.getOneByOptions({
where: { where: query,
is_recap_transaction: true,
created_at: Between(this.startOfDay, this.endOfDay),
creator_counter_no: creator_counter_no,
payment_type: payment_type,
payment_type_method_id: payment_type_method_id ?? EMPTY_UUID,
},
}); });
if (payment_type == 'cash') console.log(exist, 'das', query);
const new_recap = new TransactionModel(); const new_recap = new TransactionModel();
const total = _.sumBy(this.recapTransactions[recap], (recap) => const total = _.sumBy(this.recapTransactions[recap], (recap) =>
parseFloat(recap.payment_total), parseFloat(recap.payment_total),
@ -89,9 +95,8 @@ export class RecapReconciliationManager extends BaseCustomManager<TransactionEnt
if (exist) { if (exist) {
Object.assign(exist, { Object.assign(exist, {
payment_total: Number(exist.payment_total) + total, payment_total: total,
payment_total_net_profit: payment_total_net_profit: total,
Number(exist.payment_total_net_profit) + 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(),

View File

@ -4,49 +4,48 @@ import { TransactionDataService } from '../../../data/services/transaction-data.
import { OPERATION, STATUS } from 'src/core/strings/constants/base.constants'; import { OPERATION, STATUS } from 'src/core/strings/constants/base.constants';
import { TransactionModel } from '../../../data/models/transaction.model'; import { TransactionModel } from '../../../data/models/transaction.model';
import { RefundDeletedEvent } from 'src/modules/transaction/refund/domain/entities/event/refund-deleted.event'; import { RefundDeletedEvent } from 'src/modules/transaction/refund/domain/entities/event/refund-deleted.event';
import { RefundCreatedEvent } from 'src/modules/transaction/refund/domain/entities/event/refund-created.event';
@EventsHandler(RefundChangeStatusEvent, RefundDeletedEvent) @EventsHandler(RefundChangeStatusEvent, RefundDeletedEvent, RefundCreatedEvent)
export class RefundUpdatedHandler export class RefundUpdatedHandler
implements IEventHandler<RefundChangeStatusEvent> implements IEventHandler<RefundChangeStatusEvent>
{ {
constructor(private dataService: TransactionDataService) {} constructor(private dataService: TransactionDataService) {}
async handle(event: RefundChangeStatusEvent) { async handle(event: RefundChangeStatusEvent) {
const old_data = event.data.old;
const current_data = event.data.data; const current_data = event.data.data;
let status: STATUS; let status: STATUS;
const queryRunner = this.dataService
.getRepository()
.manager.connection.createQueryRunner();
const data = new TransactionModel();
const if_full_refund =
Number(current_data.refund_total ?? 0) ==
Number(current_data.transaction?.payment_total);
if ( if (
old_data.status != current_data.data || event.data.op == OPERATION.DELETE ||
(event.data.op == OPERATION.DELETE && current_data.status != STATUS.DRAFT) current_data.status == STATUS.CANCEL
) { )
const queryRunner = this.dataService status = STATUS.SETTLED;
.getRepository() else {
.manager.connection.createQueryRunner(); if (current_data.status == STATUS.REFUNDED && if_full_refund)
const data = new TransactionModel();
const if_full_refund =
Number(current_data.refund_total ?? 0) ==
Number(current_data.transaction?.payment_total);
if (event.data.op == OPERATION.DELETE) status = STATUS.SETTLED;
else if (current_data.status == STATUS.PENDING)
status = STATUS.PROCESS_REFUND;
else if (current_data.status == STATUS.REFUNDED && if_full_refund)
status = STATUS.REFUNDED; status = STATUS.REFUNDED;
else if (current_data.status == STATUS.REFUNDED && !if_full_refund) else if (current_data.status == STATUS.REFUNDED && !if_full_refund)
status = STATUS.PARTIAL_REFUND; status = STATUS.PARTIAL_REFUND;
else if (current_data.status == STATUS.CANCEL) status = STATUS.SETTLED; else status = STATUS.PROCESS_REFUND;
await this.dataService.update(
queryRunner,
TransactionModel,
{ id: current_data.transaction_id },
{
...data,
status: status,
},
);
} }
await this.dataService.update(
queryRunner,
TransactionModel,
{ id: current_data.transaction_id },
{
...data,
status: status,
},
);
} }
} }