private async Task <List <FinancialDataModel> > GetFinancialDataHistoricallyAsync(int companyNo, MatFinancingType matFinancing)
        {
            var models     = new List <FinancialDataModel>();
            var latestYear = await _financialDataService.GetLatestDataYearPerEstabTypeAsync(EstablishmentType.MAT);

            var taskList = new List <Task <SchoolTrustFinancialDataObject> >();

            for (int i = ChartHistory.YEARS_OF_HISTORY - 1; i >= 0; i--)
            {
                var term = SchoolFormatHelpers.FinancialTermFormatAcademies(latestYear - i);
                var task = _financialDataService.GetTrustFinancialDataObjectByCompanyNoAsync(companyNo, term, matFinancing);
                taskList.Add(task);
            }

            for (int i = ChartHistory.YEARS_OF_HISTORY - 1; i >= 0; i--)
            {
                var term         = SchoolFormatHelpers.FinancialTermFormatAcademies(latestYear - i);
                var taskResult   = await taskList[ChartHistory.YEARS_OF_HISTORY - 1 - i];
                var resultObject = taskResult;

                if (resultObject != null && resultObject.DidNotSubmit)
                {
                    var emptyObj = new SchoolTrustFinancialDataObject();
                    emptyObj.DidNotSubmit = true;
                    resultObject          = emptyObj;
                }

                models.Add(new FinancialDataModel(companyNo.ToString(), term, resultObject, EstablishmentType.MAT));
            }

            return(models);
        }
        private async Task <List <FinancialDataModel> > GetFinancialDataHistoricallyAsync(long urn, EstablishmentType estabType, CentralFinancingType cFinance)
        {
            var models     = new List <FinancialDataModel>();
            var latestYear = await _financialDataService.GetLatestDataYearPerEstabTypeAsync(estabType);

            var taskList = new List <Task <SchoolTrustFinancialDataObject> >();

            for (int i = ChartHistory.YEARS_OF_HISTORY - 1; i >= 0; i--)
            {
                var term = SchoolFormatHelpers.FinancialTermFormatAcademies(latestYear - i);
                var task = _financialDataService.GetSchoolFinancialDataObjectAsync(urn, term, estabType, cFinance);
                taskList.Add(task);
            }

            for (int i = ChartHistory.YEARS_OF_HISTORY - 1; i >= 0; i--)
            {
                var term             = SchoolFormatHelpers.FinancialTermFormatAcademies(latestYear - i);
                var resultDataObject = await taskList[ChartHistory.YEARS_OF_HISTORY - 1 - i];

                if (estabType == EstablishmentType.Academies && cFinance == CentralFinancingType.Include && resultDataObject == null)//if nothing found in MAT-Allocs collection try to source it from (non-allocated) Academies data
                {
                    resultDataObject = (await _financialDataService.GetSchoolFinancialDataObjectAsync(urn, term, estabType, CentralFinancingType.Exclude));
                }

                if (resultDataObject != null && resultDataObject.DidNotSubmit)//School did not submit finance, return & display "no data" in the charts
                {
                    resultDataObject = null;
                }

                models.Add(new FinancialDataModel(urn.ToString(), term, resultDataObject, estabType));
            }

            return(models);
        }
        private async Task <SchoolTrustFinancialDataObject> GetLatestFinance(long fuid)
        {
            var latestYear = await _financialDataService.GetLatestDataYearPerEstabTypeAsync(EstablishmentType.Federation);

            var term    = SchoolFormatHelpers.FinancialTermFormatAcademies(latestYear);
            var finance = await _financialDataService.GetFederationFinancialDataObjectByFuidAsync(fuid, term);

            return(finance);
        }
        private async Task <List <string> > GetAllAvailableTermYears()
        {
            var latestMaintainedTerm = await _financialDataService.GetLatestDataYearPerEstabTypeAsync(EstablishmentType.Maintained);

            List <string> availableTermYears = new(); //C#9

            for (int term = latestMaintainedTerm - 1; term <= latestMaintainedTerm + 3; term++)
            {
                availableTermYears.Add(SchoolFormatHelpers.FinancialTermFormatAcademies(term).Replace(" ", ""));
            }

            return(availableTermYears);
        }
        private async Task <FinancialDataModel> GetLatestFinancialDataAsync(long urn, EstablishmentType estabType, CentralFinancingType cFinance)
        {
            var latestYear = await _financialDataService.GetLatestDataYearPerEstabTypeAsync(estabType);

            var term             = SchoolFormatHelpers.FinancialTermFormatAcademies(latestYear);
            var resultDataObject = await _financialDataService.GetSchoolFinancialDataObjectAsync(urn, term, estabType, cFinance);

            if (estabType == EstablishmentType.Academies && cFinance == CentralFinancingType.Include && resultDataObject == null)//if nothing found in MAT-Allocs collection try to source it from (non-allocated) Academies data
            {
                resultDataObject = (await _financialDataService.GetSchoolFinancialDataObjectAsync(urn, term, estabType, CentralFinancingType.Exclude));
            }

            if (resultDataObject != null && resultDataObject.DidNotSubmit)//School did not submit finance, return & display "no data" in the charts
            {
                resultDataObject = null;
            }

            return(new FinancialDataModel(urn.ToString(), term, resultDataObject, estabType));
        }
        private async Task <string> LatestTermAsync(EstablishmentType type)
        {
            var latestYear = await _financialDataService.GetLatestDataYearPerEstabTypeAsync(type);

            return(SchoolFormatHelpers.FinancialTermFormatAcademies(latestYear));
        }
        private async Task <string> GetLatestTermYears(EstablishmentType financeType)
        {
            var term = await _financialDataService.GetLatestDataYearPerEstabTypeAsync(financeType);

            return(SchoolFormatHelpers.FinancialTermFormatAcademies(term).Replace(" ", ""));
        }