Exemple #1
0
        internal InstalmentPolicyDetail(IDBRow dataRow)
        {
            this.InstalmentPolicyId = dataRow.GetColumn <Guid>("InstalmentPolicyId");
            this.IsActive           = (bool)dataRow["IsActive"];
            this.InstalmentFeeType  = (InstalmentFeeType)dataRow.GetColumn <int>("AdministrationFeeBase");
            this.InstalmentFeeRate  = dataRow.GetColumn <decimal>("AdministrationFee");
            this.PrepaymentFeeType  = (PrepaymentFeeType)dataRow.GetColumn <int>("ContractTerminateType");
            this.PrepaymentFeeRate  = dataRow.GetColumn <decimal>("ContractTerminateFee");
            this.DownPaymentBasis   = (DownPaymentBasis)dataRow.GetColumn <int>("DownPaymentBasis");

            this.LatePaymentAutoCutDay = dataRow.GetColumn <int>("LatePaymentAutoCutDay");
            this.AutoCutPenaltyValue   = dataRow.GetColumn <decimal>("AutoCutPenaltyValue");
            this.AutoCutPenaltyBase    = (AutoCutPenaltyBase)dataRow.GetColumn <int>("AutoCutPenaltyBase");
            this.InterestRate          = dataRow.GetColumn <decimal>("InterestRate");

            this.ClosePenaltyValue  = dataRow.GetColumn <decimal>("ClosePenaltyValue");
            this.ClosePenaltyBase   = (ClosePenaltyBase)dataRow.GetColumn <int>("ClosePenaltyBase");
            this.DebitInterestRatio = dataRow.GetColumn <decimal>("DebitInterestRatio");
            this.DebitFreeDays      = dataRow.GetColumn <int>("DebitFreeDays");
            this.DebitInterestType  = dataRow.GetColumn <int>("DebitInterestType");

            int period = dataRow.GetColumn <int>("Period");
            InstalmentFrequence frequence = (InstalmentFrequence)dataRow.GetColumn <int>("Frequence");

            this.Period = new InstalmentPeriod(period, frequence);
        }
Exemple #2
0
        internal InstalmentPolicyDetail(DB.DBMapping.InstalmentPolicyDetail detail)
        {
            this.InstalmentPolicyId = detail.InstalmentPolicyId;
            this.IsActive           = detail.IsActive;
            this.InstalmentFeeType  = (InstalmentFeeType)detail.AdministrationFeeBase;
            this.InstalmentFeeRate  = detail.AdministrationFee;
            this.PrepaymentFeeType  = (PrepaymentFeeType)detail.ContractTerminateType;
            this.PrepaymentFeeRate  = detail.ContractTerminateFee;
            this.DownPaymentBasis   = (DownPaymentBasis)detail.DownPaymentBasis;

            this.LatePaymentAutoCutDay = detail.LatePaymentAutoCutDay;
            this.AutoCutPenaltyValue   = detail.AutoCutPenaltyValue;
            this.AutoCutPenaltyBase    = (AutoCutPenaltyBase)detail.AutoCutPenaltyBase;
            this.InterestRate          = detail.InterestRate;

            this.ClosePenaltyValue  = detail.ClosePenaltyValue;
            this.ClosePenaltyBase   = (ClosePenaltyBase)detail.ClosePenaltyBase;
            this.DebitInterestRatio = detail.DebitInterestRatio;
            this.DebitFreeDays      = detail.DebitFreeDays;
            this.DebitInterestType  = detail.DebitInterestType;

            int period = detail.Period;
            InstalmentFrequence frequence = (InstalmentFrequence)detail.Frequence;

            this.Period = new InstalmentPeriod(period, frequence);
        }
Exemple #3
0
 internal void Remove(int period, InstalmentFrequence frequence)
 {
     if (_instalmentPolicyDetails.ContainsKey(new InstalmentPeriod(period, frequence)))
     {
         _instalmentPolicyDetails.Remove(new InstalmentPeriod(period, frequence));
     }
 }
        private static InstalmentConstructParams ParseInstalment(IDBRow dataRowOrder)
        {
            InstalmentConstructParams result = new InstalmentConstructParams();

            if (dataRowOrder["InstalmentPolicyId"] == DBNull.Value)
            {
                return(null);
            }
            result.InstalmentPolicyId = (Guid)dataRowOrder["InstalmentPolicyId"];
            int period = (int)dataRowOrder["Period"];

            if (dataRowOrder["InstalmentFrequence"] == DBNull.Value)
            {
                throw new InitializeEntityFromDBException("Order", "InstalmentFrequence");
            }
            InstalmentFrequence instalmentFrequence = (InstalmentFrequence)((int)dataRowOrder["InstalmentFrequence"]);

            result.Period               = period;
            result.Frequence            = instalmentFrequence;
            result.DownPayment          = (decimal)dataRowOrder["DownPayment"];
            result.InstalmentType       = (InstalmentType)((int)dataRowOrder["PhysicalInstalmentType"]);
            result.RecalculateRateType  = (RecalculateRateType)((int)dataRowOrder["RecalculateRateType"]);
            result.IsInstalmentOverdue  = (bool)dataRowOrder["IsInstalmentOverdue"];
            result.InstalmentOverdueDay = (int)dataRowOrder["InstalmentOverdueDay"];
            result.DownPaymentBasis     = (Protocal.DownPaymentBasis)((int)dataRowOrder["DownPaymentBasis"]);
            return(result);
        }
Exemple #5
0
        internal int CalculateInstalmentQuantity(int period, InstalmentFrequence frequence)
        {
            int result = period;

            if (frequence == InstalmentFrequence.TwoWeek)
            {
                result = (int)Math.Ceiling(period * (52.0 / 12.0 / 2.0));
            }
            else if (frequence == InstalmentFrequence.Season)
            {
                result = (int)Math.Ceiling(period * (4.0 / 12.0));
            }
            return(result);
        }
Exemple #6
0
            private decimal CalculateMonthRate(decimal interestRate, InstalmentFrequence frequence)
            {
                // @rate / (CASE @frequence WHEN @FREQUENCE_MONTH THEN 12.0 WHEN @FREQUENCE_QUARTER THEN 4.0 ELSE 26.0 END)
                decimal dividend;

                if (frequence == InstalmentFrequence.Month)
                {
                    dividend = 12m;
                }
                else if (frequence == InstalmentFrequence.Season)
                {
                    dividend = 4m;
                }
                else
                {
                    dividend = 26m;
                }
                return(interestRate / dividend);
            }
Exemple #7
0
        internal DateTime CalculatePaymentDateTimeOnPlan(InstalmentFrequence frequence, int period, DateTime tradeDay)
        {
            DateTime result = tradeDay;

            if (frequence == InstalmentFrequence.Month)
            {
                result = tradeDay.AddMonths(period);
            }
            else if (frequence == InstalmentFrequence.Season)
            {
                result = tradeDay.AddMonths(period * 3);
            }
            else if (frequence == InstalmentFrequence.TwoWeek)
            {
                result = tradeDay.AddDays(period * 2 * 7);
            }
            else if (frequence == InstalmentFrequence.Year)
            {
                result = tradeDay.AddYears(period);
            }
            return(result);
        }
Exemple #8
0
            private DateTime CalculateDateTimeOnPlan(DateTime tradeDay, InstalmentFrequence frequence, int period)
            {
                DateTime result;
                int      i = period + 1;

                if (frequence == InstalmentFrequence.Month)
                {
                    result = tradeDay.AddMonths(i);
                }
                else if (frequence == InstalmentFrequence.Season)
                {
                    result = tradeDay.AddMonths(i * 3);
                }
                else if (frequence == InstalmentFrequence.TwoWeek)
                {
                    result = tradeDay.AddDays(i * 2 * 7);
                }
                else if (frequence == InstalmentFrequence.Year)
                {
                    result = tradeDay.AddYears(i);
                }
                else
                {
                    throw new InstalmentFrequenceException(frequence);
                }
                var dayOfWeek = result.DayOfWeek;

                if (dayOfWeek == DayOfWeek.Sunday)
                {
                    result = result.AddDays(1);
                }
                else if (dayOfWeek == DayOfWeek.Saturday)
                {
                    result = result.AddDays(2);
                }

                return(result);
            }
        ///// <summary>
        ///// 方式:等本息还款
        ///// </summary>
        ///// <param name="totalPeriod">期限</param>
        ///// <param name="balance">总金额</param>
        ///// <param name="interestRate">年利率</param>
        //public static List<InstalmentDetail> CalculateEqualInstalment(PhysicalOrder order, decimal balance, int totalPeriod, InstalmentFrequence frequence, decimal interestRate, DateTime tradeDay, int decimals)
        //{
        //    //InstalmentDetailCalculator.Decimals = decimals;
        //    //decimal principal = 0;
        //    //decimal rate0 = decimal.MinValue, instalmentAmount = decimal.MinValue;
        //    //decimal remainBalance = balance;
        //    //List<InstalmentDetail> result = new List<InstalmentDetail>();
        //    //for (int eachPeriod = 1; eachPeriod <= totalPeriod; eachPeriod++)
        //    //{
        //    //    decimal interest = InstalmentDetailCalculator.Round(remainBalance * rate);//每期要还的利息
        //    //    if (rate != 0)
        //    //    {
        //    //        if (rate0 != rate)
        //    //        {
        //    //            instalmentAmount = GetRepaymentAmount(remainBalance, rate0 = rate, totalPeriod);//计算每期要还的钱
        //    //        }
        //    //        principal = instalmentAmount - interest;//每期要还的本金
        //    //        remainBalance -= principal;//剩余本金
        //    //        if (eachPeriod == totalPeriod && balance != 0)
        //    //        {
        //    //            principal += balance;
        //    //            interest -= balance;
        //    //            remainBalance = 0;
        //    //        }
        //    //    }
        //    //    else
        //    //    {
        //    //        instalmentAmount = principal;
        //    //    }
        //    //    var paymentDateTimeOnPlan = InstalmentCalculator.Default.CalculatePaymentDateTimeOnPlan(frequence, eachPeriod, tradeDay);
        //    //    var instalmentDetail = new InstalmentDetail(order, eachPeriod, principal, interest, 0m, paymentDateTimeOnPlan, null);
        //    //    result.Add(instalmentDetail);
        //    //}
        //    //return result;
        //}


        ///// <summary>
        ///// 方式:等本金还款
        ///// </summary>
        ///// <param name="totalPeriod">期限</param>
        ///// <param name="amount">总金额</param>
        ///// <param name="monthRate">年利率</param>
        //public static List<InstalmentDetail> CalculateEqualPrincipal(PhysicalOrder order, decimal amount, int totalPeriod, InstalmentFrequence frequence, decimal monthRate, DateTime tradeDay, int decimals)
        //{
        //    InstalmentDetailCalculator.Decimals = decimals;
        //    decimal principal = 0;
        //    decimal remainAmount = amount;
        //    principal = InstalmentDetailCalculator.Round(amount / totalPeriod);
        //    List<InstalmentDetail> result = new List<InstalmentDetail>();
        //    decimal interest = 0m;
        //    for (int eachPeriod = 1; eachPeriod <= totalPeriod; eachPeriod++)
        //    {
        //        principal = InstalmentDetailCalculator.Round(amount / totalPeriod);
        //        interest = InstalmentDetailCalculator.Round(remainAmount * monthRate);
        //        var instalmentDetail = InstalmentDetailCalculator.CalculateInstalmentDetail(order, rate, eachPeriod, frequence, tradeDay, totalPeriod, remainAmount, principal);
        //        result.Add(instalmentDetail);
        //        remainAmount = InstalmentDetailCalculator.Round(remainAmount - principal);//剩余本金
        //    }
        //    return result;
        //}



        private static InstalmentDetail CalculateInstalmentDetail(PhysicalOrder order, decimal rate, int instalmentPeriod, InstalmentFrequence frequence, DateTime tradeDay, int lastPeriod, decimal balance, decimal originPrincipal)
        {
            decimal interest  = 0m;
            decimal principal = originPrincipal;

            if (rate != 0)
            {
                interest = InstalmentDetailCalculator.Round(balance * rate);//每期要还的利息=上个月的剩余本金×每期利率
            }
            if (instalmentPeriod != 1)
            {
                if (instalmentPeriod == lastPeriod && balance != 0)
                {
                    principal = InstalmentDetailCalculator.Round(principal + balance);
                    if (rate != 0)
                    {
                        interest = InstalmentDetailCalculator.Round(interest - balance);
                    }
                }
            }
            var      instalmentAmount      = InstalmentDetailCalculator.Round(principal + interest);
            DateTime paymentDateTimeOnPlan = InstalmentCalculator.Default.CalculatePaymentDateTimeOnPlan(frequence, instalmentPeriod, tradeDay);

            return(new InstalmentDetail(order, instalmentPeriod, principal, interest, 0m, paymentDateTimeOnPlan, null));
        }
Exemple #10
0
 internal void Update(XElement xmlNode)
 {
     foreach (XAttribute attribute in xmlNode.Attributes())
     {
         if (attribute.Name == "InstalmentPolicyId")
         {
             this.InstalmentPolicyId = Guid.Parse(attribute.Value);
         }
         else if (attribute.Name == "IsActive")
         {
             this.IsActive = XmlConvert.ToBoolean(attribute.Value);
         }
         else if (attribute.Name == "Period")
         {
             int period = int.Parse(attribute.Value);
             this.Period = new InstalmentPeriod(period, this.Period == null ? InstalmentFrequence.Month : this.Period.Frequence);
         }
         else if (attribute.Name == "Frequence")
         {
             InstalmentFrequence frequence = (InstalmentFrequence)(int.Parse(attribute.Value));
             this.Period = new InstalmentPeriod(this.Period == null ? 0 : this.Period.Period, frequence);
         }
         else if (attribute.Name == "DownPaymentBasis")
         {
             this.DownPaymentBasis = (DownPaymentBasis)(int.Parse(attribute.Value));
         }
         else if (attribute.Name == "AdministrationFeeBase")
         {
             this.InstalmentFeeType = (InstalmentFeeType)(int.Parse(attribute.Value));
         }
         else if (attribute.Name == "AdministrationFee")
         {
             this.InstalmentFeeRate = decimal.Parse(attribute.Value);
         }
         else if (attribute.Name == "ContractTerminateType")
         {
             this.PrepaymentFeeType = (PrepaymentFeeType)(int.Parse(attribute.Value));
         }
         else if (attribute.Name == "ContractTerminateFee")
         {
             this.PrepaymentFeeRate = decimal.Parse(attribute.Value);
         }
         else if (attribute.Name == "AutoCutPenaltyBase")
         {
             this.AutoCutPenaltyBase = (AutoCutPenaltyBase)(int.Parse(attribute.Value));
         }
         else if (attribute.Name == "AutoCutPenaltyValue")
         {
             this.AutoCutPenaltyValue = decimal.Parse(attribute.Value);
         }
         else if (attribute.Name == "LatePaymentAutoCutDay")
         {
             this.LatePaymentAutoCutDay = int.Parse(attribute.Value);
         }
         else if (attribute.Name == "ClosePenaltyBase")
         {
             this.ClosePenaltyBase = (ClosePenaltyBase)(int.Parse(attribute.Value));
         }
         else if (attribute.Name == "ClosePenaltyValue")
         {
             this.ClosePenaltyValue = decimal.Parse(attribute.Value);
         }
     }
 }
Exemple #11
0
 internal InstalmentPeriod(int period, InstalmentFrequence frequence)
 {
     _period    = period;
     _frequence = frequence;
 }
Exemple #12
0
 internal InstalmentFrequenceException(InstalmentFrequence frequence)
 {
     this.Frequence = frequence;
 }