Exemplo n.º 1
0
        public Maybe <IReadOnlyList <IDiscountRule> > GetDiscountRules(IPurchaseItem item)
        {
            var items = discountRules.Where(x => x.ProductName == item.Product.ProductName).ToList();


            return(items.Count > 0 ? new Maybe <IReadOnlyList <IDiscountRule> >(items) : new Maybe <IReadOnlyList <IDiscountRule> >());
        }
Exemplo n.º 2
0
        public void WhenCreated_HasProductAndQuantity()
        {
            item = fixture.Create <PurchaseItem>();

            Assert.NotNull(item.Product);
            Assert.True(item.Quantity > 0);
        }
        public static tbl_Pui CreatePurchaseItem(IPurchaseItem item)
        {
            tbl_Pui pui = new tbl_Pui();

            pui.PuiNumber   = item.PuiNumber;
            pui.PuiPrd_     = item.PuiPrdId;
            pui.Puidiscount = item.PuiDiscount;
            pui.PuiPuh_     = item.PuiPuhId;
            pui.Puivat      = item.Puivat;
            return(pui);
        }
Exemplo n.º 4
0
        public IPurchaseItem AddTax(IPurchaseItem purchaseItem)
        {
            // Check whether any word in description is in exempt list
            var isTaxExempt = _exemptItems.Any(word => purchaseItem.Description.Contains(word));

            var isImported = purchaseItem.Description.Contains("imported");

            IPurchaseItem returnItem = purchaseItem;

            if (!isTaxExempt)
            {
                returnItem = new BasicTaxPurchaseItem(returnItem);
            }

            if (isImported)
            {
                returnItem = new ImportDutyPurchaseItem(returnItem);
            }

            return(returnItem);
        }
Exemplo n.º 5
0
        public Money CalculateDiscount(IPurchaseItem item)
        {
            var applyingRules = discountRules.GetDiscountRules(item);

            var fallbackValue = new List <NoDiscountRule> {
                new NoDiscountRule()
            };
            var result = applyingRules.GetValueOrFallback(fallbackValue);

            decimal calculatedCost;

            LogMessage($"Discounts Are Cummulative: {discountRules.DiscountsAreCumulative}");

            if (!discountRules.DiscountsAreCumulative)
            {
                var discountRule = result.First();


                var fullAmount = item.FullCost.Amount;
                calculatedCost = PercentageCalculator.CalculatePercentageDiscount(fullAmount, discountRule.DiscountPercentage);

                LogMessage($"Let's see... you have {item.Quantity} of {item.Product.ProductName} ({item.FullCost}). The {discountRule.GetType().Name} discount applies\r\n. That's a {discountRule.DiscountPercentage}% discount for you! ({calculatedCost })\r\n");
            }
            else
            {
                //calculate discounts one over the other, as they are cummulative

                //JP: POSSIBLE DONT TALK TO STRANGER VIOLATION HERE, CHECK IF WE NEED TO USE THE NAME OF THE ITEM FOR SMTHNG IF NOT, TAKE MONEY AS PARAMETER
                calculatedCost = item.FullCost.Amount;

                foreach (var rule in result)
                {
                    calculatedCost = PercentageCalculator.CalculatePercentageDiscount(calculatedCost, rule.DiscountPercentage);
                }
            }

            var newCost = new Money(calculatedCost, item.Product.Cost);

            return(newCost);
        }
Exemplo n.º 6
0
 public void DeletePurchaseItem(IPurchaseItem item)
 {
     Service.DeletePurchaseItem(item);
 }
Exemplo n.º 7
0
 public void AddPuchaseItem(IPurchaseItem item)
 {
     Service.AddPuchaseItem(item);
 }
Exemplo n.º 8
0
 public void DeletePurchaseItem(IPurchaseItem item)
 {
     QuattroDataFactory.DeletePurchaseItem(item);
 }
 private static tbl_Pui LoadPurchaseItem(IPurchaseItem item)
 {
     return (from c in MerpDatabase().tbl_Pui where item.PuiId == c.Pui_ select c).First();
 }
Exemplo n.º 10
0
 public static void AddPurchaseItem(IPurchaseItem item)
 {
     MerpDatabase().tbl_Pui.AddObject(CreatePurchaseItem(item));
 }
Exemplo n.º 11
0
        public void AddProduct(IPurchaseItem item)
        {
            Guard.Against.Null(item, nameof(item));

            items.Add(item);
        }
Exemplo n.º 12
0
 // Adds item and increases sales tax and total with item details
 public void AddPurchaseItem(IPurchaseItem purchaseItem)
 {
     PurchaseItems.Add(purchaseItem);
     SalesTaxes += purchaseItem.GetPrice() - purchaseItem.OriginalPrice;
     Total      += purchaseItem.GetPrice();
 }
Exemplo n.º 13
0
 public void DeletePurchaseItem(IPurchaseItem item)
 {
     QuattroDataFactory.DeletePurchaseItem(item);
 }
Exemplo n.º 14
0
 public void AddPuchaseItem(IPurchaseItem item)
 {
     QuattroDataFactory.AddPurchaseItem(item);
 }
 public ImportDutyPurchaseItem(IPurchaseItem purchaseItem)
 {
     _purchaseItem = purchaseItem;
 }
 public static tbl_Pui CreatePurchaseItem(IPurchaseItem item)
 {
     tbl_Pui pui = new tbl_Pui();
     pui.PuiNumber = item.PuiNumber;
     pui.PuiPrd_ = item.PuiPrdId;
     pui.Puidiscount = item.PuiDiscount;
     pui.PuiPuh_ = item.PuiPuhId;
     pui.Puivat = item.Puivat;
     return pui;
 }
 public static void DeletePurchaseItem(IPurchaseItem item)
 {
     MerpDatabase().tbl_Pui.DeleteObject(LoadPurchaseItem(item));
 }
Exemplo n.º 18
0
 public static void DeletePurchaseItem(IPurchaseItem item)
 {
     MerpDatabase().tbl_Pui.DeleteObject(LoadPurchaseItem(item));
 }
 public static void AddPurchaseItem(IPurchaseItem item)
 {
     MerpDatabase().tbl_Pui.AddObject(CreatePurchaseItem(item));
 }
Exemplo n.º 20
0
 private static tbl_Pui LoadPurchaseItem(IPurchaseItem item)
 {
     return((from c in MerpDatabase().tbl_Pui where item.PuiId == c.Pui_ select c).First());
 }
Exemplo n.º 21
0
 public BasicTaxPurchaseItem(IPurchaseItem purchaseItem)
 {
     _purchaseItem = purchaseItem;
 }
Exemplo n.º 22
0
 public void AddPuchaseItem(IPurchaseItem item)
 {
     QuattroDataFactory.AddPurchaseItem(item);
 }