public static object CreateMemorialBooking(int journalId) { IDalSession session = NHSessionFactory.CreateSession(); try { IJournal journal = JournalMapper.GetJournal(session, journalId); string nextJournalEntryNumber = JournalEntryMapper.GetNextJournalEntryNumber(session, journal); IMemorialBooking newMemorialBooking = new MemorialBooking(journal, nextJournalEntryNumber); JournalEntryMapper.Insert(session, newMemorialBooking); return newMemorialBooking.Key; } finally { session.Close(); } throw new Exception("The method or operation is not implemented."); }
private static void createJournalEntryForNav(IDalSession session, INavCalculation calc, DateTime bookingDate) { IVirtualFund fund = calc.Fund; string nextJournalNumber = JournalEntryMapper.GetNextJournalEntryNumber(session, fund.JournalForFund); IMemorialBooking newEntry = new MemorialBooking(fund.JournalForFund, nextJournalNumber); newEntry.TransactionDate = calc.ValuationDate; calc.Bookings = newEntry; }
public bool Settle(IJournal journal, string nextJournalEntryNumber, IGLAccount settleDiffGLAccount) { bool success = false; if ((TradeStatements != null && TradeStatements.Count > 0) && (BankSettlements != null && BankSettlements.Count > 0)) { // TODO -> What if not in base currency???? Money diff = SettleDifference; foreach (ITradingJournalEntry journalEntry in TradeStatements) { ((IOrderExecution)journalEntry.Trade).SettleExternal(SettlementDate); } if (diff != null && diff.IsNotZero) { MemorialBooking = new MemorialBooking(journal, nextJournalEntryNumber); MemorialBooking.TransactionDate = SettlementDate; MemorialBooking.Description = "Settlement Difference"; IGLAccount glAcctA = BankSettlements[0].GLAccount; IGLAccount glAcctB = settleDiffGLAccount; IJournalEntryLine sideA = new JournalEntryLine(); sideA.GLAccount = glAcctA; sideA.Balance = diff.Negate(); sideA.Description = MemorialBooking.Description; sideA.IsSettledStatus = true; sideA.ValueDate = SettlementDate; MemorialBooking.Lines.AddJournalEntryLine(sideA); IJournalEntryLine sideB = new JournalEntryLine(); sideB.GLAccount = glAcctB; sideB.Balance = diff; sideB.Description = MemorialBooking.Description; sideB.IsSettledStatus = true; sideB.ValueDate = SettlementDate; MemorialBooking.Lines.AddJournalEntryLine(sideB); MemorialBooking.BookLines(); } success = true; } return success; }
private static bool createMgtFeeTransactionForMP(IJournal journalMgmtFee, IGLLookupRecords lookups, int mgtPeriodId, int year, int quarter, ManagementTypes managementType, FeeFactory feeFactory, DateTime minDate, DateTime maxDate, decimal taxPercentage, bool createCashInitiatedOrders) { bool retVal = false; IDalSession session = NHSessionFactory.CreateSession(); Hashtable parameterLists = new Hashtable(1); Hashtable parameters = new Hashtable(2); Util.GetDatesFromQuarter(year, quarter, out minDate, out maxDate); parameterLists.Add("periods", Util.GetPeriodsFromQuarter(year, quarter)); parameters.Add("mgtPeriodId", mgtPeriodId); parameters.Add("managementType", managementType); IList<IManagementPeriodUnit> unitsUnsorted = session.GetTypedListByNamedQuery<IManagementPeriodUnit>( "B4F.TotalGiro.ApplicationLayer.Fee.ManagementPeriodUnitsForMgtFeeTransactionCreation", parameters, parameterLists); if (unitsUnsorted != null && unitsUnsorted.Count > 0) { var unitsByMP = from a in unitsUnsorted group a by a.ManagementPeriod into g select new { ManagementPeriod = g.Key, Units = g.ToList() }; if (unitsByMP.Count() != 1) throw new ApplicationException("The number of management periods is not what is expected."); IManagementPeriod managementPeriod = unitsByMP.First().ManagementPeriod; IList<IManagementPeriodUnit> units = unitsByMP.First().Units; DateTime feeStartDate = minDate; DateTime feeEndDate = maxDate; if (managementPeriod.StartDate > minDate) feeStartDate = managementPeriod.StartDate; if (Util.IsNotNullDate(managementPeriod.EndDate) && managementPeriod.EndDate < maxDate) feeEndDate = managementPeriod.EndDate.Value; if (feeStartDate.Year != feeEndDate.Year) throw new ApplicationException("The year of the start date and end date for the management fee should equal"); string mgtFeeDescription; decimal mgtFeeThreshold; getMgtFeeInfo(managementPeriod, feeEndDate, year, quarter, out mgtFeeDescription, out mgtFeeThreshold); if (units != null && units.Count > 0) { // check the number of units int expectedUnitCount = Util.DateDiff(DateInterval.Month, feeStartDate, feeEndDate) + 1; if (expectedUnitCount != units.Count) throw new ApplicationException(string.Format("The number of units {0} does not equal the number of expected units {1}.", units.Count, expectedUnitCount)); // check if all have the same management period var mps = from a in units group a by a.ManagementPeriod into g select g.Key; if (mps.Count() != 1) throw new ApplicationException("Not all units belong to the same management period."); if (mps.First().Key != managementPeriod.Key) throw new ApplicationException("The management period is not ok."); if (Util.GetPeriodFromDate(managementPeriod.StartDate) == Util.GetPeriodFromDate(feeStartDate) && managementPeriod.StartDate.Day != feeStartDate.Day) throw new ApplicationException(string.Format("The start date of the management period ({0}) does not equal the presented start date ({1}).", managementPeriod.StartDate.ToString("yyyy-MM-dd"), feeStartDate.ToString("yyyy-MM-dd"))); if (managementPeriod.EndDate.HasValue) { if (feeEndDate > managementPeriod.EndDate) throw new ApplicationException(string.Format("The end date of the management period ({0}) does not equal the presented end date ({1}).", managementPeriod.EndDate.Value.ToString("yyyy-MM-dd"), feeEndDate.ToString("yyyy-MM-dd"))); else if (Util.GetPeriodFromDate(managementPeriod.EndDate.Value) == Util.GetPeriodFromDate(feeEndDate) && managementPeriod.EndDate.Value.Day != feeEndDate.Day) throw new ApplicationException(string.Format("The end date of the management period ({0}) does not equal the presented end date ({1}).", managementPeriod.EndDate.Value.ToString("yyyy-MM-dd"), feeEndDate.ToString("yyyy-MM-dd"))); } IAccountTypeCustomer account = (IAccountTypeCustomer)managementPeriod.Account; if (!account.ExitFeePayingAccount.Equals(account)) mgtFeeDescription += string.Format(" voor {0}", account.Number); string nextJournalEntryNumber = JournalEntryMapper.GetNextJournalEntryNumber(session, journalMgmtFee); IMemorialBooking memorialBooking = new MemorialBooking(journalMgmtFee, nextJournalEntryNumber); memorialBooking.TransactionDate = feeEndDate.AddDays(1); memorialBooking.Description = mgtFeeDescription; IManagementFee mgtFee = new ManagementFee(account, feeStartDate, feeEndDate, units, memorialBooking, taxPercentage, lookups); if (mgtFee != null && mgtFee.NettAmount != null && mgtFee.NettAmount.IsNotZero) { if (mgtFee.NettAmount.Quantity < mgtFeeThreshold) { ITradeableInstrument instrument; account = account.ExitFeePayingAccount; if (createCashInitiatedOrders && mgtFee.NeedToCreateCashInitiatedOrder(out instrument)) { if (instrument != null) { OrderAmountBased order = new OrderAmountBased(account, mgtFee.Components.TotalAmount, instrument, true, feeFactory, true); order.OrderInfo = mgtFeeDescription; mgtFee.CashInitiatedOrder = order; } else { // Sell from the biggest position IFundPosition pos = account.Portfolio.PortfolioInstrument.Where(x => x.Size.IsGreaterThanZero).OrderByDescending(x => x.CurrentValue).FirstOrDefault(); if (pos != null && (pos.CurrentBaseValue + mgtFee.NettAmount).IsGreaterThanOrEqualToZero) { OrderAmountBased order = new OrderAmountBased(account, mgtFee.Components.TotalAmount, pos.Instrument, true, feeFactory, true); order.OrderInfo = mgtFeeDescription; mgtFee.CashInitiatedOrder = order; } } } if (mgtFee.CashInitiatedOrder == null && (account.Portfolio.TotalValue() + mgtFee.TotalAmount).IsLessThanZero) throw new ApplicationException(string.Format("Could not create a management fee booking for account {0} since the total portfolio value ({1}) is insufficient.", account.DisplayNumberWithName, account.Portfolio.TotalValue().DisplayString)); mgtFee.BookLines(); GeneralOperationsBookingMapper.Update(session, mgtFee); retVal = true; } } } } session.Close(); return retVal; }
private static IMemorialBooking getNewCashDividendBooking(IDalSession session, IJournal journal, DateTime transactionDate) { string nextJournalEntryNumber = JournalEntryMapper.GetNextJournalEntryNumber(session, journal); IMemorialBooking newMemorialBooking = new MemorialBooking(journal, nextJournalEntryNumber); newMemorialBooking.TransactionDate = transactionDate; JournalEntryMapper.Insert(session, newMemorialBooking); return newMemorialBooking; }
private static bool processBondPosition( IFundPosition pos, IExchange exchange, DateTime upToDate, IList<IBondCouponPaymentDailyCalculation> oldCalculations, IGLLookupRecords lookups, IDalSession session) { bool success = false; IBond bond = pos.Instrument as IBond; if (bond == null || bond.SecCategory.Key != SecCategories.Bond) throw new ApplicationException(string.Format("The instrument {0} is not a bond.", pos.Instrument.DisplayIsinWithName)); if (bond.DoesPayInterest) { DateTime calcDate; if (Util.IsNotNullDate(pos.LastBondCouponCalcDate)) calcDate = pos.LastBondCouponCalcDate.AddDays(1); else calcDate = pos.OpenDate; while (calcDate <= upToDate) { if (exchange == null) exchange = bond.DefaultExchange ?? bond.HomeExchange; InstrumentSize size = pos.PositionTransactions.Where(x => x.TransactionDate <= calcDate).Select(x => x.Size).Sum(); if (size != null && size.IsNotZero) { if (!Util.IsWeekendOrHoliday(calcDate, exchange.ExchangeHolidays)) { DateTime settlementDate = bond.GetSettlementDate(calcDate, exchange); IBondCouponPayment bip = null; DateTime lastCouponDate = bond.LastCouponDate(settlementDate); if (Util.IsNullDate(lastCouponDate)) lastCouponDate = bond.IssueDate; DateTime nextCouponDate = bond.NextCouponDate(settlementDate); if ((bond.IsPerpetual || bond.MaturityDate >= settlementDate) && Util.IsNotNullDate(lastCouponDate) && lastCouponDate <= settlementDate && Util.IsNotNullDate(nextCouponDate) && nextCouponDate >= settlementDate) { // Per position -> Does have an Active BondCouponPayment bip = pos.BondCouponPayments.GetBondCouponPaymentByDate(settlementDate); if (bip == null) { ICouponHistory couponHistory = bond.Coupons.GetCouponByDate(settlementDate); if (couponHistory == null) { couponHistory = new CouponHistory(bond, lastCouponDate, nextCouponDate); bond.Coupons.AddCoupon(couponHistory); } int journalID = int.Parse((string)(System.Configuration.ConfigurationManager.AppSettings.Get("DefaultAccruedInterestJournal"))); IJournal journal = JournalMapper.GetJournal(session, journalID); string nextJournalEntryNumber = JournalEntryMapper.GetNextJournalEntryNumber(session, journal); IMemorialBooking memorialBooking = new MemorialBooking(journal, nextJournalEntryNumber); memorialBooking.TransactionDate = couponHistory.EndAccrualDate; bip = new BondCouponPayment(pos, couponHistory, memorialBooking); pos.BondCouponPayments.AddPayment(bip); } if (bip != null) { // Add interest accrual bip.CalculateDailyInterest(size, calcDate, settlementDate, oldCalculations != null && oldCalculations.Count > 0 ? oldCalculations.Where(x => x.CalcDate == calcDate).ToList() : null, lookups); } } // If coupon payment date equals settlementDate -> set to status -> to-be-settled if (bip != null && nextCouponDate <= settlementDate) bip.SetToBeSettled(calcDate, settlementDate); // If coupon payment date -> pay (unsettled to settled) // Settle the interest List<IBondCouponPayment> bipsToBeSettled = pos.BondCouponPayments.ToBeSettledPayments(calcDate); if (bipsToBeSettled != null && bipsToBeSettled.Count > 0) { foreach (IBondCouponPayment bipToBeSettled in bipsToBeSettled) bipToBeSettled.SettleInterest(calcDate); } success = true; } pos.LastBondCouponCalcDate = calcDate; } calcDate = calcDate.AddDays(1); } } return success; }
public static bool StornoBondTransaction(IDalSession session, ITransaction storno, IInternalEmployeeLogin employee) { bool success = false; if (storno.Approved) { IList<IBondCouponPayment> bondPaymentsToStorno = storno.GetBondPaymentsToStorno(); if (bondPaymentsToStorno != null && bondPaymentsToStorno.Count > 0) { IGLLookupRecords lookups = null; int journalID = int.Parse((string)(System.Configuration.ConfigurationManager.AppSettings.Get("DefaultAccruedInterestJournal"))); IJournal journal = JournalMapper.GetJournal(session, journalID); foreach (IBondCouponPayment payment in bondPaymentsToStorno.OrderByDescending(x => x.CouponHistory.StartAccrualDate)) { if (payment.Status == BondCouponPaymentStati.Active || payment.Status == BondCouponPaymentStati.ToBeSettled) { if (lookups == null) lookups = GlLookupRecordMapper.GetGLLookupRecords(session, BookingComponentParentTypes.AccruedInterest); payment.Cancel(); success = true; } else if (payment.Status == BondCouponPaymentStati.Settled) { string nextJournalEntryNumber = JournalEntryMapper.GetNextJournalEntryNumber(session, journal); IMemorialBooking memorialBooking = new MemorialBooking(journal, nextJournalEntryNumber); memorialBooking.TransactionDate = payment.CouponHistory.EndAccrualDate; payment.Storno(employee, storno.StornoReason, memorialBooking); success = true; } } } } return success; }