Example #1
0
        public static decimal GenerateAndSaveInterest(LoanAccount loanAccount, AgreementItem agreementItem, string type,DateTime actualDate, DateTime validDueDate, DateTime entryDate)
        {
            DateTime lastDayChangeTo30Days = actualDate;
            var lastDayOfTheMonth = LastDayOfMonthFromDateTime(actualDate);

            // Day Difference must still be equal to 30 Days
            if (lastDayChangeTo30Days == lastDayOfTheMonth)
                lastDayChangeTo30Days = ChangeTo30Days(actualDate);

            decimal totalInterest = 0;

            if (loanAccount.InterestTypeId != InterestType.FixedInterestTYpe.Id
                && loanAccount.InterestTypeId != InterestType.ZeroInterestTYpe.Id && agreementItem.MethodOfChargingInterest
                != ProductFeature.DiscountedInterestType.Name)
            {

                 totalInterest = GenerateInterestUsingRate(loanAccount, agreementItem,type,actualDate, validDueDate,entryDate);
            }
            else
            {
                    totalInterest = GenerateInterestFixed(loanAccount, type, lastDayOfTheMonth,entryDate);
            }

            return totalInterest;
        }
Example #2
0
        private static decimal SaveLoanPayment(DateTime entryDate, decimal LoanPayment, LoanAccount loanAccount, Payment ParentPayment)
        {
            if (LoanPayment > 0)
            {
                decimal amountapplied = 0;
                if (loanAccount.LoanBalance <= LoanPayment)
                    amountapplied = loanAccount.LoanBalance;
                else amountapplied = LoanPayment;
                PaymentApplication loanpaymentApplication = new PaymentApplication();
                loanpaymentApplication.Payment = ParentPayment;
                loanpaymentApplication.FinancialAccountId = loanAccount.FinancialAccountId;
                loanpaymentApplication.AmountApplied = amountapplied;
                Context.PaymentApplications.AddObject(loanpaymentApplication);

                loanAccount.LoanBalance -= amountapplied;
                LoanPayment -= amountapplied;
                LoanAccount.UpdateLoanStatus(entryDate, loanAccount, loanAccount.LoanBalance);

            }
            return LoanPayment;
        }
Example #3
0
        private static void SaveInterestPayment(DateTime entryDate, decimal InterestPayment, LoanAccount loanAccount, Payment ParentPayment)
        {
            if (InterestPayment > 0)
            {
                var receivables = from r in Context.Receivables
                                  join rs in Context.ReceivableStatus on r.Id equals rs.ReceivableId
                                  where r.FinancialAccountId == loanAccount.FinancialAccountId
                                  && rs.IsActive == true && (rs.ReceivableStatusType.Id == ReceivableStatusType.OpenType.Id
                                  || rs.ReceivableStatusType.Id == ReceivableStatusType.PartiallyPaidType.Id)
                                  orderby r.ValidityPeriod
                                  select r;
                foreach (var receivable in receivables)
                {
                    if (InterestPayment > 0)
                    {
                        decimal amountapplied = 0;
                        if (receivable.Balance <= InterestPayment)
                            amountapplied = (decimal)receivable.Balance;
                        else if (receivable.Balance > InterestPayment)
                            amountapplied = InterestPayment;

                        PaymentApplication paymentApplication = new PaymentApplication();
                        paymentApplication.Payment = ParentPayment;
                        paymentApplication.ReceivableId = receivable.Id;
                        paymentApplication.AmountApplied = amountapplied;
                        Context.PaymentApplications.AddObject(paymentApplication);
                        receivable.Balance -= amountapplied;

                        Receivable.InsertReceivableStatus(receivable.Id, receivable.Balance, entryDate);

                        InterestPayment -= amountapplied;

                    }
                    //Context.SaveChanges();

                }
            }
        }
            public LoansGrantedModel(LoanApplication loanApplication, Party party, LoanAccount loanAccount)
            {
                this.LoanApplicationId = loanApplication.ApplicationId;
                this.LoanAmount = loanApplication.LoanAmount;
                this.InterestRate = loanApplication.InterestRate;
                this.LoanTerm = loanApplication.LoanTermLength;
                var aiCollateralRequirement = ApplicationItem.GetFirstActive(loanApplication.Application, ProductFeatureCategory.CollateralRequirementType);
                this.LoanProduct = aiCollateralRequirement.ProductFeatureApplicability.FinancialProduct.Name;
                this.LoanAccountStatus = loanAccount.CurrentStatus.LoanAccountStatusType.Name;
                var collateral = aiCollateralRequirement.ProductFeatureApplicability.ProductFeature.Name;
                if (!string.IsNullOrWhiteSpace(collateral))
                    this.CollateralRequirement = collateral;
                else
                    this.CollateralRequirement = "N/A";
                this.PaymentMode = UnitOfMeasure.GetByID(loanApplication.PaymentModeUomId).Name;
                this.LoanBalance = loanAccount.LoanBalance;
                if (party.PartyTypeId == PartyType.PersonType.Id)
                {
                    Person personAsCustomer = party.Person;

                    this.BorrowersName = StringConcatUtility.Build(" ", personAsCustomer.LastNameString + ","
                        , personAsCustomer.FirstNameString, personAsCustomer.MiddleInitialString,
                        personAsCustomer.NameSuffixString);
                }
            }
Example #5
0
        public static decimal GenerateInterestForLastMonth(DateTime selectedDate, LoanAccount loanAccount, AgreementItem agreementItem, string type)
        {
            decimal interest = 0;
             var diffTodayAndRelease = 0;
             DateTime firstDayOfTheMonth = new DateTime(selectedDate.Year, selectedDate.Month, 1);
             var lastDayOfLastMonth = firstDayOfTheMonth.AddDays(-1);

             var receivablesLastMonth = ObjectContext.Receivables.Where(entity => entity.FinancialAccountId == loanAccount.FinancialAccountId
              && entity.ValidityPeriod.Month == lastDayOfLastMonth.Month && entity.ValidityPeriod.Year == lastDayOfLastMonth.Year
              && entity.ValidityPeriod.Day == lastDayOfLastMonth.Day).OrderByDescending(entity => entity.ValidityPeriod);
             diffTodayAndRelease = lastDayOfLastMonth.Subtract(loanAccount.LoanReleaseDate.Value).Days;

             //If no receivables generated where validity period until end of last month, generated bill
            if (receivablesLastMonth.Count() == 0 && diffTodayAndRelease > 0 )
             {
                 interest = GenerateAndSaveInterest(loanAccount, agreementItem,type,lastDayOfLastMonth,lastDayOfLastMonth,selectedDate);
             }
            return interest;
        }
Example #6
0
        public static decimal GenerateInterest(LoanAccount loanAccount, AgreementItem agreementItem, int days, decimal balance)
        {
            decimal interest = 0;
            string interestDescription = agreementItem.InterestRateDescription;
            decimal interestRate = agreementItem.InterestRate;

            interest = GenerateInterest(interestDescription, balance, interestRate, days);
            interest = Math.Floor(interest);
            return interest;
        }
Example #7
0
        private static decimal GenerateWithAmmort(LoanAccount loanAccount, AgreementItem agreementItem, DateTime today)
        {
            decimal totalInterest = 0;

            var ammortItems = ObjectContext.AmortizationScheduleItems.Where(entity => entity.AmortizationSchedule.AgreementId == agreementItem.AgreementId
                && today >= entity.ScheduledPaymentDate && entity.IsBilledIndicator == false);

            foreach (var item in ammortItems)
            {
                var ammortItem = ObjectContext.AmortizationScheduleItems.FirstOrDefault(entity => entity.Id == item.Id);
                totalInterest = item.InterestPayment;
                CreateReceivableWithStatus(loanAccount.FinancialAccountId,item.InterestPayment,-1,GenerateBillSave,item.ScheduledPaymentDate,item.ScheduledPaymentDate,item.ScheduledPaymentDate);
                ammortItem.IsBilledIndicator = true;
                ObjectContext.SaveChanges();

            }
            return totalInterest;
        }
Example #8
0
        private static decimal GenerateInterestUsingRate(LoanAccount loanAccount, AgreementItem agreementItem, string type,DateTime actualDate, DateTime validDueDate,DateTime entryDate)
        {
            DateTime lastDayChangeTo30Days = actualDate;
            var lastDayOfTheMonth = LastDayOfMonthFromDateTime(actualDate);
            var advanceChangeDay = SystemSetting.AdvanceChangeNoInterestStartDay;

            // Day Difference must still be equal to 30 Days
            if (lastDayChangeTo30Days == lastDayOfTheMonth)
                lastDayChangeTo30Days = ChangeTo30Days(actualDate);

            /*** INITIALISATIONS****/
            var diffBetweenPaymentAndToday = SystemSetting.GracePeriod + 1;
            var diffBetweenReleaseandToday = SystemSetting.GracePeriod + 1;
            var firstDayOfTheMonth = new DateTime(actualDate.Year, actualDate.Month, 1);
            decimal totalInterest = 0;
            var loanDisbursemntVoucher = ObjectContext.LoanDisbursementVcrs.FirstOrDefault(entity => entity.AgreementId == agreementItem.AgreementId);
            decimal loanBalance = 0;
            if (agreementItem.InterestComputationMode == ProductFeature.StraightLineMethodType.Name
                && agreementItem.MethodOfChargingInterest == ProductFeature.AddonInterestType.Name)
                loanBalance = loanAccount.LoanAmount;
            else if (agreementItem.InterestComputationMode == ProductFeature.DiminishingBalanceMethodType.Name
                && agreementItem.MethodOfChargingInterest == ProductFeature.AddonInterestType.Name)
                loanBalance = loanAccount.LoanBalance;
            /*** INITIALISATIONS****/

            //Check for last payment date
            var payments = ObjectContext.FinAcctTrans.Where(entity => entity.FinancialAccountId == loanAccount.FinancialAccountId
                         && entity.TransactionDate.Month == actualDate.Month && entity.TransactionDate.Year == actualDate.Year).OrderByDescending(entity => entity.TransactionDate);
            var latestPayment = payments.FirstOrDefault();

            if (latestPayment != null)
                diffBetweenPaymentAndToday = lastDayChangeTo30Days.Subtract(latestPayment.TransactionDate.Date).Days;
            if (lastDayChangeTo30Days.Month == loanAccount.LoanReleaseDate.Value.Month && lastDayChangeTo30Days.Year == loanAccount.LoanReleaseDate.Value.Year)
                diffBetweenReleaseandToday = lastDayChangeTo30Days.Subtract(loanAccount.LoanReleaseDate.Value.Date).Days;

            // If lastpayment date is < grace period, do not generate interest
            // if loanrelease is lesser < grace period, no interest
            if (diffBetweenPaymentAndToday > SystemSetting.GracePeriod && diffBetweenReleaseandToday > SystemSetting.GracePeriod)
            {
                decimal totalDisbursedAmount = 0;
                decimal interest = 0;
                var dayDiff = GetDays(agreementItem.PaymentMode); // default day difference is 30 days;

                var receivablesForCurrentMonth = ObjectContext.Receivables.Where(entity => entity.FinancialAccountId == loanAccount.FinancialAccountId
                && entity.ValidityPeriod.Month == actualDate.Month && entity.ValidityPeriod.Year == actualDate.Year).OrderByDescending(entity => entity.ValidityPeriod);

                var disbursementsForCurrentMonth = from pa in ObjectContext.PaymentApplications
                                                   join d in ObjectContext.Disbursements on pa.PaymentId equals d.PaymentId
                                                   join ld in ObjectContext.LoanDisbursements on d.PaymentId equals ld.PaymentId
                                                   join p in ObjectContext.Payments on d.PaymentId equals p.Id
                                                   where p.TransactionDate.Month == actualDate.Month
                                                   && p.TransactionDate.Year == p.TransactionDate.Year
                                                   && pa.LoanDisbursementVoucherId == loanDisbursemntVoucher.Id
                                                   orderby p.TransactionDate ascending
                                                   select new { payment = p, loandisbursement = ld };

                if (disbursementsForCurrentMonth.Count() != 0)
                {
                    totalDisbursedAmount = disbursementsForCurrentMonth.Sum(entity => entity.payment.TotalAmount);
                    if (receivablesForCurrentMonth.Count() != 0)
                    {
                        var interestpayment = receivablesForCurrentMonth.Sum(entity => entity.Amount - entity.Balance);

                        if (payments.Count() != 0)
                        {
                          //  totalDisbursedAmount = disbursementsForCurrentMonth.Sum(entity => entity.payment.TotalAmount);
                            loanBalance -= totalDisbursedAmount;
                            if (loanBalance != 0)
                            {
                                var previousReceivable = receivablesForCurrentMonth.FirstOrDefault(entity => entity.PaymentId == null);
                                if (previousReceivable != null)
                                {
                                    if (previousReceivable.ValidityPeriod.Date < lastDayChangeTo30Days)
                                        dayDiff = lastDayChangeTo30Days.Subtract(previousReceivable.ValidityPeriod.Date).Days;
                                    else dayDiff = 0;

                                }
                                interest = GenerateInterest(loanAccount, agreementItem, dayDiff, loanBalance);
                                CreateReceivableWithStatus(loanAccount.FinancialAccountId,interest,  -1,type,actualDate,validDueDate,entryDate);
                                totalInterest += interest;
                            }
                            foreach (var disbursement in disbursementsForCurrentMonth)
                            {
                                var previousReceivable = receivablesForCurrentMonth.FirstOrDefault(entity => entity.PaymentId == disbursement.payment.Id);
                                if (previousReceivable != null)
                                {
                                    if (previousReceivable.ValidityPeriod.Date < lastDayChangeTo30Days)
                                        dayDiff = lastDayChangeTo30Days.Subtract(previousReceivable.ValidityPeriod.Date).Days;
                                    else dayDiff = 0;
                                }
                                else
                                {
                                    //Check if advance change ang particular disbursement
                                    if (disbursement.loandisbursement.LoanDisbursementTypeId == LoanDisbursementType.ACCheque.Id && disbursement.payment.TransactionDate.Day >= advanceChangeDay)
                                        dayDiff = 0;
                                    else
                                    {
                                        dayDiff = lastDayChangeTo30Days.Subtract(disbursement.payment.TransactionDate).Days;
                                        if (disbursement.payment.TransactionDate.Day == 1) dayDiff += 1;

                                    }
                                }
                                if (dayDiff > SystemSetting.GracePeriod)
                                {
                                    loanBalance = disbursement.payment.TotalAmount;
                                    interest = GenerateInterest(loanAccount, agreementItem, dayDiff, loanBalance);
                                    CreateReceivableWithStatus(loanAccount.FinancialAccountId, interest, disbursement.payment.Id, type, actualDate, validDueDate, entryDate);
                                    totalInterest += interest;
                                }
                            }
                        }
                        else
                        {
                            //No payments, only additional loan
                            loanBalance -= totalDisbursedAmount;
                            if (loanBalance != 0)
                            {
                                var previousReceivable = receivablesForCurrentMonth.FirstOrDefault(entity => entity.PaymentId == null);
                                if (previousReceivable != null)
                                {

                                    if (previousReceivable.ValidityPeriod.Date < lastDayChangeTo30Days)
                                        dayDiff = lastDayChangeTo30Days.Subtract(previousReceivable.ValidityPeriod.Date).Days;
                                    else dayDiff = 0;
                                }
                                interest += GenerateInterest(loanAccount, agreementItem, dayDiff, loanBalance);
                                    CreateReceivableWithStatus(loanAccount.FinancialAccountId, interest, -1, type, actualDate, validDueDate,entryDate);
                                totalInterest += interest;
                            }
                            foreach (var disbursement in disbursementsForCurrentMonth)
                            {
                                var previousReceivable = receivablesForCurrentMonth.FirstOrDefault(entity => entity.PaymentId == disbursement.payment.Id);
                                if (previousReceivable != null)
                                {
                                    if (previousReceivable.ValidityPeriod.Date < lastDayChangeTo30Days)
                                        dayDiff = lastDayChangeTo30Days.Subtract(previousReceivable.ValidityPeriod.Date).Days;
                                    else dayDiff = 0;
                                }
                                else
                                {
                                    //Check if advance change ang particular disbursement
                                    if (disbursement.loandisbursement.LoanDisbursementTypeId == LoanDisbursementType.ACCheque.Id && disbursement.payment.TransactionDate.Day >= advanceChangeDay)
                                        dayDiff = 0;
                                    else
                                    {
                                        dayDiff = lastDayChangeTo30Days.Subtract(disbursement.payment.TransactionDate).Days;
                                        if (disbursement.payment.TransactionDate.Day == 1) dayDiff += 1;
                                    }
                                }
                                if (dayDiff > SystemSetting.GracePeriod)
                                {
                                    loanBalance = disbursement.payment.TotalAmount;
                                    interest = GenerateInterest(loanAccount, agreementItem, dayDiff, loanBalance);
                                    CreateReceivableWithStatus(loanAccount.FinancialAccountId, interest, disbursement.payment.Id, type, actualDate, validDueDate, entryDate);
                                    totalInterest += interest;
                                }
                            }
                        }
                    }
                    else
                    {
                        //No manual billed receivables
                        totalDisbursedAmount = disbursementsForCurrentMonth.Sum(entity => entity.payment.TotalAmount);
                        loanBalance -= totalDisbursedAmount;
                        if (loanBalance != 0)
                        {
                            interest += GenerateInterest(loanAccount, agreementItem, dayDiff, loanBalance);
                                CreateReceivableWithStatus(loanAccount.FinancialAccountId, interest, -1, type, actualDate, validDueDate,entryDate);
                        }
                        totalInterest += interest;

                        foreach (var disbursement in disbursementsForCurrentMonth)
                        {
                            interest = 0;

                            if (disbursement.loandisbursement.LoanDisbursementTypeId == LoanDisbursementType.ACCheque.Id && disbursement.payment.TransactionDate.Day >= advanceChangeDay)
                                dayDiff = 0;
                            else
                            {
                                dayDiff = lastDayChangeTo30Days.Subtract(disbursement.payment.TransactionDate).Days;
                                if (disbursement.payment.TransactionDate.Day == 1) dayDiff += 1;
                            }
                            if (dayDiff > SystemSetting.GracePeriod)
                            {
                                loanBalance = disbursement.payment.TotalAmount;
                                interest = GenerateInterest(loanAccount, agreementItem, dayDiff, loanBalance);
                                CreateReceivableWithStatus(loanAccount.FinancialAccountId, interest, disbursement.payment.Id, type, actualDate, validDueDate, entryDate);
                                totalInterest += interest;
                            }
                        }
                    }

                }
                else
                {

                    //No DISBURSEMENTS FOR THIS MONTH, Meaning no additional loan and no payments
                    if (receivablesForCurrentMonth.Count() > 0)
                    {
                        if (receivablesForCurrentMonth.FirstOrDefault() != null)
                        {
                            if (receivablesForCurrentMonth.FirstOrDefault().ValidityPeriod < lastDayChangeTo30Days)
                                dayDiff = lastDayChangeTo30Days.Subtract(receivablesForCurrentMonth.FirstOrDefault().ValidityPeriod).Days;
                            else dayDiff = 0;
                        }
                    }
                    else if (actualDate.Day != lastDayOfTheMonth.Day && actualDate.Month == lastDayOfTheMonth.Month)
                        dayDiff = actualDate.Day;
                        //for those manual billing like nov 28, day diff must be 28
                        //else it must use the default 30 days

                    //if (dayDiff > SystemSetting.GracePeriod)
                    //{
                        interest = GenerateInterest(loanAccount, agreementItem, dayDiff, loanBalance);
                        totalInterest += interest;
                        if (interest > 0)
                            CreateReceivableWithStatus(loanAccount.FinancialAccountId, interest, -1, type, actualDate, validDueDate, entryDate);
                  //  }
                }
            }
            return totalInterest;
        }
Example #9
0
 private static decimal GenerateInterestFixed(LoanAccount loanAccount, string type, DateTime lastDayOfTheMonth,DateTime entryDate)
 {
     decimal totalInterest = 0;
     var item = from i in ObjectContext.InterestItems
                where i.LoanId == loanAccount.FinancialAccountId
                && i.IsActive == true
                select i;
     var hasReceivable = from r in ObjectContext.Receivables
                         where r.FinancialAccountId == loanAccount.FinancialAccountId
                         && r.DueDate == lastDayOfTheMonth
                         select r;
     if (item.Count() != 0 && hasReceivable.Count() == 0)
     {
             totalInterest = item.FirstOrDefault().Amount;
             CreateReceivableWithStatus(loanAccount.FinancialAccountId, item.FirstOrDefault().Amount, -1, type, lastDayOfTheMonth, lastDayOfTheMonth, entryDate);
     }
     return totalInterest;
 }
        public static void UpdateLoanStatus(DateTime today, LoanAccount loanAccount, decimal balance)
        {
            var currentstatus = loanAccount.CurrentStatus;

            if ((currentstatus.StatusTypeId == LoanAccountStatusType.CurrentType.Id
                     || currentstatus.StatusTypeId == LoanAccountStatusType.DelinquentType.Id
                     || currentstatus.StatusTypeId == LoanAccountStatusType.UnderLitigationType.Id
                     || currentstatus.StatusTypeId == LoanAccountStatusType.RestructuredType.Id)
                     && balance == 0)
            {
                var isValidIndicator = ObjectContext.LoanAccountStatusTypeAssocs.Where(entity => entity.FromStatusTypeId == currentstatus.StatusTypeId
                    && entity.ToStatusTypeId == LoanAccountStatusType.PaidOffType.Id && entity.EndDate == null).Count();

                if (isValidIndicator > 0)
                {
                    currentstatus.IsActive = false;
                    LoanAccountStatu loanAccountStatus = new LoanAccountStatu();
                    loanAccountStatus.FinancialAccountId = currentstatus.FinancialAccountId;
                    loanAccountStatus.StatusTypeId = LoanAccountStatusType.PaidOffType.Id;
                    loanAccountStatus.TransitionDateTime = today;
                    loanAccountStatus.IsActive = true;
                    ObjectContext.LoanAccountStatus.AddObject(loanAccountStatus);
                }
            }
        }
        private void UpdateList(DateTime now,LoanAccount loanAccount)
        {
            var receivables = from l in ObjectContext.LoanAccounts
                              join r in ObjectContext.Receivables on l.FinancialAccountId equals r.FinancialAccountId
                              where r.Date == now && l.FinancialAccountId == loanAccount.FinancialAccountId
                              select r;

            AddLoanPaymentForm form = this.Retrieve<AddLoanPaymentForm>(ParentResourceGuid);
            LoanPaymentModel borrower = this.RetrieveBOM<LoanPaymentModel>();

            //foreach receivable newly generated
            if (txtInterestPayment.Text != "0.00")
            {
                //borrower.InterestReceivables.Clear();

                foreach(var interestReceivable in receivables){
                    ReceivableInfo interestInfo = new ReceivableInfo();
                    interestInfo.Amount = interestReceivable.Amount;
                    interestInfo.ReceivableId = interestReceivable.Id;
                    interestInfo.DueDate = interestReceivable.DueDate;
                    borrower.InterestReceivables.Add(interestInfo);
                }
            }
            borrower.UpdateAll();
        }