Example #1
0
        public static AccountDetails GetAccountDetails(int accountNrID)
        {
            IDalSession session = NHSessionFactory.CreateSession();
            IAccountTypeCustomer acc = (IAccountTypeCustomer)AccountMapper.GetAccount(session, accountNrID);
            AccountDetails returnValue = new AccountDetails()
            {
                AccountNrID = accountNrID,
                AccountNumber = String.Empty,
                FamilyID = int.MinValue,
                AssetManagerKey = int.MinValue,
                Modelid = int.MinValue,
                LifecycleId = int.MinValue,
                AccountShortName = string.Empty,
                AccountFullName = string.Empty,
                VerpandSoortID = int.MinValue,
                PandHouderID = int.MinValue,
                CounterAccountID = int.MinValue,
                CreationDate = DateTime.MinValue,
                LastUpDated = DateTime.MinValue,
                LastDateStatusChanged = DateTime.MinValue,
                FirstManagementStartDate = DateTime.MinValue,
                FinalManagementEndDate = DateTime.MinValue,
                DateTradeabilityStatusChanged = DateTime.MinValue,
                ExitFeePayingAccountID = int.MinValue,
                RemisierID = int.MinValue,
                RemisierEmployeeID = int.MinValue,
                EmployerRelationship = AccountEmployerRelationship.None,
                RelatedEmployeeID = int.MinValue,
                FirstPromisedDeposit = 0.00m,
                UseManagementFee = true,
                IsCustomer = true
            };

            if (acc != null)
            {
                returnValue.AccountNrID = acc.Key;
                returnValue.AccountNumber = acc.Number;
                if (acc.AccountOwner != null)
                {
                    returnValue.AssetManagerKey = acc.AccountOwner.Key;
                    returnValue.AssetManagerName = acc.AccountOwner.CompanyName;
                    if (acc.AccountOwner.CompanyType == ManagementCompanyType.AssetManager)
                        returnValue.AssetManagerSupportLifecycles = ((IAssetManager)acc.AccountOwner).SupportLifecycles;
                }
                if (acc.ModelPortfolio != null)
                {
                    returnValue.Modelid = acc.ModelPortfolio.Key;
                    returnValue.ModelAllowExecOnlyCustomers = acc.ModelPortfolio.AllowExecOnlyCustomers;
                }
                if (acc.Lifecycle != null)
                    returnValue.LifecycleId = acc.Lifecycle.Key;
                returnValue.IsExecOnlyCustomer = acc.IsExecOnlyCustomer;

                if (acc.ShortName != null)
                    returnValue.AccountShortName = acc.ShortName;

                if (acc.FullName != null)
                    returnValue.AccountFullName = acc.FullName;

                if (acc.CounterAccount != null)
                    returnValue.CounterAccountID = acc.CounterAccount.Key;

                returnValue.TradeableStatus = acc.TradeableStatus;

                returnValue.Status = acc.Status;

                AccountStatus statusObj = AccountMapper.GetAccountStatus(session, acc.Status);
                returnValue.StatusIsOpen = (statusObj != null ? statusObj.IsOpen : true);

                returnValue.CreationDate = acc.CreationDate;
                returnValue.LastUpDated = acc.LastUpdated;
                returnValue.LastDateStatusChanged = acc.LastDateStatusChanged;
                returnValue.DateTradeabilityStatusChanged = acc.DateTradeabilityStatusChanged;

                returnValue.FirstManagementStartDate = acc.FirstManagementStartDate;
                returnValue.FinalManagementEndDate = acc.FinalManagementEndDate;

                if (!acc.ExitFeePayingAccount.Equals(acc))
                    returnValue.ExitFeePayingAccountID = acc.ExitFeePayingAccount.Key;

                returnValue.UseManagementFee = acc.UseManagementFee;
                returnValue.UseKickBack = acc.UseKickback;

                returnValue.Notification = acc.Notifications.DisplayMessages;
                returnValue.NotificationType = acc.Notifications.DisplayNotificationType;
                returnValue.IsDeparting = acc.IsDeparting;
                returnValue.IsUnderRebalance = acc.IsUnderRebalance;

                if (acc.AccountType == AccountTypes.Customer)
                {
                    ICustomerAccount cust = (ICustomerAccount)acc;
                    returnValue.IsJointAccount = cust.IsJointAccount;
                    if (cust.Family != null)
                        returnValue.FamilyID = cust.Family.Key;
                    if (cust.VerpandSoort != null)
                        returnValue.VerpandSoortID = cust.VerpandSoort.Key;

                    if (cust.PandHouder != null)
                        returnValue.PandHouderID = cust.PandHouder.Key;

                    returnValue.ContactContractsValidated = cust.ContactContractsValidated;

                    if (cust.RemisierEmployee != null)
                    {
                        returnValue.RemisierID = cust.RemisierEmployee.Remisier.Key;
                        returnValue.RemisierEmployeeID = cust.RemisierEmployee.Key;
                    }

                    if (cust.CurrentRemisierDetails != null)
                    {
                        returnValue.KickBack = cust.CurrentRemisierDetails.KickBack;
                        returnValue.IntroductionFee = cust.CurrentRemisierDetails.IntroductionFee;
                        returnValue.SubsequentDepositFee = cust.CurrentRemisierDetails.SubsequentDepositFee;
                        returnValue.IntroductionFeeReduction = cust.CurrentRemisierDetails.IntroductionFeeReduction;
                        returnValue.SubsequentDepositFeeReduction = cust.CurrentRemisierDetails.SubsequentDepositFeeReduction;
                    }

                    returnValue.EmployerRelationship = cust.EmployerRelationship;
                    if (cust.RelatedEmployee != null)
                        returnValue.RelatedEmployeeID = cust.RelatedEmployee.Key;

                    if (cust.FirstPromisedDeposit != null)
                        returnValue.FirstPromisedDeposit = cust.FirstPromisedDeposit.Quantity;
                }
                else
                    returnValue.IsCustomer = false;
            }
            session.Close();
            return returnValue;
        }
Example #2
0
        public static void SaveCustomerAccount(AccountDetails saveValue, bool forceClosedStatus, out bool askConfirmation, out string message)
        {
            if (!SecurityManager.IsCurrentUserInRole("Data Mtce: Account Edit"))
                throw new System.Security.SecurityException("You are not authorized to update account details.");

            IDalSession session = NHSessionFactory.CreateSession();
            message = "";
            try
            {
                ICustomerAccount acc = null;
                bool isNewAccount = false;
                IPortfolioModel model = null;
                IPandHouder pandhouder = null;
                IVerpandSoort verpandSoort = null;
                ICounterAccount counterAccount = null;
                IInternalEmployeeLogin relatedEmployee = null;
                IRemisierEmployee remisierEmployee = null;
                IAccountTypeCustomer exitFeePayer = null;
                Money firstPromisedDeposit = null;
                DateTime upDateTime = session.GetServerTime();
                IInternalEmployeeLogin employee = (IInternalEmployeeLogin)LoginMapper.GetCurrentLogin(session);

                if (saveValue.AccountNrID == int.MinValue)
                    isNewAccount = true;

                if (saveValue.PandHouderID != int.MinValue)
                    pandhouder = PandHouderMapper.GetPandHouder(session, saveValue.PandHouderID);

                if (saveValue.VerpandSoortID != int.MinValue)
                    verpandSoort = VerpandSoortMapper.GetVerpandSoort(session, saveValue.VerpandSoortID);

                if (saveValue.CounterAccountID != int.MinValue)
                    counterAccount = CounterAccountMapper.GetCounterAccount(session, saveValue.CounterAccountID);

                if (saveValue.Modelid != int.MinValue)
                    model = ModelMapper.GetModel(session, saveValue.Modelid);

                if (saveValue.ExitFeePayingAccountID != int.MinValue)
                    exitFeePayer = (IAccountTypeCustomer)AccountMapper.GetAccount(session, saveValue.ExitFeePayingAccountID);

                if (saveValue.RemisierEmployeeID != int.MinValue)
                    remisierEmployee = RemisierEmployeeMapper.GetRemisierEmployee(session, saveValue.RemisierEmployeeID);

                if (saveValue.RelatedEmployeeID != int.MinValue)
                    relatedEmployee = (IInternalEmployeeLogin)LoginMapper.GetLogin(session, saveValue.RelatedEmployeeID);

                if (saveValue.FirstPromisedDeposit > 0M)
                {
                    ICurrency baseCurrency = InstrumentMapper.GetBaseCurrency(session);
                    firstPromisedDeposit = new Money(saveValue.FirstPromisedDeposit, baseCurrency);
                }

                IAssetManager am = ManagementCompanyMapper.GetAssetManager(session, saveValue.AssetManagerKey);

                if (isNewAccount)
                {
                    //string newAccountNr = am.GenerateAccountNumber();
                    //acc = new CustomerAccount(newAccountNr, "", am, model);
                }
                else
                {
                    acc = (ICustomerAccount)AccountMapper.GetAccount(session, saveValue.AccountNrID);

                    acc.Family = AccountFamilyMapper.GetAccountFamily(session, saveValue.FamilyID);

                    if (!AccountMapper.AccountStatusIsOpen(session, acc.Status))
                        throw new ApplicationException("Could not save account because its status is already closed.");

                    acc.AccountOwner = am;
                }

                askConfirmation = false;

                if (!isNewAccount && !AccountMapper.AccountStatusIsOpen(session, saveValue.Status))
                {
                    //IList positions = AccountMapper.GetPositions(session, acc, PositionReturnClass.AllPositions, PositionsView.NotZero);
                    //if (positions.Count > 0)
                    //    throw new ApplicationException(
                    //        string.Format("Could not close account because it has {0} open position{1} ({2} total portfolio value).",
                    //                      positions.Count, (positions.Count > 1 ? "s" : ""), acc.TotalPositionAmount(PositionAmountReturnValue.All)));

                    //if (!forceClosedStatus)
                    //{
                    //    askConfirmation = true;
                    //    return;
                    //}
                }

                if (am.SupportLifecycles && ((acc.Lifecycle != null ? acc.Lifecycle.Key : int.MinValue) != saveValue.LifecycleId))
                {
                    if (saveValue.LifecycleId != int.MinValue)
                        AccountOverviewAdapter.CheckLifecycleForAccount(acc, acc.PrimaryAccountHolder);

                    acc.Lifecycle = saveValue.LifecycleId != int.MinValue ? LifecycleMapper.GetLifecycle(session, saveValue.LifecycleId) : null;
                }

                if ((acc.ModelPortfolio == null && saveValue.Modelid != int.MinValue )
                    || (acc.ModelPortfolio != null && acc.ModelPortfolio.Key != saveValue.Modelid)
                    || acc.IsExecOnlyCustomer != saveValue.IsExecOnlyCustomer
                    || acc.EmployerRelationship != saveValue.EmployerRelationship
                    || isNewAccount)
                {
                    if (acc.ModelPortfolio != null && model == null && acc.TradeableStatus == Tradeability.Tradeable)
                        throw new ApplicationException("The Model is mandatory when the account is tradeable.");

                    if (acc.ActiveRebalanceInstructions != null && acc.ActiveRebalanceInstructions.Count > 0)
                    {
                        foreach (IInstruction instruction in acc.ActiveRebalanceInstructions)
                        {
                            if (instruction.Status > 1)
                                throw new ApplicationException(string.Format("It is currently not possible to change the Model since an active rebalance instruction exists for account {0}.", acc.DisplayNumberWithName));
                        }
                    }
                    acc.SetModelPortfolio(acc.Lifecycle, model, saveValue.IsExecOnlyCustomer, saveValue.EmployerRelationship, employee, DateTime.Now);
                }

                acc.IsJointAccount = saveValue.IsJointAccount;
                acc.ShortName = saveValue.AccountShortName;
                acc.VerpandSoort = verpandSoort;
                acc.PandHouder = pandhouder;
                acc.CounterAccount = counterAccount;
                acc.ExitFeePayingAccount = exitFeePayer;
                acc.EmployerRelationship = saveValue.EmployerRelationship;
                acc.RelatedEmployee = relatedEmployee;
                acc.FirstPromisedDeposit = firstPromisedDeposit;
                DateTime originalMgtEndDate = acc.ManagementEndDate;
                acc.FinalManagementEndDate = saveValue.FinalManagementEndDate;
                if (acc.TradeableStatus != saveValue.TradeableStatus)
                {
                    // check
                    if (saveValue.TradeableStatus == Tradeability.Tradeable && acc.ModelPortfolio == null)
                        throw new ApplicationException("A Model is mandatory on the account to be tradeable.");

                    acc.DateTradeabilityStatusChanged = upDateTime;
                    acc.TradeableStatus = saveValue.TradeableStatus;
                }

                if (acc.Status != saveValue.Status)
                {
                    acc.LastDateStatusChanged = upDateTime;
                    acc.Status = saveValue.Status;

                    if (!AccountMapper.AccountStatusIsOpen(session, acc.Status))
                    {
                        // Set Closed Model
                        if (acc.AccountOwner.CompanyType == ManagementCompanyType.AssetManager)
                        {
                            IPortfolioModel closedModel = ((IAssetManager)acc.AccountOwner).ClosedModelPortfolio;
                            if (closedModel != null)
                                acc.SetModelPortfolio(acc.Lifecycle, closedModel, acc.IsExecOnlyCustomer, acc.EmployerRelationship, employee, acc.LastDateStatusChanged.Date);
                        }

                        DateTime finalEndDate = Util.IsNotNullDate(acc.ManagementEndDate) ? acc.ManagementEndDate : acc.LastDateStatusChanged.Date;
                        acc.ValuationsEndDate = finalEndDate;
                        if (Util.IsNullDate(acc.FinalManagementEndDate))
                            acc.FinalManagementEndDate = finalEndDate;
                    }
                }

                if (Util.IsNullDate(originalMgtEndDate) && Util.IsNotNullDate(saveValue.FinalManagementEndDate))
                {
                    if (acc.ActiveWithdrawalInstructions.Count > 0)
                    {
                        InstructionEngine engine = new InstructionEngine();
                        int instructionsCount = 0;
                        foreach (ICashWithdrawalInstruction instruction in acc.ActiveWithdrawalInstructions)
                        {
                            if (instruction.WithdrawalDate >= saveValue.FinalManagementEndDate)
                            {
                                if (engine.CancelInstruction(instruction))
                                    instructionsCount++;
                                else
                                    throw new ApplicationException(
                                        string.Format("Could not set the Management End since withdrawal instruction {0} could not be cancelled, please cancel the instruction in the 'Withdrawal Management Console'.", instruction.Key));
                            }
                        }
                        message = string.Format("{0} withdrawal instruction(s) were cancelled", instructionsCount);
                    }

                    if (acc.WithdrawalRules.Count > 0)
                    {
                        int rulesCount = 0;
                        foreach (IWithdrawalRule rule in acc.WithdrawalRules)
                        {
                            if (rule.IsActive && (Util.IsNullDate(rule.EndDateWithdrawal) || rule.EndDateWithdrawal > saveValue.FinalManagementEndDate))
                            {
                                rule.EndDateWithdrawal = saveValue.FinalManagementEndDate;
                                rulesCount++;
                            }
                        }
                        message += Environment.NewLine + string.Format("{0} withdrawal rule(s) were cancelled", rulesCount);
                    }
                }

                // if FinalManagementEndDate > ValuationsEndDate -> update ValuationsEndDate
                if (Util.IsNotNullDate(acc.ValuationsEndDate) && acc.FinalManagementEndDate > acc.ValuationsEndDate)
                    acc.ValuationsEndDate = acc.FinalManagementEndDate;

                if (acc.UseManagementFee != saveValue.UseManagementFee)
                    acc.UseManagementFee = saveValue.UseManagementFee;
                if (acc.UseKickback != saveValue.UseKickBack)
                    acc.UseKickback = saveValue.UseKickBack;
                IRemisierHistory rh = new RemisierHistory(remisierEmployee, saveValue.KickBack, saveValue.IntroductionFee, saveValue.IntroductionFeeReduction, saveValue.SubsequentDepositFee, saveValue.SubsequentDepositFeeReduction, employee, DateTime.Now.Date);
                if (acc.CurrentRemisierDetails == null || !acc.CurrentRemisierDetails.Equals(rh))
                    acc.RemisierDetailChanges.Add(rh);

                if (isNewAccount)
                    AccountMapper.Insert(session, acc);
                else
                    AccountMapper.Update(session, acc);
            }
            finally
            {
                session.Close();
            }
        }