コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: CBasket.cs プロジェクト: pjamenaja/onixlegacy
        //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);
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        private Boolean isItemApplicable(MPackageTrayPriceDiscount pp, CBasketItem bi)
        {
            String        ppSelectType = pp.SelectionType;
            MSelectedItem vs           = (MSelectedItem)bi.Item;


            if ((ppSelectType.Equals("1")) && (vs.SelectionType.Equals("1")))
            {
                //Service
                if (vs.ServiceID.Equals(pp.ServiceId))
                {
                    return(true);
                }
            }
            else if ((ppSelectType.Equals("2")) && (vs.SelectionType.Equals("2")))
            {
                //Item
                if (vs.ItemID.Equals(pp.ItemId))
                {
                    return(true);
                }
            }
            else if ((ppSelectType.Equals("3")) && (vs.SelectionType.Equals("2")))
            {
                //Item Category VS Item

                MInventoryItem vi = (MInventoryItem)vs.ItemObj;
                if (vi.ItemCategory.Equals(pp.CategoryId))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
                }
            }
        }
コード例 #8
0
        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);
        }
コード例 #9
0
ファイル: CBasket.cs プロジェクト: pjamenaja/onixlegacy
        public void AddBasketItem(CBasketItem bi)
        {
            String key = bi.Key;

            items.Add(key, bi);

            arrs.Add(bi);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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;
                }
            }
        }
コード例 #12
0
        public CBasketItemDisplay(CBasketItem bi, BasketTypeEnum bt, int groupNum, int seq, CBasket bk)
        {
            initWeight();

            basket     = bk;
            basketType = bt;
            grpNum     = groupNum;
            sequence   = seq;
            bki        = bi;
            si         = (MSelectedItem)bi.Item;

            amount      = bki.GetAmount();
            totalAmount = bki.GetTotal();
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        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);
                }
            }
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        public CBasketItemDisplay(CTable tb)
        {
            initWeight();

            basketType = (BasketTypeEnum)CUtil.StringToInt(tb.GetFieldValue("BASKET_TYPE"));
            basket     = new CBasket(basketType);


            grpNum   = CUtil.StringToInt(tb.GetFieldValue("GROUP_NO"));
            sequence = CUtil.StringToInt(tb.GetFieldValue("GROUP_NO"));

            double  qty      = CUtil.StringToDouble(tb.GetFieldValue("QUANTITY"));
            double  amt      = CUtil.StringToDouble(tb.GetFieldValue("AMOUNT"));
            double  tot      = CUtil.StringToDouble(tb.GetFieldValue("TOTAL_AMOUNT"));
            double  discount = CUtil.StringToDouble(tb.GetFieldValue("DISCOUNT"));
            Boolean isPriced = tb.GetFieldValue("IS_PRICED").Equals("Y");

            String code = tb.GetFieldValue("CODE");

            sequence = 1;
            id       = tb.GetFieldValue("BILL_SIM_DISPLAY_ID");
            //CTable o = new CTable("");

            si             = new MSelectedItem(tb);
            si.TrayFlag    = tb.GetFieldValue("IS_TRAY");
            isTray         = si.TrayFlag.Equals("Y");
            si.EnabledFlag = "Y";
            si.VoucherID   = tb.GetFieldValue("VOUCHER_ID");
            si.VoucherNo   = tb.GetFieldValue("VOUCHER_CODE");
            si.VoucherName = tb.GetFieldValue("VOUCHER_NAME");
            si.FreeText    = tb.GetFieldValue("FREE_TEXT");

            bki = new CBasketItem(code, si, qty, amt);
            bki.SetDiscount(discount);
            if (qty != 0)
            {
                if (isPriced)
                {
                    bki.SetUnitPrice(amt / qty);
                }
            }

            amount      = amt;
            totalAmount = tot;
        }
コード例 #18
0
        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);
        }
コード例 #19
0
        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);
        }
コード例 #20
0
        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);
        }
コード例 #21
0
        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);
        }
コード例 #22
0
        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);
        }
コード例 #23
0
        //Comparer _comparer = new Comparer(System.Globalization.CultureInfo.CurrentCulture);

        public int Compare(object x, object y)
        {
            //DefaultSellPrice
            CBasketItem bi1 = x as CBasketItem;
            CBasketItem bi2 = y as CBasketItem;

            MSelectedItem si1 = (MSelectedItem)bi1.Item;
            MSelectedItem si2 = (MSelectedItem)bi2.Item;

            double defSellPrice1 = 0.00;
            double defSellPrice2 = 0.00;

            if (si1.SelectionType.Equals("1"))
            {
                //Service
                //Not yet implemented default sell price for Service right now
                defSellPrice1 = 0.00;
            }
            else
            {
                //Item
                defSellPrice1 = CUtil.StringToDouble(si1.DefaultSellPriceItem);
            }

            if (si2.SelectionType.Equals("1"))
            {
                //Service
                //Not yet implemented default sell price for Service right now
                defSellPrice2 = 0.00;
            }
            else
            {
                //Item
                defSellPrice2 = CUtil.StringToDouble(si2.DefaultSellPriceItem);
            }

            return(defSellPrice1.CompareTo(defSellPrice2));
        }
コード例 #24
0
        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);
        }
コード例 #25
0
        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();
        }
コード例 #26
0
        /* 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);
        }
コード例 #27
0
        /* 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);
        }
コード例 #28
0
        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);
        }
コード例 #29
0
        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);
        }
コード例 #30
0
        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);
        }