コード例 #1
0
 public ActionResult Index(BranchProgressReportModel model)
 {
     if (ModelState.IsValid)
     {
         GetBranchProgress(model);
     }
     ViewBag.BranchId = new SelectList(db.Branches, "BranchId", "BranchCode");
     return(View());
 }
コード例 #2
0
        public void GetBranchProgress(BranchProgressReportModel branchProgressReportModel)
        {
            //return ViewPdf("Branch Progress Report", "Index", null);
            int branchId = branchProgressReportModel.BranchId;



            #region Total Client & Active Clients (No Date Filter)
            int totalClient       = db.Clients.Count(x => x.BranchId == branchId);
            int totalActiveClient = 0;
            var activeClients     = db.LoanDisbursements.Where(x => x.LoanStatu.LoanStatus == "Active" && x.BranchId == branchId);

            var uniuqeClient = from m in activeClients
                               group m by m.ClientId into g
                               select new { g.Key };

            totalActiveClient = uniuqeClient.Count();
            #endregion

            BranchProgressReport model = new BranchProgressReport();
            model.TotalClient       = totalClient;
            model.TotalActiveClient = totalActiveClient;

            model.TotalDisbursedLoan = db.LoanDisbursements.Where(x => x.BranchId == branchId &&
                                                                  x.LoanStatu.LoanStatus == "Active" &&
                                                                  x.DisbursmentDate >= branchProgressReportModel.StartDate &&
                                                                  x.DisbursmentDate <= branchProgressReportModel.EndDate
                                                                  ).Count();


            model.TotalDisputedLoan = db.LoanDisbursements.Where(x => x.BranchId == branchId &&
                                                                 x.LoanStatu.LoanStatus == "Disputed" &&
                                                                 x.DisbursmentDate >= branchProgressReportModel.StartDate &&
                                                                 x.DisbursmentDate <= branchProgressReportModel.EndDate
                                                                 ).Count();

            var loanAmountDisbursed = db.LoanDisbursements.Where(x => x.BranchId == branchId &&
                                                                 x.LoanStatu.LoanStatus == "Active" &&
                                                                 x.DisbursmentDate >= branchProgressReportModel.StartDate &&
                                                                 x.DisbursmentDate <= branchProgressReportModel.EndDate
                                                                 ).Sum(x => x.ActualPaidAmount);

            if (loanAmountDisbursed.HasValue)
            {
                model.TotalLoanAmountDisbursed = loanAmountDisbursed.Value;
            }


            var loanDisbursed = db.LoanDisbursements.Where(x => x.BranchId == branchId &&
                                                           x.LoanStatu.LoanStatus == "Active" &&
                                                           x.DisbursmentDate >= branchProgressReportModel.StartDate &&
                                                           x.DisbursmentDate <= branchProgressReportModel.EndDate
                                                           ).ToList();

            decimal totalCollection     = 0;
            decimal totalCollectionDues = 0;
            foreach (var item in loanDisbursed)
            {
                totalCollectionDues += (db.LoanEMISchedules.Where(x => x.LoanDisbursementId == item.LoanDisbursementId &&
                                                                  x.EMIDate >= branchProgressReportModel.StartDate &&
                                                                  x.EMIDate <= branchProgressReportModel.EndDate).Sum(x => x.EMI)).HasValue ? (db.LoanEMISchedules.Where(x => x.LoanDisbursementId == item.LoanDisbursementId &&
                                                                                                                                                                         x.EMIDate >= branchProgressReportModel.StartDate &&
                                                                                                                                                                         x.EMIDate <= branchProgressReportModel.EndDate).Sum(x => x.EMI)).Value : 0;


                totalCollection += (db.LoanRepayments.Where(x => x.LoanDisbursementId == item.LoanDisbursementId &&
                                                            x.LoanRepaymentStatu.LoanRepaymentStatus == "Paid" &&
                                                            x.PaymentDate >= branchProgressReportModel.StartDate &&
                                                            x.PaymentDate <= branchProgressReportModel.EndDate
                                                            ).Sum(x => x.AmountPaid)).HasValue ? (db.LoanRepayments.Where(x => x.LoanDisbursementId == item.LoanDisbursementId &&
                                                                                                                          x.LoanRepaymentStatu.LoanRepaymentStatus == "Paid" &&
                                                                                                                          x.PaymentDate >= branchProgressReportModel.StartDate &&
                                                                                                                          x.PaymentDate <= branchProgressReportModel.EndDate
                                                                                                                          ).Sum(x => x.AmountPaid)).Value : 0;
            }

            model.TotalCollection   = totalCollection;
            model.TotalDue          = totalCollectionDues;
            model.TotalDueRemaining = totalCollectionDues - model.TotalCollection;

            model.StartDate  = branchProgressReportModel.StartDate.ToShortDateString();
            model.EndDate    = branchProgressReportModel.EndDate.ToShortDateString();
            model.BranchName = db.Branches.FirstOrDefault(x => x.BranchId == branchProgressReportModel.BranchId).BranchName.ToString();

            DownloadPdf(model);
            //return this.ViewPdf("", "GetBranchProgress", model);
        }