Beispiel #1
0
        private static IInstallment BuildNext(IInstallment previous, IScheduleConfiguration configuration)
        {
            if (previous == null)
            {
                throw new ArgumentException("Previous installment cannot be null.");
            }

            if (previous.Number == configuration.NumberOfInstallments)
            {
                return(null);
            }
            var installment = new Installment
            {
                Number    = previous.Number + 1,
                StartDate = previous.EndDate,
                EndDate   = configuration.PeriodPolicy.GetNextDate(previous.EndDate),
                Olb       = previous.Olb - previous.Principal,
            };

            if (configuration.GracePeriod < installment.Number)
            {
                configuration.CalculationPolicy.Calculate(installment, configuration);
            }
            return(installment);
        }
        public void Calculate(IInstallment installment, IScheduleConfiguration configuration)
        {
            var annuity = configuration.RoundingPolicy.Round(FindAnnuity(configuration));

            installment.Interest = CalculateInterest(installment, configuration, installment.Olb);
            installment.Principal = annuity - installment.Interest;
        }
Beispiel #3
0
        public void Calculate(IInstallment installment, IScheduleConfiguration configuration)
        {
            var annuity = configuration.RoundingPolicy.Round(FindAnnuity(configuration));

            installment.Interest  = CalculateInterest(installment, configuration, installment.Olb);
            installment.Principal = annuity - installment.Interest;
        }
 protected decimal CalculateInterest(IInstallment installment, IScheduleConfiguration configuration, decimal amount)
 {
     var daysInPeriod = configuration.PeriodPolicy.GetNumberOfDays(installment.EndDate);
     var daysInYear = configuration.YearPolicy.GetNumberOfDays(installment.EndDate);
     var interest = amount * configuration.InterestRate / 100 * daysInPeriod / daysInYear;
     return configuration.RoundingPolicy.Round(interest);
 }
        public void Calculate(IInstallment installment, IScheduleConfiguration configuration)
        {
            var number = configuration.NumberOfInstallments - configuration.GracePeriod;

            installment.Principal = configuration.RoundingPolicy.Round(configuration.Amount / number);
            installment.Interest  = CalculateInterest(installment, configuration, installment.Olb);
        }
Beispiel #6
0
 public int GetNumberOfDays(IInstallment installment, IDateShiftPolicy shiftPolicy)
 {
     if (installment.Number == 1)
     {
         return(installment.EndDate == installment.StartDate.AddMonths(1) ? 30 : (installment.EndDate - installment.StartDate).Days);
     }
     return(30);
 }
Beispiel #7
0
 public void UpdateInstallment(IInstallment installment, int contractId, int?eventId)
 {
     using (var connection = GetConnection())
         using (var transaction = connection.BeginTransaction())
         {
             UpdateInstallment(installment, contractId, eventId, transaction);
             transaction.Commit();
         }
 }
Beispiel #8
0
 public void UpdateInstallment(IInstallment pInstallment, int pContractId, int?pEventId, bool pRescheduling)
 {
     using (var connection = GetConnection())
         using (var transaction = connection.BeginTransaction())
         {
             UpdateInstallment(pInstallment, pContractId, pEventId, transaction, pRescheduling);
             transaction.Commit();
         }
 }
Beispiel #9
0
        /// <summary>
        /// this method allows us to update an installment
        /// </summary>
        /// <param name="pInstallment">the installment modified</param>
        /// <param name="pContractId"></param>
        /// <param name="pEventId">Event linked to this installment update</param>
        /// <param name="pSqlTransac"></param>
        /// <param name="pRescheduling">Is it a rescheduled installment</param>
        public void UpdateInstallment(IInstallment pInstallment, int pContractId, int?pEventId, SqlTransaction pSqlTransac, bool pRescheduling)
        {
            // Update installement in database
            const string q = @"UPDATE Installments 
                                    SET expected_date = @expectedDate, 
                                        interest_repayment = @interestRepayment, 
				                        capital_repayment = @capitalRepayment, 
                                        contract_id = @contractId, 
                                        number = @number, 
                                        paid_interest = @paidInterest, 
				                        paid_capital = @paidCapital,
                                        fees_unpaid = @feesUnpaid, 
                                        paid_date = @paidDate,
                                        paid_fees = @paidFees,
                                        comment = @comment,
                                        pending = @pending,
                                        start_date = @start_date,
                                        olb = @olb,
                                        commission = @commission,
                                        paid_commission = @paidCommission
                                     WHERE contract_id = @contractId 
                                       AND number = @number";

            using (var c = new OpenCbsCommand(q, pSqlTransac.Connection, pSqlTransac))
            {
                //primary key = contractId + number
                c.AddParam("@contractId", pContractId);
                c.AddParam("@number", pInstallment.Number);
                c.AddParam("@expectedDate", pInstallment.ExpectedDate);
                c.AddParam("@interestRepayment", pInstallment.InterestsRepayment.Value);
                c.AddParam("@capitalRepayment", pInstallment.CapitalRepayment.Value);
                c.AddParam("@paidInterest", pInstallment.PaidInterests.Value);
                c.AddParam("@paidCapital", pInstallment.PaidCapital.Value);
                c.AddParam("@paidDate", pInstallment.PaidDate);
                c.AddParam("@paidFees", pInstallment.PaidFees.Value);
                c.AddParam("@comment", pInstallment.Comment);
                c.AddParam("@pending", pInstallment.IsPending);
                c.AddParam("@start_date", pInstallment.StartDate);
                c.AddParam("@olb", pInstallment.OLB);
                c.AddParam("@commission", pInstallment.Commission);
                c.AddParam("@paidCommission", pInstallment.PaidCommissions);

                if (pInstallment is Installment)
                {
                    Installment installment = (Installment)pInstallment;
                    c.AddParam("@feesUnpaid", installment.FeesUnpaid);
                }
                else
                {
                    c.AddParam("@feesUnpaid", 0);
                }

                c.ExecuteNonQuery();
            }
        }
        public void Calculate(IInstallment installment, IScheduleConfiguration configuration)
        {
            var number = configuration.NumberOfInstallments - configuration.GracePeriod;
            var numberOfPeriods = configuration.PeriodPolicy.GetNumberOfPeriodsInYear(installment.EndDate, configuration.YearPolicy);
            var interestRate = (double)configuration.InterestRate / 100 / numberOfPeriods;

            var numerator = interestRate * (double)configuration.Amount;
            var denominator = 1 - 1 / Math.Pow(1 + interestRate, number);
            var total = configuration.RoundingPolicy.Round((decimal)(numerator / denominator));

            installment.Interest = CalculateInterest(installment, configuration, installment.Olb);
            installment.Principal = total - installment.Interest;
        }
 protected decimal CalculateInterest(IInstallment installment, IScheduleConfiguration configuration, decimal amount)
 {
     var daysInPeriod = configuration.PeriodPolicy.GetNumberOfDays(installment.EndDate);//, configuration.DateShiftPolicy);
     var daysInYear = configuration.YearPolicy.GetNumberOfDays(installment.EndDate);
     var interest = installment.Olb * configuration.InterestRate / 100 * daysInPeriod / daysInYear;
     //if schedule is flat
     if (configuration.CalculationPolicy.GetType() == typeof(FlatInstallmentCalculationPolicy))
     {
         var numberOfPeriods =
             (decimal)
                 (configuration.PeriodPolicy.GetNumberOfPeriodsInYear(
                     configuration.PreferredFirstInstallmentDate, configuration.YearPolicy));
         interest = configuration.Amount*configuration.InterestRate/numberOfPeriods/100;
     }
     return configuration.RoundingPolicy.Round(interest);
 }
        protected decimal CalculateInterest(IInstallment installment, IScheduleConfiguration configuration, decimal amount)
        {
            var daysInPeriod = configuration.PeriodPolicy.GetNumberOfDays(installment, configuration.DateShiftPolicy);
            var daysInYear   = configuration.YearPolicy.GetNumberOfDays(installment.EndDate);
            var interest     = installment.Olb * configuration.InterestRate / 100 * daysInPeriod / daysInYear;

            //if schedule is flat
            if (configuration.CalculationPolicy.GetType() == typeof(FlatInstallmentCalculationPolicy))
            {
                var numberOfPeriods =
                    (decimal)
                    (configuration.PeriodPolicy.GetNumberOfPeriodsInYear(
                         configuration.PreferredFirstInstallmentDate, configuration.YearPolicy));
                interest = configuration.Amount * configuration.InterestRate / numberOfPeriods / 100;
            }
            return(configuration.RoundingPolicy.Round(interest));
        }
        private static IInstallment BuildNext(IInstallment previous, IScheduleConfiguration configuration)
        {
            if (previous == null) throw new ArgumentException("Previous installment cannot be null.");

            if (previous.Number == configuration.NumberOfInstallments) return null;
            var installment = new Installment
            {
                Number = previous.Number + 1,
                StartDate = previous.EndDate,
                EndDate = configuration.PeriodPolicy.GetNextDate(previous.EndDate),
                Olb = previous.Olb - previous.Principal,
            };
            if (configuration.GracePeriod < installment.Number)
            {
                configuration.CalculationPolicy.Calculate(installment, configuration);
            }
            return installment;
        }
 public void Calculate(IInstallment installment, IScheduleConfiguration configuration)
 {
     var number = configuration.NumberOfInstallments - configuration.GracePeriod;
     installment.Principal = configuration.RoundingPolicy.Round(configuration.Amount / number);
     installment.Interest = CalculateInterest(installment, configuration, installment.Olb);
 }
 public int GetNumberOfDays(IInstallment installment, IDateShiftPolicy shiftPolicy)
 {
     return (shiftPolicy.ShiftDate(installment.EndDate) - shiftPolicy.ShiftDate(installment.StartDate)).Days;
 }
Beispiel #16
0
        /// <summary>
        /// this method allows us to update an installment
        /// </summary>
        /// <param name="pInstallment">the installment modified</param>
        /// <param name="pContractId"></param>
        /// <param name="pEventId">Event linked to this installment update</param>
        /// <param name="pSqlTransac"></param>
        /// <param name="pRescheduling">Is it a rescheduled installment</param>
        public void UpdateInstallment(IInstallment pInstallment,int pContractId, int? pEventId,SqlTransaction pSqlTransac, bool pRescheduling)
        {
            // Update installement in database
            const string q = @"UPDATE Installments
                                    SET expected_date = @expectedDate,
                                        interest_repayment = @interestRepayment,
                                        capital_repayment = @capitalRepayment,
                                        contract_id = @contractId,
                                        number = @number,
                                        paid_interest = @paidInterest,
                                        paid_capital = @paidCapital,
                                        fees_unpaid = @feesUnpaid,
                                        paid_date = @paidDate,
                                        paid_fees = @paidFees,
                                        comment = @comment,
                                        pending = @pending,
                                        start_date = @start_date,
                                        olb = @olb
                                     WHERE contract_id = @contractId
                                       AND number = @number";

            using (OpenCbsCommand c = new OpenCbsCommand(q, pSqlTransac.Connection, pSqlTransac))
            {
                //primary key = contractId + number
                c.AddParam("@contractId", pContractId);
                c.AddParam("@number", pInstallment.Number);
                c.AddParam("@expectedDate", pInstallment.ExpectedDate);
                c.AddParam("@interestRepayment", pInstallment.InterestsRepayment.Value);
                c.AddParam("@capitalRepayment", pInstallment.CapitalRepayment.Value);
                c.AddParam("@paidInterest", pInstallment.PaidInterests.Value);
                c.AddParam("@paidCapital", pInstallment.PaidCapital.Value);
                c.AddParam("@paidDate", pInstallment.PaidDate);
                c.AddParam("@paidFees", pInstallment.PaidFees.Value);
                c.AddParam("@comment", pInstallment.Comment);
                c.AddParam("@pending", pInstallment.IsPending);
                c.AddParam("@start_date", pInstallment.StartDate);
                c.AddParam("@olb", pInstallment.OLB);

                if (pInstallment is Installment)
                {
                    Installment installment = (Installment) pInstallment;
                    c.AddParam("@feesUnpaid", installment.FeesUnpaid);
                }
                else
                {
                    c.AddParam("@feesUnpaid", 0);
                }

                c.ExecuteNonQuery();
            }
        }
Beispiel #17
0
 public void UpdateInstallment(IInstallment pInstallment,int pContractId, int? pEventId, bool pRescheduling)
 {
     using (SqlConnection connection = GetConnection())
     using (SqlTransaction transaction = connection.BeginTransaction())
     {
         UpdateInstallment(pInstallment, pContractId, pEventId, transaction, pRescheduling);
         transaction.Commit();
     }
 }
Beispiel #18
0
 private static decimal CalculateInterest(IInstallment installment, IScheduleConfiguration configuration)
 {
     var daysInPeriod = configuration.PeriodPolicy.GetNumberOfDays(installment, configuration.DateShiftPolicy);
     var daysInYear = configuration.YearPolicy.GetNumberOfDays(installment.EndDate);
     var interest = installment.Olb*configuration.InterestRate / 100 * daysInPeriod / daysInYear;
     //if schedule is flat
     if (configuration.CalculationPolicy.GetType() == typeof(FlatInstallmentCalculationPolicy))
     {
         var numberOfPeriods =
             (decimal)
                 (configuration.PeriodPolicy.GetNumberOfPeriodsInYear(
                     configuration.PreferredFirstInstallmentDate, configuration.YearPolicy));
         var gracePeriod = configuration.ChargeInterestDuringGracePeriod ? 0 : configuration.GracePeriod;
         interest = configuration.Amount*configuration.InterestRate/numberOfPeriods/100/
                    (configuration.NumberOfInstallments - gracePeriod);
     }
     return configuration.RoundingPolicy.Round(interest);
 }
Beispiel #19
0
 public int GetNumberOfDays(IInstallment installment, IDateShiftPolicy shiftPolicy)
 {
     return((shiftPolicy.ShiftDate(installment.EndDate) - shiftPolicy.ShiftDate(installment.StartDate)).Days);
 }
Beispiel #20
0
 /// <summary>
 /// this method allows us to update an installment
 /// </summary>
 /// <param name="installment">the installment modified</param>
 /// <param name="contractId"></param>
 /// <param name="sqlTransac"></param>
 /// <param name="eventId">Event linked to this installment update</param>
 public void UpdateInstallment(IInstallment installment, int contractId, int?eventId, SqlTransaction sqlTransac)
 {
     UpdateInstallment(installment, contractId, eventId, sqlTransac, false);
 }
Beispiel #21
0
 public void UpdateInstallment(IInstallment installment, int contractId, int? eventId)
 {
     using (SqlConnection connection = GetConnection())
     using (SqlTransaction transaction = connection.BeginTransaction())
     {
         UpdateInstallment(installment, contractId, eventId, transaction);
         transaction.Commit();
     }
 }
Beispiel #22
0
 /// <summary>
 /// this method allows us to update an installment
 /// </summary>
 /// <param name="installment">the installment modified</param>
 /// <param name="contractId"></param>
 /// <param name="sqlTransac"></param>
 /// <param name="eventId">Event linked to this installment update</param>
 public void UpdateInstallment(IInstallment installment, int contractId, int? eventId, SqlTransaction sqlTransac)
 {
     UpdateInstallment(installment, contractId, eventId, sqlTransac, false);
 }
 public int GetNumberOfDays(IInstallment installment, IDateShiftPolicy shiftPolicy)
 {
     if (installment.Number == 1)
         return installment.EndDate == installment.StartDate.AddMonths(1) ? 30 : (installment.EndDate - installment.StartDate).Days;
     return 30;
 }