예제 #1
0
        /// <summary>
        /// Credits the Money object only to the amount of CashValue.
        /// </summary>
        /// <param name="toPay">The amount of cash to Pay.</param>
        /// <param name="toAdd">The Money object paid with.</param>
        /// <returns>The change.</returns>
        public Money Credit(CashValue toPay, Money toAdd)
        {
            this.Credit(toAdd);
            Money toReturn = this.Debit(new CashValue(toAdd.GetCashValue().Value - toPay.Value));

            return(toReturn);
        }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Product"/> class.
 /// </summary>
 /// <param name="i">The Inventory object to create a product from.</param>
 public Product(Inventory i)
 {
     m_productName  = i.Item_Name;
     m_quantity     = i.Quantity;
     m_sn           = new StockNumber(i.Stock_Number);
     m_price        = new CashValue(i.Price);
     m_cost         = new CashValue(i.Cost);
     m_discontinued = i.Discontinued;
 }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Product"/> class.
 /// </summary>
 /// <param name="name">The Name of the Product.</param>
 /// <param name="stockNumber">The Stock Number of the Product.</param>
 /// <param name="quantity">The Quantity of the Product.</param>
 /// <param name="cost">The Cost of the Product.</param>
 /// <param name="price">The Price of the Product.</param>
 public Product(string name, int stockNumber, int quantity, int cost, int price, bool discontinued)
 {
     m_productName  = name;
     m_sn           = new StockNumber(stockNumber);
     m_quantity     = quantity;
     m_cost         = new CashValue(cost);
     m_price        = new CashValue(price);
     m_discontinued = discontinued;
 }
예제 #4
0
 /// <summary>
 /// Tries the parse.
 /// </summary>
 /// <param name="d">The d.</param>
 /// <param name="cash">The cash.</param>
 /// <returns></returns>
 public static bool TryParse(double d, out CashValue cash)
 {
     cash = null;
     try
     {
         cash = new CashValue((int)Math.Floor((d * (double)100)));
     }
     catch (Exception e)
     {
         return(false);
     }
     return(true);
 }
예제 #5
0
        /// <summary>
        /// Parses the specified d.
        /// </summary>
        /// <param name="d">The d.</param>
        /// <returns></returns>
        public static CashValue Parse(double d)
        {
            CashValue toReturn;

            try
            {
                toReturn = new CashValue((int)Math.Floor((d * (double)100)));
            }
            catch (Exception e)
            {
                throw e;
            }
            return(toReturn);
        }
예제 #6
0
 /// <summary>
 /// Tries to parse.
 /// </summary>
 /// <param name="s">The s.</param>
 /// <param name="cash">The cash.</param>
 /// <returns></returns>
 public static bool TryParse(String s, out CashValue cash)
 {
     cash = null;
     try
     {
         s = s.Replace("$", String.Empty);
         double d = Double.Parse(s);
         cash = new CashValue((int)Math.Floor((d * (double)100)));
     }
     catch (Exception e)
     {
         return(false);
     }
     return(true);
 }
예제 #7
0
        /// <summary>
        /// Parses the specified string to a CashValue object.
        /// </summary>
        /// <param name="s">The string to parse.</param>
        /// <returns></returns>
        public static CashValue Parse(String s)
        {
            CashValue toReturn;

            try
            {
                s = s.Replace("$", String.Empty);
                double d = Double.Parse(s);
                toReturn = new CashValue((int)Math.Floor((d * (double)100)));
            }
            catch (Exception e)
            {
                throw e;
            }
            return(toReturn);
        }
예제 #8
0
        public ICurrency GetChange(ref CashValue newCashValue)
        {
            int iter = 0;

            while (iter * VALUE <= newCashValue.Value && iter < m_count)
            {
                iter++;
                if (iter * VALUE > newCashValue.Value)
                {
                    iter--;
                    break;
                }
            }
            newCashValue = new CashValue(newCashValue.Value - (iter * VALUE));
            m_count     -= iter;
            return(new TwentyDollarBills(iter));
        }
예제 #9
0
        /// <summary>
        /// Debits the Money object for the given CashValue. Returns Change.
        /// </summary>
        /// <param name="toSubtract">To subtract.</param>
        /// <returns></returns>
        public Money Debit(CashValue toSubtract)
        {
            Money toReturn = new Money();
            int   iterator = 0;

            if (toSubtract.Value < 0)
            {
                throw new ArgumentException("Too little cash was given!");
            }

            foreach (ICurrency cur in m_cash)
            {
                toReturn.m_cash[iterator] = cur.GetChange(ref toSubtract);
                iterator++;
            }
            if (toReturn.GetCashValue().Value == 0 && toSubtract.Value != 0)
            {
                throw new ArithmeticException("Change cannot be given...");
            }
            return(toReturn);
        }
예제 #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Receipt"/> class.
        /// </summary>
        /// <param name="products">The products.</param>
        /// <param name="register">The register.</param>
        internal Receipt(ICollection <Product> products, int saleId, ref Register register)
        {
            m_products = products as List <Product>;
            m_saleId   = saleId;
            int totalPrice = 0;
            int costForUs  = 0;

            foreach (Product p in products)
            {
                totalPrice += p.Quantity * p.Price.Value;
                costForUs  += p.Quantity * p.Cost.Value;
            }

            m_totalBeforeTax = new CashValue(totalPrice);

            int tax = (int)Math.Ceiling((double)totalPrice * TAX);

            m_tax = new CashValue(tax);

            int profit = costForUs - totalPrice;

            m_profit = new CashValue(profit);
        }
예제 #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Receipt"/> class.
        /// </summary>
        /// <param name="products">The products.</param>
        /// <param name="register">The register.</param>
        /// <param name="payment">The payment.</param>
        internal Receipt(ICollection <Product> products, int saleId, ref Register register, Money payment)
        {
            m_saleId   = saleId;
            m_products = products as List <Product>;
            int totalPrice = 0;
            int costForUs  = 0;

            foreach (Product p in products)
            {
                totalPrice += p.Quantity * p.Price.Value;
                costForUs  += p.Quantity * p.Cost.Value;
            }

            m_totalBeforeTax = new CashValue(totalPrice);

            int tax = (int)Math.Ceiling((double)totalPrice * TAX);

            m_tax = new CashValue(tax);

            int profit = totalPrice - costForUs;

            m_profit = new CashValue(profit);

            register.Cash.Credit(payment);

            int diff = payment.GetCashValue().Value - TotalAfterTax.Value;

            try
            {
                m_change = register.Cash.Debit(new CashValue(diff));
            }
            catch (Exception e)
            {
                register.Cash.Debit(payment.GetCashValue());
                throw e;
            }
        }