Exemplo n.º 1
0
 public static IList<IModelComponent> GetModelComponentsLatestVersion(IDalSession session, int modelID)
 {
     Hashtable parameters = new Hashtable();
     parameters.Add("modelID", modelID);
     return session.GetTypedListByNamedQuery<IModelComponent>(
         "B4F.TotalGiro.Instruments.ModelComponent.GetModelComponentsLatestVersion",
         parameters);
 }
Exemplo n.º 2
0
        public static IList<ILedgerType> GetLedgerEntryGroupings(IDalSession session, DateTime dateUntil)
        {
            string query = "B4F.TotalGiro.Communicator.Exact.LedgerEntry.GetLedgerEntryGroupings";

            Hashtable parameters = new Hashtable();
            parameters.Add("dateUntil", dateUntil);

            return session.GetTypedListByNamedQuery<ILedgerType>(query, parameters);
        }
Exemplo n.º 3
0
        public static IList<IAverageHolding> GetAverageHoldings(IDalSession session, int[] averageHoldingIds)
        {
            Hashtable parameterLists = new Hashtable(1);
            parameterLists.Add("averageHoldingIds", averageHoldingIds);

            return session.GetTypedListByNamedQuery<IAverageHolding>(
                "B4F.TotalGiro.Valuations.AverageHoldings.GetAverageHoldings",
                new Hashtable(), parameterLists);
        }
Exemplo n.º 4
0
 public static IList<IValuationCashMutation> GetValuationCashMutations(IDalSession session, int accountID, DateTime[] dates)
 {
     Hashtable parameters = new Hashtable(1);
     Hashtable parameterLists = new Hashtable(1);
     parameters.Add("accountID", accountID);
     parameterLists.Add("dates", dates);
     return session.GetTypedListByNamedQuery<IValuationCashMutation>(
         "B4F.TotalGiro.Valuations.GetValuationCashMutationDataByDates",
         parameters, parameterLists);
 }
Exemplo n.º 5
0
 public static IList<ISecurityValuationMutation> GetSecurityValuationMutations(IDalSession session, int accountID, DateTime startDate, DateTime endDate)
 {
     Hashtable parameters = new Hashtable(1);
     parameters.Add("accountID", accountID);
     parameters.Add("startDate", startDate);
     parameters.Add("endDate", endDate);
     return session.GetTypedListByNamedQuery<ISecurityValuationMutation>(
         "B4F.TotalGiro.Valuations.GetSecurityValuationMutationData",
         parameters);
 }
Exemplo n.º 6
0
 public static IList<IDepositWithdrawal> GetDepositsWithdrawals(IDalSession session, int accountID, DateTime startDate, DateTime endDate)
 {
     Hashtable parameters = new Hashtable(1);
     parameters.Add("accountID", accountID);
     parameters.Add("startDate", startDate);
     parameters.Add("endDate", endDate);
     return session.GetTypedListByNamedQuery<IDepositWithdrawal>(
         "B4F.TotalGiro.Valuations.GetDepositsWithdrawalData",
         parameters);
 }
Exemplo n.º 7
0
 public static IList<IGLAccount> GetGLAccounts(IDalSession session, bool isFixed, bool showAllowedManualOnly)
 {
     Hashtable parameters = new Hashtable();
     parameters.Add("isFixed", isFixed);
     if (showAllowedManualOnly)
         parameters.Add("isAllowedManual", true);
     return session.GetTypedListByNamedQuery<IGLAccount>(
         "B4F.TotalGiro.GeneralLedger.Static.GetGLAccounts",
         parameters);
 }
Exemplo n.º 8
0
        public static IList<ILedgerEntry> GetLedgerEntriesinFile(IDalSession session, int fileID)
        {
            string query = @"FROM LedgerEntry L
                             WHERE L.ExportedLedgerFile.Key = :fileID
                             ORDER BY L.BookingNumber";

            Hashtable parameters = new Hashtable();
            parameters.Add("fileID", fileID);

            return session.GetTypedListByNamedQuery<ILedgerEntry>(query, parameters);
        }
Exemplo n.º 9
0
        public static IList<IJournalEntryLine> GetJournalEntriesToExport(IDalSession session, ExactEntryGrouping grouping)
        {
            string query = "B4F.TotalGiro.Communicator.Exact.SubledgerEntry.GetJournalEntriesToExport";

            Hashtable parameters = new Hashtable();
            parameters.Add("exactJournalID", grouping.Key);
            parameters.Add("transactionDate", grouping.TransactionDate);

            IList<IJournalEntryLine> lines = session.GetTypedListByNamedQuery<IJournalEntryLine>(query, parameters);
            return lines;
        }
Exemplo n.º 10
0
 public static IList<IDividendHistory> GetDividendHistoryList(IDalSession session, int instrumentKey, DateTime startdate, DateTime endDate)
 {
     Hashtable parameters = new Hashtable();
     if (instrumentKey != 0 && instrumentKey != int.MinValue)
         parameters.Add("instrumentKey", instrumentKey);
     if (Util.IsNotNullDate(startdate))
         parameters.Add("startdate", startdate);
     if (Util.IsNotNullDate(endDate))
         parameters.Add("endDate", endDate);
     return session.GetTypedListByNamedQuery<IDividendHistory>(
         "B4F.TotalGiro.Instruments.CorporateAction.GetDividendHistories",
         parameters);
 }
Exemplo n.º 11
0
        /// <summary>
        /// Get lifecycle by ID
        /// </summary>
        /// <param name="session">Data access object</param>
        /// <param name="assetManagerId">Identifier</param>
        /// <param name="activityFilter">Identifier</param>
        /// <returns>List of Lifecycle objects</returns>
        public static IList<ILifecycle> GetLifecycles(IDalSession session, int assetManagerId, ActivityReturnFilter activityFilter)
        {
            Hashtable parameters = new Hashtable();
            if (assetManagerId != 0)
                parameters.Add("managementCompanyID", assetManagerId);

            if (activityFilter != ActivityReturnFilter.All)
                parameters.Add("isActive", (activityFilter == ActivityReturnFilter.Active ? true : false));

            return session.GetTypedListByNamedQuery<ILifecycle>(
                "B4F.TotalGiro.Instruments.Lifecycles",
                parameters);
        }
Exemplo n.º 12
0
        public static IList<IGeneralOperationsBooking> GetBookings(IDalSession session, GeneralOperationsBookingReturnClass bookingType, int accountId, DateTime beginDate, DateTime endDate, bool includeStornos)
        {
            Hashtable parameters = new Hashtable();
            parameters.Add("accountId", accountId);
            parameters.Add("beginDate", beginDate);
            parameters.Add("endDate", endDate);
            parameters.Add("bookTypeId", (int)bookingType);
            if (!includeStornos)
                parameters.Add("hideStornos", 1);

            return session.GetTypedListByNamedQuery<IGeneralOperationsBooking>(
                "B4F.TotalGiro.GeneralLedger.Journal.Bookings.GetGeneralOperationsBookings",
                parameters);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Get all system categories
        /// </summary>
        /// <param name="session">Data access object</param>
        /// <param name="secCategoryFilter">Type of sec category to return</param>
        /// <param name="includeNotSupported">include Not Supported sec categories</param>
        /// <returns>Collection of categories</returns>
        public static IList<ISecCategory> GetSecCategories(IDalSession session, SecCategoryFilterOptions secCategoryFilter, bool? includeNotSupported)
        {
            Hashtable parameters = new Hashtable();

            if (secCategoryFilter != SecCategoryFilterOptions.All)
                parameters.Add("secCategoryFilter", (int)secCategoryFilter);
            if (includeNotSupported.HasValue && !includeNotSupported.Value)
                parameters.Add("isSupported", true);
            IList<ISecCategory> list = session.GetTypedListByNamedQuery<ISecCategory>(
                "B4F.TotalGiro.Instruments.SecCategories",
                parameters);
            return list.ToList();

            //
        }
Exemplo n.º 14
0
        public static IList<IBenchMark> GetBenchMarks(
            IDalSession session, string isin, string instrumentName, 
            int currencyNominalId, ActivityReturnFilter activityFilter)
        {
            Hashtable parameters = new Hashtable();

            if (!string.IsNullOrEmpty(isin))
                parameters.Add("isin", Util.PrepareNamedParameterWithWildcard(isin, MatchModes.Anywhere));
            if (!string.IsNullOrEmpty(instrumentName))
                parameters.Add("instrumentName", Util.PrepareNamedParameterWithWildcard(instrumentName, MatchModes.Anywhere));
            if (currencyNominalId > 0)
                parameters.Add("currencyNominalId", currencyNominalId);
            if (activityFilter != ActivityReturnFilter.All)
                parameters.Add("isActive", activityFilter == ActivityReturnFilter.Active);
            return session.GetTypedListByNamedQuery<IBenchMark>(
                "B4F.TotalGiro.Instruments.Instrument.GetBenchmarks",
                parameters);
        }
Exemplo n.º 15
0
        public static IList<IInstrumentsHistoryConversion> GetInstrumentConversions(
            IDalSession session, string isin, string instrumentName, 
            SecCategories secCategoryId, int currencyNominalId)
        {
            Hashtable parameters = new Hashtable();

            if (!string.IsNullOrEmpty(isin))
                parameters.Add("isin", Util.PrepareNamedParameterWithWildcard(isin, MatchModes.Anywhere));
            if (!string.IsNullOrEmpty(instrumentName))
                parameters.Add("instrumentName", Util.PrepareNamedParameterWithWildcard(instrumentName, MatchModes.Anywhere));
            if (secCategoryId != SecCategories.Undefined)
                parameters.Add("secCategoryId", secCategoryId);
            if (currencyNominalId > 0)
                parameters.Add("currencyNominalId", currencyNominalId);

            return session.GetTypedListByNamedQuery<IInstrumentsHistoryConversion>(
                "B4F.TotalGiro.Instruments.History.GetInstrumentConversions",
                parameters);
        }
Exemplo n.º 16
0
        public static IEndTermValue GetEndValue(IDalSession session, DateTime endTermDate, IAccount account)
        {
            Hashtable parameters = new Hashtable(2);
            parameters.Add("endTermDate", endTermDate);
            parameters.Add("account", account);

            string hqlString = @"B4F.TotalGiro.Valuations.ReportedData.GetEndValue";

            //            string hql = string.Format(
            //                @"from EndTermValue A
            //                left join ReportingPeriod R
            //                where R.EndTermDate = :endTermDate
            //                and A.Account = :account");
            IList<IEndTermValue> result =  session.GetTypedListByNamedQuery<IEndTermValue>(hqlString, parameters);
            if ((result != null) && (result.Count > 0))
                return result[0];
            else
                return null;
        }
Exemplo n.º 17
0
        public static int[] GetNotarizableBookingIds(
            IDalSession session, GeneralOperationsBookingReturnClass bookingType,
            int managementCompanyId, int accountId)
        {
            Hashtable parameters = new Hashtable();

            if (bookingType != GeneralOperationsBookingReturnClass.All)
                parameters.Add("bookingType", (int)bookingType);

            if (managementCompanyId != 0)
                parameters.Add("managementCompanyId", managementCompanyId);

            if (accountId != 0)
                parameters.Add("accountId", accountId);

            IList<int> bookingIds = session.GetTypedListByNamedQuery<int>(
                "B4F.TotalGiro.GeneralLedger.Journal.Bookings.GetNotarizableBookingIds",
                parameters);
            return bookingIds.ToArray();
        }
Exemplo n.º 18
0
        private IList<int> getAccountKeysForRunValuationMutations(IDalSession session, DateTime maxDate)
        {
            Hashtable parameters = new Hashtable();
            parameters.Add("maxDate", maxDate);
            IList<int> accountKeysPos = session.GetTypedListByNamedQuery<int>(
                "B4F.TotalGiro.Valuations.GetAccountKeysForRunValuationMutationsFromPositions",
                parameters);

            parameters.Add("settledFlag", CashPositionSettleStatus.Settled);
            parameters.Add("unSettledFlag", CashPositionSettleStatus.UnSettled);
            parameters.Add("statusBooked", JournalEntryLineStati.Booked);
            IList<int> accountKeysJournal = session.GetTypedListByNamedQuery<int>(
                "B4F.TotalGiro.Valuations.GetAccountKeysForRunValuationMutationsFromJournal",
                parameters);

            return accountKeysJournal.Union(accountKeysPos).OrderBy(x => x).ToList();
        }
Exemplo n.º 19
0
 public static IList<IModelPerformance> GetModelBenchMarkPerformance(IDalSession session, int modelID, DateTime endDate)
 {
     Hashtable parameters = new Hashtable(1);
     parameters.Add("modelID", modelID);
     parameters.Add("quarter", Util.GetQuarter(endDate));
     parameters.Add("yyyy", endDate.Year);
     return session.GetTypedListByNamedQuery<IModelPerformance>(
         "B4F.TotalGiro.Instruments.ModelBechmarkPerformances", parameters);
 }
Exemplo n.º 20
0
        public static IList<IValuation> GetValuations(IDalSession session, int accountID, DateTime[] dates, bool includeClosedPositions, ValuationTypesFilterOptions filterOption)
        {
            Hashtable parameters = new Hashtable(1);
            Hashtable parameterLists = new Hashtable(1);
            parameters.Add("accountID", accountID);
            parameterLists.Add("dates", dates);
            if (includeClosedPositions)
                parameters.Add("includeClosedPositions", 1);
            switch (filterOption)
            {
                case ValuationTypesFilterOptions.Security:
                    parameters.Add("instrumentFilterTradeableInstruments", 1);
                    break;
                case ValuationTypesFilterOptions.Monetary:
                    parameters.Add("instrumentFilterCurrencies", 1);
                    break;
            }

            return session.GetTypedListByNamedQuery<IValuation>(
                "B4F.TotalGiro.Valuations.GetValuationData",
                parameters, parameterLists);
        }
Exemplo n.º 21
0
 public static List<IValuationTotalPortfolio> GetValuationsTotalPortfolio(IDalSession session, int accountId, DateTime[] dates)
 {
     Hashtable parameters = new Hashtable(1);
     Hashtable parameterLists = new Hashtable(1);
     parameters.Add("AccountId", accountId);
     parameterLists.Add("Dates", dates);
     return session.GetTypedListByNamedQuery<IValuationTotalPortfolio>(
         "B4F.TotalGiro.Valuations.GetValuationTotalPortfolioData",
         parameters, parameterLists);
 }
Exemplo n.º 22
0
        public static List<IFundPositionTx> GetPositionTransactions(IDalSession session, IFundPosition position, bool retrieveNonClientDisplayable)
        {
            Hashtable parameters = new Hashtable();
            Hashtable parameterLists = new Hashtable(1);
            parameters.Add("accountId", position.Account.Key);
            if (!retrieveNonClientDisplayable)
                parameters.Add("showStornos", false);
            parameterLists.Add("pedigree", position.InstrumentOfPosition.GetInstrumentPedigree()
                                                                        .Cast<IInstrument>().Select(i => i.Key).ToList());

            return session.GetTypedListByNamedQuery<IFundPositionTx>(
                "B4F.TotalGiro.Accounts.Portfolios.FundPositions.GetFundPositionTxs",
                parameters,
                parameterLists);
        }
Exemplo n.º 23
0
 public static IList<IExternalInterface> GetIntrumentExternalInterfaces(IDalSession session)
 {
     IList<IExternalInterface> list = session.GetTypedListByNamedQuery<IExternalInterface>(
         "B4F.TotalGiro.Communicator.ExternalInterfaces.ExternalInterface.GetIntrumentExternalInterfaces");
     return list;
 }
Exemplo n.º 24
0
        /// <summary>
        /// Retrieves a list of all <b>CommRule</b> objects in the system.
        /// </summary>
        /// <param name="session">An instance of the Data Access Library (see class <see cref="B4F.TotalGiro.DAL.NHSession">NHSession</see>).</param>
        /// <param name="account">The number of the account property.</param>
        /// <returns>A list of all <b>CommRule</b> objects in the system.</returns>
        public static IList<ICommRule> GetCommissionRules(IDalSession session,
            string commRuleName, int commRuleTypeId, int modelId, int accountId, int instrumentId, int buySell,
            SecCategories secCategoryId, int exchangeId, DateTime startDate, DateTime endDate,
            int commCalcId, int orderActionType, int additionalCalcId, Boolean applytoAllAccounts)
        {
            Hashtable parameters = new Hashtable();

            IManagementCompany company = LoginMapper.GetCurrentManagmentCompany(session);
            if (!company.IsStichting)
                parameters.Add("companyId", company.Key);
            if (!string.IsNullOrEmpty(commRuleName))
                parameters.Add("comruleName", Util.PrepareNamedParameterWithWildcard(commRuleName, MatchModes.Anywhere));
            if (commRuleTypeId != 0 && commRuleTypeId != int.MinValue)
                parameters.Add("commRuleTypeId", commRuleTypeId);
            if (accountId != 0 && accountId != int.MinValue)
                parameters.Add("accountId", accountId);
            if (modelId != 0 && modelId != int.MinValue)
                parameters.Add("modelId", modelId);
            if (secCategoryId != 0 && (int)secCategoryId != int.MinValue)
                parameters.Add("secCategoryId", secCategoryId);
            if (instrumentId != 0 && instrumentId != int.MinValue)
                parameters.Add("instrumentId", instrumentId);
            if (buySell != 0 && buySell != int.MinValue)
                parameters.Add("buySell", buySell);
            if (exchangeId != 0 && exchangeId != int.MinValue)
                parameters.Add("exchangeId", exchangeId);
            if (commCalcId != 0 && commCalcId != int.MinValue)
                parameters.Add("commCalcId", commCalcId);
            if (additionalCalcId != 0 && additionalCalcId != int.MinValue)
                parameters.Add("additionalCalcId", additionalCalcId);
            if (Util.IsNotNullDate(startDate))
                parameters.Add("startDate", startDate);
            if (Util.IsNotNullDate(endDate))
                parameters.Add("endDate", endDate);
            if (orderActionType != 0 && orderActionType != int.MinValue)
                parameters.Add("orderActionTypeId", orderActionType);
            if (applytoAllAccounts)
                parameters.Add("applytoAllAccounts", true);

            return session.GetTypedListByNamedQuery<ICommRule>(
                "B4F.TotalGiro.Fees.CommRules.GetCommissionRules",
                parameters);
        }
Exemplo n.º 25
0
        public static List<IFundPositionTx> GetPositionTransactionsByDate(IDalSession session, int accountId, int instrumentId, DateTime positionDate)
        {
            Hashtable parameters = new Hashtable(3);
            parameters.Add("accountId", accountId);
            parameters.Add("instrumentId", instrumentId);
            parameters.Add("positionDate", positionDate);

            return session.GetTypedListByNamedQuery<IFundPositionTx>(
                "B4F.TotalGiro.Accounts.Portfolios.FundPositions.GetPositionTransactionsByDate",
                parameters);
        }
Exemplo n.º 26
0
        public static List<IFundPosition> GetPositionsByParentInstrument(IDalSession session, int accountId, int[] parentInstrumentIds, 
                                                                         PositionsView view)
        {
            Hashtable parameters = new Hashtable();
            Hashtable listParameters = new Hashtable();

            parameters.Add("accountId", accountId);

            parameters.Add("positionsViewZero", view == PositionsView.Zero ? 1 : 0);
            parameters.Add("positionsViewNotZero", view == PositionsView.NotZero ? 1 : 0);
            parameters.Add("positionsViewAll", view == PositionsView.All ? 1 : 0);

            listParameters.Add("parentInstrumentIds", parentInstrumentIds);
            return session.GetTypedListByNamedQuery<IFundPosition>(
                "B4F.TotalGiro.Accounts.Portfolios.FundPositions.GetFundPositions",
                parameters,
                listParameters);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Retrieves a list of all <b>FeeRule</b> objects in the system.
        /// </summary>
        /// <param name="session">An instance of the Data Access Library (see class <see cref="B4F.TotalGiro.DAL.NHSession">NHSession</see>).</param>
        /// <returns>A list of all <b>CommRule</b> objects in the system.</returns>
        public static IList<IFeeRule> GetFeeRules(IDalSession session,
            int feeCalcId, int modelId, int accountId, int startPeriod, int endPeriod,
            bool isDefault, bool hasEmployerRelation, bool executionOnly, bool sendByPost)
        {
            Hashtable parameters = new Hashtable();

            IManagementCompany company = LoginMapper.GetCurrentManagmentCompany(session);
            if (!company.IsStichting)
                parameters.Add("companyId", company.Key);
            if (feeCalcId != 0 && (int)feeCalcId != int.MinValue)
                parameters.Add("feeCalcId", feeCalcId);
            if (accountId != 0 && accountId != int.MinValue)
                parameters.Add("accountId", accountId);
            if (modelId != 0 && modelId != int.MinValue)
                parameters.Add("modelId", modelId);
            if (startPeriod != 0)
                parameters.Add("startPeriod", startPeriod);
            if (endPeriod != 0)
                parameters.Add("endPeriod", endPeriod);
            if (isDefault)
                parameters.Add("isDefault", isDefault);
            if (hasEmployerRelation)
                parameters.Add("hasEmployerRelation", hasEmployerRelation);
            if (executionOnly)
                parameters.Add("executionOnly", executionOnly);
            if (sendByPost)
                parameters.Add("sendByPost", sendByPost);

            return session.GetTypedListByNamedQuery<IFeeRule>(
                "B4F.TotalGiro.Fees.FeeRules.GetFeeRules",
                parameters);
        }
Exemplo n.º 28
0
        private bool getFundPositionTxData(IDalSession session, IAccountTypeCustomer account, DateTime maxDate, out IList<IFundPositionTx> posTxs)
        {
            Hashtable parameters = new Hashtable();
            parameters.Add("accountID",account.Key);
            parameters.Add("maxDate",maxDate);

            posTxs = session.GetTypedListByNamedQuery<IFundPositionTx>(
                "B4F.TotalGiro.Valuations.GetFundPositionTxData",
                parameters);
            return (posTxs != null && posTxs.Count > 0);
        }
Exemplo n.º 29
0
        private bool getJournalEntryLineData(IDalSession session, IAccountTypeCustomer account, DateTime maxDate, out IList<IJournalEntryLine> lines)
        {
            Hashtable parameters = new Hashtable();
            parameters.Add("accountID", account.Key);
            parameters.Add("maxDate", maxDate);
            parameters.Add("settledFlag", CashPositionSettleStatus.Settled);
            parameters.Add("unSettledFlag", CashPositionSettleStatus.UnSettled);
            parameters.Add("statusBooked", JournalEntryLineStati.Booked);

            lines = session.GetTypedListByNamedQuery<IJournalEntryLine>(
                "B4F.TotalGiro.Valuations.GetJournalEntryLineData",
                parameters);
            return (lines != null && lines.Count > 0);
        }
Exemplo n.º 30
0
        public static IList GetUnitFeeOverviewList(
            IDalSession session, int assetManagerId, int remisierId, int remisierEmployeeId, 
            int modelPortfolioId, string accountNumber, string accountName, bool showActive, 
            bool showInactive, int year, int quarter, AccountContinuationStati continuationStatus, 
            ManagementTypes managementType,ManagementPeriodUnitTradeStatus tradeStatus, 
            bool includeStornoedUnits, int[] mgtPeriodIds, string sortColumn, 
            bool ascending, bool keysOnly)
        {
            Hashtable parameterLists = new Hashtable(1);
            Hashtable parameters = new Hashtable();
            string where = GetUnitFeeOverviewWhereClause(assetManagerId, remisierId, remisierEmployeeId,
                modelPortfolioId, accountNumber, accountName, showActive, showInactive, year, quarter,
                continuationStatus, managementType, tradeStatus, includeStornoedUnits, parameters, !keysOnly);

            if (mgtPeriodIds != null)
                where += string.Format(" and P.Key IN ({0})",
                    (mgtPeriodIds.Length == 0 ? "0" : string.Join(", ", Array.ConvertAll<int, string>(mgtPeriodIds, id => id.ToString()))));

            parameterLists.Add("periods", Util.GetPeriodsFromQuarter(year, quarter));
            parameters.Add("managementType", managementType);

            if (keysOnly)
            {
                string orderBy = "order by A.Number", contactsJoin = "";
                bool sortOnRemisier = false;
                if (sortColumn != "")
                {
                    string ascendingStr = (ascending ? "ASC" : "DESC");
                    sortColumn = sortColumn.ToUpper();

                    string sortProperty = "";
                    switch (sortColumn)
                    {
                        case "KEY":
                            sortProperty = "P.Key";
                            break;
                        case "ACCOUNT_NUMBER":
                            sortProperty = "A.Number";
                            break;
                        case "ACCOUNT_SHORTNAME":
                            sortProperty = "CN.Name";
                            contactsJoin = @"left join A.bagOfAccountHolders AH
                                         left join AH.Contact C
                                         left join C.CurrentNAW CN";
                            where += " and AH.IsPrimaryAccountHolder = true";
                            break;
                        case "MANAGEMENTENDDATE":
                            sortProperty = "P.endDate";
                            break;
                        case "TRADEID":
                            sortProperty = "T.Key";
                            break;
                        case "ACCOUNT_REMISIEREMPLOYEE_REMISIER_NAME":
                            sortProperty = "R.Name";
                            sortOnRemisier = true;
                            break;
                        case "ACCOUNT_REMISIEREMPLOYEE_EMPLOYEE_FULLNAME":
                            sortProperty = "E.Employee.LastName";
                            sortOnRemisier = true;
                            break;
                    }

                    if (sortProperty != "")
                        orderBy = string.Format("order by {0} {1}", sortProperty, ascendingStr);
                }

                string hql = string.Format(@"select distinct P.Key, P.endDate, A.Number, A.Status, T.Key{0}{5}
                from ManagementPeriodUnit U
                left join U.ManagementPeriod P
                left join U.UnitParent PU
                left join U.ManagementFee T
                left join PU.Account A
                {1}
                {2}
                {6}
                where (A.Family.managementTypesCharged & :managementType) <> 0
                and PU.Period in (:periods) {3}
                and P.ManagementType = :managementType {4}",
                        (contactsJoin != "" ? ", CN.Name" : ""),
                        contactsJoin,
                        modelPortfolioId > 0 ? "left join A.ModelPortfolio M " : "",
                        where, orderBy,
                        (sortOnRemisier ? ", R.Name, E.Employee.LastName" : ""),
                        (sortOnRemisier ? "left join A.RemisierEmployee E left join E.Remisier R" : ""));
                return session.GetListByHQL(hql, parameters, parameterLists);
            }
            else
            {
                string queryName;
                if (managementType == ManagementTypes.KickBack)
                    queryName = "B4F.TotalGiro.ApplicationLayer.Fee.ManagementPeriodUnitsForMgtFee";
                else
                    queryName = "B4F.TotalGiro.ApplicationLayer.Fee.ManagementPeriodUnitsForKickBack";

                IList<IManagementPeriodUnit> units = session.GetTypedListByNamedQuery<IManagementPeriodUnit>(queryName, where, parameters, parameterLists);
                if (units != null && units.Count > 0)
                {
                    IList avgHldFees = ManagementPeriodUnitMapper.GetManagementFees(session, mgtPeriodIds, ManagementFeeLocations.AverageHolding, year, quarter, managementType);
                    IList unitFees = ManagementPeriodUnitMapper.GetManagementFees(session, mgtPeriodIds, ManagementFeeLocations.Unit, year, quarter, managementType);
                    ICurrency currency = InstrumentMapper.GetBaseCurrency(session);

                    var fees = from a in avgHldFees.Cast<object[]>().Union(unitFees.Cast<object[]>())
                               select new { MgtPeriodID = (int)a[0], Period = (int)a[1], FeeType = (FeeTypes)a[2], FeeAmount = (decimal)a[3] };

                    var stuff = from u in units
                                join f in fees on new { MgtPeriodID = u.ManagementPeriod.Key, u.Period } equals new { f.MgtPeriodID, f.Period } into x
                                from f in x.DefaultIfEmpty()
                                group new { u, fp = (f != null ? new { Period = (int)f.Period, FeeAmount = new Money((decimal)f.FeeAmount, currency) } : null) } by u.ManagementPeriod
                                    into g
                                    select new { ManagementPeriod = g.Key, Units = (from gi in g select gi.u).ToList(), FeeAmounts = (from gj in g select gj.fp).ToList() };

                    List<UnitFeeOverview> list = new List<UnitFeeOverview>();
                    UnitFeeOverview.Year = year.ToString();
                    UnitFeeOverview.Quarter = string.Format("Q{0}", quarter);
                    UnitFeeOverview.Periods = Util.GetPeriodsFromQuarter(year, quarter);

                    //stuff.ToList().ForEach(p => list.Add(new UnitFeeOverview(p.Account, p.Units)));
                    foreach (var pair in stuff)
                    {
                        UnitFeeOverview item = new UnitFeeOverview(pair.ManagementPeriod, pair.Units);
                        foreach (var fee in pair.FeeAmounts)
                        {
                            if (fee != null)
                                item.AddFeeDetails(fee.Period, fee.FeeAmount);
                        }
                        list.Add(item);
                    }
                    return list;
                }
            }
            return null;
        }