コード例 #1
0
        public static bool CreateDepartureInstructions(BatchExecutionResults results, int[] accountIds, DateTime executionDate, int? counterAccountID, string transferDescription, bool noCharges)
        {
            bool retVal = false;
            if (accountIds == null || accountIds.Count() == 0)
                throw new B4F.TotalGiro.ApplicationLayer.Common.GridviewNoSelectionException();

            using (IDalSession session = NHSessionFactory.CreateSession())
            {
                ICounterAccount counterAcc = null;
                if (counterAccountID.HasValue && counterAccountID.Value != 0)
                    counterAcc = CounterAccountMapper.GetCounterAccount(session, counterAccountID.Value);

                IList<IAccountTypeCustomer> accounts = AccountMapper.GetAccounts<IAccountTypeCustomer>(session, accountIds);
                if (accounts != null && accounts.Count > 0)
                {
                    IList saveAccounts = new ArrayList();
                    foreach (IAccountTypeCustomer account in accounts)
                    {
                        try
                        {
                            int? withdrawalCount = account.ActiveWithdrawalInstructions.GetV(e => e.Count);
                            if (withdrawalCount.HasValue && withdrawalCount.Value > 0)
                                throw new ApplicationException(string.Format("{0} withdrawal instructions exist and need to be cancelled before the clients portfolio can be liquidated.", withdrawalCount.Value));

                            IClientDepartureInstruction instruction = account.CreateDepartureInstruction(executionDate, counterAcc, transferDescription, noCharges);
                            if (instruction != null)
                            {
                                saveAccounts.Add(account);
                                results.MarkSuccess();
                                if (instruction.CounterAccount == null)
                                    results.MarkWarning(string.Format("Account {0} does not have a default counter account. Please look up it's counter account otherwise the client can not be paid.", instruction.Account.DisplayNumberWithName));
                            }
                        }
                        catch (Exception ex)
                        {
                            results.MarkError(
                                new ApplicationException(string.Format("Error creating departure instruction  for {0}.", account.DisplayNumberWithName), ex));
                        }
                    }
                    retVal = AccountMapper.UpDateList(session, saveAccounts);
                }
            }
            return retVal;
        }
コード例 #2
0
        public static void UpdateLifecycleModelToAge(BatchExecutionResults results)
        {
            using (IDalSession session = NHSessionFactory.CreateSession())
            {
                try
                {
                    IManagementCompany comp = LoginMapper.GetCurrentManagmentCompany(session);
                    IInternalEmployeeLogin employee = (IInternalEmployeeLogin)LoginMapper.GetCurrentLogin(session);

                    Hashtable parameters = new Hashtable();
                    if (!comp.IsStichting)
                    {
                        IAssetManager am = (IAssetManager)comp;
                        if (!am.SupportLifecycles)
                            throw new ApplicationException("This asset manager does not support lifecycles.");
                        else
                            parameters.Add("managementCompanyID", am.Key);
                    }

                    List<ILifecycle> cycles = session.GetTypedListByNamedQuery<ILifecycle>(
                        "B4F.TotalGiro.Instruments.ActiveLifecycles",
                        parameters);

                    List<ILifecycleLine> lines = cycles.SelectMany(x => x.Lines).ToList();

                    List<Object> accountWithLifecycleData = session.GetTypedListByNamedQuery<Object>(
                        "B4F.TotalGiro.Instruments.AccountWithLifecycleData",
                        parameters);

                    var acctData = from a in accountWithLifecycleData.Cast<object[]>()
                                   where (DateTime)(a[4] ?? a[5] ?? DateTime.MinValue) != DateTime.MinValue
                                   select new
                                   {
                                       AccountID = (int)a[0],
                                       ModelID = (int)(a[2] ?? 0),
                                       LifecycleID = (int)a[3],
                                       Age = Util.CalculateCurrentAge((DateTime)(a[4] ?? a[5]))
                                   };

                    var acctNoBirthDate = from a in accountWithLifecycleData.Cast<object[]>()
                                          where (DateTime)(a[4] ?? a[5] ?? DateTime.MinValue) == DateTime.MinValue
                                          select (string)a[1];

                    if (acctNoBirthDate.Count() > 0)
                        results.MarkWarning(string.Format("{0} accounts have a primary account holder without a proper birth date: {1}",
                            acctNoBirthDate.Count(),
                            acctNoBirthDate.Take(25).JoinStrings(",")));

                    var acctIds = from x in acctData
                                  join y in lines on x.LifecycleID equals y.Parent.Key
                                  where x.Age >= y.AgeFrom && x.Age < y.AgeTo && x.ModelID != y.Model.Key
                                  select new { x.AccountID, x.Age }; //, x.Age, x.ModelID, y.AgeFrom, y.AgeTo, y.Model.ModelName };

                    foreach (var acctId in acctIds)
                    {
                        ICustomerAccount acc = (ICustomerAccount)AccountMapper.GetAccount(session, acctId.AccountID);
                        if (acc.IsDeparting)
                            results.MarkWarning(string.Format("Account {0} is departing so the model will not be updated", acc.DisplayNumberWithName));
                        else if (acc.IsUnderRebalance)
                            results.MarkWarning(string.Format("Account {0} is under rebalance so the model will not be updated", acc.DisplayNumberWithName));
                        else
                        {
                            ILifecycle lc = acc.Lifecycle;
                            IPortfolioModel model = null;
                            if (lc != null)
                            {
                                model = lc.GetRelevantModel(acctId.Age);
                                if (!acc.ModelPortfolio.Equals(model))
                                    acc.SetModelPortfolio(acc.Lifecycle, model, acc.IsExecOnlyCustomer, acc.EmployerRelationship, employee, DateTime.Now);
                                if (AccountMapper.Update(session, acc))
                                    results.MarkSuccess();
                            }
                            else
                                results.MarkError(
                                    new ApplicationException(string.Format("Account {0} did not have a lifecycle.", acc.DisplayNumberWithName)));
                        }
                    }
                }
                catch (Exception ex)
                {
                    results.MarkError(
                        new ApplicationException("Error in UpdateLifecycleModelToAge.", ex));
                }
            }
        }