using System; using CoreSavingLibrary; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; //using CoreSavingLibrary.WcfNShrlon; using CoreSavingLibrary.WcfNShrlon; using Sybase.DataWindow; using System.Web.Services.Protocols; using DataLibrary; using System.Data; using System.Globalization; namespace Saving.Applications.shrlon.dlg { public partial class w_dlg_loanreqedit : PageWebDialog, WebDialog { public String lc_loantype = null; public int ii_righttype; public int ii_apvtype; public string is_massalert = ""; //เก็บข้อความเตือน public Boolean ibl_step = true; //ใช้ตรวจสอบการดึง dlg ประเภท ดูจากหลักประกัน ดูจากเงินฝาก private DwThDate tDwMain; private DwThDate tDwperiodpay; //*******ประกาศตัวเกี่ยวกับ Javascript********// protected string jsPostmember; protected string jsPostSetPeriodSend; protected string jsPostSumClear; protected string jsPostSetPeriodPay; protected string jsPostChangePeriodPay; protected string jsPostRePermiss; protected string jsPostRightColl; protected String jsExpenseBank; protected String jsExpenseCode; protected String jsGetMemberCollno; protected String jsReNewPage; protected String jsOpenOldDocNo; protected String jsPostSetZero; protected String jsCancelRequest; protected String jsRefresh; protected String jsSetDataList; protected string jsSetloantypechg; protected string jsPostDelOtherclr; protected string jsExpensebankbrRetrieve; protected string jsGetitemdescetc; protected string jsGetexpensememno; protected string jsPostGetCollPermiss; protected string jsPostRequestamt; protected string jsPostDelMthexp; protected string jsGetitemdescmthexp; protected string jsPostPrtRpt; protected string jsPostCalInt; protected string jsPostExpireperiod_date; protected string jsPostprincipal_payment; string[] loans; string reqdoc_no = ""; String member_no = ""; int x = 1; string loanrequest_docno = ""; private n_shrlonClient shrlonService; String ls_membtype = ""; String loantype = ""; String pbl = "sl_req_gsbspc.pbl"; private int flag;//ตรวจสอบการดึงข้อมูล Sdt dt; Sta ta; int currentLoan = 1; /// /// Check Init Javascript /// public void InitJsPostBack() { jsPostmember = WebUtil.JsPostBack(this, "jsPostmember"); jsPostSetPeriodSend = WebUtil.JsPostBack(this, "jsPostSetPeriodSend"); jsPostSumClear = WebUtil.JsPostBack(this, "jsPostSumClear"); jsPostSetPeriodPay = WebUtil.JsPostBack(this, "jsPostSetPeriodPay"); jsPostChangePeriodPay = WebUtil.JsPostBack(this, "jsPostChangePeriodPay"); jsPostRePermiss = WebUtil.JsPostBack(this, "jsPostRePermiss"); jsPostRightColl = WebUtil.JsPostBack(this, "jsPostRightColl"); jsGetexpensememno = WebUtil.JsPostBack(this, "jsGetexpensememno"); jsExpenseCode = WebUtil.JsPostBack(this, "jsExpenseCode"); jsExpenseBank = WebUtil.JsPostBack(this, "jsExpenseBank"); jsGetMemberCollno = WebUtil.JsPostBack(this, "jsGetMemberCollno"); jsReNewPage = WebUtil.JsPostBack(this, "jsReNewPage"); jsOpenOldDocNo = WebUtil.JsPostBack(this, "jsOpenOldDocNo"); jsPostSetZero = WebUtil.JsPostBack(this, "jsPostSetZero"); jsCancelRequest = WebUtil.JsPostBack(this, "jsCancelRequest"); jsRefresh = WebUtil.JsPostBack(this, "jsRefresh"); jsSetDataList = WebUtil.JsPostBack(this, "jsSetDataList"); jsPostDelOtherclr = WebUtil.JsPostBack(this, "jsPostDelOtherclr"); jsSetloantypechg = WebUtil.JsPostBack(this, "jsSetloantypechg"); jsExpensebankbrRetrieve = WebUtil.JsPostBack(this, "jsExpensebankbrRetrieve"); jsPostGetCollPermiss = WebUtil.JsPostBack(this, "jsPostGetCollPermiss"); jsGetitemdescetc = WebUtil.JsPostBack(this, "jsGetitemdescetc"); jsPostRequestamt = WebUtil.JsPostBack(this, "jsPostRequestamt"); jsPostDelMthexp = WebUtil.JsPostBack(this, "jsPostDelMthexp"); jsGetitemdescmthexp = WebUtil.JsPostBack(this, "jsGetitemdescmthexp"); jsPostPrtRpt = WebUtil.JsPostBack(this, "jsPostPrtRpt"); jsPostCalInt = WebUtil.JsPostBack(this, "jsPostCalInt"); jsPostExpireperiod_date = WebUtil.JsPostBack(this, "jsPostExpireperiod_date"); jsPostprincipal_payment = WebUtil.JsPostBack(this, "jsPostprincipal_payment"); tDwMain = new DwThDate(dw_main, this); tDwMain.Add("loanrequest_date", "loanrequest_tdate"); tDwMain.Add("loanrcvfix_date", "loanrcvfix_tdate"); tDwperiodpay = new DwThDate(dw_periodpay, this); tDwperiodpay.Add("expireperiod_date", "expireperiod_tdate"); } public void WebDialogLoadBegin() { this.ConnectSQLCA(); ta = new Sta(sqlca.ConnectionString); sqlca = new DwTrans(); sqlca.Connect(); try { shrlonService = wcf.NShrlon; } catch { LtServerMessage.Text = WebUtil.ErrorMessage("ติดต่อ Web Service ไม่ได้"); return; } if (IsPostBack) { this.RestoreContextDw(dw_main); this.RestoreContextDw(dw_coll); this.RestoreContextDw(dw_clear); this.RestoreContextDw(dw_otherclr); this.RestoreContextDw(dw_periodpay); LtServerMessagecoll.Text = ""; } else { JsReNewPage(); HdShowRemark.Value = "false"; } if (dw_main.RowCount > 1) { dw_main.DeleteRow(dw_main.RowCount); } dw_message.Reset(); dw_message.InsertRow(0); dw_message.DisplayOnly = false; dw_message.Visible = false; HdCheckRemark.Value = "false"; // Panel1.Visible = true; loans = Request["loanrequest_docno"].Split(','); string oo = (currentLoan + 1) + "/" + loans.Length; string loan = loans[currentLoan]; int fixCode = 0; fixCode = loan.IndexOf("@"); loanrequest_docno = loan.Substring(0, fixCode); DwUtil.RetrieveDataWindow(dw_main,pbl,null, state.SsCoopId, loanrequest_docno); DwUtil.RetrieveDDDW(dw_main, "membtype_code", pbl); JsPostmember(); } /// /// Check PostBack Javascript /// /// public void CheckJsPostBack(string eventArg) { if (eventArg == "jsPostmember") { JsPostmember(); // clear_periodpayment(); //JsPostmember(); of_calperiodpayment(); of_initclearshare(); //of_Setperiodpaydet(); CalSumTotal(); } else if (eventArg == "jsPostSetPeriodSend") { of_initperiodsend(); of_calperiodpayment(); } else if (eventArg == "jsPostprincipal_payment") { string str_ref = ""; str_ref = Hdmthexprow.Value; int row = Convert.ToInt32(str_ref); Decimal principal_payment = 0, loanrequest_amt = 0, period = 0, principal_payment2=0; principal_payment = dw_periodpay.GetItemDecimal(row, "principal_payment"); loanrequest_amt = dw_main.GetItemDecimal(1, "loanrequest_amt"); period = dw_main.GetItemDecimal(1, "period_payamt"); //loanrequest_amt = loanrequest_amt - principal_payment; //principal_payment2 = loanrequest_amt / (period - 1); dw_main.SetItemDecimal(1, "period_payment", dw_periodpay.GetItemDecimal(1, "principal_payment")); for (int j = 1; j < row; j++) { principal_payment += dw_periodpay.GetItemDecimal(j, "principal_payment"); } loanrequest_amt = loanrequest_amt - principal_payment; principal_payment2 = loanrequest_amt / (period - row); for (int i = row; i < period; i++) { dw_periodpay.SetItemDecimal(i + 1, "principal_payment", principal_payment2); } } else if (eventArg == "jsPostExpireperiod_date") { try { CultureInfo th = System.Globalization.CultureInfo.GetCultureInfo("th-TH"); String dayss = dw_periodpay.GetItemString(1, "expireperiod_tdate"); DateTime today = DateTime.ParseExact(dayss, "ddmmyyyy", CultureInfo.InvariantCulture); decimal period_amt = 0, loanrequest_amt = 0; period_amt = dw_main.GetItemDecimal(1, "period_payamt"); loanrequest_amt = dw_main.GetItemDecimal(1, "loanrequest_amt"); DateTime end_date2 = today.AddYears((Convert.ToInt16(period_amt-1))); dw_main.SetItemString(1, "loanrcvfix_tdate", (end_date2).ToString("ddMMyyyy")); dw_main.SetItemDecimal(1, "loanrcvfix_flag", 1); if (loanrequest_amt <= 0) { return; } Decimal rowp = dw_periodpay.RowCount; int rowpint = 0; decimal period_payment = dw_main.GetItemDecimal(1, "period_payment"); decimal sumpay = 0; rowp = dw_periodpay.RowCount; for (int ii = 1; ii <= rowp; ii++) { sumpay = loanrequest_amt - period_payment; DateTime end_date = today.AddYears((ii-1)); if (loanrequest_amt < period_payment) { period_payment = loanrequest_amt; } dw_periodpay.SetItemDecimal(ii, "period", Convert.ToDecimal(ii)); // dw_periodpay.SetItemDecimal(ii, "principal_payment", period_payment); dw_periodpay.SetItemString(ii, "expireperiod_tdate", (end_date).ToString("ddMMyyyy")); dw_periodpay.SetItemDateTime(ii, "expireperiod_date", end_date); } }catch(Exception ){ } } else if (eventArg == "jsPostSumClear") { of_initpaymonthcoop(); of_initpermiss(); of_calperiodpayment(); of_initotherpay_fsv(); // of_initclearshare(); of_recalcollpermiss(); of_initwarnings(); CalSumTotal(); } else if (eventArg == "jsPostSetPeriodPay")//ระบุ จำนวน งวด { dw_periodpay.Reset(); // clear_periodpayment(); of_calperiodpayment(); of_initclearshare(); of_Setperiodpaydet(); CalSumTotal(); //for (int i = 0; i < 1; i++) //{ // dw_coll.InsertRow(0); //} } else if (eventArg == "jsPostRequestamt") // ยอดขอกู้ { // of_setintestimateloanreq(); // DwUtil.RetrieveDataWindow(dw_main, pbl, null, state.SsCoopId, loanrequest_docno); dw_periodpay.Reset(); decimal ldc_reqamt = dw_main.GetItemDecimal(1, "loanreqregis_amt"); //pom string ls_loantype = dw_main.GetItemString(1, "loantype_Code"); //pom of_initmaxperiod(ls_loantype, ldc_reqamt); //pom of_initperiodsend(); of_lastperiodpay(); of_calperiodpayment(); of_initclearshare(); of_Setperiodpaydet(); string member_no = dw_main.GetItemString(1, "member_no"); of_initloanclr(member_no); of_initloancredit(ls_loantype); if (ibl_step == true) { of_initreqloanregis(member_no, ls_loantype); of_initpaymonthcoop(); of_initpermiss(); of_initotherpay_fsv(); of_initwarnings(); //of_initcolluse(); } CalSumTotal(); } else if (eventArg == "jsPostChangePeriodPay") { int li_maxsend = 0; decimal li_period = 0; decimal ldc_salarybal = 0, ldc_periodpay = 0, ldc_minsalary; li_maxsend = Convert.ToInt32(dw_main.GetItemDecimal(1, "maxsend_payamt")); // decimal ldc_salary = dw_main.GetItemDecimal(1, "salary_amt"); decimal ldc_incomefixed = dw_main.GetItemDecimal(1, "incomemonth_fixed"); decimal ldc_incomeoth = dw_main.GetItemDecimal(1, "incomemonth_other"); decimal ldc_paycoop = dw_main.GetItemDecimal(1, "paymonth_coop"); decimal ldc_paylnreq = dw_main.GetItemDecimal(1, "paymonth_lnreq"); decimal ldc_payexp = dw_main.GetItemDecimal(1, "paymonth_exp"); decimal ldc_payoth = dw_main.GetItemDecimal(1, "paymonth_other"); decimal loanrequest_amt = dw_main.GetItemDecimal(1, "loanrequest_amt"); ldc_periodpay = dw_main.GetItemDecimal(1, "period_payment"); ldc_minsalary = dw_main.GetItemDecimal(1, "minsalary_amt"); int li_payflag = Convert.ToInt32(dw_main.GetItemDecimal(1, "custompayment_flag")); if (li_payflag == 1) { return; } li_period = dw_main.GetItemDecimal(1, "period_payamt"); int ii = 1; // for (int ii = 1; ii <= li_period; ii++) do { loanrequest_amt = loanrequest_amt - ldc_periodpay; dw_periodpay.SetItemDecimal(ii, "principal_payment", ldc_periodpay); ii++; } while (ii < li_period); int period = Convert.ToInt32(li_period); dw_periodpay.SetItemDecimal(period, "principal_payment", loanrequest_amt ); //if (li_period > li_maxsend) //{ // dw_main.SetItemDecimal(1, "period_payment", Convert.ToDecimal(Hdperiodpay.Value)); // LtServerMessage.Text = WebUtil.ErrorMessage("ชำระ/งวด น้อยเกินไป ทำให้จำนวนงวดเกิน งวดที่สามารถส่งได้"); // return; //} //else //{ //decimal ldc_loanreq = dw_main.GetItemDecimal(1, "loanrequest_amt"); //dw_main.SetItemDecimal(1, "period_payamt", li_period); //dw_main.SetItemDecimal(1, "period_payment", 1); //of_setpaymthlnreq(); // } // } CalSumTotal(); } else if (eventArg == "jsPostRePermiss") { of_initpermiss(); of_calperiodpayment(); of_initclearshare(); } else if (eventArg == "jsPostRightColl") { try { string ls_loantype = dw_main.GetItemString(1, "loantype_code"); string ls_membno = dw_main.GetItemString(1, "member_no"); string ls_coll = Hdcoll.Value; string ls_contclr = Hdcontclr.Value; string[] larr_contclr = ls_contclr.Split(','); for (int r = 0; r < larr_contclr.Length; r++) { for (int row = 1; row <= dw_clear.RowCount; row++) { string ls_contno = dw_clear.GetItemString(row, "loancontract_no"); if (ls_contno == larr_contclr[r]) { dw_clear.SetItemDecimal(row, "clear_status", 1); } } } of_initreqloanregis(ls_membno, ls_loantype); decimal ldc_maxreq = dw_main.GetItemDecimal(1, "loanreqregis_amt"); //pom of_initmaxperiod(ls_loantype, ldc_maxreq); //pom of_initpaymonthcoop(); of_initperiodsend(); of_initpermiss(); string[] larr_coll = ls_coll.Split(',').ToArray(); for (int i = 0; i < larr_coll.Length; i++) { string[] larr_colltemp = larr_coll[i].Split(':').ToArray(); HdRefcoll.Value = larr_colltemp[larr_colltemp.Length - 1]; HdRefcollrow.Value = (i + 1).ToString(); int li_collrow = dw_coll.InsertRow(0); dw_coll.SetItemString(li_collrow, "loancolltype_code", larr_colltemp[0]); dw_coll.SetItemString(li_collrow, "ref_collno", HdRefcoll.Value); CheckCollPermiss(); } //string[] larr_coll = ls_coll.Split(',').Select(t => t.Split(':')).ToArray(); //for (int i = 0; i < larr_coll.GetLength(0); i++) //{ // for (int j = 0; j < larr_coll.GetLength(0); j++) // { // string val = larr_coll[i][j]; // } //} of_calperiodpayment(); of_initotherpay_fsv(); of_initclearshare(); } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage(ex); } } else if (eventArg == "jsExpenseBank") { JsExpenseBank(); } else if (eventArg == "jsExpenseCode") { dw_main.SetItemString(1, "expense_bank", ""); dw_main.SetItemString(1, "expense_branch", ""); dw_main.SetItemString(1, "expense_accid", ""); JsExpenseCode(); } else if (eventArg == "jsGetMemberCollno") { CheckCollPermiss(); } else if (eventArg == "jsReNewPage") { JsReNewPage(); } else if (eventArg == "jsOpenOldDocNo") { JsOpenOldDocNo(); } else if (eventArg == "jsPostSetZero") { } else if (eventArg == "jsCancelRequest") { JsCancelRequest(); } else if (eventArg == "jsRefresh") { } else if (eventArg == "jsSetDataList") { JsSetDataList(); } else if (eventArg == "jsExpensebankbrRetrieve") { JsExpensebankbrRetrieve(); } else if (eventArg == "jsGetexpensememno") { JsGetexpensememno(); } else if (eventArg == "jsPostGetCollPermiss") { HdCondition.Value = "true"; int row_coll; //แถว ค้ำประกัน string as_collno = "", loancolltype_code = ""; try { row_coll = Convert.ToInt32(HdRefcollrow.Value); } catch { row_coll = 1; } as_collno = dw_coll.GetItemString(row_coll, "ref_collno"); loancolltype_code = dw_coll.GetItemString(row_coll, "loancolltype_code"); Boolean result_chk = ChkSameColl(as_collno, row_coll, loancolltype_code); if (result_chk == true && as_collno != "") { GetCollPermiss(); } } else if (eventArg == "jsGetitemdescetc") { JsGetitemdescetc(); } else if (eventArg == "jsPostDelOtherclr") { int row = int.Parse(HdRowNumber.Value); dw_otherclr.DeleteRow(row); CalSumTotal(); } else if (eventArg == "jsGetitemdescmthexp") { JsGetitemdescmthexp(); } else if (eventArg == "jsPostPrtRpt") { try { //iReportArgument args = new iReportArgument(); //string coop_id = state.SsCoopControl; //string loanreq_docno = dw_main.GetItemString(1, "loanrequest_docno"); ////ใส่อกิวเม้น ////loanreq_docno = "Q570001197"; //args.Add("as_loanreq_docno", iReportArgumentType.String, loanreq_docno); //args.Add("as_coop_id", iReportArgumentType.String, coop_id); //iReportBuider report1 = new iReportBuider(this, "หนังสือเสนอกรรมการ"); //report1.AddCriteria("r_sl_loan_req_paper", "เปิด เพื่อพิมพ์หนังสือเสนอกรรมการ", ReportType.pdf, args); //report1.AutoOpenPDF = true; //report1.Retrieve(); } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage("พิมพ์หนังสือไม่สำเร็จ " + ex); } } else if (eventArg == "jsPostCalInt") { string ls_clrcontno = ""; for (int ll_row = 1; ll_row <= dw_clear.RowCount; ll_row++) { if (dw_clear.GetItemDecimal(ll_row, "clear_status") == 1) { if (ls_clrcontno == "") { ls_clrcontno = dw_clear.GetItemString(ll_row, "loancontract_no"); } else { ls_clrcontno = "," + dw_clear.GetItemString(ll_row, "loancontract_no"); } } } dw_clear.Reset(); of_initloanclr(dw_main.GetItemString(1, "member_no")); if (ls_clrcontno != "") { string[] larr_contclr = ls_clrcontno.Split(','); for (int i = 0; i <= larr_contclr.Length; i++) { for (int j = 1; j <= dw_clear.RowCount; j++) { if (dw_clear.GetItemString(j, "loancontract_no") == larr_contclr[i].ToString()) { dw_clear.SetItemDecimal(j, "clear_status", 1); } } } } } } /// /// reset หน้าใหม่ /// private void JsReNewPage() { try { dw_main.Reset(); dw_main.InsertRow(0); dw_coll.Reset(); dw_clear.Reset(); dw_otherclr.Reset(); dw_periodpay.Reset(); dw_intspc.Reset(); dw_main.SetItemString(1, "memcoop_id", state.SsCoopControl); dw_main.SetItemString(1, "coop_id", state.SsCoopId); dw_main.SetItemDateTime(1, "loanrequest_date", state.SsWorkDate); //dw_main.SetItemDate(1, "loanrcvfix_date", state.SsWorkDate); // edit by bank tDwMain.Eng2ThaiAllRow(); RetreiveDDDW(); HdIsPostBack.Value = "false"; HdCheckRemark.Value = "false"; HdShowRemark.Value = "false"; Ltjspopup.Text = " "; Ltjspopupclr.Text = ""; } catch { } } /// /// retreive datawindows dropdown /// public void RetreiveDDDW() { try { loantype = Session["loantypeCode"].ToString(); Session.Remove("loantype"); } catch { String sql = ""; // sql = "select min(loantype_code) from lnloantype where coop_id = '" + state.SsCoopControl + "' and loangroup_code = '03'"; sql = "select min(loantype_code) from lnloantype where coop_id = '" + state.SsCoopControl + "'"; DataTable dt = WebUtil.Query(sql); if (dt.Rows.Count > 0) { lc_loantype = dt.Rows[0][0].ToString().Trim(); loantype = lc_loantype; Session.Remove("loantype"); } else { throw new Exception("ไม่พบประเภทเงินกู้"); } } try { DwUtil.RetrieveDDDW(dw_main, "loantype_code_1", pbl, null); if (loantype == "") { dw_main.SetItemString(1, "loantype_code", lc_loantype); } else { dw_main.SetItemString(1, "loantype_code", loantype); } DwUtil.RetrieveDDDW(dw_main, "expense_code", pbl, null); DwUtil.RetrieveDDDW(dw_main, "expense_bank_1", pbl, null); DwUtil.RetrieveDDDW(dw_main, "loanobjective_code_1", pbl, null); DwUtil.RetrieveDDDW(dw_otherclr, "clrothertype_code", pbl, null); } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage(ex); } } /// /// init ใบคำขอเก่า /// private void of_initlnreq() { try { string ls_coopid = "", ls_reqloandocno = ""; ls_coopid = dw_main.GetItemString(1, "coop_id"); ls_reqloandocno = dw_main.GetItemString(1, "loanrequest_docno"); txt_reqNo.Text = ls_reqloandocno; txt_member_no.Text = member_no; string[] arg = new string[2] { ls_coopid, ls_reqloandocno }; string[] arg2 = new string[2] { ls_reqloandocno, ls_coopid }; try { DwUtil.RetrieveDataWindow(dw_main, pbl, null, arg); } catch (Exception ex) { ex.ToString(); } tDwMain.Eng2ThaiAllRow(); try { DwUtil.RetrieveDataWindow(dw_clear, pbl, null, arg); } catch (Exception ex) { ex.ToString(); } try { DwUtil.RetrieveDataWindow(dw_coll, pbl, null, arg); } catch (Exception ex) { ex.ToString(); } try { DwUtil.RetrieveDataWindow(dw_otherclr, pbl, null, arg); } catch (Exception ex) { ex.ToString(); } try { DwUtil.RetrieveDataWindow(dw_intspc, pbl, null, arg); } catch (Exception ex) { ex.ToString(); } try { DwUtil.RetrieveDataWindow(dw_periodpay, pbl, null, arg2); } catch (Exception ex) { ex.ToString(); } of_Setperiodpaydet2(ls_reqloandocno, ls_coopid); } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage(ex); } } /// /// เช็คใบคำขอเก่า /// private Boolean of_checklnreq(string member_no) { try { string ls_CoopControl = state.SsCoopControl; //สาขาที่ทำรายการ String ls_loantype = "", ls_lnrequestdate = ""; ls_loantype = dw_main.GetItemString(1, "loantype_code"); ls_lnrequestdate = dw_main.GetItemString(1, "loanrequest_tdate"); string sqlStr = @"select loanrequest_docno, loanrequest_status, loanrequest_date from lnreqloan where loanrequest_status in (11,8) and coop_id = {0} and member_no = {1} and loantype_code = {2}"; sqlStr = WebUtil.SQLFormat(sqlStr, state.SsCoopControl, member_no, ls_loantype); Sdt dtchk = WebUtil.QuerySdt(sqlStr); if (dtchk.Next()) { dw_main.SetItemString(1, "loanrequest_docno", dtchk.GetString("loanrequest_docno")); DateTime ldtm_lnreq = dtchk.GetDate("loanrequest_date"); String entry_date = ldtm_lnreq.AddYears(543).ToString(); LtServerMessage.Text = WebUtil.WarningMessage("มีใบคำขอกู้สำหรับวันที่ " + entry_date + " แล้ว ระบบจะดึงข้อมูลใบคำขอให้อัตโนมัติ"); of_initlnreq(); return false; } } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage("of_checklnreq" + ex); } return true; } // public String selectMemNo(String member_no) // { // String member = ""; // String sqlStr2 = @"select member_no // from mbmembmaster // where mbmembmaster.coop_id = {0} // and mbmembmaster.member_no like '%" + member_no + "' and ROWNUM <= 1 order by member_no desc"; // sqlStr2 = WebUtil.SQLFormat(sqlStr2, state.SsCoopControl); // Sdt dt121 = WebUtil.QuerySdt(sqlStr2); // if (dt121.Next()) // { // member = dt121.GetString("member_no"); // } // return member; // } /// /// Post เลขสมาชิก /// private void JsPostmember() { //string member_no = WebUtil.MemberNoFormat(dw_main.GetItemString(1, "member_no")); string member_no = dw_main.GetItemString(1, "member_no"); string ls_loantype = dw_main.GetItemString(1, "loantype_code"); JsReNewPage(); DwUtil.RetrieveDDDW(dw_main, "membtype_code", pbl); dw_periodpay.Reset(); if (dw_coll.GetColumnNumber() > 0) { for (int i = 0; i < dw_coll.GetColumnNumber(); i++) { dw_coll.DeleteRow(0); } } else { for (int i = 0; i < 1; i++) { dw_coll.InsertRow(0); } } // member_no = selectMemNo(member_no); String membtype_desc = ""; String sqlStr = @"select mbucfmembtype.membtype_code,mbucfmembtype.membtype_desc from mbmembmaster left join mbucfmembtype on mbmembmaster.membtype_code=mbucfmembtype.membtype_code where mbmembmaster.coop_id = {0} and mbmembmaster.member_no like '%" + member_no + "'"; sqlStr = WebUtil.SQLFormat(sqlStr, state.SsCoopControl); Sdt dt11 = WebUtil.QuerySdt(sqlStr); if (dt11.Next()) { membtype_desc = dt11.GetString("membtype_desc"); } dw_main.SetItemString(1, "membtype_code", membtype_desc); dw_main.SetItemString(1, "member_no", member_no); dw_main.SetItemString(1, "loantype_code", ls_loantype); Boolean isvalid_result = false, lnreq_result = true; lnreq_result = of_checklnreq(member_no); if (lnreq_result == true) { isvalid_result = of_isvalidmember(member_no); } int num = 0; num = dw_clear.GetColumnNumber(); string ls_coopid = "", ls_reqloandocno = ""; ls_coopid = dw_main.GetItemString(1, "coop_id"); ls_reqloandocno = dw_main.GetItemString(1, "loanrequest_docno"); of_Setperiodpaydet2(ls_reqloandocno, ls_coopid); // string sql = @" // SELECT expireperiod_date ,(select Max(expireperiod_date) from lnreqloanperiodpaydet WHERE loanrequest_docno={0}) as mm,period from lnreqloanperiodpaydet // WHERE loanrequest_docno={0} "; // sql = WebUtil.SQLFormat(sql, loanrequest_docno); // Sdt dt = WebUtil.QuerySdt(sql); // int iq = 1; // while (dt.Next()) // { // //dw_periodpay.SetItemDate(iq, "expireperiod_date", dt.GetDate("expireperiod_date")); // dw_periodpay.SetItemString(iq, "expireperiod_tdate", dt.GetString("expireperiod_date")); // dw_main.SetItemString(1, "loanrcvfix_tdate", dt.GetString("mm")); // iq++; // } } /// /// ตรวจสอบการขอกู้ของสมาชิก /// private Boolean of_isvalidmember(string member_no) { string sqlStr = "", pauseloan_cause = "", ls_memtypedesc = "", ls_lnmemtypedesc = "", membtype_code = "", loancontract_no = "", ls_loantype = ""; int resign_status = 0, droploanall_flag = 0, member_type = 0, li_lnmemtype = 0; string loantype_code = dw_main.GetItemString(1, "loantype_code"); sqlStr = @"select resign_status, droploanall_flag, member_type, membtype_code from mbmembmaster where coop_id = {0} and member_no = {1}"; sqlStr = WebUtil.SQLFormat(sqlStr, state.SsCoopControl, member_no); Sdt dt1 = WebUtil.QuerySdt(sqlStr); if (dt1.Next()) { resign_status = dt1.GetInt32("resign_status"); droploanall_flag = dt1.GetInt32("droploanall_flag"); member_type = dt1.GetInt32("member_type"); membtype_code = dt1.GetString("membtype_code"); if (resign_status == 1) { LtServerMessage.Text = WebUtil.ErrorMessage("สมาชิกคนนี้ได้ลาออกแล้ว ไม่สามารถทำรายการกู้เงินได้อีก"); return false; } if (droploanall_flag == 1) { LtServerMessage.Text = WebUtil.ErrorMessage("สมาชิกคนนี้ งดกู้ทุกประเภท"); return false; } } else { LtServerMessage.Text = WebUtil.ErrorMessage("ไม่พบเลขทะเบียนสมาชิกคนนี้ #" + member_no + " กรุณาตรวจสอบ"); return false; } // ตรวจสอบว่ามีการงดกู้บางประเภทหรือเปล่า sqlStr = @"select pauseloan_cause from lnmembpauseloan where coop_id = {0} and loantype_code = {1} and member_no = {2}"; sqlStr = WebUtil.SQLFormat(sqlStr, state.SsCoopControl, loantype_code, member_no); Sdt dt2 = WebUtil.QuerySdt(sqlStr); if (dt2.Next()) { pauseloan_cause = dt2.GetString("pauseloan_cause"); LtServerMessage.Text = WebUtil.ErrorMessage("สมาชิกคนนี้ เป็นสมาชิกที่งดกู้เงินประเภทนี้อยู่ เหตุผล " + pauseloan_cause); return false; } sqlStr = @"select member_type from lnloantype where ( coop_id = {0} ) and ( loantype_code = {1} )"; sqlStr = WebUtil.SQLFormat(sqlStr, state.SsCoopControl, loantype_code); Sdt dt3 = WebUtil.QuerySdt(sqlStr); if (dt3.Next()) { li_lnmemtype = dt3.GetInt32("member_type"); if (li_lnmemtype != 0) { if (member_type != li_lnmemtype) { if (member_type == 1) { ls_memtypedesc = "สมาชิกปกติ"; } else { ls_memtypedesc = "สมาชิกสมทบ"; } if (li_lnmemtype == 1) { ls_lnmemtypedesc = "สมาชิกปกติ"; } else { ls_lnmemtypedesc = "สมาชิกสมทบ"; } LtServerMessage.Text = WebUtil.ErrorMessage("สมาชิกคนนี้เป็น '" + ls_memtypedesc + "' ไม่สามารถกู้เงินประเภทนี้ได้ เงินกู้นี้ให้กู้ได้เฉพาะ '" + ls_lnmemtypedesc + "' เท่านั้น"); return false; } } } // ตรวจสอบกลุ่มย่อยของสมาชิกสมทบว่ากู้ได้หรือเปล่า if (member_type == 2) { sqlStr = @"select membtype_code from lnloantypembtype where ( coop_id = {0} ) and ( loantype_code = {1} ) and ( membtype_code = {2} )"; sqlStr = WebUtil.SQLFormat(sqlStr, state.SsCoopControl, loantype_code, membtype_code); Sdt dt4 = WebUtil.QuerySdt(sqlStr); if (dt4.Rows.Count < 0) { LtServerMessage.Text = WebUtil.ErrorMessage("สมาชิกสมทบกลุ่มนี้ไม่ได้รับอนุญาติให้กู้เงินประเภทนี้ กรุณาตรวจสอบ"); return false; } } sqlStr = @"select a.loancontract_no, a.loantype_code from lncontmaster a, lnloantypepause b where ( a.coop_id = b.coop_id ) and ( a.loantype_code = b.loantype_code ) and ( a.memcoop_id = {0} ) and ( a.member_no = {1} ) and ( a.contract_status > 0 ) and ( b.coop_id = {0} ) and ( b.loantype_pause = {2} )"; sqlStr = WebUtil.SQLFormat(sqlStr, state.SsCoopControl, member_no, loantype_code); Sdt dt5 = WebUtil.QuerySdt(sqlStr); if (dt5.Rows.Count < 0) { loancontract_no = dt5.GetString("loancontract_no"); ls_loantype = dt5.GetString("loantype_code"); LtServerMessage.Text = WebUtil.ErrorMessage("สมาชิกคนนี้มีเงินกู้ " + loancontract_no + "(" + ls_loantype + ") อยู่ ไม่สามารถกู้เงินประเภทนี้ได้อีก"); return false; } return true; } /// /// set ข้อมูลสมาชิก /// private void of_setmemberinfo(string member_no) { try { string ls_membtypedesc = ""; decimal ldc_sharestk = 0, ldc_periodshramt = 0, ldc_shrstkvalue = 0, ldc_periodshrvalue = 0; decimal ldc_retryage = 0; DateTime ldtm_birth = DateTime.Now, ldtm_reqdate; ldtm_reqdate = dw_main.GetItemDateTime(1, "loanrequest_date"); String sqlstr = @"select mbmembmaster.coop_id, mbmembmaster.member_no, mbmembmaster.membgroup_code, mbucfmembgroup.membgroup_desc , nvl(mbmembmaster.birth_date,to_date('01/01/1900','dd/mm/yyyy')) as birth_date, nvl(mbmembmaster.member_date,to_date('01/01/1900','dd/mm/yyyy')) as member_date, nvl(mbmembmaster.work_date,to_date('01/01/1900','dd/mm/yyyy')) as work_date, nvl(mbmembmaster.retry_date,to_date('01/01/1900','dd/mm/yyyy')) as retry_date, to_number(ft_calage(birth_date,{2},4 )) as birth_age, to_number(ft_calage(member_date,{2},8 )) as member_age, to_number(ft_calage(work_date,{2},8 )) as work_age, to_number(ft_calage({2},retry_date,8 )) as retry_age, mbmembmaster.salary_amount, mbmembmaster.membtype_code, mbucfmembtype.membtype_desc, shsharemaster.last_period, shsharemaster.sharestk_amt, shsharemaster.periodshare_amt, mbucfprename.prename_desc||mbmembmaster.memb_name||' '||mbmembmaster.memb_surname as member_name, shsharemaster.payment_status, mbmembmaster.remark, mbmembmaster.rememb_flag, mbmembmaster.retry_status from mbmembmaster, mbucfmembgroup, mbucfprename, mbucfmembtype, shsharemaster where ( mbmembmaster.coop_id = mbucfmembgroup.coop_id ) and ( trim(mbmembmaster.membgroup_code) = trim(mbucfmembgroup.membgroup_code) ) and ( mbmembmaster.prename_code = mbucfprename.prename_code ) and ( mbmembmaster.coop_id = mbucfmembtype.coop_id ) and ( mbmembmaster.membtype_code = mbucfmembtype.membtype_code ) and ( mbmembmaster.coop_id = shsharemaster.coop_id ) and ( mbmembmaster.member_no = shsharemaster.member_no ) and ( ( mbmembmaster.coop_id = {0} ) and ( mbmembmaster.member_no = {1} ) and ( shsharemaster.sharetype_code = '01' ) )"; sqlstr = WebUtil.SQLFormat(sqlstr, state.SsCoopControl, member_no, ldtm_reqdate); Sdt dt = WebUtil.QuerySdt(sqlstr); if (dt.Next()) { ldc_retryage = dt.GetDecimal("retry_age"); if (ldc_retryage < 0) { ldc_retryage = 0; } ldc_sharestk = dt.GetDecimal("sharestk_amt"); ldc_periodshramt = dt.GetDecimal("periodshare_amt"); ls_membtype = dt.GetString("membtype_code"); ls_membtypedesc = dt.GetString("membtype_desc"); ldc_shrstkvalue = ldc_sharestk * 10; ldc_periodshrvalue = ldc_periodshramt * 10; if (dt.GetInt32("payment_status") != 1) { ldc_periodshrvalue = 0; } dw_main.SetItemString(1, "coop_id", dt.GetString("coop_id")); dw_main.SetItemString(1, "member_name", dt.GetString("member_name")); dw_main.SetItemString(1, "membgroup_code", dt.GetString("membgroup_code")); dw_main.SetItemString(1, "membgroup_desc", dt.GetString("membgroup_desc")); dw_main.SetItemDecimal(1, "salary_amt", dt.GetDecimal("salary_amount")); dw_main.SetItemDecimal(1, "share_lastperiod", dt.GetInt32("last_period")); dw_main.SetItemDateTime(1, "birth_date", dt.GetDate("birth_date")); dw_main.SetItemDateTime(1, "member_date", dt.GetDate("member_date")); dw_main.SetItemDateTime(1, "work_date", dt.GetDate("work_date")); dw_main.SetItemDateTime(1, "retry_date", dt.GetDate("retry_date")); dw_main.SetItemDecimal(1, "retry_status", dt.GetInt32("retry_status")); dw_main.SetItemDecimal(1, "birth_age", dt.GetDecimal("birth_age")); dw_main.SetItemDecimal(1, "member_age", dt.GetDecimal("member_age")); dw_main.SetItemDecimal(1, "work_age", dt.GetDecimal("work_age")); dw_main.SetItemDecimal(1, "retry_age", ldc_retryage); dw_main.SetItemDecimal(1, "incomemonth_other", 0); dw_main.SetItemDecimal(1, "paymonth_other", 0); // dw_main.SetItemString(1, "member_remark", dt.GetString("remark")); dw_main.SetItemDecimal(1, "share_balance", ldc_shrstkvalue); dw_main.SetItemDecimal(1, "share_periodvalue", ldc_periodshrvalue); dw_main.SetItemDecimal(1, "intestimate_amt", 0); dw_main.SetItemDecimal(1, "rememb_flag", dt.GetInt32("rememb_flag")); } //set เงินหักเงินเพิ่ม sqlstr = @"select nvl(sum( case when sign_flag = 1 then mthexpense_amt else 0 end ), 0) as incomemonth_fixed , nvl(sum( case when sign_flag = -1 then mthexpense_amt else 0 end ), 0) as paymonth_exp from mbmembmthexpense where coop_id = {0} and member_no = {1}"; sqlstr = WebUtil.SQLFormat(sqlstr, state.SsCoopControl, member_no); dt = WebUtil.QuerySdt(sqlstr); if (dt.Next()) { decimal paymonth_exp = dt.GetDecimal("paymonth_exp"); dw_main.SetItemDecimal(1, "incomemonth_fixed", dt.GetDecimal("incomemonth_fixed")); dw_main.SetItemDecimal(1, "paymonth_exp", paymonth_exp); Hdpaymouthexp.Value = Convert.ToString(paymonth_exp); } of_initexpense(member_no); } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage("of_setmemberinfo" + ex); } } /// /// init ประเภทการจ่ายเงิน /// private void of_initexpense(string as_membno) { try { string strsql = @"select expense_code, expense_bank, expense_branch, expense_accid from mbmembmaster where member_no = '" + as_membno + "'"; Sdt dtloanrcv = WebUtil.QuerySdt(strsql); if (dtloanrcv.GetRowCount() <= 0) { LtServerMessage.Text = WebUtil.WarningMessage("ไม่พบเลขที่บัญชีเงินธนาคารของสมาชิก " + as_membno); } if (dtloanrcv.Next()) { string loanrcv_code = "", loanrcv_bank = ""; try { loanrcv_code = dw_main.GetItemString(1, "expense_code"); } catch { loanrcv_code = ""; } if (loanrcv_code == "" || loanrcv_code == null) { loanrcv_code = dtloanrcv.GetString("expense_code"); } try { loanrcv_bank = dw_main.GetItemString(1, "expense_bank"); } catch { loanrcv_bank = ""; } if (loanrcv_bank == "" || loanrcv_bank == null) { loanrcv_bank = dtloanrcv.GetString("expense_bank"); } string loanrcv_branch = dtloanrcv.GetString("expense_branch"); string loanrcv_accid = dtloanrcv.GetString("expense_accid"); if (loanrcv_code != null) { dw_main.SetItemString(1, "expense_code", loanrcv_code); dw_main.SetItemString(1, "expense_bank", loanrcv_bank); if (loanrcv_branch == "" || loanrcv_branch == null) { DwUtil.RetrieveDDDW(dw_main, "expense_branch_1", "sl_loan_requestment_dol.pbl", loanrcv_bank); } else { dw_main.SetItemString(1, "expense_branch", loanrcv_branch); } dw_main.SetItemString(1, "expense_accid", loanrcv_accid); // DwUtil.RetrieveDDDW(dw_main, "expense_branch", "sl_loan_requestment_dol.pbl", null); } else { dw_main.SetItemString(1, "expense_code", "CBT"); } if (loanrcv_code == "CBT" && loanrcv_bank.Length > 2) { string sql_bkk = "select branch_name from cmucfbankbranch where bank_code = '" + loanrcv_bank + "' and branch_id = '" + loanrcv_branch + "'"; Sdt dtk = WebUtil.QuerySdt(sql_bkk); string bankbranch = ""; if (dtk.Next()) { bankbranch = dtk.GetString("branch_name").Trim(); JsExpensebankbrRetrieve(); } } if (loanrcv_code == "CBO" && loanrcv_bank.Length > 2) { string sql_bkk = "select branch_name from cmucfbankbranch where bank_code = '" + loanrcv_bank + "' and branch_id = '" + loanrcv_branch + "'"; Sdt dtk = WebUtil.QuerySdt(sql_bkk); string bankbranch = ""; if (dtk.Next()) { bankbranch = dtk.GetString("branch_name").Trim(); JsExpensebankbrRetrieve(); } } } } catch { } } /// /// set ข้อมูลประเภทเงินกู้ /// private void of_setloantypeinfo(string loantype_code) { try { string ls_salarycode = "", ls_intratetab = "", ls_intfixtab, ls_lnpermgrp; int li_apvflag = 0, li_salarychk = 0, li_chkdept, li_inttype = 0, li_intsteptype = 0; int li_intcertstatus, li_intcertlntype = 0, li_lnpaycount = 0; decimal ldc_minsalamt, ldc_minsalinc = 0, ldc_salamt, ldc_maxloan; decimal ldc_minsalperc, ldc_intincrease = 0, ldc_intfixrate = 0, ldc_idenintrate = 0; DateTime ldtm_reqdate; string sqlStr; ii_apvtype = 0; ldtm_reqdate = dw_main.GetItemDateTime(1, "loanrequest_date"); sqlStr = @"select lnt.defaultobj_code, lnt.salarybal_status, lnt.salarybal_code, lnt.loanright_type, lnt.loanpayment_type, lnt.contract_time, lnt.od_flag, lnt.intstep_type, lnt.intcertificate_status, lnt.approve_flag, ft_getlntypintrate({0}, {1},1,{2},1) as idenintrate, lnt.contint_type, lnt.inttabrate_code, lnt.inttabfix_code, lnt.intrate_increase, lnt.loanpayment_type, lnt.loanpayment_status, lnt.reqround_factor, lnt.payround_factor, lnt.inttabfix_code, lnt.lngrpcutright_flag, lnt.inttabrate_code, lnt.resign_timeadd, lnt.retryloansend_time, lnt.retryloansend_type, lnt.loanpayment_count, lnt.loanpermgrp_code, lnc.fixpaycal_type, lnt.maxloan_amt from lnloantype lnt, lnloanconstant lnc where lnt.coop_id = lnc.coop_id and lnt.coop_id = {0} and lnt.loantype_code = {1}"; sqlStr = WebUtil.SQLFormat(sqlStr, state.SsCoopControl, loantype_code, ldtm_reqdate); Sdt dtlntype = WebUtil.QuerySdt(sqlStr); if (dtlntype.Next()) { li_salarychk = dtlntype.GetInt32("salarybal_status"); ls_salarycode = dtlntype.GetString("salarybal_code"); li_intcertlntype = dtlntype.GetInt32("intcertificate_status"); li_apvflag = dtlntype.GetInt32("approve_flag"); try { ldc_idenintrate = dtlntype.GetDecimal("idenintrate"); } catch { ldc_idenintrate = 0; } li_inttype = dtlntype.GetInt32("contint_type"); ls_intratetab = dtlntype.GetString("inttabrate_code"); ls_intfixtab = dtlntype.GetString("inttabfix_code"); ldc_intincrease = dtlntype.GetDecimal("intrate_increase"); li_lnpaycount = dtlntype.GetInt32("loanpayment_count"); ldc_maxloan = dtlntype.GetDecimal("maxloan_amt"); // กำหนดรายละเอียดทั่วไปลงใบขอกู้ dw_main.SetItemDecimal(1, "loanright_type", dtlntype.GetInt32("loanright_type")); dw_main.SetItemDecimal(1, "loanpayment_type", dtlntype.GetInt32("loanpayment_type")); dw_main.SetItemDecimal(1, "contract_time", dtlntype.GetInt32("contract_time")); dw_main.SetItemString(1, "loanobjective_code", dtlntype.GetString("defaultobj_code")); dw_main.SetItemDecimal(1, "od_flag", dtlntype.GetInt32("od_flag")); dw_main.SetItemDecimal(1, "int_intsteptype", dtlntype.GetInt32("intstep_type")); dw_main.SetItemDecimal(1, "retryloansend_type", dtlntype.GetInt32("retryloansend_type")); dw_main.SetItemDecimal(1, "lnoverretry_period", dtlntype.GetInt32("retryloansend_time")); dw_main.SetItemDecimal(1, "reqround_factor", dtlntype.GetDecimal("reqround_factor")); dw_main.SetItemDecimal(1, "payround_factor", dtlntype.GetDecimal("payround_factor")); dw_main.SetItemDecimal(1, "fixpaycal_type", dtlntype.GetInt32("fixpaycal_type")); //dw_main.SetItemDecimal(1, "intcertlntype_status", li_intcertlntype); //dw_main.SetItemDecimal(1, "intcertificate_status", li_intcertstatus); ls_lnpermgrp = dtlntype.GetString("loanpermgrp_code"); if (ls_lnpermgrp != null && ls_lnpermgrp != "") { sqlStr = @"select maxpermiss_amt from lngrploanpermiss where coop_id = {0} and loanpermgrp_code = {1}"; sqlStr = WebUtil.SQLFormat(sqlStr, state.SsCoopControl, ls_lnpermgrp); Sdt dt = WebUtil.QuerySdt(sqlStr); if (dt.Next()) { dw_main.SetItemDecimal(1, "loangrpcredit_amt", dt.GetDecimal("maxpermiss_amt")); } else { dw_main.SetItemDecimal(1, "loangrpcredit_amt", 999999999999); } } else { dw_main.SetItemDecimal(1, "loangrpcredit_amt", 999999999999); } } ldc_minsalperc = 0; ldc_minsalamt = 0; if (li_intcertlntype == 1) { li_intcertstatus = 1; } else { li_intcertstatus = 0; } //กำหนดรูปแบบการชำระ if (li_lnpaycount == 0) { dw_main.SetItemString(1, "loanpay_code", "KOT"); } else { dw_main.SetItemString(1, "loanpay_code", "KEP"); } // การให้อนุมัติเลย if (li_apvflag == 1) { if (ii_apvtype == 0) { ii_apvtype = 1; } dw_main.SetItemDecimal(1, "apvimmediate_status", ii_apvtype); } else { ii_apvtype = 0; dw_main.SetItemDecimal(1, "apvimmediate_status", 0); } // อัตรา ด/บ ที่ใช้ในสัญญา dw_main.SetItemDecimal(1, "identifycont_intrate", ldc_idenintrate); switch (li_inttype) { case 0: // ไม่คิดด/บ dw_main.SetItemDecimal(1, "int_continttype", li_inttype); dw_main.SetItemDecimal(1, "int_contintrate", 0); dw_main.SetItemString(1, "int_continttabcode", ""); dw_main.SetItemDecimal(1, "int_contintincrease", 0); break; case 1: // อัตรา ด/บ คงที่ //ldc_intfixrate = inv_intsrv.of_getloanintrate( ls_intfixtab, ldtm_reqdate ) dw_main.SetItemDecimal(1, "int_continttype", li_inttype); dw_main.SetItemDecimal(1, "int_contintrate", ldc_intfixrate); dw_main.SetItemString(1, "int_continttabcode", ""); dw_main.SetItemDecimal(1, "int_contintincrease", 0); break; case 2: // อัตรา ด/บ ตามประกาศ dw_main.SetItemDecimal(1, "int_continttype", li_inttype); dw_main.SetItemDecimal(1, "int_contintrate", 0); dw_main.SetItemString(1, "int_continttabcode", ls_intratetab); dw_main.SetItemDecimal(1, "int_contintincrease", ldc_intincrease); break; case 3: // อัตรา ด/บ พิเศษเป็นช่วง dw_main.SetItemDecimal(1, "int_continttype", li_inttype); dw_main.SetItemDecimal(1, "int_contintrate", 0); dw_main.SetItemString(1, "int_continttabcode", ""); dw_main.SetItemDecimal(1, "int_contintincrease", 0); sqlStr = @"select coop_id, seq_no, inttime_type, inttime_amt, intrate_type, intratetab_code, intratefix_rate, intrate_increase, inttabrate_code from lnloantypeintspc where coop_id = {0} and loantype_code = {1}"; sqlStr = WebUtil.SQLFormat(sqlStr, state.SsCoopControl, loantype_code); Sdt dt3 = WebUtil.QuerySdt(sqlStr); int i = 0; while (dt3.Next()) { i = dw_intspc.InsertRow(0); dw_intspc.SetItemString(i, "coop_id", state.SsCoopControl); dw_intspc.SetItemDecimal(i, "seq_no", i); dw_intspc.SetItemDecimal(i, "int_continttype", dt3.GetInt32("intrate_type")); dw_intspc.SetItemDecimal(i, "int_contintrate", dt3.GetDecimal("intratefix_rate")); dw_intspc.SetItemString(i, "int_continttabcode", dt3.GetString("intratetab_code")); dw_intspc.SetItemDecimal(i, "int_contintincrease", dt3.GetDecimal("intrate_increase")); dw_intspc.SetItemDecimal(i, "int_timetype", dt3.GetInt32("inttime_type")); dw_intspc.SetItemDecimal(i, "int_timeamt", dt3.GetInt32("inttime_amt")); i++; } break; case 4: // อัตรา ด/บ ตามประกาศของเงินฝาก dw_main.SetItemDecimal(1, "int_continttype", li_inttype); dw_main.SetItemDecimal(1, "int_contintrate", 0); dw_main.SetItemString(1, "int_continttabcode", ls_intratetab); dw_main.SetItemDecimal(1, "int_contintincrease", ldc_intincrease); break; case 5: // อัตรา ด/บ ตามเงินฝากที่มาใช้กู้ dw_main.SetItemDecimal(1, "int_continttype", li_inttype); dw_main.SetItemDecimal(1, "int_contintrate", 0); dw_main.SetItemString(1, "int_continttabcode", ""); dw_main.SetItemDecimal(1, "int_contintincrease", ldc_intincrease); break; }; } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage("of_setloantypeinfo" + ex); } } /// /// set ข้อมูลหักกลบ /// private void of_initloanclr(string member_no) { string ls_loantype, ls_lntypeclr; int li_lastperiod, li_minperiod, li_finetype; int ll_row = 0; decimal ldc_apvamt, ldc_wtdamt, ldc_prnbal; decimal ldc_intrate, ldc_intestim, ldc_payperc; decimal ldc_minpercent, ldc_fineamt, ldc_fineperc, ldc_finemax, ldc_finemin; Boolean lb_period = true, lb_payment = true; string sqlStr, ls_clr = ""; try { sqlStr = @"select lm.coop_id, lm.loancontract_no, lm.loantype_code, lm.loanapprove_amt, lm.withdrawable_amt, lm.principal_balance, lm.loanpayment_type, lm.period_payment, lm.last_periodpay, nvl( lm.lastcalint_date, to_date('19000101','yyyymmdd') ) as lastcalint_date, lm.interest_arrear, nvl( lm.lastprocess_date, to_date('19000101','yyyymmdd') ) as lastprocess_date, lm.rkeep_principal, lm.rkeep_interest, lm.contract_status, lm.transfer_status, lm.loanpay_code, ft_getcontintrate( lm.coop_id, lm.loancontract_no, lm.lastcalint_date ) as contint_rate, lt.loanpermgrp_code, lt.shrstkcount_flag , nvl( lm.startcont_date, to_date('19000101','yyyymmdd') ) as startcont_date, nvl( lm.loanapprove_date, to_date('19000101','yyyymmdd') ) as loanapprove_date from lncontmaster lm, lnloantype lt where ( lm.coop_id = lt.coop_id ) and ( lm.loantype_code = lt.loantype_code ) and ( lm.memcoop_id = {0} ) and ( lm.member_no = {1} ) and ( lm.contract_status > 0 ) order by lm.loantype_code"; sqlStr = WebUtil.SQLFormat(sqlStr, state.SsCoopControl, member_no); Sdt dt = WebUtil.QuerySdt(sqlStr); while (dt.Next()) { ll_row = dw_clear.InsertRow(0); ldc_prnbal = dt.GetDecimal("principal_balance"); ldc_intrate = dt.GetDecimal("contint_rate"); dw_clear.SetItemString(ll_row, "loanpermgrp_code", dt.GetString("loanpermgrp_code")); dw_clear.SetItemDecimal(ll_row, "shrstkcount_flag", dt.GetInt32("shrstkcount_flag")); dw_clear.SetItemString(ll_row, "concoop_id", dt.GetString("coop_id")); dw_clear.SetItemString(ll_row, "loancontract_no", dt.GetString("loancontract_no")); dw_clear.SetItemString(ll_row, "loantype_code", dt.GetString("loantype_code")); dw_clear.SetItemDecimal(ll_row, "loanapprove_amt", dt.GetDecimal("loanapprove_amt")); //dw_clear.SetItemDecimal(ll_row, "loanapprove_date", dt.GetDecimal("loanapprove_date")); dw_clear.SetItemDateTime(ll_row, "startcont_date", dt.GetDate("startcont_date")); dw_clear.SetItemDecimal(ll_row, "principal_balance", ldc_prnbal); dw_clear.SetItemDecimal(ll_row, "withdrawable_amt", dt.GetDecimal("withdrawable_amt")); dw_clear.SetItemDecimal(ll_row, "loanpayment_type", dt.GetInt32("loanpayment_type")); dw_clear.SetItemDecimal(ll_row, "period_payment", dt.GetDecimal("period_payment")); dw_clear.SetItemDecimal(ll_row, "last_periodpay", dt.GetInt32("last_periodpay")); dw_clear.SetItemString(ll_row, "loanpay_code", dt.GetString("loanpay_code")); dw_clear.SetItemDateTime(ll_row, "lastcalint_date", dt.GetDate("lastcalint_date")); dw_clear.SetItemDecimal(ll_row, "intarrear_amt", dt.GetDecimal("intarrear_amt")); dw_clear.SetItemDecimal(ll_row, "intestimate_rate", ldc_intrate); //dw_clear.SetItemDateTime(ll_row, "lastprocess_date", dt.GetDate("lastprocess_date")); dw_clear.SetItemDecimal(ll_row, "rkeep_principal", dt.GetDecimal("rkeep_principal")); dw_clear.SetItemDecimal(ll_row, "rkeep_interest", dt.GetDecimal("rkeep_interest")); dw_clear.SetItemDecimal(ll_row, "contract_status", dt.GetInt32("contract_status")); dw_clear.SetItemDecimal(ll_row, "clear_status", 0); dw_clear.SetItemDecimal(ll_row, "clear_amount", 0); dw_clear.SetItemDecimal(ll_row, "fine_amt", 0); dw_clear.SetItemDecimal(ll_row, "transfer_status", dt.GetInt32("transfer_status")); // ด/บ ประมาณการ 30 วัน สำหรับประมาณการชำระ / เดือน ldc_intestim = Convert.ToDecimal(Convert.ToDouble(ldc_prnbal) * (Convert.ToDouble(ldc_intrate) / 100.00) * (30.00 / 365.00)); dw_clear.SetItemDecimal(ll_row, "intestimate_amt", ldc_intestim); // //เพิ่ม : } sqlStr = @"select loantype_clear, minperiod_pay, minpercent_pay, finecond_type, fine_amt, fine_percent, fine_maxamt from lnloantypeclr where ( coop_id = {0} ) and ( loantype_code = {1} )"; sqlStr = WebUtil.SQLFormat(sqlStr, state.SsCoopControl, dw_main.GetItemString(1, "loantype_code")); Sdt dt1 = WebUtil.QuerySdt(sqlStr); while (dt1.Next()) { ls_lntypeclr = dt1.GetString("loantype_clear"); for (int i = 1; i <= dw_clear.RowCount; i++) { ls_loantype = dw_clear.GetItemString(i, "loantype_code"); if (ls_lntypeclr == ls_loantype) { li_minperiod = dt1.GetInt32("minperiod_pay"); ldc_minpercent = dt1.GetDecimal("minpercent_pay"); ldc_apvamt = dw_clear.GetItemDecimal(i, "loanapprove_amt"); ldc_wtdamt = dw_clear.GetItemDecimal(i, "withdrawable_amt"); ldc_prnbal = dw_clear.GetItemDecimal(i, "principal_balance"); li_lastperiod = Convert.ToInt32(dw_clear.GetItemDecimal(i, "last_periodpay")); // % การชำระ (คิดจากยอดรับเงินไปแล้ว เทียบกับยอดคงเหลือ) ldc_payperc = (((ldc_apvamt - ldc_wtdamt) - ldc_prnbal) / (ldc_apvamt - ldc_wtdamt)) * 100; // ตรวจสอบว่างวดชำระถึงที่กำหนดหรือเปล่า if (li_lastperiod < li_minperiod || ldc_payperc < ldc_minpercent) { if (li_lastperiod < li_minperiod) { lb_period = false; } if (ldc_payperc < ldc_minpercent) { lb_payment = false; } //เตือนชำระไม่ถึงกำหนด if (lb_period == false || lb_payment == false) { string ls_contno = dw_clear.GetItemString(i, "loancontract_no"); ls_clr += "\\nสัญญา " + ls_contno + " งวดชำระแล้ว = " + li_lastperiod.ToString() + ", %ชำระแล้ว = " + ldc_payperc.ToString("#,##0.00") + "%"; } li_finetype = dt1.GetInt32("finecond_type"); ldc_fineperc = dt1.GetDecimal("fine_percent"); ldc_finemin = dt1.GetDecimal("fine_amt"); ldc_finemax = dt1.GetDecimal("fine_maxamt"); if ((li_finetype == 1 && (lb_period == false || lb_payment == false)) || (li_finetype == 2 && lb_period == false && lb_payment == false)) { // ส่วนของค่าปรับกรณีชำระไม่ครบตามที่กำหนด ldc_fineamt = ldc_prnbal * (ldc_fineperc / 100); if (ldc_fineamt < ldc_finemin) { ldc_fineamt = ldc_finemin; } if (ldc_fineamt > ldc_finemax) { ldc_fineamt = ldc_finemax; } dw_clear.SetItemDecimal(i, "fine_amt", ldc_fineamt); if (ldc_fineamt > 0) { ls_clr += " ต้องคิดค่าบริการ เป็นจำนวนเงิน " + ldc_fineamt.ToString("#,##0.00"); } } } dw_clear.SetItemDecimal(i, "clear_status", 0); dw_clear.SetItemDecimal(i, "clear_amount", dw_clear.GetItemDecimal(i, "principal_balance")); } } if (ls_clr != "") { is_massalert = "\\nมีสัญญาเก่าชำระหนี้ไม่ถึงตามที่กำหนด " + ls_clr; } } of_setclearintreal(); } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage("of_initloanclr" + ex); } } /// /// set สิทธิ์กู้ /// private void of_initloancredit(string as_loantype) { try { string ls_memno, ls_ccdtno; int li_mintime = 0, li_membtime, li_ccdtperiod; int li_righttype = 0, li_timefrom = 0, li_righttime = 0, li_resignaddtime = 0, li_remembflag; decimal ldc_salary, ldc_shrstkvalue, ldc_permissamt = 0; DateTime ldtm_membdate, ldtm_workdate, ldtm_expcont, ldtm_rqdate; string sqlStr; sqlStr = @"select loanright_type, customtime_type, member_time, resign_timeadd, maxloan_amt from lnloantype where ( coop_id = {0} ) and ( loantype_code = {1} )"; sqlStr = WebUtil.SQLFormat(sqlStr, state.SsCoopControl, as_loantype); Sdt dt = WebUtil.QuerySdt(sqlStr); if (dt.Next()) { li_mintime = dt.GetInt32("member_time"); li_resignaddtime = dt.GetInt32("resign_timeadd"); li_righttype = dt.GetInt32("loanright_type"); li_timefrom = dt.GetInt32("customtime_type"); } // ดึงค่าต่างๆ ที่ใช้ในการคำนวณสิทธิ ldc_salary = dw_main.GetItemDecimal(1, "salary_amt"); li_remembflag = Convert.ToInt32(dw_main.GetItemDecimal(1, "rememb_flag")); ldtm_membdate = dw_main.GetItemDateTime(1, "member_date"); // ldtm_workdate = dw_main.GetItemDateTime(1, "work_date"); ldtm_workdate =state.SsWorkDate; switch (li_righttype) { case 1:// แบบดูจากหลักประกัน case 4:// แบบดูจากเงินฝาก ls_memno = dw_main.GetItemString(1, "member_no"); this.SetOnLoadedScript("Gcoop.OpenIFrame2Extend('760', '600', 'ws_dlg_rightcoll.aspx', '?memb_no=" + ls_memno + "&loan_type=" + as_loantype + "')"); ibl_step = false; break; case 2:// แบบกำหนดเอง ldc_shrstkvalue = dw_main.GetItemDecimal(1, "share_balance"); switch (li_timefrom) { case 1: // อายุการเป็นสมาชิก li_righttime = Convert.ToInt32(dw_main.GetItemDecimal(1, "member_age")); break; //case 2: // อายุการทำงาน // li_righttime = Convert.ToInt32(dw_main.GetItemDecimal(1, "work_age")); // break; case 2: // งวดหุ้น li_righttime = Convert.ToInt32(dw_main.GetItemDecimal(1, "share_lastperiod")); break; } ldc_permissamt = this.of_callncredit_custom(as_loantype, li_righttime, ldc_shrstkvalue, ldc_salary); break; case 3:// แบบดูจากสัญญาหลัก ls_memno = dw_main.GetItemString(1, "member_no"); ldtm_rqdate = dw_main.GetItemDateTime(1, "loanrequest_date"); sqlStr = @"select contcredit_no, loancreditbal_amt, expirecont_date, maxperiod_payamt , loanrcv_code , loanrcv_bank , loanrcv_branch , loanrcv_accid from lncontcredit where ( coop_id = {0} ) and ( member_no = {1} ) and ( loantype_code = {2} ) and ( contcredit_status = 1 ) order by contcredit_no desc"; sqlStr = WebUtil.SQLFormat(sqlStr, state.SsCoopControl, ls_memno, as_loantype); Sdt dt1 = WebUtil.QuerySdt(sqlStr); if (dt1.Next()) { ls_ccdtno = dt1.GetString("contcredit_no"); ldc_permissamt = dt1.GetDecimal("loancreditbal_amt"); ldtm_expcont = dt1.GetDate("expirecont_date"); li_ccdtperiod = dt1.GetInt32("maxperiod_payamt"); } else { LtServerMessage.Text = WebUtil.ErrorMessage("ไม่พบข้อมูลวงเงินกู้ในสัญญาหลักของสมาชิกทะเบียน " + ls_memno + " ประเภทเงินกู้ " + as_loantype + " กรุณาไปกำหนดวงเงินกู้ก่อน"); break; } if (ldtm_expcont < ldtm_rqdate) { LtServerMessage.Text = WebUtil.ErrorMessage("สัญญา " + ls_ccdtno + " หมดอายุสัญญาไปแล้ว วันที่ " + ldtm_expcont.ToString("dd/mm/") + ldtm_expcont.ToString("yyyy") + 543); } // เพราะดูจากสัญญาหลัก ถ้าไม่ error ให้ใส่ค่าให้เลย dw_main.SetItemDecimal(1, "maxperiod_payamt", li_ccdtperiod); dw_main.SetItemDecimal(1, "maxsend_payamt", li_ccdtperiod); dw_main.SetItemString(1, "ref_contmastno", ls_ccdtno); dw_main.SetItemString(1, "expense_code", dt1.GetString("loanrcv_code")); dw_main.SetItemString(1, "expense_bank", dt1.GetString("loanrcv_bank")); dw_main.SetItemString(1, "expense_branch", dt1.GetString("loanrcv_branch")); dw_main.SetItemString(1, "expense_accid", dt1.GetString("loanrcv_accid")); break; } dw_main.SetItemDecimal(1, "loancredit_amt", ldc_permissamt); dw_main.SetItemDecimal(1, "loanreqregis_amt", ldc_permissamt); } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage("of_callncredit" + ex); } } /// /// คำนวณสิทธิ์กู้ /// private decimal of_callncredit_custom(string as_lntypereq, int ai_righttime, decimal adc_sharestk, decimal adc_salary) { string sqlStr; decimal ldc_maxpermiss = 0, ldc_permiss, ldc_abspermiss = 0; decimal ldc_mulsalary, ldc_mulshare; try { // สิทธิกู้สุทธิกำหนดให้ unlimit ไว้ก่อน ldc_abspermiss = 99999999999; sqlStr = @"select multiple_share, multiple_salary, maxloan_amt from lnloantypecustom where ( coop_id = {0} ) and ( loantype_code = {1} ) and ( {2} between startmember_time and endmember_time ) and ( {3} between startshare_amt and endshare_amt ) and ( {4} between startsalary_amt and endsalary_amt )"; sqlStr = WebUtil.SQLFormat(sqlStr, state.SsCoopControl, as_lntypereq, ai_righttime, adc_sharestk, adc_salary); Sdt dt = WebUtil.QuerySdt(sqlStr); while (dt.Next()) { // สิทธิกู้ขั้นนี้ ldc_mulshare = dt.GetDecimal("multiple_share"); // ldc_mulsalary = dt.GetDecimal("multiple_salary"); ldc_maxpermiss = dt.GetDecimal("maxloan_amt"); ldc_abspermiss = ldc_maxpermiss; } } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage("of_callncredit_custom" + ex); } return ldc_abspermiss; } /// /// set ยอดขอกู้ /// private void of_initpermiss() { try { decimal ldc_permissamt, ldc_grpuse, ldc_maxloan = 0, ldc_request = 0, ldc_loancredit, ldc_grpcredit, ldc_loanregis, ldc_collperc, ldc_sharestk, ldc_temp; decimal ldc_loanreq, ldc_roundfacter = 0; string ls_permissgrp = "", ls_loantype; int li_kpsumflag = 0, li_lngrpcutright = 0, li_notmoreshare = 0, li_showright, li_roundtype = 0; string sqlStr; ls_loantype = dw_main.GetItemString(1, "loantype_code"); ldc_loancredit = dw_main.GetItemDecimal(1, "loancredit_amt"); ldc_grpcredit = dw_main.GetItemDecimal(1, "loangrpcredit_amt"); ldc_loanregis = dw_main.GetItemDecimal(1, "loanreqregis_amt"); ldc_request = dw_main.GetItemDecimal(1, "loanrequest_amt"); Decimal coll_percen = 0; sqlStr = @"select lngrpcutright_flag, notmoreshare_flag, maxloan_amt, loanpermgrp_code, lngrpkeepsum_flag, showright_flag, reqround_factor, reqround_type from lnloantype where ( coop_id = {0} ) and ( loantype_code = {1} )"; sqlStr = WebUtil.SQLFormat(sqlStr, state.SsCoopControl, ls_loantype); Sdt dt = WebUtil.QuerySdt(sqlStr); if (dt.Next()) { li_lngrpcutright = dt.GetInt32("lngrpcutright_flag"); li_notmoreshare = dt.GetInt32("notmoreshare_flag"); ldc_maxloan = dt.GetDecimal("maxloan_amt"); ls_permissgrp = dt.GetString("loanpermgrp_code"); li_kpsumflag = dt.GetInt32("lngrpkeepsum_flag"); li_showright = dt.GetInt32("showright_flag"); li_roundtype = dt.GetInt32("reqround_type"); ldc_roundfacter = dt.GetDecimal("reqround_factor"); } //lngrpcutright_flag ขอกู้ได้ไม่เกินวงเงินกู้กลุ่ม //notmoreshare_flag กู้ได้ไม่เกินหุ้นที่มี //maxloan_amt วงเงินกู้สูงสุดของเงินกู้ประเภทนี้ //loanpermgrp_code เงินกู้ประเภทนี้อยู่ในกลุ่มเงินกู้รหัสอะไร //lngrpkeepsum_flag การนับเงินกู้รวมใช้ไปหักยอดรอเรียกเก็บหรือเปล่า //showright_flag แสดงสิทธิกู้ตอนคำนวณสิทธิ์เสร็จแล้วหรือเปล่า ldc_permissamt = ldc_maxloan; // วงเงินกู้รวมใช้ไป ldc_grpuse = of_calpermissloangrpused(ls_permissgrp, li_kpsumflag); // ตรวจว่าต้องตัดยอดขอกู้จากยอดกู้กลุ่มหรือไม่ if (li_lngrpcutright == 1) { if (ldc_permissamt > (ldc_loancredit - ldc_grpuse)) { ldc_permissamt = (ldc_loancredit - ldc_grpuse); } if (ldc_permissamt < 0) { ldc_permissamt = 0; } } // check กับยอด credit if (ldc_permissamt > (ldc_grpcredit - ldc_grpuse)) { ldc_permissamt = (ldc_grpcredit - ldc_grpuse); } if (ldc_permissamt > ldc_loancredit) { ldc_permissamt = ldc_loancredit; } if (ldc_permissamt > ldc_maxloan) { ldc_permissamt = ldc_maxloan; } // ตรวจว่าห้ามกู้เกินหุ้นหรือเปล่า if (li_notmoreshare == 1) { sqlStr = @"select coll_percent from lnloantypecolluse where coop_id = {0} and loantype_code = {1} and loancolltype_code = '02'"; sqlStr = WebUtil.SQLFormat(sqlStr, state.SsCoopControl, ls_loantype); Sdt dt1 = WebUtil.QuerySdt(sqlStr); if (dt.Next()) { ldc_collperc = dt.GetDecimal("coll_percent"); ldc_sharestk = dw_main.GetItemDecimal(1, "share_balance"); ldc_temp = ldc_sharestk * ldc_collperc; // ถ้ามากกว่าหุ้นที่ใช้ได้ตัดยอดลง if (ldc_permissamt > ldc_temp) { ldc_permissamt = ldc_temp; } } } if (ldc_permissamt < 0) { ldc_permissamt = 0; } dw_main.SetItemDecimal(1, "loanpermiss_amt", ldc_permissamt); // ค่าเงินที่จะขอกู้ได้ if (ldc_permissamt > ldc_loanregis) { ldc_loanreq = ldc_loanregis; } else { ldc_loanreq = ldc_permissamt; } // ปัดยอดขอกู้ if (ldc_roundfacter != 0) { decimal ldc_tempfacter = Math.Abs(ldc_roundfacter); if ((ldc_loanreq % ldc_roundfacter) > 0) { if (ldc_roundfacter > 0) { ldc_loanreq = ldc_loanreq - (ldc_loanreq % ldc_roundfacter) + ldc_roundfacter; } else { ldc_loanreq = ldc_loanreq - (ldc_loanreq % ldc_roundfacter); } } } //dw_main.SetItemDecimal(1, "loanrequest_amt", ldc_loanreq); if (ldc_request > ldc_maxloan) { ldc_request = ldc_maxloan; } dw_main.SetItemDecimal(1, "loanrequest_amt", ldc_request); HdCondition.Value = "true"; //pom - คิดงวดตามยอดขอกู้ of_initmaxperiod(ls_loantype, ldc_loanreq); // of_setintestimateloanreq(); } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage("of_initpermiss " + ex); } } /// /// set ยอดขอกู้ PostMember /// private void of_initpermiss_begin() { try { decimal ldc_permissamt, ldc_grpuse, ldc_maxloan = 0, ldc_loancredit, ldc_grpcredit, ldc_loanregis, ldc_collperc, ldc_sharestk, ldc_temp; decimal ldc_loanreq, ldc_roundfacter = 0; string ls_permissgrp = "", ls_loantype; int li_kpsumflag = 0, li_lngrpcutright = 0, li_notmoreshare = 0, li_showright, li_roundtype = 0; string sqlStr; ls_loantype = dw_main.GetItemString(1, "loantype_code"); ldc_loancredit = dw_main.GetItemDecimal(1, "loancredit_amt"); ldc_grpcredit = dw_main.GetItemDecimal(1, "loangrpcredit_amt"); ldc_loanregis = dw_main.GetItemDecimal(1, "loanreqregis_amt"); Decimal coll_percen = 0; // string sqlStr2 = @"select coll_percent // from LNLOANTYPECOLLUSE // where ( coop_id = {0} ) // and ( loantype_code = {1} ) and loancolltype_code = '02'"; // sqlStr2 = WebUtil.SQLFormat(sqlStr2, state.SsCoopControl, ls_loantype); // Sdt dt2 = WebUtil.QuerySdt(sqlStr2); // if (dt2.Next()) // { // coll_percen = dt2.GetDecimal("coll_percent"); // } sqlStr = @"select lngrpcutright_flag, notmoreshare_flag, maxloan_amt, loanpermgrp_code, lngrpkeepsum_flag, showright_flag, reqround_factor, reqround_type from lnloantype where ( coop_id = {0} ) and ( loantype_code = {1} )"; sqlStr = WebUtil.SQLFormat(sqlStr, state.SsCoopControl, ls_loantype); Sdt dt = WebUtil.QuerySdt(sqlStr); if (dt.Next()) { li_lngrpcutright = dt.GetInt32("lngrpcutright_flag"); li_notmoreshare = dt.GetInt32("notmoreshare_flag"); ldc_maxloan = dt.GetDecimal("maxloan_amt"); ls_permissgrp = dt.GetString("loanpermgrp_code"); li_kpsumflag = dt.GetInt32("lngrpkeepsum_flag"); li_showright = dt.GetInt32("showright_flag"); li_roundtype = dt.GetInt32("reqround_type"); ldc_roundfacter = dt.GetDecimal("reqround_factor"); } //lngrpcutright_flag ขอกู้ได้ไม่เกินวงเงินกู้กลุ่ม //notmoreshare_flag กู้ได้ไม่เกินหุ้นที่มี //maxloan_amt วงเงินกู้สูงสุดของเงินกู้ประเภทนี้ //loanpermgrp_code เงินกู้ประเภทนี้อยู่ในกลุ่มเงินกู้รหัสอะไร //lngrpkeepsum_flag การนับเงินกู้รวมใช้ไปหักยอดรอเรียกเก็บหรือเปล่า //showright_flag แสดงสิทธิกู้ตอนคำนวณสิทธิ์เสร็จแล้วหรือเปล่า ldc_permissamt = ldc_maxloan; // วงเงินกู้รวมใช้ไป ldc_grpuse = of_calpermissloangrpused(ls_permissgrp, li_kpsumflag); // ตรวจว่าต้องตัดยอดขอกู้จากยอดกู้กลุ่มหรือไม่ if (li_lngrpcutright == 1) { if (ldc_permissamt > (ldc_loancredit - ldc_grpuse)) { ldc_permissamt = (ldc_loancredit - ldc_grpuse); } if (ldc_permissamt < 0) { ldc_permissamt = 0; } } // check กับยอด credit if (ldc_permissamt > (ldc_grpcredit - ldc_grpuse)) { ldc_permissamt = (ldc_grpcredit - ldc_grpuse); } if (ldc_permissamt > ldc_loancredit) { ldc_permissamt = ldc_loancredit; } if (ldc_permissamt > ldc_maxloan) { ldc_permissamt = ldc_maxloan; } // ตรวจว่าห้ามกู้เกินหุ้นหรือเปล่า if (li_notmoreshare == 1) { sqlStr = @"select coll_percent from lnloantypecolluse where coop_id = {0} and loantype_code = {1} and loancolltype_code = '02'"; sqlStr = WebUtil.SQLFormat(sqlStr, state.SsCoopControl, ls_loantype); Sdt dt1 = WebUtil.QuerySdt(sqlStr); if (dt.Next()) { ldc_collperc = dt.GetDecimal("coll_percent"); ldc_sharestk = dw_main.GetItemDecimal(1, "share_balance"); ldc_temp = ldc_sharestk * ldc_collperc; // ถ้ามากกว่าหุ้นที่ใช้ได้ตัดยอดลง if (ldc_permissamt > ldc_temp) { ldc_permissamt = ldc_temp; } } } if (ldc_permissamt < 0) { ldc_permissamt = 0; } dw_main.SetItemDecimal(1, "loanpermiss_amt", ldc_permissamt); // ค่าเงินที่จะขอกู้ได้ if (ldc_permissamt > ldc_loanregis) { ldc_loanreq = ldc_loanregis; } else { ldc_loanreq = ldc_permissamt; } // ปัดยอดขอกู้ if (ldc_roundfacter != 0) { decimal ldc_tempfacter = Math.Abs(ldc_roundfacter); if ((ldc_loanreq % ldc_roundfacter) > 0) { if (ldc_roundfacter > 0) { ldc_loanreq = ldc_loanreq - (ldc_loanreq % ldc_roundfacter) + ldc_roundfacter; } else { ldc_loanreq = ldc_loanreq - (ldc_loanreq % ldc_roundfacter); } } } //dw_main.SetItemDecimal(1, "loanrequest_amt", ldc_loanreq); //Decimal share = dw_main.GetItemDecimal(1, "share_balance"); //ldc_maxloan = share * (coll_percen / 100); dw_main.SetItemDecimal(1, "loanrequest_amt", ldc_maxloan); HdCondition.Value = "true"; //pom - คิดงวดตามยอดขอกู้ of_initmaxperiod(ls_loantype, ldc_loanreq); //of_setintestimateloanreq(); } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage("of_initpermiss " + ex); } } /// /// set ดอกเบี้ยประมาณการ สำหรับคำนวณเงินเดือนคงเหลือ /// private void of_setintestimateloanreq() { decimal ldc_loanreq, ldc_intrate, ldc_intestimate; ldc_loanreq = dw_main.GetItemDecimal(1, "loanrequest_amt"); ldc_intrate = dw_main.GetItemDecimal(1, "identifycont_intrate"); ldc_intestimate = Convert.ToDecimal((Convert.ToDouble(ldc_loanreq) * (Convert.ToDouble(ldc_intrate) / 100.00) * (30.00 / 365.00))); dw_main.SetItemDecimal(1, "intestimate_amt", ldc_intestimate); } /// /// set ยอดหักจากใบคำขอ /// private void of_setpaymthlnreq() { string ls_loanpay; int li_lnpaytype; decimal ldc_intestimate, ldc_paymthlnreq = 0, ldc_reqpay; ls_loanpay = dw_main.GetItemString(1, "loanpay_code"); li_lnpaytype = Convert.ToInt32(dw_main.GetItemDecimal(1, "loanpayment_type")); ldc_reqpay = dw_main.GetItemDecimal(1, "period_payment"); ldc_intestimate = dw_main.GetItemDecimal(1, "intestimate_amt"); if (ls_loanpay != "KEP") { ldc_paymthlnreq = 0; } else { if (li_lnpaytype == 0) { ldc_paymthlnreq = 0; } else if (li_lnpaytype == 1) { ldc_paymthlnreq = ldc_reqpay + ldc_intestimate; } else if (li_lnpaytype == 2) { ldc_paymthlnreq = ldc_reqpay; } else if (li_lnpaytype == 3) { ldc_paymthlnreq = ldc_intestimate; } } dw_main.SetItemDecimal(1, "paymonth_lnreq", ldc_paymthlnreq); } /// /// คำนวณยอดขอกู้จากการชำระต่องวด /// private decimal of_calnetlnpermiss(int ai_paymenttype, int ai_period, decimal adc_netmthpay, decimal adc_intrate) { decimal ldc_permamt = 0; try { string sqlStr; int li_fixcaltype = 1; double ldc_temp, ldb_dayyear, ldc_ft = 1.00; ldb_dayyear = Convert.ToDouble(30) / Convert.ToDouble(365); adc_intrate = adc_intrate / 100; switch (ai_paymenttype) { case 0://ไม่มีการเรียกเก็บ ldc_permamt = 999999999999; break; case 1://คงต้น ldc_temp = Convert.ToDouble(ai_period) * (Convert.ToDouble(adc_intrate) * ldb_dayyear) + ldc_ft; ldc_permamt = Convert.ToDecimal((Convert.ToDouble(adc_netmthpay) * Convert.ToDouble(ai_period)) / ldc_temp); break; case 2://คงยอด double ldc_permamttmp = 1.00, ldc_fr = 0.00; //ดึงค่า config การคำนวณดอกเบี้ยเฉลี่ยต่อเดือน 1 คือ 30/365, 2 คือ /12 sqlStr = @"select fixpaycal_type from lnloanconstant where coop_id = '" + state.SsCoopControl + "'"; Sdt dt = WebUtil.QuerySdt(sqlStr); if (dt.Next()) { li_fixcaltype = dt.GetInt32("fixpaycal_type"); } if (li_fixcaltype == 1) { // ด/บ ทั้งปี / 12 ldc_temp = Math.Log(1 + (Convert.ToDouble(Convert.ToDouble(adc_intrate) / 12.00))); ldc_fr = Math.Exp(-ai_period * ldc_temp); ldc_permamttmp = (Convert.ToDouble(adc_netmthpay) * (ldc_ft - ldc_fr)) / ((Convert.ToDouble(adc_intrate) / 12)); } else { // ด/บ 30 วัน/เดือน ldc_temp = Math.Log(1 + (Convert.ToDouble(Convert.ToDouble(adc_intrate) / ldb_dayyear))); ldc_fr = Math.Exp(-ai_period * ldc_temp); ldc_permamttmp = (Convert.ToDouble(adc_netmthpay) * (ldc_ft - ldc_fr)) / ((Convert.ToDouble(adc_intrate) / ldb_dayyear)); } ldc_permamt = Convert.ToDecimal(ldc_permamttmp); break; case 3://เก็บแต่ดอกเบี้ย if (li_fixcaltype == 1) { ldc_permamt = Convert.ToDecimal(((Convert.ToDouble(adc_netmthpay) * 12) / Convert.ToDouble(adc_intrate))); } else { ldc_permamt = Convert.ToDecimal((Convert.ToDouble(adc_netmthpay) / (Convert.ToDouble(adc_intrate) * ldb_dayyear))); } break; } } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage("of_initpermiss" + ex); } return ldc_permamt; } /// /// คำนวณยอดขอกู้จากเงินเดือนคงเหลือ /// private decimal of_calmaxreqforsal() { decimal ldc_netreq = 100000; return ldc_netreq; } /// /// คำนวณเงินกู้กลุ่มที่ใช้ไป /// private decimal of_calpermissloangrpused(string as_permissgrp, int ai_kpsumflag) { decimal ldc_withdraw, ldc_balance, ldc_rkeepprin, ldc_grpuse = 0; int li_clrstatus, li_trnfer; string ls_lnpermgrp; for (int i = 1; i <= dw_clear.RowCount; i++) { ldc_withdraw = dw_clear.GetItemDecimal(i, "withdrawable_amt"); ldc_balance = dw_clear.GetItemDecimal(i, "principal_balance"); ldc_rkeepprin = dw_clear.GetItemDecimal(i, "rkeep_principal"); li_clrstatus = Convert.ToInt32(dw_clear.GetItemDecimal(i, "clear_status")); li_trnfer = Convert.ToInt32(dw_clear.GetItemDecimal(i, "transfer_status")); ls_lnpermgrp = dw_clear.GetItemString(i, "loanpermgrp_code"); if (li_clrstatus == 0 && li_trnfer == 0 && ls_lnpermgrp == as_permissgrp) { if (ai_kpsumflag == 1) { ldc_grpuse += ((ldc_withdraw + ldc_balance) - ldc_rkeepprin); } else { ldc_grpuse += (ldc_withdraw + ldc_balance); } } } return ldc_grpuse; } /// /// คำนวณยอดชำระ /// private void of_calperiodpayment() { decimal ldc_roundfacter = dw_main.GetItemDecimal(1, "payround_factor"); string ls_loantype = dw_main.GetItemString(1, "loantype_code"); Decimal li_installment = dw_main.GetItemDecimal(1, "period_payamt"); Decimal ldc_loanreq = dw_main.GetItemDecimal(1, "loanrequest_amt"); int li_paymenttype = Convert.ToInt32(dw_main.GetItemDecimal(1, "loanpayment_type")); decimal ldc_intrate = dw_main.GetItemDecimal(1, "identifycont_intrate"); //ดอกเบี้ย Decimal ldc_periodpay = 0, ldc_lastperiodpay = 0; //กำหนด ดอกเบี้ย ตั้งไว้ก่อน ldc_intrate = 1; if (ldc_intrate == 0) { LtServerMessage.Text = WebUtil.ErrorMessage("ไม่พบอัตราดอกเบี้ย กรุณาตรวจสอบ"); } double ldc_fr = 1, ldc_temp = 1; switch (li_paymenttype) { case 0: ldc_periodpay = 0; ldc_lastperiodpay = ldc_loanreq; break; case 1: if (li_installment == 0) { //Edit By BankCM //LtServerMessage.Text = WebUtil.ErrorMessage("กรุณาระบุงวดชำระ ของเงินกู้ประเภท " + ls_loantype); dw_main.SetItemDecimal(1, "period_payamt", 1); li_installment = 1; //dw_main.SetRow(1); //dw_main.SetColumn("period_payamt"); } ldc_periodpay = ldc_loanreq / li_installment; break; case 2: if (li_installment == 0) { LtServerMessage.Text = WebUtil.ErrorMessage("กรุณาระบุงวดชำระ ของเงินกู้ประเภท " + ls_loantype); // dw_main.SetItemString(1, "period_payamt", "กรอกเลข ที่นี่!!"); } int li_fixpaycaltype = Convert.ToInt32(dw_main.GetItemDecimal(1, "fixpaycal_type")); double ldb_fd = 0.00; if (li_fixpaycaltype == 1) { ldb_fd = 1.00 / 12.00; } else { ldb_fd = 30.00 / 365.00; } ldc_intrate = ldc_intrate / 100; ldc_temp = Math.Log(1.00 + (Convert.ToDouble(ldc_intrate) * ldb_fd)); ldc_fr = Math.Exp(-Convert.ToDouble(li_installment) * ldc_temp); ldc_periodpay = Convert.ToDecimal((Convert.ToDouble(ldc_loanreq) * (Convert.ToDouble(ldc_intrate) * ldb_fd)) / ((1.00 - ldc_fr))); break; case 3: ldc_periodpay = 0; ldc_lastperiodpay = ldc_loanreq; break; } //ปัดยอดชำระ if (ldc_roundfacter != 0) { decimal ldc_tempfacter = Math.Abs(ldc_roundfacter); if ((ldc_periodpay % ldc_roundfacter) > 0) { if (ldc_roundfacter > 0) { ldc_periodpay = ldc_periodpay - (ldc_periodpay % ldc_roundfacter) + ldc_roundfacter; } else { ldc_periodpay = ldc_periodpay - (ldc_periodpay % ldc_roundfacter); } } } dw_main.SetItemDecimal(1, "period_payment", ldc_periodpay); of_lastperiodpay();//pom : Lastperiodpay.01 of_setpaymthlnreq(); } /// /// คำนวณ /// private int of_calinstallment() { //-------------------------- // หาจำนวน งวดที่ต้องผ่อนชำระ โดยการส่งค่า // // argument // 1. adc_principal เงินต้น // 2. adc_payamt จำนวนชำระต่องวด (ref) // 3. adc_lastperiod จำนวนชำระงวดสุดท้าย (ref) // 4. ai_paytype รูปแบบการชำระ (คงต้น = 1, คงยอด = 2) // 5. adc_intrate อัตราดอกเบี้ย // 6. al_factor จำนวนหลักที่จะปัดตามกำหนด // 7. ai_roundtype รูปแบบการปัด<ขึ้น,ลง> // 8. ai_fixcaltype รูปแบบการคำนวณแบบคงยอด ( monthaverage = 1, 30/month= 2 ) // // return // จำนวนงวดที่ต้องผ่อนชำระ // -1 สำหรับกรณีผิดพลาด //-------------------------- int li_period = 0, li_factor = 0, li_paytype = 0; decimal ldc_mod = 0, ldc_principal = 0, ldc_payamt = 0; ldc_principal = dw_main.GetItemDecimal(1, "loanrequest_amt"); ldc_payamt = dw_main.GetItemDecimal(1, "period_payment"); li_paytype = Convert.ToInt32(dw_main.GetItemDecimal(1, "loanpayment_type")); //li_factor = Convert.ToInt32(dw_main.GetItemDecimal(1, "payround_factor")); //// parameter check //if (ldc_principal == 0 || ldc_payamt == 0) //{ // return -1; //} //// ปรับค่าจำนวนชำระต่องวดด้วย factor //if (li_factor != 0) //{ // ldc_payamt = ldc_payamt + li_factor; //} //if al_factor > 0 then // ldc_mod = mod( adc_payamt, al_factor) // if ldc_mod > 0 then // adc_payamt = adc_payamt - ldc_mod // if ai_roundtype = 1 then // adc_payamt = adc_payamt + al_factor // end if // if adc_payamt <= 0 then // adc_payamt = al_factor // end if // end if //end if switch (li_paytype) { case 1: li_period = Convert.ToInt32((int)Math.Ceiling(ldc_principal / ldc_payamt)); break; case 2: decimal ldc_interest = 0, ldc_prinpay = 0, ldc_identifyintrate; int li_fixcaltype = 1; li_fixcaltype = Convert.ToInt32(dw_main.GetItemDecimal(1, "fixpaycal_type")); ldc_identifyintrate = dw_main.GetItemDecimal(1, "identifycont_intrate"); while (ldc_principal > 0) { if (li_fixcaltype == 1) { ldc_interest = Convert.ToDecimal((Convert.ToDouble(ldc_principal) * (Convert.ToDouble(ldc_identifyintrate) / 100.00)) / 12.00); } else { ldc_interest = Convert.ToDecimal(((Convert.ToDouble(ldc_principal) * (Convert.ToDouble(ldc_identifyintrate) / 100.00)) / 365.00) * 30.00); } // check ว่ายอด ด/บ มากกว่ายอดชำระ/งวด หรือไม่ if (ldc_interest >= ldc_payamt) { LtServerMessage.Text = WebUtil.ErrorMessage("ชำระต่อเดือน, ยอดชำระต่อเดือน น้อยกว่ายอด ด/บ ที่คิดได้ ( เงินต้น = " + ldc_principal.ToString("#,##") + ")" + "\nยอดชำระต่อเดือน = " + ldc_payamt.ToString("#,##") + "\nยอดดอกเบี้ยที่คิดได้ = " + ldc_interest.ToString("#,##") + "\nโปรแกรมไม่สามารถคำนวณงวดการชำระได้"); return -1; } ldc_prinpay = ldc_payamt - ldc_interest; if (ldc_prinpay > ldc_principal) { ldc_prinpay = ldc_principal; } ldc_principal = ldc_principal - ldc_prinpay; li_period++; } break; } return li_period; } /// คำนวน งวดสุดท้าย ย้อนกลับ private void of_lastperiodpay() //pom : of_lastperiodpay คำนวณงวดสุดท้ายและ { string ls_loantype = dw_main.GetItemString(1, "loantype_code"); Decimal maxsend_payamt = dw_main.GetItemDecimal(1, "maxsend_payamt"); Decimal period_payamt = dw_main.GetItemDecimal(1, "period_payamt"); Decimal period_payment = dw_main.GetItemDecimal(1, "period_payment"); Decimal loanrequest_amt = dw_main.GetItemDecimal(1, "loanrequest_amt"); decimal loanpayment_type = dw_main.GetItemDecimal(1, "loanpayment_type"); decimal custompayment_flag = dw_main.GetItemDecimal(1, "custompayment_flag"); //decimal loanpayment_status = dw_main.GetItemDecimal(1, "loanpayment_status"); //decimal ldc_intrate = dw_main.GetItemDecimal(1, "int_contintrate"); decimal ldc_intrate = dw_main.GetItemDecimal(1, "identifycont_intrate"); //คำนวณงวดสุดท้าย decimal ldc_period_lastpayment, ldc_tmp, ldc_diff, ldc_newpayamt; ldc_period_lastpayment = period_payment; ldc_newpayamt = 0; if (loanpayment_type == 1) { // ldc_newpayamt = Math.Ceiling(loanrequest_amt / period_payment); //ldc_tmp = ldc_newpayamt * period_payment; ldc_tmp = period_payment; // period_payamt = ldc_newpayamt; if (ldc_tmp != loanrequest_amt) { ldc_diff = ldc_tmp - loanrequest_amt; if (ldc_diff > period_payment) { ldc_diff = ldc_diff - period_payment; period_payamt = period_payamt - 1; } ldc_period_lastpayment = period_payment - ldc_diff; } else { ldc_period_lastpayment = period_payment; } } else { decimal ldc_temptot, ldc_tempint, ldc_tempay, ldc_tempreq; int i; int li_fixcaltype = 1; //ldc_intrate = dw_main.GetItemDecimal(1, "int_contintrate"); ldc_intrate = ldc_intrate / 100; //ตั้งแต่ BAAC ldc_tempreq = loanrequest_amt; ldc_temptot = 0; for (i = 1; (i <= period_payamt); i++) { if (ldc_temptot >= loanrequest_amt) break; ldc_tempay = 0; ldc_tempint = 0; if (li_fixcaltype == 1) //เฉลี่ยรายเดือน { ldc_tempint = (ldc_tempreq * ldc_intrate) * (1 / 12); ldc_tempay = period_payamt - ldc_tempint; } else if (li_fixcaltype == 2) //เฉลี่ยรายวัน { ldc_tempint = (ldc_tempreq * ldc_intrate) * (30 / 365); ldc_tempay = period_payamt - ldc_tempint; } if ((ldc_tempreq - ldc_temptot) < ldc_tempay) { ldc_period_lastpayment = ldc_tempay + ldc_tempint; } else { ldc_period_lastpayment = period_payment; } ldc_temptot = ldc_temptot + ldc_tempay; ldc_tempreq = ldc_tempreq - ldc_tempay; } } dw_main.SetItemDecimal(1, "period_lastpayment", ldc_period_lastpayment); dw_main.SetItemDecimal(1, "period_payamt", period_payamt); } /// /// set ค่าจากข้อมูลลงรับ /// private void of_initreqloanregis(string member_no, string loantype_code) { try { string SqlLoanRegis = "select reqregister_docno, loanrequest_amt,loanapprove_amt,remark " + " from lnreqloanregister " + " where member_no = '" + member_no + "' " + " and loantype_code = '" + loantype_code + "' " + " and reqregister_status = 8 " + " and rownum = 1 " + " order by lnreqreceive_date desc "; Sdt DtLoanRegis = WebUtil.QuerySdt(SqlLoanRegis); if (DtLoanRegis.Rows.Count > 0) { dw_main.SetItemDecimal(1, "loanreqregis_amt", Convert.ToDecimal(DtLoanRegis.Rows[0]["loanrequest_amt"].ToString())); dw_main.SetItemString(1, "ref_registerno", DtLoanRegis.GetString("reqregister_docno")); } } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage("of_Initreqloanregis" + ex); } } /// /// set ยอดหักจากสหกรณ์ /// private void of_initpaymonthcoop() { try { decimal ldc_sumpay = 0, ldc_periodpay = 0, ldc_sumloan = 0, ldc_shrperiod, ldc_intest; int li_clrstatus, li_shrpaystatus, li_paytype; string ls_loanpay, ls_reqloanpay; // ดึงรายการหุ้น ldc_shrperiod = dw_main.GetItemDecimal(1, "share_periodvalue"); //ดึงรายการหนี้ for (int i = 1; i <= dw_clear.RowCount; i++) { li_clrstatus = Convert.ToInt32(dw_clear.GetItemDecimal(i, "clear_status")); string contno = dw_clear.GetItemString(i, "loancontract_no"); if (li_clrstatus == 0) { try { ls_loanpay = dw_clear.GetItemString(i, "loanpay_code"); } catch { ls_loanpay = "KEP"; } if (ls_loanpay == "KEP") { li_paytype = Convert.ToInt32(dw_clear.GetItemDecimal(i, "loanpayment_type")); ldc_periodpay = dw_clear.GetItemDecimal(i, "period_payment"); ldc_intest = dw_clear.GetItemDecimal(i, "intestimate_amt"); if (li_paytype == 0) { ldc_periodpay = 0; } else if (li_paytype == 1) { ldc_periodpay += ldc_intest; } else if (li_paytype == 3) { ldc_periodpay = ldc_intest; } ldc_sumloan = ldc_sumloan + ldc_periodpay; } } } ldc_sumpay = ldc_sumloan + ldc_shrperiod; dw_main.SetItemDecimal(1, "paymonth_coop", ldc_sumpay); } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage("of_initpaymonthcoop" + ex); } } /// /// set งวดสูงสุด /// private void of_initmaxperiod(string as_loantype, decimal adc_requestamt) { try { string sqlStr; sqlStr = @"select max_period from lnloantypeperiod where coop_id = {0} and loantype_code = {1} and {2} between money_from and money_to"; sqlStr = WebUtil.SQLFormat(sqlStr, state.SsCoopControl, as_loantype, adc_requestamt); Sdt dt = WebUtil.QuerySdt(sqlStr); if (dt.Next()) { dw_main.SetItemDecimal(1, "maxperiod_payamt", dt.GetInt32("max_period")); dw_main.SetItemDecimal(1, "period_payamt", dt.GetInt32("max_period")); } } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage("of_initmaxperiod" + ex); } } /// /// set งวดส่ง /// private void of_initperiodsend() { int li_loanright = 0; li_loanright = Convert.ToInt32(dw_main.GetItemDecimal(1, "loanright_type")); if (li_loanright == 3) { dw_main.SetItemDecimal(1, "period_payamt", dw_main.GetItemDecimal(1, "maxsend_payamt")); return; } try { int li_periodpay = 0, li_lnoverretry, li_retrysendtype, li_lnoverstatus, period_payamt; // li_maxperiod = 0,li_retryage, string ls_loantype = dw_main.GetItemString(1, "loantype_code"); li_lnoverretry = Convert.ToInt32(dw_main.GetItemDecimal(1, "lnoverretry_period")); li_retrysendtype = Convert.ToInt32(dw_main.GetItemDecimal(1, "retryloansend_type")); li_lnoverstatus = Convert.ToInt32(dw_main.GetItemDecimal(1, "lnoverretry_status")); period_payamt = Convert.ToInt32(dw_main.GetItemDecimal(1, "maxsend_payamt")); // li_retryage = Convert.ToInt32(dw_main.GetItemDecimal(1, "retry_age")); // li_maxperiod = Convert.ToInt32(dw_main.GetItemDecimal(1, "maxperiod_payamt")); //ห้ามส่งเกินเกษียณ /* if (li_retrysendtype == 0) { li_periodpay = li_retryage; } //ส่งเกินได้ตามงวดที่ระบุ ไม่ตรวจสอบเงินไข if (li_retrysendtype == 1) { li_periodpay = li_retryage + li_lnoverretry; } //ส่งเกินได้ตามงวดที่ระบุ ตรวจสอบเงินไข if (li_retrysendtype == 2) { if (li_lnoverstatus == 1) { li_periodpay = li_retryage + li_lnoverretry; } else { li_periodpay = li_retryage; } }*/ /* if (li_periodpay > li_maxperiod) { li_periodpay = li_maxperiod; }*/ // dw_main.SetItemDecimal(1, "maxsend_payamt", period_payamt); // dw_main.SetItemDecimal(1, "period_payamt", period_payamt); // dw_main.SetItemDecimal(1, "maxsend_payamt", period_payamt); // dw_main.SetItemDecimal(1, "period_payamt", period_payamt); } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage("of_initperiodsend" + ex); } } /// /// init ค่าธรรมเนียมค่าบริการ /// private void of_initotherpay_fsv() { string ls_itemcode, ls_contno; int li_clrstatus, li_lastperiod = 0; decimal ldc_fineamt = 0, ldc_sumfine = 0, ldc_lnapprove = 0, ldc_paypercent = 0, ldc_prnbalance = 0, ldc_withdraw = 0, ldc_loanamt = 0, ldc_payamt; for (int i = 1; i <= dw_clear.RowCount; i++) { li_clrstatus = Convert.ToInt32(dw_clear.GetItemDecimal(i, "clear_status")); ldc_fineamt = dw_clear.GetItemDecimal(i, "fine_amt"); if (li_clrstatus == 1 && ldc_fineamt > 0) { ldc_sumfine += ldc_fineamt; //ls_contno = dw_clear.GetItemString(i, "loancontract_no"); //li_lastperiod = Convert.ToInt32(dw_clear.GetItemDecimal(i, "last_periodpay")); //ldc_lnapprove = dw_clear.GetItemDecimal(i, "loanapprove_amt"); //ldc_prnbalance = dw_clear.GetItemDecimal(i, "principal_balance"); //ldc_withdraw = dw_clear.GetItemDecimal(i, "withdrawable_amt"); //ldc_loanamt = ldc_lnapprove - ldc_withdraw; //ldc_payamt = ldc_loanamt - ldc_prnbalance; //ldc_paypercent = (ldc_payamt * 100) / ldc_loanamt; //is_massalert += "\\nสัญญา " + ls_contno + " งวดชำระแล้ว = " + li_lastperiod.ToString() + ",% ชำระแล้ว = " + ldc_paypercent.ToString("#,##0.00") + "% ต้องคิดค่าบริการ เป็นจำนวนเงิน " + ldc_fineamt.ToString("#,##0.00"); } } if (ldc_sumfine > 0) { int row = 0; for (int r = 1; r <= dw_otherclr.RowCount; r++) { ls_itemcode = dw_otherclr.GetItemString(r, "clrothertype_code"); if (ls_itemcode == "FSV") { row = r; break; } } if (row == 0) { row = dw_otherclr.InsertRow(0); } dw_otherclr.SetItemString(row, "clrothertype_code", "FSV"); dw_otherclr.SetItemString(row, "clrother_desc", "ค่าธรรมเนียมในการบริหาร"); dw_otherclr.SetItemDecimal(row, "clrother_amt", ldc_sumfine); dw_otherclr.SetItemDecimal(row, "clear_status", 1); //is_massalert = "\\nมีสัญญาเก่าชำระหนี้ไม่ถึงตามที่กำหนด " + is_massalert; } } /// /// ซื้อหุ้นเพิ่ม /// private void of_initclearshare() { try { string sqlStr, ls_loantype, ls_lnpermgrp, ls_clrpermgrp; int li_shrbuytype, li_clrstatus, li_shrcntflag; decimal ldc_calamt = 0, ldc_loanreq = 0, ldc_shrpercent = 0, ldc_shrstk = 0, ldc_reqshare, ldc_clrshare; ls_loantype = dw_main.GetItemString(1, "loantype_code"); ldc_loanreq = dw_main.GetItemDecimal(1, "loanrequest_amt"); ldc_shrstk = dw_main.GetItemDecimal(1, "share_balance"); sqlStr = @"select shrstk_buytype from lnloantype where coop_id = {0} and loantype_code = {1}"; sqlStr = WebUtil.SQLFormat(sqlStr, state.SsCoopControl, ls_loantype); Sdt dt = WebUtil.QuerySdt(sqlStr); if (dt.Next()) { li_shrbuytype = dt.GetInt32("shrstk_buytype"); if (li_shrbuytype == 0) { return; } switch (li_shrbuytype) { case 1://เทียบ %หุ้น ที่มีกับยอดขอกู้ ldc_calamt = 0; break; case 2://เทียบ %หุ้น ที่มีกับยอดหนี้คงเหลือทั้งหมดกับยอดขอกู้ for (int r = 1; r <= dw_clear.RowCount; r++) { li_clrstatus = Convert.ToInt32(dw_clear.GetItemDecimal(r, "clear_status")); li_shrcntflag = Convert.ToInt32(dw_clear.GetItemDecimal(r, "shrstkcount_flag")); if (li_clrstatus == 0 && li_shrcntflag == 1) { ldc_calamt += dw_clear.GetItemDecimal(r, "principal_balance"); } } break; case 3://เทียบ %หุ้น ที่มีกับยอดหนี้ขอกลุ่มเงินกู้นี้ ls_lnpermgrp = dw_main.GetItemString(1, "loanpermgrp_code"); for (int r = 1; r <= dw_clear.RowCount; r++) { li_clrstatus = Convert.ToInt32(dw_clear.GetItemDecimal(r, "clear_status")); li_shrcntflag = Convert.ToInt32(dw_clear.GetItemDecimal(r, "shrstkcount_flag")); ls_clrpermgrp = dw_clear.GetItemString(r, "loanpermgrp_code"); if (li_clrstatus == 0 && li_shrcntflag == 1 && ls_lnpermgrp == ls_clrpermgrp) { ldc_calamt += dw_clear.GetItemDecimal(r, "principal_balance"); } } break; } ldc_calamt = ldc_calamt + ldc_loanreq; sqlStr = @"select sharestk_percent from lnloantypebuyshare where coop_id = {0} and loantype_code = {1} and {2} between startloan_amt and endloan_amt"; sqlStr = WebUtil.SQLFormat(sqlStr, state.SsCoopControl, ls_loantype, ldc_calamt); dt = WebUtil.QuerySdt(sqlStr); if (dt.Next()) { int row = 0; for (int r = 1; r <= dw_otherclr.RowCount; r++) { string ls_item = dw_otherclr.GetItemString(r, "clrothertype_code"); if (ls_item == "SHR") { row = r; } } ldc_shrpercent = dt.GetDecimal("sharestk_percent"); ldc_reqshare = ldc_calamt * (ldc_shrpercent / 100); if (ldc_reqshare % 10 != 0) { decimal sharemod = ldc_reqshare % 10; ldc_reqshare = ldc_reqshare + (10 - sharemod); } //if (ldc_shrstk > ldc_reqshare && row > 0) //{ // //dw_otherclr.DeleteRow(row); //} //else ////if (ldc_shrstk < ldc_reqshare) เก่า //{ //ldc_clrshare = ldc_reqshare - ldc_shrstk; ////if ((ldc_clrshare % 10) > 0) ////{ //// ldc_clrshare = ldc_clrshare - (ldc_clrshare % 10) + 10; ////} //if (row == 0) //{ // row = dw_otherclr.InsertRow(0); //} //dw_otherclr.SetItemString(row, "clrothertype_code", "SHR"); //dw_otherclr.SetItemString(row, "clrother_desc", "ซื้อหุ้นเพิ่ม"); //dw_otherclr.SetItemDecimal(row, "clear_status", 1); //dw_otherclr.SetItemDecimal(row, "clrother_amt", ldc_clrshare); if (row == 0) // เงื่อนไข การซื้อหุ้นเพิ่ม กล้า { row = dw_otherclr.InsertRow(0); } if (ldc_reqshare < 10) { ldc_reqshare = 10; } else { dw_otherclr.SetItemString(row, "clrothertype_code", "SHR"); dw_otherclr.SetItemString(row, "clrother_desc", "ซื้อหุ้นเพิ่ม"); dw_otherclr.SetItemDecimal(row, "clear_status", 1); dw_otherclr.SetItemDecimal(row, "clrother_amt", ldc_reqshare); is_massalert += "\\n\\nมีทุนเรือนหุ้นไม่ถึงตามที่กำหนด \\nมูลค่าหนี้เงินกู้ที่นำมาคำนวณการซื้อหุ้น = " + ldc_calamt.ToString("#,##0.00") + "\\nต้องซื้อหุ้นเพิ่มเป็นจำนวนเงิน = " + ldc_reqshare.ToString("#,##0.00"); } } } //} else { for (int r = 1; r <= dw_otherclr.RowCount; r++) { string ls_item = dw_otherclr.GetItemString(r, "clrothertype_code"); if (ls_item == "SHR") { dw_otherclr.DeleteRow(r); break; } } } } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage("of_initclearshare" + ex); }; } /// /// alert ข้อความแจ้งเตือนต่างๆ /// private void of_initwarnings() { if (is_massalert != "") { this.SetOnLoadedScript("alert('" + is_massalert + "')"); } } /// /// init หลักประกันตามค่าคงที่ /// private void of_initcolluse() { string sqlStr, ls_loantype; int li_useshare = 0, li_useman, li_row = 0; decimal ldc_loanreq; ls_loantype = dw_main.GetItemString(1, "loantype_code"); ldc_loanreq = dw_main.GetItemDecimal(1, "loanrequest_amt"); if (ldc_loanreq <= 0) { ldc_loanreq = 1; } sqlStr = @"select useman_amt, useshare_flag from lnloantypereqgrt where coop_id = {0} and loantype_code = {1} and {2} between money_from and money_to"; sqlStr = WebUtil.SQLFormat(sqlStr, state.SsCoopControl, ls_loantype, ldc_loanreq); dt = WebUtil.QuerySdt(sqlStr); if (dt.Next()) { li_useman = dt.GetInt32("useman_amt"); li_useshare = dt.GetInt32("useshare_flag"); if (li_useshare == 1) { //for (int r = 1; r <= dw_coll.RowCount; r++) //{ // string ls_colltype; // ls_colltype = dw_coll.GetItemString(r, "loancolltype_code"); // if (ls_colltype == "02") // { // li_row = r; // CheckCollPermiss(); // } //} if (dw_coll.GetColumnNumber() > 0) { dw_coll.SetItemString(1, "loancolltype_code", "02"); CheckCollPermiss(); } else { dw_coll.InsertRow(0); dw_coll.SetItemString(1, "loancolltype_code", "02"); CheckCollPermiss(); } } //if (li_row <= 0) //ไม่ต้อง __เพิ่มหุ้นค้ำอัตโนมัติ //{ // li_row = dw_coll.InsertRow(0); // dw_coll.SetItemString(li_row, "loancolltype_code", "02"); // HdRefcollrow.Value = li_row.ToString(); // CheckCollPermiss(); //} if (li_useman > 0) { li_row = 0; for (int r = 1; r <= li_useman; r++) { li_row = dw_coll.InsertRow(0); dw_coll.SetItemString(li_row, "loancolltype_code", "01"); } } } } /// /// ตรวจสอบหลักประกัน /// private void CheckCollPermiss() { string as_loantype = "", as_colltype = "", as_collno = ""; int row_coll; //แถว ค้ำประกัน try { row_coll = Convert.ToInt32(HdRefcollrow.Value); } catch { row_coll = 1; } as_loantype = dw_main.GetItemString(1, "loantype_code"); try { as_colltype = dw_coll.GetItemString(row_coll, "loancolltype_code"); } catch { as_colltype = ""; } as_collno = HdRefcoll.Value; //ประเภทหลักประกันเป็น หุ้น if (as_colltype == "02") { try { as_collno = dw_main.GetItemString(1, "member_no"); } catch { as_collno = ""; } }//ประเภทหลักประกันเป็น หลักทรัพย์ else if (as_colltype == "04") { try { as_collno = HdRefcollNO.Value; } catch { as_collno = ""; } }//ประเภทหลักประกันเป็น เงินฝาก else if (as_colltype == "03") { try { as_collno = dw_coll.GetItemString(row_coll, "ref_collno"); } catch { as_collno = ""; } }//ประเภทหลักประกัน ตำแหน่ง else if (as_colltype == "55") { try { as_collno = dw_main.GetItemString(1, "member_no"); } catch { as_collno = ""; } } else if (as_collno != "") { try { as_collno = WebUtil.MemberNoFormat(as_collno); } catch { as_collno = ""; } } try { Boolean result_chk = ChkSameColl(as_collno, row_coll, as_colltype); if (result_chk == true && as_collno != "") { string sqlStr = ""; string description = ""; //คน if (as_colltype == "01") { //เช็คสิทธิ์การค้ำประกัน (as_reqlntype, as_colltype, as_refcoopid, as_refcollno); // int result = wcf.Shrlon.of_isvalidcoll(state.SsWsPass, as_loantype, as_colltype, state.SsCoopControl, as_collno);//pb120 int result = wcf.NShrlon.of_isvalidcoll(state.SsWsPass, as_loantype, as_colltype, state.SsCoopControl, as_collno); //pn125 if (result == 1 && as_collno != "") { DateTime ldtm_loanreq = dw_main.GetItemDateTime(1, "loanrequest_date"); int li_retryage = 0; string sql = @"select mbucfprename.prename_desc||mbmembmaster.memb_name||' '||mbmembmaster.memb_surname as member_name from mbmembmaster, mbucfprename where ( mbmembmaster.prename_code = mbucfprename.prename_code ) and ( mbmembmaster.coop_id = {0} ) and ( mbmembmaster.member_no = {1} )"; sql = WebUtil.SQLFormat(sql, state.SsCoopControl, as_collno, ldtm_loanreq); dt = ta.Query(sql); if (dt.Next()) { description = dt.GetString("member_name"); dw_coll.SetItemString(row_coll, "ref_collno", as_collno); dw_coll.SetItemString(row_coll, "description", description); //li_retryage = dt.GetInt32("retry_age"); //int li_periodpay = Convert.ToInt32(dw_main.GetItemDecimal(1, "period_payamt")); //if (li_retryage < li_periodpay) //{ // LtServerMessagecoll.Text = WebUtil.WarningMessage("ผู้ค้ำคนนี้ ค้ำประกันได้สูงสุด " + li_retryage + " งวด ซื่งน้อยกว่างวดขอกู้"); //} } dw_coll.SetItemDecimal(row_coll, "collbase_amt", 0); dw_coll.SetItemDecimal(row_coll, "collbase_percent", 0); dw_coll.SetItemDecimal(row_coll, "collmax_amt", 0); dw_coll.SetItemDecimal(row_coll, "collbalance_amt", 0); dw_coll.SetItemDecimal(row_coll, "collactive_amt", 0); dw_coll.SetItemDecimal(row_coll, "collactive_percent", 0); dw_coll.SetItemDecimal(row_coll, "collused_amt", 0); } // if (as_colltype == "01") // { // //เช็คสิทธิ์การค้ำประกัน (as_reqlntype, as_colltype, as_refcoopid, as_refcollno); // // int result = wcf.Shrlon.of_isvalidcoll(state.SsWsPass, as_loantype, as_colltype, state.SsCoopControl, as_collno);//pb120 // int result = wcf.NShrlon.of_isvalidcoll(state.SsWsPass, as_loantype, as_colltype, state.SsCoopControl, as_collno); //pn125 // if (result == 1 && as_collno != "") // { // DateTime ldtm_loanreq = dw_main.GetItemDateTime(1, "loanrequest_date"); // int li_retryage = 0; // string sql = @"select mbucfprename.prename_desc||mbmembmaster.memb_name||' '||mbmembmaster.memb_surname as member_name, // // from mbmembmaster, // mbucfprename // where ( mbmembmaster.prename_code = mbucfprename.prename_code ) // and ( mbmembmaster.coop_id = {0} ) // and ( mbmembmaster.member_no = {1} )"; // sql = WebUtil.SQLFormat(sql, state.SsCoopControl, as_collno, ldtm_loanreq); // dt = ta.Query(sql); // if (dt.Next()) // { // description = dt.GetString("member_name"); // dw_coll.SetItemString(row_coll, "ref_collno", as_collno); // dw_coll.SetItemString(row_coll, "description", description); // //li_retryage = dt.GetInt32("retry_age"); // int li_periodpay = Convert.ToInt32(dw_main.GetItemDecimal(1, "period_payamt")); // //if (li_retryage < li_periodpay) // //{ // // LtServerMessagecoll.Text = WebUtil.WarningMessage("ผู้ค้ำคนนี้ ค้ำประกันได้สูงสุด " + li_retryage + " งวด ซื่งน้อยกว่างวดขอกู้"); // //} // } // } GetCollPermiss(); }//หุ้น else if (as_colltype == "02") { dw_coll.SetItemString(row_coll, "ref_collno", as_collno); dw_coll.SetItemString(row_coll, "description", "ทุนเรือนหุ้น " + dw_main.GetItemString(1, "member_name")); GetCollPermiss(); } else if (as_colltype == "03") { sqlStr = @"select deptaccount_name from dpdeptmaster where deptclose_status = 0 and deptaccount_no = '" + as_collno + "'"; dt = ta.Query(sqlStr); if (dt.Next()) { description = dt.GetString("deptaccount_name"); dw_coll.SetItemString(row_coll, "ref_collno", as_collno); dw_coll.SetItemString(row_coll, "description", "บัญชี" + description); } GetCollPermiss(); }//หลักทรัพย์ else if (as_colltype == "04") { sqlStr = @"select collmast_desc , redeem_flag from lncollmaster where collmast_no = '" + as_collno + "'"; dt = ta.Query(sqlStr); if (dt.Next()) { description = dt.GetString("collmast_desc"); dw_coll.SetItemString(row_coll, "ref_collno", as_collno); dw_coll.SetItemString(row_coll, "description", description); } GetCollPermiss(); } //Edit By BankCM For get position coll else if (as_colltype == "55") { decimal collactive_percent = 0, collpermiss = 0, collmaxcoll = 0; if ((dw_coll.RowCount - 1) <= 1) { for (int i = 1; i <= dw_coll.RowCount - 1; i++) { collactive_percent = 0; collpermiss = 0; try { collpermiss = collpermiss + dw_coll.GetItemDecimal(i, "collactive_amt"); } catch { collpermiss = collpermiss + 0; } try { collactive_percent = collactive_percent + dw_coll.GetItemDecimal(i, "collactive_percent"); } catch { collactive_percent = collactive_percent + 0; } } collpermiss = dw_main.GetItemDecimal(1, "loanrequest_amt") - collpermiss; collactive_percent = 100 - collactive_percent; collmaxcoll = dw_main.GetItemDecimal(1, "loanrequest_amt"); } else { collpermiss = dw_main.GetItemDecimal(1, "loanrequest_amt"); collactive_percent = 100; collmaxcoll = dw_main.GetItemDecimal(1, "loanrequest_amt"); } dw_coll.SetItemString(row_coll, "ref_collno", dw_main.GetItemString(1, "member_no")); dw_coll.SetItemString(row_coll, "description", dw_main.GetItemString(1, "member_name")); dw_coll.SetItemDecimal(row_coll, "collbalance_amt", collpermiss); dw_coll.SetItemDecimal(row_coll, "collbase_amt", collpermiss); dw_coll.SetItemDecimal(row_coll, "collactive_amt", collpermiss); dw_coll.SetItemDecimal(row_coll, "collactive_percent", collactive_percent); dw_coll.SetItemDecimal(row_coll, "collbase_percent", 100); dw_coll.SetItemDecimal(row_coll, "collmax_amt", collmaxcoll); } } } catch (Exception ex) { LtServerMessagecoll.Text += WebUtil.ErrorMessage(ex); } } /// /// ตรวจสอบสิทธิ์ค้ำ /// private void of_recalcollpermiss() { HdCondition.Value = "true"; string ls_memno = "", ls_loantype = "", ls_colltype = "", ls_collno = "", ls_reqdocno, ls_excludecont = ""; decimal ldc_collbaseamt = 0, ldc_maxcoll = 0, ldc_collbasepercent = 0, ldc_collusecont = 0, ldc_collusereq = 0, ldc_collbal = 0; int li_clrstatus = 0; DateTime ldtm_lnreq; ls_memno = dw_main.GetItemString(1, "member_no"); ls_loantype = dw_main.GetItemString(1, "loantype_code"); ls_reqdocno = dw_main.GetItemString(1, "loanrequest_docno"); ldtm_lnreq = dw_main.GetItemDateTime(1, "loanrequest_date"); for (int i = 1; i <= dw_clear.RowCount; i++) {//ดึงเลขที่สัญญาหักกลบที่ถูกเลือก li_clrstatus = Convert.ToInt32(dw_clear.GetItemDecimal(i, "clear_status")); if (li_clrstatus == 1) { ls_excludecont += "," + dw_clear.GetItemString(i, "loancontract_no"); } } if (ls_excludecont != "") { ls_excludecont = ls_excludecont.Substring(1); } for (int r = 1; r <= dw_coll.RowCount; r++) { ls_colltype = dw_coll.GetItemString(r, "loancolltype_code"); ls_collno = dw_coll.GetItemString(r, "ref_collno"); if (ls_collno.Trim() == "") { continue; } try {//สิทธิค้ำสูงสุด if (ls_colltype == "04") { string sql = @"select est_price, est_percent from lncollmaster where ( coop_id = {0} ) and ( collmast_no = {1} )"; sql = WebUtil.SQLFormat(sql, state.SsCoopControl, ls_collno); dt = ta.Query(sql); if (dt.Next()) { ldc_collbaseamt = dt.GetDecimal("est_price"); ldc_collbasepercent = dt.GetDecimal("est_percent"); ldc_maxcoll = ldc_collbaseamt; } } else { wcf.NShrlon.of_getcollpermiss(state.SsWsPass, ls_loantype, ls_colltype, state.SsCoopControl, ls_collno, ldtm_lnreq, ref ldc_collbaseamt, ref ldc_maxcoll, ref ldc_collbasepercent); //pb125 } dw_coll.SetItemDecimal(r, "collbase_amt", ldc_collbaseamt); dw_coll.SetItemDecimal(r, "collbase_percent", ldc_collbasepercent); dw_coll.SetItemDecimal(r, "collmax_amt", ldc_maxcoll); } catch (Exception ex) { LtServerMessagecoll.Text += WebUtil.WarningMessage(ex); } //เฉพาะคนค้ำต้องตรวจนับสัญญา if (ls_colltype == "01") { try { //int result = wcf.Shrlon.of_checkcollmancount(state.SsWsPass, state.SsCoopControl, ls_collno, ls_memno, ls_loantype, ls_excludecont, ls_reqdocno); //pb120 int result = wcf.NShrlon.of_checkcollmancount(state.SsWsPass, state.SsCoopControl, ls_collno, ls_memno, ls_loantype, ls_excludecont, ls_reqdocno); //pb125 } catch (Exception ex) { LtServerMessagecoll.Text += WebUtil.ErrorMessage(ex); } } try {//สิทธิ์ค้ำที่ใช้ไปของใบคำขอ //ldc_collusecont = wcf.Shrlon.of_getcollusecontamt(state.SsWsPass, state.SsCoopControl, ls_collno, ls_loantype, ls_colltype, ls_excludecont, ls_reqdocno); //pb120 ldc_collusecont = wcf.NShrlon.of_getcollusecontamt(state.SsWsPass, state.SsCoopControl, ls_collno, ls_loantype, ls_colltype, ls_excludecont, ls_reqdocno); //pb125 } catch (Exception ex) { ex.ToString(); } try {//เช็คจำนวนสัญญาที่สามารถใช้ค้ำได้ //ldc_collusereq = wcf.Shrlon.of_getcollusereqamt(state.SsWsPass, state.SsCoopControl, ls_collno, ls_loantype, ls_colltype, ls_reqdocno);//pb120// ldc_collusereq = wcf.NShrlon.of_getcollusereqamt(state.SsWsPass, state.SsCoopControl, ls_collno, ls_loantype, ls_colltype, ls_reqdocno); //pb125 } catch (Exception ex) { ex.ToString(); } ldc_collbal = (ldc_collbaseamt - ldc_collusecont - ldc_collusereq) * ldc_collbasepercent / 100; dw_coll.SetItemDecimal(r, "collbalance_amt", ldc_collbal); } } /// /// ตรวจสอบสิทธิ์ค้ำ /// private void GetCollPermiss() { string as_memno = "", as_loantype = "", as_colltype = "", as_collno = "", as_reqdocno, as_excludecont = ""; int row_coll, row_clr; decimal clear_status = 0, //สถาณะสัญญาหักกลบ loanreqregis_amt, //ยอดขอกู้ collpermiss = 0, //สิทธิค้ำสูงสุด collactive_percent = 0, //% ค้ำ collmaxcoll = 0; //สิทธิ์ค้ำสูงสุดของสัญญาเงินกู้ decimal permiss = 0, //ref service of_getcollpermiss percent = 0, //ref service of_getcollpermiss maxcoll = 0; //ref service of_getcollpermiss decimal flag_permiss, //flag การคำนวณ เปอร์เซ็นต์ flag_collmancount; //flag การคำนวณ เปอร์เซ็นต์ decimal collusecontamt = 0, //สิทธิ์ค้ำที่ใช้ไปของใบคำขอ collusereqamt = 0, //เช็คจำนวนสัญญาที่สามารถใช้ค้ำได้ collbalance_amt, //สิทธิค้ำคงเหลือ collactive_amt = 0; //ค้ำประกัน Decimal share_balance = 0; //ยอดหุ้น DateTime adtm_check; //วันที่ทำรายการ Decimal collactive__amt = dw_main.GetItemDecimal(1, "loanrequest_amt"); try { row_coll = Convert.ToInt32(HdRefcollrow.Value); } catch { row_coll = 1; } share_balance = dw_main.GetItemDecimal(1, "share_balance"); as_loantype = dw_main.GetItemString(1, "loantype_code"); adtm_check = dw_main.GetItemDateTime(1, "loanrequest_date"); as_memno = dw_main.GetItemString(1, "member_no"); as_reqdocno = dw_main.GetItemString(1, "loanrequest_docno"); if (as_reqdocno == "Auto") { as_reqdocno = null; } loanreqregis_amt = dw_main.GetItemDecimal(1, "loanreqregis_amt"); try { as_colltype = dw_coll.GetItemString(row_coll, "loancolltype_code"); } catch { as_colltype = ""; } as_collno = dw_coll.GetItemString(row_coll, "ref_collno"); ; row_clr = dw_clear.RowCount; for (int i = 1; i <= row_clr; i++) {//ดึงเลขที่สัญญาหักกลบที่ถูกเลือก clear_status = dw_clear.GetItemDecimal(i, "clear_status"); if (clear_status == 1) { if (flag == 1) { as_excludecont += ","; } as_excludecont += dw_clear.GetItemString(i, "loancontract_no"); flag = 1; } } if (as_colltype == "04") { string sql = @"select mortgage_price, estimate_price, est_percent from lncollmaster where ( coop_id = {0} ) and ( collmast_no = {1} )"; // string sql = @"select dol_prince, est_price, est_percent from lncollmaster // where ( coop_id = {0} ) and ( collmast_no = {1} )"; sql = WebUtil.SQLFormat(sql, state.SsCoopControl, as_collno); dt = ta.Query(sql); if (dt.Next()) { collpermiss = dt.GetDecimal("estimate_price"); collactive_percent = dt.GetDecimal("est_percent"); collmaxcoll = collpermiss; Decimal tt = dt.GetDecimal("mortgage_price"); percent = 100; dw_coll.SetItemDecimal(row_coll, "collbase_amt", tt); dw_coll.SetItemDecimal(row_coll, "collbase_percent", percent); dw_coll.SetItemDecimal(row_coll, "collmax_amt", collmaxcoll); dw_coll.SetItemDecimal(row_coll, "collbalance_amt", collpermiss); dw_coll.SetItemDecimal(row_coll, "collactive_amt", collactive__amt); dw_coll.SetItemDecimal(row_coll, "collactive_percent", percent); dw_coll.SetItemDecimal(row_coll, "collused_amt", 0); } } if (as_colltype == "02")//หุ้น { int result = wcf.NShrlon.of_getcollpermiss(state.SsWsPass, as_loantype, as_colltype, state.SsCoopControl, as_collno, adtm_check, ref permiss, ref maxcoll, ref percent); //pb125 decimal shrclr_amt = 0; //แก้ kla Decimal buyshare = 0, collamt = 0; if (dw_otherclr.GetColumnNumber() > 0) { for (int i = 1; i <= dw_otherclr.RowCount; i++) { if (dw_otherclr.GetItemString(i, "clrothertype_code") == "SHR") { shrclr_amt += dw_otherclr.GetItemDecimal(i, "clrother_amt"); } } collpermiss += shrclr_amt; collpermiss = collpermiss + share_balance; } else { collpermiss = permiss; } //collactive_percent = percent; //collmaxcoll = maxcoll; collactive_percent = percent; // collamt = share_balance + collpermiss; collmaxcoll = (collpermiss * collactive_percent) / 100; flag_permiss = 1; dw_coll.SetItemDecimal(row_coll, "collbase_amt", collpermiss); dw_coll.SetItemDecimal(row_coll, "collbase_percent", collactive_percent); dw_coll.SetItemDecimal(row_coll, "collmax_amt", collmaxcoll); try {//สิทธิ์ค้ำที่ใช้ไปของใบคำขอ collusecontamt = wcf.NShrlon.of_getcollusecontamt(state.SsWsPass, state.SsCoopControl, as_collno, as_loantype, as_colltype, as_excludecont, as_reqdocno); //pb125 } catch (Exception ex) { ex.ToString(); } try {//เช็คจำนวนสัญญาที่สามารถใช้ค้ำได้ collusereqamt = wcf.NShrlon.of_getcollusereqamt(state.SsWsPass, state.SsCoopControl, as_collno, as_loantype, as_colltype, as_reqdocno); //pb125 } catch (Exception ex) { ex.ToString(); } //collbalance_amt = (collpermiss - collusecontamt - collusereqamt) * percent / 100; collbalance_amt = collmaxcoll; //ถ้า สิทธิ์ค้ำคงเหลือ มากกว่า สิทธิ์ค้ำสูงสุดของสัญญานี้ ให้ สิทธิ์ค้ำ = สิทธิ์ค้ำสูงสุด if (collbalance_amt > maxcoll) { collactive_amt = maxcoll; } else { collactive_amt = collbalance_amt; } //ถ้า ขอกู้ น้อยกว่า สิทธิ์ค้ำ ให้ สิทธิ์ค้ำ = ขอกู้ if (loanreqregis_amt <= collactive_amt) { collactive_amt = loanreqregis_amt; } //หา %ค้ำชำระ //collactive_percent = collactive_amt * collactive_percent / loanreqregis_amt; //collactive_percent = collactive_amt * 100 / loanreqregis_amt; Decimal percent_share = 0, coll_balance = 0; if (dw_otherclr.GetColumnNumber() < 0) { string sql = @"select multiple_share from LNLOANTYPECUSTOM where ( coop_id = {0} ) and ( loantype_code = {1} )"; sql = WebUtil.SQLFormat(sql, state.SsCoopControl, as_loantype); dt = ta.Query(sql); if (dt.Next()) { percent_share = dt.GetDecimal("multiple_share"); } coll_balance = dw_otherclr.GetItemDecimal(1, "compute_2"); coll_balance = coll_balance * percent_share; } collactive_percent = percent; if (collbalance_amt > 0) { dw_coll.SetItemDecimal(row_coll, "collbalance_amt", collbalance_amt + coll_balance); dw_coll.SetItemDecimal(row_coll, "collactive_amt", collactive_amt); dw_coll.SetItemDecimal(row_coll, "collactive_percent", collactive_percent); dw_coll.SetItemDecimal(row_coll, "collused_amt", collusecontamt); dw_coll.SetItemDecimal(row_coll, "collbase_percent", collactive_percent); } else { dw_coll.SetItemDecimal(row_coll, "collbalance_amt", 0); dw_coll.SetItemDecimal(row_coll, "collactive_amt", 0); dw_coll.SetItemDecimal(row_coll, "collactive_percent", 0); } } } /// /// ตรวจสอบการซ้ำของหลักประกัน /// public Boolean ChkSameColl(String as_collno, int row_coll, string as_colltype) { string ref_collno = "", loancolltype_code = ""; Boolean retrn = true; for (int i = 1; i <= dw_coll.RowCount; i++) { if (row_coll != i && as_collno != "") { try { ref_collno = dw_coll.GetItemString(i, "ref_collno"); loancolltype_code = dw_coll.GetItemString(i, "loancolltype_code"); } catch { ref_collno = ""; loancolltype_code = ""; } if (ref_collno != "") { if ((as_collno == ref_collno) && (as_colltype == loancolltype_code)) { LtServerMessagecoll.Text += WebUtil.WarningMessage("พบหลักประกันซ้ำ " + ref_collno); //Response.Write(@""); dw_coll.SetItemString(row_coll, "ref_collno", ""); dw_coll.SetItemString(row_coll, "description", ""); retrn = false; } else { retrn = true; } } } } return retrn; } /// ///บันทึกใบคำขอ /// public void SaveWebSheet() { int li_return = JsCheckDataBeforesave(); if (li_return == 1) { String dwMain_XML = dw_main.Describe("DataWindow.Data.XML"); String dwColl_XML = ""; String dwClear_XML = ""; String dwOtherClr_XML = ""; String dwMthexp_XML = ""; String dwIntspc_XML = ""; String dwPeriodpay_XML = ""; //mai กรณี ไม่มีการค้ำประกันให้สามารถบันทึกได้ if (dw_coll.RowCount > 0) { dwColl_XML = dw_coll.Describe("DataWindow.Data.XML"); } if (dw_clear.RowCount > 0) { dwClear_XML = dw_clear.Describe("DataWindow.Data.XML"); } if (dw_otherclr.RowCount > 0) { dwOtherClr_XML = dw_otherclr.Describe("DataWindow.Data.XML"); } if (dw_intspc.RowCount > 0) { dwIntspc_XML = dw_intspc.Describe("DataWindow.Data.XML"); } if (dw_mthexp.RowCount > 0) { dwMthexp_XML = dw_mthexp.Describe("DataWindow.Data.XML"); } if (dw_periodpay.RowCount > 0) { dwPeriodpay_XML = dw_periodpay.Describe("DataWindow.Data.XML"); } str_savereqloan strSave = new str_savereqloan(); strSave.xml_main = dwMain_XML; strSave.xml_clear = dwClear_XML; strSave.xml_guarantee = dwColl_XML; strSave.xml_otherclr = dwOtherClr_XML; strSave.xml_mthexp = dwPeriodpay_XML; //wa เปลียนมาใช้สำหรับส่งไป บันทึกตารางชำระ strSave.xml_intspc = dwIntspc_XML; // strSave.xml_intcertdet = dwPeriodpay_XML strSave.entry_id = state.SsUsername; // ส่งให้ service save try { wcf.NShrlon.of_save_lnreq(state.SsWsPass, ref strSave);//pb125 } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage(ex); } reqdoc_no = strSave.request_no; txt_reqNo.Text = reqdoc_no; txt_member_no.Text = member_no; int li_apv = Convert.ToInt16(dw_main.GetItemDecimal(1, "apvimmediate_status")); if (li_apv == 1 || li_apv == 2) { string contno = strSave.loancontract_no; Hdcontno.Value = contno; HdReturn.Value = "11"; } x = 2; dw_main.SetItemString(1, "loanrequest_docno", reqdoc_no); //---Srart Script--- Response.Write(@""); //---End Script--- // Edit By BankCM For print contract,coll contract and cover sheet with iReport //if (!(PrintContracConsider(reqdoc_no))) //{ // ScriptManager.RegisterStartupScript(Page, this.GetType(), "AlertMessage", "", false); //} LtServerMessage.Text = WebUtil.CompleteMessage("บันทึกข้อมูลเรียบร้อยแล้ว"); //พิมพ์หนังสือเสนอกรรมการ เงินกู้พิเศษ string lngrp_code = ""; String sql = @"select loangroup_code from lnloantype where loantype_code = {0}"; sql = WebUtil.SQLFormat(sql, dw_main.GetItemString(1, "loantype_code")); Sdt result = WebUtil.QuerySdt(sql); while (result.Next()) { lngrp_code = result.GetString("loangroup_code"); } if (lngrp_code == "03") { // Panel1.Visible = true; HdPrtReqdocno.Value = reqdoc_no; } //Printcont(reqdoc_no); Ltdividen.Text = " "; Ltjspopup.Text = " "; if (li_apv == 0) { String ls_loantype = dw_main.GetItemString(1, "loantype_code"); Session["loantypeCode"] = ls_loantype; JsReNewPage(); } } } private static string XmlReadVar(string responseData, string szVar) { int i1stLoc = responseData.IndexOf("<" + szVar + ">"); if (i1stLoc < 0) return string.Empty; int ilstLoc = responseData.IndexOf(""); if (ilstLoc < 0) return string.Empty; int len = szVar.Length; return responseData.Substring(i1stLoc + len + 2, ilstLoc - i1stLoc - len - 2); } public void WebDialogLoadEnd() { try { str_itemchange strList = new str_itemchange(); strList.xml_main = dw_main.Describe("DataWindow.Data.XML"); if (dw_clear.RowCount == 0) { strList.xml_clear = null; } else { strList.xml_clear = dw_clear.Describe("DataWindow.Data.XML"); } if (dw_coll.RowCount == 0) { strList.xml_guarantee = null; } else { strList.xml_guarantee = dw_coll.Describe("DataWindow.Data.XML"); } Session["strItemchange"] = strList; //หาจำนวนงวดที่ชำระ string member_no = dw_main.GetItemString(1, "member_no"); if (member_no != null || member_no != "") { DateTime startkeep_date = dw_main.GetItemDate(1, "startkeep_date"); DateTime retry_date = dw_main.GetItemDateTime(1, "retry_date"); Int32 month_ = 12 - (startkeep_date.Month - 1); Int32 retryage = (retry_date.Year - startkeep_date.Year - 1) * 12 + 9 + month_; dw_main.SetItemDecimal(1, "retry_age", retryage); } } catch { } HdRefcoll.Value = ""; dw_main.SaveDataCache();//main dw_coll.SaveDataCache();//หลักประกัน dw_clear.SaveDataCache();//หักกลบ dw_otherclr.SaveDataCache();//หักอื่น dw_periodpay.SaveDataCache(); is_massalert = ""; Session["loantypeCode"] = dw_main.GetItemString(1, "loantype_code"); } private DateTime JsGetPostingdate(int year, int month, DateTime request_date) { string ls_sql = "select postingdate from amworkcalendar where year = " + year.ToString() + " and month = " + month.ToString(); DateTime postingdate = request_date; Sdt dtpro = WebUtil.QuerySdt(ls_sql); if (dtpro.Next()) { try { int daypost = dtpro.GetInt32("postingdate"); year = year - 543; string postdate = daypost.ToString() + "/" + month.ToString() + "/" + year.ToString(); postingdate = Convert.ToDateTime(postdate); // if (postingdate < request_date) { postingdate = request_date; } } catch { postingdate = request_date; } //กรณี วันที่จ่ายเงิน=วันที่ขอกู้ } else { postingdate = request_date; } return postingdate; } /// /// fillter ประเภทการจ่ายเงิน /// private void JsGetexpensememno() { try { string memno = dw_main.GetItemString(1, "member_no"); string strsql = @"select expense_code, expense_bank, expense_branch, expense_accid from mbmembmaster where member_no = '" + memno + "'"; try { Sdt dtloanrcv = WebUtil.QuerySdt(strsql); if (dtloanrcv.GetRowCount() <= 0) { LtServerMessage.Text = WebUtil.WarningMessage("ไม่พบเลขที่บัญชีเงินธนาคารของสมาชิก " + memno); } if (dtloanrcv.Next()) { string loanrcv_code = "", loanrcv_bank = ""; try { loanrcv_code = dw_main.GetItemString(1, "expense_code"); } catch { loanrcv_code = ""; } if (loanrcv_code == "" || loanrcv_code == null) { loanrcv_code = dtloanrcv.GetString("expense_code"); } try { loanrcv_bank = dw_main.GetItemString(1, "expense_bank"); } catch { loanrcv_bank = ""; } if (loanrcv_bank == "" || loanrcv_bank == null) { loanrcv_bank = dtloanrcv.GetString("expense_bank"); } string loanrcv_branch = dtloanrcv.GetString("expense_branch"); string loanrcv_accid = dtloanrcv.GetString("expense_accid"); if (loanrcv_code != null) { dw_main.SetItemString(1, "expense_code", loanrcv_code); dw_main.SetItemString(1, "expense_bank", loanrcv_bank); if (loanrcv_branch == "" || loanrcv_branch == null) { DwUtil.RetrieveDDDW(dw_main, "expense_branch_1", "sl_loan_requestment_dol.pbl", loanrcv_bank); } else { dw_main.SetItemString(1, "expense_branch", loanrcv_branch); } dw_main.SetItemString(1, "expense_accid", loanrcv_accid); } else { dw_main.SetItemString(1, "expense_code", "CBT"); } if (loanrcv_code == "CBT" && loanrcv_bank.Length > 2) { string sql_bkk = "select branch_name from cmucfbankbranch where bank_code = '" + loanrcv_bank + "' and branch_id = '" + loanrcv_branch + "'"; Sdt dtk = WebUtil.QuerySdt(sql_bkk); string bankbranch = ""; if (dtk.Next()) { bankbranch = dtk.GetString("branch_name").Trim(); JsExpensebankbrRetrieve(); } } if (loanrcv_code == "CBO" && loanrcv_bank.Length > 2) { string sql_bkk = "select branch_name from cmucfbankbranch where bank_code = '" + loanrcv_bank + "' and branch_id = '" + loanrcv_branch + "'"; Sdt dtk = WebUtil.QuerySdt(sql_bkk); string bankbranch = ""; if (dtk.Next()) { bankbranch = dtk.GetString("branch_name").Trim(); JsExpensebankbrRetrieve(); } } } } catch { } } catch { } } private void JsExpenseCode() { string expendCode = ""; try { expendCode = dw_main.GetItemString(1, "expense_code"); } catch { } if (expendCode == null || expendCode == "") return; if ((expendCode == "CHQ") || (expendCode == "TRN") || (expendCode == "CBT") || (expendCode == "DRF") || (expendCode == "TBK")) { try { DwUtil.RetrieveDDDW(dw_main, "expense_bank_1", "sl_loan_requestment.pbl", null); } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage(ex); } } else if (expendCode == "CBO") { //ฝั่งธนาคาร dw_main.Modify("t_20.visible =1"); dw_main.Modify("expense_bank.visible =1"); dw_main.Modify("t_30.visible =1"); dw_main.Modify("expense_bank_1.visible =1"); dw_main.Modify("t_39.visible =1"); dw_main.Modify("expense_branch.visible =1"); dw_main.Modify("t_27.visible =1"); dw_main.Modify("expense_branch_1.visible =1"); dw_main.Modify("b_expense_branch.visible = 1"); try { DwUtil.RetrieveDDDW(dw_main, "expense_bank_1", "sl_loan_requestment.pbl", null); JsGetexpensememno(); } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage(ex); } } else if ((expendCode == "CSH") || (expendCode == "BEX") || (expendCode == "MON") || (expendCode == "MOS") || (expendCode == "MOO")) { //ฝั่งธนาคาร dw_main.Modify("t_20.visible =0"); dw_main.Modify("expense_bank.visible =0"); dw_main.Modify("t_30.visible =0"); dw_main.Modify("expense_bank_1.visible =0"); dw_main.Modify("t_39.visible =0"); dw_main.Modify("expense_branch.visible =0"); dw_main.Modify("t_27.visible =0"); dw_main.Modify("expense_branch_1.visible =0"); dw_main.Modify("b_expense_branch.visible =0"); dw_main.Modify("t_38.visible =0"); dw_main.Modify("expense_accid.visible =0"); } } private void JsGetitemdescetc() { try { int row = Convert.ToInt16(Hdothercltrow.Value); string itemetc_code = dw_otherclr.GetItemString(row, "clrothertype_code"); string sql_prmgrp = "select slipitemtype_desc from slucfslipitemtype where slipitemtype_code = '" + itemetc_code + "'"; Sdt dt_itemetc = WebUtil.QuerySdt(sql_prmgrp); if (dt_itemetc.Next()) { string item_desc = dt_itemetc.GetString("slipitemtype_desc"); dw_otherclr.SetItemString(row, "clrother_desc", item_desc); } } catch { } } /// /// set รายละเอียด ยอดหักจาก slip เงินเดือน /// private void JsGetitemdescmthexp() { try { //int row = Convert.ToInt16(Hdmthexprow.Value); // string sql_mthexp = "select mthexpense_desc from mbucfmthexpense where mthexpense_code = '" + mthexp_code + "'"; //Sdt dt_mthexp = WebUtil.QuerySdt(sql_mthexp); //if (dt_mthexp.Next()) //{ // string mthexp_desc = dt_mthexp.GetString("mthexpense_desc"); //} } catch { } } /// /// Retrieve ธนาคาร /// private void JsExpenseBank() { try { String bankCode; try { bankCode = dw_main.GetItemString(1, "expense_bank").Trim(); } catch { bankCode = "034"; } String bankbranch; try { bankbranch = dw_main.GetItemString(1, "expense_branch").Trim(); } catch { bankbranch = "0000"; } DwUtil.RetrieveDDDW(dw_main, "expense_bank_1", "sl_loan_requestment_dol.pbl", ""); } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage(ex); } } /// /// Retrieve สาขาธนาคาร /// private void JsExpensebankbrRetrieve() { try { String bankCode; try { bankCode = dw_main.GetItemString(1, "expense_bank").Trim(); } catch { bankCode = "034"; } DwUtil.RetrieveDDDW(dw_main, "expense_branch_1", "sl_loan_requestment_dol.pbl", bankCode); } catch { } } /// /// open ใบคำขอเก่า /// private void JsOpenOldDocNo() { try { string ls_reqloandocno = dw_main.GetItemString(1, "loanrequest_docno"); string ls_CoopControl = state.SsCoopControl; string[] arg = new string[2] { ls_CoopControl, ls_reqloandocno }; DateTime ldtm_now = DateTime.Now; txt_reqNo.Text = ls_reqloandocno; txt_member_no.Text = member_no; Hdcoopid.Value = ls_CoopControl; DwUtil.RetrieveDataWindow(dw_main, pbl, null, arg); DwUtil.RetrieveDataWindow(dw_clear, pbl, null, arg); DwUtil.RetrieveDataWindow(dw_coll, pbl, null, arg); DwUtil.RetrieveDataWindow(dw_otherclr, pbl, null, arg); DwUtil.RetrieveDataWindow(dw_periodpay, pbl, null, arg); tDwMain.Eng2ThaiAllRow(); string loantype_code = dw_main.GetItemString(1, "loantype_code"); try { RetreiveDDDW(); // DwUtil.RetrieveDDDW(dw_main, "loantype_code_1", pbl, null); if (dw_main.RowCount > 1) dw_main.DeleteRow(dw_main.RowCount); JsExpenseBank(); JsExpensebankbrRetrieve(); dw_main.SetItemString(1, "loantype_code", loantype_code); Decimal loanrequestStatus = dw_main.GetItemDecimal(1, "loanrequest_status"); //เปิดให้แก้ไขได้หลังจาก open if ((loanrequestStatus != 8) && (loanrequestStatus != 81) && (loanrequestStatus != 11)) { dw_main.DisplayOnly = true; dw_clear.DisplayOnly = true; dw_coll.DisplayOnly = true; dw_otherclr.DisplayOnly = true; } else { dw_main.DisplayOnly = false; dw_clear.DisplayOnly = false; dw_coll.DisplayOnly = false; dw_otherclr.DisplayOnly = false; } } catch (Exception ex) { //LtServerMessage.Text = WebUtil.ErrorMessage("JsOpenOldDocNo====>" + ex); } } catch { } } /// /// ยกเลิก ใบคำขอกู้ /// private void JsCancelRequest() { String dwXmlMain = dw_main.Describe("DataWindow.Data.XML"); String cancelID = state.SsUsername; String coop_id = state.SsCoopId; string cancle_date = state.SsWorkDate.ToShortDateString(); try { Decimal loanrequestStatus = dw_main.GetItemDecimal(1, "loanrequest_status"); string loanreqdocno = dw_main.GetItemString(1, "loanrequest_docno"); //เปิดให้แก้ไขได้หลังจาก open if ((loanrequestStatus == 8) || (loanrequestStatus == 81)) { string sql_up = "update lnreqloan set loanrequest_status = -9, cancel_id = '" + cancelID + "' where loanrequest_docno = '" + loanreqdocno + "'"; WebUtil.ExeSQL(sql_up); WebUtil.ExeSQL("commit"); LtServerMessage.Text = "ยกเลิกใบคำขอก้เรียบร้อยแล้ว"; dw_main.DisplayOnly = true; dw_clear.DisplayOnly = true; dw_coll.DisplayOnly = true; dw_otherclr.DisplayOnly = true; } } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage("JsCancelRequest===>" + ex); } } private void JsSetDataList() { str_itemchange strList = new str_itemchange(); strList = WebUtil.nstr_itemchange_session(this); //pb12.5 //strList = WebUtil.str_itemchange_session(this); //pb12 if (dw_clear.RowCount == 0) { strList.xml_clear = null; } else { strList.xml_clear = dw_clear.Describe("DataWindow.Data.XML"); } if (dw_coll.RowCount == 0) { strList.xml_guarantee = null; } else { strList.xml_guarantee = dw_coll.Describe("DataWindow.Data.XML"); } Session["strItemchange"] = strList; } private void CalSumTotal() // กล้าเพิ่ม คำนวณ ยอดรับเงินสุทธิ { Decimal loanrequest_amt = 0, buyshare = 0, insurance = 0, clear_status = 0; if (dw_clear.GetColumnNumber() > 0 && dw_otherclr.GetColumnNumber() < 1) { clear_status = dw_clear.GetItemDecimal(1, "clear_status"); if (clear_status == 1) { loanrequest_amt = dw_main.GetItemDecimal(1, "loanrequest_amt"); // buyshare = dw_otherclr.GetItemDecimal(1, "compute_2"); insurance = dw_clear.GetItemDecimal(1, "compute_1"); dw_main.SetItemDecimal(1, "salary_amt", loanrequest_amt - (insurance)); } else { loanrequest_amt = dw_main.GetItemDecimal(1, "loanrequest_amt"); // buyshare = dw_otherclr.GetItemDecimal(1, "compute_2"); dw_main.SetItemDecimal(1, "salary_amt", loanrequest_amt); } } else if (dw_clear.GetColumnNumber() > 0 && dw_otherclr.GetColumnNumber() > 0) { clear_status = dw_clear.GetItemDecimal(1, "clear_status"); if (clear_status == 1) { loanrequest_amt = dw_main.GetItemDecimal(1, "loanrequest_amt"); buyshare = dw_otherclr.GetItemDecimal(1, "compute_2"); insurance = dw_clear.GetItemDecimal(1, "compute_1"); dw_main.SetItemDecimal(1, "salary_amt", loanrequest_amt - (buyshare + insurance)); } else { loanrequest_amt = dw_main.GetItemDecimal(1, "loanrequest_amt"); buyshare = dw_otherclr.GetItemDecimal(1, "compute_2"); dw_main.SetItemDecimal(1, "salary_amt", loanrequest_amt - (buyshare)); } } else { loanrequest_amt = dw_main.GetItemDecimal(1, "loanrequest_amt"); if (dw_otherclr.GetColumnNumber() > 0) { buyshare = dw_otherclr.GetItemDecimal(1, "compute_2"); dw_main.SetItemDecimal(1, "salary_amt", loanrequest_amt - (buyshare)); } else { // buyshare = dw_otherclr.GetItemDecimal(1, "compute_2"); dw_main.SetItemDecimal(1, "salary_amt", loanrequest_amt); } } } private int JsCheckDataBeforesave() { //ตรวจค้ำประกัน wa int coll_num = 0; string loantype_code = dw_main.GetItemString(1, "loantype_code"); decimal loanrequest_amt = dw_main.GetItemDecimal(1, "loanrequest_amt"); int collrow = dw_coll.RowCount; String sqlpro = @" select useman_amt, useshare_flag from lnloantypereqgrt where loantype_code = '" + loantype_code + "' and money_from <= " + loanrequest_amt.ToString() + @" and money_to >= " + loanrequest_amt.ToString(); Sdt dtgrt = WebUtil.QuerySdt(sqlpro); if (dtgrt.Next()) { coll_num = Convert.ToInt32(dtgrt.GetDecimal("useman_amt")); int coll_share = Convert.ToInt32(dtgrt.GetDecimal("useshare_flag")); } else { coll_num = 0; } if (coll_num > collrow) { //แสดงข้อความ LtServerMessage.Text = WebUtil.ErrorMessage("ท่านป้อนสมาชิกค้ำประกันไม่ครบ กรุณาป้อนให้ครบด้วย ต้องระบุคนค้ำประกัน จำนวน " + coll_num.ToString()); return 1; } return 1; } private void of_Setperiodpaydet() //กล้า แก้เพิ่ม { try { //สร้างตารางการชำระรายปี Decimal loanrequest_amt = dw_main.GetItemDecimal(1, "loanrequest_amt"); Decimal period_amt = 0; period_amt = dw_main.GetItemDecimal(1, "period_payamt"); String year = ""; string sql = "SELECT ACCOUNT_YEAR FROM ACCACCOUNTYEAR WHERE ACCACCOUNTYEAR.COOP_ID = '" + state.SsCoopControl + "' and CLOSE_ACCOUNT_STAT=0"; sql = WebUtil.SQLFormat(sql); Sdt dt = WebUtil.QuerySdt(sql); if (dt.Next()) { year = dt.GetString("ACCOUNT_YEAR"); } CultureInfo th = System.Globalization.CultureInfo.GetCultureInfo("th-TH"); DateTime today = Convert.ToDateTime(state.SsWorkDate); //DateTime day = state.SsWorkDate; String dayss = "31/03/" + year; today = DateTime.ParseExact(dayss, "dd/MM/yyyy", CultureInfo.InvariantCulture); DateTime end_date2 = today.AddYears((Convert.ToInt16(period_amt))); dw_main.SetItemString(1, "loanrcvfix_tdate", (end_date2).ToString("ddMMyyyy", th)); dw_main.SetItemDecimal(1, "loanrcvfix_flag", 1); if (loanrequest_amt <= 0) { return; } Decimal rowp = dw_periodpay.RowCount; int rowpint = 0; //สร้างแถว if (period_amt > rowpint) { rowp = period_amt; //for (int i = rowpint + 1; i <= rowpint; i++) //{ // dw_periodpay.InsertRow(0); //} rowpint = Convert.ToInt16(rowp); for (int i = 0; i < rowpint; i++) { dw_periodpay.InsertRow(0); } } // DateTime dt = DateTime.Parse(dw_main.GetItemDateTime(1, "loanrequest_tdate")); // dw_main.SetItemDateTime(1, "loanrequest_date", state.SsWorkDate); //DateTime end_date = today.AddDays(365 * (ii)); //gen ยอดชำระ decimal period_payment = dw_main.GetItemDecimal(1, "period_payment"); decimal sumpay = 0; rowp = dw_periodpay.RowCount; for (int ii = 1; ii <= rowp; ii++) { sumpay = loanrequest_amt - period_payment; DateTime end_date = today.AddYears((ii)); if (loanrequest_amt < period_payment) { period_payment = loanrequest_amt; } dw_periodpay.SetItemDecimal(ii, "period", Convert.ToDecimal(ii)); dw_periodpay.SetItemDecimal(ii, "principal_payment", period_payment); dw_periodpay.SetItemString(ii, "expireperiod_tdate", (end_date).ToString("ddMMyyyy", th)); dw_periodpay.SetItemDateTime(ii, "expireperiod_date", end_date); } } catch (Exception ex) { } } private void of_Setperiodpaydet2(string req_docno, string coop_id) //กล้า แก้เพิ่ม { try { CultureInfo th = System.Globalization.CultureInfo.GetCultureInfo("th-TH"); //DateTime day = state.SsWorkDate; // String dayss = "31/03/" + year; //today = DateTime.ParseExact(dayss, "dd/MM/yyyy", CultureInfo.InvariantCulture); //DateTime end_date2 = today.AddYears(543)); DateTime today; // rowp = dw_periodpay.RowCount; string sql = "SELECT expireperiod_date FROM lnreqloanperiodpaydet where loanrequest_docno = '" + req_docno + "' and coop_id='" + coop_id + "'"; sql = WebUtil.SQLFormat(sql); Sdt dt = WebUtil.QuerySdt(sql); int ii = 1; while (dt.Next()) { today = dt.GetDate("expireperiod_date"); // DateTime end_date = today.AddYears(543); dw_periodpay.SetItemString(ii, "expireperiod_tdate", (today).ToString("ddMMyyyy", th)); dw_periodpay.SetItemDateTime(ii, "expireperiod_date", today); ii++; dw_main.SetItemDateTime(1, "loanrcvfix_date", (today)); dw_main.SetItemString(1, "loanrcvfix_tdate", (today).ToString("ddMMyyyy", th)); } } catch (Exception ex) { } } private void of_setexpensedefault(string as_memno) //pom : setexpense-default { string memberNo = as_memno; string ls_loantype = dw_main.GetItemString(1, "loantype_code"); try { decimal defaultpaytype = 1; String sqlStrdefaultpay = @" SELECT defaultpay_type FROM LNLOANTYPE WHERE LOANTYPE_CODE='" + ls_loantype + "'"; Sdt dt1 = WebUtil.QuerySdt(sqlStrdefaultpay); if (dt1.GetRowCount() < 1) { defaultpaytype = 1; } if (dt1.Next()) {// try { defaultpaytype = dt1.GetDecimal("defaultpay_type"); } catch { defaultpaytype = 1; } } if (defaultpaytype == 2) { JsGetexpensememno(); } else if (defaultpaytype == 1) //pom : pay_by_default_loantyp - เงินสด / โอน =ไปเอาเลขบัญชีจากทะเบียนสมาขิก { dw_main.SetItemString(1, "expense_code", "CSH"); } } catch { } } //private bool PrintContracConsider(String RequestDocNo) //{ // try // { // iReportArgument args = new iReportArgument(); // args.Add("lnreqdocno", iReportArgumentType.String, RequestDocNo); // iReportBuider report = new iReportBuider(this, ""); // report.AddCriteria("r_ln_print_loan_req_checkpermiss", "ใบปะหน้าพิจารณาการขอกู้", ReportType.pdf, args); // report.AutoOpenPDF = true; // report.Retrieve(); // return true; // } // catch // { // return false; // } //} /// /// set ดอกเบี้ยจริง /// private void of_setclearintreal() { string ls_contno = ""; decimal ldc_clearint = 0, ldc_prncalint = 0; DateTime ldtm_calfrom; for (int i = 1; i <= dw_clear.RowCount; i++) { ldc_prncalint = dw_clear.GetItemDecimal(i, "principal_balance"); if (ldc_prncalint > 0) { ls_contno = dw_clear.GetItemString(i, "loancontract_no"); ldtm_calfrom = dw_clear.GetItemDateTime(i, "lastcalint_date"); ldc_clearint = wcf.NShrlon.of_computeinterest_single(state.SsWsPass, state.SsCoopControl, ls_contno, ldc_prncalint, ldtm_calfrom, state.SsWorkDate); } else { ldc_clearint = 0; } dw_clear.SetItemDecimal(i, "intreal_amt", ldc_clearint); } } } }