Ejemplo n.º 1
0
        /** Timeline ER - Fetch SUB-groups **/
        public List <AccountMultipleYearsViewModel> FetchSubGroupsForTimelineEr(Scenario scenario,
                                                                                AccountMultipleYearsViewModel accMultiYears,
                                                                                StructureType selectedType,
                                                                                ERAccountType selectedERAccountType)
        {
            List <AccountYearDto> allBaseAndScenarioAccounts = GetBaseAndScenarioYears(scenario);

            string selectedAccountId = accMultiYears.AccountId;
            List <AccountYearViewModel> allAccounts = null;
            bool isFunctionGroups = selectedType == StructureType.Functions || selectedType == StructureType.SubjectsThenFunctions;

            string idOfParentInSuperordinateStructure = null;

            if (selectedType == StructureType.SubjectsThenFunctions || selectedType == StructureType.FunctionsThenSubjects)
            {
                idOfParentInSuperordinateStructure = accMultiYears.IdOfParentInSuperordinateStructure ?? accMultiYears.AccountId;
                int levelOfSubordinatedAccounts = accMultiYears.IdOfParentInSuperordinateStructure == null ? 1 : (accMultiYears.AccountLevel + 1);

                allAccounts = GetEnumerableForErSubAccountsInMixedStructure(allBaseAndScenarioAccounts,
                                                                            selectedType,
                                                                            selectedERAccountType,
                                                                            idOfParentInSuperordinateStructure,
                                                                            accMultiYears.AccountId,
                                                                            levelOfSubordinatedAccounts,
                                                                            accMultiYears.SelectedYears)
                              .ToList();
            }
            else if (selectedType == StructureType.Functions || selectedType == StructureType.Subjects)
            {
                var query = GroupAccountYearsAndJoinWithAccountGroups(isFunctionGroups,
                                                                      allBaseAndScenarioAccounts,
                                                                      (accMultiYears.AccountLevel + 1));

                // accounts contains all accounts as a flat list:
                // Pick all accounts, whose id starts with the clicked account's id
                allAccounts = query.Where(a => a.AccountId.Substring(0, accMultiYears.AccountLevel) == selectedAccountId)
                              .ToList();
            }

            MultipleYearsViewModel multiYearsModel = _dataSvc.AssembleMultiYearsAccountModels(isFunctionGroups,
                                                                                              selectedERAccountType,
                                                                                              accMultiYears.SelectedYears,
                                                                                              scenario.FinancialYear,
                                                                                              allAccounts);

            if (selectedType == StructureType.SubjectsThenFunctions || selectedType == StructureType.FunctionsThenSubjects)
            {
                foreach (AccountMultipleYearsViewModel acc in multiYearsModel.AccountsWithMultipleYears)
                {
                    acc.IdOfParentInSuperordinateStructure = idOfParentInSuperordinateStructure;
                }
            }
            return(multiYearsModel?.AccountsWithMultipleYears ?? null);
        }
        /** Timeline ER - Fetch SUB-groups **/
        public async Task <List <AccountMultipleYearsViewModel> > FetchSubGroupsForTimelineEr(AccountMultipleYearsViewModel accMultiYears,
                                                                                              StructureType selectedType,
                                                                                              ERAccountType selectedERAccountType,
                                                                                              int mostRecentFinancialYear)
        {
            string selectedAccountId = accMultiYears.AccountId;
            List <AccountYearViewModel> allAccounts = null;
            bool isFunctionGroups = selectedType == StructureType.Functions || selectedType == StructureType.SubjectsThenFunctions;

            string idOfParentInSuperordinateStructure = null;

            if (selectedType == StructureType.SubjectsThenFunctions || selectedType == StructureType.FunctionsThenSubjects)
            {
                idOfParentInSuperordinateStructure = accMultiYears.IdOfParentInSuperordinateStructure ?? accMultiYears.AccountId;
                int levelOfSubordinatedAccounts = accMultiYears.IdOfParentInSuperordinateStructure == null ? 1 : (accMultiYears.AccountLevel + 1);

                allAccounts = await GetQueryForErSubAccountsInMixedStructure(selectedType,
                                                                             selectedERAccountType,
                                                                             idOfParentInSuperordinateStructure,
                                                                             accMultiYears.AccountId,
                                                                             levelOfSubordinatedAccounts,
                                                                             accMultiYears.SelectedYears)
                              .ToListAsync();
            }
            else if (selectedType == StructureType.Functions || selectedType == StructureType.Subjects)
            {
                var query = GetQueryForErAccounts(isFunctionGroups,
                                                  accMultiYears.SelectedYears,
                                                  (accMultiYears.AccountLevel + 1));

                // accounts contains all accounts as a flat list:
                // Pick all accounts, whose id starts with the clicked account's id
                allAccounts = await query.Where(a => a.AccountId.Substring(0, accMultiYears.AccountLevel) == selectedAccountId)
                              .ToListAsync();
            }

            MultipleYearsViewModel multiYearsModel = AssembleMultiYearsAccountModels(isFunctionGroups,
                                                                                     selectedERAccountType,
                                                                                     accMultiYears.SelectedYears,
                                                                                     mostRecentFinancialYear,
                                                                                     allAccounts);

            if (selectedType == StructureType.SubjectsThenFunctions || selectedType == StructureType.FunctionsThenSubjects)
            {
                foreach (AccountMultipleYearsViewModel acc in multiYearsModel.AccountsWithMultipleYears)
                {
                    acc.IdOfParentInSuperordinateStructure = idOfParentInSuperordinateStructure;
                }
            }
            return(multiYearsModel?.AccountsWithMultipleYears ?? null);
        }