Merge branch 'development' of ssh://git.eigen.co.id:2222/eigen/pos-be into fix/bug-firman

fix/bug-firman
Firman Ramdhani 2024-08-21 09:37:39 +07:00
commit 7c0df75670
19 changed files with 181 additions and 11 deletions

View File

@ -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,

View File

@ -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',

View File

@ -13,7 +13,7 @@ export class FixDemographyNationality1723716561482
`ALTER TABLE "transaction_demographies" DROP COLUMN "foreign"`,
);
await queryRunner.query(
`CREATE TYPE "public"."transaction_demographies_nationality_enum" AS ENUM('local', 'foreign')`,
`CREATE TYPE "public"."transaction_demographies_nationality_enum" AS ENUM('local', 'foreign', 'mix')`,
);
await queryRunner.query(
`ALTER TABLE "transaction_demographies" ADD "nationality" "public"."transaction_demographies_nationality_enum" NOT NULL DEFAULT 'local'`,

View File

@ -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"`);
}
}

View File

@ -4,14 +4,64 @@ import { ItemRateEntity } from '../../domain/entities/item-rate.entity';
import { InjectRepository } from '@nestjs/typeorm';
import { ItemRateModel } from '../models/item-rate.model';
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
import { Repository } from 'typeorm';
import { In, Repository } from 'typeorm';
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
@Injectable()
export class ItemRateDataService extends BaseDataService<ItemRateEntity> {
constructor(
@InjectRepository(ItemRateModel, CONNECTION_NAME.DEFAULT)
private repo: Repository<ItemRateModel>,
@InjectRepository(ItemModel, CONNECTION_NAME.DEFAULT)
private itemRepo: Repository<ItemModel>,
) {
super(repo);
}
async itemsRateTotal(season_id: string, items: string[]): Promise<number> {
const rates = await this.repo.find({
where: {
season_period_id: season_id,
item_id: In(items),
},
});
return rates.reduce((total, current) => total + Number(current.price), 0);
}
async updateRatesBySeasonItem(
season_id: string,
item_id: string,
price: number,
): Promise<void> {
this.repo.update(
{
season_period_id: season_id,
item_id,
},
{ price },
);
}
async findBundlingByItem(item_id: string): Promise<ItemModel[]> {
const bundlings = await this.itemRepo.find({
where: {
breakdown_bundling: true,
bundling_items: {
id: item_id,
},
},
});
return Promise.all(
await bundlings.map(async (bundling) => {
return await this.itemRepo.findOne({
relations: ['bundling_items'],
where: {
id: bundling.id,
},
});
}),
);
}
}

View File

@ -5,7 +5,6 @@ import { ItemRateEntity } from '../entities/item-rate.entity';
import { DeleteItemRateManager } from './managers/delete-item-rate.manager';
import { UpdateItemRateManager } from './managers/update-item-rate.manager';
import { BaseDataOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-data.orchestrator';
import { STATUS } from 'src/core/strings/constants/base.constants';
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
import { BatchDeleteItemRateManager } from './managers/batch-delete-item-rate.manager';
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';

View File

@ -20,6 +20,7 @@ export class UpdateItemRateManager extends BaseUpdateManager<ItemRateEntity> {
}
async afterProcess(): Promise<void> {
this.updateBundlingBreakdown(this.dataId);
return;
}
@ -42,4 +43,25 @@ export class UpdateItemRateManager extends BaseUpdateManager<ItemRateEntity> {
},
];
}
async updateBundlingBreakdown(id: string) {
const { item_id, season_period_id } =
await this.dataService.getOneByOptions({
where: { id },
});
const bundlings = await this.dataService.findBundlingByItem(item_id);
for (const bundling of bundlings) {
const ids = bundling.bundling_items.map((item) => item.id);
const totalRates = await this.dataService.itemsRateTotal(
season_period_id,
ids,
);
this.dataService.updateRatesBySeasonItem(
season_period_id,
bundling.id,
totalRates,
);
}
}
}

View File

@ -1,11 +1,9 @@
import { Body, Controller, Delete, Param, Post, Put } from '@nestjs/common';
import { Body, Controller, Get, Param, Put } from '@nestjs/common';
import { ItemRateDataOrchestrator } from '../domain/usecases/item-rate-data.orchestrator';
import { ItemRateDto } from './dto/item-rate.dto';
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { ItemRateEntity } from '../domain/entities/item-rate.entity';
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto';
import { Public } from 'src/core/guards';
@ApiTags(`${MODULE_NAME.ITEM_RATE.split('-').join(' ')} - data`)

View File

@ -19,13 +19,14 @@ import { ItemRateModel } from './data/models/item-rate.model';
import { SeasonPeriodHolidayHandler } from './domain/usecases/handlers/item-created.handler';
import { SeasonPeriodDataService } from 'src/modules/season-related/season-period/data/services/season-period-data.service';
import { SeasonPeriodModel } from 'src/modules/season-related/season-period/data/models/season-period.model';
import { ItemModel } from '../item/data/models/item.model';
@Global()
@Module({
imports: [
ConfigModule.forRoot(),
TypeOrmModule.forFeature(
[ItemRateModel, SeasonPeriodModel],
[ItemRateModel, SeasonPeriodModel, ItemModel],
CONNECTION_NAME.DEFAULT,
),
CqrsModule,

View File

@ -28,6 +28,7 @@ export class DetailRefundManager extends BaseDetailManager<RefundEntity> {
selectRelations: [
'transaction',
'transaction.items',
'items.bundling_items',
'items.refunds item_refunds',
'item_refunds.refund item_refunds_refund',
],
@ -60,6 +61,7 @@ export class DetailRefundManager extends BaseDetailManager<RefundEntity> {
'transaction',
'items',
'bundling_items',
'item_refunds',
'item_refunds_refund.id',
'item_refunds_refund.status',

View File

@ -33,4 +33,5 @@ export const TransactionModels = [
export enum DemographyNationality {
LOCAL = 'local',
FOREIGN = 'foreign',
MIX = 'mix',
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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[];
}

View File

@ -16,6 +16,7 @@ import { TransactionPaymentType } from '../../../constants';
@Injectable()
export class ConfirmDataTransactionManager extends BaseUpdateStatusManager<TransactionEntity> {
protected relations = ['items', 'items.bundling_items'];
getResult(): string {
return `Success active data ${this.result.invoice_code}`;
}

View File

@ -18,7 +18,7 @@ import { apm } from 'src/core/apm';
@Injectable()
export class ConfirmTransactionManager extends BaseUpdateStatusManager<TransactionEntity> {
protected relations = ['items'];
protected relations = ['items', 'items.bundling_items'];
getResult(): string {
return `Success active data ${this.result.invoice_code}`;

View File

@ -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',

View File

@ -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,15 @@ export function mappingRevertTransaction(data, type) {
item_bundlings: item.item.bundling_items?.map(
(bundling) => bundling.name,
),
bundling_items: item.item.bundling_items?.map((bundling) => {
if (bundling.item_id) return 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,

View File

@ -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,