public decimal getAmountPaid(string batchNO) { var LS = new List <LoanSummaryVM>(); decimal finalamt = 0; var loan = context.pf_LoanRegisters.Where(x => x.batchNo == batchNO).ToList(); foreach (var a in loan) { int interest = 0; var loantypeint = context.Pf_loanType.FirstOrDefault(x => x.Id == a.LoanTypeID); var loanreview = context.npf_loantypereview.Where(x => x.LoanType == loantypeint.Code); foreach (var r in loanreview) { var d = new LoanSummaryVM(); if (r.ReviewDate.Date > a.EffectiveDate.Date) { continue; } else { interest = r.Interestrate; d.amountpaid = (((decimal)a.Amount + (((decimal)a.Amount * interest) / 100)) / Convert.ToInt32(a.Tenure)) * a.loancount; } LS.Add(d); } } finalamt = LS.Sum(x => x.amountpaid); return(finalamt); }
public async Task <IActionResult> LoanSummary2(string year, int type) { var LS = new List <LoanSummaryVM>(); var batchno = context.pf_LoanRegisters.DistinctBy(x => x.batchNo).Where(x => x.LoanTypeID == type).ToList(); foreach (var a in batchno) { var d = new LoanSummaryVM { noofpeople = context.pf_LoanRegisters.Where(x => x.batchNo == a.batchNo).Count(), totalloan = getinterest(a.batchNo),//(decimal)context.pf_LoanRegisters.Where(x => x.batchNo == a.batchNo).ToList().Sum(x => x.Amount), amountpaid = getAmountPaid(a.batchNo), curcount = a.loancount, term = Convert.ToInt32(a.Tenure), amountperyearR = (decimal)context.npf_Histories.Where(x => x.batchNo == a.batchNo && x.doctype != "JV" && x.period.Substring(0, 4) == year && x.refno.Substring(0, 3) == a.batchNo.Substring(0, 3) && x.remarks == "LOAN REVERSAL").ToList().Sum(x => x.cramt), amountperyear = (decimal)context.npf_Histories.Where(x => x.batchNo == a.batchNo && x.doctype != "JV" && x.period.Substring(0, 4) == year).ToList().Sum(x => x.cramt), amountpaidP = (decimal)context.npf_Histories.Where(x => x.batchNo == a.batchNo && x.doctype != "JV").ToList().Sum(x => x.cramt), amountpaidOP = (decimal)context.npf_Histories.Where(x => x.batchNo == a.batchNo && x.doctype == "JV").ToList().Sum(x => x.cramt), batchno = a.batchNo, Effectivedate = a.EffectiveDate, loantype = (int)a.LoanTypeID, //noofde=faulter = hcount }; if (d.amountperyear == 0) { continue; } d.amountperyear = d.amountperyear - d.amountperyearR; d.amountpaidH = d.totalloan - d.amountpaidOP + d.amountpaidP; if (d.amountpaidH >= d.totalloan) { d.amountpaidH = d.amountpaidH - d.totalloan; d.amountowned = d.amountowned - d.totalloan; } d.amountowned = d.amountpaid - d.amountpaidH; LS.Add(d); } decimal total = LS.ToList().Sum(x => x.amountperyear); return(await generatePdf.GetPdf("Views/LoanPosition/LoansummaryReport.cshtml", LS.OrderBy(x => x.batchno))); ////return View(loanRecieveableList); }