private ArrayList sortBasketItem(CBasket trackingBasket, CPackageItemAdapter v) { int cnt = trackingBasket.GetBasketItemCount(); ArrayList arr = new ArrayList(); for (int i = 0; i < cnt; i++) { CBasketItem bi = trackingBasket.GetBasketItem(i); arr.Add(bi); } MPackage pkg = getPackage(); if (pkg.PackageType.Equals("5") || pkg.PackageType.Equals("10")) { //Bundle arr.Sort(new BasketItemComparatorHightestPriceFirst()); } else if (v.QuantityType.Equals("1")) { //Used arr.Sort(new BasketItemComparatorLowestPriceFirst()); } else { //2 - Free, cheapest come first arr.Sort(new BasketItemComparatorHightestPriceFirst()); } return(arr); }
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); }
protected void accumulateBasket(CBasket used, CBasket freed, CBasket bk) { CBasket tmp = freed; if (bk.BasketType == BasketTypeEnum.Used) { tmp = used; } int cnt = bk.GetBasketItemCount(); for (int i = 0; i < cnt; i++) { CBasketItem bi = bk.GetBasketItem(i); int c = tmp.GetBasketItemCount(); Boolean found = false; for (int j = 0; j < c; j++) { CBasketItem nbi = tmp.GetBasketItem(j); if (bi.Key.Equals(nbi.Key)) { bi.Quantity = bi.Quantity + nbi.Quantity; found = true; break; } } if (!found) { tmp.AddBasketItem(bi); } } }
//public void CopyFrom(CBasket src) //{ // TotalAmount = src.TotalAmount; // int cnt = src.GetBasketItemCount(); // for (int i = 0; i < cnt; i++) // { // CBasketItem bi = src.GetBasketItem(i); // AddBasketItem(bi); // } //} public void CopyEntireFrom(CBasket src) { TotalAmount = src.TotalAmount; BundledAmount = src.BundledAmount; int cnt = src.GetBasketItemCount(); for (int i = 0; i < cnt; i++) { CBasketItem bi = src.GetBasketItem(i); CBasketItem nbi = new CBasketItem(bi.Key, bi.Item, bi.Quantity); nbi.SetFinalDiscount(bi.GetFinalDiscount()); nbi.IsFinalDiscounted = bi.IsFinalDiscounted; nbi.IsPostGift = bi.IsPostGift; nbi.IsTray = bi.IsTray; if (bi.IsPriced()) { nbi.SetUnitPrice(bi.GetUnitPrice()); } nbi.SetDiscount(bi.GetDiscount()); AddBasketItem(nbi); } }
private static void processBasketNode(CBasket bk) { int cnt = bk.GetBasketItemCount(); bk.ClearItem(); for (int i = 0; i < cnt; i++) { CBasketItem bi = bk.GetBasketItem(i); if (bi.Quantity > 0) { bk.AddItem(bi); } } }
private void updateBasketItem(CBasket bi, Hashtable filterHash) { int cnt = bi.GetBasketItemCount(); for (int i = 0; i < cnt; i++) { CBasketItem bki = bi.GetBasketItem(i); if (filterHash.ContainsKey(bki.Key)) { bki.IsPostGift = true; } } }
private CBasket getQualifyItem(CPackageItemAdapter v, CBasket trackingBasket, int required) { CBasket nbk = null; if (v.QuantityType.Equals("1")) { //Used nbk = new CBasket(BasketTypeEnum.Used); } else { //2 = Free/Bonus nbk = new CBasket(BasketTypeEnum.FreeAnnonymous); } int cnt = trackingBasket.GetBasketItemCount(); for (int i = 0; i < cnt; i++) { CBasketItem bi = trackingBasket.GetBasketItem(i); MSelectedItem si = (MSelectedItem)bi.Item; if (v.SelectionType.Equals("1")) { //Service if (v.ServiceID.Equals(si.ServiceID) && (bi.TempLeftQty >= required)) { bi.TempLeftQty = bi.TempLeftQty - required; CBasketItem nbi = new CBasketItem(bi.Key, si, required); nbk.AddBasketItem(nbi); return(nbk); } } else if (v.SelectionType.Equals("2")) { //Item if (v.ItemID.Equals(si.ItemID) && (bi.TempLeftQty >= required)) { bi.TempLeftQty = bi.TempLeftQty - required; CBasketItem nbi = new CBasketItem(bi.Key, si, required); nbk.AddBasketItem(nbi); return(nbk); } } } return(null); }
protected CBasket finalizeBasket(CBasket bskt, BasketTypeEnum retType) { CBasket nbk = new CBasket(retType); if (bskt == null) { return(nbk); } int cnt = bskt.GetBasketItemCount(); for (int i = 0; i < cnt; i++) { CBasketItem bi = bskt.GetBasketItem(i); if (bi.TempLeftQty > 0) { bi.Quantity = bi.TempLeftQty; nbk.AddBasketItem(bi); } } return(nbk); }
/* 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) { //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); }