public async Task <ActionResult> Index(string matNo, string name, UnitType unit = UnitType.AbsoluteMoney, RevenueGroupType tab = RevenueGroupType.Expenditure, MatFinancingType financing = MatFinancingType.TrustAndAcademies, ChartFormat format = ChartFormat.Charts)
        {
            ChartGroupType chartGroup;

            switch (tab)
            {
            case RevenueGroupType.Expenditure:
                chartGroup = ChartGroupType.TotalExpenditure;
                break;

            case RevenueGroupType.Income:
                chartGroup = ChartGroupType.TotalIncome;
                break;

            case RevenueGroupType.Balance:
                chartGroup = ChartGroupType.InYearBalance;
                break;

            default:
                chartGroup = ChartGroupType.All;
                break;
            }

            var latestYear = _financialDataService.GetLatestDataYearForTrusts();
            var term       = FormatHelpers.FinancialTermFormatAcademies(latestYear);

            var dataResponse = _financialDataService.GetAcademiesByMatNumber(term, matNo);

            var sponsorVM = await BuildSponsorVMAsync(matNo, name, dataResponse, tab, chartGroup, financing);

            List <string> terms      = _financialDataService.GetActiveTermsForMatCentral();
            var           latestTerm = terms.First();

            UnitType unitType;

            switch (tab)
            {
            case RevenueGroupType.Workforce:
                unitType = UnitType.AbsoluteCount;
                break;

            case RevenueGroupType.Balance:
                unitType = unit == UnitType.AbsoluteMoney || unit == UnitType.PerPupil || unit == UnitType.PerTeacher ? unit : UnitType.AbsoluteMoney;
                break;

            default:
                unitType = unit;
                break;
            }

            _fcService.PopulateHistoricalChartsWithSchoolData(sponsorVM.HistoricalCharts, sponsorVM.HistoricalSchoolFinancialDataModels, latestTerm, tab, unitType, SchoolFinancialType.Academies);

            ViewBag.Tab         = tab;
            ViewBag.ChartGroup  = chartGroup;
            ViewBag.UnitType    = unitType;
            ViewBag.Financing   = financing;
            ViewBag.ChartFormat = format;

            return(View(sponsorVM));
        }
        public async Task <ActionResult> Detail(int urn, UnitType unit = UnitType.AbsoluteMoney, CentralFinancingType financing = CentralFinancingType.Include, RevenueGroupType tab = RevenueGroupType.Expenditure, ChartFormat format = ChartFormat.Charts)
        {
            ChartGroupType chartGroup;

            switch (tab)
            {
            case RevenueGroupType.Expenditure:
                chartGroup = ChartGroupType.TotalExpenditure;
                break;

            case RevenueGroupType.Income:
                chartGroup = ChartGroupType.TotalIncome;
                break;

            case RevenueGroupType.Balance:
                chartGroup = ChartGroupType.InYearBalance;
                break;

            case RevenueGroupType.Workforce:
                chartGroup = ChartGroupType.Workforce;
                break;

            default:
                chartGroup = ChartGroupType.All;
                break;
            }

            var schoolDetailsFromEdubase = _contextDataService.GetSchoolByUrn(urn.ToString());

            if (schoolDetailsFromEdubase == null)
            {
                return(View("EmptyResult", new SchoolSearchViewModel(base.ExtractSchoolComparisonListFromCookie(), SearchTypes.SEARCH_BY_NAME_ID)));
            }

            SchoolViewModel schoolVM = await BuildSchoolVMAsync(tab, chartGroup, financing, schoolDetailsFromEdubase);

            UnitType unitType;

            switch (tab)
            {
            case RevenueGroupType.Workforce:
                unitType = UnitType.AbsoluteCount;
                break;

            case RevenueGroupType.Balance:
                unitType = unit == UnitType.AbsoluteMoney || unit == UnitType.PerPupil || unit == UnitType.PerTeacher ? unit : UnitType.AbsoluteMoney;
                break;

            default:
                unitType = unit;
                break;
            }

            _fcService.PopulateHistoricalChartsWithSchoolData(schoolVM.HistoricalCharts, schoolVM.HistoricalSchoolFinancialDataModels, (BuildTermsList(schoolVM.FinancialType)).First(), tab, unitType, schoolVM.FinancialType);

            ViewBag.Tab         = tab;
            ViewBag.ChartGroup  = chartGroup;
            ViewBag.UnitType    = unitType;
            ViewBag.Financing   = financing;
            ViewBag.ChartFormat = format;

            return(View("Detail", schoolVM));
        }