Ejemplo n.º 1
0
        public ActionResult SetCustomer(int id, int value)
        {
            var entity = SalesQuote.Find(id);
            var item   = Customer.TryFind(value);

            if (entity.IsCompleted || entity.IsCancelled)
            {
                Response.StatusCode = 400;
                return(Content(Resources.ItemAlreadyCompletedOrCancelled));
            }

            if (item != null)
            {
                entity.Customer = item;
                entity.Contact  = null;
                entity.ShipTo   = null;

                if (item.SalesPerson == null)
                {
                    entity.SalesPerson = CurrentUser.Employee;
                }
                else
                {
                    entity.SalesPerson = item.SalesPerson;
                }

                if (entity.Terms == PaymentTerms.NetD && !entity.Customer.HasCredit)
                {
                    entity.Terms = PaymentTerms.Immediate;
                }

                switch (entity.Terms)
                {
                case PaymentTerms.Immediate:
                    entity.DueDate = entity.Date;
                    break;

                case PaymentTerms.NetD:
                    entity.DueDate = entity.Date.AddDays(entity.Customer.CreditDays);
                    break;
                }

                entity.Updater          = CurrentUser.Employee;
                entity.ModificationTime = DateTime.Now;

                using (var scope = new TransactionScope()) {
                    entity.UpdateAndFlush();
                }
            }

            return(Json(new {
                id = id,
                value = entity.FormattedValueFor(x => x.Customer),
                terms = entity.Terms,
                termsText = entity.Terms.GetDisplayName(),
                dueDate = entity.FormattedValueFor(x => x.DueDate),
                salesPerson = entity.SalesPerson.Id,
                salesPersonName = entity.SalesPerson.Name
            }));
        }
Ejemplo n.º 2
0
        public ActionResult SetDate(int id, DateTime?value)
        {
            var entity = SalesQuote.Find(id);

            if (entity.IsCompleted || entity.IsCancelled)
            {
                Response.StatusCode = 400;
                return(Content(Resources.ItemAlreadyCompletedOrCancelled));
            }

            if (value != null)
            {
                entity.Date             = value.Value;
                entity.Updater          = CurrentUser.Employee;
                entity.ModificationTime = DateTime.Now;

                using (var scope = new TransactionScope()) {
                    entity.UpdateAndFlush();
                }
            }

            return(Json(new {
                id = id,
                value = entity.FormattedValueFor(x => x.Date)
            }));
        }
Ejemplo n.º 3
0
        public void GetFinishCost__Test()
        {
            ExteriorFinish exteriorFinishChosen = new ExteriorFinish();
            SalesQuote     salesQuote           = new SalesQuote(0.1M, 0.2M, 0.3M, Accessories.None, exteriorFinishChosen);
            decimal        expectedFinishCost;
            decimal        standard  = 202.02M;
            decimal        pearlized = 404.04M;
            decimal        custom    = 606.06M;

            switch (exteriorFinishChosen)
            {
            case ExteriorFinish.Custom:
                expectedFinishCost = custom;
                break;

            case ExteriorFinish.Pearlized:
                expectedFinishCost = pearlized;
                break;

            case ExteriorFinish.Standard:
                expectedFinishCost = standard;
                break;

            default:
                expectedFinishCost = 0.00M;
                break;
            }
            decimal actualFinishCost = salesQuote.FinishCost;

            Assert.AreEqual(expectedFinishCost, actualFinishCost);
        }
Ejemplo n.º 4
0
        public void Constructor_VehicleSalesPrice_TradeInAmount_SalesTaxRate_Accessories_Finish_Test()
        {
            //Arrange
            decimal        vehicleSalesPrice = 10000;
            decimal        tradeInAmount     = 2000;
            decimal        salesTaxRate      = 0.1m;
            Accessories    accessories       = Accessories.LeatherInterior;
            ExteriorFinish finish            = ExteriorFinish.Custom;
            SalesQuote     salesQuote        = new SalesQuote(vehicleSalesPrice, tradeInAmount, salesTaxRate, accessories, finish);
            PrivateObject  target            = new PrivateObject(salesQuote);

            //Act
            decimal        expectedVehicleSalesPrice = 10000;
            decimal        expectedTradeInAmount     = 2000;
            decimal        expectedSalesTaxRate      = 0.1m;
            Accessories    expectedAccessories       = Accessories.LeatherInterior;
            ExteriorFinish expectedFinish            = ExteriorFinish.Custom;
            decimal        actualVehicleSalesPrice   = (decimal)target.GetField("vehicleSalesPrice");
            decimal        actualTradeInAmount       = (decimal)target.GetField("tradeInAmount");
            Accessories    actualAccessories         = (Accessories)target.GetField("accessoriesChosen");
            ExteriorFinish actualFinish    = (ExteriorFinish)target.GetField("exteriorFinishChosen");
            decimal        actualSalesRate = 0.1m;

            //Assert
            Assert.AreEqual(expectedVehicleSalesPrice, actualVehicleSalesPrice);
            Assert.AreEqual(expectedTradeInAmount, actualTradeInAmount);
            Assert.AreEqual(expectedAccessories, actualAccessories);
            Assert.AreEqual(expectedFinish, actualFinish);
            Assert.AreEqual(expectedSalesTaxRate, actualSalesRate);
        }
Ejemplo n.º 5
0
        public void SetTradeInAmountSpecial_Test()
        {
            //Arrange
            decimal        vehicleSalesPrice = 10000;
            decimal        tradeInAmount     = 2000;
            decimal        salesTaxRate      = 0.1m;
            Accessories    accessories       = Accessories.LeatherInterior;
            ExteriorFinish finish            = ExteriorFinish.Custom;
            SalesQuote     salesQuote        = new SalesQuote(vehicleSalesPrice, tradeInAmount, salesTaxRate, accessories, finish);

            //Act
            decimal expcetedTradeInAmount = 2000;

            //Assert
            try
            {
                salesQuote.TradeInAmount = -1000;
                Assert.Fail("Did not throw ArgumentOutOfRangeException as expected.");
            }
            catch (ArgumentOutOfRangeException)
            {
                PrivateObject abc = new PrivateObject(salesQuote);
                decimal       actualTradeInAmount = (decimal)abc.GetField("tradeInAmount");
                Assert.AreEqual(expcetedTradeInAmount, actualTradeInAmount);
            }
        }
Ejemplo n.º 6
0
 public void SalesQuote_WithNoAccessoriesAndFinishChosen_VehicleSalesPrice_Greater_Exception_Test()
 {
     decimal    vehicleSalesPrice = 0.1M;
     decimal    tradeInAmount     = 0.3M;
     decimal    salesTaxRate      = 4M;
     SalesQuote actualSalesQuote  = new SalesQuote(vehicleSalesPrice, tradeInAmount, salesTaxRate);
 }
Ejemplo n.º 7
0
        public void SalesQuote_Test()
        {
            decimal        vehicleSalePrice             = 0.1M;
            decimal        tradeInAmount                = 0.2M;
            decimal        salesTaxRate                 = 0.1M;
            Accessories    accessoriesChosen            = new Accessories();
            ExteriorFinish exteriorFinishChosen         = new ExteriorFinish();
            SalesQuote     salesQuote                   = new SalesQuote(vehicleSalePrice, tradeInAmount, salesTaxRate, accessoriesChosen, exteriorFinishChosen);
            decimal        expectedVehicleSalePrice     = 0.1M;
            decimal        expectedTradeInAmount        = 0.2M;
            decimal        expectedSalesTaxRate         = 0.1M;
            Accessories    expectedAccessoriesChosen    = new Accessories();
            ExteriorFinish expectedExteriorFinishChosen = new ExteriorFinish();
            PrivateObject  target = new PrivateObject(salesQuote);
            decimal        actualVehicleSalePrice     = (decimal)target.GetField("vehicleSalePrice");
            decimal        actualTradeInAmount        = (decimal)target.GetField("tradeInAmount");
            decimal        actualSalesTaxRate         = (decimal)target.GetField("salesTaxRate");
            Accessories    actualAccessoriesChosen    = (Accessories)target.GetField("accessoriesChosen");
            ExteriorFinish actualExteriorFinishChosen = (ExteriorFinish)target.GetField("exteriorFinishChosen");

            Assert.AreEqual(expectedSalesTaxRate, actualSalesTaxRate);
            Assert.AreEqual(expectedTradeInAmount, actualTradeInAmount);
            Assert.AreEqual(expectedVehicleSalePrice, actualVehicleSalePrice);
            Assert.AreEqual(expectedAccessoriesChosen, actualAccessoriesChosen);
            Assert.AreEqual(expectedExteriorFinishChosen, actualExteriorFinishChosen);
        }
Ejemplo n.º 8
0
        public ActionResult SetShipTo(int id, int value)
        {
            var entity = SalesQuote.Find(id);
            var item   = Address.TryFind(value);

            if (entity.IsCompleted || entity.IsCancelled)
            {
                Response.StatusCode = 400;
                return(Content(Resources.ItemAlreadyCompletedOrCancelled));
            }

            if (item != null)
            {
                entity.ShipTo           = item;
                entity.Updater          = CurrentUser.Employee;
                entity.ModificationTime = DateTime.Now;

                using (var scope = new TransactionScope()) {
                    entity.UpdateAndFlush();
                }
            }

            return(Json(new {
                id = id,
                value = entity.ShipTo.ToString()
            }));
        }
Ejemplo n.º 9
0
        public void GetAccessoryCost_StereoSystem_Test()
        {
            //Arrange
            SalesQuote salesQuote = new SalesQuote(10000, 2000, 0.1m, Accessories.StereoSystem, ExteriorFinish.Pearlized);

            //Assert
            Assert.AreEqual(505.05m, salesQuote.AccessoryCost);
        }
Ejemplo n.º 10
0
        public void AccessoriesChosen__Get_LeatherInterior_Test()
        {
            SalesQuote  salesQuote = new SalesQuote(0.1M, 0.2M, 0.3M, Accessories.LeatherInterior, ExteriorFinish.None);
            Accessories expectedAccessoriesChosen = Accessories.LeatherInterior;
            Accessories actualAccessoriesChosen   = salesQuote.AccessoriesChosen;

            Assert.AreEqual(expectedAccessoriesChosen, actualAccessoriesChosen);
        }
Ejemplo n.º 11
0
        public void GetAccessoriesChosen_All_Test()
        {
            SalesQuote  salesQuote = new SalesQuote(0.1M, 0.2M, 0.3M, Accessories.All, ExteriorFinish.None);
            Accessories expectedAccessoriesChosen = Accessories.All;
            Accessories actualAccessoriesChosen   = salesQuote.AccessoriesChosen;

            Assert.AreEqual(expectedAccessoriesChosen, actualAccessoriesChosen);
        }
Ejemplo n.º 12
0
        public void GetAccessoryCost_None_Test()
        {
            //Arrange
            SalesQuote salesQuote = new SalesQuote(10000, 2000, 0.1m, Accessories.None, ExteriorFinish.Pearlized);

            //Assert
            Assert.AreEqual(0, salesQuote.AccessoryCost);
        }
Ejemplo n.º 13
0
        public void GetAccessoryCost_ComputerNavigation_Test()
        {
            //Arrange
            SalesQuote salesQuote = new SalesQuote(10000, 2000, 0.1m, Accessories.ComputerNavigation, ExteriorFinish.Pearlized);

            //Assert
            Assert.AreEqual(1515.15m, salesQuote.AccessoryCost);
        }
Ejemplo n.º 14
0
        public void GetAmountDue_Test()
        {
            SalesQuote salesQuote        = new SalesQuote(0.1M, 0.2M, 0.3M, Accessories.None, ExteriorFinish.Standard);
            decimal    expectedAmountDue = 262.556M;
            decimal    actualAmountDue   = salesQuote.AmountDue;

            Assert.AreEqual(expectedAmountDue, actualAmountDue);
        }
Ejemplo n.º 15
0
        public void GetSalesTax_Test()
        {
            SalesQuote salesQuote       = new SalesQuote(0.1M, 0.2M, 0.3M, Accessories.None, ExteriorFinish.Standard);
            decimal    expectedSalesTax = 60.636M;
            decimal    actualSalesTax   = salesQuote.SalesTax;

            Assert.AreEqual(expectedSalesTax, actualSalesTax);
        }
Ejemplo n.º 16
0
        public void GetSubTotal_Test()
        {
            SalesQuote salesQuote       = new SalesQuote(0.1M, 0.2M, 0.3M, Accessories.None, ExteriorFinish.Standard);
            decimal    expectedSubTotal = 202.12M;
            decimal    actualSubTotal   = salesQuote.SubTotal;

            Assert.AreEqual(expectedSubTotal, actualSubTotal);
        }
Ejemplo n.º 17
0
        public void GetExteriorChosen_Standard_Test()
        {
            SalesQuote     salesQuote             = new SalesQuote(0.1M, 0.2M, 0.3M, Accessories.None, ExteriorFinish.Standard);
            ExteriorFinish expectedExteriorChosen = ExteriorFinish.Standard;
            ExteriorFinish actualExteriorChosen   = salesQuote.ExteriorFinishChosen;

            Assert.AreEqual(expectedExteriorChosen, actualExteriorChosen);
        }
Ejemplo n.º 18
0
        public void GetAccessoryCost_LeatherInterior_Test()
        {
            //Arrange
            SalesQuote salesQuote = new SalesQuote(10000, 2000, 0.1m, Accessories.LeatherInterior, ExteriorFinish.Pearlized);

            //Assert
            Assert.AreEqual(1010.10m, salesQuote.AccessoryCost);
        }
Ejemplo n.º 19
0
        public void GetAccessoryCost_StereoAndLeather_Test()
        {
            //Arrange
            SalesQuote salesQuote = new SalesQuote(10000, 2000, 0.1m, Accessories.StereoAndLeather, ExteriorFinish.Pearlized);

            //Assert
            Assert.AreEqual(1515.15m, salesQuote.AccessoryCost);
        }
Ejemplo n.º 20
0
        public void GetFinishCost_Pearlized_Test()
        {
            //Arrange
            SalesQuote salesQuote = new SalesQuote(10000, 2000, 0.1m, Accessories.LeatherAndNavigation, ExteriorFinish.Pearlized);

            //Assert
            Assert.AreEqual(404.04m, salesQuote.FinishCost);
        }
Ejemplo n.º 21
0
        public void GetAccessoryCost_LeatherAndNavigation_Test()
        {
            //Arrange
            SalesQuote salesQuote = new SalesQuote(10000, 2000, 0.1m, Accessories.LeatherAndNavigation, ExteriorFinish.Pearlized);

            //Assert
            Assert.AreEqual(2525.25m, salesQuote.AccessoryCost);
        }
Ejemplo n.º 22
0
        public void SetVehicleSalesPrice_EqualToZero_Test()
        {
            //Arrange
            SalesQuote salesQuote = new SalesQuote(10000, 2000, 0.1m, Accessories.LeatherInterior, ExteriorFinish.Custom);

            //Act
            salesQuote.VehicleSalePrice = 0;
        }
Ejemplo n.º 23
0
        public void GetFinishCost_Standard_Test()
        {
            //Arrange
            SalesQuote salesQuote = new SalesQuote(10000, 2000, 0.1m, Accessories.LeatherAndNavigation, ExteriorFinish.Standard);

            //Assert
            Assert.AreEqual(202.02m, salesQuote.FinishCost);
        }
Ejemplo n.º 24
0
        public void GetAccessoriesChosen_LeatherAndNavigation_Test()
        {
            SalesQuote  salesQuote = new SalesQuote(0.1M, 0.2M, 0.3M, Accessories.LeatherAndNavigation, ExteriorFinish.None);
            Accessories expectedAccessoriesChosen = Accessories.LeatherAndNavigation;
            Accessories actualAccessoriesChosen   = salesQuote.AccessoriesChosen;

            Assert.AreEqual(expectedAccessoriesChosen, actualAccessoriesChosen);
        }
Ejemplo n.º 25
0
        public void SetTradeInAmount_LessThanZero_Test()
        {
            //Arrange
            SalesQuote salesQuote = new SalesQuote(10000, 2000, 0.1m, Accessories.LeatherInterior, ExteriorFinish.Custom);

            //Act
            salesQuote.TradeInAmount = -1;
        }
Ejemplo n.º 26
0
        public void AccessoriesChosen_Get_StereoSystem_Test()
        {
            SalesQuote  salesQuote = new SalesQuote(0.1M, 0.2M, 0.3M, Accessories.StereoSystem, ExteriorFinish.None);
            Accessories expectedAccessoriesChosen = Accessories.StereoSystem;
            Accessories actualAccessoriesChosen   = salesQuote.AccessoriesChosen;

            Assert.AreEqual(expectedAccessoriesChosen, actualAccessoriesChosen);
        }
Ejemplo n.º 27
0
        public void GetFinishCost_None_Test()
        {
            //Arrange
            SalesQuote salesQuote = new SalesQuote(10000, 2000, 0.1m, Accessories.LeatherAndNavigation, ExteriorFinish.None);

            //Assert
            Assert.AreEqual(0, salesQuote.FinishCost);
        }
Ejemplo n.º 28
0
        public void TradeInAmount_Get_Test()
        {
            decimal    tradeInAmount         = 0.4M;
            SalesQuote salesQuote            = new SalesQuote(0.3M, tradeInAmount, 0.3M, Accessories.None, ExteriorFinish.None);
            decimal    expectedTradeInAmount = 0.4M;
            decimal    actualTradeInAmount   = salesQuote.TradeInAmount;

            Assert.AreEqual(expectedTradeInAmount, actualTradeInAmount);
        }
Ejemplo n.º 29
0
        public void TradeInAmountChanged_Test()
        {
            this.eventActual = null;
            SalesQuote salesQuote = new SalesQuote(20000, 2000, 0.2m, Accessories.ComputerNavigation, ExteriorFinish.Custom);

            salesQuote.TradeInAmountChanged += TestHandler;
            salesQuote.TradeInAmount         = 1000;
            Assert.AreEqual("Event triggered.", eventActual);
        }
Ejemplo n.º 30
0
        public void ExteriorFinishChosenChanged_Test()
        {
            this.eventActual = null;
            SalesQuote salesQuote = new SalesQuote(20000, 2000, 0.2m, Accessories.ComputerNavigation, ExteriorFinish.Custom);

            salesQuote.ExteriorFinishChosenChanged += TestHandler;
            salesQuote.ExteriorFinishChosen         = ExteriorFinish.Pearlized;
            Assert.AreEqual("Event triggered.", eventActual);
        }
Ejemplo n.º 31
0
        public ActionResult New()
        {
            var dt = DateTime.Now;
            var item = new SalesQuote ();

            item.Store = WebConfig.Store;

            if (item.Store == null) {
                return View ("InvalidStore");
            }

            if (!CashHelpers.ValidateExchangeRate ()) {
                return View ("InvalidExchangeRate");
            }

            // Store and Serial
            try {
                item.Serial = (from x in SalesQuote.Queryable
                           where x.Store.Id == item.Store.Id
                           select x.Serial).Max () + 1;
            } catch {
                item.Serial = 1;
            }

            item.Customer = Customer.TryFind (WebConfig.DefaultCustomer);
            item.SalesPerson = CurrentUser.Employee;
            item.Date = dt;
            item.Terms = PaymentTerms.Immediate;
            item.DueDate = DateTime.Now.AddDays ((WebConfig.DefaultDueDaysAdded));
            item.Currency = WebConfig.DefaultCurrency;
            item.ExchangeRate = CashHelpers.GetTodayDefaultExchangeRate ();

            item.Creator = CurrentUser.Employee;
            item.CreationTime = dt;
            item.Updater = item.Creator;
            item.ModificationTime = dt;

            using (var scope = new TransactionScope ()) {
                item.CreateAndFlush ();
            }

            return RedirectToAction ("Edit", new {
                id = item.Id
            });
        }