public async Task <OfferLetterDetailObj> Handle(GenerateOfferLetterQuery request, CancellationToken cancellationToken) { var _LoanOffer = await _repo.GetLoanapplicationOfferLeterAsync(request.ApplicationReference); OfferLetterDetailObj offerletterResp = new OfferLetterDetailObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage() } }; if (_LoanOffer != null) { var _Companies = await _serverRequest.GetAllCompanyAsync(); var _Currency = await _serverRequest.GetCurrencyAsync(); var _LoanCustomer = await _loanCustomerRepo.GetLoanCustomersAsync(); var _Product = await _product.GetProductsAsync(); offerletterResp.CompanyName = _Companies.companyStructures.FirstOrDefault(c => c.companyStructureId == _LoanOffer.CompanyId)?.name; offerletterResp.ProductName = _Product.FirstOrDefault(c => c.ProductId == _LoanOffer.ApprovedProductId)?.ProductName; offerletterResp.CurrencyName = _Currency.commonLookups.FirstOrDefault(c => c.LookupId == _LoanOffer.CurrencyId)?.LookupName; offerletterResp.Tenor = _LoanOffer.ApprovedTenor; offerletterResp.InterestRate = _LoanOffer.ApprovedRate; offerletterResp.LoanAmount = _LoanOffer.ApprovedAmount; offerletterResp.ExchangeRate = _LoanOffer.ExchangeRate; offerletterResp.CustomerAddress = _LoanCustomer.FirstOrDefault(a => a.CustomerId == _LoanOffer.CustomerId)?.Address; offerletterResp.CustomerEmailAddress = _LoanCustomer.FirstOrDefault(d => d.CustomerId == _LoanOffer.CustomerId)?.Email; offerletterResp.CustomerPhoneNumber = _LoanCustomer.FirstOrDefault(d => d.CustomerId == _LoanOffer.CustomerId)?.PhoneNo; offerletterResp.ApplicationDate = _LoanOffer.ApplicationDate; offerletterResp.LoanApplicationId = _LoanOffer.ApplicationRefNumber; offerletterResp.RepaymentSchedule = "Not applicable"; offerletterResp.RepaymentTerms = "Not applicable"; offerletterResp.Purpose = _LoanOffer.Purpose; offerletterResp.CustomerName = $"{_LoanCustomer.FirstOrDefault(d => d.CustomerId == _LoanOffer.CustomerId)?.FirstName} {_LoanCustomer.FirstOrDefault(d => d.CustomerId == _LoanOffer.CustomerId)?.LastName} "; } var decision = _repo.GetOfferletterDecision(_LoanOffer.LoanApplicationId); var customerDocs = await _loanCustomerRepo.GetCustomerDocumentsAsync(_LoanOffer.CustomerId); var signatureExist = customerDocs.Any(s => s.DocumentTypeId == 1); if (decision != null && signatureExist) { if (decision.ReportStatus.ToLower().Trim() == "accept") { offerletterResp.Signature = customerDocs.FirstOrDefault(x => x.DocumentTypeId == 1)?.DocumentFile; } } if (offerletterResp != null) { offerletterResp.Status.IsSuccessful = true; return(offerletterResp); } offerletterResp.Status.Message.FriendlyMessage = "Unable to fetch offer letter"; return(offerletterResp); }
public async Task <ActionResult <LoanApplicationRespObj> > SubmitLoanForCreditAppraisal([FromQuery] LoanApplicationSearchObj model) { try { var response = await _repo.SubmitLoanForCreditAppraisal(model.LoanApplicationId); if (response.Status.IsSuccessful) { var companyList = await _serverRequest.GetAllCompanyAsync(); var loanObj = _context.credit_loanapplication.Find(model.LoanApplicationId); var customerObj = _context.credit_loancustomer.Find(loanObj.CustomerId); var productFeeList = _context.credit_productfee.Where(x => x.ProductId == loanObj.ApprovedProductId && x.Deleted == false).ToList(); foreach (var item in productFeeList) { decimal productamount = 0; var fee = _context.credit_fee.FirstOrDefault(x => x.FeeId == item.FeeId && x.IsIntegral == false && x.Deleted == false); if (item.ProductFeeType == 2)//Percentage { productamount = (loanObj.ApprovedAmount * Convert.ToDecimal(item.ProductAmount)) / 100; } else///Fixed { productamount = Convert.ToDecimal(item.ProductAmount); } if (fee != null) { CustomerTransactionObj customerTrans = new CustomerTransactionObj { CasaAccountNumber = customerObj.CASAAccountNumber, Description = "Payment of Non Integral Fee", TransactionDate = DateTime.Now, ValueDate = DateTime.Now, TransactionType = "Debit", CreditAmount = 0, DebitAmount = productamount, Beneficiary = companyList.companyStructures.FirstOrDefault(x => x.companyStructureId == loanObj.CompanyId)?.name, ReferenceNo = loanObj.ApplicationRefNumber, }; _customerTrans.CustomerTransaction(customerTrans); } } } return(new LoanApplicationRespObj { ResponseId = response.ResponseId, Status = response.Status }); } catch (Exception ex) { var errorCode = ErrorID.Generate(5); _logger.Error($"ErrorID : {errorCode} Ex : {ex?.Message ?? ex?.InnerException?.Message} ErrorStack : {ex?.StackTrace}"); return(new LoanApplicationRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage { FriendlyMessage = "Error Occurred", TechnicalMessage = ex?.Message, MessageId = errorCode } } }); } }