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);
        }
Esempio n. 2
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);
        }
        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);
                }
            }
        }
Esempio n. 4
0
        //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);
            }
        }
Esempio n. 5
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);
                }
            }
        }
Esempio n. 6
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);
        }
        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);
        }
Esempio n. 9
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);
        }
Esempio n. 10
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);
        }
Esempio n. 11
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);
        }
Esempio n. 12
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);
        }
Esempio n. 13
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);
        }
        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);
        }
Esempio n. 15
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)
        {
            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);
        }