public async Task <IActionResult> UpdateLoanReversal([FromBody] Pf_LoanRegister val)
        {
            var getPersonId = unitOfWork.person.GetPersonBySVC_No(x => x.PersonID == val.PersonID);
            var getLoanType = unitOfWork.loanType.GetLoanTypeByCode(x => x.Id == val.LoanTypeID);

            string fund = HttpContext.Session.GetString("fundtypecode");
            string loan = getLoanType.loanacct.Substring(0, 4);

            using (SqlConnection sqls = new SqlConnection(_connectionstring))
            {
                using (SqlCommand cmd = new SqlCommand("npf_update_loanReversal", sqls))
                {
                    cmd.CommandTimeout = 1200;
                    cmd.CommandType    = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@globaluser", User.Identity.Name));
                    cmd.Parameters.Add(new SqlParameter("@fundtype", fund));
                    cmd.Parameters.Add(new SqlParameter("@batchno", val.batchNo));
                    cmd.Parameters.Add(new SqlParameter("@loantype", getLoanType.loanacct.Substring(0, 4)));
                    cmd.Parameters.Add(new SqlParameter("@persid", val.PersonID));
                    cmd.Parameters.Add(new SqlParameter("@periodH", val.LoanAppNo));
                    cmd.Parameters.Add(new SqlParameter("@docdate", val.ApproveDate));
                    cmd.Parameters.Add("@error", SqlDbType.Char, 500);
                    cmd.Parameters["@error"].Direction = ParameterDirection.Output;

                    await sqls.OpenAsync();

                    await cmd.ExecuteNonQueryAsync();

                    string message = (string)cmd.Parameters["@error"].Value;
                    return(Ok(new { responseCode = 200, responseDescription = message }));
                }
            }
        }
        public async Task <IActionResult> updateLoanRegisterbybatch([FromBody] Pf_LoanRegister val)
        {
            var getPersonId = unitOfWork.person.GetPersonBySVC_No(x => x.PersonID == val.PersonID);
            var getLoanType = unitOfWork.loanType.GetLoanTypeByCode(x => x.Id == val.LoanTypeID);

            using (SqlConnection sqls = new SqlConnection(_connectionstring))
            {
                using (SqlCommand cmd = new SqlCommand("npf_Batch_update_loan", sqls))
                {
                    cmd.CommandTimeout = 1200;
                    cmd.CommandType    = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@globaluser", User.Identity.Name));
                    cmd.Parameters.Add(new SqlParameter("@fundcode", HttpContext.Session.GetString("fundtypecode")));
                    cmd.Parameters.Add(new SqlParameter("@batchno", val.batchNo));
                    cmd.Parameters.Add(new SqlParameter("@status", val.Status));
                    cmd.Parameters.Add("@message", SqlDbType.Char, 500);
                    cmd.Parameters["@message"].Direction = ParameterDirection.Output;

                    await sqls.OpenAsync();

                    await cmd.ExecuteNonQueryAsync();


                    return(Ok(new { responseCode = 200, responseDescription = "Updated Successfully" }));
                }
            }
        }
        public async Task <IActionResult> PutBatchApproveLoanSPAsync([FromBody] Pf_LoanRegister val)
        {
            var getPersonId = unitOfWork.person.GetPersonBySVC_No(x => x.PersonID == val.PersonID);
            var getLoanType = unitOfWork.loanType.GetLoanTypeByCode(x => x.Id == val.LoanTypeID);

            using (SqlConnection sqls = new SqlConnection(_connectionstring))
            {
                using (SqlCommand cmd = new SqlCommand("npf_Batch_approval_loan", sqls))
                {
                    cmd.CommandTimeout = 1200;
                    cmd.CommandType    = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@globaluser", User.Identity.Name));
                    cmd.Parameters.Add(new SqlParameter("@fundcode", HttpContext.Session.GetString("fundtypecode")));
                    cmd.Parameters.Add(new SqlParameter("@batchno", val.LoanAppNo));
                    cmd.Parameters.Add(new SqlParameter("@chqno", val.ChequeNo));
                    cmd.Parameters.Add(new SqlParameter("@bankcode", val.BankID));


                    await sqls.OpenAsync();

                    await cmd.ExecuteNonQueryAsync();

                    return(Ok(new { responseCode = 200, responseDescription = "Updated Successfully" }));
                }
            }
        }
        public IActionResult Put([FromBody] Pf_LoanRegister value)
        {
            try
            {
                if (value.Id <= 0)
                {
                    return(Ok(new { responseCode = 500, responseDescription = "Invalid Loan Record" }));
                }
                var getLoanReg = loanRegisterService.GetLoanRegisterById(value.Id).Result;
                //if (value.Status != "8")-----kenneth
                //{
                getLoanReg.ApproveDate         = value.ApproveDate;
                getLoanReg.BankID              = value.BankID;
                getLoanReg.StatusAndStatusDate = value.StatusAndStatusDate;
                getLoanReg.remarks             = value.remarks;
                getLoanReg.Status              = value.Status;
                loanRegisterService.UpdateLoanRegister(getLoanReg);


                return(Ok(new { responseCode = 200, responseDescription = "Updated Successfully" }));
            }
            catch (Exception ex)
            {
                return(Ok(new { responseCode = 500, responseDescription = "Failed" }));
            }
        }
        public async System.Threading.Tasks.Task <IActionResult> PutLoanAppAsync([FromBody] Pf_LoanRegister value)
        {
            try
            {
                if (value.Id <= 0)
                {
                    return(Ok(new { responseCode = 500, responseDescription = "Invalid Loan Record" }));
                }
                var getLoanReg = loanRegisterService.GetLoanRegisterById(value.Id).Result;

                var getPersonId    = unitOfWork.person.GetPersonBySVC_No(x => x.PersonID == value.PersonID);
                int databasetenure = 0;
                var getLoanType    = unitOfWork.loanType.GetLoanTypeByCode(x => x.Id == value.LoanTypeID);

                string remarks = "";
                value.Status = "1";

                databasetenure = Int32.Parse(getLoanType.Tenure);

                if (databasetenure != Int32.Parse(value.Tenure))
                {
                    remarks += "|Incorrect Loan Tenure Supplied" + "_" + Int32.Parse(value.Tenure);
                }

                decimal amountYOUcantake = 0;
                //check eligibility
                amountYOUcantake = await loanRegisterService.loanAmountPerRankBy2(getPersonId.rank, getLoanType.Code, value.FundTypeID.Value);

                if (value.Amount > amountYOUcantake)
                {
                    remarks += "|You can not take more than" + "_" + amountYOUcantake;
                }
                value.remarks += remarks;

                if (remarks != "")
                {
                    value.Status = "2";
                }
                getLoanReg.Status              = value.Status;
                getLoanReg.Tenure              = value.Tenure;
                getLoanReg.Amount              = value.Amount;
                getLoanReg.LoanTypeID          = value.LoanTypeID;
                getLoanReg.remarks             = value.remarks;
                getLoanReg.StatusAndStatusDate = value.StatusAndStatusDate;
                getLoanReg.StatusAndStatusDate = value.remarks;
                getLoanReg.batchNo             = value.batchNo;
                getLoanReg.loancount           = value.loancount;
                await loanRegisterService.UpdateLoanRegister(getLoanReg);

                return(Ok(new { responseCode = 200, responseDescription = "Updated Successfully" }));
            }
            catch (Exception ex)
            {
                return(Ok(new { responseCode = 500, responseDescription = "Failed" }));
            }
        }
 public async Task <bool> AddLoanRegister(Pf_LoanRegister loanRegister)
 {
     unitOfWork.loanRegisterRepository.Create(loanRegister);
     return(await unitOfWork.Done());
 }
 public async Task <bool> UpdateLoanRegister(Pf_LoanRegister pf_LoanRegister)
 {
     unitOfWork.loanRegisterRepository.Update(pf_LoanRegister);
     return(await unitOfWork.Done());
 }
        public IActionResult createLoanRegister([FromBody] Pf_LoanRegister value)
        {
            try
            {
                if (value.PersonID == null)
                {
                    return(Ok(new { responseCode = 500, responseDescription = "Kindly Supply Person Service Number" }));
                }
                var getPersonId    = unitOfWork.person.GetPersonBySVC_No(x => x.PersonID == value.PersonID);
                int databasetenure = 0;

                //02/29/2020
                var getLoanType = unitOfWork.loanType.GetLoanTypeByCode(x => x.Id == value.LoanTypeID);
                var loacct      = getLoanType.loanacct.Substring(0, 5) + getPersonId.SVC_NO;
                var getledger   = unitOfWork.npf_Ledgers.Getledger(x => x.acctcode == loacct);
                //var loacct = getLoanType.loanacct.Substring(0,4)+"-" + getPersonId.SVC_NO;

                if (getledger != null)
                {
                    getledger.opbalance = 0; getledger.adbbalance = 0; getledger.crbalance = 0;

                    var checkloan = getledger.opbalance + getledger.adbbalance - getledger.crbalance;

                    if (checkloan > 0)
                    {
                        return(Ok(new { responseCode = 500, responseDescription = "You have" + "" + checkloan + " " + " Outstanding Balance on Previous Loan" }));
                    }
                }
                string remarks = "";
                //value.Status = ;
                value.LoanAppNo = getPersonId.SVC_NO + getLoanType.Code + DateTime.Now.Year + DateTime.Now.Month;
                value.batchNo   = value.batchNo + "_" + getLoanType.Description;
                databasetenure  = Int32.Parse(getLoanType.Tenure);

                if (databasetenure != Int32.Parse(value.Tenure))
                {
                    remarks += "|Incorrect Loan Tenure Supplied" + "_" + Int32.Parse(value.Tenure);
                }


                //check eligibility
                decimal amountYOUcantake = unitOfWork.loanRegisterRepository.loanAmountPerRankBy2(getPersonId.rank, getLoanType.Code).Result;

                if (value.Amount > amountYOUcantake)
                {
                    remarks += "|You can not take more than" + "_" + amountYOUcantake;
                }
                value.remarks += remarks;

                if (remarks != "")
                {
                    value.Status = "2";
                }

                unitOfWork.loanRegisterRepository.Create(value);
                unitOfWork.Done().Wait();

                return(Ok(new { responseCode = 200, responseDescription = "Created Successfully" }));
            }
            catch (Exception ex)
            {
                return(Ok(new { responseCode = 500, responseDescription = "Failed" }));
            }
        }