  <%--
  - FileName   : SSRList.jsp
  - Author     : gyeongmo an
  - Date       : 2014.08.12
  - Copyright  : Copyright (c) 2014 www.udapsoft.co.kr, Inc.
  - All rights reserved.
  - Description: Shiping Status Report
--%>
<%@ 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.*" %>
<%@ 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 fevent   		   = storage.getEvent();	
	
	//공통코드
	CommCodeManager commCodeManager = new CommCodeManager();
	InitCombo initCombo = new InitCombo();

	initCombo.makeComboData(commCodeManager.getCodeRowSet("911"), "CODE", "NAME");
	String statusSheetComboListText = initCombo.getCode();
	String statusSheetComboListValue = initCombo.getCodeName();
	
	
	//해외/구분
	
	//기한
	
	//완료유무
	
%>
<SCRIPT language="JavaScript">
/*예약함수*/
var sheet1;
var sheet1Row;
var sheet1PageNo = 1;
var pageLastRowIndex = 1;
var validationResult = false;
var filterShow = false;

function _onReady(){
	gridInit(sheet1);

	jQuery("#btnSearch").click(function() {
		jQuery("#fevent").val("GET_SSR_LIST");
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/process/process/SSRList_sheet.screen";
		Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 10, "");
	});
	
	jQuery("#btnAdd").click(function() {
		var f= document.form1;
		if(f.dept_cd.value == "") {
			//f.dept_cd.value = "1604";
			alert("현장을 선택해 주세요.");
			return;
		}
		$("#dept_cd2").val(f.dept_cd.value);
		$("#dept_nm2").val(f.dept_nm.value);
		jQuery("#fevent").val("REG_SSR_DETAIL");
		jQuery("#form1").attr("action", "/process/process/SSRDetail.screen");
		jQuery("#form1").attr("target", "_self");
		jQuery("#form1").attr("method", "post");
		jQuery("#form1").submit();	
	});
	
	jQuery("#btnSave").click(function() {
		if(confirm("삭제하시겠습니까?")) {
			jQuery("#fevent").val("SAVE_SSR_LIST");
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/process/process/SSRList_sheet.screen";
			var result = Modular.view.IBSheet7.doSave(sheet1, url, jQuery("#form1"), false);	
		}
	});
	
	jQuery("#btnExcel").click(function() {
		if(sheet1.RowCount() == 0) {
			alert("내역이 없습니다.");
			return;
		}
		var params = { FileName : "SSRList.xls",  SheetName : "SSRList", SheetDesign:0, Merge:1, DownCols:"dept_nm|srn_no|invoice_no|bl_no|po_number|"+
				"description|vendor_info|payment|invoice_value|condition|origin|fob_date|item_description|value|currency|pkg|kgs|cbm|shipping_mode|"+
				"twenty_dc|twenty_dt|twenty_fr|fourty_dc|fourty_dt|fourty_fr|pol|pod|atd_pol|etd_pol|atd_pod|etd_pod|cc|ata_site|vessel_name|"+
				"confirm_date|confirm_emp_no|remarks", TitleText:"Shipping Status Report", UserMerge:"0,0,1,37", AutoSizeColumn:1  } ;
		sheet1.Down2Excel(params);
	});
	
	$("#dataClear2").click(function(){$("#sYmdSt").val("");$("#sYmdEd").val("");});

	sheet1.SetActionMenu("ExcelDown");
	
	jQuery("#btnSearch").click();
	
	autoResize();
}

function gridInit(sheetName){
	var init_sheet = {};
	init_sheet.Cfg = {SearchMode:2, Page:10, MergeSheet:msPrevColumnMerge + msHeaderOnly, PrevColumnMergeMode:0};
	init_sheet.Cols = [
	       			{Header:'상태|상태',								Type:"Status",			SaveName:"status", 				Width:50, 	Align:"Center", Hidden:"True"},
	       			{Header:'삭제|삭제',								Type:"DelCheck",		SaveName:"del_check", 			Width:50, 	Align:"Center", Hidden:"True"},
	    			{Header:'현장코드|현장코드',							Type:"Text", 			SaveName:"dept_cd", 			Width:0, 	Align:"Center", Edit:"false", Hidden:"True"},
	    			{Header:'Project|Project',						Type:"Text", 			SaveName:"dept_nm", 			Width:250, 	Align:"Left", Edit:"false"},
	    			{Header:'Numbering|☞SRN No',					Type:"Text", 			SaveName:"srn_no", 				Width:100, 	Align:"Center", Edit:"false", Cursor:"Pointer"},
	    			{Header:'Numbering|Invoice No',					Type:"Text", 			SaveName:"invoice_no",			Width:150, 	Align:"Left", Edit:"false"},
	    			{Header:'Numbering|B/L No',						Type:"Text", 			SaveName:"bl_no", 				Width:150,	Align:"Left", Edit:"false"},
	    			{Header:'Numbering|PO Number',					Type:"Text", 			SaveName:"po_number", 			Width:150,	Align:"Left", Edit:"false"},
	    			{Header:'PO|Description',						Type:"Text", 			SaveName:"description", 		Width:200, 	Align:"Left", Edit:"false"},
	    			{Header:'PO|Vendor',							Type:"Text", 			SaveName:"vendor_info", 		Width:100, 	Align:"Left", Edit:"false"},
	    			{Header:'PO|Payment',							Type:"Text",	 		SaveName:"payment", 			Width:60, 	Align:"Center", Edit:"false"},
	    			{Header:'PO|Invoice Value',						Type:"Text", 			SaveName:"invoice_value", 		Width:100, 	Align:"Right", Edit:"false"},
	    			{Header:'Delivery|Condition',					Type:"Text", 			SaveName:"condition", 			Width:110, 	Align:"Center", Edit:"false"},
	    			{Header:'Delivery|Origin',						Type:"Text", 			SaveName:"origin", 				Width:100, 	Align:"Left", Edit:"false"},
	    			{Header:'Delivery|Ship Date',					Type:"Date", 			SaveName:"fob_date", 			Width:90, 	Align:"Center", Edit:"false"},
	    			{Header:'Cargo Detail|Item description',		Type:"Text", 			SaveName:"item_description", 	Width:200, 	Align:"Left", Edit:"false"},
	    			{Header:'Cargo Detail|Value',					Type:"Text", 			SaveName:"value", 				Width:90, 	Align:"Right", Edit:"false"},
	    			{Header:'Cargo Detail|Currency',				Type:"Combo", 			SaveName:"currency", 			Width:90, 	Align:"Center", Edit:"false", ComboText:"<%=statusSheetComboListText%>", ComboCode:"<%=statusSheetComboListValue%>"},
	    			{Header:'Cargo Detail|PKG',						Type:"Float", 			SaveName:"pkg", 				Width:70, 	Align:"Right", Edit:"false", PointCount:2},
	    			{Header:'Cargo Detail|KGS',						Type:"Text", 			SaveName:"kgs", 				Width:70, 	Align:"Right", Edit:"false"},
	    			{Header:'Cargo Detail|CBM',						Type:"Text", 			SaveName:"cbm", 				Width:100, 	Align:"Right", Edit:"false"},
	    			{Header:'Cargo Detail|Shipping Mode',			Type:"Text", 			SaveName:"shipping_mode", 		Width:130, 	Align:"Center", Edit:"false"},
	    			{Header:'Container Type|20\'DC',				Type:"Int", 			SaveName:"twenty_dc", 			Width:40, 	Align:"Right", Edit:"false"},
	    			{Header:'Container Type|20\'OT',				Type:"Int", 			SaveName:"twenty_dt", 			Width:40, 	Align:"Right", Edit:"false"},
	    			{Header:'Container Type|20\'FR',				Type:"Int", 			SaveName:"twenty_fr", 			Width:40, 	Align:"Right", Edit:"false"},
	    			{Header:'Container Type|40\'DC',				Type:"Int", 			SaveName:"fourty_dc", 			Width:40, 	Align:"Right", Edit:"false"},
	    			{Header:'Container Type|40\'OT',				Type:"Int", 			SaveName:"fourty_dt", 			Width:40, 	Align:"Right", Edit:"false"},
	    			{Header:'Container Type|40\'FR',				Type:"Int", 			SaveName:"fourty_fr", 			Width:40, 	Align:"Right", Edit:"false"},
	    			{Header:'Container Type|45\'FT',				Type:"Int", 			SaveName:"fourty_fft", 			Width:40, 	Align:"Right", Edit:"false"},
	    			{Header:'Shipping Schedule|Port of Loading',	Type:"Text", 			SaveName:"pol", 				Width:100, 	Align:"Left", Edit:"false"},
	    			{Header:'Shipping Schedule|Port of Discharge',	Type:"Text", 			SaveName:"pod", 				Width:100, 	Align:"Left", Edit:"false"},
	    			{Header:'Shipping Schedule|ATD POL',			Type:"Date", 			SaveName:"atd_pol", 			Width:90, 	Align:"Center", Edit:"false"},
	    			{Header:'Shipping Schedule|ETD POL',			Type:"Date", 			SaveName:"etd_pol", 			Width:90, 	Align:"Center", Edit:"false"},
	    			{Header:'Shipping Schedule|ATD POD',			Type:"Date", 			SaveName:"atd_pod", 			Width:90, 	Align:"Center", Edit:"false"},
	    			{Header:'Shipping Schedule|STA POD',			Type:"Date", 			SaveName:"etd_pod", 			Width:90, 	Align:"Center", Edit:"false"},
	    			{Header:'Shipping Schedule|Customs Clearance',	Type:"Date", 			SaveName:"cc", 					Width:90, 	Align:"Center", Edit:"false"},
	    			{Header:'Shipping Schedule|on Site',			Type:"Date", 			SaveName:"ata_site", 			Width:90, 	Align:"Center", Edit:"false"},
	    			{Header:'Vessel Name|Vessel Name',				Type:"Text", 			SaveName:"vessel_name", 		Width:150, 	Align:"Left", Edit:"false"},
	    			{Header:'Confirm Date|Confirm Date',			Type:"Date", 			SaveName:"confirm_date", 		Width:90, 	Align:"Center", Edit:"false"},
	    			{Header:'Confirm User|Confirm User',			Type:"Text", 			SaveName:"confirm_emp_no", 		Width:90, 	Align:"Center", Edit:"false"},
	    			{Header:'Remarks|Remarks',						Type:"Text", 			SaveName:"remarks", 			Width:400, 	Align:"Left", Edit:"false"},
	    			{Header:'shipping_id|shipping_id',				Type:"Text", 			SaveName:"shipping_id", 		Width:200, 	Align:"Left", Edit:"false", Hidden:"True"},
	    			{Header:'pur_cont_id|pur_cont_id',				Type:"Text", 			SaveName:"pur_cont_id", 		Width:200, 	Align:"Left", Edit:"false", Hidden:"True"},
	    			{Header:'confirm_yn|confirm_yn',				Type:"Text", 			SaveName:"confirm_yn", 			Width:200, 	Align:"Left", Edit:"false", Hidden:"True"}
	    		];

	init_sheet.HeaderMode = {Sort:1};
	IBS_InitSheet(sheetName, init_sheet);
	sheetName.SetDataAutoTrim(0);
	
	setGridSize();
}

function sheet1_OnSearchEnd(code, message) {
    if(code == 0) {
    	setGridSize();
    	sheet1.SetColFontColor("srn_no", "#0000ff");
	} else {
		alert(message);
	}
}

function sheet1_OnSaveEnd(code, msg) {
    if(code >= 0) {
    	alert("삭제했습니다.");
    } else {
    	alert(msg);
    }
    	jQuery("#btnSearch").click();
}

function sheet1_OnSelectMenu(Text, Code) {
	switch(Text) {
		case "ExcelDown":
			jQuery("#btnExcel").click();
		break;
	}
}

function setGridSize() {
	//sheet1.FitColWidth();
}
	
function sheet1_OnSmartResize(Width, Height) { 
	//sheet1.FitColWidth();
	autoResize();
}

function autoResize(){
	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 clearDiscipline() {
	var f= document.form1;
	f.p_discipline.value = "";
}

function sheet1_OnDblClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
	if (sheet1.ColSaveName(0, Col) == "srn_no") {
		var f = document.form1;
		f.dept_cd2.value = sheet1.GetCellValue(Row, "dept_cd");
		f.dept_nm2.value = sheet1.GetCellValue(Row, "dept_nm");
		f.shipping_id.value = sheet1.GetCellValue(Row, "shipping_id");
		f.pur_cont_id.value = sheet1.GetCellValue(Row, "pur_cont_id");
		f.fevent.value ="GET_SSR_DETAIL";
	    f.action = "/process/process/SSRDetail.screen";
	    f.target = "_self";
	    f.method = "post";  
	    f.submit();
	}
}

function sheet1_OnClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
	var f = document.form1;
	
	if (sheet1.ColSaveName(0, Col) == "del_check") {
		if(sheet1.GetCellValue(Row, "confirm_yn") == "9") {
			alert("확정된 데이터는 삭제할 수 없습니다.");
			sheet1.SetCellValue(Row, "del_check", "0");
			return;
		}
	}
}

$(document).on("keyup", "input:text", function(e) {
    if (e.keyCode == 13)
    {
    	jQuery("#btnSearch").click();
    }
});





document.body.onresize = addEvent( document.body.onresize, "autoResize()");
</SCRIPT>

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

<form id="form1" name="form1" method="post" modular:type="search" style="width:100%;height:100%;">
<INPUT type="hidden" name="fevent" id="fevent" value="">
<INPUT type="hidden" name="shipping_id">
<INPUT type="hidden" name="pur_cont_id">
<INPUT type="hidden" name="dept_cd2">
<INPUT type="hidden" name="dept_nm2">

<div align="left" id="title">
    <ul>
     <li>Shipping Status Report</li>
    </ul>
  </div> 
	<!-- 검색조건 시작 -->
	<table id="search-table" class="search-form-table">
		<colgroup>
			<col width="80" />
			<col width="400" />
			<col width="120" />
			<col width="*" />
			<col width="250" />
		</colgroup>
		<tr>
			<th>Project</th>
			<td>
		   		<%=InputText.getSiteCodeNew("dept_cd", "dept_nm", "", user, params.get("dept_cd"), params.get("dept_nm"))%>
			</td>
			<th>Shipping Date</th>
			<td>
				<%= InputText.get("sYmdSt", params.get("sYmdSt"), 10, 50, "hangule,center, desc=기간,ReadOnly") %>
				<IMG name="sYmdSt_img" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" style="cursor:pointer;" onClick="JavaScript:dlgMCalendar('sYmdSt');">
							~
				<%= InputText.get("sYmdEd", params.get("sYmdEd"), 10, 50, "hangule,center, desc=기간,ReadOnly") %>
				<IMG name="sYmdEd_img" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" style="cursor:pointer;" onClick="JavaScript:dlgMCalendar('sYmdEd');">
				<IMG name="dataClear2" id="dataClear2" src="/img/buyer/button/bt_eraser1.gif" border="0" align="absmiddle" style="cursor:pointer;">
			</td>
			<td class="button" rowspan="3">
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnSearch">Search</a></span>
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnAdd">Add</a></span>
				<!-- <span class="btnSearch center"><a href="javascript:void(0);" id="btnSave">Save</a></span> -->
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnExcel">Excel</a></span>
			</td>
		</tr>
		<tr>
			<th>SRN No</th>
			<td>
				<%= InputText.get("p_srn_no", params.get("p_srn_no"), 77, 50, "hangule, desc=SRN No, PerSize") %>
			</td>
			<th>Vendor</th>
			<td>
				<%= InputText.get("corp_name", params.get("corp_name"), 60, 50, "hangule, desc=corp name, PerSize") %>
			</td>
		</tr>
		<tr>
			<th>Status</th>
			<td colspan="3">
				<SELECT name="p_status">
					<OPTION value="">전체</OPTION>
	                <OPTION value="1">작성</OPTION>
	                <OPTION value="5">업체요청</OPTION>
	                <OPTION value="9">완료</OPTION>
	            </SELECT>
			</td>
		</tr>
	</table>
	<!-- 검색조건 종료 -->
	<div id="sheet1_div" style="padding-top:5px; height: auto; min-height: 400px; overflow: auto;">
		<script>createIBSheet('sheet1','100%', '400px');</script>
	</div>
	
</FORM>
