<%--
  - Author(s)  : Kim Myung Ho
  - Date       : 2014.08.11
  - Description: 계약결과 리스트
  --%>
  
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="com.udapsoft.waf.system.HandlerStorage" %>
<%@ page import="com.udapsoft.waf.common.ui.*" %>
<%@ 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" />
<%@ page import="kr.co.hsnc.common.config.WAFConfig %>
<%
	String guarUrl = WAFConfig.get("waf.guar.url");

    ctx.init(request, response);
    HandlerStorage storage = ctx.getHandlerStorage();
    ValueObject params = storage.getParams();
    ValueObject user = storage.getUser();
%>
<SCRIPT language="JavaScript">
	/*예약함수*/
	var sheet1 = new ibsheetObject();
	var sheet3 = new ibsheetObject();
	var sheet1Row;
	var sheet1PageNo = 1;
	var pageLastRowIndex = 1;
	var validationResult = false;
	var filterShow = false;
	
	function _onReady(){
		/**
		 *	IBSheet object initialize
		 */
		grid1Init(sheet1);
		grid3Init(sheet3);
		/**
		 *	Application Initialize
		*/
		$("#btnSearch").click(function() {
			jQuery("#fevent").val("SHEET_SELECT");
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/cont/purchase/SubconPayGuarList_sheet.screen";
			Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 30, "");
			
			jQuery("#fevent").val("SHEET_EXCEL");
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/cont/purchase/SubconPayGuarList_sheet.screen";
			Modular.view.IBSheet7.doSearch(sheet3, url, jQuery("#form1"), 30, "");
	
		});	 
		$("#btnExcel").click(function() {
			
			
			if(sheet3.RowCount() == 0) {
				alert("내역이 없습니다.");
				return;
			}
			var params = { FileName : "SubconPayGuarList.xls",  SheetName : "ContTargetList", SheetDesign:0, Merge:1, DownCols:"DEPT_NAME|OUT_ITEM|BUILD_NAME|CONT_NAME|CON_AMT|WARR_AMT|DUR_DATE|WARR_DATE", TitleText:"외주_하도급대금 지급보증 수수료", UserMerge:"0,0,1,8", AutoSizeColumn:1  } ;
			sheet3.Down2Excel(params);
		});	
		$("#p_dept_nm").keydown(function (event){var keycode = (event.keyCode ? event.keyCode : event.which);	if(keycode == 8){$("#p_dept_cd").val("");$("#p_dept_nm").val("");}});
		$("#p_cont_status").change(function(){$("#btnSearch").click();});
		$("#p_build_nm").keydown(function (event){var keycode = (event.keyCode ? event.keyCode : event.which);if(keycode == 13)$("#btnSearch").click();});
		$("#p_dealer_nm").keydown(function (event){var keycode = (event.keyCode ? event.keyCode : event.which);if(keycode == 13)$("#btnSearch").click();});
		//$("#btnSearch").click();  2015.9.17 Default조회 제외.
		$("#dataClear").click(function(){$("#ContFromDt").val("");$("#ContToDt").val("");});
		
		auto1Resize();
	}
	
	/**
	 *	IBSheet object initialize
	 */
	function grid1Init(sheetName){
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, Page:100};
		init_sheet.Cols = [
                    	{Header:'현장명',				Type:"Text", 			SaveName:"DEPT_NAME", 			Width:200, 		Align:"Left" , 		Edit:"false"},
		    			{Header:'☞계약명',			Type:"Text", 			SaveName:"BUILD_NAME", 			Width:200, 		Align:"Left" , 		Edit:"false"},
		    			{Header:'업체명',				Type:"Text", 			SaveName:"MEMBER_NAME", 		Width:80, 		Align:"Left" , 		Edit:"false"},
		    			{Header:'공사기간',			Type:"Text", 			SaveName:"WORK_START_END_DATE", Width:80, 		Align:"Center", 	Edit:"false"},
		    			{Header:'계약금액',			Type:"Text", 			SaveName:"CON_AMT", 			Width:80, 		Align:"right",		Edit:"false"},
		    			{Header:'☞계약번호',			Type:"Text", 			SaveName:"CON_DOC_NO",			Width:120, 		Align:"Left", 		Edit:"false",	Cursor:"pointer"},
		    			{Header:'자료',				Type:"Image", 			SaveName:"IMG_GB", 	   		    Width:50, 		Align:"Center" , 	Edit:"false",	Cursor:"pointer"},
		    			{Header:'변경차수',			Type:"Text", 			SaveName:"MOD_NO", 				Width:50,		Align:"Center",		Hidden:"True"},
		    			{Header:'계약일자',			Type:"Text", 			SaveName:"CON_DATE", 			Width:80, 		Align:"Center" , 	Edit:"false"},
		    			{Header:'상태',				Type:"Combo", 			SaveName:"STATUS_CD", 			Width:80, 		Align:"center", 	Edit:"false",	ComboText:"계약완료", ComboCode:"50",		Hidden:"True"},
		    			{Header:'발급여부',			Type:"Text", 			SaveName:"WARR_STATUS", 		Width:80,  	    Align:"Left", 		Edit:"false"},
		    			{Header:'변경구분',			Type:"Text", 			SaveName:"CAUSECODE_NM", 		Width:80,  	    Align:"Left", 		Edit:"false"},
		    			{Header:'PUR_CONT_MOD_ID',	Type:"Text", 			SaveName:"PUR_CONT_MOD_ID", 	Width:0, 		Align:"Center",		Hidden:"True"},
		    			{Header:'PUR_CONT_ID',		Type:"Text", 			SaveName:"PUR_CONT_ID", 		Width:0, 		Align:"Center",		Hidden:"True"},
		];
		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		sheetName.SetImageList(0,"/img/buyer/button/bt_search_right.gif");
		sheetName.SetActionMenu("ExcelDown");
		setGrid1Size();		
	}
	
	/**
	 *	IBSheet Event: Search End(IBSheet 데이터 조회 CallBack)
	 */
	function sheet1_OnSearchEnd(code, message) {
	    if(code == 0) {
	    	setGrid1Size();
	    	sheet1.SetColFontColor("CON_DOC_NO", "#0000ff");
	    	//2017.07.11 SetImageList로 왜 대체가 안됨. 
	    	for(i=1; i <= sheet1.RowCount(); i++){
	    		sheet1.SetCellImage(i, "IMG_GB", 0);
			}	    	
		} else {
			//조회 에러 수행
			alert(message);
		}
	}
	
	/**
	 *	IBSheet Event: Click
	 */
	function sheet1_OnDblClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
		 if ((sheet1.ColSaveName(Col) == "CON_DOC_NO") && ("<%= user.get("RIGHT_NAME")%>" == "PURCHASE" || "<%= user.get("RIGHT_NAME")%>" == "ADMIN NEW") ) {
				var f = document.form1;
			    f.isSubmit = false;
				$("#PUR_CONT_MOD_ID").val(sheet1.GetCellValue(Row, "PUR_CONT_MOD_ID"));
				$("#PUR_CONT_ID").val(sheet1.GetCellValue(Row, "PUR_CONT_ID"));
				$("#MOD_NO").val(sheet1.GetCellValue(Row, "MOD_NO"));
				 
				if (sheet1.GetCellValue(Row,"WARR_STATUS") == "미신청"){
					$("#fevent").val("INSERT_DATA");
				}else{	
					$("#fevent").val("UPDATE_DATA");
				}
				
				$("#form1").attr("action", "/cont/purchase/SubconPayGuarDetail.screen");
				$("#form1").attr("target", "_self");
				$("#form1").attr("method", "post");
				$("#form1").submit();
			}else if(sheet1.ColSaveName(Col) == "IMG_GB"){
				var job_div = "P";
				var popUrl = "/payment/purchase/PayItemPurDashBoardPop.screen?job_div="+job_div+"&sModule=LM&purContId="+sheet1.GetCellValue(Row, "PUR_CONT_ID")+"&job_auth=<%= user.get("RIGHT_NAME")%>";
				var popOption = "width=800, height=600, resizable=no, scrollbars=yes, status=no;";
	 			window.open(popUrl,"",popOption); 
				
	 		}
	 }
	
	function grid3Init(sheetName){
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, Page:100};
		init_sheet.Cols = [
		    			{Header:'현장명',			 	    Type:"Text", 			SaveName:"DEPT_NAME", 			Width:150, 		Align:"Left" , 		Edit:"false"},
		    			{Header:'공종명',				    Type:"Text", 			SaveName:"OUT_ITEM", 		    Width:150, 		Align:"Left" , 		Edit:"false"},
		    			{Header:'계약명',				    Type:"Text", 			SaveName:"BUILD_NAME", 			Width:100, 		Align:"Left", 		Edit:"false"},
		    			{Header:'업체명',				    Type:"Text", 			SaveName:"CONT_NAME", 			Width:100, 		Align:"Left", 		Edit:"false"},
		    			{Header:'계약금액(VAT포함)',		Type:"Text", 			SaveName:"CON_AMT", 		    Width:100, 		Align:"right",		Edit:"false"},
		    			{Header:'수수료금액',				Type:"Text", 			SaveName:"WARR_AMT",	        Width:150, 		Align:"right", 	    Edit:"false"},
		    			{Header:'계약기간',				Type:"Text", 			SaveName:"DUR_DATE", 			Width:180,		Align:"Center",		Edit:"false"},
		    			{Header:'발행날짜',				Type:"Text", 			SaveName:"WARR_DATE", 		    Width:80, 		Align:"Center" , 	Edit:"false"},
		    			
		];
		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		setGrid3Size();		
	}
	

	function sheet3_OnSearchEnd(code, message) {
	    if(code == 0) {
	    	
		} else {
			//조회 에러 수행
			alert("상세조회 실패");
		}
	}
	function setGrid3Size() {sheet3.FitColWidth();}
	function sheet3_OnSmartResize(Width, Height) { 
		sheet3.FitColWidth();
	}
	function auto3Resize(){
		var t1_height = document.getElementById("t1").scrollHeight + 10;
		var iframeHeight= document.body.scrollHeight - t1_height;   
		var iframeWidth= document.body.scrollWidth;   
		sheet3.SetSheetHeight(iframeHeight); 
	}	
	/**
	 *	IBSheet size setting
	 */
	function setGrid1Size() {sheet1.FitColWidth();}

	function sheet1_OnSmartResize(Width, Height) { 
		sheet1.FitColWidth();
		//auto1Resize();
		
	}
	function auto1Resize(){
		var t1_height = document.getElementById("search-table").scrollHeight + document.getElementById("title").scrollHeight+ 24;
		var iframeHeight= document.body.scrollHeight - t1_height;   
		var iframeWidth= document.body.scrollWidth;   
		
		sheet1.SetSheetHeight(iframeHeight); 
	}	
	

	//자동로그인 기능
	function f_gologin(login_id,login_pw){
		var f = document.form1;
		if('<%= user.get("ACCT_TYPE_CODE")%>' != "ADMIN"){
			dlgAlert("User who logged in as administrator only can do automatic log-in.");
			return;
		}
	
		f.login_id.value = login_id;
		f.login_pw.value = login_pw;
	
		if( !submitXmlRequest("/sign_on_check", "", document.form1) ) {
			alert("Log-in is being processed.");
		};
		
	}

	function doAttachFilePop(obj, No, fObj, fileGB, fileDir) {
		var editFile = "";
		 if(obj==''){
			alert("After you have saved, you can attach a file.");
		}
		else if(obj != ''){ 
			if(fObj.guarStatus.value != "02"){editFile="Y";}else{editFile="Y";}
			if(No=="1"){
				viewFileListNew(fileGB, obj.value, fObj.p_AttachFileGuar1, editFile, fileDir, "subconPayOutOffPopup");
			}else{
				viewFileListNew(fileGB, obj.value, fObj.p_AttachFileGuar2, editFile, fileDir, "subconPayOutOffPopup");
			}
		} 
	} 

	//보증정보팝업 호출
	function popContWarr(wG, wSeq, wCauseCd, wOnOff, wGStatus, wOffid, wConRefNo) {
		var win_id = "subconPayOutOffPopup";			
		var param = "";
		var param = "?purContModId=" + jQuery("#PUR_CONT_MOD_ID").val();
		var param = param + "&warrGubun=" + wG;
		var param = param + "&warrSeq=" + wSeq;
		var param = param + "&causeCode=" + wCauseCd;
		var param = param + "&viewDiv=SUBCONPAY";
		var param = param + "&pop_win_id=" + win_id;
		var url = "";

		if (wOnOff == ""){
			alert("발급구분을 선택해 주세요.");return;
		}
		if(wOnOff=="N"){
			var param = param + "&fevent=WARR_OFF";
			url = "/portal/guar/subconPayOutOffPopup.screen"+param;			
			fLayerPop(win_id, url, 560,500, '','', 'YES');
		}else if(wOnOff=="Y"){
			if((wGStatus=="08") || (wGStatus=="09")){
				var	sGuarKind		=	wG;														//보증서종류
				var	sGuarSeq		=	wSeq;															//일련번호
				var	sGuarOnoffYn	=	wOnOff;												//온오프여부
				var	sGuarStatus		=	wGStatus;													//보증진행상태
				var	sChgNo			=	jQuery("#MOD_NO").val();	//계약차수
				var	style			=	"";
				var	src				=	"";
				var	sGrtType	=	"006";	//	보증종목구분 : 지급
				//검토대기나 완료일경우
				if(sGuarOnoffYn == "Y" && sGuarStatus.length > 0 && (sGuarStatus == "08" || sGuarStatus == "09")){
					var	sOffId				=	wOffid;		//	수신기관 ID
					var	conRefNo			=	wConRefNo; 							//	계약번호
					var	sGrtSeq				=	wSeq;	//	보증차수			
					var	sMsgFuncCode		=	"53";																//	문서기능
					var	sModule				=	"EB";																//	모듈구분코드
					
					if(sChgNo == "")	
						sChgNo	=	"00";
					else if(sChgNo.length == 1)
						sChgNo = "0" + sChgNo;
						
					if(sGrtSeq.length == 1)
						sGrtSeq = "0" + sGrtSeq;
						
					//parameter 확인 요함
					src		= "<%=guarUrl%>/transure/view/KSCFCView.jsp?offID="+sOffId+"&conRefNo="+conRefNo+"&conSeqNo="+sChgNo+"&grtSeq="+sGrtSeq+"&grtType="+sGrtType+"&msgFuncCode="+sMsgFuncCode+"&module="+sModule;
					style	=	"width=720,height=800, loactionbar=visible, menubar=visible, scrollbars=no";
				}
				//alert(src);
				var	id		=	"WARR";		
				var	clNew	=	window.open(src,id,style);
				
				if(clNew == null){
					alert("          ▒【보증신청】페이지는 팝업창으로 구성되어 있습니다. ▒\n\n\n'팝업이 차단되었습니다. 팝업 또는 추가 옵션을 보려면 여기를 클릭하십시오.' 라는\n\n 메세지가 보일경우에는 그 메세지를 클릭하셔서 '현재 사이트의 팝업을 항상 허용'이나\n\n'임시로 팝업허용'으로 설정해주시기 바랍니다.");
				}else{
					clNew.focus();
				}				
			}else{		//온라인 처음 등록
				var param = param + "&fevent=WARR_ON";
				var param = param + "&PUR_CONT_ID=" + jQuery("#PUR_CONT_ID").val();
				var param = param + "&MOD_NO=" + jQuery("#MOD_NO").val();
				url = "/portal/guar/subconPayOutOnPopup.screen"+param;			
				fLayerPop(win_id, url, 800,700, '','', 'YES');				
			}
		}	
	}	
	//보증정보팝업 종료후 액션
	function popContWarrClose(returnValue){
		if(returnValue == null){
			fLayerPopClose('subconPayOutOffPopup');
		}else{
			if(returnValue[0] == 0){
				fLayerPopClose('subconPayOutOffPopup');
				var f = document.form1;
			    f.isSubmit = false;
				$("#PUR_CONT_MOD_ID").val(returnValue[2]);
				jQuery("#fevent").val("SHEET_WARR");
				var url = Modular.model.PageContext.CONTEXT_ROOT + "/cont/purchase/SubconPayGuarList_sheet.screen";
				Modular.view.IBSheet7.doSearch(sheet2, url, jQuery("#form1"), 10, "");
			}
		}
	}
	
	document.body.onresize = addEvent( document.body.onresize, "auto1Resize()");
</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="PUR_CONT_MOD_ID" value="">
<INPUT type="hidden" name="PUR_CONT_ID" value="">
<INPUT type="hidden" name="MOD_NO" value="">
<INPUT type='hidden' name="acct_id" value="<%= params.get("acct_id") %>">
<INPUT type='hidden' name="p_cont_status" value="50">

<div align="left" id="title">
	<ul>
		<li><%= storage.getPgmName() %></li>
	</ul>
</div> 

<!-- 검색조건 시작 -->
<table id="search-table" class="search-form-table">
	<colgroup>
		<col width="100" />
		<col width="*" />
		<col width="100" />
		<col width="*" />
		<col width="100" />
	</colgroup>
  <tr height="25"> 
  	<th>현장</th>
   	<td>
  		<%=InputText.getSiteCodeNew("p_dept_cd", "p_dept_nm", "", user, params.get("p_dept_cd"), params.get("p_dept_nm"))%>
	</td>
  	<th>계약명</th>
   	<td>
   		<INPUT type="text" name="p_build_nm" class="input" value="<%= params.get("p_build_nm") %>" style="width:90%"> 
	</td>
	<td class="button" rowspan="2">
		<span class="btnSearch center" id="btnSearch"><a href="javascript:void(0);">검색</a></span>
		<span class="btnSearch center" id="btnExcel"><a href="javascript:void(0);">엑셀</a></span>
	</td>	
  </tr>
  <tr>	
    <th>업체명</th>
    <td> 
       <INPUT type="text" name="p_dealer_nm" class="input" value="<%= params.get("p_dealer_nm") %>" style="width:90%"> 
    </td>
    <th>계약기간</th>
    <td> 
		<%= InputText.get("ContFromDt", params.get("ContFromDt"), 10, 50, "hangule,center, desc=계약일자,ReadOnly") %>
		<IMG name="start_img" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" style="cursor:pointer;" onClick="JavaScript:dlgCalendar('ContFromDt');">
					~
		<%= InputText.get("ContToDt", params.get("ContToDt"), 10, 50, "hangule,center, desc=계약일자,ReadOnly") %>
		<IMG name="start_img" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" style="cursor:pointer;" onClick="JavaScript:dlgCalendar('ContToDt');">
		<IMG name="dataClear" id="dataClear" src="/img/buyer/button/bt_eraser1.gif" border="0" align="absmiddle" style="cursor:pointer;">
    </td>    
  </tr>
</table>
</form>


<div id="sheet1_div" style="padding-top:5px; height: auto; min-height: 315px; overflow: auto;">
	<script>createIBSheet('sheet1','100%', '300px');</script>
</div>
 
<div id="sheet3_div" style="padding-top:5px; height: auto; min-height: 130px; overflow: auto; display:none;"> 
	<script>createIBSheet('sheet3','100%', '130px');</script>
</div>