コード例 #1
0
        public void ShouldClonePaymentInfo()
        {
            PaymentInfo info  = BuildDefaultPaymentInfo();
            PaymentInfo clone = info.Clone();

            Assert.AreNotSame(info, clone);
            Assert.AreEqual(info.ToString(), clone.ToString());
        }
コード例 #2
0
        private static IState CalculateTotal(PaymentInfo pInfo)
        {
            paymentInfo = pInfo;
            Decimal balanceDue = 0;

            if (!(cr.Document.CanEmpty))
            {
                PaymentInfo currentPaymentInfo = paymentInfo.Clone();
                if (currentPaymentInfo.Amount == 0)
                {
                    currentPaymentInfo.Amount = cr.Document.BalanceDue;
                }
                promoDocument = new PromotionDocument(cr.Document, currentPaymentInfo, PromotionType.Document);
                if (promoDocument.HasAdjustment)
                {
                    balanceDue = promoDocument.BalanceDue;
                }
                else
                {
                    balanceDue = cr.Document.BalanceDue;
                }
                if (!(cr.State is PaymentAfterTotalAdjustment))
                {
                    cancelState = States.Start.Instance;
                }
            }
            else
            {
                balanceDue = cr.Document.BalanceDue;
            }

            // Ýf payment is point payment, dont gain point so clear it
            if (paymentInfo is CreditPaymentInfo && ((CreditPaymentInfo)paymentInfo).Credit.IsPointPayment)
            {
                if (promoDocument != null && promoDocument.Points != null && promoDocument.Points.Count > 0)
                {
                    promoDocument.Points.Clear();
                }

                // And if point payment amount bigger than balanceDue, fix it
                if (paymentInfo.Amount > balanceDue)
                {
                    paymentInfo.Amount = balanceDue;
                }
            }

            if (paymentInfo.Amount == 0)
            {
                if (paymentInfo is CurrencyPaymentInfo)
                {
                    decimal dec = Math.Round(balanceDue / ((CurrencyPaymentInfo)paymentInfo).ExchangeRate, 2);
                    paymentInfo.Amount = Math.Round(dec * ((CurrencyPaymentInfo)paymentInfo).ExchangeRate, 2);
                    //paymentInfo.Amount = Math.Truncate(100 * (dec * ((CurrencyPaymentInfo)paymentInfo).ExchangeRate)) / 100;
                }
                else
                {
                    paymentInfo.Amount = balanceDue;
                }
            }

            //TODO This crap should be in HYDisplay
            DisplayAdapter.Customer.Show(PosMessage.SUBTOTAL, balanceDue);

            return(cr.State = States.ConfirmPayment.Instance(DisplayAdapter.AmountPairFormat(PosMessage.TOTAL,
                                                                                             balanceDue,
                                                                                             paymentInfo.ToString(),
                                                                                             paymentInfo.Amount),
                                                             new StateInstance <Decimal>(Pay),
                                                             new StateInstance(cancelState)));
        }