public async Task <IActionResult> SalesReport(int?periodId, string entity = "advisor")
        {
            MLFSReportingPeriod period;
            List <SalesReport>  report = new List <SalesReport>();

            //get period
            if (periodId == null)
            {
                return(NotFound());
            }
            period = await _periodData.GetPeriodById((int)periodId);

            if (period == null)
            {
                return(NotFound());
            }

            //get advsiors
            List <MLFSAdvisor> advisors = await _advisorData.GetAdvisors();

            List <MLFSIncome> income = await _incomeData.GetIncome(period);

            List <MLFSSale> sales = await _salesData.GetSales(period);

            List <MLFSDebtorAdjustment> adjs = await _adjustmentData.GetAdjustments(period);

            List <MLFSBudget> budgets = await _budgetData.GetBudgets(period);

            if (entity.ToLower() == "advisor")
            {
                foreach (MLFSAdvisor adv in advisors)
                {
                    SalesReport line = new SalesReport(income, sales, adjs, budgets, adv, period);
                    report.Add(line);
                }
            }
            if (entity.ToLower() == "organisation")
            {
                report = report.GroupBy(x => x.Organisation).Select(y => new ViewModels.SalesReport()
                {
                    Period             = y.FirstOrDefault().Period,
                    PeriodId           = y.FirstOrDefault().PeriodId,
                    Advisor            = y.Key,
                    AdvisorId          = 0,
                    Organisation       = y.Key,
                    Budget             = y.Sum(z => z.Budget),
                    New_Business       = y.Sum(z => z.New_Business),
                    Renewals           = y.Sum(z => z.Renewals),
                    Unallocated        = y.Sum(z => z.Unallocated),
                    Clawback           = y.Sum(z => z.Clawback),
                    NotTakenUp         = y.Sum(z => z.NotTakenUp),
                    Adjustment         = y.Sum(z => z.Adjustment),
                    Debtors_Variance   = y.Sum(z => z.Debtors_Variance),
                    Debtors_Adjustment = y.Sum(z => z.Debtors_Adjustment),
                    Total = y.Sum(z => z.Total)
                }).ToList();
            }
            else if (entity.ToLower() == "campaign")
            {
                report = ViewModels.SalesReport.CreateByCampaign(income, period);
            }

            return(PartialView("_SalesReport", report.OrderBy(x => x.Advisor)));
        }
Exemplo n.º 2
0
        // GET: MLFSDebtorAdjustments
        public async Task <IActionResult> Transactions(int debtorId)
        {
            List <MLFSDebtorAdjustment> adjs = await _adjustmentData.GetAdjustments(debtorId);

            return(PartialView("Index", adjs));
        }