<%--
  - FileName   : resolutionFinishList.jsp
  - Author(s)  : ok
  - Date       : 2014.07.18
  - Copyright  : Copyright (c) 2013 www.udapsoft.co.kr, Inc.
  - 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" />
<%
    ctx.init(request, response);
    HandlerStorage storage = ctx.getHandlerStorage();
    ValueObject params = storage.getParams();
    ValueObject user = storage.getUser();
    String event = storage.getEvent();
    //String deptCd   = user.get("site_code");
    //String deptName = user.get("site_name");
    //deptCd   = params.get("buseo");
    //RowSet rowSet = storage.getRowSet("ROWSET");
    //RowSet acctTypeRowSet = storage.getRowSet("AcctTypeRowSet"); //계정 타입
    //System.out.println("acctyType:"+acctTypeRowSet);
  
    //상태
    String statusSheetComboListText 	   = (String)storage.getObject("selectText");
	String statusSheetComboListValue 	   = (String)storage.getObject("selectValue");
	
%>
<SCRIPT language="JavaScript">
	/*예약함수*/
	var sheet1;
	var sheet1Row;
	var sheet1PageNo = 1;
	var sheet2;
	var sheet2Row;
	var sheet2PageNo = 1;	
	var pageLastRowIndex = 1;
	var validationResult = false;
	var filterShow = false;
	
	function _onReady(){
		/**
		 *	IBSheet object initialize
		 */
		gridInit(sheet1);
		grid2Init(sheet2);
		
		autoResize();
	
		/**
		 *	Application Initialize
		 */
		jQuery("#btnSearch").click(function() {
 
 			if(jQuery("#searchDeptCd").val() == ""){
				alert("현장을 선택해주세요.");
				jQuery("#searchDeptCd").focus();
				return;
			}  
			
 			if($('#surtaxGb').val() == '1'){
 	 			jQuery("#fevent").val("GET_DATA");
 				var url = Modular.model.PageContext.CONTEXT_ROOT + "/payment/outside/ResolutionFinishList_sheet.screen";
 				Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 10, ""); 
 			} else {
 	 			jQuery("#fevent").val("GET_DATA2");
 				var url = Modular.model.PageContext.CONTEXT_ROOT + "/payment/outside/ResolutionFinishList_sheet.screen";
 				Modular.view.IBSheet7.doSearch(sheet2, url, jQuery("#form1"), 10, "");  				
 			} 					
		});
		
		pageinit();
		
	}
	
	function pageinit(){
		
		//달력 조건에 당해년도1월, 당해년도당월 셋팅
		setSearchDate();
		
		//jQuery("#btnSearch").click();
	      
	}
	
	/**
	 *	IBSheet object initialize
	 */
	function gridInit(sheetName){
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, Page:10, MergeSheet:7,PrevColumnMergeMode:0};
		init_sheet.Cols = [
			    			{Header:'상태|상태',					Type:"Status", 			SaveName:"Status",					Width:100, 	Align:"Left", Hidden:"True"},
			    			{Header:'현장명|현장명',				Type:"Text", 			SaveName:"DEPT_NAME",				Width:100, 	Align:"Left"},
			    			{Header:'계약번호|계약번호',				Type:"Text", 			SaveName:"CON_DOC_NO",				Width:120, 	Align:"Left", Hidden:"True"},
			    			{Header:'계약명|계약명',				Type:"Text", 			SaveName:"BUILD_NAME",				Width:110, 	Align:"Left"},
			    			{Header:'업체명|업체명',				Type:"Text", 			SaveName:"MEMBER_NAME",				Width:100, 	Align:"Left"},
			    			{Header:'공사기간|공사기간',				Type:"Text", 			SaveName:"START_END_WORK_DATE", 	Width:130, 	Align:"Left"},
			    			{Header:'통화구분|통화구분',				Type:"Text", 			SaveName:"CURRENCY_GB",				Width:55, 	Align:"Center"},
			    			{Header:'통화구분자리|통화구분자리',		Type:"Int", 			SaveName:"CURRENCY_DIGIT",			Width:100, 	Align:"Left", Hidden:"True"},
			    			{Header:'계약금액|계약금액',				Type:"Int", 			SaveName:"CON_SUPPLY_AMT",	 		Width:80, 	Align:"Right"},
			    			{Header:'계약금액|합계',				Type:"Int", 			SaveName:"CON_AMT", 				Width:40, 	Align:"Right", Hidden:"True"},
			    			{Header:'계약상선급금|계약상선급금',		Type:"Int", 			SaveName:"PREPAY_SUPPLY_AMT",	 	Width:80, 	Align:"Right"},
			    			{Header:'선급금발생|선급금발생',			Type:"Int", 			SaveName:"REQ_PREPAY_SUPPLY_AMT",	Width:80, 	Align:"Right"},
			    			{Header:'선급금\n신청날짜|선급금\n신청날짜',Type:"Text", 			SaveName:"PREPAY_DATE",	 			Width:65, 	Align:"Right"},
			    			{Header:'기성년월|기성년월',				Type:"Text", 			SaveName:"ACMP_YYYYMM",	 			Width:50, 	Align:"Right"},
			    			{Header:'지급\n차수|지급\n차수',			Type:"Int", 			SaveName:"ACMP_NO",	 				Width:40, 	Align:"Right"},
			    			{Header:'기성액|금회기성',				Type:"Int", 			SaveName:"FUND_AMT",	 			Width:80, 	Align:"Right"},
			    			{Header:'기성액|선급금공제',				Type:"Int", 			SaveName:"PAY_DEDUCT_AMT",	 		Width:80, 	Align:"Right"},
			    			{Header:'기성액|실지불액',				Type:"Int", 			SaveName:"REQU_SUPPLY_AMT",	 		Width:80, 	Align:"Right"},
			    			{Header:'기성액|잔여기성',				Type:"Int", 			SaveName:"MOD_FUND_AMT",	 		Width:80, 	Align:"Right"},
			    			{Header:'기성율\n(%)|기성율\n(%)',		Type:"Float", 			SaveName:"FUND_RATE",	 			Width:40, 	Align:"Right",	Format:"##0.00"},
			    			{Header:'상태|상태',					Type:"Combo", 			SaveName:"STATUS_CD",	 			Width:50, 	Align:"Center",	ComboText:"<%=statusSheetComboListText%>", ComboCode:"<%=statusSheetComboListValue%>"}
			    			
		];

		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		sheetName.SetEditable(false);
		
		var info = [{StdCol:1, SumCols:"CON_AMT|FUND_AMT", ShowCumulate:0,Sort:0,CaptionCol:1}
	    ,{StdCol:2, SumCols:"CON_AMT|FUND_AMT|PAY_DEDUCT_AMT|REQU_SUPPLY_AMT|FUND_RATE", ShowCumulate:0,Sort:0,CaptionCol:2}];
		sheetName.ShowSubSum(info);
		sheetName.SetActionMenu("ExcelDown");
		setGridSize();
	}

	function sheet1_OnSelectMenu(Text, Code) {
		// text 또는 code값으로 Action수행
		switch(Text) {
			case "ExcelDown":
			sheetExcelDown(sheet1,$('li').html());
			break;
		}
	}

	
	/**
	 *	IBSheet Event: Search End(IBSheet 데이터 조회 CallBack)
	 */
	function sheet1_OnSearchEnd(code, message) {
	    if(code == 0) {
	    	
	    	//sheet1.SetSumValue(0,"합 계");
	    	//sheet1.SetCellAlign(sheet1.LastRow(),0,"Center");
	    	//sheet1.SetMergeCell (sheet1.LastRow(), 0, 1,11);
	    	
	    	var lr = sheet1.LastRow();
	    	var str = "";
	    	var startrow = 2;
	    	var endrow = 0;
	    	var backColor = "";

	    	var totalConAmtValue = 0;
	    	var totalModAmtValue = 0;
	    	var totalRatAmtValue = 0.00;
  	    	for(var i=2; i <= lr; i++){
  	    		endrow = endrow + 1;
	   			
  	    		str = sheet1.GetCellText(i,2);
  	   			if(str.indexOf("소계:") > -1){
  	   				var digit = sheet1.GetCellValue(i -1 , "CURRENCY_DIGIT");
	   				sheet1.SetCellAlign(i,3,"Center");
	   				
	   				sheet1.SetCellText(i,3, "소계");
	   				
	   				//sheet1.SetRangeBackColor(i,2,i,12,"#fffacd");
	   			
   					sheet1.SetMergeCell(i,3,1,12);
   					
     				var conAmtValue = sheet1.GetCellValue(i - 1, "CON_AMT");
     				var conAmtValue2 = sheet1.GetCellValue(i - 1, "CON_SUPPLY_AMT");
    				totalConAmtValue = Number(totalConAmtValue) + Number(conAmtValue2); 
    				sheet1.SetCellValue(i, "CON_AMT", conAmtValue.toFixed(digit));
    				var modAmtValue = sheet1.GetCellValue(i - 1, "MOD_FUND_AMT");
    				totalModAmtValue = Number(totalModAmtValue) + Number(modAmtValue);
    				sheet1.SetCellValue(i, "MOD_FUND_AMT", Number(modAmtValue).toFixed(digit));
    				if( sheet1.GetCellValue(i, "MOD_FUND_AMT") == "0" ) { sheet1.SetCellValue(i, "FUND_RATE", "100"); }
    				
    				//var test = sheet1.GetCellValue(i - 1, "DEPT_NAME");
    				//sheet1.SetCellValue(i, "DEPT_NAME", test);
    				
    				//endrow = i - startrow;    			
    				
    				if(digit == 0){
	    				var info = {Type: "Int" , Format:"Integer"};
	    				sheet1.InitCellProperty(i , "FUND_AMT", info);
	    				sheet1.InitCellProperty(i , "PAY_DEDUCT_AMT", info);
	    				sheet1.InitCellProperty(i , "REQU_SUPPLY_AMT", info);
	    				sheet1.InitCellProperty(i , "MOD_FUND_AMT", info);
    				}else{
    					var info = {Type: "Float" , PointCount:digit};
	    				sheet1.InitCellProperty(i , "FUND_AMT", info);
	    				sheet1.InitCellProperty(i , "PAY_DEDUCT_AMT", info);
	    				sheet1.InitCellProperty(i , "REQU_SUPPLY_AMT", info);
	    				sheet1.InitCellProperty(i , "MOD_FUND_AMT", info);
    				}
	    		}
	   			str = sheet1.GetCellText(i,1);
	    		if(str.indexOf("소계:") > -1){
	    			sheet1.SetCellAlign(i,1,"Center");
	    			
	    			sheet1.SetCellText(i,1, "소계");
	    			
	    			//sheet1.SetRangeBackColor(i,1,i,12,"#e0ffff");

	    			//alert(startrow);
	    			//alert(endrow);
	    			
	    			sheet1.SetMergeCell(startrow, 1, endrow, 1);

   					sheet1.SetMergeCell(i,1,1,14);
   					
    				var fundAmtValue = sheet1.GetCellValue(i, "FUND_AMT");	
    				totalRatAmtValue = Number(fundAmtValue) / Number(totalConAmtValue) * 100;	

    				sheet1.SetCellValue(i, "CON_AMT", totalConAmtValue);
    				sheet1.SetCellValue(i, "MOD_FUND_AMT", totalModAmtValue);
    				sheet1.SetCellValue(i, "FUND_RATE", totalRatAmtValue.toFixed(2));
    				
    				var info = {Type: "Int" , Format:"Integer"};
    				sheet1.InitCellProperty(i , "CON_AMT", info);
    				sheet1.InitCellProperty(i , "MOD_FUND_AMT", info);
    				
    				
   		    		totalConAmtValue = 0;	
    		    	totalModAmtValue = 0;
    		    	totalRatAmtValue = 0.00;
    		    	
    		    	startrow = i + 1;
    		    	endrow = 0;
	    		
	    		}
	    		
	    		if(sheet1.GetCellValue(i , "CURRENCY_DIGIT") != ""){
		    		if(sheet1.GetCellValue(i , "CURRENCY_DIGIT") > 0){
		    			var digit = sheet1.GetCellValue(i, "CURRENCY_DIGIT");
	    				var info = {Type: "Float" , PointCount:digit};
	    				sheet1.InitCellProperty(i , "CON_SUPPLY_AMT", info);
	    				sheet1.InitCellProperty(i , "CON_AMT", info);
	    				sheet1.InitCellProperty(i , "PREPAY_SUPPLY_AMT", info);
	    				sheet1.InitCellProperty(i , "REQ_PREPAY_SUPPLY_AMT", info);
	    				sheet1.InitCellProperty(i , "PREPAY_DATE", info);
	    				sheet1.InitCellProperty(i , "FUND_AMT", info);
	    				sheet1.InitCellProperty(i , "PAY_DEDUCT_AMT", info);
	    				sheet1.InitCellProperty(i , "REQU_SUPPLY_AMT", info);
	    				sheet1.InitCellProperty(i , "MOD_FUND_AMT", info);
	    			}else{
	    				var info = {Type: "Int" , PointCount:digit};
	    				sheet1.InitCellProperty(i , "CON_SUPPLY_AMT", info);
	    				sheet1.InitCellProperty(i , "CON_AMT", info);
	    				sheet1.InitCellProperty(i , "PREPAY_SUPPLY_AMT", info);
	    				sheet1.InitCellProperty(i , "REQ_PREPAY_SUPPLY_AMT", info);
	    				sheet1.InitCellProperty(i , "PREPAY_DATE", info);
	    				sheet1.InitCellProperty(i , "FUND_AMT", info);
	    				sheet1.InitCellProperty(i , "PAY_DEDUCT_AMT", info);
	    				sheet1.InitCellProperty(i , "REQU_SUPPLY_AMT", info);
	    				sheet1.InitCellProperty(i , "MOD_FUND_AMT", info);
	    			}
	    		}
	    		
	    		
		    	/* var info = {Type: "Int", Align: "Right", Format:"Integer"};
		    	sheet1.InitCellProperty(i, "CON_AMT", info);
		    	info = {Type: "Int", Align: "Right", Format:"Integer"};
		    	sheet1.InitCellProperty(i, "MOD_FUND_AMT", info);
		    	 */
		    	
		    	
	    	
	    	} 
	    	
	    	setGridSize();
		} else {
			//조회 에러 수행
			alert(message);
		}
	}
	
	/**
	 *	IBSheet Event: Save End(IBSheet 데이터 저장 CallBack)
	 */
	function sheet1_OnSaveEnd(code, msg) {
	    if(code >= 0) {
	    	alert("저장 성공");
	    } else {
	    	alert(msg);
        }
	}
	
	/**
	 *	IBSheet Event: Click
	 */
	function sheet1_OnClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
		 //masterSheetRow = Row;
	}
	
	/**
	 *	IBSheet size setting
	 */
	function setGridSize() {
		sheet1.FitColWidth();
	}
	
	/**
	 *	IBSheet Event: DBLCLICK
	 */
	 function sheet1_OnDblClick(Row, Col, Value, CellX, CellY, CellW, CellH) {

	 }

	function doResult(resultObj) {
		try {
			if( resultObj.getRequestEvent() == "" ) {
				if( resultObj.getSuccess() ) {				
					var f = document.form1;   				  				
					f.action = "/main.screen";				
	    			f.target = "_parent";             			
	    			f.submit();			
				}
				else {
					dlgErrorMsg(resultObj);
				}
				document.form1.isSubmit = false;
			}else if( resultObj.getRequestEvent() == "GET_EHR_DATA" ) {
				if( resultObj.getSuccess() ) {
					alert("EHR Synchronize Complete");
					doSearch(document.all.sheet1);
				}
				else {
					dlgErrorMsg(resultObj);
				}
				document.form1.isSubmit = false;
			}
		}
		catch(errorObject) {
	        showErrorDlg("doResult()", errorObject);
		}
	}


	function searchAccDept(p_dept_cd, p_dept_nm){
		
		result = window.showModalDialog(getDummyUrl('/lib/dlgSearchAccDept.screen'),'부서 찾기','dialogWidth:620px;dialogHeight:460px; center:yes; help:no; status:no; scroll:no; resizable:no');
		
		if( result == null ){
			document.form1.p_dept_cd.value = "";   //부서코드
			document.form1.p_dept_nm.value = "";   //부서명

		}else{
			document.form1.p_dept_cd.value = result[0];   //부서코드
			document.form1.p_dept_nm.value = result[1];   //부서명
		}

	}

	function doKeyPress() {
	
	    if( event.keyCode == 13 ) {
			jQuery("#btnSearch").click();
	    }
	}	

	function calendar(thisDayObj){
		dlgMCalendar(thisDayObj);
		
	}		
	
	//검색조건에 기성년월 초기 설정
	function setSearchDate(){
	    
		var newDay = new Date( get_year(), get_month(), "");
	    var lastDay = newDay.getDate();
	    //var yyyymmbeginning = get_year() +'-'+ get_month() +'-'+ '01';
	    //var yyyymmlast	= get_year() +'-'+ get_month() +'-'+ lastDay;
	    var searchFromDate = get_year() +'-'+ '01';
	    var searchToDate   = get_year() +'-'+ get_month();
    	    
	    jQuery('#searchFromDate').val(searchFromDate);
	    jQuery('#searchToDate').val(searchToDate);

	}

	function sheet1_OnSmartResize(Width, Height) { 
		sheet1.FitColWidth();
		autoResize();
	}
	
	function autoResize(){
		var t1_height = document.getElementById("search-table").scrollHeight  + document.getElementById("bugase").scrollHeight + document.getElementById("title").scrollHeight + 54;
		var iframeHeight= document.body.scrollHeight - t1_height;   
		var iframeWidth= document.body.scrollWidth;   
		
		
		sheet1.SetSheetHeight(iframeHeight); 
	}
	
	function searchSite() {
		
		var win_id = "_searchSite";
		var link = "/lib/dlgSearchSpotDept_Unitcd.screen";
		    link += "?pop_win_id="+win_id;
		fLayerPop(win_id, link, 550,500, '', '', 'NO');
		
	}
	
	function searchSiteClose(result) {
		if( result == null ){
			document.form1.searchDeptCd.value = "";   //부서코드
			document.form1.searchDeptNm.value = "";   //부서명
		}else{
			document.form1.searchDeptCd.value = result[0];   //부서코드
			document.form1.searchDeptNm.value = result[1];   //부서명
		}
		fLayerPopClose('_searchSite');
	}

	function chgSurtaxGb(val){
		if(val == '1'){
			$('#spnSurtaxGb').text('별도');
			jQuery('#sheet2_div').hide();
			jQuery('#sheet1_div').show(); 		
		} else {
			$('#spnSurtaxGb').text('포함');
			jQuery('#sheet1_div').hide();
			jQuery('#sheet2_div').show();
		}		
	}
	
	/**
	 *	IBSheet object initialize
	 */
	function grid2Init(sheetName){
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, Page:10, MergeSheet:7,PrevColumnMergeMode:0};
		init_sheet.Cols = [
			    			{Header:'상태|상태|상태',					Type:"Status", 			SaveName:"Status",					Width:100, 	Align:"Left", Hidden:"True"},
			    			{Header:'현장명|현장명|현장명',				Type:"Text", 			SaveName:"DEPT_NAME",				Width:100, 	Align:"Left"},
			    			{Header:'계약번호|계약번호|계약번호',		Type:"Text", 			SaveName:"CON_DOC_NO",				Width:120, 	Align:"Left", Hidden:"True"},
			    			{Header:'계약명|계약명|계약명',				Type:"Text", 			SaveName:"BUILD_NAME",				Width:110, 	Align:"Left"},
			    			{Header:'업체명|업체명|업체명',				Type:"Text", 			SaveName:"MEMBER_NAME",				Width:100, 	Align:"Left"},
			    			{Header:'공사기간|공사기간|공사기간',		Type:"Text", 			SaveName:"START_END_WORK_DATE", 	Width:130, 	Align:"Left"},
			    			{Header:'통화구분|통화구분|통화구분',		Type:"Text", 			SaveName:"CURRENCY_GB",				Width:55, 	Align:"Center"},
			    			{Header:'통화구분자리|통화구분자리|통화구분자리',	Type:"Int", 		SaveName:"CURRENCY_DIGIT",			Width:100, 	Align:"Left", Hidden:"True"},
			    			{Header:'계약금액|공급가|공급가',			Type:"Int", 			SaveName:"CON_SUPPLY_AMT",	 		Width:80, 	Align:"Right"},
			    			{Header:'계약금액|부가세|부가세',			Type:"Int", 			SaveName:"CON_SURTAX_AMT",	 		Width:80, 	Align:"Right"},
			    			{Header:'계약금액|합계|합계',				Type:"Int", 			SaveName:"CON_AMT", 				Width:80, 	Align:"Right"},
			    			{Header:'계약상선급금|공급가|공급가',		Type:"Int", 			SaveName:"PREPAY_SUPPLY_AMT",	 	Width:80, 	Align:"Right"},
			    			{Header:'계약상선급금|부가세|부가세',		Type:"Int",				SaveName:"PREPAY_SURTAX_AMT",	 	Width:80, 	Align:"Right"},
			    			{Header:'선급금발생|공급가|공급가',			Type:"Int", 			SaveName:"REQ_PREPAY_SUPPLY_AMT",	Width:80, 	Align:"Right"},
			    			{Header:'선급금발생|부가세|부가세',			Type:"Int", 			SaveName:"REQ_PREPAY_SURTAX_AMT",	Width:80, 	Align:"Right"},
			    			{Header:'선급금\n신청날짜|선급금\n신청날짜|선급금\n신청날짜',Type:"Text", SaveName:"PREPAY_DATE",	 		Width:65, 	Align:"Right"},
			    			{Header:'기성년월|기성년월|기성년월',		Type:"Text", 			SaveName:"ACMP_YYYYMM",	 			Width:50, 	Align:"Right"},
			    			{Header:'지급\n차수|지급\n차수|지급\n차수',	Type:"Int", 			SaveName:"ACMP_NO",	 				Width:40, 	Align:"Right"},
			    			{Header:'기성액|금회기성|금회기성',			Type:"Int", 			SaveName:"FUND_AMT",	 			Width:80, 	Align:"Right"},
			    			{Header:'기성액|선급금공제|선급금공제',		Type:"Int", 			SaveName:"PAY_DEDUCT_AMT",	 		Width:80, 	Align:"Right"},
			    			{Header:'기성액|실지불액|공급가',			Type:"Int", 			SaveName:"REQU_SUPPLY_AMT",	 		Width:80, 	Align:"Right"},
			    			{Header:'기성액|실지불액|부가세',			Type:"Int", 			SaveName:"REQU_SURTAX_AMT",	 		Width:80, 	Align:"Right"},
			    			{Header:'기성액|실지불액|합계',				Type:"Int", 			SaveName:"REQU_AMT",		 		Width:80, 	Align:"Right"},
			    			{Header:'기성액|잔여기성|공급가',			Type:"Int", 			SaveName:"MOD_FUND_AMT",	 		Width:80, 	Align:"Right"},
			    			{Header:'기성액|잔여기성|부가세',			Type:"Int", 			SaveName:"MOD_SURTAX_AMT",	 		Width:80, 	Align:"Right"},
			    			{Header:'기성액|잔여기성|합계',				Type:"Int", 			SaveName:"MOD_AMT",	 				Width:80, 	Align:"Right"},
			    			{Header:'기성율\n(%)|기성율\n(%)|기성율\n(%)',	Type:"Float", 		SaveName:"FUND_RATE",	 			Width:40, 	Align:"Right",	Format:"##0.00"},
			    			{Header:'상태|상태|상태',					Type:"Combo", 			SaveName:"STATUS_CD",	 			Width:50, 	Align:"Center",	ComboText:"<%=statusSheetComboListText%>", ComboCode:"<%=statusSheetComboListValue%>"}
			    			
		];

		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		sheetName.SetEditable(false);
		
		var info = [{StdCol:1, SumCols:"CON_AMT|FUND_AMT", ShowCumulate:0,Sort:0,CaptionCol:1}
	    ,{StdCol:2, SumCols:"CON_AMT|FUND_AMT|PAY_DEDUCT_AMT|REQU_SUPPLY_AMT|REQU_SURTAX_AMT|REQU_AMT|FUND_RATE", ShowCumulate:0,Sort:0,CaptionCol:2}];
		sheetName.ShowSubSum(info);
		sheetName.SetActionMenu("ExcelDown");
		setGrid2Size();
	}	
	
	/**
	 *	IBSheet size setting
	 */
	function setGrid2Size() {
		sheet2.FitColWidth();
	}
	
	function sheet2_OnSelectMenu(Text, Code) {
		// text 또는 code값으로 Action수행
		switch(Text) {
			case "ExcelDown":
			sheetExcelDown(sheet2,$('li').html());
			break;
		}
	}
	
	/**
	 *	IBSheet Event: Search End(IBSheet 데이터 조회 CallBack)
	 */
	function sheet2_OnSearchEnd(code, message) {
	    if(code == 0) {
	    	//sheet1.SetSumValue(0,"합 계");
	    	//sheet1.SetCellAlign(sheet1.LastRow(),0,"Center");
	    	//sheet1.SetMergeCell (sheet1.LastRow(), 0, 1,11);
	    	
	    	var lr = sheet2.LastRow();
	    	var str = "";
	    	var startrow = 3;
	    	var endrow = 0;
	    	var backColor = "";

	    	var totalConAmtValue = 0;
	    	var totalModAmtValue = 0;
	    	var totalModSurtaxAmtValue = 0;
	    	var totalModValue = 0;
	    	var totalRatAmtValue = 0.00;
  	    	for(var i=3; i <= lr; i++){
  	    		endrow = endrow + 1;
  	    		str = sheet2.GetCellText(i,2);
  	   			if(str.indexOf("소계:") > -1){
  	   				var digit = sheet2.GetCellValue(i -1 , "CURRENCY_DIGIT");
	   				sheet2.SetCellAlign(i,3,"Center");
	   				
	   				sheet2.SetCellText(i,3, "소계");
	   				
	   				//sheet1.SetRangeBackColor(i,2,i,12,"#fffacd");
	   			
   					sheet2.SetMergeCell(i,3,1,15);
   					
     				var conAmtValue = sheet2.GetCellValue(i - 1, "CON_AMT");
     				var conAmtValue2 = sheet2.GetCellValue(i - 1, "CON_SUPPLY_AMT");
    				totalConAmtValue = Number(totalConAmtValue) + Number(conAmtValue2); 
    				sheet2.SetCellValue(i, "CON_AMT", conAmtValue.toFixed(digit));
    				var modAmtValue = sheet2.GetCellValue(i - 1, "MOD_FUND_AMT");
    				totalModAmtValue = Number(totalModAmtValue) + Number(modAmtValue);
    				sheet2.SetCellValue(i, "MOD_FUND_AMT", Number(modAmtValue).toFixed(digit));
    				var modSurtaxValue = sheet2.GetCellValue(i - 1, "MOD_SURTAX_AMT");
    				totalModSurtaxAmtValue = Number(totalModSurtaxAmtValue) + Number(modSurtaxValue);
    				sheet2.SetCellValue(i, "MOD_SURTAX_AMT", Number(modSurtaxValue).toFixed(digit));
    				var modValue = sheet2.GetCellValue(i - 1, "MOD_AMT");
    				totalModValue = Number(totalModValue) + Number(modValue);
    				sheet2.SetCellValue(i, "MOD_AMT", Number(modValue).toFixed(digit));    				
    				if( sheet2.GetCellValue(i, "MOD_FUND_AMT") == "0" ) { sheet2.SetCellValue(i, "FUND_RATE", "100"); }
    				
    				//var test = sheet1.GetCellValue(i - 1, "DEPT_NAME");
    				//sheet1.SetCellValue(i, "DEPT_NAME", test);
    				
    				//endrow = i - startrow;    			
    				
    				if(digit == 0){
	    				var info = {Type: "Int" , Format:"Integer"};
	    				sheet2.InitCellProperty(i , "FUND_AMT", info);
	    				sheet2.InitCellProperty(i , "PAY_DEDUCT_AMT", info);
	    				sheet2.InitCellProperty(i , "REQU_SUPPLY_AMT", info);
	    				sheet2.InitCellProperty(i , "REQU_SURTAX_AMT", info);
	    				sheet2.InitCellProperty(i , "REQU_AMT", info);
	    				sheet2.InitCellProperty(i , "MOD_FUND_AMT", info);
	    				sheet2.InitCellProperty(i , "MOD_SURTAX_AMT", info);
	    				sheet2.InitCellProperty(i , "MOD_AMT", info);
    				}else{
    					var info = {Type: "Float" , PointCount:digit};
	    				sheet2.InitCellProperty(i , "FUND_AMT", info);
	    				sheet2.InitCellProperty(i , "PAY_DEDUCT_AMT", info);
	    				sheet2.InitCellProperty(i , "REQU_SUPPLY_AMT", info);
	    				sheet2.InitCellProperty(i , "REQU_SURTAX_AMT", info);
	    				sheet2.InitCellProperty(i , "REQU_AMT", info);
	    				sheet2.InitCellProperty(i , "MOD_FUND_AMT", info);
	    				sheet2.InitCellProperty(i , "MOD_SURTAX_AMT", info);
	    				sheet2.InitCellProperty(i , "MOD_AMT", info);
    				}    				    			
	    		}
	   			str = sheet2.GetCellText(i,1);
	    		if(str.indexOf("소계:") > -1){
	    			sheet2.SetCellAlign(i,1,"Center");
	    			
	    			sheet2.SetCellText(i,1, "소계");
	    			
	    			//sheet1.SetRangeBackColor(i,1,i,12,"#e0ffff");

	    			//alert(startrow);
	    			//alert(endrow);
	    			
	    			sheet2.SetMergeCell(startrow, 1, endrow, 1);

   					sheet2.SetMergeCell(i,1,1,17);
   					
    				var fundAmtValue = sheet2.GetCellValue(i, "FUND_AMT");	
    				totalRatAmtValue = Number(fundAmtValue) / Number(totalConAmtValue) * 100;	

    				//sheet2.SetCellValue(i, "CON_AMT", totalConAmtValue);
    				sheet2.SetCellValue(i, "MOD_FUND_AMT", totalModAmtValue);
    				sheet2.SetCellValue(i, "FUND_RATE", totalRatAmtValue.toFixed(2));
    				
    				var info = {Type: "Int" , Format:"Integer"};
    				//sheet2.InitCellProperty(i , "CON_AMT", info);
    				sheet2.InitCellProperty(i , "MOD_FUND_AMT", info);
    				
    				
   		    		totalConAmtValue = 0;	
    		    	totalModAmtValue = 0;
    		    	totalRatAmtValue = 0.00;
    		    	
    		    	startrow = i + 1;
    		    	endrow = 0;
	    		
	    		}
	    		
	    		if(sheet2.GetCellValue(i , "CURRENCY_DIGIT") != ""){
		    		if(sheet2.GetCellValue(i , "CURRENCY_DIGIT") > 0){
		    			var digit = sheet2.GetCellValue(i, "CURRENCY_DIGIT");
	    				var info = {Type: "Float" , PointCount:digit};
	    				sheet2.InitCellProperty(i , "CON_SUPPLY_AMT", info);
	    				sheet2.InitCellProperty(i , "CON_SURTAX_AMT", info);
	    				sheet2.InitCellProperty(i , "CON_AMT", info);
	    				sheet2.InitCellProperty(i , "PREPAY_SUPPLY_AMT", info);
	    				sheet2.InitCellProperty(i , "PREPAY_SURTAX_AMT", info);
	    				sheet2.InitCellProperty(i , "REQ_PREPAY_SUPPLY_AMT", info);
	    				sheet2.InitCellProperty(i , "REQ_PREPAY_SURTAX_AMT", info);
	    				sheet2.InitCellProperty(i , "PREPAY_DATE", info);
	    				sheet2.InitCellProperty(i , "FUND_AMT", info);
	    				sheet2.InitCellProperty(i , "PAY_DEDUCT_AMT", info);
	    				sheet2.InitCellProperty(i , "REQU_SUPPLY_AMT", info);
	    				sheet2.InitCellProperty(i , "REQU_SURTAX_AMT", info);
	    				sheet2.InitCellProperty(i , "REQU_AMT", info);
	    				sheet2.InitCellProperty(i , "MOD_FUND_AMT", info);
	    				sheet2.InitCellProperty(i , "MOD_SURTAX_AMT", info);
	    				sheet2.InitCellProperty(i , "MOD_AMT", info);
	    			}else{
	    				var info = {Type: "Int" , PointCount:digit};
	    				sheet2.InitCellProperty(i , "CON_SUPPLY_AMT", info);
	    				sheet2.InitCellProperty(i , "CON_SURTAX_AMT", info);
	    				sheet2.InitCellProperty(i , "CON_AMT", info);
	    				sheet2.InitCellProperty(i , "PREPAY_SUPPLY_AMT", info);
	    				sheet2.InitCellProperty(i , "PREPAY_SURTAX_AMT", info);
	    				sheet2.InitCellProperty(i , "REQ_PREPAY_SUPPLY_AMT", info);
	    				sheet2.InitCellProperty(i , "REQ_PREPAY_SURTAX_AMT", info);
	    				sheet2.InitCellProperty(i , "PREPAY_DATE", info);
	    				sheet2.InitCellProperty(i , "FUND_AMT", info);
	    				sheet2.InitCellProperty(i , "PAY_DEDUCT_AMT", info);
	    				sheet2.InitCellProperty(i , "REQU_SUPPLY_AMT", info);
	    				sheet2.InitCellProperty(i , "REQU_SURTAX_AMT", info);
	    				sheet2.InitCellProperty(i , "REQU_AMT", info);
	    				sheet2.InitCellProperty(i , "MOD_FUND_AMT", info);
	    				sheet2.InitCellProperty(i , "MOD_SURTAX_AMT", info);
	    				sheet2.InitCellProperty(i , "MOD_AMT", info);
	    			}
	    		}
	    		
	    		
		    	/* var info = {Type: "Int", Align: "Right", Format:"Integer"};
		    	sheet2.InitCellProperty(i, "CON_AMT", info);
		    	info = {Type: "Int", Align: "Right", Format:"Integer"};
		    	sheet2.InitCellProperty(i, "MOD_FUND_AMT", info);
		    	 */
		    	
		    	
	    	
	    	} 
	    	
	    	setGrid2Size();
		} else {
			//조회 에러 수행
			alert(message);
		}
	}
	
	function sheet2_OnSmartResize(Width, Height) { 
		sheet2.FitColWidth();
		auto2Resize();
	}
	
	function auto2Resize(){
		var t1_height = document.getElementById("search-table").scrollHeight  + document.getElementById("bugase").scrollHeight + document.getElementById("title").scrollHeight + 24;
		var iframeHeight= document.body.scrollHeight - t1_height;   
		var iframeWidth= document.body.scrollWidth;   
		
		
		sheet2.SetSheetHeight(iframeHeight); 
	}	
</SCRIPT>


<modular:search id="form1">
	<modular:key id="fevent" />
</modular:search>

<BODY onresize="autoResize()" >
<form id="form1" name="form1" method="post" modular:type="search">

	<INPUT type="hidden" name="fevent" id="fevent" value="">
	<INPUT type="hidden" name="formdata1" id="formdata1" value="formdata1Test">
	
	<div align="left" id="title">
    	<ul>
     		<li>외주_기성완료현황</li>
    	</ul>
  	</div> 

	<!-- 검색조건 영역 : 시작 -->
	<table id="search-table" class="search-form-table">
		<colgroup>
			<col width="100px">
			<col width="*">
			<col width="100px">
			<col width="*">
			<col width="100px">
			<col width="*">
			<col width="100px">
		</colgroup>
		<TR>
			<Th>현장</Th>
			<TD>
				<%=InputText.getSiteCodeNew("searchDeptCd", "searchDeptNm", "", user, "", "")%>
<%-- 			  	<%= InputText.get("searchDeptCd", "", 12, 10, "ID,ReadOnly,PerSize") %>
				<%= InputText.get("searchDeptNm", "", 17, 30, "ID,PerSize,ReadOnly") %>
				<IMG onclick="searchSite();" src="/img/buyer/button/bt_search_right.gif" alt="현장찾기" border="0" align="absmiddle" style="cursor:hand;"> --%>
			</TD>
			<TH>업체명</TH>
			<TD colspan="3">
				<INPUT type="text" id="searchCorp" name="searchCorp" value="" maxlength="50" class="input" style="IME-MODE : active; width:90%;"  desc='업체명' onKeyPress="doKeyPress();">
			</TD>
			<TD class="button" rowspan="2">
				<!-- 검색버튼 영역 : 시작 -->
			    <span class="btnSearch center"><a href="javascript:void(0);" id="btnSearch">검색</a></span>
			    <!-- 검색버튼 영역 : 종료 -->   
			</TD>
		</TR>
		<TR>
			<Th>계약명</Th>
			<TD>
				<INPUT type="text" id="searchBuldNm" name="searchBuldNm" value="" maxlength="50" class="input" style="IME-MODE : active; width:90%;"  desc='계약명' onKeyPress="doKeyPress();">
			</TD>
  			<Th>기성년월</Th>
   			<TD>
   				<%= InputText.get("searchFromDate", "", 10, 50, "hangule,center, desc=기성년월, ReadOnly") %>
				<IMG name="start_img" id="calender_from" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" style="cursor:pointer;" onClick="JavaScript:dlgMCalendar('searchFromDate');">
				~
				<%= InputText.get("searchToDate", "", 10, 50, "hangule,center, desc=기성년월, ReadOnly") %>
				<IMG name="start_img" id="calender_to" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" style="cursor:pointer;" onClick="JavaScript:dlgMCalendar('searchToDate');">
   				
<!--    				<input type="text" id="searchFromDate" name="searchFromDate" value="" readonly style="width:15%; text-align: center;" maxlength="7">
				<A href="JavaScript:calendar('searchFromDate');"><IMG src="/img/buyer/button/bt_calender.gif" alt="달력" border="0" align="absmiddle"></A>
				&nbsp;~&nbsp;&nbsp;
				<input type="text" id="searchToDate" name="searchToDate" value="" readonly style="width:15%; text-align: center;" maxlength="7">
				<A href="JavaScript:calendar('searchToDate');"><IMG src="/img/buyer/button/bt_calender.gif" alt="달력" border="0" align="absmiddle"></A>    --> 				
			</TD>
		    <Th>부가세</Th>
		    <TD>
			     <select name="surtaxGb" id="surtaxGb" style="width: 70px;" onChange="chgSurtaxGb(this.value);">
					<option value="1">별도</option>
					<option value="2">포함</option>
				</select>		    	 
		    </TD>			
  		</TR>
	</TABLE>	
	<img src="/img/com/blank.gif" height="5px" />
   <div align="right" id="bugase">
    	<ul>
     		<li valign="bottom"><span style="color: red;">* 부가세<span id="spnSurtaxGb">별도</span></span></li>
    	</ul>
  	</div>
	<div id="sheet1_div" style="padding-top:5px; height: auto; min-height: 350px; overflow: auto;">
		<script>createIBSheet('sheet1','100%', '350px');</script>
	</div>
	<div id="sheet2_div" style="padding-top:5px; height: auto; min-height: 350px; overflow: auto; display:none;">
		<script>createIBSheet('sheet2','100%', '350px');</script>
	</div>	
</FORM>
</body>