fix(SPG-743) Refund dengan code invoice yang sama terkena validasi
parent
d14d9101ae
commit
1636f6b930
|
@ -0,0 +1,49 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class UpdateRelationTableTransaction1722581313837
|
||||
implements MigrationInterface
|
||||
{
|
||||
name = 'UpdateRelationTableTransaction1722581313837';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "refunds" DROP CONSTRAINT "FK_8bb3b7579f49990d2e77684acd4"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "refunds" DROP CONSTRAINT "REL_8bb3b7579f49990d2e77684acd"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "refund_items" DROP CONSTRAINT "FK_07b481a163c219f5de8fb1c90b3"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "refund_items" DROP CONSTRAINT "REL_07b481a163c219f5de8fb1c90b"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "refunds" ADD CONSTRAINT "FK_8bb3b7579f49990d2e77684acd4" FOREIGN KEY ("transaction_id") REFERENCES "transactions"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "refund_items" ADD CONSTRAINT "FK_07b481a163c219f5de8fb1c90b3" FOREIGN KEY ("transaction_item_id") REFERENCES "transaction_items"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "refund_items" DROP CONSTRAINT "FK_07b481a163c219f5de8fb1c90b3"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "refunds" DROP CONSTRAINT "FK_8bb3b7579f49990d2e77684acd4"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "refund_items" ADD CONSTRAINT "REL_07b481a163c219f5de8fb1c90b" UNIQUE ("transaction_item_id")`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "refund_items" ADD CONSTRAINT "FK_07b481a163c219f5de8fb1c90b3" FOREIGN KEY ("transaction_item_id") REFERENCES "transaction_items"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "refunds" ADD CONSTRAINT "REL_8bb3b7579f49990d2e77684acd" UNIQUE ("transaction_id")`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "refunds" ADD CONSTRAINT "FK_8bb3b7579f49990d2e77684acd4" FOREIGN KEY ("transaction_id") REFERENCES "transactions"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -86,8 +86,6 @@ export class RecapReconciliationManager extends BaseCustomManager<TransactionEnt
|
|||
where: query,
|
||||
});
|
||||
|
||||
if (payment_type == 'cash') console.log(exist, 'das', query);
|
||||
|
||||
const new_recap = new TransactionModel();
|
||||
const total = _.sumBy(this.recapTransactions[recap], (recap) =>
|
||||
parseFloat(recap.payment_total),
|
||||
|
|
|
@ -29,7 +29,7 @@ export class RefundItemModel
|
|||
// transaction to transaction item
|
||||
@Column('varchar', { name: 'transaction_item_id', nullable: true })
|
||||
transaction_item_id: string;
|
||||
@OneToOne(() => TransactionItemModel, (model) => model.refund, {
|
||||
@ManyToOne(() => TransactionItemModel, (model) => model.refunds, {
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { RefundEntity } from '../../domain/entities/refund.entity';
|
||||
import { Column, Entity, JoinColumn, OneToMany, OneToOne } from 'typeorm';
|
||||
import { Column, Entity, JoinColumn, ManyToOne, OneToMany } from 'typeorm';
|
||||
import { BaseStatusModel } from 'src/core/modules/data/model/base-status.model';
|
||||
import { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model';
|
||||
import { RefundItemModel } from './refund-item.model';
|
||||
|
@ -64,7 +64,7 @@ export class RefundModel
|
|||
// relation to transaction
|
||||
@Column('varchar', { name: 'transaction_id', nullable: true })
|
||||
transaction_id: string;
|
||||
@OneToOne(() => TransactionModel, (model) => model.refund, {
|
||||
@ManyToOne(() => TransactionModel, (model) => model.refunds, {
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
|
|
|
@ -38,7 +38,6 @@ export class BatchConfirmRefundManager extends BaseBatchUpdateStatusManager<Refu
|
|||
|
||||
if (this.data.status == STATUS.DRAFT) {
|
||||
Object.assign(this.data, {
|
||||
code: `RF-${data?.['transaction']?.invoice_code.split('-')[1]}`,
|
||||
request_date: new Date(),
|
||||
status: STATUS.PENDING,
|
||||
});
|
||||
|
|
|
@ -53,7 +53,6 @@ export class ConfirmRefundManager extends BaseUpdateStatusManager<RefundEntity>
|
|||
|
||||
if (data.status == STATUS.DRAFT) {
|
||||
Object.assign(this.data, {
|
||||
code: `RF-${data.transaction?.invoice_code?.split('-')[1]}`,
|
||||
request_date: new Date(),
|
||||
status: STATUS.PENDING,
|
||||
});
|
||||
|
|
|
@ -13,6 +13,8 @@ import { RefundModel } from '../../../data/models/refund.model';
|
|||
import { BaseCreateManager } from 'src/core/modules/domain/usecase/managers/base-create.manager';
|
||||
import { RefundCreatedEvent } from '../../entities/event/refund-created.event';
|
||||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||
import { In, Not } from 'typeorm';
|
||||
import { generateInvoiceCodeHelper } from 'src/modules/transaction/transaction/domain/usecases/managers/helpers/generate-invoice-code.helper';
|
||||
|
||||
@Injectable()
|
||||
export class CreateRefundManager extends BaseCreateManager<RefundEntity> {
|
||||
|
@ -26,13 +28,10 @@ export class CreateRefundManager extends BaseCreateManager<RefundEntity> {
|
|||
};
|
||||
});
|
||||
|
||||
Object.assign(this.data, {
|
||||
refund_items: refund_items,
|
||||
});
|
||||
|
||||
const exist = await this.dataService.getOneByOptions({
|
||||
where: {
|
||||
transaction_id: this.data.transaction.id,
|
||||
status: Not(In([STATUS.CANCEL])),
|
||||
},
|
||||
});
|
||||
if (exist) {
|
||||
|
@ -57,6 +56,11 @@ export class CreateRefundManager extends BaseCreateManager<RefundEntity> {
|
|||
error: 'Unprocessable Entity',
|
||||
});
|
||||
}
|
||||
|
||||
Object.assign(this.data, {
|
||||
refund_items: refund_items,
|
||||
code: await generateInvoiceCodeHelper(this.dataService, 'RF'),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ export class DetailRefundManager extends BaseDetailManager<RefundEntity> {
|
|||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
mappingTransaction(this.result['transaction']);
|
||||
mappingTransaction(this.result['transaction'], this.dataId);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,12 @@ export class DetailRefundManager extends BaseDetailManager<RefundEntity> {
|
|||
joinRelations: [],
|
||||
|
||||
// relation join and select (relasi yang ingin ditampilkan),
|
||||
selectRelations: ['transaction', 'transaction.items', 'items.refund'],
|
||||
selectRelations: [
|
||||
'transaction',
|
||||
'transaction.items',
|
||||
'items.refunds item_refunds',
|
||||
'item_refunds.refund item_refunds_refund',
|
||||
],
|
||||
|
||||
// relation yang hanya ingin dihitung (akan return number)
|
||||
countRelations: [],
|
||||
|
@ -55,7 +60,9 @@ export class DetailRefundManager extends BaseDetailManager<RefundEntity> {
|
|||
|
||||
'transaction',
|
||||
'items',
|
||||
'refund',
|
||||
'item_refunds',
|
||||
'item_refunds_refund.id',
|
||||
'item_refunds_refund.status',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { Column, Entity, JoinColumn, ManyToOne, OneToOne } from 'typeorm';
|
||||
import { Column, Entity, JoinColumn, ManyToOne, OneToMany } from 'typeorm';
|
||||
import { BaseCoreModel } from 'src/core/modules/data/model/base-core.model';
|
||||
import { TransactionItemEntity } from '../../domain/entities/transaction-item.entity';
|
||||
import { TransactionModel } from './transaction.model';
|
||||
|
@ -80,10 +80,10 @@ export class TransactionItemModel
|
|||
transaction: TransactionModel;
|
||||
|
||||
// relations to refund
|
||||
@OneToOne(() => RefundItemModel, (model) => model.transaction_item, {
|
||||
@OneToMany(() => RefundItemModel, (model) => model.transaction_item, {
|
||||
cascade: true,
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
refund: RefundItemModel;
|
||||
refunds: RefundItemModel[];
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { TransactionEntity } from '../../domain/entities/transaction.entity';
|
||||
import { Column, Entity, OneToMany, OneToOne } from 'typeorm';
|
||||
import { Column, Entity, OneToMany } from 'typeorm';
|
||||
import { BaseStatusModel } from 'src/core/modules/data/model/base-status.model';
|
||||
import {
|
||||
TransactionType,
|
||||
|
@ -233,10 +233,10 @@ export class TransactionModel
|
|||
taxes: TransactionTaxModel[];
|
||||
|
||||
// relations to refund
|
||||
@OneToOne(() => RefundModel, (model) => model.transaction, {
|
||||
@OneToMany(() => RefundModel, (model) => model.transaction, {
|
||||
cascade: true,
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
refund: RefundModel;
|
||||
refunds: RefundModel[];
|
||||
}
|
||||
|
|
|
@ -25,7 +25,12 @@ export class DetailTransactionManager extends BaseDetailManager<TransactionEntit
|
|||
joinRelations: [],
|
||||
|
||||
// relation join and select (relasi yang ingin ditampilkan),
|
||||
selectRelations: ['items', 'items.refund item_refund', 'refund'],
|
||||
selectRelations: [
|
||||
'items',
|
||||
'items.refunds item_refunds',
|
||||
'item_refunds.refund item_refunds_refund',
|
||||
'refunds',
|
||||
],
|
||||
|
||||
// relation yang hanya ingin dihitung (akan return number)
|
||||
countRelations: [],
|
||||
|
@ -76,8 +81,11 @@ export class DetailTransactionManager extends BaseDetailManager<TransactionEntit
|
|||
`${this.tableName}.payment_total`,
|
||||
|
||||
'items',
|
||||
'item_refund',
|
||||
'refund',
|
||||
'item_refunds',
|
||||
'item_refunds_refund.id',
|
||||
'item_refunds_refund.status',
|
||||
|
||||
'refunds',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,12 @@ export async function generateInvoiceCodeHelper(dataService, code) {
|
|||
invoice_code: ILike(`%${month_year}%`),
|
||||
};
|
||||
|
||||
if (code == 'RF') {
|
||||
query = {
|
||||
code: ILike(`%${month_year}%`),
|
||||
};
|
||||
}
|
||||
|
||||
if (code == 'PYM') {
|
||||
query = {
|
||||
payment_code: ILike(`%${month_year}%`),
|
||||
|
|
|
@ -4,7 +4,7 @@ import {
|
|||
TransactionType,
|
||||
} from 'src/modules/transaction/transaction/constants';
|
||||
|
||||
export function mappingTransaction(data) {
|
||||
export function mappingTransaction(data, refundId?: string) {
|
||||
let payment_type_bank: any = null;
|
||||
const season_period = {
|
||||
id: data.season_period_id,
|
||||
|
@ -26,6 +26,9 @@ export function mappingTransaction(data) {
|
|||
|
||||
const items = data?.['items']?.map((itemData) => {
|
||||
let tenant;
|
||||
let refund = itemData.refunds?.find(
|
||||
(item) => ![STATUS.CANCEL].includes(item.refund.status),
|
||||
);
|
||||
|
||||
if (itemData.item_tenant_id) {
|
||||
tenant = {
|
||||
|
@ -35,6 +38,9 @@ export function mappingTransaction(data) {
|
|||
};
|
||||
}
|
||||
|
||||
if (refundId)
|
||||
refund = itemData.refunds?.find((item) => item.refund.id == refundId);
|
||||
|
||||
return {
|
||||
item: {
|
||||
id: itemData.item_id,
|
||||
|
@ -49,20 +55,27 @@ export function mappingTransaction(data) {
|
|||
},
|
||||
},
|
||||
id: itemData.id,
|
||||
refund: itemData.refund,
|
||||
refund: refund,
|
||||
qty: itemData.qty,
|
||||
qty_remaining: itemData.qty_remaining,
|
||||
total_price_refund: itemData.refund?.refund_total ?? 0,
|
||||
total_price_refund: refund?.refund_total ?? 0,
|
||||
total_price: itemData.total_price,
|
||||
};
|
||||
});
|
||||
|
||||
const refund = data.refunds?.find(
|
||||
(refund) => ![STATUS.CANCEL].includes(refund.status),
|
||||
);
|
||||
|
||||
Object.assign(data, {
|
||||
season_period: season_period,
|
||||
items: items,
|
||||
payment_type_bank: payment_type_bank,
|
||||
refund: refund,
|
||||
});
|
||||
|
||||
delete data.refunds;
|
||||
|
||||
delete data.season_period_id;
|
||||
delete data.season_period_name;
|
||||
delete data.season_period_type_id;
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
RelationParam,
|
||||
} from 'src/core/modules/domain/entities/base-filter.entity';
|
||||
import { BetweenQueryHelper } from 'src/core/helpers/query/between-query.helper';
|
||||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||
|
||||
@Injectable()
|
||||
export class IndexTransactionManager extends BaseIndexManager<TransactionEntity> {
|
||||
|
@ -20,12 +21,16 @@ export class IndexTransactionManager extends BaseIndexManager<TransactionEntity>
|
|||
|
||||
async afterProcess(): Promise<void> {
|
||||
this.result?.data?.map((item) => {
|
||||
const activeRefund = item['refunds'].find(
|
||||
(refund) => ![STATUS.CANCEL].includes(refund.status),
|
||||
);
|
||||
|
||||
Object.assign(item, {
|
||||
refund_code: item['refund']?.code ?? null,
|
||||
refund_date: item['refund']?.refund_date ?? null,
|
||||
refund_code: activeRefund?.code ?? null,
|
||||
refund_date: activeRefund?.refund_date ?? null,
|
||||
});
|
||||
|
||||
delete item['refund'];
|
||||
delete item['refunds'];
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
@ -36,7 +41,7 @@ export class IndexTransactionManager extends BaseIndexManager<TransactionEntity>
|
|||
joinRelations: [],
|
||||
|
||||
// relation join and select (relasi yang ingin ditampilkan),
|
||||
selectRelations: ['items', 'refund'],
|
||||
selectRelations: ['items', 'refunds'],
|
||||
|
||||
// relation yang hanya ingin dihitung (akan return number)
|
||||
countRelations: [],
|
||||
|
@ -76,10 +81,10 @@ export class IndexTransactionManager extends BaseIndexManager<TransactionEntity>
|
|||
`${this.tableName}.payment_type_method_name`,
|
||||
`${this.tableName}.payment_type_method_number`,
|
||||
|
||||
`refund.id`,
|
||||
`refund.code`,
|
||||
`refund.refund_date`,
|
||||
`refund.request_date`,
|
||||
`refunds.id`,
|
||||
`refunds.code`,
|
||||
`refunds.refund_date`,
|
||||
`refunds.request_date`,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue