protected void lvLoanInterestedRate_ItemInserting(object sender, ListViewInsertEventArgs e)
        {
            NewLoanInterestedKeyRepository facade = new NewLoanInterestedKeyRepository();
            StoreProRepository storeFacade = new StoreProRepository();

            RadNumericTextBox monthRate = (lvLoanInterestedRate.InsertItem.FindControl("radMonthRate")) as RadNumericTextBox;
            TextBox rateDisplay = (lvLoanInterestedRate.InsertItem.FindControl("tbRateDisplay")) as TextBox;
            RadNumericTextBox rnbVNDRate = (lvLoanInterestedRate.InsertItem.FindControl("rnbVNDRate")) as RadNumericTextBox;
            RadNumericTextBox rnbUSDRate = (lvLoanInterestedRate.InsertItem.FindControl("rnbUSDRate")) as RadNumericTextBox;

            if ((Int16)monthRate.Value <= 0)
            {
                RadWindowManager1.RadAlert("Deposite Rate is required!", 340, 150, "Alert", null);
                return;
            }

            BLOANINTEREST_KEY intKey = new BLOANINTEREST_KEY();
            intKey.MonthLoanRateNo = (Int16)monthRate.Value;
            intKey.USD_InterestRate = (decimal)rnbUSDRate.Value;
            intKey.VND_InterestRate = (decimal)rnbVNDRate.Value;
            intKey.LoanInterest_Key = rateDisplay.Text;
            intKey.Id = (Int16)monthRate.Value;
            storeFacade.StoreProcessor().B_LoanInterested_Key_history_process(intKey.MonthLoanRateNo, intKey.VND_InterestRate, intKey.USD_InterestRate, this.UserId, 1);

            facade.Add(intKey);
            facade.Commit();
            LoadDataTolvLoanInterestedRate();
        }
        protected void lvLoanInterestedRate_ItemUpdating(object sender, ListViewUpdateEventArgs e)
        {
            NewLoanInterestedKeyRepository facade = new NewLoanInterestedKeyRepository();
            StoreProRepository storeFacade = new StoreProRepository();

            RadNumericTextBox monthRate = (lvLoanInterestedRate.EditItem.FindControl("radMonthRate")) as RadNumericTextBox;
            TextBox rateDisplay = (lvLoanInterestedRate.EditItem.FindControl("tbRateDisplay")) as TextBox;
            RadNumericTextBox rnbVNDRate = (lvLoanInterestedRate.EditItem.FindControl("rnbVNDRate")) as RadNumericTextBox;
            RadNumericTextBox rnbUSDRate = (lvLoanInterestedRate.EditItem.FindControl("rnbUSDRate")) as RadNumericTextBox;
            Label lbl = (lvLoanInterestedRate.Items[e.ItemIndex].FindControl("lbID")) as Label;
            String ids = "";
            if (lbl != null)
                ids = lbl.Text;

            BLOANINTEREST_KEY intKey = new BLOANINTEREST_KEY();
            intKey.MonthLoanRateNo = (Int16)monthRate.Value;
            intKey.USD_InterestRate = (decimal)rnbUSDRate.Value;
            intKey.VND_InterestRate = (decimal)rnbVNDRate.Value;
            intKey.LoanInterest_Key = rateDisplay.Text;
            intKey.Id = Int32.Parse(ids);

            BLOANINTEREST_KEY exits = facade.GetById(intKey.Id);
            if (exits != null)
            {
                storeFacade.StoreProcessor().B_LoanInterested_Key_history_process(intKey.MonthLoanRateNo, intKey.VND_InterestRate, intKey.USD_InterestRate, this.UserId, 2);
                facade.Update(facade.GetById(intKey.Id), intKey);
                facade.Commit();
            }
            lvLoanInterestedRate.EditIndex = -1;
            LoadDataTolvLoanInterestedRate();
        }
        protected void lvRateExchange_ItemUpdating(object sender, ListViewUpdateEventArgs e)
        {
            ExchangeRatesRepository facade = new ExchangeRatesRepository();
            StoreProRepository storeFacade = new StoreProRepository();

            TextBox tbcurrency = (lvRateExchange.EditItem.FindControl("tbCurrency")) as TextBox;
            RadNumericTextBox rnbVNDRate = (lvRateExchange.EditItem.FindControl("rnbVNDRate")) as RadNumericTextBox;
            Label lbl = (lvRateExchange.Items[e.ItemIndex].FindControl("lbID")) as Label;
            String ids = "";
            if (lbl != null)
                ids = lbl.Text;

            B_ExchangeRates exchangeRate = new B_ExchangeRates();
            exchangeRate.Rate = (decimal)rnbVNDRate.Value;
            exchangeRate.Currency = tbcurrency.Text;
            exchangeRate.Id = Int32.Parse(ids);

            B_ExchangeRates exits = facade.GetById(exchangeRate.Id);
            if (exits != null)
            {
                storeFacade.StoreProcessor().B_ExchangeRate_history_process(exchangeRate.Currency, exchangeRate.Rate, this.UserId, 2);
                facade.Update(facade.GetById(exchangeRate.Id), exchangeRate);
                facade.Commit();
            }
            lvRateExchange.EditIndex = -1;
            LoadDataTolvRateExchange();
        }
        protected void lvRateExchange_ItemInserting(object sender, ListViewInsertEventArgs e)
        {
            ExchangeRatesRepository facade = new ExchangeRatesRepository();
            StoreProRepository storeFacade = new StoreProRepository();

            TextBox tbcurrency = (lvRateExchange.InsertItem.FindControl("tbCurrency")) as TextBox;
            RadNumericTextBox rnbVNDRate = (lvRateExchange.InsertItem.FindControl("rnbVNDRate")) as RadNumericTextBox;

            B_ExchangeRates exchangeRate = new B_ExchangeRates();

            exchangeRate.Rate = (decimal)rnbVNDRate.Value;
            exchangeRate.Currency = tbcurrency.Text;
            storeFacade.StoreProcessor().B_ExchangeRate_history_process(exchangeRate.Currency, exchangeRate.Rate, this.UserId, 1);

            facade.Add(exchangeRate);
            facade.Commit();
            LoadDataTolvRateExchange();
        }
        protected void lvLoanInterestedRate_ItemDeleting(object sender, ListViewDeleteEventArgs e)
        {
            String ids = "";
            Label lbl = (lvLoanInterestedRate.Items[e.ItemIndex].FindControl("lbID")) as Label;
            if (lbl != null)
                ids = lbl.Text;

            if (!String.IsNullOrEmpty(ids))
            {
                StoreProRepository storeFacade = new StoreProRepository();
                NewLoanInterestedKeyRepository facade = new NewLoanInterestedKeyRepository();
                var itm = facade.GetById(Int16.Parse(ids));
                if (itm != null)
                {
                    storeFacade.StoreProcessor().B_LoanInterested_Key_history_process(itm.MonthLoanRateNo, itm.VND_InterestRate, itm.USD_InterestRate, this.UserId, 3);
                    facade.Delete(itm);
                    facade.Commit();
                    LoadDataTolvLoanInterestedRate();
                }

            }
        }
        protected void lvRateExchange_ItemDeleting(object sender, ListViewDeleteEventArgs e)
        {
            String ids = "";
            Label lbl = (lvRateExchange.Items[e.ItemIndex].FindControl("lbID")) as Label;
            if (lbl != null)
                ids = lbl.Text;

            if (!String.IsNullOrEmpty(ids))
            {
                StoreProRepository storeFacade = new StoreProRepository();
                ExchangeRatesRepository facade = new ExchangeRatesRepository();
                var itm = facade.GetById(Int16.Parse(ids));
                if (itm != null)
                {
                    storeFacade.StoreProcessor().B_ExchangeRate_history_process(itm.Currency, itm.Rate, this.UserId, 3);
                    facade.Delete(itm);
                    facade.Commit();
                    LoadDataTolvRateExchange();
                }

            }
        }
 protected void btCalcu_Click(object sender, EventArgs e)
 {
     StoreProRepository facade = new StoreProRepository();
     facade.StoreProcessor().B_Normal_Loan_Process_Payment(dtpDate.SelectedDate);
 }
        public void UpdateDataToPriciplePaymentSchedule(BNEWNORMALLOAN normalLoanEntryM, int replaymentTime, int userID)
        {
            NormalLoanPaymentSchedule facde = new NormalLoanPaymentSchedule();
            var ds = PrepareDataForLoanContractSchedule(normalLoanEntryM, replaymentTime);
            DataTable dtInfor = ds.DtInfor;
            DataTable dtItems = ds.DtItems;

            if (dtInfor == null || dtItems == null)
            {
                return;
            }
            facde.DeleteAllScheduleOfContract(dtInfor.Rows[0]["Code"].ToString(), replaymentTime);

            foreach (DataRow it in dtItems.Rows)
            {
                B_NORMALLOAN_PAYMENT_SCHEDULE princleSchedue = new B_NORMALLOAN_PAYMENT_SCHEDULE();
                princleSchedue.Code = dtInfor.Rows[0]["Code"].ToString();
                princleSchedue.CustomerID = dtInfor.Rows[0]["CustomerID"].ToString();
                princleSchedue.LoanAmount = decimal.Parse((dtInfor.Rows[0]["LoanAmount"].ToString().Replace(",", "")));
                princleSchedue.Drawdown = String.IsNullOrEmpty(dtInfor.Rows[0]["Drawdown"].ToString()) ? this.disbursalDate : (DateTime)dtInfor.Rows[0]["Drawdown"];
                princleSchedue.InterestKey = dtInfor.Rows[0]["InterestKey"].ToString();
                princleSchedue.Freq = dtInfor.Rows[0]["Freq"].ToString();
                princleSchedue.PeriodRepaid = replaymentTime;
                princleSchedue.Interest = (Decimal)dtInfor.Rows[0]["interest"];

                princleSchedue.Period = (Int16)it["Perios"];
                princleSchedue.DueDate = (DateTime)it["DueDate"];
                princleSchedue.PrincipalAmount = (Decimal)it["Principle"];
                princleSchedue.PrinOS = (Decimal)it["PrinOS"];
                princleSchedue.InterestAmount = (Decimal)it["InterestAmount"];
                princleSchedue.CreateBy = userID;
                princleSchedue.CreateDate = facde.GetSystemDatetime();
                facde.Add(princleSchedue);

            }
            facde.Commit();

            StoreProRepository storeFacase = new StoreProRepository();
            storeFacase.StoreProcessor().B_Normal_Loan_Process_Payment_AmendAuthorizeProcess(dtInfor.Rows[0]["Code"].ToString(), replaymentTime);
        }
 private string generateCode()
 {
     VietVictoryCoreBankingEntities bd = new VietVictoryCoreBankingEntities();
     StoreProRepository storePro = new StoreProRepository();
     return storePro.StoreProcessor().B_BMACODE_GetNewID("CRED_REVOLVING_CONTRACT", REFIX_MACODE, ".").First<string>();
 }
        private void processDebitCashRepayment()
        {
            StoreProRepository facade = new StoreProRepository();
            CashRepaymentRepository cashFacade = new CashRepaymentRepository();
            if (normalLoanEntryM != null && !String.IsNullOrEmpty(normalLoanEntryM.CreditAccount))
            {
                var cashRepay = cashFacade.FindActiveCashRepayment(normalLoanEntryM.CreditAccount).FirstOrDefault();
                if (cashRepay != null && cashRepay.AmountDeposited != null)
                {
                    facade.StoreProcessor().B_Normal_Loan_CashRepayment_Subtract_To_Account(normalLoanEntryM.CreditAccount, cashRepay.AmountDeposited, normalLoanEntryM.Code, this.UserId);

                }
            }
        }
        private void LoadRemainLoanAmount()
        {
            StoreProRepository facade = new StoreProRepository();
            CashRepaymentRepository cashFacade = new CashRepaymentRepository();
            double remainAmount = 0;
            var amt = facade.StoreProcessor().B_Normal_Loan_GetRemainLoanAmount(tbNewNormalLoan.Text).FirstOrDefault();
            remainAmount = amt == null ? 0 : (double)amt;

            if(normalLoanEntryM!=null && !String.IsNullOrEmpty(normalLoanEntryM.CreditAccount)){
                var cashRepay = cashFacade.FindActiveCashRepayment(normalLoanEntryM.CreditAccount).FirstOrDefault();

                if (cashRepay != null && cashRepay.AmountDeposited != null)
                {
                    remainAmount = remainAmount - (cashRepay.AmountDeposited == null ? 0 : (double)cashRepay.AmountDeposited);
                }

            }

            tbOutstandingAmount.Value = remainAmount;
        }
 private void LoadMainCategoryCombobox(string selectedItem)
 {
     StoreProRepository storeFacade = new StoreProRepository();
     var db = storeFacade.StoreProcessor().B_BRPODCATEGORY_GetAll_IdOver200().ToList();
     Util.LoadData2RadCombo(radcbMainCategory, db, "CatId", "Display", "-Select Main Category-", false);
     radcbMainCategory.SelectedValue = selectedItem;
 }
        //private void LoadCustomerCombobox(string SelectedCus)
        //{
        //    BCustomerRepository facade1 = new BCustomerRepository();
        //    var db = facade1.getCustomerList("AUT");
        //    List<BCUSTOMER_INFO> hh = db.ToList<BCUSTOMER_INFO>();
        //    Util.LoadData2RadCombo(rcbCustomerID, hh, "CustomerID", "ID_FullName", "-Select Customer Code-", false);
        //    if (!String.IsNullOrEmpty(SelectedCus))
        //    {
        //        rcbCustomerID.SelectedValue = SelectedCus;
        //    }
        //}
        void LoadAllAccount(string custID, string currency, string credit, string printRep, string inRep, string chagreRep)
        {
            StoreProRepository storeFacade = new StoreProRepository();
            var ds = storeFacade.StoreProcessor().BOPENACCOUNT_LOANACCOUNT_GetByCode(custID, currency).ToList();

            //Database.BOPENACCOUNT_LOANACCOUNT_GetByCode(name, currency);
            Util.LoadData2RadCombo(rcbCreditToAccount, ds, "Id", "Display", "-Select a credit Account-", true);

            if (!String.IsNullOrEmpty(credit))
            {
                rcbCreditToAccount.SelectedValue = credit;
            }
        }
        private bool isCurrentAmountEnoughtForRequestCash()
        {
            StoreProRepository facade = new StoreProRepository();
            CashRepaymentRepository cashFacade = new CashRepaymentRepository();
            decimal AccRemainAmount = 0;

            if (normalLoanEntryM != null && !String.IsNullOrEmpty(normalLoanEntryM.CreditAccount))
            {
                var cashRepay = cashFacade.FindActiveCashRepayment(normalLoanEntryM.CreditAccount).FirstOrDefault();

                AccRemainAmount = (decimal)facade.StoreProcessor().B_Normal_Loan_Account_GetCurrentAmount(normalLoanEntryM.CreditAccount).FirstOrDefault();

                if (cashRepay != null && cashRepay.AmountDeposited != null)
                {
                    if (AccRemainAmount < cashRepay.AmountDeposited)
                    {
                        return false;
                    }
                }
            }
            else
            {
                return false;
            }
            return true;
        }
 private string generateCode()
 {
     StoreProRepository storePro = new StoreProRepository();
     return storePro.StoreProcessor().B_BMACODE_GetNewID("SALARY_PAYMENT", "TT", ".").First<string>();
 }
        protected void LoadCreditAccount()
        {
            StoreProRepository facade = new StoreProRepository();

            comboCreditAcct.Items.Clear();
            comboCreditAcct.Items.Add(new RadComboBoxItem(""));
            comboCreditAcct.DataValueField = "Id";
            comboCreditAcct.DataTextField = "Id";
            comboCreditAcct.DataSource = bd.SQLData.B_BCRFROMACCOUNT_GetByCurrency_Name(txtDrawerCusName.Text, comboCreditCurrency.SelectedValue);
            //comboCreditAcct.DataSource = facade.StoreProcessor().B_BCRFROMACCOUNT_GetByCurrency_Name(txtDrawerCusName.Text, comboCreditCurrency.SelectedValue).ToList();
            comboCreditAcct.DataBind();
        }
 private void CalcRemainDisbursalLoanAmount()
 {
     StoreProRepository facade = new StoreProRepository();
     decimal planAmount = tbLoanAmount.Text != "" ? decimal.Parse(tbLoanAmount.Text) : 0;
     var rus = facade.StoreProcessor().B_LOAN_DISBURSAL_SCHEDULE_Get_Total_LoanAmount(tbNewNormalLoan.Text).First<double?>();
     this.remainLoanAmountDis = rus == null ? 0 : (double)rus;
     remainLoanAmountDis = ((double)planAmount - remainLoanAmountDis);
 }