protected void preserveOriginalGroupingTray(CBasketSet output, CBasketSet input)
 {
     output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.UsedTray));
     output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.FreeAnnonymousTray));
     output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.BundledTray));
     output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.Available));
 }
Beispiel #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);
        }
 protected void preserveOriginalGrouping(CBasketSet output, CBasketSet input)
 {
     output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.Used));
     output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.FreeAnnonymous));
     output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.Bundled));
     output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.FreeVoucher));
     output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.AvailableTray));
     output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.PricedTray));
     output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.DiscountedTray));
     output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.UsedTray));
     output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.FreeAnnonymousTray));
     output.AddByArray(input.GetAllBasketByType(BasketTypeEnum.BundledTray));
 }
        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);
        }
        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);
        }
 private static void processBasketSetNode(CBasketSet bset)
 {
     bset.ClearItem();
     foreach (BasketTypeEnum bt in bset.GetBasketTypes())
     {
         ArrayList arr = bset.GetAllBasketByType(bt);
         foreach (CBasket bk in arr)
         {
             processBasketNode(bk);
             if (bk.Items.Count > 0)
             {
                 bset.AddItem(bk);
             }
         }
     }
 }
        protected void copyBasketsExc(CBasketSet dst, CBasketSet src, Hashtable incSet)
        {
            ArrayList types = src.GetBasketTypes();

            foreach (BasketTypeEnum t in types)
            {
                if (!incSet.ContainsKey(t))
                {
                    ArrayList arr = src.GetAllBasketByType(t);
                    if (arr.Count > 0)
                    {
                        dst.AddByArray(arr);
                    }
                }
            }
        }
        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);
        }
Beispiel #9
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);
        }
Beispiel #10
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();
        }
        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);
        }
Beispiel #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)
        {
            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);
        }