Ejemplo n.º 1
0
        public void SettleInterest(DateTime calcDate)
        {
            if (HasSettled)
                throw new ApplicationException("This interest payment already settled.");

            const string DefErr = "Can not settle the accrued interest. ";

            if (this.Status != BondCouponPaymentStati.ToBeSettled)
                throw new ApplicationException(DefErr + "The status does not equal to-be-settled.");

            if (this.DailyCalculations == null || this.DailyCalculations.Count == 0)
                throw new ApplicationException(DefErr + "No calculations.");

            if (this.CouponHistory.EndAccrualDate > calcDate)
                throw new ApplicationException(DefErr + "The date to sttle the interest is in the future.");

            Money accruedInterest = this.DailyCalculations.LastCalculation.CalculatedAccruedInterestUpToDate;
            IGLAccount glAccount = Components[0].MainLine.GLAccount;
            JournalEntryLine newLine1 = new JournalEntryLine();
            newLine1.BookDate = CouponHistory.EndAccrualDate;
            newLine1.clientSettle(GeneralOpsJournalEntry, newLine1, glAccount, accruedInterest, this.Components[0].Component, this.Account);
            newLine1.Description = "Settle Interest " + newLine1.BookDate.ToString("dd-MM-yyyy");

            JournalEntryLine newLine2 = new JournalEntryLine();
            newLine2.BookDate = CouponHistory.EndAccrualDate;
            newLine2.clientSettle(GeneralOpsJournalEntry, newLine2, glAccount.GLSettledAccount, accruedInterest.Negate(), this.Components[0].Component, this.Account);
            newLine2.Description = "Settle Interest " + newLine2.BookDate.ToString("dd-MM-yyyy");
            Components[0].MainLine = newLine2;

            foreach (IJournalEntryLine line in Components[0].JournalLines)
            {
                if (!line.GLAccount.IsSettledWithClient)
                    line.IsSettledStatus = true;
            }
            this.Status = BondCouponPaymentStati.Settled;
            this.IsNotarizable = true;
        }
Ejemplo n.º 2
0
        public bool Cancel(bool ignoreSizeNotZero)
        {
            const string defErr = "It is not possible to Cancel an inactive BondCouponPayment, use storno instead. ";
            if (!(this.Status == BondCouponPaymentStati.Active))
                throw new ApplicationException(defErr + "The payment is not active");

            if (HasSettled)
                throw new ApplicationException(defErr + "This interest payment already settled");

            if (!ignoreSizeNotZero)
            {
                InstrumentSize size = Position.PositionTransactions.Where(x => x.TransactionDate <= CouponHistory.EndAccrualDate).Select(x => x.Size).Sum();
                if (size.IsNotZero)
                    throw new ApplicationException(defErr + "The position size is not equal to zero");
            }

            Money cancelAmount = this.DailyCalculations.TotalAccruedInterest;
            if (cancelAmount.IsNotZero)
            {
                // Find day where Pos Size got zero
                DateTime posClosingDate = CouponHistory.EndAccrualDate;
                while (Position.PositionTransactions.Any(x => x.TransactionDate <= posClosingDate) && Position.PositionTransactions.Where(x => x.TransactionDate <= posClosingDate).Select(x => x.Size).Sum().IsZero)
                {
                    posClosingDate = posClosingDate.AddDays(-1);
                    if (posClosingDate < CouponHistory.StartAccrualDate)
                        throw new ApplicationException(defErr + "The position closing date could not be determined");
                }

                foreach (IJournalEntryLine line in this.GeneralOpsJournalEntry.Lines)
                {
                    JournalEntryLine newLine = new JournalEntryLine();
                    newLine.clientSettle(
                        GeneralOpsJournalEntry,
                        newLine,
                        line.GLAccount,
                        line.Balance.Negate(),
                        this.Components[0].Component,
                        line.GiroAccount);
                    newLine.ValueDate = line.ValueDate;
                    newLine.Description = string.Format("Cancellation {0}", line.ValueDate.ToString("dd-MM-yyyy"));
                }

                this.GeneralOpsJournalEntry.BookLines();
                this.Position.LastBondCouponCalcDate = posClosingDate;
            }
            this.Status = BondCouponPaymentStati.Cancelled;

            return !(this.Status == BondCouponPaymentStati.Active);
        }