Exemple #1
0
        public static IState VoidAdjustedItem(Hashtable data)
        {
            /* when the cancel menu(key) selected with quantity
             * search the sale list to find items
             * whose product is equal to product to be cancel and
             * whose remaing quantity is equal to at least quantity to be cancel and
             * whose unit price has not been found yet in other words cancel menu does not contains the item with same unit price
             * define the quantity and amount of item to be cancel and add the cancel menu
             */
            IProduct adjustedPoduct = (IProduct)data["Product"];
            Decimal  quantity       = (Decimal)data["Quantity"];

            /* unitprices contains the information of how much item was sold with the corresponding unitprice
             * when an item is added to cancel menu relating data is removed
             * so no item with same price could be add to list
             */
            System.Collections.Generic.Dictionary <decimal, decimal> unitprices
                = (System.Collections.Generic.Dictionary <decimal, decimal>)data["UnitPrices"];

            /* Cancel menu contains the items with
             * quantity to be cancel
             * item name
             * unit price * quantity to be cancel
             */
            MenuList cancelMenu = new MenuList();

            foreach (FiscalItem fiscalItem in cr.Document.Items)
            {
                if (fiscalItem is SalesItem && fiscalItem.Product.Id == adjustedPoduct.Id && unitprices.ContainsKey(fiscalItem.UnitPrice))
                {
                    if (unitprices[fiscalItem.UnitPrice] >= quantity)
                    {
                        SalesItem temp = (SalesItem)(fiscalItem.Clone());
                        temp.Quantity     = quantity;
                        temp.TotalAmount  = quantity * temp.UnitPrice;
                        temp.VoidAmount   = 0;
                        temp.VoidQuantity = 0;

                        unitprices.Remove(fiscalItem.UnitPrice);
                        cancelMenu.Add(temp);
                    }
                }
            }

            return(ListVoid.Instance(cancelMenu, new ProcessSelectedItem <FiscalItem>(VoidSelectedItem)));
        }
Exemple #2
0
        public override void Enter()
        {
            /* when the cancel menu(key) selected without quantity
             * create a list which contains the items whose remaining quantity is bigger than zero
             */
            MenuList cancelMenu = new MenuList();

            foreach (FiscalItem fiscalItem in cr.Document.Items)
            {
                if (fiscalItem is SalesItem)
                {
                    VoidItem voidItem = new VoidItem(fiscalItem);
                    /* quantity of void item is equal to remaining quantity of sale item */
                    if (Math.Abs(voidItem.Quantity) > 0 && cr.Document.CanAddItem(voidItem))
                    {
                        cancelMenu.Add(fiscalItem);
                    }
                }
            }

            cr.State = ListVoid.Instance(cancelMenu, new ProcessSelectedItem <FiscalItem>(VoidSelectedItem));
        }