예제 #1
0
        public IEnumerable <ProfitForProduct> ViewProfitForProductsBasedOnDuration(IEnumerable <Product> products, Expression <Func <Batch, bool> > predicate = null)
        {
            List <ProfitForProduct> ProfitForProductsList = new List <ProfitForProduct>();

            foreach (var item in products)
            {
                string[] ProfitForProducts = predicate == null?BatchRepo.GetAll(x => x.ProductId == item.Id).Select(x => x.ProfitMargin).ToArray() :
                                                 BatchRepo.GetAll(x => x.ProductId == item.Id).Where(predicate).Select(x => x.ProfitMargin).ToArray();

                double[] ExpectedProfit = new double[ProfitForProducts.Count()];
                double[] ActualProfit   = new double[ProfitForProducts.Count()];


                for (var i = 0; i < ProfitForProducts.Count(); ++i)
                {
                    ExpectedProfit[i] = GetProfitForProduct(ProfitForProducts[i])["Expected"];
                    ActualProfit[i]   = GetProfitForProduct(ProfitForProducts[i])["Actual"];
                }

                double AverageExpectedProfitMargin = ExpectedProfit.Average();
                double AverageActualProfitMargin   = ActualProfit.Average();

                ProfitForProductsList.Add(new ProfitForProduct
                {
                    ProductName    = item.Name,
                    ActualProfit   = AverageActualProfitMargin,
                    ExpectedProfit = AverageExpectedProfitMargin,
                });
            }
            return(ProfitForProductsList);
        }
예제 #2
0
        public IEnumerable <Batch> ProductsPast75PercentOfShelfLife()
        {
            List <Batch> ProductsInStoreList = new List <Batch>();

            ProductsInStoreList = BatchRepo.GetAll(x => (x.QuantitySold + x.QuantityAuctioned + x.QuantityDisposedOf) < x.QuantityPurchased).ToList();
            List <Batch> SoonToExpireProductsInList = new List <Batch>();

            foreach (var item in ProductsInStoreList)
            {
                DateTime ManufactureDate = item.ManufactureDate;
                DateTime ExpiryDate      = item.ExpiryDate;

                if (ExpiryDate > DateTime.Now)
                {
                    if (IsProductPast75PercentOfShelfLife(item))
                    {
                        if (ProductToBeAuctionedRepo.GetAll(x => x.BatchId == item.Id).FirstOrDefault() == null &&
                            AuctionRepo.GetAll(x => x.BatchId == item.Id).FirstOrDefault() == null)
                        {
                            ProductToBeAuctionedRepo.Add(new ProductToBeAuctioned()
                            {
                                AuctionPrice             = 0,
                                HasBeenReviewedByManager = false,
                                BatchId = item.Id,
                                //StoreId = new StoreManager().GetStoreId(),
                                DateOfAuction = ReturnAuctionDateUsingPercentageOfShelfLife(80, item),
                            });
                        }

                        SoonToExpireProductsInList.Add(item);
                    }
                }
            }
            return(SoonToExpireProductsInList);
        }
예제 #3
0
        public LossForProduct GetLossForProduct(Guid productId)
        {
            Product        Product     = ProductRepo.Get(x => x.Id == productId);
            LossForProduct LossRecords = new LossForProduct();


            Batch[] ProductInStoreRecords = BatchRepo.GetAll(x => x.ProductId == productId).ToArray();
            Guid[]  ProductInStoreIds     = ProductInStoreRecords.Select(x => x.Id).ToArray();
            Loss[]  LossesForProduct      = LossRepo.GetAll(x => x.Batch.ProductId == productId).OrderBy(x => x.DateOfLoss).ToArray();

            Dictionary <int, Dictionary <Month, double> > LossPerYear = new Dictionary <int, Dictionary <Month, double> >();

            LossPerYear = GroupLossPerYear(LossesForProduct);

            foreach (var item in LossPerYear)
            {
                int Year = item.Key;
                Dictionary <Month, double> LossPerMonth = item.Value;
                LossRecords.LossForProductInYear.Add(new LossForProductInYear()
                {
                    Year = Year, LossPerMonth = LossPerMonth,
                });
            }
            LossRecords.Product = Product;
            return(LossRecords);
        }
        public TransactionsForProduct GetTransactionsForProduct(Guid productId, out Dictionary <int, Dictionary <Month, double> > TurnoverPerYear, Expression <Func <Transaction, bool> > TransactionPredicate = null)
        {
            Product Product = ProductRepo.Get(x => x.Id == productId);

            TransactionsForProduct TransactionsRecords = new TransactionsForProduct();

            Batch[] ProductInStoreRecords = BatchRepo.GetAll(x => x.ProductId == productId).ToArray();
            Guid[]  ProductInStoreIds     = ProductInStoreRecords.Select(x => x.Id).ToArray();

            Transaction[] TransactionsForProduct = TransactionPredicate == null?TransactionRepo.GetAll(x => x.Batch.ProductId == productId).OrderBy(x => x.DateOfTransaction).ToArray() : TransactionRepo.GetAll(x => x.Batch.ProductId == productId).Where(TransactionPredicate).OrderBy(x => x.DateOfTransaction).ToArray();

            Dictionary <int, Dictionary <Month, double> > TransactionsPerYear = new Dictionary <int, Dictionary <Month, double> >();

            TransactionsPerYear = GroupTransactionsPerYear(TransactionsForProduct, out TurnoverPerYear);

            if (TransactionsPerYear != null)
            {
                foreach (var item in TransactionsPerYear)
                {
                    int Year = item.Key;
                    Dictionary <Month, double> TransactionsPerMonth = item.Value;
                    TransactionsRecords.TransactionsForProductInYear.Add(new TransactionsForProductInYear()
                    {
                        Year = Year, TransactionsPerMonth = TransactionsPerMonth
                    });
                }
                TransactionsRecords.Product = Product;

                return(TransactionsRecords);
            }

            return(null);
        }
예제 #5
0
 public IEnumerable <Batch> RetrieveProductInStoreRecordsForProduct(Guid productId)
 {
     return(BatchRepo.GetAll(x => x.ProductId == productId));
 }
 public List <Batch> GetBatchesForAllProductsForStore(Guid storeId)
 {
     return(BatchRepo.GetAll(x => x.Product.StoreId == storeId).ToList());
 }