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 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 isDeductAble(CPackageItemAdapter v, CBasket trackingBasket, int required) { CBasket qualifyBasket = null; if (v.SelectionType.Equals("1") || v.SelectionType.Equals("2")) { qualifyBasket = getQualifyItem(v, trackingBasket, required); } else if (v.SelectionType.Equals("3")) { qualifyBasket = getQualifyItemByGroup(v, trackingBasket, required); } return(qualifyBasket); }
protected int ratioStatus(Hashtable combinedHash, int minumConfigQty, int ratio, CBasket trackingBasket) { CBasket usedAccum = new CBasket(BasketTypeEnum.Used); CBasket freeAccum = new CBasket(BasketTypeEnum.FreeAnnonymous); foreach (String key in combinedHash.Keys) { MBaseModel u = (MBaseModel)combinedHash[key]; CPackageItemAdapter v = new CPackageItemAdapter(u); if ((ratio % minumConfigQty) != 0) { return(-1); } if ((ratio * CUtil.StringToInt(v.Quantity) % minumConfigQty) != 0) { return(-1); } int required = (ratio * CUtil.StringToInt(v.Quantity) / minumConfigQty); CBasket bk = isDeductAble(v, trackingBasket, required); if (bk == null) { //Not enough return(1); } else { //Use returned basket to add item to hash for summing the quantity accumulateBasket(usedAccum, freeAccum, bk); } } lastGoodUsed = usedAccum; lastGoodFree = freeAccum; return(0); }
private CBasket getQualifyItemByGroup(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); } //This should be sorted by Price and sort order depend on Quantity Type //QuantityType = 1, most expensive come first //QuantityType = 2, cheapest come first ArrayList sortedArr = sortBasketItem(trackingBasket, v); int cnt = sortedArr.Count; //trackingBasket.GetBasketItemCount(); for (int i = 0; i < cnt; i++) { CBasketItem bi = (CBasketItem)sortedArr[i]; //trackingBasket.GetBasketItem(i); MSelectedItem si = (MSelectedItem)bi.Item; if (si.ItemCategory.Equals(v.ItemCategoryID) && (bi.TempLeftQty > 0)) { int req = 0; if (required >= bi.TempLeftQty) { req = (int)bi.TempLeftQty; required = required - (int)bi.TempLeftQty; bi.TempLeftQty = 0.00; } else { req = required; bi.TempLeftQty = bi.TempLeftQty - required; required = 0; } CBasketItem nbi = new CBasketItem(bi.Key, si, req); nbk.AddBasketItem(nbi); } if (required <= 0) { break; } } if (required <= 0) { //Got all required return(nbk); } return(null); }