private bool terminateAccount(IClientDepartureInstruction instruction) { DateTime finalEndDate = instruction.Account.FinalManagementEndDate; if (Util.IsNullDate(finalEndDate)) finalEndDate = DateTime.Today; IPortfolioModel closedModel = ((IAssetManager)instruction.Account.AccountOwner).ClosedModelPortfolio; if (closedModel != null) { using (IDalSession session = NHSessionFactory.CreateSession()) { IInternalEmployeeLogin employee = (IInternalEmployeeLogin)LoginMapper.GetCurrentLogin(session); instruction.Account.SetModelPortfolio(closedModel, employee, finalEndDate.AddDays(1)); } } instruction.Account.LastDateStatusChanged = DateTime.Now; instruction.Account.ValuationsEndDate = finalEndDate; instruction.Account.Status = AccountStati.Inactive; return true; }
private bool transferAllCash(IClientDepartureInstruction instruction) { bool success = false; // Create MoneyTransferOrder Money totalValue = instruction.Account.TotalAll; if (totalValue.IsGreaterThanZero && instruction.MoneyTransferOrder == null) { if (instruction.Account.Portfolio.PortfolioInstrument.Where(x => x.Size.IsNotZero).Count() > 0) instruction.Message += "Active positions still exist. Cancel this instruction and create a new one."; else { Money moneyOrderAmount = instruction.Account.ActiveMoneyTransferOrders.Select(x => x.Amount).Sum(); if ((totalValue - moneyOrderAmount).IsGreaterThanZero) { IMoneyTransferOrder moneyOrder = new MoneyTransferOrder(instruction, totalValue); instruction.MoneyTransferOrder = moneyOrder; instruction.Message += string.Format("Money Transfer order created ({0})", moneyOrder.Amount.DisplayString); success = true; } else instruction.Message += string.Format("Money Transfer not possible since active moneyorders already exist ({0})", moneyOrderAmount.DisplayString); } } return success; }
private bool settleAccount(IClientDepartureInstruction instruction) { bool mgtFeeCharged = false; instruction.Message = ""; if (instruction.CounterAccount == null) { instruction.Message = "Could not settle the account, look up the counter account."; return false; } IManagementPeriod managementPeriod = instruction.Account.CurrentManagementFeePeriod; if (managementPeriod != null) { IList<IManagementPeriodUnit> unitsNotCharged = managementPeriod.ManagementPeriodUnits .Where(x => x.ManagementFee == null) .OrderByDescending(x => x.StartDate) .ToList(); Dictionary<int, Tuple<int, int>> quarterYears = new Dictionary<int, Tuple<int, int>>(); if (unitsNotCharged != null && unitsNotCharged.Count > 0) { BatchExecutionResults results = new BatchExecutionResults(); IManagementPeriodUnit lastUnit = unitsNotCharged.FirstOrDefault(); if (lastUnit != null && lastUnit.EndDate.Equals(managementPeriod.EndDate)) { // get all quarter periods not yet charged foreach (IManagementPeriodUnit unit in unitsNotCharged) { Tuple<int, int> quarterYear = new Tuple<int, int>(Util.GetQuarter(unit.EndDate), unit.EndDate.Year); int key = quarterYear.Item2 * 100 + quarterYear.Item1; if (!quarterYears.ContainsKey(key)) quarterYears.Add(key, quarterYear); } if (quarterYears.Count() == 0) { instruction.Message = "Could not charge management fee."; return false; } else if (quarterYears.Count() == 1) { mgtFeeCharged = ManagementFeeOverviewAdapter.CreateMgtFeeTransactions(results, new int[] { lastUnit.ManagementPeriod.Key }, quarterYears.Values.First().Item2, quarterYears.Values.First().Item1, B4F.TotalGiro.Accounts.ManagementPeriods.ManagementTypes.ManagementFee, false); } else if (quarterYears.Count() > 1) { // Only charge last 2 // check if last 2 are chronological int maxItemKey = quarterYears.Keys.OrderByDescending(x => x).ElementAt(0); int prevItemKey = quarterYears.Keys.OrderByDescending(x => x).ElementAt(1); Tuple<int, int> maxQuarterYear = quarterYears[maxItemKey]; if (Util.GetPreviousQuarterYear(maxQuarterYear.Item1, maxQuarterYear.Item2).Equals(quarterYears[prevItemKey])) ManagementFeeOverviewAdapter.CreateMgtFeeTransactions(results, new int[] { lastUnit.ManagementPeriod.Key }, quarterYears[prevItemKey].Item2, quarterYears[prevItemKey].Item1, B4F.TotalGiro.Accounts.ManagementPeriods.ManagementTypes.ManagementFee, false); mgtFeeCharged = ManagementFeeOverviewAdapter.CreateMgtFeeTransactions(results, new int[] { lastUnit.ManagementPeriod.Key }, quarterYears[maxItemKey].Item2, quarterYears[maxItemKey].Item1, B4F.TotalGiro.Accounts.ManagementPeriods.ManagementTypes.ManagementFee, false); } instruction.Message = ManagementFeeOverviewAdapter.FormatErrorsForCreateMgtFeeTransactions(results).Replace("<br/>", ""); } else { // check if lastUnit is charged IManagementPeriodUnit lastChargedUnit = managementPeriod.ManagementPeriodUnits .Where(x => x.ManagementFee != null) .OrderByDescending(x => x.StartDate) .FirstOrDefault(); if (lastChargedUnit != null && lastChargedUnit.EndDate.Equals(managementPeriod.EndDate)) { if (lastUnit == null) mgtFeeCharged = true; else { Tuple<int, int> lastQY = new Tuple<int, int>(Util.GetQuarter(lastChargedUnit.EndDate), lastChargedUnit.EndDate.Year); Tuple<int, int> unChargedQY = new Tuple<int, int>(Util.GetQuarter(lastUnit.EndDate), lastUnit.EndDate.Year); if (Util.GetPreviousQuarterYear(lastQY.Item1, lastQY.Item2).Equals(unChargedQY)) instruction.Message = "The previous quarter {0}{1} has not been charged"; else mgtFeeCharged = true; } } } } } else mgtFeeCharged = true; if (mgtFeeCharged) { transferAllCash(instruction); } return true; }
private bool liquidatePortfolio(IClientDepartureInstruction instruction) { bool retVal = false; bool sizeBasedOrdersExits = false; IList orders = new ArrayList(); IList<IOrder> openOrders = instruction.Account.OpenOrdersForAccount; if (openOrders.Any(x => x.IsAmountBased)) throw new ApplicationException(string.Format("The account {0} does have pending amount based orders and thus can not be liquidated.", instruction.Account.DisplayNumberWithName)); sizeBasedOrdersExits = openOrders.Any(x => x.IsSizeBased); if (instruction.Account.Get(e => e.Portfolio).Get(e => e.PortfolioInstrument) != null) { foreach (IFundPosition pos in instruction.Account.Portfolio.PortfolioInstrument.ExcludeNonTradeableInstruments().Where(x => x.Size.IsNotZero)) { InstrumentSize openOrderSize = null; if (sizeBasedOrdersExits) openOrderSize = openOrders .Where(x => x.RequestedInstrument.Key == pos.Instrument.Key) .Select(x => x.OpenValue).Sum(); InstrumentSize orderSize = pos.Size.Negate() - openOrderSize; if (orderSize.IsNotZero) { IOrder order = new OrderSizeBased(instruction.Account, orderSize, true, getFeeFactory(FeeFactoryInstanceTypes.Commission), instruction.DoNotChargeCommission, OrderActionTypes.Departure); order.Instruction = instruction; order.OrderInfo = string.Format("Portfolio liquidated on {0}", DateTime.Now.ToString()); orders.Add(order); } } if (orders.Count > 0) { instruction.UpdateableOrders = orders; instruction.Message = string.Format("{0} orders generated to liquidate portfolio on {1}", orders.Count, DateTime.Now.ToString()); retVal = true; } } return retVal; }
private string getDescriptionLine(IClientDepartureInstruction instruction, int line, ICounterAccount counterAccount) { string transferDescription = getDescriptionLine(instruction.TransferDescription, line); switch (line) { case 1: return string.Format("{0} eind afrekening", instruction.Account.Number); case 2: if (!string.IsNullOrEmpty(transferDescription)) return transferDescription; else return "Liquidatie portfolio"; case 3: if (!string.IsNullOrEmpty(transferDescription)) return transferDescription; else return string.Format("Voor {0}", instruction.Account.ShortName); case 4: if (!string.IsNullOrEmpty(transferDescription)) return transferDescription; else { if (counterAccount.IsPublic) return "Transfer naar derden"; else return "Transfer naar eigen rekening"; } } return ""; }
private string getDescriptionLine(IClientDepartureInstruction instruction, int line) { return getDescriptionLine(instruction, line, null); }
public MoneyTransferOrder(IClientDepartureInstruction instruction, Money amount) { if (instruction == null) throw new ApplicationException(err_def + "the instruction is mandatory"); ICounterAccount counterAccount = null; if (instruction.CounterAccount != null) counterAccount = instruction.CounterAccount; if (counterAccount == null) throw new ApplicationException(err_def + "the counter account is mandatory"); fillFromInstruction(instruction, counterAccount, amount); this.TransferDescription1 = getDescriptionLine(instruction, 1); this.TransferDescription2 = getDescriptionLine(instruction, 2); this.TransferDescription3 = getDescriptionLine(instruction, 3); this.TransferDescription4 = getDescriptionLine(instruction, 4, counterAccount); instruction.MoneyTransferOrder = this; }