feat: add breakdown item to transaction
parent
f4387767a8
commit
f2bc4dd46d
|
@ -44,7 +44,10 @@ import { ItemRateModel } from './modules/item-related/item-rate/data/models/item
|
|||
import { GoogleCalendarModule } from './modules/configuration/google-calendar/google-calendar.module';
|
||||
import { TransactionModule } from './modules/transaction/transaction/transaction.module';
|
||||
import { TransactionModel } from './modules/transaction/transaction/data/models/transaction.model';
|
||||
import { TransactionItemModel } from './modules/transaction/transaction/data/models/transaction-item.model';
|
||||
import {
|
||||
TransactionItemBreakdownModel,
|
||||
TransactionItemModel,
|
||||
} from './modules/transaction/transaction/data/models/transaction-item.model';
|
||||
import { TransactionTaxModel } from './modules/transaction/transaction/data/models/transaction-tax.model';
|
||||
import { ReconciliationModule } from './modules/transaction/reconciliation/reconciliation.module';
|
||||
import { ReportModule } from './modules/reports/report/report.module';
|
||||
|
@ -111,6 +114,7 @@ import { TransactionDemographyModel } from './modules/transaction/transaction/da
|
|||
TransactionItemModel,
|
||||
TransactionTaxModel,
|
||||
TransactionDemographyModel,
|
||||
TransactionItemBreakdownModel,
|
||||
UserModel,
|
||||
VipCategoryModel,
|
||||
VipCodeModel,
|
||||
|
|
|
@ -20,6 +20,7 @@ export enum TABLE_NAME {
|
|||
TENANT = 'tenants',
|
||||
TRANSACTION = 'transactions',
|
||||
TRANSACTION_ITEM = 'transaction_items',
|
||||
TRANSACTION_ITEM_BREAKDOWN = 'transaction_item_breakdowns',
|
||||
TRANSACTION_TAX = 'transaction_taxes',
|
||||
TRANSACTION_DEMOGRAPHY = 'transaction_demographies',
|
||||
USER = 'users',
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddBreakdownItemTransaction1724127202672
|
||||
implements MigrationInterface
|
||||
{
|
||||
name = 'AddBreakdownItemTransaction1724127202672';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE "transaction_item_breakdowns" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "item_id" character varying NOT NULL, "item_name" character varying NOT NULL, "hpp" bigint, "base_price" bigint, "item_rates" bigint, "transaction_item_id" uuid, CONSTRAINT "PK_e04a30c648d3ba8778e9fb67fdd" PRIMARY KEY ("id"))`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "transaction_item_breakdowns" ADD CONSTRAINT "FK_b8c63b1f3ecace500587da713ae" 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 "transaction_item_breakdowns" DROP CONSTRAINT "FK_b8c63b1f3ecace500587da713ae"`,
|
||||
);
|
||||
await queryRunner.query(`DROP TABLE "transaction_item_breakdowns"`);
|
||||
}
|
||||
}
|
|
@ -1,7 +1,10 @@
|
|||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
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 {
|
||||
TransactionBundlingItemEntity,
|
||||
TransactionItemEntity,
|
||||
} from '../../domain/entities/transaction-item.entity';
|
||||
import { TransactionModel } from './transaction.model';
|
||||
import { RefundItemModel } from 'src/modules/transaction/refund/data/models/refund-item.model';
|
||||
|
||||
|
@ -86,4 +89,40 @@ export class TransactionItemModel
|
|||
onUpdate: 'CASCADE',
|
||||
})
|
||||
refunds: RefundItemModel[];
|
||||
|
||||
@OneToMany(
|
||||
() => TransactionItemBreakdownModel,
|
||||
(model) => model.transaction_item,
|
||||
{
|
||||
cascade: true,
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
},
|
||||
)
|
||||
bundling_items: TransactionItemBreakdownModel[];
|
||||
}
|
||||
|
||||
@Entity(TABLE_NAME.TRANSACTION_ITEM_BREAKDOWN)
|
||||
export class TransactionItemBreakdownModel extends BaseCoreModel<TransactionBundlingItemEntity> {
|
||||
@Column('varchar')
|
||||
item_id: string;
|
||||
|
||||
@Column('varchar')
|
||||
item_name: string;
|
||||
|
||||
@Column('bigint', { nullable: true })
|
||||
hpp: number;
|
||||
|
||||
@Column('bigint', { nullable: true })
|
||||
base_price: number;
|
||||
|
||||
@Column('bigint', { nullable: true })
|
||||
item_rates: number;
|
||||
|
||||
@ManyToOne(() => TransactionItemModel, (model) => model.bundling_items, {
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
@JoinColumn({ name: 'transaction_item_id' })
|
||||
transaction_item: TransactionItemModel;
|
||||
}
|
||||
|
|
|
@ -25,4 +25,13 @@ export interface TransactionItemEntity extends BaseCoreEntity {
|
|||
qty: number;
|
||||
qty_remaining: number;
|
||||
taxes: string;
|
||||
bundling_items?: TransactionBundlingItemEntity[];
|
||||
}
|
||||
|
||||
export interface TransactionBundlingItemEntity extends BaseCoreEntity {
|
||||
item_id: string;
|
||||
item_name: string;
|
||||
hpp: number;
|
||||
base_price: number;
|
||||
item_rates: number;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import {
|
|||
TransactionUserType,
|
||||
} from '../../constants';
|
||||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||
import { TransactionItemEntity } from './transaction-item.entity';
|
||||
|
||||
export interface TransactionEntity extends BaseStatusEntity {
|
||||
// general info
|
||||
|
@ -84,4 +85,6 @@ export interface TransactionEntity extends BaseStatusEntity {
|
|||
|
||||
calendar_id?: string;
|
||||
calendar_link?: string;
|
||||
|
||||
items: TransactionItemEntity[];
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ export class DetailTransactionManager extends BaseDetailManager<TransactionEntit
|
|||
// relation join and select (relasi yang ingin ditampilkan),
|
||||
selectRelations: [
|
||||
'items',
|
||||
'items.bundling_items',
|
||||
'items.refunds item_refunds',
|
||||
'item_refunds.refund item_refunds_refund',
|
||||
'refunds',
|
||||
|
@ -84,6 +85,7 @@ export class DetailTransactionManager extends BaseDetailManager<TransactionEntit
|
|||
`${this.tableName}.payment_midtrans_url`,
|
||||
|
||||
'items',
|
||||
'bundling_items',
|
||||
'item_refunds',
|
||||
'item_refunds_refund.id',
|
||||
'item_refunds_refund.status',
|
||||
|
|
|
@ -3,6 +3,7 @@ import {
|
|||
TransactionPaymentType,
|
||||
TransactionType,
|
||||
} from 'src/modules/transaction/transaction/constants';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
export function mappingTransaction(data, refundId?: string) {
|
||||
try {
|
||||
|
@ -54,6 +55,7 @@ export function mappingTransaction(data, refundId?: string) {
|
|||
id: itemData.item_category_id,
|
||||
name: itemData.item_category_name,
|
||||
},
|
||||
bundling_items: itemData.bundling_items,
|
||||
},
|
||||
id: itemData.id,
|
||||
refund: refund,
|
||||
|
@ -187,6 +189,14 @@ export function mappingRevertTransaction(data, type) {
|
|||
item_bundlings: item.item.bundling_items?.map(
|
||||
(bundling) => bundling.name,
|
||||
),
|
||||
bundling_items: item.item.bundling_items?.map((bundling) => {
|
||||
return {
|
||||
...bundling,
|
||||
item_id: bundling.id,
|
||||
item_name: bundling.name,
|
||||
id: uuidv4(),
|
||||
};
|
||||
}),
|
||||
|
||||
item_tenant_id: item.item.tenant?.id ?? null,
|
||||
item_tenant_name: item.item.tenant?.id ?? null,
|
||||
|
|
|
@ -18,7 +18,10 @@ import { DetailTransactionManager } from './domain/usecases/managers/detail-tran
|
|||
import { BatchDeleteTransactionManager } from './domain/usecases/managers/batch-delete-transaction.manager';
|
||||
import { BatchConfirmTransactionManager } from './domain/usecases/managers/batch-confirm-transaction.manager';
|
||||
import { TransactionModel } from './data/models/transaction.model';
|
||||
import { TransactionItemModel } from './data/models/transaction-item.model';
|
||||
import {
|
||||
TransactionItemBreakdownModel,
|
||||
TransactionItemModel,
|
||||
} from './data/models/transaction-item.model';
|
||||
import { TransactionTaxModel } from './data/models/transaction-tax.model';
|
||||
import { CancelTransactionManager } from './domain/usecases/managers/cancel-transaction.manager';
|
||||
import { BatchCancelTransactionManager } from './domain/usecases/managers/batch-cancel-transaction.manager';
|
||||
|
@ -46,6 +49,7 @@ import { TransactionDemographyModel } from './data/models/transaction-demography
|
|||
TransactionModel,
|
||||
TransactionItemModel,
|
||||
TransactionDemographyModel,
|
||||
TransactionItemBreakdownModel,
|
||||
TransactionTaxModel,
|
||||
TaxModel,
|
||||
SalesPriceFormulaModel,
|
||||
|
|
Loading…
Reference in New Issue