Exemplo n.º 1
0
        public void InitReport()
        {
            DateTime start = new DateTime(2016, 1, 1);
            DateTime end   = new DateTime(2017, 12, 31);

            result = report.Report(start, end, agentId);
        }
        public SalesByAgentModel Report(RequestModel Request)
        {
            if (Request.EndDate <= Request.StartDate)
            {
                throw new Exception("Incorrect Date");
            }
            List <Invoice>    Invoices        = UnitOfWork.Invoices.Get().Where(x => x.Date >= Request.StartDate && x.Date <= Request.EndDate).ToList();
            List <Invoice>    InvoicesOfAgent = UnitOfWork.Invoices.Get().Where(x => x.Date >= Request.StartDate && x.Date <= Request.EndDate && x.Agent.Id == Request.Id).ToList();
            double            grandTotal      = Math.Round(Invoices.Sum(x => x.SubTotal), 2);
            Agent             agent           = UnitOfWork.Agents.Get(Request.Id);
            double            AgentTotal      = Math.Round(InvoicesOfAgent.Sum(x => x.SubTotal), 2);
            SalesByAgentModel result          = new SalesByAgentModel()
            {
                AgentName    = agent.Name,
                StartDate    = Request.StartDate,
                EndDate      = Request.EndDate,
                AgentTotal   = AgentTotal,
                PercentTotal = Math.Round(100 * InvoicesOfAgent.Sum(x => x.SubTotal) / grandTotal, 2)
            };

            result.Sales = InvoicesOfAgent.OrderBy(x => x.Customer.Id).ToList()
                           .GroupBy(x => x.Customer.Town.Region.ToString())
                           .Select(x => Factory.Create
                                       (InvoicesOfAgent, x.Key, x.Sum(y => y.SubTotal), AgentTotal, Invoices))
                           .ToList();

            return(result);
        }
Exemplo n.º 3
0
        public SalesByAgentModel Report(DateTime start, DateTime end, int agentId)
        {
            SalesByAgentModel result = new SalesByAgentModel();
            var   Invoices           = _unitOfWork.Invoices.Get().Where(x => (x.Date >= start && x.Date <= end)).ToList();
            Agent a = _unitOfWork.Agents.Get(agentId);

            result.StartDate = start;
            result.EndDate   = end;
            result.Sales     = new List <RegionSalesByAgentModel>();
            result.AgentName = a.Name;
            double total      = 0;
            double grandTotal = Invoices.Sum(x => x.Total);

            var query = Invoices.Where(x => x.Agent.Id == agentId).GroupBy(x => x.Customer.Town.Region.ToString())
                        .Select(x => new
            {
                Name  = x.Key,
                Total = x.Sum(y => y.Total)
            }).ToList();

            foreach (var item in query)
            {
                total += item.Total;
            }

            result.AgentTotal   = Math.Round(total, 2);
            result.PercentTotal = Math.Round(100 * total / grandTotal, 2);

            foreach (var item in query)
            {
                RegionSalesByAgentModel region = new RegionSalesByAgentModel()
                {
                    RegionName    = item.Name,
                    RegionTotal   = Math.Round(item.Total, 2),
                    RegionPercent = Math.Round(100 * item.Total / total, 2),
                    TotalPercent  = Math.Round(100 * item.Total / grandTotal, 2)
                };
                result.Sales.Add(region);
            }

            return(result);
        }
Exemplo n.º 4
0
        public SalesByAgentModel Report(RequestModel Request)
        {
            List <Invoice> Invoices = UnitOfWork.Invoices.Get().Where(x => x.Date >= Request.StartDate && x.Date <= Request.EndDate).ToList();
            double         total    = Invoices.Sum(x => x.Total);

            List <Invoice> AgentInvoices = Invoices.Where(x => x.Agent.Id == Request.Id).ToList();


            double agentTotal = AgentInvoices.Sum(x => x.Total);

            SalesByAgentModel result = new SalesByAgentModel()
            {
                StartDate    = Request.StartDate,
                EndDate      = Request.EndDate,
                AgentName    = UnitOfWork.Agents.Get(Request.Id).Name,
                AgentTotal   = agentTotal,
                ProcentTotal = Math.Round(100 * agentTotal / total, 2)
            };

            result.Sales = AgentInvoices.GroupBy(x => x.Customer.Town.Region.ToString())
                           .Select(x => Factory.Create(x.Key, x.Sum(y => y.Total), total, agentTotal))
                           .ToList();
            return(result);
        }