/**
 * @(#)file    BidIngBiz.java
 * @(#)author  Son Hyung Min 
 * @(#)version 1.0
 * @(#)date    2014-06-23
 * @(#)since   JDK 1.4.2
 */
package kr.co.udapsoft.ebid.buyer.bid.purchase.biz;



import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import oracle.toplink.internal.ox.StrBuffer;
import kr.co.hsnc.common.base.WAFLogger;
import kr.co.hsnc.common.sql.Row;
import kr.co.hsnc.common.sql.RowSet;
import kr.co.hsnc.common.sql.RowSetImpl;
import kr.co.hsnc.common.sql.WAFSQLException;
import kr.co.hsnc.common.sql.persistent.Persistent;
import kr.co.hsnc.common.sql.persistent.PersistentImpl;
import kr.co.hsnc.common.sql.search.Search;
import kr.co.hsnc.common.sql.search.SearchImpl;
import kr.co.hsnc.common.sql.util.RowSetUtility;
import kr.co.hsnc.common.util.ValueObject;
import kr.co.udapsoft.common.code.CommCodeManager;
import kr.co.udapsoft.ebid.buyer.common.file.FileManager;
import kr.co.udapsoft.ebid.buyer.sycs.user.biz.UserCommon;

import com.udapsoft.modular.web.ibsheet7.IBSheet7Factory;
import com.udapsoft.modular.web.ibsheet7.util.IBSheet7Utils;
import com.udapsoft.waf.system.Biz;
import com.udapsoft.waf.system.HandlerStorage;

   
public class ReBidBiz extends Biz {

	public ReBidBiz(HandlerStorage storage) {
		super(storage);
	}

	public void doBiz() throws Exception {
        ValueObject user = new ValueObject();
      try{
		if(storage.compareEvent("FORM_SELECT")){//견적의뢰
	            user = getOrderReqeustValueObject();
	            storage.addValueObject("Order", user);
	            /**		파일 목록 조회			 **/
		        storage.addValueObject(user.get("DOC_ETC_IN"), getfilelist(user.get("DOC_ETC_IN"),params.get("DEMANDED_ID"),user.get("DOC_ETC_IN")));
		        storage.addValueObject(user.get("DOC_ETC_OUT"), getfilelist(user.get("DOC_ETC_OUT"),params.get("DEMANDED_ID"),user.get("DOC_ETC_OUT")));
		}else if(storage.compareEvent("FORM_SELECT_SITE")){//견적의뢰
            user = getOrderReqeustValueObject2(params.get("DEMANDED_ID"));
            storage.addValueObject("Order", user);
            /**		파일 목록 조회			 **/
	        storage.addValueObject(user.get("DOC_ETC_IN"), getfilelist(user.get("DOC_ETC_IN"),params.get("DEMANDED_ID"),user.get("DOC_ETC_IN")));
	        storage.addValueObject(user.get("DOC_ETC_OUT"), getfilelist(user.get("DOC_ETC_OUT"),params.get("DEMANDED_ID"),user.get("DOC_ETC_OUT")));
		}else if(storage.compareEvent("GET_CORP_LIST")){
			 params.set("sheet1", getCorpList(params.get("DEMANDED_ID")));
	         storage.addObject("ibsheet7Data", IBSheet7Factory.createIBSheet7(params, storage.request));
		}else if(storage.compareEvent("GET_ITEM_LIST")){
			if("Y".equals(params.get("FOR_PO_YN"))){
				params.set("sheet2", geforPo_itemList(params));	
			}else{
				params.set("sheet2", getitemList(params));
			}
	        storage.addObject("ibsheet7Data", IBSheet7Factory.createIBSheet7(params, storage.request));
		}
      }  catch (WAFSQLException se) {
	            super.doException(se);
	            this.storage.setSuccess(false);  
	            this.storage.setMessage(se.getMessage());
	            System.out.println("******************");
	            System.out.println(se.getMessage());
	            storage.setDetailMessage(se);
	            
	        }
		
	}
	
	private ValueObject getfilelist(String filegb,String id,String returnid){
		ValueObject vo = new ValueObject();
		RowSet rowSet = FileManager.getFileList(filegb, id);
		String str="";
	        for(int i=0;i<rowSet.size();i++){
	        	Row row=rowSet.getRow(i);
	        	str += (i+1)+" : "+row.get("FILE_NAME")+" ("+ row.get("FILE_SIZE")+")";
	        	if(i+1!=rowSet.size()){
	        		str +="\r\n";
	        	}
	        }
	        vo.set(returnid, str);
		return vo;
	}

	/**
	 * 발주의뢰(외주) 접수를 검색하여 리턴
	 * @param Params
	 * @return
	 */
	private RowSet getBoardList(ValueObject param) {

		Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        
     //   String sqlstr = "";
        StrBuffer sqlstr = new StrBuffer();
        try{ 
        	sqlstr.append(" SELECT A.BID_DEG																															\n");
        	sqlstr.append("      , B.DEPT_NM																																\n");
        	sqlstr.append("      , A.BID_NO																																\n");
        	sqlstr.append("      , A.DEMANDED_TITLE																													\n");
        	sqlstr.append("      , A.ONBID_YN																															\n");
        	sqlstr.append("      , TO_CHAR(A.REQUEST_DATE,'YYYY-MM-DD') AS REQUEST_DATE														\n");
        	sqlstr.append("      , TO_CHAR(A.RECEIPT_DATE,'YYYY-MM-DD') AS RECEIPT_DATE															\n");
        	sqlstr.append("      , A.STATUS_CD 																															\n");
        	sqlstr.append("      , F_GET_CODE_NAME('BID_STATUS_CD',STATUS_CD) AS STATUS_NM													\n");
        	sqlstr.append("      , A.DEMANDED_ID		 																												\n");
        	sqlstr.append("   FROM BID_MASTER A	, ACZ10100V B																									\n");
        	sqlstr.append("   WHERE A.DEPT_CD = B.DEPT_CD																										\n");
        	sqlstr.append("   AND A.STATUS_CD IN ('04','05','06')																							\n");
        	if(!param.get("P_DEPT_CD").isEmpty())
        		sqlstr.append("   AND A.DEPT_CD = '"+param.get("P_DEPT_CD")+"'																											\n");
        	if(!param.get("p_demanded_title").isEmpty())
        		sqlstr.append("   AND A.DEMANDED_TITLE LIKE '%'|| '"+param.get("p_demanded_title")+"' ||'%'																						\n");
        	if(!param.get("P_DEMANDED_FROM_DT").isEmpty() && !param.get("P_DEMANDED_TO_DT").isEmpty())
        		sqlstr.append("   AND A.REQUEST_DATE BETWEEN  '"+param.get("P_DEMANDED_FROM_DT")+"' AND '"+param.get("P_DEMANDED_TO_DT")+"'		\n");
        	if(!param.get("P_RCEIPT_FROM_DT").isEmpty() && !param.get("P_RCEIPT_TO_DT").isEmpty())
        		sqlstr.append("   AND A.REQUEST_DATE BETWEEN  '"+param.get("P_RCEIPT_FROM_DT")+"' AND '"+param.get("P_RCEIPT_TO_DT")+"'					\n");
        	if(!param.get("P_DEMANDED_STATUS").isEmpty())
        		sqlstr.append("   AND A.STATUS_CD = '"+param.get("P_DEMANDED_STATUS")+"'																						\n");
			search.setStatement(sqlstr.toString());
            rowSet = search.execute();
        }
        catch (WAFSQLException se) {
            super.doException(se);
            this.storage.setSuccess(false);  
            this.storage.setMessage(se.getMessage());
            storage.setDetailMessage(se);
        }
        finally {    
            if(rowSet == null){
            	rowSet = new RowSetImpl();
            }
        }
        return rowSet;
	}
	

	
	/**
	 * 발주의뢰(외주) 접수 상세를 검색하여 리턴
	 * @param Params
	 * @return
	 */
	private ValueObject getOrderReqeustValueObject() {

		Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        ValueObject valueobject = null;
     //   String sqlstr = "";
        StrBuffer sqlstr = new StrBuffer();
        try{
               sqlstr.append("       SELECT TO_CHAR(TO_DATE(A.DEMANDED_DATE,'YYYYMMDD'),'YYYY-MM-DD') AS DEMANDED_DATE,                                        \n");
		       sqlstr.append("       A.DEMANDED_TITLE,                                        \n");
		       sqlstr.append("       A.DEMANDED_KIND,                                        \n");
		       sqlstr.append("       F_GET_CODE_NAME('911',A.CURRENCY_GB) AS CURRENCY_GB_NM,                                        \n");
		       sqlstr.append("       A.CURRENCY_GB,                                        \n");
		       sqlstr.append("       A.DEPT_CD,                                        \n");
		       sqlstr.append("       A.EMP_NO,                                        \n");
		       sqlstr.append("       GET_USER_BUSEO_NM(A.EMP_NO) AS BUSEO_NM,                                          \n");
		       sqlstr.append("       A.DELIVERY_CONDITION,                                        \n");
		       sqlstr.append("       A.CRE_BY,                                        \n");
		       sqlstr.append("       A.CRE_DATE,                                        \n");
		       sqlstr.append("       A.UPD_BY,                                        \n");
		       sqlstr.append("       A.UPD_DATE,                                        \n");
		       sqlstr.append("       A.DEMANDED_NO,                                        \n");
		       sqlstr.append("       A.BID_APP_DATE,                                        \n");
		       sqlstr.append("       A.BID_APP_NO,                                        \n");
		       sqlstr.append("       A.PAY_ITEM,                                        \n");
		       sqlstr.append("       F_GET_PAY_ITEM_VIEW(A.PAY_ITEM,A.COST_CODE,A.COST_TYPE,A.DEPT_CD) AS PAY_ITEM_NM,                \n");
		       sqlstr.append("       A.COST_CODE,                                        \n");
		       sqlstr.append("       A.COST_TYPE,                                        \n");
		       sqlstr.append("       TO_CHAR(A.RECEIPT_DATE,'YYYY-MM-DD') AS RECEIPT_DATE,                                        \n");
		       sqlstr.append("       DECODE(A.SITEDESC_FLAG,'Y','예','N','아니오','') AS SITEDESC_FLAG,                                        \n");
		       sqlstr.append("       A.SITEDESCCHRGPRSNID,                                        \n");
		       sqlstr.append("       F_GET_USER_NM(A.SITEDESCCHRGPRSNID) AS SITEDESCCHRGPRSNNM,                                        \n");
		       sqlstr.append("       A.SITEDESCTELNO,                                        \n");
		       sqlstr.append("       TO_CHAR(A.SITEDESCDATE,'YYYY-MM-DD HH24:MI') AS SITEDESCDATE,                                        \n");
		       sqlstr.append("       TO_CHAR(A.SITEDESCDATE,'YYYY-MM-DD') AS SITEDESCDT,                                        \n");
		       sqlstr.append("       A.SITEDESCPLACE,                                        \n");
		       sqlstr.append("       A.SITEDESCEMAIL,                                        \n");
		       sqlstr.append("       A.PUREMPNO,                                        \n");
		       sqlstr.append("       F_GET_USER_NM(A.PUREMPNO) AS PUREMPNM,                                        \n");
		       sqlstr.append("       A.INNER_REMARKS,                                        \n");
		       sqlstr.append("       A.TBE_FLAG,                                        \n");
		       sqlstr.append("       A.OUTER_REMARKS,                                        \n");
		       sqlstr.append("       A.DEMANDED_ID,                                        \n");
		       sqlstr.append("       TO_CHAR(A.REQUEST_DATE,'YYYY-MM-DD') AS REQUEST_DATE,                                        \n");
		       sqlstr.append("       A.ATT_ID,                                        \n");
		       sqlstr.append("       A.BID_NO,                                        \n");
		       sqlstr.append("       A.BID_DEG,                                        \n");
		       sqlstr.append("       F_GET_CODE_NAME('ONBID',A.ONBID_YN) AS ONBID_YN,                                       \n");
		       sqlstr.append("       F_GET_CODE_NAME('CMPT_CD',A.CMPT_CD) AS CMPT_NM,                                        \n");
		       sqlstr.append("       A.CMPT_CD,                                        \n");
		       sqlstr.append("       F_GET_CODE_NAME('SUCC_CD',A.SUCC_CD) AS SUCC_NM,                                        \n");
		       sqlstr.append("       A.SUCC_CD,                                        \n");
		       sqlstr.append("       TO_CHAR(TO_DATE(A.NOTI_DY,'YYYYMMDD'),'YYYY-MM-DD') AS NOTI_DY,                                        \n");
		       sqlstr.append("       A.SITEDESC_CRG_NM,                                        \n");
		       sqlstr.append("       TO_CHAR(A.BID_FROM_DT,'YYYY-MM-DD') AS BID_FROM_DT,                                        \n");
		       sqlstr.append("       TO_CHAR(A.BID_FROM_DT,'HH24') AS BID_FROM_HH,                                        \n");
		       sqlstr.append("       TO_CHAR(A.BID_FROM_DT,'MI') AS BID_FROM_MI,                                        \n");
		       sqlstr.append("       DECODE(A.STATUS_CD, '20', TO_CHAR(A.BID_TO_DT,'YYYY-MM-DD'), '25', TO_CHAR(A.BID_TO_DT,'YYYY-MM-DD'),'30',TO_CHAR(A.BID_TO_DT,'YYYY-MM-DD'),  '')AS BID_TO_DT,                                        \n");
		       sqlstr.append("       DECODE(A.STATUS_CD, '20', TO_CHAR(A.BID_TO_DT,'HH24'), '25', TO_CHAR(A.BID_TO_DT,'HH24'),'30',TO_CHAR(A.BID_TO_DT,'HH24'), '') AS BID_TO_HH,                                        \n");
		       sqlstr.append("       DECODE(A.STATUS_CD, '20', TO_CHAR(A.BID_TO_DT,'MI'), '25', TO_CHAR(A.BID_TO_DT,'MI'),'30',TO_CHAR(A.BID_TO_DT,'MI'), '') AS BID_TO_MI,                                        \n");
		       //sqlstr.append("       TO_CHAR(A.BID_TO_DT,'YYYY-MM-DD') AS BID_TO_DT,                                        \n");
		       //sqlstr.append("       TO_CHAR(A.BID_TO_DT,'HH24') AS BID_TO_HH,                                        \n");
		       //sqlstr.append("       TO_CHAR(A.BID_TO_DT,'MI') AS BID_TO_MI,                                        \n");
		       sqlstr.append("       A.PO_EMPNM,                                        \n");
		       sqlstr.append("       A.OPEN_EMPNM,                                        \n");
		       sqlstr.append("       A.OPEN_EMPID,                                        \n");
		       sqlstr.append("       TO_CHAR(TO_DATE(A.DELI_FROM_DY,'YYYYMMDD'),'YYYY-MM-DD') AS DELI_FROM_DY,                                        \n");
		       sqlstr.append("       TO_CHAR(TO_DATE(A.DELI_TO_DY,'YYYYMMDD'),'YYYY-MM-DD') AS DELI_TO_DY,                                        \n");
		       sqlstr.append("       A.DELIVERY_PLACE,                                        \n");
		       sqlstr.append("       A.CONTFUL_RATE,                                        \n");
		       sqlstr.append("       A.CONTFUL_CONDI,                                        \n");
		       sqlstr.append("       A.WARR_RATE,                                        \n");
		       sqlstr.append("       A.WARR_CONDI,                                        \n");
		       sqlstr.append("       A.DEPT_NM,                                        \n");
		       sqlstr.append("       A.REQ_DEPT_CD,                                        \n");
		       sqlstr.append("       A.REQ_DEPT_NM,                                        \n");
		       sqlstr.append("       A.EMP_NM,                                        \n");
		       sqlstr.append("       A.STATUS_CD,                                        \n");
		       sqlstr.append("       F_GET_CODE_NAME('BID_STATUS_CD',A.STATUS_CD) AS STATUS_NM,                                      \n");    
		       sqlstr.append("       A.OPEN_DT,                                        \n");
		       sqlstr.append("       A.CONT_APP_DATE,                                        \n");
		       sqlstr.append("       A.CONT_APP_NO,                                        \n");
		       sqlstr.append("       A.CONT_AMT,                                        \n");
		       sqlstr.append("       A.ACT_AMT,                                        \n");
		       sqlstr.append("       A.ACT_RATE,                                        \n");
		       sqlstr.append("       A.PUR_AMT,                                        \n"); //구매외주 예산 2015.3.4 MKLEE
		       sqlstr.append("       A.DOC_ETC_IN,                                        \n");
		       sqlstr.append("       A.DOC_ETC_OUT,                                        \n");
		       sqlstr.append("       A.BID_MASTER_NM,                                        \n");
		       sqlstr.append("       A.POSTPONE_REASON,                                        \n");
		       sqlstr.append("       A.CANCEL_REASON,                                        \n");
		       sqlstr.append("       A.CURRENCY_GB_YN,                                        \n");
		       sqlstr.append("       A.DELIVERY_CONDITION_YN,                                        \n");
		       //sqlstr.append("       A.EXCHANGE                                        \n");
		       sqlstr.append("       TO_CHAR(B.SUPP_REQ_DY,'YYYY-MM-DD') AS SUPP_REQ_DY,                                        \n");
		       sqlstr.append("       B.EVAL_EMPNM,                                        \n");
		       sqlstr.append("       B.EVAL_EMPID,                                        \n");
		       sqlstr.append("       A.OUT_ITEM_CD,                                        \n");
		       sqlstr.append("       GET_OUT_ITEM_NM(A.OUT_ITEM_CD) AS OUT_ITEM_NM,						\n");
		       sqlstr.append("       A.PBC_DEFECT_CONDI2,			\n");
		       sqlstr.append("       A.PBC_DEFECT_CONDI,			\n");
		       sqlstr.append("       A.CBC_DERECT_TERM_CD,			\n");
		       sqlstr.append("       A.CBC_DERECT_TERM_CD2,			\n");
		       sqlstr.append("       F_GET_CODE_NAME('CBC_DERECT_TERM_CD',A.CBC_DERECT_TERM_CD) AS CBC_DERECT_TERM_NM,			\n");
		       sqlstr.append("       A.CBC_DEFECT_DAY,				\n");
		       sqlstr.append("       A.CBC_DEFECT_DAY2,				\n");
		       sqlstr.append("       A.WARR_RATE,				\n");
		       sqlstr.append("       A.WARR_CONDI,				\n");
		       sqlstr.append("       A.CONTFUL_RATE,				\n");
		       sqlstr.append("       A.CONTFUL_CONDI,			\n");
		       sqlstr.append("       A.PBC_FRSTGUAR_RATE,			\n");
		       sqlstr.append("       A.PBC_FRSTGUAR_CONDI,			\n");
		       sqlstr.append("       A.PBC_REST_RATE,				\n");
		       sqlstr.append("       A.PBC_REST_CONDI,				\n");
		       sqlstr.append("       A.CPC_MID_RATE,				\n");
		       sqlstr.append("       A.PBC_MID_CONDI,				\n");
		       sqlstr.append("       A.CBC_FIRST_RATE,				\n");
		       sqlstr.append("       A.PBC_FIRST_CONDI,			\n");
		       sqlstr.append("       A.CBC_DAMAGE_RATE,			\n");
		       sqlstr.append("       A.CBC_DAMAGE_MAXRATE,			\n");
		       sqlstr.append("       A.CBC_DAMAGE_CD,			\n");
		       sqlstr.append("       A.PBC_OPTION_COMMENT,			\n");
		       sqlstr.append("       A.PBC_OPTION_YN,				\n");
		       sqlstr.append("       A.PBC_FEE_YN,				\n");
		       sqlstr.append("       A.DELIVERY_CONDITION,			\n");
		       sqlstr.append("       A.DELIVERY_CONDITION_YN,			\n");
		       sqlstr.append("       A.PBC_LANDTRAN_YN,			\n");
		       sqlstr.append("       A.PBC_PACK_YN,				\n");
		       sqlstr.append("       A.PBC_DOC_YN,				\n");
		       sqlstr.append("       A.PBC_TEST_YN,				\n");
		       sqlstr.append("       A.PBC_SPETOOL_YN,				\n");
		       sqlstr.append("       A.PBC_COMMISS_YN,				\n");
		       sqlstr.append("       A.PBC_INSTALL_YN,				\n");
		       sqlstr.append("       A.PBC_CBE_TYPE_CD,			\n");
		       sqlstr.append("       NVL(A.DIV_PO_YN,'N') AS DIV_PO_YN,							\n");
		       sqlstr.append("       A.MATERIAL_GB,															\n");
		       sqlstr.append("       A.PAY_DIV,																\n");
		       sqlstr.append("       C.NEW_DEMANDED_ID,												\n");
		       sqlstr.append("       DECODE(C.CNT,0,'N','','N',NULL,'N','Y') AS FOR_PO_YN,		\n");
		       sqlstr.append("       C.OUTER_REMARKS AS PO_OUTER_REMARKS,					\n");
		       sqlstr.append("       C.INNER_REMARKS AS PO_INNER_REMARKS,						\n");
		       sqlstr.append("       C.FILE_GB_IN,															\n");
		       sqlstr.append("       C.FILE_GB_OUT,															\n");
		       sqlstr.append("       DECODE(A.STATUS_CD, '20', A.REBID_REASON, '25', A.REBID_REASON, '30', A.REBID_REASON, '')  AS REBID_REASON,															\n");
		       sqlstr.append("       DECODE(A.STATUS_CD, '20', A.REBID_OUTREASON, '25', A.REBID_OUTREASON, '30', A.REBID_OUTREASON, '')  AS REBID_OUTREASON,															\n");
		       sqlstr.append("       A.MAIN_PR_CONTENTS, -- 주요발주내용							\n");
		       sqlstr.append("       A.BID_SUPP_SELECT_REASON, -- 입찰업체선정사유					\n");
		       sqlstr.append("       (SELECT DETAILCD FROM EBID_COM911T WHERE BASECD = 'REPORTER_LIST' AND CHG_CODE01 = 'PUR' AND DETAILSORTNM = 1) AS PUR_LEADER	\n");
		       sqlstr.append("        FROM BID_MASTER A  , TBE_INFO B ,							 \n");
		       sqlstr.append("       (SELECT * FROM PMM_DEMANDED_REQUEST A 				\n");
		       sqlstr.append("       ,(SELECT DEMANDED_NO AS D_NO									\n");
		       sqlstr.append("       ,MAX(DEMANDED_ID) AS NEW_DEMANDED_ID 					\n");
		       sqlstr.append("       ,COUNT(DEMANDED_ID) CNT 										 \n");
		       sqlstr.append("       FROM PMM_DEMANDED_REQUEST 									 \n");
		       sqlstr.append("       WHERE PR_TYPE='20' 													 \n");
		       sqlstr.append("       AND NVL(EBID_STATUS_CD,'01')='01'								 \n"); 
		       sqlstr.append("       GROUP BY DEMANDED_NO) B 										 \n");
		       sqlstr.append("       WHERE A.DEMANDED_ID = B.NEW_DEMANDED_ID) C 			 \n");
		       sqlstr.append("       WHERE A.BID_NO = '"+params.get("BID_NO")+"'				\n");
		       sqlstr.append("       AND A.BID_DEG = '"+params.get("BID_DEG")+"'					\n");
		       sqlstr.append("       AND A.BID_NO = B.BID_NO(+)										\n");
			   sqlstr.append("       AND A.BID_DEG = B.BID_DEG(+)									\n");
			   sqlstr.append("       AND A.DEMANDED_NO = C.DEMANDED_NO(+)					\n");
			   sqlstr.append("  	  AND A.DEMANDED_KIND IN ('C','P','B')	       						\n");
        	search.setStatement(sqlstr.toString());
            rowSet = search.execute();
            if( rowSet != null && rowSet.size() > 0 ){
            	valueobject = RowSetUtility.getValueObject(rowSet.getRow(0));
            }
        }
        catch(WAFSQLException se) {
        	super.doException(se);
            this.storage.setSuccess(false);
            this.storage.setMessage(se.getMessage());
            storage.setDetailMessage(se);
        }
        finally {

        	if( valueobject == null ) valueobject = new ValueObject();
            return valueobject;
        }
	}
	
	/**
	 * 발주의뢰(외주) 접수 상세를 검색하여 리턴
	 * @param Params
	 * @return
	 */
	private ValueObject getOrderReqeustValueObject2(String DEMANDED_ID) {

		Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        ValueObject valueobject = null;
     //   String sqlstr = "";
        StrBuffer sqlstr = new StrBuffer();
        try{
            	sqlstr.append("       SELECT TO_CHAR(TO_DATE(A.DEMANDED_DATE,'YYYYMMDD'),'YYYY-MM-DD') AS DEMANDED_DATE,                                        \n");
		       sqlstr.append("       A.DEMANDED_TITLE,                                        \n");
		       sqlstr.append("       A.DEMANDED_KIND,                                        \n");
		       sqlstr.append("       A.CURRENCY_GB,                                        \n");
		       sqlstr.append("       A.DEPT_CD,                                        \n");
		       sqlstr.append("       A.EMP_NO,                                        \n");
		       sqlstr.append("       GET_USER_BUSEO_NM(A.EMP_NO) AS BUSEO_NM,                                          \n");
		       sqlstr.append("       A.DELIVERY_CONDITION,                                        \n");
		       sqlstr.append("       A.CRE_BY,                                        \n");
		       sqlstr.append("       A.CRE_DATE,                                        \n");
		       sqlstr.append("       A.UPD_BY,                                        \n");
		       sqlstr.append("       A.UPD_DATE,                                        \n");
		       sqlstr.append("       A.DEMANDED_NO,                                        \n");
		       sqlstr.append("       A.BID_APP_DATE,                                        \n");
		       sqlstr.append("       A.BID_APP_NO,                                        \n");
		       sqlstr.append("       A.PAY_ITEM,                                        \n");
		       sqlstr.append("       F_GET_PAY_ITEM_VIEW(A.PAY_ITEM,A.COST_CODE,A.COST_TYPE,A.DEPT_CD) AS PAY_ITEM_NM,                \n");
		       sqlstr.append("       A.COST_CODE,                                        \n");
		       sqlstr.append("       A.COST_TYPE,                                        \n");
		       sqlstr.append("       TO_CHAR(A.RECEIPT_DATE,'YYYY-MM-DD') AS RECEIPT_DATE,                                        \n");
		       sqlstr.append("       A.SITEDESC_FLAG,                                    \n");
		       sqlstr.append("       A.SITEDESCCHRGPRSNID,                                        \n");
		       sqlstr.append("       F_GET_USER_NM(A.SITEDESCCHRGPRSNID) AS SITEDESCCHRGPRSNNM,                                        \n");
		       sqlstr.append("       A.SITEDESCTELNO,                                        \n");
		       sqlstr.append("       TO_CHAR(A.SITEDESCDATE,'YYYY-MM-DD HH24:MI') AS SITEDESCDATE,                                        \n");
		       sqlstr.append("       TO_CHAR(A.SITEDESCDATE,'YYYY-MM-DD') AS SITEDESCDT,                                        \n");
		       sqlstr.append("       A.SITEDESCPLACE,                                        \n");
		       sqlstr.append("       A.SITEDESCEMAIL,                                        \n");
		       sqlstr.append("       A.PUREMPNO,                                        \n");
		       sqlstr.append("       F_GET_USER_NM(A.PUREMPNO) AS PUREMPNM,                                        \n");
		       sqlstr.append("       A.INNER_REMARKS,                                        \n");
		       sqlstr.append("       A.TBE_FLAG,                                    	   \n");
		       sqlstr.append("       A.OUTER_REMARKS,                                        \n");
		       sqlstr.append("       A.DEMANDED_ID,                                        \n");
		       sqlstr.append("       TO_CHAR(A.REQUEST_DATE,'YYYY-MM-DD') AS REQUEST_DATE,                                        \n");
		       sqlstr.append("       A.ATT_ID,                                        \n");
		       sqlstr.append("       A.BID_NO,                                        \n");
		       sqlstr.append("       A.BID_DEG,                                        \n");
		       sqlstr.append("       F_GET_CODE_NAME('ONBID',ONBID_YN) AS ONBID_YN,                                       \n");
		       sqlstr.append("       F_GET_CODE_NAME('CMPT_CD',A.CMPT_CD) AS CMPT_NM,                                        \n");
		       sqlstr.append("       A.CMPT_CD,                                        \n");
		       sqlstr.append("       F_GET_CODE_NAME('SUCC_CD',A.SUCC_CD) AS SUCC_NM,                                        \n");
		       sqlstr.append("       A.SUCC_CD,                                        \n");
		       sqlstr.append("       TO_CHAR(TO_DATE(A.NOTI_DY,'YYYYMMDD'),'YYYY-MM-DD') AS NOTI_DY,                                        \n");
		       sqlstr.append("       A.SITEDESC_CRG_NM,                                        \n");
		       sqlstr.append("       TO_CHAR(A.BID_FROM_DT,'YYYY-MM-DD') AS BID_FROM_DT,                                        \n");
		       sqlstr.append("       TO_CHAR(A.BID_FROM_DT,'HH24') AS BID_FROM_HH,                                        \n");
		       sqlstr.append("       TO_CHAR(A.BID_FROM_DT,'MI') AS BID_FROM_MI,                                        \n");
		       sqlstr.append("       TO_CHAR(A.BID_TO_DT,'YYYY-MM-DD') AS BID_TO_DT,                                        \n");
		       sqlstr.append("       TO_CHAR(A.BID_TO_DT,'HH24') AS BID_TO_HH,                                        \n");
		       sqlstr.append("       TO_CHAR(A.BID_TO_DT,'MI') AS BID_TO_MI,                                        \n");
		       sqlstr.append("       A.PO_EMPNM,                                        \n");
		       sqlstr.append("       A.OPEN_EMPNM,                                        \n");
		       sqlstr.append("       A.OPEN_EMPID,                                        \n");
		       sqlstr.append("       TO_CHAR(TO_DATE(A.DELI_FROM_DY,'YYYYMMDD'),'YYYY-MM-DD') AS DELI_FROM_DY,                                        \n");
		       sqlstr.append("       TO_CHAR(TO_DATE(A.DELI_TO_DY,'YYYYMMDD'),'YYYY-MM-DD') AS DELI_TO_DY,                                        \n");
		       sqlstr.append("       A.DELIVERY_PLACE,                                        \n");
		       sqlstr.append("       A.CONTFUL_RATE,                                        \n");
		       sqlstr.append("       A.CONTFUL_CONDI,                                        \n");
		       sqlstr.append("       A.WARR_RATE,                                        \n");
		       sqlstr.append("       A.WARR_CONDI,                                        \n");
		       sqlstr.append("       A.DEPT_NM,                                        \n");
		       sqlstr.append("       A.REQ_DEPT_CD,                                        \n");
		       sqlstr.append("       A.REQ_DEPT_NM,                                        \n");
		       sqlstr.append("       A.EMP_NM,                                        \n");
		       sqlstr.append("       A.STATUS_CD,                                        \n");
		       sqlstr.append("       A.OPEN_DT,                                        \n");
		       sqlstr.append("       A.CONT_APP_DATE,                                        \n");
		       sqlstr.append("       A.CONT_APP_NO,                                        \n");
		       sqlstr.append("       A.CONT_AMT,                                        \n");
		       sqlstr.append("       A.ACT_AMT,                                        \n");
		       sqlstr.append("       A.ACT_RATE,                                        \n");
		       sqlstr.append("       A.DOC_ETC_IN,                                        \n");
		       sqlstr.append("       A.DOC_ETC_OUT,                                        \n");
		       sqlstr.append("       REPLACE(A.BID_MASTER_NM,'[재입찰]','') AS BID_MASTER_NM,                                        \n");
		       sqlstr.append("       A.POSTPONE_REASON,                                        \n");
		       sqlstr.append("       A.CANCEL_REASON,                                        \n");
		       sqlstr.append("       A.CURRENCY_GB_YN,                                        \n");
		       sqlstr.append("       A.DELIVERY_CONDITION_YN,                                        \n");
		       //sqlstr.append("       A.EXCHANGE                                        \n");
		       sqlstr.append("       TO_CHAR(B.SUPP_REQ_DY,'YYYY-MM-DD') AS SUPP_REQ_DY,                                        \n");
		       sqlstr.append("       B.EVAL_EMPNM,                                        \n");
		       sqlstr.append("       B.EVAL_EMPID,                                        \n");
		       sqlstr.append("       GET_OUT_ITEM_NM(A.OUT_ITEM_CD) AS OUT_ITEM_NM						\n");
		       sqlstr.append("        FROM BID_MASTER A  , TBE_INFO B                                      \n");
		       sqlstr.append("       WHERE A.BID_NO = '"+params.get("BID_NO")+"'							\n");
		       sqlstr.append("       AND A.BID_DEG = '"+params.get("BID_DEG")+"'							\n");
		       sqlstr.append("       AND A.BID_NO = B.BID_NO(+)							\n");
			   sqlstr.append("       AND A.BID_DEG = B.BID_DEG(+)							\n");
			   sqlstr.append("  	  AND A.DEMANDED_KIND IN ('C','P','B')	       																									\n");

        	search.setStatement(sqlstr.toString());
            rowSet = search.execute();
            if( rowSet != null && rowSet.size() > 0 ){
            	valueobject = RowSetUtility.getValueObject(rowSet.getRow(0));
            }
        }
        catch(WAFSQLException se) {
        	super.doException(se);
            this.storage.setSuccess(false);
            this.storage.setMessage(se.getMessage());
            storage.setDetailMessage(se);
        }
        finally {

        	if( valueobject == null ) valueobject = new ValueObject();
            return valueobject;
        }
	}
	
	/**
	 * 발주의뢰(외주) 접수 상세 / 견적대상업체 를 검색하여 리턴
	 * @param Params
	 * @return
	 */
	private RowSet getCorpList(String DEMANDED_ID) {

		Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        
     //   String sqlstr = "";
        StrBuffer sqlstr = new StrBuffer();
        try{
        	sqlstr.append(" SELECT A.BID_NO,										\n");
        	sqlstr.append("        A.BID_DEG,											\n");
        	sqlstr.append("        A.VENDOR_CD,										\n");
        	sqlstr.append("        A.VENDOR_NO,										\n");
        	sqlstr.append("        A.VENDOR_NAME,									\n");
        	sqlstr.append("        A.REPRE_NO,										\n");
        	sqlstr.append("        A.CHARGE_NAME,									\n");
        	sqlstr.append("        A.CHAGE_HP,										\n");
        	sqlstr.append("        A.CHARGE_EMAIL,									\n");
        	sqlstr.append("        A.CURRENCY_GB,									\n");
        	sqlstr.append("        A.EXCHANGE,										\n");
        	sqlstr.append("        A.DELIVERY_CONDITION,						\n");
        	sqlstr.append("        A.SITEPARTI_YN,									\n");
        	sqlstr.append("        NVL(A.SITE_ATTEND_YN,'NULL') AS SITE_ATTEND_YN,					\n");
        	sqlstr.append("        A.TBEAPPR_YN,									\n");
        	sqlstr.append("        A.TBEEVALUATE_YN,								\n");
        	sqlstr.append("        A.CERT_DN,											\n");
        	sqlstr.append("        A.ESTI_SIGNDATA,								\n");
        	sqlstr.append("        A.ATT_ID,											\n");
        	sqlstr.append("        A.RECM_DEPT_ID,									\n");
        	sqlstr.append("        A.RECM_DEPT_NM,								\n");
        	sqlstr.append("        A.RECM_EMPID,									\n");
        	sqlstr.append("        A.RECOMMEND_REASON,						\n");
        	sqlstr.append("        F_GET_D_CURRENCY(A.ESTI_TOT_AMT,F_GET_CURRENCY_DIGIT(B.CURRENCY_GB)) AS ESTI_TOT_AMT,								\n");
        	//sqlstr.append("        ROUND((A.ESTI_TOT_AMT/(SELECT ACT_AMT FROM  BID_MASTER WHERE BID_NO = A.BID_NO AND BID_DEG = A.BID_DEG) * 100),1) AS ESTI_TOT_RATE,								\n");
        	sqlstr.append("        DECODE(NVL(C.ACT_AMT, 0), 0, 0, ROUND((A.ESTI_TOT_AMT/C.ACT_AMT * 100),1)) AS ESTI_TOT_RATE,      							\n");
        	sqlstr.append("        A.WON_ESTI_TOT_AMT,						\n");
        	sqlstr.append("        A.SUCC_YN,										\n");
        	sqlstr.append("        A.FIB_REASON,									\n");
        	sqlstr.append("        A.DISQ_REASON,									\n");
        	sqlstr.append("        A.CRE_BY,										\n");
        	sqlstr.append("        A.CRE_DATE,										\n");
        	sqlstr.append("        A.UPD_BY,										\n");
        	sqlstr.append("        A.UPD_DATE,										\n");
        	sqlstr.append("        D.APPR_TOT_RATE,									\n");
        	sqlstr.append("        D.VALID_BID_YN,  								\n");
        	sqlstr.append("		   DECODE(D.VALID_BID_YN,'Y','입찰가능','N','입찰불가','미평가') AS VALID_BID_YN_NM 		\n");
        	sqlstr.append("   FROM BID_SUPP A, BID_PUR_CONDI B	,BID_MASTER C		\n");  //2015.12.17 실행금액 없는경우 오류수정 
        	sqlstr.append("		  ,(SELECT CORP_ID, MAX(APPR_TOT_RATE) AS APPR_TOT_RATE , MAX(APPR_DY) APPR_DY, MAX(ARR_ID) ARR_ID, DOC_CD,VALID_BID_YN    	\n");
            sqlstr.append("	          FROM SUPP_APPR 																							\n");
			sqlstr.append("	         WHERE DOC_CD IN ('01', '02')  AND (CORP_ID,ARR_ID) IN (SELECT CORP_ID,MAX(ARR_ID)             	        	\n");
			sqlstr.append("                                                                   FROM SUPP_APPR                     				\n");
			sqlstr.append("                                                                  WHERE DOC_CD IN ('01', '02')        				\n");
			sqlstr.append("                                                                  GROUP BY CORP_ID)                   				\n");
			sqlstr.append("          GROUP BY CORP_ID, DOC_CD,VALID_BID_YN ) D            	                                             		\n");
        	sqlstr.append(" WHERE A.BID_NO = '"+params.get("BID_NO")+"'			\n");
        	sqlstr.append(" AND A.BID_DEG = '"+params.get("BID_DEG")+"'			\n");
        	sqlstr.append(" AND A.BID_NO = B.BID_NO(+)							\n");
        	sqlstr.append(" AND A.BID_DEG = B.BID_DEG(+)						\n");
        	sqlstr.append(" AND A.VENDOR_CD = B.VENDOR_CD(+)					\n");
        	sqlstr.append(" AND A.BID_NO = C.BID_NO								\n");
        	sqlstr.append(" AND A.BID_DEG = C.BID_DEG							\n");
        	sqlstr.append(" AND A.VENDOR_CD = D.CORP_ID(+)						\n");
        	sqlstr.append(" ORDER BY A.ESTI_TOT_AMT ASC							\n");
			
			search.setStatement(sqlstr.toString());
            rowSet = search.execute();
        }
        catch (WAFSQLException se) {
            super.doException(se);
            this.storage.setSuccess(false);
            this.storage.setMessage(se.getMessage());
            storage.setDetailMessage(se);
        }
        finally {    
            if(rowSet == null){
            	rowSet = new RowSetImpl();
            }
        }
        
        return rowSet;
	}
	
	/**
	 * 입찰내역 리스트 조회
	 * @param Params
	 * @return
	 */
	private RowSet getitemList(ValueObject param) {
		Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        StrBuffer sqlstr = new StrBuffer();
        try{
        	sqlstr.append("    SELECT A.BID_NO,          \n");
        	sqlstr.append("           A.BID_DEG,          \n");
        	sqlstr.append("           A.MATERIAL_CD,          \n");
        	sqlstr.append("           TO_CHAR(TO_DATE(A.REQUEST_DATE,'YYYYMMDD'),'YYYY-MM-DD') AS REQUEST_DATE,          \n");
        	sqlstr.append("           A.CONT_UNIT_AMT,          \n");
        	sqlstr.append("           A.ACT_UNIT_AMT,          \n");
        	sqlstr.append("           A.DEMANDED_PRI,          \n");
        	sqlstr.append("           A.DEMANDED_QTY,          \n");
        	sqlstr.append("           A.STD,          \n");
        	sqlstr.append("           B.MATERIAL_NAME,          \n");
        	sqlstr.append("           F_GET_UNIT_KIND_NAME(A.MATERIAL_CD) AS UNIT_KIND          \n");
        	sqlstr.append("      FROM BID_ITEM A , PMM_COMM_MATERIAL_MASTER B          \n");
        	sqlstr.append("      WHERE A.MATERIAL_CD = B.MATERIAL_CD          \n");
        	sqlstr.append("        AND A.BID_NO = ?																														\n");
        	sqlstr.append("        AND A.BID_DEG = ?																														\n");	
        	sqlstr.append("        ORDER BY A.MATERIAL_CD																												\n");
			search.setStatement(sqlstr.toString());
			search.addParameter(param.get("BID_NO"));
			search.addParameter(param.get("BID_DEG"));
			
			System.out.println(sqlstr.toString());
			System.out.println(search.getParameters());
            rowSet = search.execute();
        }catch (WAFSQLException se) {
            super.doException(se);
            this.storage.setSuccess(false);  
            this.storage.setMessage(se.getMessage());
            storage.setDetailMessage(se);
        }finally{    
            if(rowSet == null)rowSet = new RowSetImpl();
        }
        return rowSet;
	}
	
	/**
	 * 입찰내역 리스트 조회
	 * @param Params
	 * @return
	 */
	private RowSet geforPo_itemList(ValueObject param) {
		Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        StrBuffer sqlstr = new StrBuffer();
        try{
        	/* 2018.10.25 소경준 주임 요청 수정 . 이전차수와 비교.
        	sqlstr.append("   SELECT A1.BID_NO                                                                                                            \n");
        	sqlstr.append("        ,A1.BID_DEG                                                                                                            \n");
        	sqlstr.append("        ,A1.DEMANDED_NO                                                                                                        \n");
        	sqlstr.append("        ,A1.MATERIAL_CD                                                                                                        \n");
        	sqlstr.append("        ,A1.CONT_UNIT_AMT   --  입찰_내역.도급단가                                                                             \n");
        	sqlstr.append("        ,A1.ACT_UNIT_AMT    --  입찰_내역.실행단가                                                                             \n");
        	sqlstr.append("        ,A1.BID_DEM_PRI--  입찰내역.발주의뢰 단가                                                                              \n");
        	sqlstr.append("        ,A1.BID_DEM_QTY --  입찰내역.발주의뢰 수량                                                                             \n");
        	sqlstr.append("        ,A1.CONT_PRI    --  도급단가                                                                                           \n");
        	sqlstr.append("        ,A1.DEMANDED_PRI    --  실행단가                                                                                       \n");
        	sqlstr.append("        ,A1.DEMANDED_QTY   --  수량                                                                                            \n");
        	sqlstr.append("        ,A1.CHG_MOD_CD                                                                                                         \n");
        	sqlstr.append("        ,A1.STD                                                                                                                \n");
        	sqlstr.append("        ,F_GET_MATERIAL_NAME(a1.MATERIAL_cd) as material_name                                                                  \n");
        	sqlstr.append("        ,F_GET_UNIT_KIND_NAME(A1.MATERIAL_CD) AS UNIT_KIND                                                                     \n");
        	sqlstr.append("        ,F_GET_MATL_SPEC_NAME(a1.material_cd) as MATERIAL_SPEC                                                                 \n"); 
        	sqlstr.append("        FROM(                                                                                                                  \n");
        	sqlstr.append("        SELECT NVL(X.BID_NO,?) BID_NO                                                                \n");
        	sqlstr.append("        ,NVL(X.BID_DEG, ?) BID_DEG                                                                                           \n");
        	sqlstr.append("        ,NVL(X.DEMANDED_NO,Y.DEMANDED_NO) DEMANDED_NO                                                                          \n");
        	sqlstr.append("        ,NVL(X.MATERIAL_CD,Y.MATERIAL_CD) MATERIAL_CD                                                                          \n");
        	sqlstr.append("        ,NVL(X.CONT_UNIT_AMT,0) AS CONT_UNIT_AMT   --  입찰_내역.도급단가                                                      \n");          
        	sqlstr.append("        ,NVL(X.ACT_UNIT_AMT,0)  AS ACT_UNIT_AMT   --  입찰_내역.실행단가                                                       \n");         
        	sqlstr.append("        ,NVL(X.DEMANDED_PRI,0)    BID_DEM_PRI--  입찰내역.발주의뢰 단가                                                        \n");        
        	sqlstr.append("        ,NVL(X.DEMANDED_QTY,0)   BID_DEM_QTY --  입찰내역.발주의뢰 수량                                                        \n");        
        	sqlstr.append("        ,NVL(X.STD, '-') AS STD    --  규격                                                                                    \n");
        	sqlstr.append("        ,Y.CONT_PRI    --  도급단가                                                                                            \n");
        	sqlstr.append("        ,Y.DEMANDED_PRI    --  실행단가                                                                                        \n");
        	sqlstr.append("        ,Y.DEMANDED_QTY   --  수량                                                                                             \n");
        	sqlstr.append("        ,CASE WHEN X.BID_NO IS NULL THEN 'INSERT'                                                                              \n");
        	sqlstr.append("                  WHEN Y.DEMANDED_NO IS NULL THEN 'DELETE'                                                                     \n");
        	sqlstr.append("                  WHEN Y.DEMANDED_NO IS NOT NULL AND Y.DEMANDED_NO IS NOT NULL THEN 'UPDATE'                                   \n");                             
        	sqlstr.append("           END CHG_MOD_CD                                                                                                      \n");
        	sqlstr.append("        FROM (SELECT B.DEMANDED_NO                                                                                             \n");
        	sqlstr.append("           ,A.*                                                                                                                \n");
        	sqlstr.append("        FROM BID_ITEM A                                                                                                        \n");
        	sqlstr.append("          ,BID_MASTER B                                                                                                        \n");
        	sqlstr.append("        WHERE A.BID_NO = B.BID_NO                                                                                              \n");
        	sqlstr.append("        AND A.BID_DEG = B.BID_DEG) X                                                                                           \n");
        	sqlstr.append("        FULL OUTER JOIN (SELECT B.DEMANDED_NO                                                                                  \n");
        	sqlstr.append("                    ,A.*                                                                                                       \n");
        	sqlstr.append("         FROM PMM_DEMANDED_ITEM A                                                                                              \n");
        	sqlstr.append("                  ,(SELECT DEMANDED_NO, MAX(DEMANDED_ID) DEMANDED_ID                                                           \n");     
        	sqlstr.append("         FROM PMM_DEMANDED_REQUEST                                                                                             \n");
        	sqlstr.append("          WHERE PR_TYPE = '20'                                                                                                 \n");
        	sqlstr.append("         AND NVL(EBID_STATUS_CD,'01') = '01'                                                                                   \n");
        	sqlstr.append("          GROUP BY DEMANDED_NO) B                                                                                              \n");
        	sqlstr.append("          WHERE A.DEMANDED_ID = B.DEMANDED_ID                                                                                  \n");
        	sqlstr.append("          ) Y  ON X.DEMANDED_NO = Y.DEMANDED_NO AND X.MATERIAL_CD = Y.MATERIAL_CD                                              \n");                  
        	sqlstr.append("         WHERE Y.DEMANDED_NO = ?                                                                         \n");
        	sqlstr.append("          ) A1																																																									\n");
        	*/
        	sqlstr.append(" SELECT A.BID_NO                                                                         \n");                        
        	sqlstr.append("       ,A.MATERIAL_CD                                                                    \n");                          
            sqlstr.append("       ,B.CONT_UNIT_AMT B_CONT_UNIT                                                      \n");                         
            sqlstr.append("       ,B.ACT_UNIT_AMT  B_ACT_UNIT                                                       \n");                    
            sqlstr.append("       ,B.DEMANDED_QTY  B_QTY                                                            \n");                    
            sqlstr.append("       ,NVL(C.CONT_UNIT_AMT, D.CONT_PRI )    C_CONT_UNIT                                 \n");                  
            sqlstr.append("       ,NVL(C.ACT_UNIT_AMT, D.DEMANDED_PRI)  C_ACT_UNIT                                  \n");
            sqlstr.append("       ,NVL(C.DEMANDED_QTY, D.DEMANDED_QTY)  C_QTY                                       \n");
            sqlstr.append("       ,A.STD                                                                            \n");
            sqlstr.append("       ,F_GET_MATERIAL_NAME(A.MATERIAL_CD) as MATERIAL_NAME                             \n");
            sqlstr.append("       ,F_GET_UNIT_KIND_NAME(A.MATERIAL_CD) AS UNIT_KIND                                \n");
            sqlstr.append("       ,F_GET_MATL_SPEC_NAME(A.MATERIAL_CD) as MATERIAL_SPEC                            \n");
            sqlstr.append("   FROM (SELECT BID_NO                                                                   \n");
            sqlstr.append("               ,MATERIAL_CD                                                              \n");
            sqlstr.append("               ,MAX(STD) STD                                                             \n");
            sqlstr.append("           FROM BID_ITEM                                                                 \n");
            sqlstr.append("          WHERE BID_NO = ?                                                               \n");
            sqlstr.append("           GROUP BY BID_NO, MATERIAL_CD) A                                               \n");
            sqlstr.append("        ,BID_ITEM B                                                                      \n");
            sqlstr.append("        ,BID_ITEM C                                                                      \n");
            sqlstr.append("        ,( SELECT A.*                                                                    \n");
            sqlstr.append("             FROM PMM_DEMANDED_ITEM A                                                    \n");
            sqlstr.append("                ,(SELECT MAX(A.DEMANDED_ID) DEMANDED_ID                                  \n");
            sqlstr.append("                    FROM PMM_DEMANDED_REQUEST A                                          \n");
            sqlstr.append("                        ,BID_MASTER B                                                    \n");
            sqlstr.append("                   WHERE A.DEMANDED_NO = B.DEMANDED_NO                                   \n");
            sqlstr.append("                     AND B.BID_NO = ?                                                    \n");
            sqlstr.append("                     AND PR_TYPE = '20' ) B                                              \n");
            sqlstr.append("            WHERE A.DEMANDED_ID = B.DEMANDED_ID                                          \n");
            sqlstr.append("         )D                                                                              \n");
            sqlstr.append("  WHERE A.BID_NO = B.BID_NO(+)                                                           \n");
            sqlstr.append("    AND A.MATERIAL_CD = B.MATERIAL_CD(+)                                                 \n");
            sqlstr.append("    AND A.BID_NO = C.BID_NO(+)                                                           \n");
            sqlstr.append("    AND A.MATERIAL_CD = C.MATERIAL_CD(+)                                                 \n");
            sqlstr.append("    AND A.MATERIAL_CD = D.MATERIAL_CD(+)                                                 \n");
            sqlstr.append("    AND B.BID_DEG(+) = ?                                                                 \n");
            sqlstr.append("    AND C.BID_DEG(+) = ?                                                                 \n");
                           	
        	
			search.setStatement(sqlstr.toString());
			search.addParameter(param.get("BID_NO"));
			search.addParameter(param.get("BID_NO"));
			search.addParameter(Integer.parseInt(param.get("BID_DEG"))-1);
			search.addParameter(param.get("BID_DEG"));
			
			System.out.println("***************6");
			System.out.println(sqlstr.toString());
			System.out.println(search.getParameters());
			
            rowSet = search.execute();
        }catch (WAFSQLException se) {
            super.doException(se);
            this.storage.setSuccess(false);  
            this.storage.setMessage(se.getMessage());
            storage.setDetailMessage(se);
        }finally{    
            if(rowSet == null)rowSet = new RowSetImpl();
        }
        return rowSet;
	}
	
	
}