Example #1
0
        public void InitReport()
        {
            DateTime start = new DateTime(2016, 1, 1);
            DateTime end   = new DateTime(2016, 12, 31);

            result = report.Report(start, end);
        }
Example #2
0
        public SalesByRegionModel Report(DateTime start, DateTime end)
        {
            List <Invoice>     Invoices = _unitOfWork.Invoices.Get().Where(x => x.Date >= start && x.Date <= end).ToList();
            SalesByRegionModel result   = new SalesByRegionModel(start, end)
            {
                GrandTotal = Invoices.Sum(x => x.SubTotal)
            };

            result.Sales = Invoices.OrderBy(x => x.Customer.Id).ToList()
                           .GroupBy(x => x.Customer.Town.Region.ToString())
                           .Select(x => _factory.Create(Invoices, x.Key, x.Sum(y => y.SubTotal)))
                           .ToList();
            return(result);
        }
Example #3
0
        public SalesByRegionModel Report(RequestModel Request)
        {
            List <Invoice>     Invoices = UnitOfWork.Invoices.Get().Where(x => x.Date >= Request.StartDate && x.Date <= Request.EndDate).ToList();
            SalesByRegionModel result   = new SalesByRegionModel()
            {
                StartDate  = Request.StartDate,
                EndDate    = Request.EndDate,
                GrandTotal = Invoices.Sum(x => x.Total)
            };

            result.Sales = Invoices.OrderBy(x => x.Customer.Id).ToList()
                           .GroupBy(x => x.Customer.Town.Region.ToString())
                           .Select(x => Factory.Create
                                       (Invoices, x.Key, x.Sum(y => y.Total)))
                           .ToList();
            return(result);
        }
Example #4
0
        public SalesByRegionModel Report(RequestModel Request)
        {
            List <Invoice>     Invoices = UnitOfWork.Invoices.Get().Where(x => x.Date >= Request.StartDate && x.Date <= Request.EndDate).ToList();
            SalesByRegionModel result   = new SalesByRegionModel()
            {
                StartDate  = Request.StartDate,
                EndDate    = Request.EndDate,
                Title      = "Sales by Region",
                Agent      = BillingIdentity.CurrentUser.Name,
                GrandTotal = Invoices.Sum(x => x.SubTotal)
            };

            result.Sales = Invoices.OrderBy(x => x.Customer.Id).ToList()
                           .GroupBy(x => x.Customer.Town.Region.ToString())
                           .Select(x => new SalesByRegionModel.RegionSales()
            {
                RegionName = x.Key, RegionTotal = x.Sum(y => y.SubTotal)
            })
                           .ToList();

            foreach (var sale in result.Sales)
            {
                sale.RegionPercent = Math.Round(100 * sale.RegionTotal / result.GrandTotal, 2);
                sale.Agents        = Invoices.Where(x => x.Customer.Town.Region.ToString() == sale.RegionName)
                                     .OrderBy(x => x.Agent.Name)
                                     .GroupBy(x => x.Agent.Name)
                                     .Select(x => new SalesByRegionModel.AgentSales()
                {
                    AgentName     = x.Key,
                    AgentTotal    = Math.Round(x.Sum(y => y.Total), 2),
                    RegionPercent = Math.Round(100 * x.Sum(y => y.Total) / sale.RegionTotal, 2),
                    TotalPercent  = Math.Round(100 * x.Sum(y => y.Total) / result.GrandTotal, 2)
                }).ToList();
            }

            return(result);
        }