예제 #1
0
        public static PaymentInfo[] GeneratePaymentSchema(PaymentSchemaType paymentSchemaType, DateTime startDate, DateTime endDate, decimal amount, decimal discount = 0m)
        {
            if (amount == 0m)
            {
                return(new PaymentInfo[0]);
            }

            discount = InitDiscount(paymentSchemaType, discount);

            amount *= 1m - discount / 100m;

            switch (paymentSchemaType)
            {
            case PaymentSchemaType.OnceThrough:
            case PaymentSchemaType.OnceThroughWithDiscount:
                var schema = new PaymentInfo[1];
                schema[0] = new PaymentInfo {
                    Date = startDate, Amount = amount
                };
                return(schema);

            case PaymentSchemaType.HalfYear:
            case PaymentSchemaType.HalfYearWithDiscount:
                return(GeneratePaymentSchema(6, startDate, endDate, amount));

            case PaymentSchemaType.Quarterly:
            case PaymentSchemaType.QuarterlyWithDiscount:
                return(GeneratePaymentSchema(3, startDate, endDate, amount));

            case PaymentSchemaType.Monthly:
            case PaymentSchemaType.MonthlyWithDiscount:
                return(GeneratePaymentSchema(1, startDate, endDate, amount));

            //case PaymentSchemaType.OneQuarterlyEightMonthly:
            //    int firstQuarterMonthCount = (monthsCount < 4 ? monthsCount : 4);
            //    length = (monthsCount - firstQuarterMonthCount) + 1;
            //    schema = new PaymentInfo[length];

            //    schema[0] = new PaymentInfo();
            //    schema[0].Date = fromDate;
            //    schema[0].Amount = (length > 1 ? Math.Round(amountPerMonth * firstQuarterMonthCount, 2) : amount);
            //    amount -= (decimal)schema[0].Amount;

            //    //premium=120
            //    //count=12
            //    //premium=120-40(პირველი 4 თვე)
            //    for (int i = 1; i < length - 1; i++)
            //    {
            //        schema[i] = new PaymentInfo();
            //        schema[i].Date = schema[i - 1].Date.AddMonths(i == 1 ? 3 : 1);
            //        schema[i].Amount = amountPerMonth;
            //        amount -= amountPerMonth;
            //    }
            //    break;

            default:
                throw new ArgumentException("choose correct payment type.", nameof(paymentSchemaType));
            }
        }
예제 #2
0
 private static decimal InitDiscount(PaymentSchemaType paymentSchemaType, decimal discount)
 {
     switch (paymentSchemaType)
     {
     case PaymentSchemaType.OnceThroughWithDiscount:
     case PaymentSchemaType.HalfYearWithDiscount:
     case PaymentSchemaType.QuarterlyWithDiscount:
     case PaymentSchemaType.MonthlyWithDiscount:
         return(discount);
     }
     return(0m);
 }