private void updateDisplayItem(CBasketItemDisplay bi)
        {
            String          key = String.Format("{0}-{1}-{2}-{3}", bi.SelectionType, bi.ItemID, bi.ServiceID, bi.IsTray);
            CItemPriceAccum hbi = (CItemPriceAccum)priceHash[key];

            if (hbi == null)
            {
                hbi = new CItemPriceAccum();

                hbi.Amount   = bi.Amount;
                hbi.Quantity = bi.Quantity;
                hbi.Discount = bi.Discount;

                priceHash[key] = hbi;
            }
            else
            {
                hbi.Amount   = hbi.Amount + bi.Amount;
                hbi.Quantity = hbi.Quantity + bi.Quantity;
                hbi.Discount = hbi.Discount + bi.Discount;
            }

            hbi.DiscountPerUnit = hbi.Discount / hbi.Quantity;
            hbi.AmountPerUnit   = hbi.Amount / hbi.Quantity;
        }
        private void updateDocumentItemPrice(MAccountDoc doc)
        {
            ObservableCollection <MAccountDocItem> items = vw.AccountItem;
            Hashtable quantityHash = new Hashtable();

            foreach (MAccountDocItem di in items)
            {
                String key = getKey(di);

                String flag = di.ExtFlag;
                if (flag.Equals("D"))
                {
                    continue;
                }

                CItemPriceAccum qbi = (CItemPriceAccum)quantityHash[key];
                if (qbi == null)
                {
                    qbi               = new CItemPriceAccum();
                    qbi.Quantity      = CUtil.StringToDouble(di.Quantity);
                    quantityHash[key] = qbi;
                }
                else
                {
                    qbi.Quantity = qbi.Quantity + CUtil.StringToDouble(di.Quantity);
                }
            }

            foreach (MAccountDocItem di in items)
            {
                String flag = di.ExtFlag;
                if (flag.Equals("D"))
                {
                    continue;
                }

                String          key = getKey(di);
                CItemPriceAccum hbi = (CItemPriceAccum)priceHash[key];

                CItemPriceAccum qdi             = (CItemPriceAccum)quantityHash[key];
                double          qty             = qdi.Quantity;
                double          amt             = 0.00;
                double          unitPrice       = 0.00;
                double          discount        = 0.00;
                double          discountPerUnit = discount / qty;

                if (hbi == null)
                {
                    di.Quantity           = qty.ToString();
                    di.Amount             = "0.00";
                    di.Discount           = "0.00";
                    di.TotalAfterDiscount = "0.00";
                    di.TOTAL_AMT          = "0.00";
                }
                else
                {
                    amt             = hbi.Amount;
                    unitPrice       = amt / qty;
                    discount        = hbi.Discount;
                    discountPerUnit = discount / qty;


                    double itemQty  = CUtil.StringToDouble(di.Quantity);
                    double itemAmt  = unitPrice * itemQty;
                    double itemDisc = discountPerUnit * itemQty;

                    double afterDiscount = itemAmt - itemDisc;

                    di.UnitPrice          = unitPrice.ToString();
                    di.Amount             = itemAmt.ToString();
                    di.Discount           = itemDisc.ToString();
                    di.TotalAfterDiscount = afterDiscount.ToString();
                    di.TOTAL_AMT          = di.TotalAfterDiscount;
                }

                if (!flag.Equals("A"))
                {
                    di.ExtFlag = "E";
                }
            }
        }