Compare commits
No commits in common. "109898b076925941c90d1ffdf29c77b03c02e3f8" and "f23a9f3510722b9d2ede3b553144a5f9f784ccac" have entirely different histories.
109898b076
...
f23a9f3510
|
@ -1,43 +0,0 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddDiscountForItemTransaction1726824289989
|
||||
implements MigrationInterface
|
||||
{
|
||||
name = 'AddDiscountForItemTransaction1726824289989';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "transaction_items" ADD "subtotal" numeric`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "transaction_items" ADD "discount_value" numeric`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "transaction_item_breakdowns" ADD "subtotal" numeric`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "transaction_item_breakdowns" ADD "discount_value" numeric`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "transaction_item_breakdowns" ADD "total_price" numeric`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "transaction_item_breakdowns" DROP COLUMN "total_price"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "transaction_item_breakdowns" DROP COLUMN "discount_value"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "transaction_item_breakdowns" DROP COLUMN "subtotal"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "transaction_items" DROP COLUMN "discount_value"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "transaction_items" DROP COLUMN "subtotal"`,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class ChangeColumnName1726830293878 implements MigrationInterface {
|
||||
name = 'ChangeColumnName1726830293878';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "transaction_items" RENAME COLUMN "subtotal" TO "total_net_price"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "transaction_item_breakdowns" RENAME COLUMN "subtotal" TO "total_net_price"`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "transaction_item_breakdowns" RENAME COLUMN "total_net_price" TO "subtotal"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "transaction_items" RENAME COLUMN "total_net_price" TO "subtotal"`,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -52,12 +52,6 @@ export class TransactionItemModel
|
|||
@Column('decimal', { name: 'item_tenant_share_margin', nullable: true })
|
||||
item_tenant_share_margin: number;
|
||||
|
||||
@Column('decimal', { nullable: true })
|
||||
total_net_price: number;
|
||||
|
||||
@Column('decimal', { nullable: true })
|
||||
discount_value: number;
|
||||
|
||||
// calculation data
|
||||
@Column('decimal', { name: 'total_price', nullable: true })
|
||||
total_price: number;
|
||||
|
@ -145,16 +139,6 @@ export class TransactionItemBreakdownModel extends BaseCoreModel<TransactionBund
|
|||
@Column('bigint', { nullable: true })
|
||||
item_rates: number;
|
||||
|
||||
@Column('decimal', { nullable: true })
|
||||
total_net_price: number;
|
||||
|
||||
@Column('decimal', { nullable: true })
|
||||
discount_value: number;
|
||||
|
||||
// calculation data
|
||||
@Column('decimal', { name: 'total_price', nullable: true })
|
||||
total_price: number;
|
||||
|
||||
@Column('decimal', { nullable: true })
|
||||
total_profit_share: number;
|
||||
|
||||
|
|
|
@ -19,8 +19,6 @@ export interface TransactionItemEntity extends BaseCoreEntity {
|
|||
|
||||
// calculation data
|
||||
total_price: number;
|
||||
total_net_price: number;
|
||||
discount_value: number;
|
||||
total_hpp: number;
|
||||
total_profit: number;
|
||||
total_share_tenant: number;
|
||||
|
@ -34,8 +32,6 @@ export interface TransactionBundlingItemEntity extends BaseCoreEntity {
|
|||
item_id: string;
|
||||
item_name: string;
|
||||
hpp: number;
|
||||
total_net_price: number;
|
||||
discount_value: number;
|
||||
base_price: number;
|
||||
item_rates: number;
|
||||
total_price?: number;
|
||||
|
|
|
@ -39,6 +39,7 @@ export class PriceCalculator {
|
|||
if (item.bundling_items) {
|
||||
for (let b = 0; b < item.bundling_items.length; b++) {
|
||||
const bundling = item.bundling_items[b];
|
||||
bundling.total_price = bundling.item_rates ?? bundling.base_price;
|
||||
|
||||
const bundlingPrice = await this.calculateItem(bundling);
|
||||
const bundlingValues = this.calculatePrice(bundlingPrice);
|
||||
|
@ -107,7 +108,7 @@ export class PriceCalculator {
|
|||
const dppValue = calculateFormula(
|
||||
dpp.formula_string,
|
||||
taxes,
|
||||
transaction.total_net_price,
|
||||
transaction.total_price,
|
||||
);
|
||||
|
||||
values['dpp'] = dppValue;
|
||||
|
|
|
@ -161,17 +161,8 @@ export function mappingRevertTransaction(data, type) {
|
|||
});
|
||||
}
|
||||
|
||||
const { payment_sub_total, discount_value, discount_percentage } = data;
|
||||
const discountPercent =
|
||||
discount_value && +discount_value > 0
|
||||
? +discount_value / +payment_sub_total
|
||||
: discount_percentage / 100;
|
||||
const discountValue = payment_sub_total * discountPercent;
|
||||
|
||||
Object.assign(data, {
|
||||
payment_total_net_profit: data.payment_total,
|
||||
discount_value: discountValue,
|
||||
discount_percentage: discountPercent * 100,
|
||||
customer_category_id: data.customer_category?.id ?? null,
|
||||
customer_category_name: data.customer_category?.name ?? null,
|
||||
season_period_id: data.season_period?.id ?? null,
|
||||
|
@ -183,30 +174,10 @@ export function mappingRevertTransaction(data, type) {
|
|||
data.items?.map((item) => {
|
||||
const total_price =
|
||||
Number(item.item.price ?? item.item.base_price) * Number(item.qty);
|
||||
const discount = discountPercent * total_price;
|
||||
const net_price = total_price - discount;
|
||||
const share_margin = item.item.tenant?.share_margin ?? 0;
|
||||
const total_share_tenant =
|
||||
share_margin > 0 ? (Number(share_margin) / 100) * total_price : 0;
|
||||
|
||||
item.bundling_items = item.item.bundling_items?.map((bundling) => {
|
||||
if (bundling.item_id) return bundling;
|
||||
|
||||
const basePrice = bundling.item_rates ?? bundling.base_price;
|
||||
const discount = discountPercent * basePrice;
|
||||
const total = basePrice - discount;
|
||||
|
||||
return {
|
||||
...bundling,
|
||||
item_id: bundling.id,
|
||||
item_name: bundling.name,
|
||||
total_net_price: basePrice,
|
||||
discount_value: discount,
|
||||
total_price: total,
|
||||
id: uuidv4(),
|
||||
};
|
||||
});
|
||||
|
||||
Object.assign(item, {
|
||||
item_id: item.item.id,
|
||||
item_name: item.item.name,
|
||||
|
@ -221,13 +192,20 @@ export function mappingRevertTransaction(data, type) {
|
|||
(bundling) => bundling.name,
|
||||
),
|
||||
breakdown_bundling: item.item.breakdown_bundling,
|
||||
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,
|
||||
item_tenant_share_margin: item.item.tenant?.share_margin ?? null,
|
||||
|
||||
total_net_price: net_price,
|
||||
discount_value: discount,
|
||||
total_price: total_price,
|
||||
total_hpp: Number(item.item.hpp) * Number(item.qty),
|
||||
total_share_tenant: total_share_tenant,
|
||||
|
|
Loading…
Reference in New Issue