<%--
  - Name   : PSRList.jsp
  - Author(s)  : gyeongmo an
  - Date       : 2014.09.03
  - Copyright  : Copyright (c) 2014 www.udapsoft.co.kr, Inc.
  - Description: PSRList
  --%>
  
<%@ 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="kr.co.udapsoft.common.code.CommCodeManager" %>
<%@ 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 fevent = storage.getEvent();
    RowSet p_dis = storage.getRowSet("ROWSET");
    RowSet p_exe = storage.getRowSet("ROWSET1");
    String dis_code = "";
    String dis_name = "";
    for(int i=0;i<p_exe.size();i++){   
		if(i==p_exe.size()-1){
			dis_name +=(p_exe.getColumn(i,"ESTDESC").toString().substring(8)) ;
			dis_code +=(p_exe.getColumn(i,"PAYITEM").toString().substring(8)) ;
		}else{
			dis_name =dis_name+(p_exe.getColumn(i,"ESTDESC").toString().substring(8)+"|") ;
		    dis_code =dis_code+(p_exe.getColumn(i,"PAYITEM").toString().substring(8)+"|") ; 			
		}
    }    
    
    String today = DateUtil.formatDateTime(DateUtil.getToday(), "yyyyMMdd", "yyyyMMdd");
    String week1 = DateUtil.getPrePostDate("yyyyMMdd", 7);
    String week2 = DateUtil.getPrePostDate("yyyyMMdd", 14);
    
    params.set("CutDt", DateUtil.formatDateTime(DateUtil.getToday(), "yyyyMMdd", "yyyy-MM-dd"));
    
%>

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

var sheet2;
var sheet2Row;
var sheet2PageNo = 1;


function _onReady(){
	gridInit(sheet1);
	gridInit(sheet2);
	var f = document.form1;
	
	jQuery("#btnSearch").click(function() {
		if(f.dept_cd.value == "") {
			alert("현장을 선택해 주세요.");
			return;
		}
 
		jQuery("#fevent").val("GET_PSR_LIST");
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/process/process/PSRList_sheet.screen";
		Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 10, "");
	});
	
	jQuery("#btnExcel").click(function() {
		sheetExcelDown(sheet1,$('li').html());
		/*var dept_nm =  f.dept_nm.value ; 
		if(sheet1.RowCount() == 0) {
			alert("내역이 없습니다.");
			return;
		}

		var params = { FileName : "PSRList.xls",  SheetName : "PSRList", SheetDesign:0, Merge:1, DownCols:"DIS_NM|MR_NO|TITLE|QTY|SHIPPING_MODE|onoff|PSR_PFA|"+
				"MR_ISSUE|MR_APPROVAL|RFQ_ISSUE|QUO|TBE_ISSUE|TBE_APPROVAL|CBE|PO_ISSUE|VP_IN|VP_OUT|FINAL_VENDOR|MAJOR_RAW|RECEIPT_RAW|PIM|FAT|"
				+"FAB_TIME|SHIPPING|LANDING|ONSITE|REMARKS", TitleText:"PSR List\r\n"+dept_nm, UserMerge:"0,0,1,27 1,0,1,3", AutoSizeColumn:1  } ;
		sheet1.Down2Excel(params);*/
	});
	     
	jQuery("#btnBudget").click(function() { 
		if(!confirm("실행예산 자료 생성하시겠습니까?")) {
		   return ;
		}
		if(f.dept_cd.value == "") {
			alert("현장을 선택해 주세요.");
			return;
		}

		jQuery("#proc_gb").val("1");
		submitXmlRequest("/process/process/PSRList_form.screen", "GET_PROC", document.form1); 
	});
	jQuery("#btnActual").click(function() {
		if(f.dept_cd.value == "") {
			alert("현장을 선택해 주세요.");
			return;
		}
		
		if(!confirm("저장 후 Plan대비 Forecast, Actual자료 생성 하시겠습니까?")) {
			   return ;
		}
		//SAVE
		jQuery("#proc_gb").val("2");
		jQuery("#fevent").val("SAVE_PSR");
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/process/process/PSRList_sheet.screen";
		Modular.view.IBSheet7.doSave(sheet1, url, jQuery("#form1"), 10, "");	
		
		//submitXmlRequest("/process/process/PSRList_form.screen", "GET_PROC", document.form1); 
	});
	
	jQuery("#btntest").click(function() {
		if(f.dept_cd.value == "") {
			alert("현장을 선택해 주세요.");
			return;
		}
		if(confirm("Actual자료 생성 하시겠습니까?")) {
			jQuery("#proc_gb").val("3");
			submitXmlRequest("/process/process/PSRList_form.screen", "GET_PROC", document.form1); 
		}
		
	});
	
	jQuery("#btnAdd").click(function() {
		//P만 등록가능. 집계하면 F,A자동생성 
		
		if(f.dept_cd.value == "") {
			alert("현장을 선택해 주세요.");
			return;
		}
		//var Row = sheet1.DataCopy();
		var Row = sheet1.DataInsert(0);
		sheet1.SetCellValue(Row, "PSR_KIND", "P");
		sheet1.SetCellValue(Row, "PSR_PFA", "P");	 
	});
	jQuery("#btnSave").click(function() {
		if(!confirm("저장하시겠습니까?")) {
			   return ;
		}
		jQuery("#fevent").val("SAVE_PSR");
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/process/process/PSRList_sheet.screen";
		Modular.view.IBSheet7.doSave(sheet1, url, jQuery("#form1"), 10, "");	
		
	});
	jQuery("#btnMail").click(function() {
		if(f.dept_cd.value == "") {
			alert("현장을 선택해 주세요.");
			return;
		}
		
		if(!confirm("지연 및 도래하는 자료 메일발송 하시겠습니까?")) {
			   return ;
		}
		
		submitXmlRequest("/process/process/PSRList_form.screen", "SEND_MAIL", document.form1); 
	});
	jQuery("#btnDef").click(function() {
		if(f.dept_cd.value == "") {
			alert("현장을 선택해 주세요.");
			return;
		}
		
		var win_id = "_dlgPSRDefinePop";
 		var link = "/process/process/dlgPSRDefinePop.screen";
 		    link += "?pop_win_id="+win_id;
 		    link += "&BASECD=SSR_DEPT&fevent=DEPTPOP";
 		
 		fLayerPop(win_id, link, 700,400, '', '', 'NO');
	});
	jQuery("#btnReport").click(function() {
		if(f.dept_cd.value == "") {
			alert("현장을 선택해 주세요.");
			return;
		}		 
		jQuery("#fevent").val("GET_PSR_REPORT");
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/process/process/PSRReport_sheet.screen";
		Modular.view.IBSheet7.doSearch(sheet2, url, jQuery("#form1"), 10, "");
		
	}); 	
	autoResize();
}


function gridInit(sheetName){
	var init_sheet = {}; 
	init_sheet.Cfg = {SearchMode:2, MergeSheet:msPrevColumnMerge+ msHeaderOnly};
	
	if(sheetName.id == "sheet1") {
		init_sheet.Cols = [
                            {Header:'상태|상태',							 Type:"Status",   SaveName:"status", 		 Width:50, 	Align:"Center", Hidden:"True"},
                            {Header:'삭제|삭제',							 Type:"DelCheck", SaveName:"del_check", 	 Width:50, 	Align:"Center", ColMerge:"false",HeaderCheck:0},
                            {Header:'Discipline|Dis',	                 Type:"Combo",	  SaveName:"DIS_FACE",		 Width:50, 	Align:"Left",   ColMerge:"false", Edit:"True", ComboText:"<%=dis_name%>" , ComboCode:"<%=dis_code%>" },
			       			{Header:'Discipline|Dis Co',	             Type:"Text",	  SaveName:"DIS_CD",		 Width:50, 	Align:"Left",   ColMerge:"false", Edit:"True"  },
			       			{Header:'Discipline|Discipline Nm',	         Type:"Text",	  SaveName:"DIS_NM",		 Width:100, Align:"Left",   ColMerge:"false",Edit:"True" },
			       			{Header:'MR No|MR No',	                     Type:"Text",	  SaveName:"MR_NO",		     Width:120, Align:"Left",   Edit:"True", ColMerge:"false"},
			       			{Header:'MR No|MR No',	                     Type:"Text",	  SaveName:"MR_NO1",	     Width:120, Align:"Left",   Edit:"True", Hidden:"True"},
			       			{Header:'Item No|Item No',	                 Type:"Text",	  SaveName:"ITEM_NO",	     Width:150, Align:"Left",   Edit:"True" },
			       			{Header:'Title|Title',	                     Type:"Text",	  SaveName:"TITLE",		     Width:150, Align:"Left",   Edit:"True" },
			       			{Header:'QTY|QTY',	                         Type:"Text",	  SaveName:"QTY",		     Width:60,  Align:"Left",   Edit:"True" },
			       			{Header:'Shipping Mode|Shipping Mode',	     Type:"Text",	  SaveName:"SHIPPING_MODE",  Width:100, Align:"Cneter", Edit:"True" },
			       			{Header:'On/Off Shore|On/Off Shore',	     Type:"Text",	  SaveName:"onoff",		     Width:80,  Align:"Cneter", Edit:"True" },
			       			{Header:'Proposed Bidders|Proposed Bidders', Type:"Text",	  SaveName:"CORP_NM",		 Width:150, Align:"Left",   Edit:"false", Cursor:"Pointer"  },
			       			{Header:'GB|GB',	                         Type:"Text",	  SaveName:"PSR_PFA",		 Width:30, 	Align:"Center", Edit:"false"},
			       			{Header:'MR Issue|yy-mm-dd',	             Type:"Date",	  SaveName:"MR_ISSUE",	     Width:80, 	Align:"Center", Format:"yy-MM-dd", ColMerge:"false"},
			       			{Header:'MR Approval|MR Approval',	         Type:"Date",	  SaveName:"MR_APPROVAL",	 Width:80, 	Align:"Center", Format:"yy-MM-dd", ColMerge:"false"},
			       			{Header:'RFQ Issue|RFQ Issue',	             Type:"Date",	  SaveName:"RFQ_ISSUE",	     Width:80, 	Align:"Center", Format:"yy-MM-dd", ColMerge:"false"},
			       			{Header:'Quo Date|Quo Date',	             Type:"Date",	  SaveName:"QUO",		     Width:80, 	Align:"Center", Format:"yy-MM-dd", ColMerge:"false"},
			       			{Header:'TBE Issue|TBE Issue',	             Type:"Date",	  SaveName:"TBE_ISSUE",	     Width:80, 	Align:"Center", Format:"yy-MM-dd", ColMerge:"false"},
			       			{Header:'TBE Approval|TBE Approval',	     Type:"Date",	  SaveName:"TBE_APPROVAL",   Width:80, 	Align:"Center", Format:"yy-MM-dd", ColMerge:"false"},
			       			{Header:'CBE|CBE',	                         Type:"Date",	  SaveName:"CBE",		     Width:80, 	Align:"Center", Format:"yy-MM-dd", ColMerge:"false"},
			       			{Header:'PO Issue|PO Issue',	             Type:"Date",	  SaveName:"PO_ISSUE",	     Width:80, 	Align:"Center", Format:"yy-MM-dd", ColMerge:"false"},
			       			{Header:'Vendor Datas|In',	                 Type:"Date",	  SaveName:"VP_IN",		     Width:80, 	Align:"Center", Format:"yy-MM-dd", ColMerge:"false"},
			       			{Header:'Vendor Datas|Out',	                 Type:"Date",	  SaveName:"VP_OUT",		 Width:80, 	Align:"Center", Format:"yy-MM-dd", ColMerge:"false"},
			       			{Header:'Vendor Datas|Final Vendor',	     Type:"Date",	  SaveName:"FINAL_VENDOR",   Width:80, 	Align:"Center", Format:"yy-MM-dd", ColMerge:"false"},
			       			{Header:'Manufacturing|Major Raw PO',	     Type:"Date",	  SaveName:"MAJOR_RAW",	     Width:80, 	Align:"Center", Format:"yy-MM-dd", ColMerge:"false"},
			       			{Header:'Manufacturing|Receipt of Raw',	     Type:"Date",	  SaveName:"RECEIPT_RAW",	 Width:80, 	Align:"Center", Format:"yy-MM-dd", ColMerge:"false"},
			       			{Header:'Manufacturing|PIM',	             Type:"Date",	  SaveName:"PIM",		     Width:80, 	Align:"Center", Format:"yy-MM-dd", ColMerge:"false"},
			       			{Header:'Manufacturing|FAT',	             Type:"Date",	  SaveName:"FAT",		     Width:80, 	Align:"Center", Format:"yy-MM-dd", ColMerge:"false"},
			       			{Header:'Fabrication|TIME',   	             Type:"Text",	  SaveName:"FAB_TIME",	     Width:60, 	Align:"Center", Edit:"false", ColMerge:"false"},
			       			{Header:'SSR|Shipping',	                     Type:"Date",	  SaveName:"SHIPPING",	     Width:80, 	Align:"Center", Format:"yy-MM-dd",Edit:"True", ColMerge:"false"},
			       			{Header:'SSR|Landing',	                     Type:"Date",	  SaveName:"LANDING",		 Width:80, 	Align:"Center", Format:"yy-MM-dd",Edit:"True", ColMerge:"false"},
			       			{Header:'SSR|OnSite',	                     Type:"Date",	  SaveName:"ONSITE",		 Width:80, 	Align:"Center", Format:"yy-MM-dd",Edit:"True", ColMerge:"false"},
			       			{Header:'Remarks|Remarks',	                 Type:"Text",	  SaveName:"REMARKS",		 Width:100, Align:"Left" },
			       			{Header:'PSR_ID|PSR_ID',	                 Type:"Text",	  SaveName:"PSR_ID",		 Width:30, 	Align:"Center", Edit:"false", Hidden:"True"},
			       			{Header:'corp_id|corp_id',	                 Type:"Text",	  SaveName:"CORP_ID",		 Width:0, 	Align:"Left",   Hidden:"True" },
			       			{Header:'pur_cont_id|pur_cont_id',	         Type:"Text",	  SaveName:"pur_cont_id",	 Width:0, 	Align:"Left",   Hidden:"True" },
			       			{Header:'pur_cont_id|dept_cd',	             Type:"Text",	  SaveName:"DEPT_CD",		 Width:0, 	Align:"Left",   Hidden:"True" },
			       			{Header:'PSR_KIND|PSR_KIND',	             Type:"Text",	  SaveName:"PSR_KIND",		 Width:0, 	Align:"Left",   Hidden:"True" }  
		];
	} else if(sheetName.id == "sheet2") { 
		init_sheet.Cols = [
                           {Header:'상태|상태',							 Type:"Status",   SaveName:"status", 		 Width:50, 	Align:"Center", Hidden:"True"},
                          	{Header:'discipline|discipline',	         Type:"Text",	  SaveName:"DIS_NM",		 Width:100, Align:"Left",   ColMerge:"True"},
			       			{Header:'No.of Req|No.of Req',               Type:"Text",	  SaveName:"CNT",		     Width:60,  Align:"Center",  ColMerge:"True" },
			       			{Header:'Plan|Actual',	                     Type:"Text",	  SaveName:"PSR_PFA",		 Width:60,  Align:"Center",   },
			       			{Header:'MR Issue|MR Issue',	             Type:"Text",	  SaveName:"MR_ISSUE",	     Width:60, 	Align:"Center"},
			       			{Header:'MR Approval|MR Approval',	         Type:"Text",	  SaveName:"MR_APPROVAL",	 Width:60, 	Align:"Center"},
			       			{Header:'RFQ Issue|RFQ Issue',	             Type:"Text",	  SaveName:"RFQ_ISSUE",	     Width:60, 	Align:"Center"},
			       			{Header:'Quo Date|Quo Date',	             Type:"Text",	  SaveName:"QUO",		     Width:60, 	Align:"Center"},
			       			{Header:'TBE Issue|TBE Issue',	             Type:"Text",	  SaveName:"TBE_ISSUE",	     Width:60, 	Align:"Center"},
			       			{Header:'TBE Approval|TBE Approval',	     Type:"Text",	  SaveName:"TBE_APPROVAL",   Width:60, 	Align:"Center"},
			       			{Header:'PO Issue|PO Issue',	             Type:"Text",	  SaveName:"PO_ISSUE",	     Width:60, 	Align:"Center"},
			       			{Header:'PIM|PIM',	                         Type:"Text",	  SaveName:"PIM",		     Width:60, 	Align:"Center"},
			       			{Header:'FAT|FAT',	                         Type:"Text",	  SaveName:"FAT",		     Width:60, 	Align:"Center"},
			       			{Header:'Shipping|Shipping',	             Type:"Text",	  SaveName:"SHIPPING",	     Width:60, 	Align:"Center"},
			       			{Header:'Onsite|Onsite',	                 Type:"Text",	  SaveName:"ONSITE",	     Width:60, 	Align:"Center"},
			       			{Header:'CHK|MR_ISSUE_YN',	                 Type:"Text",	  SaveName:"MR_ISSUE_YN",	 Width:60, 	Align:"Center", Hidden:"False"},
			       			{Header:'CHK|MR_APPROVAL_YN',	             Type:"Text",	  SaveName:"MR_APPROVAL_YN", Width:60, 	Align:"Center", Hidden:"False"},
			       			{Header:'CHK|QUO_YN',	                     Type:"Text",	  SaveName:"QUO_YN",		 Width:60, 	Align:"Center", Hidden:"False"},
			       			{Header:'CHK|TBE_ISSUE_YN',	                 Type:"Text",	  SaveName:"TBE_ISSUE_YN",	 Width:60, 	Align:"Center", Hidden:"False"},
			       			{Header:'CHK|TBE_APPROVAL_YN',	             Type:"Text",	  SaveName:"TBE_APPROVAL_YN",Width:60, 	Align:"Center", Hidden:"False"},
			       			{Header:'CHK|PIM_YN',	                     Type:"Text",	  SaveName:"PIM_YN",		 Width:60, 	Align:"Center", Hidden:"False"},
			       			
		];
	} 

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

function setGridSize(sheetName) {
	//sheetName.FitColWidth();
}

function sheet1_OnSaveEnd(code, msg) {
    if(code >= 0) {
    	if (jQuery("#proc_gb").val() == "2") {   //get actual인경우 
    		jQuery("#proc_gb").val("2");
    		submitXmlRequest("/process/process/PSRList_form.screen", "GET_PROC", document.form1); 
    	}else{
    		alert("저장 되었습니다.");
        	jQuery("#btnSearch").click();
    	}
    	
    } else {
    	alert("저장실패");
    }
} 

function sheet1_OnSearchEnd(code, message) {
    if(code == 0) {
    		
    	var v_pre_mr = "";
    	var v_pre_row = 0 ; 
    	var v_color = "";
    	setGridSize(sheet1);
    	
    	 for(var i=2; i<sheet1.RowCount()+2; i++) {
        	if (sheet1.GetCellValue(i, "pur_cont_id") != "")
    		{
    			sheet1.SetCellFontColor(i, "CORP_NM", "#0000ff");
    		}
    		if(sheet1.GetCellValue(i, "PSR_PFA") == "F") {    			
    			for (var j = 14; j<= 32; j ++ ){
    				if (j != 29){ //fabrication time 제외 
	    				if('<%=week2%>' >= sheet1.GetCellValue(i, j) && '<%=week1%>' < sheet1.GetCellValue(i, j)){
	    					sheet1.SetCellBackColor(i-1, j, "#66CCFF"); //2주
	                    	sheet1.SetCellBackColor(i, j, "#66CCFF"); //2주 
	                    	v_color = "#66CCFF";	                
	        			} 
	                    if( '<%=week1%>' >= sheet1.GetCellValue(i, j) && '<%=today%>' < sheet1.GetCellValue(i, j)){
	                    	sheet1.SetCellBackColor(i-1, j, "#FFFF66"); //1주
	                    	sheet1.SetCellBackColor(i, j, "#FFFF66"); //1주 
	                    	v_color = "#FFFF66";	                    	   
	        			}   
	                    if('<%=today%>' >= sheet1.GetCellValue(i, j) && sheet1.GetCellValue(i, j) != ""){
	                    	sheet1.SetCellBackColor(i-1, j, "#FFCC66"); //지연
	                    	sheet1.SetCellBackColor(i, j, "#FFCC66"); //지연
	                    	v_color = "#FFCC66";
	        			}
	                    for (var m = i+1; m<sheet1.RowCount()+2; m++ ){
                    		if (sheet1.GetCellValue(m, "MR_NO") == sheet1.GetCellValue(i, "MR_NO") && sheet1.GetCellValue(m, "PSR_PFA") == "A" && sheet1.GetCellValue(m, j) == ""){
                    			sheet1.SetCellBackColor(m, j, v_color);
                    		}else if(sheet1.GetCellValue(m, "MR_NO") == sheet1.GetCellValue(i, "MR_NO") && sheet1.GetCellValue(m, "PSR_PFA") == "A" && sheet1.GetCellValue(m, j) != ""){
                    			sheet1.SetCellBackColor(i-1, j, "#FFFFFF"); //Plan
            					sheet1.SetCellBackColor(i, j, "#FFFFFF"); //Forecast
                    		}
                    		if (sheet1.GetCellValue(m, "MR_NO") != sheet1.GetCellValue(i, "MR_NO")){
                    			break;
                    		}
                    	}
	                    v_color = "";
    				}
    			}     			
    		}    		 
    		
    		//P만있는경우 title분리  
    		if (sheet1.GetCellValue(i, "MR_NO") != v_pre_mr  && i - Number(v_pre_row) == 1) {
    			sheet1.SetMergeCell(i,5, 1, 1);
    			sheet1.SetMergeCell(i,6, 1, 1);
    			sheet1.SetMergeCell(i,7, 1, 1);
    			sheet1.SetMergeCell(i,8, 1, 1);
    			sheet1.SetMergeCell(i,9, 1, 1);
    			sheet1.SetMergeCell(i,10, 1, 1);
    		}
    		if (sheet1.GetCellValue(i, "PSR_PFA") == "P"){
    			v_pre_mr = sheet1.GetCellValue(i, "MR_NO");
    			v_pre_row = i;
    		}     		
    	}      	
 		
 	} else {
		//조회 에러 수행
		alert(message);	
	}
}

function sheet2_OnSearchEnd(code, message) {
    if(code == 0) {
    	if(sheet2.RowCount() == 0) {
			alert("내역이 없습니다.");
			return;
		}
    	
    	var f= document.form1;
    	var cutdt = "" ; 
    	var s_title = "DIS_NM|CNT|PSR_PFA|";
    	var s_len = 0;
    	if (sheet2.GetCellValue(2, "MR_ISSUE_YN") == "Y"){
    		 s_title = s_title + "MR_ISSUE|";
    		 s_len = s_len + 1;
    		 cutdt = cutdt + "|";
    	}
    	if (sheet2.GetCellValue(2, "MR_APPROVAL_YN") == "Y"){
   		 	 s_title = s_title + "MR_APPROVAL|";
   		     s_len = s_len + 1;
    		 cutdt = cutdt + "|";
       	}
    	s_title = s_title + "RFQ_ISSUE|"
    	if (sheet2.GetCellValue(2, "QUO_YN") == "Y"){
   		     s_title = s_title + "QUO|";
   		     s_len = s_len + 1;
    		 cutdt = cutdt + "|";
   	    }
    	if (sheet2.GetCellValue(2, "TBE_ISSUE_YN") == "Y"){
   		     s_title = s_title + "TBE_ISSUE|";
   		     s_len = s_len + 1;
    		 cutdt = cutdt + "|";
   	    }
    	if (sheet2.GetCellValue(2, "TBE_APPROVAL_YN") == "Y"){
  		     s_title = s_title + "TBE_APPROVAL|";
   		     s_len = s_len + 1;
    		 cutdt = cutdt + "|";
  	    }
    	s_title = s_title + "PO_ISSUE|";
    	if (sheet2.GetCellValue(2, "PIM_YN") == "Y"){
  		     s_title = s_title + "PIM|";
   		     s_len = s_len + 1;
    		 cutdt = cutdt + "|";
  	    }

		cutdt = cutdt + "Cut-Off Date : " + f.CutDt.value;
    	s_title = s_title + "FAT|SHIPPING|ONSITE" ;
    	var s_len2 = 4 + s_len;
    	s_len = s_len + 8 ;
    	var s_len_title = "0,0,1," + s_len + " 1," + s_len2 + ",1,4";
    	var params = { FileName : "PSRReport.xls",  SheetName : "Summary", SheetDesign:1, Merge:1, DownCols:s_title
		 		,TitleText:"Achievements of Procurement - " + f.dept_nm.value + "\r\n||||" + cutdt ,ExcelFontSize :"10" , UserMerge:s_len_title, AutoSizeColumn:1  } ; 
		//sheet2.Down2Excel(params);
		
		sheet2.Down2ExcelBuffer(true);  
		// 첫번째 워크시트에 담아두기를 예약함.
		sheet2.Down2Excel(params); 
		// 두번째 워크시트에 담아두기를 예약함.
		var v_dis_nm = sheet1.GetCellValue(2, "DIS_NM");
		var v_DownRows = "0|1";
		for (var i=2; i < sheet1.RowCount()+2; i++ ){	 
			if (v_dis_nm != sheet1.GetCellValue(i, "DIS_NM")){				
				sheet1.Down2Excel({ FileName : "PSRReport.xls",  SheetName : v_dis_nm, SheetDesign:1 , DownRows:v_DownRows, DownCols:"DIS_CD|DIS_NM|MR_NO|ITEM_NO|TITLE|QTY|SHIPPING_MODE|onoff|PSR_PFA|CORP_NM|"+
					"MR_ISSUE|MR_APPROVAL|RFQ_ISSUE|QUO|TBE_ISSUE|TBE_APPROVAL|CBE|PO_ISSUE|VP_IN|VP_OUT|FINAL_VENDOR|MAJOR_RAW|RECEIPT_RAW|PIM|FAT|"
					+"FAB_TIME|SHIPPING|LANDING|ONSITE|REMARKS", ExcelFontSize :"10" , AutoSizeColumn : 1, Merge : 1} ); 
				v_DownRows = "0|1";
				v_dis_nm = "";
			}
			v_DownRows = v_DownRows + "|" + i;
			v_dis_nm = sheet1.GetCellValue(i, "DIS_NM"); 
		} 
		sheet1.Down2Excel({ FileName : "PSRReport.xls",  SheetName : "Total List", SheetDesign:1 ,   DownCols:"DIS_CD|DIS_NM|MR_NO|ITEM_NO|TITLE|QTY|SHIPPING_MODE|onoff|PSR_PFA|CORP_NM|"+
			"MR_ISSUE|MR_APPROVAL|RFQ_ISSUE|QUO|TBE_ISSUE|TBE_APPROVAL|CBE|PO_ISSUE|VP_IN|VP_OUT|FINAL_VENDOR|MAJOR_RAW|RECEIPT_RAW|PIM|FAT|"
			+"FAB_TIME|SHIPPING|LANDING|ONSITE|REMARKS",ExcelFontSize :"10" ,  AutoSizeColumn : 1, Merge : 1} ); 
		// 버퍼링된 모든 엑셀 자료를 1개의 엑셀문서에 모두 모아서 즉시 다운로드 한다.
		sheet2.Down2ExcelBuffer(false); 		
	} else {
		//조회 에러 수행
		alert(message);
	}
}

function clearDiscipline() {
	var f= document.form1;
	f.p_discipline.value = "";
}

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

function sheet1_OnSmartResize(Width, Height) { 
	autoResize();
}

function autoResize(){	
	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 sheet1_OnClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
	if(Row > 1){
		if (sheet1.ColSaveName(Col) == "del_check" && sheet1.GetCellText(Row,"PSR_PFA") == "P") { //P가 삭제되면 F,A모두 삭제 
			var v_mr_no =  sheet1.GetCellText(Row,"MR_NO");
			var v_find_row = sheet1.FindText("MR_NO", v_mr_no, 0);

			for(var i=v_find_row; i<sheet1.RowCount()+2; i++) {
				if (v_mr_no == sheet1.GetCellText(i,"MR_NO")){
					sheet1.SetCellValue(i, Col, Value);
				}else{
					break;
				}
			}		 
		}
	}
}

function sheet1_OnDblClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
	if(Row > 2){
		if (sheet1.ColSaveName(Col) == "CORP_NM" && sheet1.GetCellValue(Row, "pur_cont_id") != 0) {
			var url = "/payment/purchase/PayItemPurDashBoardPop.screen";
	        url += "?job_div=P";
	        url += "&sModule=LM";
	        url += "&purContId=" + sheet1.GetCellValue(Row, "pur_cont_id");
	        openPopup(url, "btnDashTestPop", "yes", 800, 600);
		}
	}
}
function sheet1_OnChange(Row, Col, Value, CellX, CellY, CellW, CellH) { 
	if (Col == 2){
		var vText =  sheet1.GetCellText(Row,"DIS_FACE");
		sheet1.SetCellText(Row, "DIS_NM", vText.substring(5,vText.length));
		sheet1.SetCellText(Row, "DIS_CD", sheet1.GetCellValue(Row,"DIS_FACE"));	
	}	
	if (Col == 2 || Col == 3 || Col == 4 || Col == 7 || Col == 8 || Col == 9 || Col == 10  || Col == 11  ){ //PFA동시수정 
		var v_mr_no =  sheet1.GetCellText(Row,"MR_NO");
		var v_find_row = sheet1.FindText("MR_NO", v_mr_no, 0);

		for(var i=v_find_row; i<sheet1.RowCount()+2; i++) {
			if (v_mr_no == sheet1.GetCellText(i,"MR_NO")){
				sheet1.SetCellValue(i, Col, Value);
			}else{
				break;
			}
		}		
	}	
	if (Col == 14){ //approval 날짜지정 
		if (sheet1.GetCellValue(Row, 15) == "")
		{
			var value = sheet1.GetCellValue(Row, 14);		
			var dt = new Date(value.substring(0,4), value.substring(4,6),value.substring(6,8));
			
			var v_year = "";
			var v_month = "";
			var v_day = "";
			dt.setDate(dt.getDate() + 14);
			if (dt.getDate() == 31){
				if (dt.getMonth() == 4 || dt.getMonth() == 6 || dt.getMonth() == 9 || dt.getMonth() == 11 ){
					dt.setDate(dt.getDate() + 1);
				}
			}
		 
			if (dt.getMonth() == 2 && dt.getDate() > 28) 
			{
				dt.setDate(dt.getDate() + (32 - dt.getDate()));
			}
			if (dt.getMonth() == 0  ) 
			{
				v_month = '12-';
				v_year = dt.getFullYear()-1;
				v_year = v_year + '-';
				v_year = v_year.substring(2,5);
			}else{
				v_month = dt.getMonth()+'-';
				v_year = dt.getFullYear()+'-';
				v_year = v_year.substring(2,5);
			}
			
			v_day = dt.getDate()+'-';
			
			if (v_month.length == 2){
	        	v_month = '0' + v_month;
	        }
			if (v_day.length == 2){
	        	v_day = '0' + v_day;
	        }
			sheet1.SetCellValue(Row, 15, v_year+v_month+v_day.substring(0,2));
		}
		
	}	
	if (Col == 18){//approval 날짜지정 
		if (sheet1.GetCellValue(Row, 19) == "")
		{
			var value = sheet1.GetCellValue(Row, 18);		
			var dt = new Date(value.substring(0,4), value.substring(4,6),value.substring(6,8));
			var v_year = "";
			var v_month = "";
			var v_day = "";
			dt.setDate(dt.getDate() + 14);
			if (dt.getDate() == 31){
				if (dt.getMonth() == 4 || dt.getMonth() == 6 || dt.getMonth() == 9 || dt.getMonth() == 11 ){
					dt.setDate(dt.getDate() + 1);
				}
			}
			if (dt.getMonth() == 2 && dt.getDate() > 28) 
			{
				dt.setDate(dt.getDate() + (32 - dt.getDate()));
			}
			if (dt.getMonth() == 0  ) 
			{
				v_month = '12-';
				v_year = dt.getFullYear()-1;
				v_year = v_year + '-';
				v_year = v_year.substring(2,5);
			}else{
				v_month = dt.getMonth()+'-';
				v_year = dt.getFullYear()+'-';
				v_year = v_year.substring(2,5);
			}
			
			v_day = dt.getDate()+'-';
			if (v_month.length == 2){
	        	v_month = '0' + v_month;
	        }
			if (v_day.length == 2){
	        	v_day = '0' + v_day;
	        }
			sheet1.SetCellValue(Row, 19, v_year+v_month+v_day.substring(0,2));
		}		
	} 
}

function on_change_dept() {
	var f = document.form1;
	var win_id = "_searchSiteNew";
	var link = "/lib/dlgSearchSpotDept_Unitcd_New.screen";
	    link += "?sheetOpenYn=Y&pop_win_id="+win_id+"&obj_dept_cd="+f.dept_cd.value+"&obj_dept_nm="+f.dept_nm.value;
	fLayerPop(win_id, link, 570,420, '', '', 'NO'); 
}
function searchSiteClose(result) { 
	var f = document.form1;
	if( result == null ){
		f.dept_cd.value = "";   //부서코드
		f.dept_nm.value = "";   //부서명
	}else{
		f.dept_cd.value = result[0];   //부서코드
		f.dept_nm.value = result[1];   //부서명
	}
	fLayerPopClose('_searchSiteNew');
	
	//현장변경후 reload(컬럼변경)
	f.fevent.value ="";
	f.action = "/process/process/PSRList.screen";
	f.target = "_self";
	f.method = "post";  
	f.submit();
}

function doResult(resultObj) {
	try {
		document.form1.isSubmit = false;
		if( resultObj.getRequestEvent() == "GET_PROC") {
			if( resultObj.getSuccess() ) {
				jQuery("#proc_gb").val("");
				alert("생성완료 되었습니다.");
				jQuery("#btnSearch").click();
			}
			else {
				jQuery("#proc_gb").val("");
				dlgErrorMsg(resultObj);
			}
		} else if( resultObj.getRequestEvent() == "SEND_MAIL" ) {
			if( resultObj.getSuccess() ) {
				alert("메일발송 완료되었습니다.");
			}
			else {
				alert("메일발송 실패");
			}
		} 
	}
	catch(errorObject) {
		showErrorDlg("doResult()", errorObject);
	}
}
	
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">
<INPUT type="hidden" name="proc_gb" id="proc_gb" value="<%= params.get("proc_gb") %>"> 

<div align="left" id="title">
    <ul>
     <li>Procurement Status ReportList</li>
    </ul>
  </div> 
	<!-- 검색조건 시작 -->
	<table id="search-table" class="search-form-table">
		<colgroup>
			<col width="100" />
			<col width="400" />
			<col width="100" />
			<col width="*" />
			<col width="400" />
		</colgroup>
		<tr>
			<th>Project</th>
			<td>                      
		   		<%= InputText.get("dept_cd", user.get("dept_cd"), 5, 5, "hangule,center,desc=Project,ReadOnly") %>
		   		<%= InputText.get("dept_nm", user.get("dept_nm"), 30, 30, "hangule,desc=Project,ReadOnly") %>
		   		<IMG id='_btn_dept'  onClick="on_change_dept();" src='/img/buyer/button/bt_search_right.gif' border='0' align='absmiddle' alt='[현장찾기]' style='cursor:pointer;'>
                &nbsp;<IMG id='_btn_clear' onClick="dlgClearNew('dept_cd', 'dept_nm'); " src='/img/buyer/button/bt_eraser1.gif' border='0' align='absmiddle' alt='[초기화]' style='cursor:pointer;'>
			</td>
			<th>MR No.</th>
			<td>
				<%= InputText.get("p_mr_no", "", 53, 50, "hangule, desc=MR No, PerSize") %>
			</td>
			<td class="button" rowspan="2">
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnSearch">Search</a></span> 
				<!-- <span class="btnSearch center"><a href="javascript:void(0);" id="btnExcel">Excel</a></span> -->
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnBudget">Get Budget</a></span>
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnActual">Get Actual</a></span>
				<!-- <span class="btnSearch center"><a href="javascript:void(0);" id="btntest">Don't click!!</a></span> -->
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnReport">Report</a></span>
				<p style="height:2px;"></p>
				<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="btnMail">Send mail</a></span>
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnDef">Def PJT</a></span>
			</td>
		</tr>
		<tr>
			<th>Discipline</th>
			<td>
			    <%= HTMLMaker.getSelectTag(p_dis, "ESTDESC", "ESTDESC" , "p_discipline", "style='width:28%;height=18;'", "<OPTION value=''>-- 전체 --</OPTION>", params.get("p_discipline"), 0) %>
		 	</td>
		 	<th>Cut-off Date</th>
			<td>
			    <%= InputText.get("CutDt", params.get("CutDt"), 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('CutDt');">
			</td>
		</tr>
	</table>   	        
	<table> 
	<tr><td bgcolor="#66CCFF">2주전 알림</td><td bgcolor="#FFFF66">1주전 알림</td><td bgcolor="#FFCC66">지연 </td><TD valign='middle'>&nbsp;검색  Ctrl+Shift+F</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>
	<div id="sheet2_div"  style="padding-top:5px;   display:none">
		<script>createIBSheet('sheet2','100%', '4px');</script>
	</div>
</form>