<%--
  - FileName   : SSRDetail.jsp
  - Author     : gyeongmo an
  - Date       : 2014.08.12
  - Copyright  : Copyright (c) www.udapsoft.co.kr, Inc.
  - All rights reserved.
--%>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="com.udapsoft.waf.system.HandlerStorage" %>
<%@ page import="kr.co.hsnc.common.sql.*" %>
<%@ page import="kr.co.hsnc.common.util.*"%>
<%@ page import="kr.co.udapsoft.ebid.buyer.common.file.FileManager"%>
<%@ page import="com.udapsoft.waf.common.ui.*" %>
<%@ page import="com.udapsoft.waf.common.util.DateUtil" %>
<%@ page import="kr.co.udapsoft.common.code.CommCodeManager" %>
<%@ page import="java.text.*" %>
<%@ page import="com.udapsoft.waf.common.util.*" %>
<%@ include file="/jsp/work/taglib.jsp" %>
<jsp:useBean id="ctx" class="com.udapsoft.waf.system.context.SessionContext" scope="session" />
<%
DecimalFormat df = new DecimalFormat("###,###");
%>
<%
    ctx.init(request, response);
	String fevent = ctx.get("fevent");
	HandlerStorage storage = ctx.getHandlerStorage();

	ValueObject params = storage.getParams();
	ValueObject user = storage.getValueObject("User");
	
	ValueObject vo = storage.getValueObject("ssrDetail");
	
	// 첨부파일
	ValueObject vo_file = storage.getValueObject("SSR_DETAIL");

	String isModify = "";
	if(vo.get("shipping_id").equals("")) {
		isModify = "false";
	} else {
		isModify = "true";
	}
	
	String invoice_value = "";
	String pkg = "";
	
	String twenty_dc = "";
	String twenty_dt = "";
	String twenty_fr = "";
	String fourty_dc = "";
	String fourty_dt = "";
	String fourty_fr = "";
	String fourty_fft = "";
	String total = "";
	
	if(!vo.get("invoice_value").equals(""))
	{
	    invoice_value = df.format(Long.parseLong(vo.get("invoice_value")));
	}
	if(!vo.get("pkg").equals(""))
	{
	    pkg = df.format(Integer.parseInt(vo.get("pkg")));
	}
	if(!vo.get("twenty_dc").equals(""))
	{
		twenty_dc = df.format(Integer.parseInt(vo.get("twenty_dc")));
	}
	if(!vo.get("twenty_dt").equals(""))
	{
		twenty_dt = df.format(Integer.parseInt(vo.get("twenty_dt")));
	}
	if(!vo.get("twenty_fr").equals(""))
	{
		twenty_fr = df.format(Integer.parseInt(vo.get("twenty_fr")));
	}
	if(!vo.get("fourty_dc").equals(""))
	{
		fourty_dc = df.format(Integer.parseInt(vo.get("fourty_dc")));
	}
	if(!vo.get("fourty_dt").equals(""))
	{
		fourty_dt = df.format(Integer.parseInt(vo.get("fourty_dt")));
	}
	if(!vo.get("fourty_fr").equals(""))
	{
		fourty_fr = df.format(Integer.parseInt(vo.get("fourty_fr")));
	}
	if(!vo.get("fourty_fft").equals(""))
	{
		fourty_fft = df.format(Integer.parseInt(vo.get("fourty_fft")));
	}
	if(!vo.get("total").equals(""))
	{
		total = df.format(Integer.parseInt(vo.get("total")));
	}
	
	String today = DateUtil.formatDateTime(DateUtil.getToday(), "yyyyMMdd", "yyyyMMdd");
%>

<SCRIPT language="JavaScript">
/*예약함수*/
var sheet1;
var sheet1Row;
var sheet1PageNo = 1;
var pageLastRowIndex = 1;
var validationResult = false;
var filterShow = false;

var deptPurGubun = "";

function _onReady(){
	gridInit(sheet1);

	jQuery("#btnList").click(function() {
		jQuery("#fevent").val("GET_LIST");
		jQuery("#form1").attr("action", "/process/process/SSRList.screen");
		jQuery("#form1").attr("target", "_self");
		jQuery("#form1").attr("method", "post");
		jQuery("#form1").submit();	
	});
	
	jQuery("#btnAdd").click(function() {
		var f= document.form1;
	    var win_id = "_shippingTargetSearch";
		var link = "/process/process/ShippingTargetSearch.screen";
		link += "?pop_win_id="+win_id+"&dept_cd="+f.dept_cd2.value+"&dept_nm="+encodeURI(encodeURIComponent(f.dept_nm2.value),"UTF-8");
		fLayerPop(win_id, link, 1200,370, '', '', 'NO');
	});
	
	jQuery("#btnSave").click(function() {
		
		var f = document.form1;
		
		var value   = $(':radio[name=payment]:checked').val();
		
		if( $("#item_description").val() == "" ) {
			alert("Item Description은 필수입력 항목 입니다.");
			$("#item_description").focus();
			return;
		} else {
			if ( stringByteSize4UTF($("#item_description").val()) > 120 ) {
		    	alert("Item Description은 120자까지 입력하실 수 있습니다.");
		    	return;
		    }
		}
		
		if( $("#invoice_no").val() == "" ) {
			alert("Invoice No은 필수입력 항목 입니다.");
			$("#invoice_no").focus();
			return;
		}else {
			if ( stringByteSize4UTF($("#invoice_no").val()) > 30 ) {
		    	alert("invoice_no은 30자까지 입력하실 수 있습니다.");
		    	return;
		    }
		}
		if ( stringByteSize4UTF($("#vessel_name").val()) > 50 ) {
	    	alert("invoice_no은 영문 50자 한글 15자 까지 입력하실 수 있습니다.");
	    	return;
	    }
		/* 
		if( $("#shipDate").val() == "" ) {
			alert("Ship Date는 필수입력 항목 입니다.");
			$("#shipDate").focus();
			return;
		}

		if( $("#shipping_mode").val() == "" ) {
			alert("Shipping Mode는 필수입력 항목 입니다.");
			$("#shipping_mode").focus();
			return;
		}
		
		
		if ( stringByteSize4UTF($("#origin").val()) > 100 ) {
	    	alert("Origin은 100자까지 입력하실 수 있습니다.");
	    	return;
	    }
		 

		if ( stringByteSize4UTF($("#remarks").val()) > 100 ) {
	    	alert("Remarks는 100자까지 입력하실 수 있습니다.");
	    	return;
	    }
		
		if(sheet1.RowCount() == 0) {
			alert("상품내역을 추가해 주세요.");
			return;
		} else {
			for(var i=1; i<sheet1.RowCount()+1; i++) {
				if(sheet1.GetCellValue(i, "ship_qty") == "" || sheet1.GetCellValue(i, "ship_qty") == "0") {
					alert("선적량이 0인 자료가 있습니다.");
					sheet1.SelectCell(i, "ship_qty");
					return;
				}
			}
		} */
		
		if(confirm("저장하시겠습니까?")){
			if(<%=isModify%> == false){
				//저장
				f.oversea_gb.value = sheet1.GetCellValue(1, "oversea_gb");
				/* f.pur_cont_id.value = sheet1.GetCellValue(1, "pur_cont_id"); */
				/* f.corp_id.value = sheet1.GetCellValue(1, "corp_id"); */
				submitXmlRequest("/process/process/SSRDetail_form.screen", "SAVE_SSR_DETAIL", f, "SUCCESS");
		    	/* jQuery("#fevent").val("SAVE_SSR_DETAIL");
				var url = Modular.model.PageContext.CONTEXT_ROOT + "/process/process/SSRDetail_sheet.screen";
				var result = Modular.view.IBSheet7.doSave(sheet1, url, jQuery("#form1"), false); */
			}else{
				//수정
				<%-- f.pur_cont_id.value = '<%=params.get("pur_cont_id")%>'; --%>
				
				
				submitXmlRequest("/process/process/SSRDetail_form.screen", "UPDATE_SSR_DETAIL", f, "SUCCESS");
				
				/* jQuery("#fevent").val("UPDATE_SSR_DETAIL");
				var url = Modular.model.PageContext.CONTEXT_ROOT + "/process/process/SSRDetail_sheet.screen";
				var result = Modular.view.IBSheet7.doSave(sheet1, url, jQuery("#form1"), false); */
			}
		}
	});
	
	//2015.3.17 ATD/ATA저장
	jQuery("#btnSubSave").click(function() {
		if(confirm("ATD/ATA 저장하시겠습니까?")){
			jQuery("#fevent").val("UPDATE_ATDATA_DETAIL");
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/process/process/SSRDetail_sheet.screen";
			var result = Modular.view.IBSheet7.doSave(sheet1, url, jQuery("#form1"), false);
		}
	});
	
	jQuery("#btnDelete").click(function() {
		var f = document.form1;
		f.pur_cont_id.value = '<%=params.get("pur_cont_id")%>';
		if(confirm("전체 삭제하시겠습니까?")){
			submitXmlRequest("/process/process/SSRDetail_form.screen", "DELETE_SSR_DETAIL", f, "SUCCESS");
		}
	});
	
	jQuery("#btn_row_del").click(function() {
		var f = document.form1;
		var temp = "N";
		for(var i=0; i<sheet1.LastRow(); i++) {
			if(sheet1.GetCellValue(i+1, "status") == "I" || sheet1.GetCellValue(i+1, "status") == "U" ||
					sheet1.GetCellValue(i+1, "status") == "R") {
				temp = "Y";
			}
		}
		
		
		
		if(confirm("삭제하시겠습니까?")){
			jQuery("#fevent").val("DELETE_SSR_DETAIL_SHEET");
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/process/process/SSRDetail_sheet.screen";
			var result = Modular.view.IBSheet7.doSave(sheet1, url, jQuery("#form1"), false);
		}
	});
	
	jQuery("#btnConfirm").click(function() {
		var f = document.form1;
		f.material_gb.value = sheet1.GetCellValue(1, "material_gb");
		
		if(<%=isModify%> == false){
			alert("저장을 먼저 해주세요.");
			return;
		}
		
		
		if( f.polEtd.value == "" ) {
			alert("POL ETD를 선택해 주세요.");
			$("#polEtd").focus();
			return;
		}
		if( f.polAtd.value == "" ) {
			alert("POL ATD를 선택해 주세요.");
			$("#polAtd").focus();
			return;
		}
		if(f.polAtd.value.replace(/-/gi, "") > '<%=today%>') {
			alert("POL ATD가 오늘보다 나중 날짜 입니다.");
			return;
		}
		if( f.podEtd.value == "" ) {
			alert("POD STA를 선택해 주세요.");
			$("#podEtd").focus();
			return;
		}
		if( f.pol.value == "" ) {
			alert("출발지를 입력해 주세요.");
			$("#pol").focus();
			return;
		}
		if( f.pod.value == "" ) {
			alert("도착지를 입력해 주세요.");
			$("#pod").focus();
			return;
		}
		
		if(sheet1.RowCount() == 0) {
			alert("상품내역을 추가해 주세요.");
			return;
		} 
		
		for(var i=sheet1.LastRow(); i>=1; i--) {
			if( Number(sheet1.GetCellValue(i, "ship_qty2")) < Number(sheet1.GetCellValue(i, "ship_qty")) && sheet1.GetCellValue(i, "ship_qty2") != "" )	{
				alert("확정할 수 있는 수량을 초과하였습니다. \n 자재코드 : " + sheet1.GetCellValue(1, "material_cd"));
				sheet1.SelectCell(i, "ship_qty");
				return;
			}
			
			if(sheet1.GetCellValue(i ,"Status") == "R"){
				sheet1.SetCellValue(i,"Status", "U");
			}
		}
	
		if(confirm("확정 하시겠습니까?")) {
			var f = document.form1;
			f.pur_cont_id.value = '<%=params.get("pur_cont_id")%>';
			jQuery("#fevent").val("CONFIRM_SSR_DETAIL");
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/process/process/SSRDetail_sheet.screen";
			var result = Modular.view.IBSheet7.doSave(sheet1, url, jQuery("#form1"), false);	
		}
	});
	
	$("[name=date_img]").click(function(){
		var id = $(this).attr("id").substring(0, $(this).attr("id").lastIndexOf("_"));
		dlgCalendar(id);
	});

	get_ssr_detail_sheet();
	
	autoResize();
}

function gridInit(sheetName){
	var init_sheet = {};
	init_sheet.Cfg = {SearchMode:2, Page:10};
	init_sheet.Cols = [
	       			{Header:'상태',					Type:"Status",		SaveName:"status", 		Width:50, 	Align:"Center", Hidden:"True"},
	       			{Header:'Del',					Type:"DelCheck",		SaveName:"check", 		Width:50, 	Align:"Center"},
	       			{Header:'Material Code',				Type:"Text",			SaveName:"material_cd", 		Width:90, 	Align:"Center", Edit:"false"},
	       			{Header:'☞Material Name',				Type:"Text",			SaveName:"material_name", 		Width:150, 	Align:"Left", Edit:"false", Cursor:"Pointer"},
	       			{Header:'Material Spec',					Type:"Text",			SaveName:"material_spec", 		Width:100, 	Align:"Left", Edit:"false"},
	       			{Header:'Material Unit',					Type:"Text",			SaveName:"item_unit", 		Width:50, 	Align:"Center", Edit:"false"},
	       			{Header:'PO No',				Type:"Text",			SaveName:"ord_doc_no", 		Width:130, 	Align:"Left", Edit:"false"},
	       			{Header:'PO Title',				Type:"Text",			SaveName:"cst_doc_name", 		Width:250, 	Align:"Left", Edit:"false"},
	       			{Header:'Vendor Name',				Type:"Text",			SaveName:"vendor_nm", 		Width:90, 	Align:"Left", Edit:"false"},
	       			{Header:'Payment',				Type:"Text",			SaveName:"payment_nm", 		Width:90, 	Align:"Left", Edit:"false"},
	       			{Header:'Condition',				Type:"Text",			SaveName:"condition_nm", 		Width:90, 	Align:"Left", Edit:"false"},
	       			{Header:'PO Qty',				Type:"Float",			SaveName:"item_qty", 		Width:90, 	Align:"Right", PointCount:2, Edit:"false"},
	       			{Header:'Ship Remain Qty',				Type:"Float",			SaveName:"jan_qty", 		Width:90, 	Align:"Right", PointCount:2, Edit:"false"},
	       			{Header:'PO Price',				Type:"Float",			SaveName:"item_price", 		Width:90, 	Align:"Right", Edit:"false", PointCount:2},
	       			{Header:'PO Amount',				Type:"Float",			SaveName:"item_amt", 		Width:90, 	Align:"Right", Edit:"false", Hidden:"True", PointCount:2},
	       			{Header:'Ship Qty',				Type:"Float",		SaveName:"ship_qty", 		Width:90, 	Align:"Right", PointCount:2},
	       			{Header:'Ship Amt',				Type:"Float",		SaveName:"ship_amt", 		Width:90, 	Align:"Right", PointCount:2, Edit:"false"},
	       			{Header:'shipping_detail_id',				Type:"Text",		SaveName:"shipping_detail_id", 		Width:100, 	Align:"Center", PointCount:2, Hidden:"True"},
	       			{Header:'계약ID',				Type:"Text",		SaveName:"pur_cont_id", 		Width:100, 	Align:"Center", Hidden:"True"},
	       			{Header:'shipping_id',				Type:"Text",		SaveName:"shipping_id", 		Width:100, 	Align:"Center", Hidden:"True"},
	       			{Header:'통화구분',				Type:"Text",		SaveName:"currency_gb", 		Width:100, 	Align:"Center", Hidden:"True"},
	       			{Header:'국내외구분',				Type:"Text",		SaveName:"oversea_gb", 		Width:100, 	Align:"Center", Hidden:"True"},
	       			{Header:'업체코드',				Type:"Text",		SaveName:"corp_id", 		Width:100, 	Align:"Center", Hidden:"True"},
	       			{Header:'기존선적수량',				Type:"Float",		SaveName:"ship_qty2", 		Width:90, 	Align:"Right", PointCount:2, Hidden:"True"},
	       			{Header:'자재구분코드',				Type:"Text",		SaveName:"material_gb", 		Width:90, 	Align:"Right", 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("material_name", "#0000ff");
	} else {
		//조회 에러 수행
		//alert(message);
		alert("조회 실패");
	}
}

function sheet1_OnSaveEnd(code, msg) {
    if(code >= 0) {
    	if(jQuery("#fevent").val() == "CONFIRM_SSR_DETAIL") {
    		alert("확정 성공");
    	} else {
	    	alert("저장 성공");
    	}
    	reloading();
    } else {
    	alert(msg);
    }
}

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

function autoResize(){
	var t1_height = document.getElementById("f_table").scrollHeight + document.getElementById("title").scrollHeight + 24 + 45;
	var iframeHeight= document.body.scrollHeight - t1_height;   
	
	sheet1.SetSheetHeight(iframeHeight); 
}	

function save_ssr_detail_sheet() {
	
	if ( !sheet1.IsDataModified() ) {
		alert("저장했습니다.");
		reloading();
	} else {
		jQuery("#fevent").val("SAVE_SSR_DETAIL_SHEET");
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/process/process/SSRDetail_sheet.screen";
		var result = Modular.view.IBSheet7.doSave(sheet1, url, jQuery("#form1"), false);
	}
}


function reloading() {
	if(jQuery("#fevent").val() != "DELETE_SSR_DETAIL_SHEET") {
		var f = document.form1;
		f.shipping_id.value = '<%=params.get("shipping_id")%>';
		f.shipping_detail_id.value = '<%=params.get("shipping_detail_id")%>';
		f.material_cd.value = '<%=params.get("material_cd")%>';
		f.pur_cont_id.value = sheet1.GetCellValue(1, "pur_cont_id");
		
		f.fevent.value = "";
		f.fevent.value ="GET_SSR_DETAIL";
	    f.action = "/process/process/SSRDetail.screen";
	    f.target = "_self";
	    f.method = "post";  
	    f.submit();
	}
}

function SearchShippingTargetSearch(result) {
	if(result != null) {
		
		var material_cd = result[0];
		var material_name = result[1];
		var material_spec = result[2];
		var item_unit = result[3];
		var jan_qty = result[4];
		var item_qty = result[5];
		var item_price = result[6];
		var item_amt = result[7];
		var pur_cont_id = result[8];
		var ord_doc_no = result[9];
		var cst_doc_name = result[10];
		var currency_gb = result[11];
		var oversea_gb = result[12];
		var corp_id = result[13];
		var material_gb = result[14];
		

		var stop = 1;
		for ( var j = 0; j < material_cd.length; j++) {

			stop = 1;

			with (sheet1) {
				if (LastRow() >= 1) {
					for ( var i = 1; i <= LastRow(); i++) {
						if (GetCellValue(i, "material_cd") == material_cd[j] && GetCellValue(i, "pur_cont_id") == pur_cont_id[j]) {
							alert(material_cd[j] + "(은)는 중복된 이름입니다.");
							stop = 2;
							break;
						}
						
						if (GetCellValue(i, "material_gb") != material_gb[j]) {
							alert("자재구분이 다른 자료 입니다.");
							stop = 2;
							break;
						}
						
						if( GetCellValue(i, "currency_gb") != currency_gb[j] ) {
							alert("통화구분이 다른 자료 입니다.");
							stop = 2;
							break;
						}
					}
				}
			}
			if (stop == 1) {
				var rowIndex;
				rowIndex = sheet1.DataInsert(-1);
				
				sheet1.SetCellValue(rowIndex, "material_cd", material_cd[j]); 
				sheet1.SetCellValue(rowIndex, "material_name", material_name[j]); 
				sheet1.SetCellValue(rowIndex, "material_spec", material_spec[j]); 
				sheet1.SetCellValue(rowIndex, "item_unit", item_unit[j]); 
				sheet1.SetCellValue(rowIndex, "jan_qty", jan_qty[j]); 
				sheet1.SetCellValue(rowIndex, "item_qty", item_qty[j]); 
				sheet1.SetCellValue(rowIndex, "item_price", item_price[j]); 
				sheet1.SetCellValue(rowIndex, "item_amt", item_amt[j]);
				sheet1.SetCellValue(rowIndex, "ord_doc_no", ord_doc_no[j]);
				sheet1.SetCellValue(rowIndex, "cst_doc_name", cst_doc_name[j]);
				sheet1.SetCellValue(rowIndex, "pur_cont_id", pur_cont_id[j]);
				sheet1.SetCellValue(rowIndex, "ship_qty", jan_qty[j]);
				sheet1.SetCellValue(rowIndex, "currency_gb", currency_gb[j]);
				sheet1.SetCellValue(rowIndex, "oversea_gb", oversea_gb[j]);
				sheet1.SetCellValue(rowIndex, "corp_id", corp_id[j]);
				sheet1.SetCellValue(rowIndex, "material_gb", material_gb[j]);
			}
		}
	}
	
	fLayerPopClose('_shippingTargetSearch');
}

function doResult(resultObj) {
	try {
		if( resultObj.getRequestEvent() == "SAVE_SSR_DETAIL" ) {
			if( resultObj.getSuccess() ) {
				save_ssr_detail_sheet();
			}
			else {
				dlgErrorMsg(resultObj);
			}
		} else if ( resultObj.getRequestEvent() == "UPDATE_SSR_DETAIL" ) {
			if( resultObj.getSuccess() ) {
				save_ssr_detail_sheet();
			}
			else {
				dlgErrorMsg(resultObj);
			}
		} else if ( resultObj.getRequestEvent() == "DELETE_SSR_DETAIL" ) {
			if( resultObj.getSuccess() ) {
				alert("삭제 완료");
				
				var f = document.form1;
				f.fevent.value = "GET_SSR_LIST";
			    f.action = "/process/process/SSRList.screen";
			    f.target = "_self";
			    f.method = "post";  
			    f.submit();
			}
			else {
				dlgErrorMsg(resultObj);
			}
		} 
	}
	catch(errorObject) {
		showErrorDlg("doResult()", errorObject);
	}
}

//첨부파일   
function doAttachFile(obj) {
	 if(obj==''){
		alert("저장을 한 후 파일을 첨부할 수 있습니다.");
	}
	else if(obj != ''){ 
		viewFileListNew('SSR_DETAIL', obj.value, document.form1.p_AttachFile, "Y", "progress/ssr");
	} 
}
function doAttachFileDiv(obj) {
	 if(obj==''){
		alert("저장을 한 후 파일을 첨부할 수 있습니다.");
	}
	else if(obj != ''){ 
		viewFileListNew('SSR_DETAIL', obj.value, document.getElementById("attach_file_view"), "N", "progress/ssr");
	} 
}

/**
 * 첨부파일 예약 함수
 */
function fileDown(file_id){
		var url="/common/file/FileDownloadServlet";
 		url += "?file_id=" + file_id;
 		
 		window.open(url, "_fileDown", "toolbar=no, width=400, height=100, top=500, left=400, toolbar=no,directories=no,status=no,scrollbars=yes,resize=no,menubar=no,target=new")
}

function get_ssr_detail_sheet() {
	jQuery("#fevent").val("GET_SSR_DETAIL_SHEET");
	var url = Modular.model.PageContext.CONTEXT_ROOT + "/process/process/SSRDetail_sheet.screen";
	Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 10, "");
}

function sheet1_OnClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
	var f = document.form1;
	if(Row > 0){
		if (sheet1.ColSaveName(0, Col) == "material_name") {
			// 상태값이 S일때만 팝업 열림
			if(sheet1.GetCellValue(Row, "status") == "I" || sheet1.GetCellValue(Row, "status") == "U" || sheet1.GetCellValue(Row, "status") == "D") {
				alert("저장을 먼저 해주세요.");
				return;
			} else {
				var win_id = "_partialMaterialSearch";
				var link = "/process/process/PartialMaterialSearch.screen";
				link += "?pop_win_id="+win_id+"&shipping_detail_id="+sheet1.GetCellValue(Row,"shipping_detail_id")+"&shipping_id="+
						f.shipping_id.value+"&material_cd="+sheet1.GetCellValue(Row,"material_cd")+"&pur_cont_id="+sheet1.GetCellValue(Row,"pur_cont_id")+
						"&material_name="+sheet1.GetCellValue(Row,"material_name")+"&ship_no="+f.srn_no.value+"&status="+f.confirm_yn.value;
				fLayerPop(win_id, link, 870,400, '', '', 'NO');
			}
		}
	}
}

function PartialMaterialSearch(result) {
	if(result != null) {
		
	}
	
	fLayerPopClose('_partialMaterialSearch');
}

function changeContainerType() {
	 var f = document.form1;
	var hap = 0;	
	 hap = Number(f.twenty_dc.value.replace(/,/gi, "")) + Number(f.twenty_dt.value.replace(/,/gi, "")) + 
	 Number(f.twenty_fr.value.replace(/,/gi, "")) + Number(f.fourty_dc.value.replace(/,/gi, "")) + 
	 Number(f.fourty_dt.value.replace(/,/gi, "")) + Number(f.fourty_fr.value.replace(/,/gi, ""))+ Number(f.fourty_fft.value.replace(/,/gi, ""));
	 f.total.value = hap;
}


function sheet1_OnChange(Row, Col, Value, OldValue, RaiseFlag) {
	
	
	if (sheet1.ColSaveName(0, Col) == "ship_qty") {
		if( sheet1.GetCellValue(Row, "ship_qty") > sheet1.GetCellValue(Row, "ship_qty2") && sheet1.GetCellValue(Row, "ship_qty2") != "" ) {
			alert("선적량이 잔량보다 많습니다.");
			sheet1.SetCellValue(Row, "ship_qty", OldValue, 0);
			return;
		} else {
			sheet1.SetCellValue(Row, "ship_amt", sheet1.GetCellValue(Row, "ship_qty") * sheet1.GetCellValue(Row, "item_price"));	
		}
	}
}

function SearchUser(gubun) {
	deptPurGubun = gubun;
	var win_id = "_searchUserPopup";
	var link = "/lib/dlgSearchUserPop.screen";
	    link += "?pop_win_id="+win_id;
	fLayerPop(win_id, link, 700,400, '', '', 'NO');	
}

function SearchUserClose(result){
	var f= document.form1;
	
	if(deptPurGubun == "dept") {
		f.dept_emp_name.value = result[1];
		f.dept_emp_no.value = result[9];
		f.dept_hand_tel_no.value = result[7];
		f.dept_e_mail.value = result[8];	
	} else {
		f.pur_emp_name.value = result[1];
		f.pur_emp_no.value = result[9];
		f.pur_hand_tel_no.value = result[7];
		f.pur_e_mail.value = result[8];
	}
	fLayerPopClose('_searchUserPopup');
}

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">

<INPUT type="hidden" name="fevent" value="<%= params.get("fevent") %>">
<INPUT type="hidden" name="shipping_id" value="<%= params.get("shipping_id") %>">
<INPUT type="hidden" name="dept_cd" value="<%=StringUtils.nvl(params.get("dept_cd"), vo.get("dept_cd"))%>">
<INPUT type="hidden" name="dept_nm" value="<%=StringUtils.nvl(params.get("dept_nm"), vo.get("dept_nm"))%>">
<INPUT type="hidden" name="dept_cd2" value="<%=StringUtils.nvl(params.get("dept_cd2"), vo.get("dept_cd"))%>">
<INPUT type="hidden" name="dept_nm2" value="<%=StringUtils.nvl(params.get("dept_nm2"), vo.get("dept_nm"))%>">
<INPUT type="hidden" name="shipping_detail_id" value="<%= params.get("shipping_detail_id") %>">
<INPUT type="hidden" name="material_cd" value="<%= params.get("material_cd") %>">
<INPUT type="hidden" name="vendor_cd" value="<%= vo.get("corp_id") %>">
<INPUT type="hidden" name="vendor_name" value="<%= vo.get("vendor_name") %>">
<INPUT type="hidden" name="confirm_yn" value="<%= vo.get("confirm_yn") %>">
<INPUT type="hidden" name="oversea_gb">
<INPUT type="hidden" name="pur_cont_id">
<INPUT type="hidden" name="corp_id">
<INPUT type="hidden" name="sYmdSt" value="<%= params.get("sYmdSt") %>">
<INPUT type="hidden" name="sYmdEd" value="<%= params.get("sYmdEd") %>">
<INPUT type="hidden" name="p_srn_no" value="<%= params.get("p_srn_no") %>">
<INPUT type="hidden" name="corp_name" value="<%= params.get("corp_name") %>">
<INPUT type="hidden" name="material_gb" value="">

	<!-- 제목 및 버튼 -->
   	<table width="100%">
		<colgroup>
			<col width="500" />
			<col width="*" />
		</colgroup>
	<tr>
	   	<th>
		   <div align="left" id="title">
		    <ul>
		     <li>Shipping Detail</li>
		    </ul>
		   </div>
	   </th>
	   <td align="right">
			<%
				if(!vo.get("confirm_yn").equals("9")) {
			%>
				<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="btnDelete">Delete</a></span>
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnConfirm">Confirm</a></span>		
			<%
				}
			%>
			
			<%
				if(vo.get("confirm_yn").equals("9")) {
			%>
			    <span class="btnSearch center"><a href="javascript:void(0);" id="btnSubSave">ATD/ATA저장</a></span>
			<%
				}
			%>
			<span class="btnSearch center"><a href="javascript:void(0);" id="btnList">List</a></span>
			
	   </td>
   	</tr>
   	</table>


<!-- 데이터 영역 : 시작 -->
<TABLE class="form-table" id="f_table">
		<colgroup>
			<col width="10%" />
			<col width="35%" />
			<col width="13%" />
			<col width="*" />
		</colgroup>	
  <TR height="25"> 
    <th> SRN No</th>
	<TD>
			<%	if( fevent.equals("REG_SSR_DETAIL") ) { %>
			 	SRN No는 자동으로 발번 됩니다.
			<% 	} else { %>
				<%= InputText.get("srn_no", vo.get("srn_no"), 95, 20, "readOnly, persize") %>
			<% } %>
    </TD>
    <th> Contract</th>
	<TD>
		<%=CommCodeManager.getSelectCodeList("SHORE_YN","SHORE_YN","height=18;width:100px;","",vo.get("SHORE_YN")) %>
	</TD>
  </TR>		
  <TR height="25"> 
	<th>Bill of Lading</th>
	<TD> 
		<%= InputText.get("bl_no", vo.get("bl_no"), 95, 30, "persize") %>
	</TD>
	<th class="required"> Item Description</th>
	<TD>
		<%= InputText.get("item_description", vo.get("item_description"), 95, 120, "persize") %>
	</TD>
	
  </TR>  
  <TR height="25"> 
  	 <th>Origin</th>
      <TD>
      	<%= InputText.get("origin", vo.get("origin"), 95, 100, "persize") %>
      </TD>      
  	<th class="required"> Invoice No</th>
	<TD>
		<%= InputText.get("invoice_no", vo.get("invoice_no"), 95, 30, "persize") %> 
 	</TD>
  </TR>
  <TR height="25"> 
       <th>PKG / KGS</th>
      <TD> 
      	<%= InputText.get("pkg", pkg, 46, 2, "number, persize, right") %>
      	<%= InputText.get("kgs", vo.get("kgs"), 46, 30, "persize, right") %>
      </TD>
	<th>Invoice Value</th>
	<TD>
		<%= InputText.get("invoice_value", invoice_value, 69, 12, "number, persize, right", "Number") %>
	</TD>
  </TR>
   <TR height="25"> 
  	 <th>CBM</th>
	  <TD>
      	<%= InputText.get("cbm", vo.get("cbm"), 95, 30, "persize") %>
      </TD>
      <th>Customs Clearance</th>
      <TD>
      	<%= InputText.get("cc", DateUtil.formatDateTime(vo.get("cc"), "yyyyMMdd", "yyyy-MM-dd"), 20, 50, "readOnly, persize, center") %>
		<IMG name="cc_date_img" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" onClick="JavaScript:dlgCalendar('cc');">
      </TD>
   </TR>
   <TR height="25">
    <th>Vessel Name</th>
      <TD > 
      	<%= InputText.get("vessel_name", vo.get("vessel_name"), 95, 50, "persize") %>
      </TD>
      <th class="required">Shipping Mode</th>
      <TD>
        <%= CommCodeManager.getSelectCodeList("SHIP_MODE", "shipping_mode", "width:26%;height=18px;", "", vo.get("shipping_mode"), "") %>
      </TD>
   </TR>
   
   <TR height="25">
      <th rowspan="3">Container Type</th>
      <TD rowspan="3">
      	<table>
      		<tr>
      			<td>20'DC</td><td>20'OT</td><td>20'FR</td><td>40'DC</td><td>40'OT</td><td>40'FR</td><td>45'FT</td><td>Total</td>
      		</tr>
      		<tr height="25">
      			<td>
      				<%= InputText.get("twenty_dc", twenty_dc, 70, 2, "number, persize, right", "", "onPropertyChange=\"javascript:changeContainerType()\"") %>
      			</td>
      			<td>
      				<%= InputText.get("twenty_dt", twenty_dt, 70, 2, "number, persize, right", "", "onPropertyChange=\"javascript:changeContainerType()\"") %>
      			</td>
      			<td>
      				<%= InputText.get("twenty_fr", twenty_fr, 70, 2, "number, persize, right", "", "onPropertyChange=\"javascript:changeContainerType()\"") %>
      			</td>
      			<td>
      				<%= InputText.get("fourty_dc", fourty_dc, 70, 2, "number, persize, right", "", "onPropertyChange=\"javascript:changeContainerType()\"") %>
      			</td>
      			<td>
      				<%= InputText.get("fourty_dt", fourty_dt, 70, 2, "number, persize, right", "", "onPropertyChange=\"javascript:changeContainerType()\"") %>
      			</td>
      			<td>
      				<%= InputText.get("fourty_fr", fourty_fr, 70, 2, "number, persize, right", "", "onPropertyChange=\"javascript:changeContainerType()\"") %>
      			</td>
      			<td>
      				<%= InputText.get("fourty_fft", fourty_fft, 70, 2, "number, persize, right", "", "onPropertyChange=\"javascript:changeContainerType()\"") %>
      			</td>
      			<td>
					<%= InputText.get("total", total, 70, 20, "number, persize, readOnly, right") %>
				</td>
      		</tr>
      	</table>
      </TD>
   	  
	 <th>on Site Plan/Actual</th>
      <TD>
        <%= InputText.get("onsitePlanDate", DateUtil.formatDateTime(vo.get("onsite_plan_date"), "yyyyMMdd", "yyyy-MM-dd"), 20, 50, "readOnly, persize, center") %>
		<IMG name="onsitePlanDate_date_img" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" onClick="JavaScript:dlgCalendar('onsitePlanDate');">
		<%= InputText.get("onsiteArrivalDate", DateUtil.formatDateTime(vo.get("onsite_arrival_date"), "yyyyMMdd", "yyyy-MM-dd"), 20, 50, "readOnly, persize, center") %>
		<IMG name="onsiteArrivalDate_date_img" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" onClick="JavaScript:dlgCalendar('onsiteArrivalDate');">
      </TD>
     </tr>
     <tr height= "25">
      <th class="required">POL ETD/ATD</th>
      <TD>
        <%= InputText.get("pol", vo.get("pol"), 52, 30, "persize") %>
        <%= InputText.get("polEtd", DateUtil.formatDateTime(vo.get("pol_etd"), "yyyyMMdd", "yyyy-MM-dd"), 15, 50, "readOnly, persize, center") %>
		<IMG name="polEtd_date_img" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" onClick="JavaScript:dlgCalendar('polEtd');">
		<%= InputText.get("polAtd", DateUtil.formatDateTime(vo.get("pol_atd"), "yyyyMMdd", "yyyy-MM-dd"), 15, 50, "readOnly, persize, center") %>
		<IMG name="polAtd_date_img" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" onClick="JavaScript:dlgCalendar('polAtd');">
      </TD>
    </tr> 
    <tr height="25">
      <th class="required">POD STA/ATA</th>
      <TD>
        <%= InputText.get("pod", vo.get("pod"), 52, 30, "persize") %>
        <%= InputText.get("podEtd", DateUtil.formatDateTime(vo.get("pod_etd"), "yyyyMMdd", "yyyy-MM-dd"), 15, 50, "readOnly, persize, center") %>
		<IMG name="podEtd_date_img" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" onClick="JavaScript:dlgCalendar('podEtd');">
		<%= InputText.get("podAtd", DateUtil.formatDateTime(vo.get("pod_atd"), "yyyyMMdd", "yyyy-MM-dd"), 15, 50, "readOnly, persize, center") %>
		<IMG name="podAtd_date_img" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" onClick="JavaScript:dlgCalendar('podAtd');">
      </TD>
   </TR>
   <TR height="25">
      <th>Field Material Manager</th>
      <TD> 
      	<%= InputText.get("dept_emp_name", vo.get("dept_emp_name"), 17, 10, "desc=,readOnly") %>
		<INPUT type='hidden' name="dept_emp_no" desc="" value="<%=vo.get("dept_emp_no")%>">
		<IMG src="/img/buyer/button/bt_search_right.gif" alt="담당자" border="0" align="absmiddle" style="cursor:pointer;" onClick="JavaScript:SearchUser('dept');">
		<%= InputText.get("dept_hand_tel_no", vo.get("dept_hand_tel_no"), 20, 50, "readOnly, persize, center") %>
		<%= InputText.get("dept_e_mail", vo.get("dept_e_mail"), 38, 50, "readOnly, persize, center") %>
      </TD>
      <th style="text-align: left;">Purchasing Manager</th>   
      <TD> 
      	<%= InputText.get("pur_emp_name", vo.get("pur_emp_name"), 12, 10, "desc=,readOnly, center") %>
		<INPUT type='hidden' name="pur_emp_no" desc="" value="<%=vo.get("pur_emp_no")%>">
		<IMG src="/img/buyer/button/bt_search_right.gif" alt="담당자" border="0" align="absmiddle" style="cursor:pointer;" onClick="JavaScript:SearchUser('pur');">
		<%= InputText.get("pur_hand_tel_no", vo.get("pur_hand_tel_no"), 24, 30, "persize, readOnly, center") %>
		<%= InputText.get("pur_e_mail", vo.get("pur_e_mail"), 39, 30, "persize, readOnly, center") %>
      </TD>
   </tr>
   <TR height="25">
   		<th>Remarks</th>
      <TD> 
      	<TEXTAREA name="remarks" style="width:95%" rows="8" class="input"><%=vo.get("remarks") %></TEXTAREA>
      </TD>
      <th> Attach File</th>
        <td style="padding-top: 3px;"> 
			<TEXTAREA name="p_AttachFile" style="width:85%" rows="9" class="input" readOnly><%=vo_file.get("SSR_DETAIL") %></TEXTAREA>
			<!-- <IMG src="/img/buyer/icon/icon_plus.gif" alt="adjust size" border="0" align="top" onClick="JavaScript:toggleTextarea(this, document.form1.p_AttachFile, 1, 9);" style="cursor:hand;"> -->
	        <IMG id='search_spot_button' onClick="doAttachFile(document.form1.shipping_id);" src='/img/buyer/button/bt_change.gif' border='0'  align="top" align='absmiddle' alt='[Attach File]' style='cursor:hand;'>  		 	
	    </td>
   </TR>
 </TABLE>
 
 <table id=item_list width="100%">
	<colgroup>
		<col width="500" />
		<col width="*" />
	</colgroup>
	<tr>
   		<th>
   		<div class="application-info magT20">
			<div class="application-sub-title">
				<span class="title">ITEM List</span>
			</div>
		</div>
   		</th>
   		<td align="right">
			<%
				if(!vo.get("confirm_yn").equals("9")) {
			%>
				<span class="btnSearch center"><a href="javascript:void(0);" id="btn_row_del">Delete</a></span>
			<%
				}
			%>
   		</td>
  	</tr>
</table>
 
<div id="sheet1_div" style="padding-top:5px; height: auto; min-height: 210px; overflow: auto;">
	<script>createIBSheet('sheet1','100%', '210px');</script>
</div>
</FORM>