Esempio n. 1
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);
        }
Esempio n. 2
0
        public double GetLossAmountForProduct(Guid productId, int year = 0, Month month = Month.None)
        {
            LossForProduct       LossRecords       = GetLossForProduct(productId);
            LossForProductInYear LossRecordForYear = LossRecords.LossForProductInYear.FirstOrDefault(x => x.Year == year);

            return(year == 0 ? LossRecords.LossForProductInYear.Sum(x => x.LossPerMonth.Sum(y => y.Value)): (month == Month.None?LossRecordForYear.LossPerMonth.Sum(x => x.Value):LossRecordForYear.LossPerMonth[month]));
        }
Esempio n. 3
0
        private void CompileMonthlyProfitLossRatio(ref ProfitLossVM yearlyRatioRecord, ProfitsForProduct profitRecords, LossForProduct lossRecords, Month month)
        {
            int    Year           = yearlyRatioRecord.Year;
            double ProfitQuantity = profitRecords.ProfitsForProductInYear.FirstOrDefault(x => x.Year == Year).ProfitsPerMonth[month];
            double LossQuantity   = lossRecords.LossForProductInYear.FirstOrDefault(x => x.Year == Year).LossPerMonth[month];

            yearlyRatioRecord.Records.Add(new ProfitLossMonthlyVM()
            {
                Month  = Month.February,
                Profit = ProfitQuantity,
                Loss   = LossQuantity,
            });
        }
Esempio n. 4
0
        public List <ProfitLossVM> GetProfitLossRatio(Guid id)
        {
            List <ProfitLossVM> TotalRatioRecords = new List <ProfitLossVM>();
            ProfitsForProduct   ProfitRecords     = GetProfitForProduct(id);
            LossForProduct      LossRecords       = LossLogic.GetLossForProduct(id);

            int ProfitStartYear = ProfitRecords.StartYear;
            int ProfitsEndYear  = ProfitRecords.EndYear;
            int LossStartYear   = LossRecords.StartYear;
            int LossEndYear     = LossRecords.EndYear;

            int StartYear = ProfitStartYear < LossStartYear ? ProfitStartYear : LossStartYear;
            int EndYear   = ProfitsEndYear < LossEndYear ? LossEndYear : ProfitsEndYear;

            for (int i = StartYear; i <= EndYear; ++i)
            {
                ProfitLossVM YearlyRatioRecord = new ProfitLossVM {
                    Year = i
                };

                for (Month j = Month.January; j <= Month.December; ++j)
                {
                    switch (j)
                    {
                    case Month.January:
                        CompileMonthlyProfitLossRatio(ref YearlyRatioRecord, ProfitRecords, LossRecords, Month.January);
                        break;

                    case Month.February:
                        CompileMonthlyProfitLossRatio(ref YearlyRatioRecord, ProfitRecords, LossRecords, Month.February);

                        break;

                    case Month.March:
                        CompileMonthlyProfitLossRatio(ref YearlyRatioRecord, ProfitRecords, LossRecords, Month.March);
                        break;

                    case Month.April:
                        CompileMonthlyProfitLossRatio(ref YearlyRatioRecord, ProfitRecords, LossRecords, Month.April);
                        break;

                    case Month.May:
                        CompileMonthlyProfitLossRatio(ref YearlyRatioRecord, ProfitRecords, LossRecords, Month.May);
                        break;

                    case Month.June:
                        CompileMonthlyProfitLossRatio(ref YearlyRatioRecord, ProfitRecords, LossRecords, Month.June);
                        break;

                    case Month.July:
                        CompileMonthlyProfitLossRatio(ref YearlyRatioRecord, ProfitRecords, LossRecords, Month.July);
                        break;

                    case Month.August:
                        CompileMonthlyProfitLossRatio(ref YearlyRatioRecord, ProfitRecords, LossRecords, Month.August);
                        break;

                    case Month.September:
                        CompileMonthlyProfitLossRatio(ref YearlyRatioRecord, ProfitRecords, LossRecords, Month.September);
                        break;

                    case Month.October:
                        CompileMonthlyProfitLossRatio(ref YearlyRatioRecord, ProfitRecords, LossRecords, Month.October);
                        break;

                    case Month.November:
                        CompileMonthlyProfitLossRatio(ref YearlyRatioRecord, ProfitRecords, LossRecords, Month.November);
                        break;

                    case Month.December:
                        CompileMonthlyProfitLossRatio(ref YearlyRatioRecord, ProfitRecords, LossRecords, Month.December);
                        break;
                    }
                }
                TotalRatioRecords.Add(YearlyRatioRecord);
            }

            return(TotalRatioRecords);
        }