Compare commits

...

3 Commits

Author SHA1 Message Date
shancheas 18dc15e442 Merge branch 'development' of ssh://git.eigen.co.id:2222/eigen/pos-be into development
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2024-10-08 16:27:20 +07:00
shancheas 198dcb4933 feat: add discount value to vip code 2024-10-08 16:26:40 +07:00
shancheas 901c67137b feat: calculate discount for bundling 2024-10-08 15:40:54 +07:00
6 changed files with 50 additions and 9 deletions

View File

@ -0,0 +1,25 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddDiscountValueToVoucher1728377112337
implements MigrationInterface
{
name = 'AddDiscountValueToVoucher1728377112337';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "vip_codes" ADD "discount_value" numeric`,
);
await queryRunner.query(
`ALTER TABLE "vip_codes" ALTER COLUMN "discount" DROP NOT NULL`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "vip_codes" ALTER COLUMN "discount" SET NOT NULL`,
);
await queryRunner.query(
`ALTER TABLE "vip_codes" DROP COLUMN "discount_value"`,
);
}
}

View File

@ -51,12 +51,6 @@ export class PosTransactionHandler implements IEventHandler<ChangeDocEvent> {
},
});
const taxes = await this.taxService.getManyByOptions({
where: {
status: STATUS.ACTIVE,
},
});
const queryRunner = this.dataService
.getRepository()
.manager.connection.createQueryRunner();

View File

@ -189,11 +189,19 @@ export function mappingRevertTransaction(data, type) {
const total_share_tenant =
share_margin > 0 ? (Number(share_margin) / 100) * total_price : 0;
const bundlingTotalPrice =
(item.item?.bundling_items?.reduce(
(a, b) => a + Number(b.item_rates ?? b.base_price),
0,
) ?? 0) * +item.qty;
const totalAndBundlingRatio = total_price / bundlingTotalPrice;
item.bundling_items = item.item.bundling_items?.map((bundling) => {
if (bundling.item_id) return bundling;
const basePrice =
(bundling.item_rates ?? bundling.base_price) * +item.qty;
(bundling.item_rates ?? bundling.base_price) *
+item.qty *
totalAndBundlingRatio;
const discount = discountPercent * basePrice;
const total = basePrice - discount;

View File

@ -12,11 +12,15 @@ export class VipCodeModel
@Column('varchar', { name: 'code' })
code: string;
@Column('integer', { name: 'discount' })
@Column('integer', { name: 'discount', nullable: true })
discount: number;
@Column('decimal', { nullable: true })
discount_value: number;
@Column('varchar', { name: 'vip_category_id' })
vip_category_id: string;
@ManyToOne(() => VipCategoryModel, (model) => model.vip_codes, {
onDelete: 'CASCADE',
onUpdate: 'CASCADE',

View File

@ -3,4 +3,5 @@ import { BaseEntity } from 'src/core/modules/domain/entities/base.entity';
export interface VipCodeEntity extends BaseEntity {
code: string;
discount: number;
discount_value?: number;
}

View File

@ -16,12 +16,21 @@ export class VipCodeDto extends BaseDto implements VipCodeEntity {
@ApiProperty({
name: 'discount',
type: Number,
required: true,
required: false,
example: 85,
})
@IsNumber()
discount: number;
@ApiProperty({
name: 'discount_value',
type: Number,
required: false,
example: 25000,
})
@IsNumber()
discount_value: number;
@ApiProperty({
name: 'vip_category',
type: Object,