<%--
  - FileName   : ComparePayplanActual.jsp
  - Author(s)  : ok
  - Date       : 2019.08.08
  - 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.*" %>
<%@ page import="com.udapsoft.waf.common.util.DateUtil" %>
<%@ 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();
 
	//상태 sheetComboList Data
	String statusSheetComboListText 	   = (String)storage.getObject("selectText");
	String statusSheetComboListValue 	   = (String)storage.getObject("selectValue");
 
	 
	//검색조건 현장 설정
	String initSearchDeptCd = params.get("searchDeptCd");
	String initSearchDeptNm = params.get("searchDeptNm");
	//검색조건 계약명 설정
	String initSearchBuildName = params.get("searchBuildName");
	//검색조건 작성일
	String  initSearchDateStart = params.get("searchDateStart");
	String  initSearchDateEnd = params.get("searchDateEnd");
	
    //com.udapsoft.waf.common.util.DateUtil
	ValueObject defaultDate = DateUtil.getDefaultPeriod();
	if("".equals(initSearchDateStart)){
		initSearchDateStart = defaultDate.get("START_DATE");
	}
	if("".equals(initSearchDateEnd)){
		initSearchDateEnd = defaultDate.get("END_DATE");
	} 	
%>
<SCRIPT language="JavaScript">
	/*예약함수*/
	var sheet1;
	var sheet1Row;
	var sheet1PageNo = 1;
	var pageLastRowIndex = 1;
	var validationResult = false;
	var filterShow = false;
	
	function _onReady(){
		/**
		 *	IBSheet object initialize
		 */
		gridInit(sheet1);
		
		autoResize();
	
		/**
		 *	Application Initialize
		 */
		jQuery("#btnSearch").click(function() {

			jQuery("#fevent").val("GET_DATA");
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/payment/purchase/ComparePayplanActual_sheet.screen";
			Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 30, ""); 
			
		});
		
		$("#chk_all").click(function() {
			if($("#chk_all").is(":checked") == true){
				$("#chk_all").val("Y");
			}else{
				$("#chk_all").val("N");
			}
		});
		
		pageinit();
		
	}
	
	function pageinit(){
		
		//달력 조건에 당해년도1월, 당해년도당월 셋팅
		setSearchDate();
		
		//jQuery("#btnSearch").click();
	      
	}
	
	/**
	 *	IBSheet object initialize
	 */
	function gridInit(sheetName){
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, Page:100, MergeSheet:7};
		init_sheet.Cols = [
			    			{Header:'상태',				Type:"Status", 		SaveName:"STATUS", 				Width:0, 	Align:"Center", Hidden:"True"},
			    			{Header:'현장|코드',			Type:"Text", 		SaveName:"DEPT_CD",				Width:200, 	Align:"Left",   Hidden:"True"},
			    			{Header:'현장명|현장명',		Type:"Text", 		SaveName:"DEPT_NAME",			Width:200, 	Align:"Left"},
			    			{Header:'계약번호|계약번호',	Type:"Text", 		SaveName:"ORD_DOC_NO",			Width:200, 	Align:"Left"},
			    			{Header:'최종차수|최종차수',	Type:"Text", 		SaveName:"MOD_NO",			    Width:60, 	Align:"Center"},
			    			{Header:'계약명|계약명',		Type:"Text", 		SaveName:"CST_DOC_NAME",		Width:200, 	Align:"Left"},
			    			{Header:'대금|구분',		    Type:"Text", 		SaveName:"GB",				    Width:60, 	Align:"Left"},
			    			{Header:'대금|일자',		    Type:"Text", 	    SaveName:"A_REQ_DATE",			Width:80, 	Align:"Center"},
			    			{Header:'대금|금액',		    Type:"Float", 		SaveName:"A_AMT",				Width:80, 	Align:"Right", Format:"Integer"},
			    			{Header:'대금|횟수',			Type:"Text", 		SaveName:"A_CNT",				Width:40, 	Align:"Center"},
			    			{Header:'계획|금액',		    Type:"Float", 		SaveName:"P_AMT",				Width:80, 	Align:"Right", Format:"Integer"},
			    			{Header:'계획|지급여부',		Type:"Text", 		SaveName:"P_PAY_YN",			Width:40, 	Align:"Center"},
			    			{Header:'계획|횟수',		    Type:"Text", 		SaveName:"P_CNT",				Width:40, 	Align:"Center"},
			    			{Header:'차액|차액',			Type:"Float",		SaveName:"DIFF",		        Width:80, 	Align:"Right", Format:"Integer"},
			    			{Header:'대금|계약번호',		Type:"AutoSum",		SaveName:"PUR_CONT_MOD_ID",		Width:100, 	Align:"Center" ,Hidden:"True"},
			    			{Header:'대금|계약번호',		Type:"Text", 		SaveName:"PUR_CONT_ID",         Width:100, 	Align:"Center" ,Hidden:"True"},
			    			{Header:'대금|지급번호',		Type:"Float", 		SaveName:"PAYREQ_ID",		    Width:50, 	Align:"Center",Hidden:"True"}
        ];

		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		sheetName.SetEditable(false);
		
		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,2);
	    	
	    	var lr = sheet1.LastRow();
	    	var str = "";
	    	var startrow = 2;
	    	var endrow = 1;
	    	var backColor = "";
	    	
	    	var totalConAmtValue = 0;
	    	var totalModAmtValue = 0;
	    	var totalRatAmtValue = 0.00;
	    	
	    	for(var i=1; i <= lr; i++){

 	   			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, 1);
   					sheet1.SetMergeCell(i,1,1,5);
   					sheet1.SetMergeCell(i,7,1,2);
   					
    				var remainderAcmpSupplyamt = sheet1.GetCellValue(i-1, "REMAINDER_ACMP_SUPPLYAMT");	//잔여
	    			var curAcmpPercent = sheet1.GetCellValue(i-1, "CUR_ACMP_PERCENT");	//지급율
	    		
    				sheet1.SetCellValue(i, "REMAINDER_ACMP_SUPPLYAMT", remainderAcmpSupplyamt);
    				sheet1.SetCellValue(i, "CUR_ACMP_PERCENT", curAcmpPercent.toFixed(2));
    				
    				totalConAmtValue = 0;	
    		    	totalModAmtValue = 0;
    		    	totalRatAmtValue = 0.00;
    		    	
    		    	startrow = i + 1;
	    		}
	    		
		    	//var info = {Type: "Int", Align: "Right", Format:"Integer"};
		    	var info = {Type: "Float", Align: "Right", Format:"##0.00"};
		    	sheet1.InitCellProperty(i, "CUR_ACMP_PERCENT", info);
		    	var info2 = {Type: "Int", Align: "Right", Format:"Integer"};
		    	sheet1.InitCellProperty(i, "REMAINDER_ACMP_SUPPLYAMT", info2);
		    	
	    	}
	    	 
	    	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 ) {
			doSearch(document.all.sheet1)
	    }
	}	

	function calendar(thisDayObj){
		dlgCalendar(thisDayObj);
		
	}		
	
	//검색조건에 기성년월 초기 설정
	function setSearchDate(){
	    
		//검색조건 시작일 
		var startDate = get_year() +'-'+ get_month()  +'-'+ '01';
	    if(jQuery('#searchDateStart').val() == ""){
	    	jQuery('#searchDateStart').val(startDate);	
	    }
			
		//검색조건 종료일
		var nowYearMonth = new Date( get_year(), get_month(), "");
	    var lastDay = nowYearMonth.getDate();
		var endDate = get_year() +'-'+ get_month()  +'-'+ lastDay;
	    if(jQuery('#searchDateEnd').val() == ""){
	    	jQuery('#searchDateEnd').val(endDate);	
	    }
	    
	}

	function sheet1_OnSmartResize(Width, Height) { 
		sheet1.FitColWidth();
		autoResize();
	}
	
	function autoResize(){
/* 		var t1_height = document.getElementById("t1").scrollHeight + 10;
		var iframeHeight= document.body.scrollHeight - t1_height;   
		var iframeWidth= document.body.scrollWidth;   
		
		sheet1.SetSheetHeight(iframeHeight);  */
		var t1_height = document.getElementById("search-table").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');
	}
	
</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="">   
	
	
	<div align="left" id="title">
    	<ul>
     		<li>대금계획과 지급현황 비교</li>
    	</ul>
  	</div> 

	<!-- 검색조건 영역 : 시작 -->
	<table id="search-table" class="search-form-table">
		<colgroup>
			<col width="100px">
			<col width="40%">
			<col width="100px">
			<col width="*" />
			<col width="100px">
		</colgroup>
		<TR>
			<Th>현장</Th>
			<TD>
				<%--<%=InputText.getSiteCode("searchDeptCd", "searchDeptNm", "", user, initSearchDeptCd, initSearchDeptNm)%> --%>
				<%=InputText.getSiteCodeNew("searchDeptCd", "searchDeptNm", "", user, initSearchDeptCd, initSearchDeptNm)%>				 
			</TD>
			<Th>계약명</Th>
			<TD>
				<INPUT type="text" id="searchBuildName" name="searchBuildName" value="<%=initSearchBuildName%>" maxlength="50" class="input" style="IME-MODE : active;width:95%;"   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>
				<%= InputText.get("searchDateStart", initSearchDateStart, 15, 10, "Center, date, PerSize, readonly", "date", "") %>
				<a href="JavaScript:calendar('searchDateStart');"><img src="/img/buyer/button/bt_calender.gif" alt="달력" border="0" align="absmiddle" /></a>
				&nbsp;~&nbsp;
				<%= InputText.get("searchDateEnd", initSearchDateEnd, 15, 10, "Center, date, PerSize, readonly", "date", "") %>
				<a href="JavaScript:calendar('searchDateEnd');"><img src="/img/buyer/button/bt_calender.gif" alt="달력" border="0" align="absmiddle" /></a>			
			</TD>
			<th>전체조회</th>
			<td>
				<input type="checkbox" id="chk_all" name="chk_all" value="N">
			</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></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>
</FORM>
</body>