예제 #1
0
파일: Loan.cs 프로젝트: kanawut/SMCLoan
        public Payment Pay(DateTime date , decimal amount)
        {
            var payment = new Payment();
            payment.Days = ( date.Date - this.LastPaydate.Date).Days;
            payment.PaidAmount = amount;
            payment.PaidDate = date;

            payment.InterestAmount = Math.Round( (Outstanding * PreviousOwner.IntersetRate * payment.Days) / 36500 , 2 ,MidpointRounding.AwayFromZero );

            decimal tempInterestAmount = payment.InterestAmount;

            if (payment.InterestAmount > amount)
            {
                payment.InterestAmount = amount;
            }

            if(amount - payment.InterestAmount < 0   )
            {
                payment.PaidPrincipalAmount = 0;
            }
                else
                {
                 payment.PaidPrincipalAmount = (amount - payment.InterestAmount);
                }

            payment.Outstanding = this.Outstanding - payment.PaidPrincipalAmount;

            this.LastPaydate = date;
            this.Outstanding = payment.Outstanding;

            if (payment.PaidPrincipalAmount == 0.0m)
            {
                this.Accrued = this.Accrued + ( tempInterestAmount - payment.PaidAmount);
            }

            this.Payments.Add(payment);

            return payment;
        }
예제 #2
0
파일: Loan.cs 프로젝트: JakkreeTha/Smcloan
        public Payment Pay(DateTime date, decimal amount)
        {
            if (date < this.LastPayDate)
            {
                throw new ArgumentException("Paid date cannot before the last pay date", "date"); // nameof(date)
            }

            var payment = new Payment();
            TimeSpan ts = date - LastPayDate;
            int days = ts.Days;
            decimal interestAmount = Math.Round(this.Outstanding * (decimal)PreviousOwner.InterestRate
                                      * days / 36500,
                                      2, MidpointRounding.AwayFromZero);

            interestAmount += this.Accrued;

            payment.Days = days;
            payment.PaidAmount = amount;
            payment.PaidDate = date;

            if (interestAmount <= amount)
            {
                payment.InterestAmount = interestAmount;
                this.Accrued = 0m;
            }
            else
            {
                payment.InterestAmount = amount;
                this.Accrued = interestAmount - amount;
            }

            payment.PaidPrincipalAmount = amount - payment.InterestAmount;
            payment.Outstanding = this.Outstanding - payment.PaidPrincipalAmount;

            this.LastPayDate = date;
            this.Outstanding = payment.Outstanding;
            return payment;
        }
예제 #3
0
파일: Loan.cs 프로젝트: JoJoushi/SmcLoan
        public Payment Pay(DateTime date, decimal amount)
        {
            if (date < this.LastPayDate)
            {
                string s = @"Paid date can not before the last pay date.
                Last Pay Date is " + this.LastPayDate.ToString("yyyy-MM-dd");
                throw new ArgumentException(s, "date"); // nameof(date)
            }

            var pay = new Payment();
            pay.Days = (date.Date - LastPayDate.Date).Days;
            pay.PaidDate = date;
            pay.PaidAmount = amount;

            pay.InterestAmount = Math.Round((this.Outstanding * (decimal)PreviousOwner.InterestRate) * pay.Days / 36500,2, MidpointRounding.AwayFromZero);
            if (this.Accrued != 0)
                pay.InterestAmount += this.Accrued;

            if (amount <= pay.InterestAmount)
            {
                this.Accrued = Math.Round(pay.InterestAmount - amount,2, MidpointRounding.AwayFromZero);
                pay.InterestAmount = amount;
            }

            if (pay.InterestAmount >= amount)
                pay.PaidPrincipalAmount = 0;
            else
            {
                this.Accrued = 0;
                pay.PaidPrincipalAmount = amount - pay.InterestAmount;
            }

            pay.Outstanding = this.Outstanding - pay.PaidPrincipalAmount;
            this.Outstanding = pay.Outstanding;
            this.LastPayDate = date;
            return pay;
        }
예제 #4
0
파일: Loan.cs 프로젝트: vasansmc/SmcLoan
        public Payment Pay(DateTime date, decimal amount)
        {
            var payment = new Payment();
            TimeSpan ts = date - LastPayDate;
            int days = ts.Days;
            decimal interestAmount = Math.Round(this.Outstanding * (decimal)PreviousOwner.InterestRate
                                      * days / 36500,
                                      2, MidpointRounding.AwayFromZero);

            interestAmount += this.Accrued;

            payment.Days = days;
            payment.PaidAmount = amount;
            payment.PaidDate = date;

            if (interestAmount <= amount)
            {
                payment.InterestAmount = interestAmount;
                this.Accrued = 0m;
            }
            else
            {
                payment.InterestAmount = amount;
                this.Accrued = interestAmount - amount;
            }

            payment.PaidPrincipalAmount = amount - payment.InterestAmount;
            payment.Outstanding = this.Outstanding - payment.PaidPrincipalAmount;

            this.LastPayDate = date;
            this.Outstanding = payment.Outstanding;

            this.Payments.Add(payment);

            return payment;
            //throw new NotImplementedException();
        }
예제 #5
0
 private void outputPayment(Payment p)
 {
     output.WriteLine("{0:s}\t{1} days\r\nPaid: {2:n2}\r\nPrincipal: {3:n2}\r\nInterest: {4:n2}\r\nOutstanding: {5:n2}",
       p.PaidDate, p.Days,
       p.PaidAmount, p.PaidPrincipalAmount, p.InterestAmount,
       p.Outstanding);
 }