示例#1
0
        public ProfitsForProduct GetProfitForProduct(Guid productId, Expression <Func <Transaction, bool> > TransactionPredicate = null)
        {
            Product           Product       = ProductRepo.Get(x => x.Id == productId);
            ProfitsForProduct ProfitRecords = new ProfitsForProduct();

            ProfitRecords.Product = Product;

            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> > ProfitsPerYear = new Dictionary <int, Dictionary <Month, double> >();

            ProfitsPerYear = GroupProfitsPerYear(TransactionsForProduct);

            foreach (var item in ProfitsPerYear)
            {
                int Year = item.Key;
                Dictionary <Month, double> ProfitsPerMonth = item.Value;
                ProfitRecords.ProfitsForProductInYear.Add(new ProfitsForProductInYear()
                {
                    Year            = Year,
                    ProfitsPerMonth = ProfitsPerMonth,
                });
            }


            return(ProfitRecords);
        }
示例#2
0
        public double GetProfitAmountForProduct(Guid productId, int year = 0, Month month = Month.None)
        {
            ProfitsForProduct       ProfitRecords       = GetProfitForProduct(productId);
            ProfitsForProductInYear ProfitRecordForYear = ProfitRecords.ProfitsForProductInYear.FirstOrDefault(x => x.Year == year);

            return(year == 0 ? ProfitRecords.ProfitsForProductInYear.Sum(x => x.ProfitsPerMonth.Sum(y => y.Value)) : (month == Month.None ? ProfitRecordForYear.ProfitsPerMonth.Sum(x => x.Value) : ProfitRecordForYear.ProfitsPerMonth[month]));
        }
        public Dictionary <string, double> ProfitForProduct(Guid productId)
        {
            Dictionary <string, double> Report       = new Dictionary <string, double>();
            ProfitsForProduct           ProfitRecord = ProfitLogic.GetProfitForProduct(productId);

            ProfitRecord.ProfitsForProductInYear.ForEach(x =>
            {
                Report.Add(x.Year.ToString(), x.ProfitsPerMonth.Sum(y => y.Value));
            });
            return(Report);
        }
示例#4
0
        public ActionResult ProfitForProduct(Guid id)
        {
            List <ProfitLossForBatch> BatchProfitRecords  = ProfitLogic.ProfitsForProductByBatch(id);
            ProfitsForProduct         YearlyProfitRecords = ProfitLogic.GetProfitForProduct(id);

            ViewBag.Product = ProductRepo.Get(x => x.Id == id);
            return(View(new ProfitForProductAnalysisVM
            {
                BatchProfitRecords = BatchProfitRecords,
                YearlyProfitRecords = YearlyProfitRecords,
            }));
        }
示例#5
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,
            });
        }
示例#6
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);
        }