Esempio n. 1
0
        }         // GetStateAt

        public void Recalculate(Loan loan, DateTime dateTime)
        {
            var payEarlyCalc = new LoanRepaymentScheduleCalculator(loan, dateTime, this.amountToChargeFrom);

            payEarlyCalc.GetState();

            try {
                long nlLoanId = serviceInstance.GetLoanByOldID(loan.Id, loan.Customer.Id);
                if (nlLoanId > 0)
                {
                    var nlModel = serviceInstance.GetLoanState(loan.Customer.Id, nlLoanId, dateTime, 1);
                    Log.InfoFormat("<<<Recalculate NL_Compare {0}\n  'old' loan: {1} >>>", nlModel, loan);
                }
                else
                {
                    Log.InfoFormat("<<<Recalculate NL loan for oldid {0} not found >>>", loan.Id);
                }
            } catch (Exception) {
                Log.InfoFormat("<<< NL_Compare Fail at: {0}", Environment.StackTrace);
            }
        }         // Recalculate
Esempio n. 2
0
        }         // MakePayment

        public LoanScheduleItem GetStateAt(Loan loan, DateTime dateTime)
        {
            var payEarlyCalc = new LoanRepaymentScheduleCalculator(loan, dateTime, this.amountToChargeFrom);
            var result       = payEarlyCalc.GetState();

            try {
                long nlLoanId = serviceInstance.GetLoanByOldID(loan.Id, loan.Customer.Id);
                if (nlLoanId > 0)
                {
                    var nlModel = serviceInstance.GetLoanState(loan.Customer.Id, nlLoanId, dateTime, 1);
                    Log.InfoFormat("<<<GetStateAt NL_Compare at : {0} ;  nlModel : {1} loan: {2} >>>", Environment.StackTrace, nlModel, loan);
                }
                else
                {
                    Log.InfoFormat("<<<GetStateAt NL loan for oldid {0} not found >>>", loan.Id);
                }
            } catch (Exception) {
                Log.InfoFormat("<<<GetStateAt NL_Compare Fail at : {0}", Environment.StackTrace);
            }

            return(result);
        }         // GetStateAt
Esempio n. 3
0
        }         // PayAllLoansForCustomer

        /// <exception cref="OverflowException">The sum is larger than <see cref="F:System.Decimal.MaxValue" />.</exception>
        /// <exception cref="ArgumentNullException"><paramref /> or <paramref /> is null.</exception>
        /// <exception cref="InvalidCastException"><paramref /> cannot be cast to the element type of the current <see cref="T:System.Array" />.</exception>
        public void PayAllLateLoansForCustomer(
            Customer customer,
            decimal amount,
            string transId,
            DateTime?term                   = null,
            string description              = null,
            string sManualPaymentMethod     = null,
            NL_Payments nlPaymentCommomData = null)
        {
            DateTime date = term ?? DateTime.Now;

            IEnumerable <Loan> loans = customer.ActiveLoans.Where(l => l.Status == LoanStatus.Late);

            var nlLoansList = serviceInstance.GetCustomerLoans(customer.Id).ToList();

            if (nlLoansList.Count > 0)
            {
                nlLoansList.ForEach(l => Log.InfoFormat("PayAllLateLoansForCustomer NLLoanID={0}", l.LoanID));
            }

            foreach (var loan in loans)
            {
                if (amount <= 0)
                {
                    break;
                }

                LoanRepaymentScheduleCalculator c = new LoanRepaymentScheduleCalculator(loan, term, this.amountToChargeFrom);
                LoanScheduleItem state            = c.GetState();

                decimal late = loan.Schedule.Where(s => s.Status == LoanScheduleStatus.Late).Sum(s => s.LoanRepayment) + state.Interest + state.Fees + state.LateCharges;

                decimal money = Math.Min(amount, late);

                NL_Payments nlPayment = null;

                // customer's nl loans
                if (nlLoansList.Count > 0)
                {
                    // current loan
                    var nlLoan = nlLoansList.FirstOrDefault(x => x.OldLoanID == loan.Id);

                    if (nlLoan != null)
                    {
                        var nlModel = serviceInstance.GetLoanState(loan.Customer.Id, nlLoan.LoanID, DateTime.UtcNow, 1);

                        decimal nlLate = nlModel.Interest + nlModel.Fees;
                        nlModel.Loan.Histories.ForEach(h => h.Schedule.Where(s => s.LoanScheduleStatusID == (int)NLScheduleStatuses.Late).Sum(s => nlLate += s.Principal));
                        decimal nlMoney = Math.Min(amount, nlLate);

                        Log.InfoFormat("<<< NL_Compare: Loan:{0} NLModel:{1}.\n late={2}, nlLate={3}, amount={4}, money={5}, nlMoney={6} >>>", loan, nlModel, late, nlLate, amount, money, nlMoney);

                        nlPayment = new NL_Payments()
                        {
                            Amount          = money,
                            CreatedByUserID = 1,
                            CreationTime    = DateTime.UtcNow,
                            LoanID          = nlLoan.LoanID,
                            PaymentTime     = DateTime.UtcNow,
                            Notes           = "PayAllLateLoansForCustomer",
                            //PaymentMethodID = (int)NLLoanTransactionMethods.CustomerAuto,
                            PaymentStatusID   = (int)NLPaymentStatuses.Active,
                            PaymentSystemType = nlPaymentCommomData != null ? nlPaymentCommomData.PaymentSystemType : NLPaymentSystemTypes.None,
                            PaymentMethodID   = nlPaymentCommomData != null ? nlPaymentCommomData.PaymentMethodID : (int)NLLoanTransactionMethods.Manual                           // put better check
                        };
                    }
                }

                PayLoan(loan, transId, money, null, date, description, false, sManualPaymentMethod, nlPayment);

                amount = amount - money;
            }     // for
        }         // PayAllLateLoansForCustomer