feat: calculate discount for bundling

pull/108/head
shancheas 2024-10-08 15:40:54 +07:00
parent e6066b534c
commit 901c67137b
1 changed files with 9 additions and 1 deletions

View File

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