<%--
  - FileName   : QuotPurSuppReg.jsp
  - Author(s)  : HOONSEOK CHOI	
  - Date       : 2023-11	
  --%>
  


<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="com.udapsoft.waf.system.HandlerStorage" %>
<%@ page import="com.udapsoft.waf.common.ui.*" %>
<%@ page import="com.udapsoft.waf.common.ui.InitCombo" %>
<%@ page import="kr.co.udapsoft.common.code.CommCodeManager" %>
<%@ page import="kr.co.hsnc.common.util.*"%>
<%@ page import="kr.co.hsnc.common.sql.*" %>
<%@ include file="/jsp/work/taglib.jsp" %>
<jsp:useBean id="ctx" class="com.udapsoft.waf.system.context.SessionContext" scope="session" />
<%
    ctx.init(request, response);
    HandlerStorage storage = ctx.getHandlerStorage();
    ValueObject params = storage.getParams();
    ValueObject user = storage.getUser();
    String event = storage.getEvent();
    
    ValueObject vo = storage.getValueObject("QuotPurSuppReg");
    
    String status = "";
    status = params.get("status");
    
	String job_gubun = "";
    
    if(params.get("job_div").equals("P"))
    {
        job_gubun = "구매";
    }
    else
    {
        job_gubun = "외주";
    }
    
	//공통코드
  	CommCodeManager commCodeManager = new CommCodeManager();
  	InitCombo initCombo = new InitCombo();
%>

<script type="text/javascript">
<!--
	$(function(){
	    
	    var event = "<%=event%>";
	    var status = "<%=vo.get("STATUS_CD")%>";
	    var f = document.form1;
	    
	    if(event == "")
		{
		    $("#btn_delete_area").css("display", "none");
		}
	    else if(event == "GET_DETAIL")
		{
	        $("#corp_reg_no").attr("readonly", true);
	        $("#corp_reg_no").css("background-color", "#f0f0f0");
	        
	        if(status == "AA")
            {
	            $("#btn_delete_area").css("display", "inline");
            }
	        else
            {
				$("#corp_reg_no").attr("readonly", true);
				$("#corp_reg_no").addClass("bg_gry");
            }
		}
	    
	    
	    //숫자만 입력받기.
		$(document).on("keyup", "input:text[numberOnly]", function() {$(this).val( $(this).val().replace(/[^0-9]/gi,"") );});
	    
	    
	    
		$("#btn_list").click(function(){
		    var job_div = $("#job_div").val();
		    
			$("#form1").attr("action", "/quot/purchase/QuotPurSuppRegList.screen");
			$("#form1").attr("target", "_self");
			$("#form1").attr("method", "post");
			$("#form1").submit();
		});
		
		
		$("#btn_save").click(function(){
		    
		    var u_email = $("#email");
		    
		    
		 	// 정규식 - 이메일 유효성 검사
	        var regEmail = /([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		 
	     	//입력값 체크
	     	if($("#corp_reg_no").val().trim() != "")
	     	{
	     		var regNum = /^[0-9]{10}$/;
	     	    
	     	    if(!regNum.test($("#corp_reg_no").val().trim()))
	     	    {
	     	       	alert("사업자 번호를 확인해 주세요.");
	     	      	$("#corp_reg_no").focus();
	                return false;
	     	    }
	     	}
	     	else
	     	{
	     	   alert("사업자 번호를 입력해 주세요");
	     	   $("#corp_reg_no").focus();
	     	   return false;
	     	}
	     	
	     	if($("#corp_kor").val().trim() == "")
	     	{
	     	   alert("업체명을 입력해 주세요");
	     	   $("#corp_kor").focus();
	     	   return false;
	     	}
	     	else if($("#rep_name").val().trim() == "")
	     	{
	     	   alert("대표자명을 입력해 주세요");
	     	   $("#rep_name").focus();
	     	   return false;
	     	}
	     	else if($("#charge_name").val().trim() == "")
	     	{
	     	   alert("담당자명을 입력해 주세요");
	     	   $("#charge_name").focus();
	     	   return false;
	     	}
	     	else if($("#h_phon_1").val().trim() == "" || $("#h_phon_2").val().trim() == "" || $("#h_phon_3").val().trim() == "" )
	        {
	            alert("휴대전화 번호를 입력해 주시기 바랍니다.");
                return false;
	        }
	     	

	        if(u_email.val().trim() == "")
	        {
	            alert("이메일주소를 입력 해 주세요");
	            u_email.focus();
	            return false;
	        } 
	        else 
	        {
	            if(!regEmail.test(u_email.val())) 
	            {
	                alert("이메일 주소가 유효하지 않습니다");
	                u_email.focus();
	                return false;
	            }
	        }
	        
	        if( status == "" ) {
	        	if( confirm("저장 하시겠습니까? ") ) {
		            submitXmlRequest("/quot/purchase/QuotPurSuppReg_form.screen", "NEW_SAVE_DATA", f, "VALUEOBJECT");
	        	}
	        } else {
	        	if( confirm("수정 하시겠습니까? ") ) {
		            submitXmlRequest("/quot/purchase/QuotPurSuppReg_form.screen", "NEW_UPDATE_DATA", f, "VALUEOBJECT");
	        	}
	        }
		});
		
		
		
		$("#btn_delete").click(function(){
		    if(confirm("삭제 하시겠습니까?"))
	        {
		        submitXmlRequest("/quot/purchase/QuotPurSuppReg_form.screen", "DELETE_DATA", f);
	        }
		});
		
		
	});
	
	
	
	function doResult(resultObj) {
	    
		try {
			if(resultObj.getRequestEvent() == "DELETE_DATA")
			{
			    if( resultObj.getSuccess() ) 
				{
					document.form1.isSubmit = false;
					
					alert("삭제 되었습니다.");
					
					$("#form1").attr("action", "/quot/purchase/QuotPurSuppRegList.screen");
					$("#form1").attr("target", "_self");
					$("#form1").attr("method", "post");
					$("#form1").submit();
					
				}
				else 
				{
				    document.form1.isSubmit = false;
					alert("삭제가 실패하였습니다.");
				}
			} else if( resultObj.getRequestEvent() == "NEW_SAVE_DATA" ) {
				if( resultObj.getSuccess() ) 
				{
					alert("저장 하였습니다.");
					var job_div = $("#job_div").val();
				    
					$("#form1").attr("action", "/quot/purchase/QuotPurSuppRegList.screen");
					$("#form1").attr("target", "_self");
					$("#form1").attr("method", "post");
					$("#form1").submit();
					document.form1.isSubmit = false;
				}
				else 
				{
					alert(resultObj.getValueObject().get("errMsg"));
					document.form1.isSubmit = false;
				}
			} else if ( resultObj.getRequestEvent() == "NEW_UPDATE_DATA" ) {
				if( resultObj.getSuccess() ) 
				{
					document.form1.isSubmit = false;
					
				    alert("수정 하였습니다.");
				    
				    $("#fevent").val("GET_DETAIL");
				    $("#form1").attr("action", "/quot/purchase/QuotPurSuppReg.screen");
					$("#form1").submit();
				}
				else 
				{
				    document.form1.isSubmit = false;
					alert("수정 실패하였습니다.");
				}
			}
		}
		catch(errorObject) {
			showErrorDlg("doResult()", errorObject);
		}
	}
//-->
</script>

<modular:search id="form1">
	<modular:key id="fevent" />
</modular:search>
<form id="form1" name="form1" method="post" modular:type="search">
<INPUT type="hidden" name="fevent" id="fevent" value="">
<input type="hidden" name="p_corp_id" id="p_corp_id" value="<%=params.get("p_corp_id") %>" />
<input type="hidden" name="p_charge_seq" id="p_charge_seq" value="<%=vo.get("CHARGE_SEQ") %>" />
<input type="hidden" name="job_div" id="job_div" value="<%=params.get("job_div") %>" />
<!-- <input type="hidden" name="p_status" id="p_status" value="" /> -->

<!-- 목록 파라메터 -->
<input type="hidden" name="corp_no" id="corp_no" value="<%=params.get("corp_no") %>" />
<input type="hidden" name="corp_name" id="corp_name" value="<%=params.get("corp_name") %>" />
<%-- <input type="hidden" name="STATUS_CD" id="STATUS_CD" value="<%=params.get("STATUS_CD") %>" /> --%>



<table border="0" cellspacing="0" cellpadding="0" style="width: 100%;">
	<tr>
		<td style="text-align: left;">
			<div align="left" id="title" style="float: left;">
				<ul>
			    	<li><%=job_gubun %>_견적용 협력업체 상세</li>
			    	<li>
			   	</ul>
			</div> 
		</td>
		<td style="text-align: right; vertical-align: bottom;">
			<span class="btnSearch center"><a href="javascript:void(0);" id="btn_list">목록</a></span>
			<span class="btnSearch center" id="btn_save_area"><a href="javascript:void(0);" id="btn_save">저장</a></span>
			<span class="btnSearch center" id="btn_delete_area"><a href="javascript:void(0);" id="btn_delete">삭제</a></span>
		</td>
	</tr>
</table>

<!-- 발주의뢰정보 : 시작 -->
<div class="application-info magT10">
	<div class="application-sub-title">
		<span class="title">회사정보</span>
	</div>
</div>
<table cellspacing="1" cellpadding="0" class="form-table">
	<colgroup>
	<col width="100px"/>
	<col WIDTH="25%"/>
	<col width="100px"/>
	<col WIDTH="25%"/>
	<col width="100px"/>
	<col WIDTH="25%"/>
	</colgroup>
				<!-- 검색조건 타이틀 1 -->
	<TH class="required">
		사업자번호
	</th>
	<td>
	<input type="text" name="corp_reg_no" id="corp_reg_no" numberOnly="true" SIZE="10" maxlength="10" value="<%=vo.get("corp_reg_no")%>" />
	</td>
				<TH class="required">
	   				업체명
				</th>
				<td>
					<input type="text" name="corp_kor" id="corp_kor" style="width: 85%;"  value="<%=vo.get("corp_kor")%>" />
			</td>
			<TH class="required">
	   			대표자명
			</th>
			<td>
					<input type="text" name="rep_name" id="rep_name" style="width: 85%;"  value="<%=vo.get("rep_name")%>"/>
	</td>
	</tr>
	
	<tr height="25"> 
	<th class="required">
	 			상태
	</th>
	<td>
			<%=CommCodeManager.getSelectCodeSearchList("QUOT_SUPP_REG_STATUS","STATUS_CD","height=18;width:80px;","",vo.get("STATUS_CD"),"","DETAILCD") %>
	</td>
	<th class="required">
	 			국내/외 구분
	</th>
	<td colspan="3">
			 <%=CommCodeManager.getSelectCodeSearchList("IN_OUT_DIV","in_out_div","height=18;width:80px;","",vo.get("in_out_div"),"","DETAILCD") %>
	</td>
	</tr>
	<tr>
	<th>의견</th>
	<td colspan="5">
		<textarea name="remark" id="remark" rows="5" style="width: 100%;"><%=vo.get("remark") %></textarea>
	</td>
	</tr>
</table>

<div class="application-info magT20">
	<div class="application-sub-title">
		<span class="title">담당자 정보</span>
	</div>
</div>
<table cellspacing="1" cellpadding="0" class="form-table">
	<colgroup>
	<col width="100px"/>
	<col WIDTH="25%"/>
	<col width="100px"/>
	<col WIDTH="25%"/>
	<col width="100px"/>
	<col WIDTH="25%"/>
	</colgroup>
				
				<tr height="25"> 
    				<TH class="required">
    					담당자명
    				</th>
   					<td class="search_table_data">
  						<input type="text" name="charge_name" id="charge_name" style="width: 85%;" value="<%=vo.get("charge_name")%>"/>
					</td>
    				<TH class="required">
        				이메일
    				</th>
    				<td class="search_table_data">
    					<input type="text" name="email" id="email" style="width: 85%;ime-mode:inactive"  value="<%=vo.get("charge_email")%>"/>
    				</td>
    				<TH class="required">
        				휴대전화
    				</th>
    				<td class="search_table_data">
    					<input type="text" name="h_phon_1" id="h_phon_1" SIZE="3" numberOnly="true" maxlength="3" value="<%=vo.get("HP1")%>"/> -
    					<input type="text" name="h_phon_2" id="h_phon_2" SIZE="4" numberOnly="true" maxlength="4" value="<%=vo.get("hp2")%>"/> - 
    					<input type="text" name="h_phon_3" id="h_phon_3" SIZE="4" numberOnly="true" maxlength="4" value="<%=vo.get("hp3")%>"/> 
    				</td>
  				</tr>
			</table>
</form>