//
        // GET: /ProductUpcharge/Create
        public ActionResult Create(string returnUrl, int ProductID = 0)
        {
            ViewBag.ReturnUrl = returnUrl;

            var list = db.Products.Where(p => p.ProductStatus != archived &&
                                                p.Campaign.CampaignStatus != archived &&
                                                p.Campaign.Company.CompanyStatus != archived);
            ViewBag.ProductID = new SelectList(list, "ProductID", "ProductName");

            // Generate Decoration method for member initialization
            ProductUpcharge productUpcharge = new ProductUpcharge();
            productUpcharge.OnCreate();

            return View(productUpcharge);
        }
Exemplo n.º 2
0
 // Non-generated Constructor
 public UpchargeSellPrice(ProductUpcharge upcharge, string name, int level)
 {
     // TODO: Complete member initialization
     this.ProductUpcharge = upcharge;
     this.UpchargeSellPriceName = name;
     this.UpchargeSellPriceLevel = level;
     this.AuditTrails = new HashSet<AuditTrail>();
     this.UpchargeSellPriceStatus = MyExtensions.GetEnumDescription(Status.Active);
 }
Exemplo n.º 3
0
        // ProductUpcharge
        public AuditTrail(DateTime dateTime, string userName, ProductUpcharge productUpcharge, int id, string comment)
        {
            this.AuditTrailTimeStamp = dateTime;
            this.AuditTrailUserName = userName;
            this.AuditTrailComment = comment;

            if(id > 0)
            {
                this.UpchargeID = id;
            }
            else
            {
                this.ProductUpcharge = productUpcharge;
            }
        }
        public void Compute_Product_With_Upcharge()
        {
            // Data Input
            var product = new Product() { ProductCost = 1, ProductAnnualSalesProjection = 100 };
            product.ProductUpcharges = new List<ProductUpcharge>();
            ProductUpcharge upcharge1 = new ProductUpcharge();
            upcharge1.UpchargeAmount = 2;
            upcharge1.UpchargeSellPrices = new List<UpchargeSellPrice>();
            upcharge1.UpchargeSellPrices.Add(new UpchargeSellPrice() { UpchargeSellPriceName = "Employee", UpchargeSellPriceLevel = 1 });
            upcharge1.UpchargeSellPrices.Add(new UpchargeSellPrice() { UpchargeSellPriceName = "Retail", UpchargeSellPriceLevel = 2 });

            product.ProductUpcharges.Add(upcharge1);
            product.Fees = new List<Fee>();
            product.Fees.Add(new Fee() { FeeType = MyExtensions.GetEnumDescription(FeeTypeList.Dollar_Amount), FeeDollarAmount = 1 });
            product.Fees.Add(new Fee() { FeeType = MyExtensions.GetEnumDescription(FeeTypeList.Amortized), FeeAmortizedCharge = 100, FeeAmortizedType = MyExtensions.GetEnumDescription(AmortizedTypeList.Annual_Sales_Projection) });
            product.Fees.Add(new Fee() { FeeType = MyExtensions.GetEnumDescription(FeeTypeList.Percent), FeePercent = 10, FeePercentType = MyExtensions.GetEnumDescription(PercentTypeList.Division) });
            product.Fees.Add(new Fee() { FeeType = MyExtensions.GetEnumDescription(FeeTypeList.Percent), FeePercent = 10, FeePercentType = MyExtensions.GetEnumDescription(PercentTypeList.Multiplication) });
            product.ProductSellPrices = new List<ProductSellPrice>();
            product.ProductSellPrices.Add(new ProductSellPrice() { SellPriceName = "Employee", SellPriceMarginPercent = 50, SellPriceLevel = 1 });
            product.ProductSellPrices.Add(new ProductSellPrice() { SellPriceName = "Retail", SellPriceMarginPercent = 50, SellPriceLevel = 2 });

            foreach(var sellPrice in product.ProductSellPrices)
            {
                sellPrice.Fees = new List<Fee>();
                if(sellPrice.SellPriceName == "Retail")
                {
                    sellPrice.Fees.Add(new Fee() { FeeType = MyExtensions.GetEnumDescription(FeeTypeList.Percent), FeePercent = 20, FeePercentType = MyExtensions.GetEnumDescription(PercentTypeList.Multiplication) });
                }
            }

            // Run Calculator
            var feeCalculator = new FeeCalculator(product);
            feeCalculator.ComputeAllProductPrices(false);

            // Created to get same value though division
            decimal value = ((decimal)3 / (decimal).9) * (decimal)1.1;
            value = feeCalculator.RoundNumberToDecimalPlace(value, 3);
            Assert.AreEqual(value, product.ProductTotalCost);

            foreach(var sellPrice in product.ProductSellPrices)
            {
                decimal sellPriceValue = value / (decimal)(.50);
                foreach(var fee in sellPrice.Fees)
                {
                    if(fee.FeePercentType == MyExtensions.GetEnumDescription(PercentTypeList.Multiplication))
                    {
                        sellPriceValue = sellPriceValue * (decimal)1.2;
                    }
                    else
                    {
                        sellPriceValue = sellPriceValue / (decimal).8;
                    }
                }

                Assert.AreEqual(feeCalculator.RoundNumberToDecimalPlace(sellPriceValue, 3), sellPrice.SellPriceFinalAmount);
            }

            // Check Upcharge values
            foreach(var upcharge in product.ProductUpcharges)
            {
                // Created to get same value though division
                decimal newValue = (decimal)1;// cost
                newValue += 2; // upcharge
                newValue += 2; // dollar charges
                newValue = (decimal)(newValue / ((decimal)1 - (decimal)((decimal)10 / (decimal)100))); // divide
                newValue = (decimal)(((decimal)10 / (decimal)100) + (decimal)1) * newValue; // multiply
                newValue = feeCalculator.RoundNumberToDecimalPlace(newValue, 3);

                Assert.AreEqual(newValue, upcharge.UpchargeTotalCost);

                foreach(var upchargeSellPrice in upcharge.UpchargeSellPrices)
                {
                    decimal sellPriceValue = newValue / (decimal)(.50);
                    foreach(var fee in product.ProductSellPrices.Where(p => p.SellPriceLevel == upchargeSellPrice.UpchargeSellPriceLevel).FirstOrDefault().Fees)
                    {
                        if(fee.FeePercentType == MyExtensions.GetEnumDescription(PercentTypeList.Multiplication))
                        {
                            sellPriceValue = sellPriceValue * (decimal)1.2;
                        }
                        else
                        {
                            sellPriceValue = sellPriceValue / (decimal).8;
                        }
                    }
                    Assert.AreEqual(feeCalculator.RoundNumberToDecimalPlace(sellPriceValue, 3), upchargeSellPrice.UpchargeSellPriceFinalAmount);
                }
            }
        }
        public ActionResult Create(ProductUpcharge productUpcharge, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                // Get productUpcharge's product and get sell prices
                Product thisProduct = db.Products.Where(p => p.ProductID == productUpcharge.ProductID).FirstOrDefault();
                foreach(var sellPrice in thisProduct.ProductSellPrices)
                {
                    UpchargeSellPrice newUpchargeSellPrice = new UpchargeSellPrice(productUpcharge, sellPrice.SellPriceName, sellPrice.SellPriceLevel);
                    db.UpchargeSellPrices.Add(newUpchargeSellPrice);
                }

                db.ProductUpcharges.Add(productUpcharge);
                db.SaveChanges();

                if(returnUrl == null)
                {
                    return RedirectToAction("Index");
                }
                return Redirect(returnUrl);
            }

            var list = db.Products.Where(p => p.ProductStatus != archived &&
                                                p.Campaign.CampaignStatus != archived &&
                                                p.Campaign.Company.CompanyStatus != archived);
            ViewBag.ProductID = new SelectList(list, "ProductID", "ProductName", productUpcharge.ProductID);
            return View(productUpcharge);
        }
        public ActionResult Edit(ProductUpcharge productupcharge)
        {
            if (ModelState.IsValid)
            {
                db.Entry(productupcharge).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            var list = db.Products.Where(p => p.ProductStatus != archived &&
                                                p.Campaign.CampaignStatus != archived &&
                                                p.Campaign.Company.CompanyStatus != archived);
            ViewBag.ProductID = new SelectList(list, "ProductID", "ProductName", productupcharge.ProductID);
            return View(productupcharge);
        }