public ActionResult SaveLoanPreClose(string LoanMasterId)
        {
            MemberLoanClosure memberLoanClosure = new MemberLoanClosure();
            int ID = string.IsNullOrEmpty(LoanMasterId.DecryptString()) ? default(int) : Convert.ToInt32(LoanMasterId.DecryptString());
            var memberLoanDisbursement = _memberloanapplicationService.GetMemberLoanDisbursementDetailsById(ID, UserInfo.UserID);

            LoadDropDowns();
            memberLoanClosure = _memberloanapplicationService.GetLoanClosureDemands(ID, GroupInfo.MeetingDate);
            List <GroupMemberDemandDto> lstDemands = new List <GroupMemberDemandDto>();

            lstDemands = _groupMemberReceiptService.GetTransactionDemands(Convert.ToString(GroupInfo.MeetingDate), memberLoanDisbursement.MemberID);
            var lstloanDemands = lstDemands.Where(x => x.LoanMasterId == ID).ToList();
            GroupMemberReceiptDto _grpMbrRecptDto = new GroupMemberReceiptDto();

            try
            {
                ViewBag.LockStatus = GroupInfo.LockStatus;
                _grpMbrRecptDto.AccountMasterID = memberLoanDisbursement.AccountMasterId;
                _grpMbrRecptDto.TransactionMode = "C";


                _grpMbrRecptDto.TransactionDate = GroupInfo.MeetingDate;

                _grpMbrRecptDto.VoucherRefNumber = memberLoanDisbursement.PaymentVoucherNumber;
                _grpMbrRecptDto.CollectionAgent  = 0;


                _grpMbrRecptDto.TotalAmount = memberLoanClosure.InterestDemand + memberLoanClosure.PrincipleDemand;

                _grpMbrRecptDto.MemberId  = memberLoanDisbursement.MemberID;
                _grpMbrRecptDto.Narration = "Loan Pre Closing";

                //Transactions Read
                _grpMbrRecptDto.Transactions = new List <GroupMemberReceiptTranDto>();
                foreach (var memberdemand in lstloanDemands)
                {
                    GroupMemberReceiptTranDto objTran = null;
                    objTran                 = new GroupMemberReceiptTranDto();
                    objTran.SLAccountId     = memberdemand.SLAhId;
                    objTran.GLAccount       = memberdemand.GLAhName;
                    objTran.SLAccount       = memberdemand.SLAhName;
                    objTran.ReferenceNumber = "RefCloser";
                    objTran.SubAhId         = memberdemand.SubAhId;
                    objTran.Amount          = memberLoanClosure.PrincipleDemand;
                    objTran.InterestDue     = 0;
                    _grpMbrRecptDto.Transactions.Add(objTran);
                }
                //Save
                int       GroupId   = GroupInfo.GroupID;
                ResultDto resultDto = _groupMemberReceiptService.AddUpdateMemberReceipt(_grpMbrRecptDto, UserInfo.UserID, GroupId);
                _grpMbrRecptDto.VoucherNumber   = resultDto.ObjectCode;
                _grpMbrRecptDto.AccountMasterID = resultDto.ObjectId;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(View());
        }
        public ActionResult CreateGroupMemberReceipt(FormCollection form)
        {
            GroupMemberReceiptDto _grpMbrRecptDto = new GroupMemberReceiptDto();

            try
            {
                ViewBag.LockStatus = GroupInfo.LockStatus;
                _grpMbrRecptDto.AccountMasterID = Convert.ToInt32(Request.Form["AccountMasterID"]);
                _grpMbrRecptDto.TransactionMode = Convert.ToString(Request.Form["TransactionMode"]);

                string   tranDate   = _grpMbrRecptDto.TransactionMode == "C" ? Request.Form["TransactionDate"] : Request.Form["txtTransactionDate"];
                DateTime dtTranDate = tranDate.ConvertToDateTime();
                _grpMbrRecptDto.TransactionDate = dtTranDate;

                _grpMbrRecptDto.VoucherRefNumber = Convert.ToString(Request.Form["VoucherRefNumber"]);
                _grpMbrRecptDto.CollectionAgent  = Convert.ToInt32(Request.Form["CollectionAgent"]);

                if (_grpMbrRecptDto.TransactionMode == "BC")
                {
                    _grpMbrRecptDto.ChequeNumber = Convert.ToString(Request.Form["ChequeNumber"]);
                    _grpMbrRecptDto.ChequeDate   = Request.Form["ChequeDate"].ConvertToDateTime();
                }
                _grpMbrRecptDto.TotalAmount = Convert.ToDecimal(Request.Form["hdnTotalAmount"]);
                if (_grpMbrRecptDto.TransactionMode != "C")
                {
                    _grpMbrRecptDto.BankEntryId = Convert.ToInt32(Request.Form["BankEntryId"]);
                }
                _grpMbrRecptDto.MemberId  = Convert.ToInt32(Request.Form["MemberId"]);
                _grpMbrRecptDto.Narration = Convert.ToString(Request.Form["Narration"]);

                //Transactions Read
                _grpMbrRecptDto.Transactions = new List <GroupMemberReceiptTranDto>();

                int maxCount = Convert.ToInt32(Request.Form["hdnMaxTranCount"]);
                GroupMemberReceiptTranDto objTran = null;
                for (int index = 1; index < maxCount; index++)
                {
                    objTran                 = new GroupMemberReceiptTranDto();
                    objTran.SLAccountId     = Convert.ToInt32(Request.Form["hdnSlAccountID_" + index]);
                    objTran.GLAccount       = Convert.ToString(Request.Form["hdnGlAccount_" + index]);
                    objTran.SLAccount       = Convert.ToString(Request.Form["hdnSlAccount_" + index]);
                    objTran.ReferenceNumber = Convert.ToString(Request.Form["hdnRefNumber_" + index]);
                    decimal expectedDemand = default(decimal);
                    decimal.TryParse(Request.Form["hdnexpectedamount_" + index], out expectedDemand);
                    int subAhId = default(int);
                    int.TryParse(Request.Form["hdnSubAHID_" + index], out subAhId);
                    objTran.SubAhId = subAhId;

                    objTran.Amount = Convert.ToDecimal(Request.Form["CrAmount_" + index]);
                    if (objTran.SLAccount.ToUpper().Contains("SERVICE COST") && objTran.Amount < expectedDemand)
                    {
                        objTran.InterestDue = expectedDemand - objTran.Amount;
                    }
                    if (objTran.SLAccount.ToUpper().Contains("LOAN") && objTran.Amount < expectedDemand && !(objTran.SLAccount.ToUpper().Contains("SERVICE COST")))
                    {
                        objTran.PrincipleDue = expectedDemand - objTran.Amount;
                    }
                    _grpMbrRecptDto.Transactions.Add(objTran);
                }

                //Save
                int       GroupId   = GroupInfo.GroupID;
                ResultDto resultDto = _groupMemberReceiptService.AddUpdateMemberReceipt(_grpMbrRecptDto, UserInfo.UserID, GroupId);
                _grpMbrRecptDto.VoucherNumber   = resultDto.ObjectCode;
                _grpMbrRecptDto.AccountMasterID = resultDto.ObjectId;

                LoadMemberReceiptDropDowns();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(View(_grpMbrRecptDto));
        }