private CBasketSet finalizeOutput(CBasketSet input, CBasket trackingBasket, CBasket used, CBasket free) { CBasketSet output = new CBasketSet(); if ((used == null) && (free == null)) { return(input); } //The original ones preserveOriginalGrouping(output, input); output.AddBasket(finalizeBasket(trackingBasket, BasketTypeEnum.Available)); CBasket bundled = finalizeBasket(used, BasketTypeEnum.Bundled); output.AddBasket(bundled); int cnt = bundled.GetBasketItemCount(); for (int i = 0; i < cnt; i++) { CBasketItem bi = bundled.GetBasketItem(i); bi.SetUnitPrice(0.00); } MPackage pkg = getPackage(); bundled.SetAppliedPackage(getPackage()); bundled.BundledAmount = triedCount * CUtil.StringToDouble(pkg.BundleAmount); return(output); }
/* Return array of BasketSet, return null if package not applicable */ /* * Basket(Available) = {A:10, C:2, D:7} * Basket(Used) = {B:3} * Basket(Free) = {E:1} * BasketSet = {A={A:10, C:2, D:7}, U={B:3}, F={E:1}} */ public override CBasketSet ApplyPakageLogic(CBasketSet inBasket) { if (!isPackageEligible(res, null, false)) { res.SetInputBasketSet(inBasket.Clone()); res.SetOutputBasketSet(inBasket); addProcessingResult(res); return(inBasket); } Hashtable accumHash = getAccumulateHash(inBasket); Hashtable filterHash = getEligibleItemsHash(accumHash); CPrice accum = getAccumulatePrice(filterHash); CBasketSet output = finalizeOutput(inBasket, filterHash, accum); res.SetInputBasketSet(inBasket.Clone()); res.SetOutputBasketSet(output); addProcessingResult(res); if (giftCount <= 0) { res.SetErrorCode("ERROR_NO_PROMOTION_MATCH"); res.SetStatus(ProcessingResultStatus.ProcessingFail); } else { res.SetStatus(ProcessingResultStatus.ProcessingSuccess); } return(output); }
protected void preserveOriginalGroupingTray(CBasketSet output, CBasketSet input) { output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.UsedTray)); output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.FreeAnnonymousTray)); output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.BundledTray)); output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.Available)); }
private CBasketSet finalizeOutput(CBasketSet input, Hashtable filterHash) { CBasketSet interim = new CBasketSet(); MPackage pkg = getPackage(); ArrayList types = input.GetBasketTypes(); foreach (BasketTypeEnum bt in types) { ArrayList baskets = input.GetAllBasketByType(bt); foreach (CBasket bk in baskets) { if (bt == BasketTypeEnum.Bundled) { if (isInBasketType(bt)) { totalBundleAmt = totalBundleAmt + bk.BundledAmount; } } CBasket nbk = new CBasket(bt); nbk.CopyEntireFrom(bk); if (isInBasketType(bk.BasketType)) { updateBasketItem(nbk, filterHash); } interim.AddBasket(nbk); } } return(interim); }
public CBasketSet MergeUsedToAvailable(CBasketSet inBasket, Boolean trayFlag) { BasketTypeEnum type1 = BasketTypeEnum.Available; BasketTypeEnum type2 = BasketTypeEnum.Used; String name = "MergeUsedToAvailable"; if (trayFlag) { type1 = BasketTypeEnum.AvailableTray; type2 = BasketTypeEnum.UsedTray; name = name + "Tray"; } CBasketSet output = new CBasketSet(); CProcessingResult res = new CProcessingResult(name); res.SetInputBasketSet(inBasket.Clone()); ArrayList useds = inBasket.GetAllBasketByType(type2); ArrayList avails = inBasket.GetAllBasketByType(type1); if (avails != null) { foreach (CBasket a in avails) { //Move the original 'Available' basket CBasket na = new CBasket(type1); na.CopyEntireFrom(a); output.AddBasket(na); } } if (useds != null) { foreach (CBasket u in useds) { CBasket nb = new CBasket(type1); nb.CopyEntireFrom(u); output.AddBasket(nb); } } Hashtable filterSet = new Hashtable(); filterSet[type1] = null; filterSet[type2] = null; copyBasketsExc(output, inBasket, filterSet); res.IsOperation = true; res.SetOutputBasketSet(output); res.SetStatus(ProcessingResultStatus.ProcessingSuccess); addProcessingResult(res); return(output); }
public CBasketSet Clone() { CBasketSet output = new CBasketSet(); foreach (BasketTypeEnum bt in types) { ArrayList arr = (ArrayList)baskets[bt]; output.AddByArray(arr); } return(output); }
private Hashtable getAccumulateHash(CBasketSet inBasket) { Hashtable hash = new Hashtable(); ArrayList types = inBasket.GetBasketTypes(); foreach (BasketTypeEnum bt in types) { if (!isInBasketType(bt)) { continue; } ArrayList arr = inBasket.GetAllBasketByType(bt); foreach (CBasket bs in arr) { int cnt = bs.GetBasketItemCount(); for (int i = 0; i < cnt; i++) { CBasketItem bi = bs.GetBasketItem(i); if (bi.IsFinalDiscounted) { //Don't need to discount it again continue; } String key = bi.Key; CPrice p = null; //At this point, the Amount of Bundle items is 0.00 (will be added in later step) if (!hash.ContainsKey(key)) { p = new CPrice(); p.Quantity = bi.Quantity; p.TotalAmount = bi.GetTotal(); hash.Add(key, p); } else { p = (CPrice)hash[key]; p.Quantity = p.Quantity + bi.Quantity; p.TotalAmount = p.TotalAmount + bi.GetTotal(); } } } } return(hash); }
protected void preserveOriginalGrouping(CBasketSet output, CBasketSet input) { output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.Used)); output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.FreeAnnonymous)); output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.Bundled)); output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.FreeVoucher)); output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.AvailableTray)); output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.PricedTray)); output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.DiscountedTray)); output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.UsedTray)); output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.FreeAnnonymousTray)); output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.BundledTray)); }
public static CBasketSet CreateInitialBasketSet(ObservableCollection <MSelectedItem> selectedItems) { Hashtable tmps = new Hashtable(); CBasket abk = new CBasket(BasketTypeEnum.Available); CBasket tbk = new CBasket(BasketTypeEnum.AvailableTray); CBasketSet bks = new CBasketSet(); foreach (MSelectedItem v in selectedItems) { if (v.EnabledFlag.Equals("N")) { continue; } String key = String.Format("{0}-{1}", v.TrayFlag, v.Key); CBasketItem o = (CBasketItem)tmps[key]; if (o == null) { CBasketItem bi = new CBasketItem(v.Key, v, CUtil.StringToDouble(v.ItemQuantity)); tmps[key] = bi; if (v.TrayFlag.Equals("Y")) { tbk.AddBasketItem(bi); bi.IsTray = true; } else { abk.AddBasketItem(bi); bi.IsTray = false; } } else { o.Quantity = o.Quantity + CUtil.StringToDouble(v.ItemQuantity); } } if (tbk.GetBasketItemCount() > 0) { bks.AddBasket(tbk); } if (abk.GetBasketItemCount() > 0) { bks.AddBasket(abk); } return(bks); }
protected void copyBasketsExc(CBasketSet dst, CBasketSet src, Hashtable incSet) { ArrayList types = src.GetBasketTypes(); foreach (BasketTypeEnum t in types) { if (!incSet.ContainsKey(t)) { ArrayList arr = src.GetAllBasketByType(t); if (arr.Count > 0) { dst.AddByArray(arr); } } } }
private static void processBasketSetNode(CBasketSet bset) { bset.ClearItem(); foreach (BasketTypeEnum bt in bset.GetBasketTypes()) { ArrayList arr = bset.GetAllBasketByType(bt); foreach (CBasket bk in arr) { processBasketNode(bk); if (bk.Items.Count > 0) { bset.AddItem(bk); } } } }
private static CProcessingResultJob createJobResultNode(CProcessingResult rs) { CProcessingResultJob j = new CProcessingResultJob(rs); CBasketSet inset = rs.GetInputBasketSet(); processBasketSetNode(inset); CBasketSet outset = rs.GetOutputBasketSet(); processBasketSetNode(outset); j.AddItem(inset); j.AddItem(outset); return(j); }
private CBasketSet finalizeOutput(CBasketSet input, CBasket trackingBasket, CBasket used, CBasket free) { CBasketSet output = new CBasketSet(); if ((used == null) && (free == null)) { return(input); } //The original ones preserveOriginalGroupingTray(output, input); output.AddBasket(finalizeBasket(trackingBasket, BasketTypeEnum.AvailableTray)); output.AddBasket(finalizeBasket(used, BasketTypeEnum.UsedTray)); output.AddBasket(finalizeBasket(free, BasketTypeEnum.FreeAnnonymousTray)); return(output); }
private CBasketSet finalizeOutput(CBasketSet input, CBasket trackingBasket, CBasket used, CBasket free) { CBasketSet output = new CBasketSet(); if ((used == null) && (free == null)) { return(input); } //The original ones preserveOriginalGrouping(output, input); output.AddBasket(finalizeBasket(trackingBasket, BasketTypeEnum.Available)); output.AddBasket(finalizeBasket(used, BasketTypeEnum.Used)); if (triedCount > 0) { MPackage pkg = getPackage(); ObservableCollection <MPackageVoucher> gifts = pkg.PackageVoucherFree; CBasket gbsk = new CBasket(BasketTypeEnum.FreeVoucher); foreach (MPackageVoucher g in gifts) { if (g.EnabledFlag.Equals("N")) { continue; } MSelectedItem si = createSelectedItem(g); CBasketItem bi = new CBasketItem(si.Key, si, CUtil.StringToInt(g.Quantity) * triedCount); gbsk.AddBasketItem(bi); } if (gbsk.GetBasketItemCount() > 0) { output.AddBasket(gbsk); } } return(output); }
private double getSumAmount(CBasketSet input, BasketTypeEnum type) { ArrayList baskets = input.GetAllBasketByType(type); if (baskets == null) { return(0.00); } double total = 0.00; foreach (CBasket bk in baskets) { BasketTypeEnum bt = bk.BasketType; if (type != bt) { continue; } if (!isInBasketType(bt)) { continue; } if (bt == BasketTypeEnum.Bundled) { total = total + bk.BundledAmount; } else { int cnt = bk.GetBasketItemCount(); for (int i = 0; i < cnt; i++) { CBasketItem bi = bk.GetBasketItem(i); total = total + bi.GetAmount(); } } } return(total); }
/* Return array of BasketSet, return null if package not applicable */ /* * Basket(Available) = {A:10, C:2, D:7} * Basket(Used) = {B:3} * Basket(Free) = {E:1} * BasketSet = {A={A:10, C:2, D:7}, U={B:3}, F={E:1}} */ public override CBasketSet ApplyPakageLogic(CBasketSet inBasket) { if (!isPackageEligible(res, null, false)) { res.SetInputBasketSet(inBasket.Clone()); res.SetOutputBasketSet(inBasket); addProcessingResult(res); return(inBasket); } Hashtable accumHash = getAccumulateHash(inBasket); Hashtable filterHash = getEligibleItemsHash(accumHash); //CPrice accum = getAccumulatePrice(filterHash); //totalBundleAmt created in finalizeOutput() and used in getAccumulatePrice() CBasketSet output = finalizeOutput(inBasket, filterHash); CPrice accum = getAccumulatePrice(filterHash); res.SetInputBasketSet(inBasket.Clone()); res.SetOutputBasketSet(output); Boolean priceMatched = calculateFinalDiscount(accum); addProcessingResult(res); if ((filterHash.Count <= 0) || (!priceMatched)) { res.SetErrorCode("ERROR_NO_PROMOTION_MATCH"); res.SetStatus(ProcessingResultStatus.ProcessingFail); } else { res.SetStatus(ProcessingResultStatus.ProcessingSuccess); } return(output); }
public static void CreateDisplayView(CBasketSet basketSet, MBillSimulate bsim, ItemDisplayUpdate callback) { ArrayList sorted = new ArrayList(); bsim.ResultItemsCTable.Clear(); bsim.ClearPromotionItem("BILL_RESULT_ITEM"); bsim.ClearPromotionItem("BILL_FREE_ITEM"); bsim.ClearPromotionItem("BILL_VOUCHER_ITEM"); bsim.ClearPromotionItem("BILL_POSTGIFT_ITEM"); double total = 0.00; ArrayList bts = basketSet.GetBasketTypes(); foreach (BasketTypeEnum bt in bts) { ArrayList arr = basketSet.GetAllBasketByType(bt); int grp = 1; foreach (CBasket bk in arr) { MPackage pkg = bk.GetAppliedPackage(); int cnt = bk.GetBasketItemCount(); int seq = 0; for (int j = 0; j < cnt; j++) { CBasketItem bi = bk.GetBasketItem(j); if (bi.Quantity > 0) { CBasketItemDisplay bid = new CBasketItemDisplay(bi, bt, grp, seq, bk); seq++; bid.SetPromotion(pkg); if (bt.ToString().Contains("Tray")) { bid.IsTray = true; } if ((bt == BasketTypeEnum.FreeAnnonymous) || (bt == BasketTypeEnum.FreeAnnonymousTray)) { //bsim.FreeItems.Add(bid); bsim.AddPromotionItem(bid, "BILL_FREE_ITEM"); } else if (bt == BasketTypeEnum.FreeVoucher) { //bsim.VoucherItems.Add(bid); bsim.AddPromotionItem(bid, "BILL_VOUCHER_ITEM"); } else if (bt == BasketTypeEnum.PostFree) { //bsim.PostGiftItems.Add(bid); bsim.AddPromotionItem(bid, "BILL_POSTGIFT_ITEM"); } else { sorted.Add(bid); } } } grp++; } } sorted.Sort(new SelectedItemComparator()); total = populateResultItems(bsim, "BILL_RESULT_ITEM", sorted, callback); bsim.TotalAmount = total.ToString(); bsim.DiscountAmount = totalFinalDiscount.ToString(); bsim.NetAmount = (total - totalFinalDiscount).ToString(); }
/* Create BasketSet */ public static CBasketSet PromotionProcessing(MCompanyPackage companyPackage, CBasketSet inBskSet, MBaseModel bill) { CBasketSet tmpBs = inBskSet; resultsArr.Clear(); totalFinalDiscount = 0.00; ArrayList pkgArr = new ArrayList(); pkgArr.Add(companyPackage.TrayPackageGroup); pkgArr.Add(companyPackage.TrayPricePackage); pkgArr.Add(companyPackage.GroupingPackage); pkgArr.Add(companyPackage.PricingPackage); pkgArr.Add(companyPackage.DiscountPackage); pkgArr.Add(companyPackage.FinalDiscountPackage); pkgArr.Add(companyPackage.PostGiftPackage); /* Tray Process Grouping ... until Post Gift */ for (int i = 1; i <= 7; i++) { ObservableCollection <MCompanyPackage> pkgList = (ObservableCollection <MCompanyPackage>)pkgArr[i - 1]; foreach (MCompanyPackage cp in pkgList) { if (!cp.ExtFlag.Equals("D")) { MPackage pkg = getLoadedPackage(cp.PackageGroup, cp.PackageID); CPromotionProcessor pp = getPromotionProcessor(pkg, bill); CBasketSet outBs = pp.ApplyPakageLogic(tmpBs); if (pp is CPromotionProcessorFinalDiscount) { CPromotionProcessorFinalDiscount fd = (CPromotionProcessorFinalDiscount)pp; if (fd.IsFinalDiscount) { totalFinalDiscount = totalFinalDiscount + fd.FinalDiscount; } } collectResults(pp.GetProcessingResults()); //Use output as an input in the next try tmpBs = outBs; } } if (i == 1) { /* Post Tray Grouping processing */ CPromotionProcessorOperation opt1 = new CPromotionProcessorOperation(null, CLanguage.getValue("pkg_group_operation"), bill); CBasketSet mrg = opt1.MergeUsedToAvailable(tmpBs, true); CBasketSet sum1 = opt1.SumInGroup(mrg, BasketTypeEnum.FreeAnnonymousTray); CBasketSet sum2 = opt1.SumInGroup(sum1, BasketTypeEnum.AvailableTray); collectResults(opt1.GetProcessingResults()); tmpBs = sum2; } else if (i == 3) { /* Post Grouping processing */ CPromotionProcessorOperation opt1 = new CPromotionProcessorOperation(null, CLanguage.getValue("pkg_group_operation"), bill); CBasketSet mrg = opt1.MergeUsedToAvailable(tmpBs, false); CBasketSet sum1 = opt1.SumInGroup(mrg, BasketTypeEnum.FreeAnnonymous); CBasketSet sum2 = opt1.SumInGroup(sum1, BasketTypeEnum.Available); collectResults(opt1.GetProcessingResults()); tmpBs = sum2; } else if (i == 4) { MPackage defPkg = new MPackage(new CTable("")); defPkg.PackageName = CLanguage.getValue("pkg_default_price"); /* Post Pricing processing */ CPromotionProcessor def1 = new CPromotionProcessorPricingDefault(defPkg, CLanguage.getValue("pkg_group_pricing"), bill); CBasketSet defBs = def1.ApplyPakageLogic(tmpBs); collectResults(def1.GetProcessingResults()); tmpBs = defBs; } } return(tmpBs); }
public void SetInputBasketSet(CBasketSet bks) { inpBs = bks; inpBs.Direction = "INPUT"; }
/* Return array of BasketSet, return null if package not applicable */ /* * Basket(Available) = {A:10, C:2, D:7} * Basket(Used) = {B:3} * Basket(Free) = {E:1} * BasketSet = {A={A:10, C:2, D:7}, U={B:3}, F={E:1}} */ public override CBasketSet ApplyPakageLogic(CBasketSet inBasket) { //Support only first one Available type basket CBasket avBskt = inBasket.GetBasket(BasketTypeEnum.AvailableTray, 0); if (!isPackageEligible(res, avBskt, true)) { res.SetInputBasketSet(inBasket.Clone()); res.SetOutputBasketSet(inBasket); addProcessingResult(res); return(inBasket); } loadPackagePriceDefinitions(); int cnt = avBskt.GetBasketItemCount(); int matchCnt = 0; CBasket nb = new CBasket(BasketTypeEnum.PricedTray); CBasket db = new CBasket(BasketTypeEnum.DiscountedTray); CBasket absk = new CBasket(BasketTypeEnum.AvailableTray); //For each item in the "AvailableTray" basket for (int i = 0; i < cnt; i++) { CBasketItem bi = avBskt.GetBasketItem(i); CBasketItem bo = calculatePrice(bi); if (bo == null) { //Move to AvailableTray but in the new basket absk.AddBasketItem(bi); } else { matchCnt++; CBasketItem di = calculateDiscount(bo); if (di == null) { nb.AddBasketItem(bo); } else { db.AddBasketItem(di); } } } CBasketSet output = new CBasketSet(); if (nb.GetBasketItemCount() > 0) { output.AddBasket(nb); } if (db.GetBasketItemCount() > 0) { output.AddBasket(db); } if (absk.GetBasketItemCount() > 0) { output.AddBasket(absk); } Hashtable filterSet = new Hashtable(); filterSet[BasketTypeEnum.AvailableTray] = null; copyBasketsExc(output, inBasket, filterSet); if (matchCnt <= 0) { res.SetErrorCode("ERROR_NO_PROMOTION_MATCH"); res.SetStatus(ProcessingResultStatus.ProcessingFail); } else { res.SetStatus(ProcessingResultStatus.ProcessingSuccess); } res.SetInputBasketSet(inBasket.Clone()); res.SetOutputBasketSet(output); addProcessingResult(res); return(output); }
public virtual CBasketSet ApplyPakageLogic(CBasketSet inBasket) { return(null); }
public void SetOutputBasketSet(CBasketSet bks) { outBs = bks; outBs.Direction = "OUTPUT"; }
/* Return array of BasketSet, return null if package not applicable */ /* * Basket(Available) = {A:10, C:2, D:7} * Basket(Used) = {B:3} * Basket(Free) = {E:1} * BasketSet = {A={A:10, C:2, D:7}, U={B:3}, F={E:1}} */ public override CBasketSet ApplyPakageLogic(CBasketSet inBasket) { CBasket avBskt = inBasket.GetBasket(BasketTypeEnum.Available, 0); if (!isPackageEligible(res, avBskt, true)) { res.SetInputBasketSet(inBasket.Clone()); res.SetOutputBasketSet(inBasket); addProcessingResult(res); return(inBasket); } loadAllPossibleUsedAndFree(); int multiplier = minumConfigQty; Boolean done = false; int goodBasketCnt = 0; CBasket trackingBasket = null; CBasket lastTrackingBkt = null; while (!done) { trackingBasket = new CBasket(BasketTypeEnum.Available); int cnt = avBskt.GetBasketItemCount(); for (int i = 0; i < cnt; i++) { CBasketItem bi = avBskt.GetBasketItem(i); //Keep current amount of each item in the basket CBasketItem nbi = new CBasketItem(bi.Key, bi.Item, bi.Quantity); trackingBasket.AddBasketItem(nbi); } int status = ratioStatus(combinedHash, minumConfigQty, multiplier, trackingBasket); if (status == 0) { //Good basket are already kept lastTrackingBkt = trackingBasket; lastSuccessMultiplier = multiplier; triedCount++; goodBasketCnt++; } else if (status == 1) { done = true; } multiplier++; } if (goodBasketCnt <= 0) { //Unable to find the best match res.SetErrorCode("ERROR_NO_PROMOTION_MATCH"); res.SetStatus(ProcessingResultStatus.ProcessingFail); } else { res.SetStatus(ProcessingResultStatus.ProcessingSuccess); } CBasketSet output = finalizeOutput(inBasket, lastTrackingBkt, getLastGoodUsedBasket(), getLastGoodFreeBasket()); res.SetInputBasketSet(inBasket.Clone()); res.SetOutputBasketSet(output); addProcessingResult(res); return(output); }
/* Return array of BasketSet, return null if package not applicable */ /* * Basket(Available) = {A:10, C:2, D:7} * Basket(Used) = {B:3} * Basket(Free) = {E:1} * BasketSet = {A={A:10, C:2, D:7}, U={B:3}, F={E:1}} */ public override CBasketSet ApplyPakageLogic(CBasketSet inBasket) { ArrayList priceds = inBasket.GetAllBasketByType(BasketTypeEnum.Priced); CBasketSet output = new CBasketSet(); int matchCnt = 0; if (!isPackageEligible(res, null, false)) { res.SetInputBasketSet(inBasket.Clone()); res.SetOutputBasketSet(inBasket); addProcessingResult(res); return(inBasket); } loadPackageDiscountDefinitions(); if (priceds == null) { priceds = new ArrayList(); } foreach (CBasket b in priceds) { int c = b.GetBasketItemCount(); CBasket nb = new CBasket(BasketTypeEnum.Discounted); CBasket absk = new CBasket(BasketTypeEnum.Priced); for (int i = 0; i < c; i++) { CBasketItem bi = b.GetBasketItem(i); CBasketItem bo = calculateDiscount(bi); if (bo != null) { matchCnt++; nb.AddBasketItem(bo); } else { //Move to Priced but in the new basket absk.AddBasketItem(bi); } } if (nb.GetBasketItemCount() > 0) { output.AddBasket(nb); } if (absk.GetBasketItemCount() > 0) { output.AddBasket(absk); } } Hashtable filterSet = new Hashtable(); filterSet[BasketTypeEnum.Priced] = null; copyBasketsExc(output, inBasket, filterSet); if (matchCnt <= 0) { res.SetErrorCode("ERROR_NO_PROMOTION_MATCH"); res.SetStatus(ProcessingResultStatus.ProcessingFail); } else { res.SetStatus(ProcessingResultStatus.ProcessingSuccess); } res.SetInputBasketSet(inBasket.Clone()); res.SetOutputBasketSet(output); addProcessingResult(res); return(output); }
/* Return array of BasketSet, return null if package not applicable */ /* * Basket(Available) = {A:10, C:2, D:7} * Basket(Used) = {B:3} * Basket(Free) = {E:1} * BasketSet = {A={A:10, C:2, D:7}, U={B:3}, F={E:1}} */ public override CBasketSet ApplyPakageLogic(CBasketSet inBasket) { //Do nothing return(inBasket); }
private CBasketSet finalizeOutput(CBasketSet input, Hashtable filterHash, CPrice accum) { CBasketSet interim = new CBasketSet(); MPackage pkg = getPackage(); double totalBundleAmt = getSumAmount(input, BasketTypeEnum.Bundled); accum.TotalAmount = accum.TotalAmount + totalBundleAmt; double ratio = calculateRatio(accum); if (ratio > 0) { ObservableCollection <MPackageVoucher> gifts = pkg.PackagePostGiftFrees; CBasket nbk = new CBasket(BasketTypeEnum.PostFree); foreach (MPackageVoucher g in gifts) { if (g.EnabledFlag.Equals("N")) { continue; } double qty = CUtil.StringToDouble(g.Quantity) * ratio; if (qty > 0) { MSelectedItem si = createSelectedItem(g); CBasketItem nbi = new CBasketItem(si.Key, si, qty); nbk.AddBasketItem(nbi); } } if (nbk.GetBasketItemCount() > 0) { interim.AddBasket(nbk); giftCount++; } } //Copy the originals to output ArrayList types = input.GetBasketTypes(); foreach (BasketTypeEnum bt in types) { ArrayList baskets = input.GetAllBasketByType(bt); foreach (CBasket bk in baskets) { CBasket obk = new CBasket(bt); obk.CopyEntireFrom(bk); if (isInBasketType(bk.BasketType) && (giftCount > 0)) { updateBasketItem(obk, filterHash); } interim.AddBasket(obk); } } return(interim); }
public CBasketSet SumInGroup(CBasketSet inBasket, BasketTypeEnum bt) { CBasketSet output = new CBasketSet(); CProcessingResult res = new CProcessingResult("SumInGroup-" + bt.ToString()); res.SetInputBasketSet(inBasket.Clone()); Hashtable quantities = new Hashtable(); Hashtable objects = new Hashtable(); ArrayList keys = new ArrayList(); ArrayList items = inBasket.GetAllBasketByType(bt); if (items == null) { items = new ArrayList(); } foreach (CBasket b in items) { int cnt = b.GetBasketItemCount(); for (int i = 0; i < cnt; i++) { CBasketItem bi = b.GetBasketItem(i); object o = quantities[bi.Key]; if (o == null) { quantities[bi.Key] = bi.Quantity; objects[bi.Key] = bi; keys.Add(bi.Key); } else { double tmp = (double)quantities[bi.Key]; tmp = tmp + bi.Quantity; quantities[bi.Key] = tmp; } } } CBasket bkt = new CBasket(bt); foreach (String k in keys) { CBasketItem bi = (CBasketItem)objects[k]; double qty = (double)quantities[k]; CBasketItem bki = new CBasketItem(k, bi.Item, qty); bkt.AddBasketItem(bki); } if (bkt.GetBasketItemCount() > 0) { output.AddBasket(bkt); } Hashtable filterSet = new Hashtable(); filterSet[bt] = null; copyBasketsExc(output, inBasket, filterSet); res.IsOperation = true; res.SetOutputBasketSet(output); res.SetStatus(ProcessingResultStatus.ProcessingSuccess); addProcessingResult(res); return(output); }
public void AddItem(CBasketSet bs) { childs.Add(bs); }