private Boolean calculateFinalDiscount(CPrice p) { Boolean matched = false; MPackage pkg = getPackage(); String pricingDef = pkg.DiscountDefinition; MIntervalConfig ivc = new MIntervalConfig(new CTable("")); ivc.DeserializeConfig(pricingDef); CPrice o = null; CBasketItem dummy = new CBasketItem("", null, p.Quantity, p.TotalAmount); if (ivc.SelectionType == 1) { //step o = getStepDiscount(ivc, dummy); } else { //Tier o = getTierDiscount(ivc, dummy); } if (o != null) { res.FinalDiscount = o.DiscountAmount; finalDiscount = res.FinalDiscount; isFinalDiscount = true; matched = true; } return(matched); }
private double calculateRatio(CPrice p) { MPackage pkg = getPackage(); String pricingDef = pkg.DiscountDefinition; MIntervalConfig ivc = new MIntervalConfig(new CTable("")); ivc.DeserializeConfig(pricingDef); CPrice o = null; CBasketItem dummy = new CBasketItem("", null, p.Quantity, p.TotalAmount); //Gui might not see correctly earlier pkg.DiscountMapType = "1"; ivc.TierScopeType = 0; if (ivc.SelectionType == 1) { //step o = getStepDiscount(ivc, dummy); } else { //Tier o = getTierDiscount(ivc, dummy); } if (o != null) { //Use DiscountAmount as a temp field return(o.DiscountAmount); } return(-9999); }
public CPrice getTierPrice(MIntervalConfig ivc, CBasketItem bi) { foreach (MInterval iv in ivc.IntervalItems) { double from = CUtil.StringToDouble(iv.FromValue); double to = CUtil.StringToDouble(iv.ToValue); double value = CUtil.StringToDouble(iv.ConfigValue); if ((bi.Quantity > from) && (bi.Quantity <= to)) { CPrice p = new CPrice(); if (ivc.TierScopeType == 1) { p.TotalAmount = value; p.UnitPrice = value / bi.Quantity; } else { //0 - by unit price p.TotalAmount = value * bi.Quantity; p.UnitPrice = value; } return(p); } } return(null); }
protected CPrice getTierDiscount(MIntervalConfig ivc, CBasketItem bi) { MPackage pkg = getPackage(); double qty = 0.00; if (ivc.MappingType == 0) { //Map by quantity qty = bi.Quantity; } else { //Map by amount qty = bi.GetAmount(); } foreach (MInterval iv in ivc.IntervalItems) { double from = CUtil.StringToDouble(iv.FromValue); double to = CUtil.StringToDouble(iv.ToValue); double value = CUtil.StringToDouble(iv.ConfigValue); if ((qty > from) && (qty <= to)) { CPrice p = new CPrice(); if (ivc.TierScopeType == 0) { //Fixed p.DiscountAmount = value; } else if (ivc.TierScopeType == 1) { //Per unit p.DiscountAmount = bi.Quantity * value; } else { //2 - Percent of amount p.DiscountAmount = (value * bi.GetAmount()) / 100; } return(p); } } return(null); }
private CBasketItem calculatePrice(CBasketItem bi) { MPackage pkg = getPackage(); CBasketItem nbi = new CBasketItem(bi.Key, bi.Item, bi.Quantity); foreach (MPackagePrice pp in pkg.PackageItemPrices) { if (pp.EnabledFlag.Equals("N")) { continue; } if (!isItemApplicable(pp, bi)) { continue; } MIntervalConfig ivc = new MIntervalConfig(new CTable("")); ivc.DeserializeConfig(pp.PricingDefination); CPrice o = null; if (ivc.SelectionType == 1) { //step o = getStepPrice(ivc, bi); } else { //Tier o = getTierPrice(ivc, bi); } if (o != null) { nbi.SetAppliedPackage(pkg); nbi.SetUnitPrice(o.UnitPrice); return(nbi); } } return(null); }
private CBasketItem calculateDiscount(CBasketItem bi) { MPackage pkg = getPackage(); MSelectedItem vi = (MSelectedItem)bi.Item; CBasketItem nbi = new CBasketItem(bi.Key, bi.Item, bi.Quantity); nbi.SetUnitPrice(bi.GetUnitPrice()); foreach (MPackageTrayPriceDiscount pp in pkg.PackageTrayByItems) { if (!isItemApplicable(pp, bi)) { continue; } MIntervalConfig ivc = new MIntervalConfig(new CTable("")); ivc.DeserializeConfig(pp.DiscountDefination); CPrice o = null; if (ivc.SelectionType == 1) { //step o = getStepDiscount(ivc, bi); } else { //Tier o = getTierDiscount(ivc, bi); } if (o != null) { nbi.SetAppliedPackage(pkg); nbi.SetDiscount(o.DiscountAmount); return(nbi); } } return(null); }
private CBasketItem calculatePrice(CBasketItem bi) { CBasketItem nbi = new CBasketItem(bi.Key, bi.Item, bi.Quantity); MSelectedItem si = (MSelectedItem)bi.Item; String pricingDef = si.PricingDefination; if (si.SelectionType.Equals("1")) { pricingDef = si.ServicePricingDefinition; } MIntervalConfig ivc = new MIntervalConfig(new CTable("")); ivc.DeserializeConfig(pricingDef); CPrice o = null; if (ivc.SelectionType == 1) { //step o = getStepPrice(ivc, bi); } else { //Tier o = getTierPrice(ivc, bi); } if (o != null) { nbi.SetAppliedPackage(getPackage()); nbi.SetUnitPrice(o.UnitPrice); return(nbi); } return(null); }
private CBasketItem calculatePrice(CBasketItem bi) { MPackage pkg = getPackage(); MIntervalConfig ivc = null; CPrice o = null; Boolean applicable = false; CBasketItem nbi = new CBasketItem(bi.Key, bi.Item, bi.Quantity); foreach (MPackageTrayPriceDiscount pp in pkg.PackageTrayByItems) { if (pp.EnabledFlag.Equals("N")) { continue; } if (!isItemApplicable(pp, bi)) { continue; } //Applicable here applicable = true; ivc = new MIntervalConfig(new CTable("")); ivc.DeserializeConfig(pp.PricingDefination); o = null; if (ivc.SelectionType == 1) { //step o = getStepPrice(ivc, bi); } else { //Tier o = getTierPrice(ivc, bi); } if (o != null) { //Got the price nbi.SetAppliedPackage(pkg); nbi.SetUnitPrice(o.UnitPrice); return(nbi); } } //Applicable but price not match here, or not applicable for all if (!applicable) { //Not applicable for all return(null); } //Get Default Price here MSelectedItem si = (MSelectedItem)bi.Item; ivc = new MIntervalConfig(new CTable("")); String pricingDef = si.PricingDefination; if (si.SelectionType.Equals("1")) { pricingDef = si.ServicePricingDefinition; } ivc.DeserializeConfig(pricingDef); o = null; if (ivc.SelectionType == 1) { //step o = getStepPrice(ivc, bi); } else { //Tier o = getTierPrice(ivc, bi); } if (o != null) { nbi.SetAppliedPackage(pkg); nbi.SetUnitPrice(o.UnitPrice); return(nbi); } return(null); }
public CPrice getStepPrice(MIntervalConfig ivc, CBasketItem bi) { ArrayList intervals = new ArrayList(); int idx = 0; foreach (MInterval iv in ivc.IntervalItems) { iv.Used = 0.00; intervals.Add(iv); idx++; } if (intervals.Count <= 0) { return(null); } double left = bi.Quantity; int cnt = ivc.IntervalItems.Count; idx = 0; while (left > 0) { MInterval iv = (MInterval)intervals[idx]; double from = CUtil.StringToDouble(iv.FromValue); double to = CUtil.StringToDouble(iv.ToValue); double value = CUtil.StringToDouble(iv.ConfigValue); double gap = to - from; iv.RepeatCount++; double used = 0.00; if (left > gap) { left = left - gap; used = gap; } else { used = left; left = 0.00; } iv.Used = iv.Used + used; idx++; if (idx >= cnt) { idx = 0; } } double total = 0.00; foreach (MInterval vi in intervals) { if (ivc.StepScopeType == 1) { total = total + vi.RepeatCount * CUtil.StringToDouble(vi.ConfigValue); } else { //0 - by unit price total = total + vi.Used * CUtil.StringToDouble(vi.ConfigValue); } } CPrice p = new CPrice(); p.TotalAmount = total; p.UnitPrice = total / bi.Quantity; return(p); }
protected CPrice getStepDiscount(MIntervalConfig ivc, CBasketItem bi) { ArrayList intervals = new ArrayList(); MPackage pkg = getPackage(); int idx = 0; foreach (MInterval iv in ivc.IntervalItems) { iv.Used = 0.00; intervals.Add(iv); idx++; } double qty = 0.00; if (ivc.MappingType == 0) { qty = bi.Quantity; } else { //Map by amount //We can use both total bill amount or amount that we use for looking up qty = bi.GetAmount(); } double left = qty; int cnt = ivc.IntervalItems.Count; idx = 0; while (left > 0) { MInterval iv = (MInterval)intervals[idx]; double from = CUtil.StringToDouble(iv.FromValue); double to = CUtil.StringToDouble(iv.ToValue); double value = CUtil.StringToDouble(iv.ConfigValue); double gap = to - from; iv.RepeatCount++; double used = 0.00; if (left > gap) { left = left - gap; used = gap; } else { used = left; left = 0.00; } iv.Used = iv.Used + used; idx++; if (idx >= cnt) { idx = 0; } } double total = 0.00; foreach (MInterval vi in intervals) { if (ivc.TierScopeType == 0) { //Fixed total = total + vi.RepeatCount * CUtil.StringToDouble(vi.ConfigValue); } else if (ivc.TierScopeType == 1) { //Per unit if (ivc.MappingType == 0) { //Map by quantity total = total + vi.Used * CUtil.StringToDouble(vi.ConfigValue); } } else { //2 - Percent of amount if (ivc.MappingType == 1) { //Map by amount //For step, we can use the vi.Used from the amount that we split it up total = total + vi.Used * CUtil.StringToDouble(vi.ConfigValue) / 100; } } } CPrice p = new CPrice(); p.DiscountAmount = total; return(p); }