Merge branch 'development' of ssh://git.eigen.co.id:2222/eigen/pos-be into feat/adjustment-report
continuous-integration/drone/push Build is passing Details

pull/98/head
Firman Ramdhani 2024-09-20 18:34:58 +07:00
commit 109898b076
6 changed files with 118 additions and 11 deletions

View File

@ -0,0 +1,43 @@
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"`,
);
}
}

View File

@ -0,0 +1,23 @@
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"`,
);
}
}

View File

@ -52,6 +52,12 @@ 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;
@ -139,6 +145,16 @@ 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;

View File

@ -19,6 +19,8 @@ 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;
@ -32,6 +34,8 @@ 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;

View File

@ -39,7 +39,6 @@ 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);
@ -108,7 +107,7 @@ export class PriceCalculator {
const dppValue = calculateFormula(
dpp.formula_string,
taxes,
transaction.total_price,
transaction.total_net_price,
);
values['dpp'] = dppValue;

View File

@ -161,8 +161,17 @@ 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,
@ -174,10 +183,30 @@ 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,
@ -192,20 +221,13 @@ 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,