Exemplo n.º 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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
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 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);
        }
Exemplo n.º 5
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
            preserveOriginalGroupingTray(output, input);

            output.AddBasket(finalizeBasket(trackingBasket, BasketTypeEnum.AvailableTray));
            output.AddBasket(finalizeBasket(used, BasketTypeEnum.UsedTray));
            output.AddBasket(finalizeBasket(free, BasketTypeEnum.FreeAnnonymousTray));

            return(output);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 10
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);
        }