public override IGeneralOperationsBooking Storno(IInternalEmployeeLogin employee, string reason, IMemorialBooking journalEntry) { if (Status != BondCouponPaymentStati.Settled) throw new ApplicationException("It is not possible to storno a bond interest payements that has not a status of paid."); if (Position.BondCouponPayments.Where(x => x.CouponHistory.StartAccrualDate > this.CouponHistory.EndAccrualDate && ((x.Status == BondCouponPaymentStati.Settled && !(x.StornoBooking != null || x.IsStorno)) || x.Status == BondCouponPaymentStati.Active)).Count() > 0) throw new ApplicationException(string.Format("Bond interest payements exists after {0} that should be stornoed first.", CouponHistory.EndAccrualDate.ToShortDateString())); BondCouponPayment newStorno = new BondCouponPayment(); newStorno.Position = this.Position; newStorno.CouponHistory = this.CouponHistory; newStorno.Status = this.Status; newStorno.IsNotarizable = this.IsNotarizable; DateTime newLastDate = CouponHistory.StartAccrualDate.AddDays(-1); if (newLastDate < Position.OpenDate) newLastDate = Position.OpenDate; Position.LastBondCouponCalcDate = newLastDate; return this.storno(employee, reason, journalEntry, newStorno); }
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; }