/**
 * @(#)file    ContChgRcvBiz.java
 * @(#)author  kyj
 * @(#)version 1.0
 * @(#)date    2015-01-22
 * @(#)since   JDK 1.4.2
 */
package kr.co.udapsoft.ebid.buyer.cont.purchase.biz;


import java.sql.Connection;

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.ebid.buyer.common.file.FileManager;

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


   
public class ContChgRcvBiz extends Biz {

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

	public void doBiz() throws Exception {
        ValueObject user = new ValueObject();
        //WAFLogger.debug("BidIngListBiz :  ~" + storage.getUser());

		boolean success = false;
		
		if(storage.compareEvent("")){
			
		}else if(storage.compareEvent("FORM_SELECT")){
            user = getContChgRcvValueObject(params.get("PUR_CONT_MOD_ID"));//2016.03.10
            storage.addValueObject("ContInfo", user);
            
            RowSet getFileListRowSet = getFileListRowSet("PUR_CONTCHGFILE_GB_"+params.get("PUR_CONT_MOD_ID"), "");
            storage.addRowSet("getFileListRowSet", getFileListRowSet);
            
            ValueObject suppinfo = getSuppInfo(user.get("BID_NO"),user.get("BID_DEG"), user.get("VENDOR_CD"));	//입찰 업체 정보 조회
            storage.addValueObject("suppinfo", suppinfo);
            
            storage.addValueObject("SIGN_INFO", getSignInfo(params.get("PUR_CONT_MOD_ID")));
		}else if(storage.compareEvent("FORM_SAVE")){
			success = saveContChgRcvProc(super.conn.getConnection(), params);
			super.storage.setSuccess(success);
			
		}else if(storage.compareEvent("CONT_REJECT")){		//반려 
			ContChgRcvStatusUp(super.conn.getConnection(), params);	
			super.storage.setSuccess(true);
			
		}else if(storage.compareEvent("GET_ATTACHFILE")){
			//첨부파일
			ValueObject AttachFile = getfilelist("PUR_CONT_MOD_ID",params.get("PUR_CONT_MOD_ID"),"AttachFile");
	        storage.addValueObject("VALUEOBJECT", AttachFile);
        }else if(storage.compareEvent("SHEET_SELECT")){
        	params.set("sheet1", getContChgRcvList(params));
			
			storage.addObject("ibsheet7Data", IBSheet7Factory.createIBSheet7(params, storage.request));
        }else if(storage.compareEvent("CONT_CHG_DATA")){
        	
        	success = saveContChg(params);
        }else if(storage.compareEvent("DUP_CHK")){
			//첨부파일
        	ValueObject dupCnt = getDupCnt(params.get("PUR_CONT_MOD_ID"), params.get("PUR_CONT_MOD_ID"));
	        storage.addValueObject("VALUEOBJECT", dupCnt);
        }else if(storage.compareEvent("GET_CONT_CHG_ATTACHFILE")){
			//첨부파일
			ValueObject AttachFile = getContChgfilelist("AttachFile");
	        storage.addValueObject("VALUEOBJECT", AttachFile);
        }		
	}
	
	
	/**
	 * 계약 상세 정보
	 * @param Params
	 * @return
	 */
	private ValueObject getContChgRcvValueObject(String DEMANDED_ID) {
		
		Search search = new SearchImpl();
		RowSet rowSet = new RowSetImpl();
		ValueObject valueobject = null;
		//   String sqlstr = "";
		StrBuffer sqlstr = new StrBuffer();
		try{

			sqlstr.append("	     SELECT A.PUR_CONT_MOD_ID                                                                                                                                             \n");
			sqlstr.append("	          , A.ORD_DOC_NO                                                                                                                                                  \n");
			sqlstr.append("	          , A.MOD_NO                                                                                                                                                      \n");
			sqlstr.append("	          , NVL(A.MOD_GB, '00') AS MOD_GB                                                                                                              \n");
			sqlstr.append("	          , A.DEPT_NAME                                                                                                                                                   \n");
			sqlstr.append("	          , A.CST_DOC_NAME                                                                                                                                                \n");
			sqlstr.append("	          , A.ORD_CON_DATE                                                                                                                                                \n");
			sqlstr.append("	          , A.ORD_AMT                                                                                                                                                     \n");
			sqlstr.append("	          , A.ORD_START_DATE                                                                                                                                              \n");
			sqlstr.append("	          , A.ELEC_CON_YN                                                                                                                                                 \n");
			sqlstr.append("	          , TO_CHAR(A.ORD_START_DATE,'YYYY') AS START_WORK_DATE_YEAR                                                                                                      \n");
			sqlstr.append("	          , TO_CHAR(A.ORD_START_DATE,'MM') AS START_WORK_DATE_MONTH                                                                                                       \n");
			sqlstr.append("	          , TO_CHAR(A.ORD_START_DATE,'DD') AS START_WORK_DATE_DAY                                                                                                         \n");
			sqlstr.append("	          , A.ORD_END_DATE                                                                                                                                                \n");
			sqlstr.append("	          , TO_CHAR(A.ORD_END_DATE,'YYYY') AS END_WORK_DATE_YEAR                                                                                                          \n");
			sqlstr.append("	          , TO_CHAR(A.ORD_END_DATE,'MM') AS END_WORK_DATE_MONTH                                                                                                           \n");
			sqlstr.append("	          , TO_CHAR(A.ORD_END_DATE,'DD') AS END_WORK_DATE_DAY                                                                                                             \n");
			sqlstr.append("	          , A.CON_GB                                                                                                                                                      \n");
			sqlstr.append("	          , A.CURRENCY_GB                                                                                                                                                 \n");
			sqlstr.append("	          , (SELECT CHG_CODE01 FROM EBID_COM911T WHERE BASECD='911' AND DETAILCD=A.CURRENCY_GB) AS SOSUNUM                                                                \n");
			sqlstr.append("	          , TO_CHAR(A.ORD_CON_DATE,'YYYY') AS CON_DATE_YEAR                                                                                                               \n");
			sqlstr.append("	          , TO_CHAR(A.ORD_CON_DATE,'MM') AS CON_DATE_MONTH                                                                                                                \n");
			sqlstr.append("	          , TO_CHAR(A.ORD_CON_DATE,'DD') AS CON_DATE_DAY                                                                                                                  \n");
			sqlstr.append("	          , A.STATUS_CD                                                                                                                                                   \n");
			sqlstr.append("	          , F_GET_CODE_NAME('CONT_STATUS_CD',A.STATUS_CD) AS STATUS_NM                                                                                                    \n");
			sqlstr.append("	          , A.TEMPLATE_CD                                                                                                                                                 \n");
			sqlstr.append("	          , A.TRUE_RANDOM                                                                                                                                                 \n");
			sqlstr.append("	          , A.CONT_HASH                                                                                                                                                   \n");
			sqlstr.append("	          , A.MODI_REQ_REASON                                                                                                                                             \n");
			sqlstr.append("	          , A.MODI_REQ_DT                                                                                                                                                 \n");
			sqlstr.append("	          , B.DEMANDED_NO                                                                                                                                                 \n");
			sqlstr.append("	          , B.DEMANDED_TITLE                                                                                                                                              \n");
			sqlstr.append("	          , TO_CHAR(TO_DATE(B.DEMANDED_DATE),'YYYY-MM-DD') AS DEMANDED_DATE                                                                                               \n");
			sqlstr.append("	          , B.REQ_DEPT_NM                                                                                                                                                 \n");
			sqlstr.append("	          , B.EMP_NO                                                                                                                                                      \n");
			sqlstr.append("	          , B.EMP_NM                                                                                                                                                      \n");
			sqlstr.append("	          , GET_OUT_ITEM_NM(B.OUT_ITEM_CD) AS OUT_ITEM_NM                                                                                                               \n");
			sqlstr.append("	          , A.CON_CONFIRM_ID                                                                                                                                              \n");
			sqlstr.append("	          , A.CON_CONFIRM_NAME                                                                                                                                            \n");
			sqlstr.append("	          , DECODE(D.CORP_ID, '', 0, D.CORP_ID)  AS O_CORP_ID                                                                                                             \n");
			sqlstr.append("	          , DECODE(D.MEMBER_NAME, '', C.CORP_KOR, D.MEMBER_NAME)  AS O_MEMBER_NAME                                                                                        \n");
			sqlstr.append("	          , DECODE(D.ADDRESS, '', C.ADDRESS, D.ADDRESS) AS O_ADDRESS                                                                                                      \n");
			sqlstr.append("	          , DECODE(D.BOSS_NAME, '', C.REP_NAME, D.BOSS_NAME) AS O_BOSS_NAME                                                                                               \n");
			sqlstr.append("	          , DECODE(D.VENDCD, '', C.CORP_REG_NO, D.VENDCD) AS O_REG_NO                                                                                                     \n");
			sqlstr.append("	          , D.USER_NAME AS O_USER_NAME                                                                                                                                    \n");
			sqlstr.append("	          , D.TEL_NUM AS O_TEL_NUM                                                                                                                                        \n");
			sqlstr.append("	          , D.DIVISION AS O_DIVISION                                                                                                                                      \n");
			sqlstr.append("	          , D.POSITION AS O_POSITION                                                                                                                                      \n");
			sqlstr.append("	          , D.HP AS O_HP                                                                                                                                                  \n");
			sqlstr.append("	          , D.EMAIL AS O_EMAIL                                                                                                                                            \n");
			sqlstr.append("	          , TO_CHAR(D.SIGN_DATE,'YYYY-MM-DD HH24:MI:SS') AS O_SIGN_DATE                                                                                                   \n");
			sqlstr.append("	          , D.VENDCD AS O_VENDCD                                                                                                                                          \n");
			sqlstr.append("	          , E.CORP_ID  AS C_CORP_ID                                                                                                                                       \n");
			sqlstr.append("	          , E.MEMBER_NAME AS C_MEMBER_NAME                                                                                                                                \n");
			sqlstr.append("	          , E.ADDRESS AS C_ADDRESS                                                                                                                                        \n");
			sqlstr.append("	          , E.BOSS_NAME AS C_BOSS_NAME                                                                                                                                    \n");
			sqlstr.append("	          , E.USER_NAME AS C_USER_NAME                                                                                                                                    \n");
			sqlstr.append("	          , E.TEL_NUM AS C_TEL_NUM                                                                                                                                        \n");
			sqlstr.append("	          , E.DIVISION AS C_DIVISION                                                                                                                                      \n");
			sqlstr.append("	          , E.POSITION AS C_POSITION                                                                                                                                      \n");
			sqlstr.append("	          , E.HP AS C_HP                                                                                                                                                  \n");
			sqlstr.append("	          , E.VENDCD AS C_VENDCD                                                                                                                                          \n");
			sqlstr.append("	          , E.EMAIL AS C_EMAIL                                                                                                                                            \n");
			sqlstr.append("	          , TO_CHAR(E.SIGN_DATE,'YYYY-MM-DD HH24:MI:SS') AS C_SIGN_DATE                                                                                                   \n");
			sqlstr.append("	          , F_GET_D_CURRENCY(NVL(A.FRST_CON_AMT,0), F_GET_CURRENCY_DIGIT(A.CURRENCY_GB)) AS BEF_CONT_AMT                                                                  \n");
			sqlstr.append("	          , F_GET_D_CURRENCY(NVL(A.CHG_CON_AMT,0), F_GET_CURRENCY_DIGIT(A.CURRENCY_GB)) AS AFT_CONT_AMT                                                                  \n");
			sqlstr.append("	          , F_GET_D_CURRENCY(NVL(A.CHG_CON_AMT,0)-NVL(A.FRST_CON_AMT,0), F_GET_CURRENCY_DIGIT(A.CURRENCY_GB)) AS CHG_CONT_AMT                                                                  \n");
			sqlstr.append("	          , F_GET_D_CURRENCY(NVL(A.FRST_EXE_AMT,0), F_GET_CURRENCY_DIGIT(A.CURRENCY_GB)) AS BEF_BUG_AMT                                                                    \n");
			sqlstr.append("	          , F_GET_D_CURRENCY(NVL(A.CHG_EXE_AMT,0), F_GET_CURRENCY_DIGIT(A.CURRENCY_GB)) AS AFT_BUG_AMT                                                                    \n");
			sqlstr.append("	          , F_GET_D_CURRENCY(NVL(A.CHG_EXE_AMT,0)-NVL(A.FRST_EXE_AMT,0), F_GET_CURRENCY_DIGIT(A.CURRENCY_GB)) AS CHG_BUG_AMT                                                                    \n");
			sqlstr.append("	            , CASE WHEN NVL(A.CHG_CON_AMT,0) > 0 THEN '도급대비: '||F_GET_D_CURRENCY(ROUND(A.CHG_EXE_AMT / A.CHG_CON_AMT * 100,1),1)||'%'                                      \n");
			sqlstr.append("	              END CHG_BUG_RATE                                                                                                                                            \n");
			sqlstr.append("	          , F_GET_D_CURRENCY(NVL(F.ORD_SUPPLY_AMT,0), F_GET_CURRENCY_DIGIT(A.CURRENCY_GB)) AS BEF_SUPP_AMT                                                                  \n");
			sqlstr.append("	          , F_GET_D_CURRENCY(NVL(A.ORD_SUPPLY_AMT,0), F_GET_CURRENCY_DIGIT(A.CURRENCY_GB)) AS AFT_SUPP_AMT                                                                  \n");
			sqlstr.append("	          , F_GET_D_CURRENCY(NVL(A.ORD_SUPPLY_AMT,0)- NVL(F.ORD_SUPPLY_AMT,0), F_GET_CURRENCY_DIGIT(A.CURRENCY_GB)) AS CHG_SUPP_AMT                                                                  \n");
			sqlstr.append("	            , CASE WHEN NVL(A.CHG_EXE_AMT,0) > 0THEN '예산대비: '||F_GET_D_CURRENCY(ROUND(A.ORD_SUPPLY_AMT / A.CHG_EXE_AMT * 100,1),1)||'%'                                       \n");                                                                        
			sqlstr.append("	              END CHG_SUPP_RATE                                                                                                                                           \n");                      
			sqlstr.append("	          , TO_CHAR(TO_DATE(F.ORD_END_DATE), 'YYYY-MM-DD') AS BEF_CONT_DATE                                                                                              \n");
			sqlstr.append("	          , TO_CHAR(TO_DATE(A.ORD_END_DATE), 'YYYY-MM-DD') AS AFT_CONT_DATE                                                                                              \n");
			sqlstr.append("	          ,CASE WHEN TO_DATE(F.ORD_CON_DATE) IS NOT NULL AND TO_DATE(A.ORD_CON_DATE) IS NOT NULL THEN                                                                   \n");
			sqlstr.append("	           CASE WHEN TO_DATE(F.ORD_END_DATE) - TO_DATE(A.ORD_END_DATE) < 0 THEN TO_NUMBER(TO_DATE(F.ORD_END_DATE) - TO_DATE(A.ORD_END_DATE)  )||'일'                  \n");
			sqlstr.append("	           WHEN TO_DATE(F.ORD_END_DATE) - TO_DATE(A.ORD_END_DATE) > 0 THEN TO_NUMBER(TO_DATE(A.ORD_END_DATE) - TO_DATE(F.ORD_END_DATE) ) ||'일'                       \n");
			sqlstr.append("	           ELSE '0일'                                                                                                                                                     \n");
			sqlstr.append("	           END                                                                                                                                                            \n");
			sqlstr.append("	           END CONT_DATE_NM                                                                                                                                               \n");
			sqlstr.append("	          , A.IN_SPE_INFO                                                                                                                                                      \n");
			sqlstr.append("	          , A.IN_CHG_INFO                                                                                                                                                   \n");
			sqlstr.append("	          , G.DIGIT                                                                                                                                                       \n");
			sqlstr.append("	          , A.DEM_ID DEM_ID                                                                                                                                               \n");
			//2019.10.17 타절계약 추가 S
			sqlstr.append("	          , B.OUT_ITEM_CD                                                                                                                                                 \n");
			sqlstr.append("	          , B.MATERIAL_GB                                                                                                                                                 \n");
			sqlstr.append("	          , A.PUR_CONT_ID                                                                                                                                                 \n");
			sqlstr.append("	          , F.CORP_ID AS BEF_C_CORP_ID                                                                                                                                    \n");
			sqlstr.append("           ,(SELECT VENDCD FROM CONT_PUR_SUPP WHERE PUR_CONT_MOD_ID = F.PUR_CONT_MOD_ID AND SIGN_SEQ = 2) AS BEF_C_VEND_CD                                                 \n");
			//2019.10.17 타절계약 추가 E
			sqlstr.append("	          , A.BID_NO                                                                                                                                                      \n");
			sqlstr.append("	          , A.BID_DEG                                                                                                                                                     \n");
			sqlstr.append("	          , (SELECT CORP_ID FROM PUR2000T WHERE PUR_CONT_ID = A.PUR_CONT_ID AND MOD_NO=0) AS VENDOR_CD                                                                    \n");
			//2022.07.20 발주진행율 ,누적율 누계 추가
			sqlstr.append("	          , A.PO_PRC                                                                                                                                                      \n");
			sqlstr.append("	          , A.RES_PRC                                                                                                                                                     \n");
			sqlstr.append("	  FROM PUR2000T A, BID_MASTER B, HEAD_OFFICE_INFO C, CONT_PUR_SUPP D, CONT_PUR_SUPP E, PUR2000T F,                                                                        \n");
			sqlstr.append("	          (SELECT DETAILCD,DETAILNM,CHG_CODE01 AS DIGIT FROM EBID_COM911T WHERE BASECD = '911') G                                                                         \n");
			sqlstr.append("	  WHERE A.BID_NO = B.BID_NO(+)                                                                                                                                            \n");
			sqlstr.append("	  AND A.BID_DEG = B.BID_DEG(+)                                                                                                                                            \n");
			sqlstr.append("	  AND A.PUR_CONT_MOD_ID = D.PUR_CONT_MOD_ID(+)                                                                                                                            \n");
			sqlstr.append("	  AND D.SIGN_SEQ(+) = 1 --원사업자                                                                                                                                        \n");
			sqlstr.append("	  AND A.PUR_CONT_MOD_ID = E.PUR_CONT_MOD_ID(+)                                                                                                                            \n");
			sqlstr.append("	  AND E.SIGN_SEQ(+) = 2 --계약업체정보                                                                                                                                    \n");
			//sqlstr.append("	  AND F.DEMANDED_ID ='"+DEMANDED_ID+"'                                                                                                                                           \n");
			sqlstr.append("	  AND A.PUR_CONT_MOD_ID ='"+DEMANDED_ID+"'                                                                                                                                           \n");
			sqlstr.append("	  AND A.PUR_CONT_ID = F.PUR_CONT_ID                                                                                                                            \n");
			sqlstr.append("	  AND A.MOD_NO - 1 = F.MOD_NO                                                                                                                            \n");
			sqlstr.append("	  AND A.CURRENCY_GB = G.DETAILCD  																																																																				\n");
			  
			  
            System.out.println(sqlstr.toString());
			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);
			//WAFLogger.debug(sqlstr.toString());
			//WAFLogger.debug("WAFSQLException : " + se.getMessage());
		}
		finally {
			
			if( valueobject == null ) valueobject = new ValueObject();
			//WAFLogger.debug("### valueobject size : " + valueobject.size());
			return valueobject;
		}
	}
	
    /** 첨부서류조회 
     * @return
     * @throws Exception
     */
    public RowSet getFileListRowSet(String id, String code) throws Exception {
        Search search = new SearchImpl();
        RowSet listRowSet = null;
        StringBuffer sqlstr = new StringBuffer();
        try {

        	sqlstr.append(" SELECT DISTINCT  \n");
        	sqlstr.append("        A.DETAILCD,						 \n");
        	sqlstr.append(" 	   A.DETAILNM,								 \n");
        	sqlstr.append(" 	   A.DETAILSORTNM,							 \n");
        	sqlstr.append(" 	   B.ID AS DOC_CD,							 \n");
        	sqlstr.append(" 	   '" + id + "' AS FILE_GB,	 \n");
        	sqlstr.append(" 	   NVL(B.ID, A.DETAILCD) AS ID,	 \n");
        	sqlstr.append(" 	   A.CHG_CODE02 AS EDIT_YN	 \n");
        	sqlstr.append("	FROM EBID_COM911T A, PUB0510T B					 \n");
        	sqlstr.append("	WHERE A.BASECD = 'PUR_CONTCHGFILE_GB'	 \n");
        	sqlstr.append("	AND A.CHG_CODE01 = 'Y'			 \n");
        	sqlstr.append("	AND A.DETAILCD = B.ID(+)						 \n");
        	sqlstr.append("	AND B.FILE_GB(+) = '" + id + "'	 \n");
        	sqlstr.append("ORDER BY DETAILCD \n");
        	
            search.setStatement(sqlstr.toString());
            
            listRowSet = search.execute();
            WAFLogger.debug(sqlstr.toString());
            
        } catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> getListRowSet() : \n" + e.getMessage());
            WAFLogger.error("SQL : " + search.getStatement());
            WAFLogger.error(e);
            
        } finally {
            if( listRowSet == null ) listRowSet = new RowSetImpl();
           
        }
        
        return listRowSet;
    }
    
	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 connection
	 * @param valueObject
	 * @throws Exception
	 */
	public boolean saveContChgRcvProc(Connection connection, ValueObject valueObject) throws Exception {
		//WAFLogger.debug("valueObject : " + valueObject);

        try {
        	conn.begin();
        	saveContChgRcv(super.conn.getConnection(), params);		//계약 정보 저장

        	//2019.10.17 타절계약 - 사업자번호 변경인 경우
        	if(params.get("p_mode_gb").equals("98") && !params.get("p_bef_corp_id").equals(params.get("p_aft_corp_id"))){
        		updateContCorpChg(super.conn.getConnection(), params);
        	}
        	
			return true;
        }
        catch(Exception e) {
        	//WAFLogger.debug("Exception : " + e.getMessage());
            WAFLogger.error(this.getClass().getName() + " --> addChangeContProc() : " + e.getMessage());
            WAFLogger.error(e);

            conn.setRollback();
            
            this.storage.setSuccess(false);  
            this.storage.setMessage(e.getMessage());            
            storage.setDetailMessage(e);
            return false;
        }
        finally {
        	super.conn.end();
        }        
    }		



	/**
     * 변경계약접수 업데이트
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public boolean saveContChgRcv(Connection connection, ValueObject valueObject) throws Exception {
		//WAFLogger.debug("valueObject : " + valueObject);
        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        System.out.println(valueObject.get("p_aft_cont_date"));
        try {
        	sqlstr.append("		UPDATE PUR2000T SET 			\n");
        	sqlstr.append("        MOD_GB		    = ? 		\n");	
        	sqlstr.append("      , FRST_CON_AMT		= ? 		\n");	        	        
        	sqlstr.append("      , CHG_CON_AMT		= ? 		\n");	        	   
        	sqlstr.append("      , FRST_EXE_AMT		= ? 		\n");	        	        
			sqlstr.append("      , CHG_EXE_AMT		= ? 		\n");	        	        
			sqlstr.append("      , ORD_SUPPLY_AMT	= ? 		\n");	        	        
			sqlstr.append("      , ord_end_date		= ? 		\n");	        	        
			sqlstr.append("      , IN_SPE_INFO		= ? 		\n");	        	        
			sqlstr.append("      , IN_CHG_INFO		= ? 		\n");
			sqlstr.append("      , PO_PRC			= ? 		\n");	        	        
			sqlstr.append("      , RES_PRC			= ? 		\n");
			sqlstr.append(" 	 , UPD_BY  			= ?  		\n");	
        	sqlstr.append(" 	 , UPD_DATE  		= SYSDATE  	\n");	
        	sqlstr.append("		WHERE   PUR_CONT_MOD_ID = "+ valueObject.get("PUR_CONT_MOD_ID") +"	\n");
        	
            persistent.setStatement(sqlstr.toString());
            
            persistent.addParameter(valueObject.get("p_mode_gb"));										        	
        	persistent.addParameter(valueObject.get("p_bef_cont_amt").replaceAll(",", ""));										        	
        	persistent.addParameter(valueObject.get("p_aft_cont_amt").replaceAll(",", ""));										        	
        	persistent.addParameter(valueObject.get("p_bef_bug_amt").replaceAll(",", ""));										        	
        	persistent.addParameter(valueObject.get("p_aft_bug_amt").replaceAll(",", ""));										        	
        	persistent.addParameter(valueObject.get("p_aft_supp_amt").replaceAll(",", ""));										        	
        	persistent.addParameter(valueObject.get("p_aft_cont_date"));	
        	persistent.addParameter(valueObject.get("p_sp_remark"));	
        	persistent.addParameter(valueObject.get("p_remark"));
        	persistent.addParameter(valueObject.get("p_po_prc"));	
        	persistent.addParameter(valueObject.get("p_res_prc"));
            
        	persistent.addParameter(storage.getUser().get("acct_id"));	
        	
            persistent.execute();
            
            return true;
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            //WAFLogger.debug("Exception : " + e.getMessage());
            throw e;
        }
    }	

	/**
     * 반려 업데이트
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public boolean ContChgRcvStatusUp(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	/**
        	 * 2018.11.19
        	 * 이인오
        	 * 안쓰는소스 경영정보 디비링크삭제
        	 */
        	//WAFLogger.debug("Exception : " + valueObject.get("pConClsYn"));
	        	sqlstr.append("UPDATE PMM_DEMANDED_REQUEST!CCSIF SET  	\n");
	        	sqlstr.append(" 	DEMANDED_STATUS = 80		\n");
	        	sqlstr.append("    ,RTN_REASON  = ?		\n");
	        	sqlstr.append("    ,RTN_EMPNO  = ?		\n");
	        	sqlstr.append("    ,RTN_DATE  = TO_CHAR(SYSDATE,'YYYYMMDD')		\n");
	        	    	        	
	        	sqlstr.append("WHERE DEMANDED_ID = ?						\n");
	        	sqlstr.append("AND   PUR_CONT_MOD_ID = ?						\n");
	            persistent.setStatement(sqlstr.toString());
	            persistent.addParameter(valueObject.get("RJCTREASON"));
	            persistent.addParameter(storage.getUser().get("acct_id"));
	            persistent.addParameter(valueObject.get("DEMANDED_ID"));
	            persistent.addParameter(valueObject.get("PUR_CONT_MOD_ID"));


            persistent.execute();
//
            return true;
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            //WAFLogger.debug("Exception : " + e.getMessage());
            throw e;
        }
    }	
	
    
	private ValueObject getDupCnt(String sign_cont_req_id, String sign_cont_mod_id) {
		
		Search search = new SearchImpl();
		RowSet rowSet = new RowSetImpl();
		ValueObject valueobject = null;
		ValueObject user = storage.getUser();
		//   String sqlstr = "";
		StrBuffer sqlstr = new StrBuffer();
		try{
			
			sqlstr.append(" SELECT  COUNT(*) AS CNT                                                                   	\n");
    		sqlstr.append(" FROM    SIGN001T                                                                     	\n");
    		sqlstr.append("	WHERE SIGN_CLASS_CD = 'ebid_pcpoD'												\n");
    		sqlstr.append("	AND SIGN_DECI_CLASS IN ('11','14')												\n");
    		sqlstr.append("	AND KEY_COL1 = '"+sign_cont_mod_id+"'	 														\n");
    		sqlstr.append("	AND ATTR_6  = '0'  																				\n");
    		//sqlstr.append("	AND CRE_BY = '"+user.get("acct_id")+"'													\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);
			//WAFLogger.debug(sqlstr.toString());
			//WAFLogger.debug("WAFSQLException : " + se.getMessage());
		}
		finally {
			
			if( valueobject == null ) valueobject = new ValueObject();
			//WAFLogger.debug("### valueobject size : " + valueobject.size());
			return valueobject;
		}
	}
	
	/**
	 * 계약 대상리스트 조회
	 * @param Params
	 * @return
	 */
	private RowSet getContChgRcvList(ValueObject param) {

		Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        StrBuffer sqlstr = new StrBuffer();
       
        try{
			
        	
        	sqlstr.append("	                SELECT E.MATERIAL_CD                                                                      	\n");                        
        	sqlstr.append("	                     , F_GET_MATERIAL_NAME(E.MATERIAL_CD) AS MATERIAL_NAME                                	\n");                        
        	sqlstr.append("	                     , F_GET_MATL_SPEC_NAME(E.MATERIAL_CD) AS MATERIAL_SPEC                               	\n");                        
        	sqlstr.append("	                     , F_GET_UNIT_KIND_NAME(E.MATERIAL_CD)  AS UNIT_KIND_NAME                               \n");                        
        	sqlstr.append("	                     , C.ITEM_QTY      AS CON_ITEM_QTY                                                    	\n");                        
        	sqlstr.append("	                     , E.ITEM_QTY CHG_ITEM_QTY                                                              \n");                        
        	sqlstr.append("	                     , A.PUR_CONT_MOD_ID                                                                    \n");                        
        	sqlstr.append("	                FROM PUR2000T A   --CHG                                                                     \n");                 
        	sqlstr.append("	                   , CONT_PUR_ITEM E                                                                        \n");   
        	sqlstr.append("	                   , ( SELECT B.*                                                                           \n");  
        	sqlstr.append("	                         FROM PUR2000T A   --BEFORE                                                         \n");                                         
        	sqlstr.append("	                            , CONT_PUR_ITEM B                                                               \n");  
        	sqlstr.append("	                            , PUR2000T C                                                                    \n");  
        	sqlstr.append("	                        WHERE A.PUR_CONT_MOD_ID = B.PUR_CONT_MOD_ID                                         \n");  
        	sqlstr.append("	                          AND A.PUR_CONT_ID = C.PUR_CONT_ID                                                 \n");  
        	sqlstr.append("	                          AND C.PUR_CONT_MOD_ID = '"+params.get("PUR_CONT_MOD_ID")+"'                       \n"); 
        	sqlstr.append("	                          AND A.MOD_NO = C.MOD_NO - 1) C                                                    \n");  
        	sqlstr.append("	                WHERE A.PUR_CONT_MOD_ID = E.PUR_CONT_MOD_ID                                             	\n");                        
        	sqlstr.append("	                AND   E.MATERIAL_CD = C.MATERIAL_CD(+)                                                     	\n");                        
        	sqlstr.append("	                AND   A.PUR_CONT_MOD_ID  = '"+params.get("PUR_CONT_MOD_ID")+"'                            	\n");                          
        	sqlstr.append("	                ORDER BY E.MATERIAL_CD DESC   																\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();
            }
        }
        //WAFLogger.debug("### rowSet size : " + rowSet.size());
        return rowSet;
	}
	
	public boolean saveContChg(ValueObject params)throws Exception{
		conn.begin();
		try{
			Connection con = conn.getConnection();
			
        	
        	updateMaster(con, params);
        	String maxPurContid = getMaxPurCntId();
        	
        	params.set("maxPurContid", maxPurContid);
    		addChangeContProc(con,params);	//변경 계약 축

			
		}catch(Exception e ){
			e.printStackTrace();
			conn.setRollback();
			storage.setSuccess(false);
			return false;
		}finally{
			conn.end();
		}
		return true;
	}
	
	
    /**
     * PMM_DEMANDED_REQUEST 상태값을 업데이트해준다.
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void updateMaster(Connection connection, ValueObject vo) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StringBuffer sqlstr = null;
        
        try {
        	/**
        	 * 2018.11.19
        	 * 이인오
        	 * 안쓰는소스 경영정보 디비링크삭제
        	 */
        	sqlstr = new StringBuffer();
   			sqlstr.append(" UPDATE  PMM_DEMANDED_REQUEST!CCSIF  					\n");
    		sqlstr.append("      SET DEMANDED_STATUS = '50'    						\n");
    		sqlstr.append(" WHERE DEMANDED_ID	= ?    							\n");
    		persistent.setStatement(sqlstr.toString());
            persistent.addParameter(vo.get("DEMANDED_ID"));
            persistent.execute();
        }
        catch(Exception e) {

            WAFLogger.error(this.getClass().getName() + " --> updateMaster() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }
	
	private String getMaxPurCntId() {
        
        Search search = new SearchImpl();
        String sqlstr = "";
        try {
            sqlstr 	= 	"SELECT PUR2000T_S.NEXTVAL AS MAX_PUR_CONT_MOD_ID \n"
            		+	"  FROM DUAL\n";

            search.setStatement(sqlstr);
            return search.execute().getRow(0).get("MAX_PUR_CONT_MOD_ID");
        }
        catch(Exception e) {

            WAFLogger.error(this.getClass().getName() + " --> getMaxPurCntId() : " + e.getMessage());
            WAFLogger.error("SQL : " + search.getStatement());
            WAFLogger.error(e);
            return null;
        }
    }
	
	
	
	/**
     * 변경 계약 정보 추가
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void addChangeContProc(Connection connection, ValueObject valueObject) throws Exception {
		//WAFLogger.debug("valueObject : " + valueObject);

        try {

        	addChangeContPur(super.conn.getConnection(), params);	//변경 계약 축
        	
			addChangeContSupport(super.conn.getConnection(), params);	//변경 계약 축
			
			addChangeContItem(super.conn.getConnection(), params);	//변경계약 아이템 저장
			
        }
        catch(Exception e) {
        	  WAFLogger.error(this.getClass().getName() + " --> addChangeContProc() : " + e.getMessage());
              WAFLogger.error("SQL : " + e.getMessage());
              WAFLogger.error(e);
              throw e;
        }
            
    }
	
	/**
     * 변경 계약 업체 정보 추가
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public boolean addChangeContPur(Connection connection, ValueObject valueObject) throws Exception {
		//WAFLogger.debug("valueObject : " + valueObject);
        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	
        	
        	sqlstr.append("			INSERT INTO PUR2000T                                                          \n");
        	sqlstr.append("			       (         PUR_CONT_MOD_ID                                              \n");
        	sqlstr.append("			         ,        PUR_CONT_ID                                                 \n");
        	sqlstr.append("			         ,        MOD_NO                                                      \n");
        	sqlstr.append("			         ,        MOD_GB                                                      \n");
        	sqlstr.append("			         ,        MOD_RSN                                                     \n");
        	sqlstr.append("			         ,        MOD_REQ_DATE                                                \n");
        	sqlstr.append("			         ,        MOD_CORP_RSN                                                \n");
        	sqlstr.append("			         ,        DEPT_CD                                                     \n");
        	sqlstr.append("			         ,        DEPT_NAME                                                   \n");
        	sqlstr.append("			         ,        CON_GB                                                      \n");
        	sqlstr.append("			         ,        ORD_DOC_NO                                                  \n");
        	sqlstr.append("			         ,        CST_DOC_NAME                                                \n");
        	sqlstr.append("			         ,        REQ_DEPT_CD                                                 \n");
        	sqlstr.append("			         ,        REQ_DATE                                                    \n");
        	sqlstr.append("			         ,        REQ_USERID                                                  \n");
        	sqlstr.append("			         ,        REQ_USERNM                                                  \n");
        	sqlstr.append("			         ,        REQ_DOC_NO                                                  \n");
        	sqlstr.append("			         ,        CST_DATE                                                    \n");
        	sqlstr.append("			         ,        CON_IN_DATE                                                 \n");
        	sqlstr.append("			         ,        ELEC_CON_YN                                                 \n");
        	sqlstr.append("			         ,        ORD_CON_DATE                                                \n");
        	sqlstr.append("			         ,        PAY_COND_GB                                                 \n");
        	sqlstr.append("			         ,        PAY_CONTENT                                                 \n");
        	sqlstr.append("			         ,        LEAD_COND_GB                                                \n");
        	sqlstr.append("			         ,        LEAD_PLACE                                                  \n");
        	sqlstr.append("			         ,        CORP_ID                                                     \n");
        	sqlstr.append("			         ,        ORD_START_DATE                                              \n");
        	sqlstr.append("			         ,        ORD_END_DATE                                                \n");
        	sqlstr.append("			         ,        ORD_SEND_DATE                                               \n");
        	sqlstr.append("			         ,        ORD_AMT                                                     \n");
        	sqlstr.append("			         ,        ORD_SUPPLY_AMT                                              \n");
        	sqlstr.append("			         ,        ORD_SURTAX_AMT                                              \n");
        	sqlstr.append("			         ,        PREPAY_AMT                                                  \n");
        	sqlstr.append("			         ,        MID_AMT                                                     \n");
        	sqlstr.append("			         ,        RMDR_AMT                                                    \n");
        	sqlstr.append("			         ,        PREPAY_EXE_YN                                               \n");
        	sqlstr.append("			         ,        PREPAY_GUAR_AMT                                             \n");
        	sqlstr.append("			         ,        CON_GUAR_AMT_RATE                                           \n");
        	sqlstr.append("			         ,        CON_GUAR_AMT                                                \n");
        	sqlstr.append("			         ,        CON_GUAR_TERM                                               \n");
        	sqlstr.append("			         ,        DEF_GUAR_AMT_RATE                                           \n");
        	sqlstr.append("			         ,        DEF_GUAR_AMT                                                \n");
        	sqlstr.append("			         ,        DEF_GUAR_TERMS                                              \n");
        	sqlstr.append("			         ,        DEF_GUAR_TERMS_TXT                                          \n");
        	sqlstr.append("			         ,        DEF_GUAR_TERMS2                                             \n");
        	sqlstr.append("			         ,        DEF_GUAR_TERMS_TXT2                                         \n");
        	sqlstr.append("			         ,        DEL_RATE_GB                                                 \n");
        	sqlstr.append("			         ,        CON_CHARGE_ID                                               \n");
        	sqlstr.append("			         ,        CON_CHARGE_NAME                                             \n");
        	sqlstr.append("			         ,        CON_DISPLAY_TXT                                             \n");
        	sqlstr.append("			         ,        ADD_FILE_KIND                                               \n");
        	sqlstr.append("			         ,        CORP_SIGN_DATE                                              \n");
        	sqlstr.append("			         ,        COMPANY_SIGN_DATE                                           \n");
        	sqlstr.append("			         ,        ENT_CLS_YN                                                  \n");
        	sqlstr.append("			         ,        PAY_GROUP                                                   \n");
        	sqlstr.append("			         ,        PAYMENT_TERMS                                               \n");
        	sqlstr.append("			         ,        ACCT_GB                                                     \n");
        	sqlstr.append("			         ,        GUA_GB                                                      \n");
        	sqlstr.append("			         ,        CURRENCY_GB                                                 \n");
        	sqlstr.append("			         ,        PAY_ITEM                                                    \n");
        	sqlstr.append("			         ,        COST_CODE                                                   \n");
        	sqlstr.append("			         ,        COST_TYPE                                                   \n");
        	sqlstr.append("			         ,        ONSHORE_CD                                                  \n");
        	sqlstr.append("			         ,        CONTRACTID                                                  \n");
        	sqlstr.append("			         ,        G_ID                                                        \n");
        	sqlstr.append("			         ,        P_ID                                                        \n");
        	sqlstr.append("			         ,        PREPAY_AMT_RATE                                             \n");
        	sqlstr.append("			         ,        PREPAY_PAYMENT_NM                                           \n");
        	sqlstr.append("			         ,        MID_AMT_RATE                                                \n");
        	sqlstr.append("			         ,        MID_PAYMENT_NM                                              \n");
        	sqlstr.append("			         ,        MID_PAYMENT_TXT                                             \n");
        	sqlstr.append("			         ,        RMDR_AMT_RATE                                               \n");
        	sqlstr.append("			         ,        RMDR_PAYMENT_NM                                             \n");
        	sqlstr.append("			         ,        RMDR_PAYMENT_TXT                                            \n");
        	sqlstr.append("			         ,        PREPAY_GUAR_AMT_RATE                                        \n");
        	sqlstr.append("			         ,        OVERSEA_GB                                                  \n");
        	sqlstr.append("			         ,        PUR_LIST_GB                                                 \n");
        	sqlstr.append("			         ,        CON_RUN_STS                                                 \n");
        	sqlstr.append("			         ,        BID_NO                                                      \n");
        	sqlstr.append("			         ,        BID_DEG                                                     \n");
        	sqlstr.append("			         ,        STATUS_CD                                                   \n");
        	sqlstr.append("			         ,        TEMPLATE_CD                                                 \n");
        	sqlstr.append("			         ,        MODI_REQ_REASON                                             \n");
        	sqlstr.append("			         ,        MODI_REQ_DT                                                 \n");
        	sqlstr.append("			         ,        CON_CLS_YN                                                  \n");
        	sqlstr.append("			         ,        PAY_DIV                                                     \n");
        	sqlstr.append("			         ,        DEM_ID                                                      \n");
        	sqlstr.append("			         ,        IN_SPE_INFO                                                 \n");
        	sqlstr.append("			         ,        IN_CHG_INFO                                                 \n");
        	sqlstr.append("			         ,        FRST_CON_AMT                                                \n"); 
        	sqlstr.append("			         ,        FRST_EXE_AMT                                                \n");
        	sqlstr.append("			         ,        CHG_CON_AMT                                                 \n");
        	sqlstr.append("			         ,        CHG_EXE_AMT                                                 \n");
        	sqlstr.append("			         ,        CRE_BY                                                      \n");
        	sqlstr.append("			         ,        CRE_DATE    )                                               \n");
        	sqlstr.append("			SELECT ?                                                                      \n");
        	sqlstr.append("			         ,        A.PUR_CONT_ID                                               \n");
        	sqlstr.append("			         ,        MOD_NO + 1                                                  \n");
        	sqlstr.append("			         ,        NULL                                                        \n");
        	sqlstr.append("			         ,        NULL                                                        \n");
        	sqlstr.append("			         ,        NULL                                                        \n");
        	sqlstr.append("			         ,        NULL                                                        \n");
        	sqlstr.append("			         ,        A.DEPT_CD                                                   \n");
        	sqlstr.append("			         ,        A.DEPT_NAME                                                 \n");
        	sqlstr.append("			         ,        A.CON_GB                                                    \n");
        	sqlstr.append("			         ,        A.ORD_DOC_NO                                                \n");
        	sqlstr.append("			         ,        A.CST_DOC_NAME                                              \n");
        	sqlstr.append("			         ,        A.REQ_DEPT_CD                                               \n");
        	sqlstr.append("			         ,        A.REQ_DATE                                                  \n");
        	sqlstr.append("			         ,        A.REQ_USERID                                                \n");
        	sqlstr.append("			         ,        A.REQ_USERNM                                                \n");
        	sqlstr.append("			         ,        A.REQ_DOC_NO                                                \n");
        	sqlstr.append("			         ,        A.CST_DATE                                                  \n");
        	sqlstr.append("			         ,        A.CON_IN_DATE                                               \n");
        	sqlstr.append("			         ,        A.ELEC_CON_YN                                               \n");
        	sqlstr.append("			         ,        A.ORD_CON_DATE                                              \n");
        	sqlstr.append("			         ,        A.PAY_COND_GB                                               \n");
        	sqlstr.append("			         ,        A.PAY_CONTENT                                               \n");
        	sqlstr.append("			         ,        A.LEAD_COND_GB                                              \n");
        	sqlstr.append("			         ,        A.LEAD_PLACE                                                \n");
        	sqlstr.append("			         ,        A.CORP_ID                                                   \n");
        	sqlstr.append("			         ,        A.ORD_START_DATE                                            \n");
        	sqlstr.append("			         ,        A.ORD_END_DATE                                              \n");
        	sqlstr.append("			         ,        A.ORD_SEND_DATE                                             \n");
        	sqlstr.append("			         ,        A.ORD_AMT                                                   \n");
        	sqlstr.append("			         ,        A.ORD_SUPPLY_AMT                                            \n");
        	sqlstr.append("			         ,        A.ORD_SURTAX_AMT                                            \n");
        	sqlstr.append("			         ,        A.PREPAY_AMT                                                \n");
        	sqlstr.append("			         ,        A.MID_AMT                                                   \n");
        	sqlstr.append("			         ,        A.RMDR_AMT                                                  \n");
        	sqlstr.append("			         ,        A.PREPAY_EXE_YN                                             \n");
        	sqlstr.append("			         ,        A.PREPAY_GUAR_AMT                                           \n");
        	sqlstr.append("			         ,        A.CON_GUAR_AMT_RATE                                         \n");
        	sqlstr.append("			         ,        A.CON_GUAR_AMT                                              \n");
        	sqlstr.append("			         ,        A.CON_GUAR_TERM                                             \n");
        	sqlstr.append("			         ,        A.DEF_GUAR_AMT_RATE                                         \n");
        	sqlstr.append("			         ,        A.DEF_GUAR_AMT                                              \n");
        	sqlstr.append("			         ,        A.DEF_GUAR_TERMS                                            \n");
        	sqlstr.append("			         ,        A.DEF_GUAR_TERMS_TXT                                        \n");
        	sqlstr.append("			         ,        A.DEF_GUAR_TERMS2                                           \n");
        	sqlstr.append("			         ,        A.DEF_GUAR_TERMS_TXT2                                       \n");
        	sqlstr.append("			         ,        A.DEL_RATE_GB                                               \n");
        	sqlstr.append("			         ,        A.CON_CHARGE_ID                                             \n");
        	sqlstr.append("			         ,        A.CON_CHARGE_NAME                                           \n");
        	sqlstr.append("			         ,        A.CON_DISPLAY_TXT                                           \n");
        	sqlstr.append("			         ,        A.ADD_FILE_KIND                                             \n");
        	sqlstr.append("			         ,        A.CORP_SIGN_DATE                                            \n");
        	sqlstr.append("			         ,        A.COMPANY_SIGN_DATE                                         \n");
        	sqlstr.append("			         ,        A.ENT_CLS_YN                                                \n");
        	sqlstr.append("			         ,        A.PAY_GROUP                                                 \n");
        	sqlstr.append("			         ,        A.PAYMENT_TERMS                                             \n");
        	sqlstr.append("			         ,        A.ACCT_GB                                                   \n");
        	sqlstr.append("			         ,        A.GUA_GB                                                    \n");
        	sqlstr.append("			         ,        A.CURRENCY_GB                                               \n");
        	sqlstr.append("			         ,        A.PAY_ITEM                                                  \n");
        	sqlstr.append("			         ,        A.COST_CODE                                                 \n");
        	sqlstr.append("			         ,        A.COST_TYPE                                                 \n");
        	sqlstr.append("			         ,        A.ONSHORE_CD                                                \n");
        	sqlstr.append("			         ,        A.CONTRACTID                                                \n");
        	sqlstr.append("			         ,        A.G_ID                                                      \n");
        	sqlstr.append("			         ,        A.P_ID                                                      \n");
        	sqlstr.append("			         ,        A.PREPAY_AMT_RATE                                           \n");
        	sqlstr.append("			         ,        A.PREPAY_PAYMENT_NM                                         \n");
        	sqlstr.append("			         ,        A.MID_AMT_RATE                                              \n");
        	sqlstr.append("			         ,        A.MID_PAYMENT_NM                                            \n");
        	sqlstr.append("			         ,        A.MID_PAYMENT_TXT                                           \n");
        	sqlstr.append("			         ,        A.RMDR_AMT_RATE                                             \n");
        	sqlstr.append("			         ,        A.RMDR_PAYMENT_NM                                           \n");
        	sqlstr.append("			         ,        A.RMDR_PAYMENT_TXT                                          \n");
        	sqlstr.append("			         ,        A.PREPAY_GUAR_AMT_RATE                                      \n");
        	sqlstr.append("			         ,        A.OVERSEA_GB                                                \n");
        	sqlstr.append("			         ,        A.PUR_LIST_GB                                               \n");
        	sqlstr.append("			         ,        A.CON_RUN_STS                                               \n");
        	sqlstr.append("			         ,        A.BID_NO                                                    \n");
        	sqlstr.append("			         ,        A.BID_DEG                                                   \n");
        	sqlstr.append("			         ,        '00'                                                        \n");
        	sqlstr.append("			         ,        NULL                                                        \n");
        	sqlstr.append("			         ,        A.MODI_REQ_REASON                                           \n");
        	sqlstr.append("			         ,        A.MODI_REQ_DT                                               \n");
        	sqlstr.append("			         ,        1                                                           \n");
        	sqlstr.append("			         ,        A.PAY_DIV                                                   \n");
        	sqlstr.append("			         ,        B.DEMANDED_ID                                                           \n");
        	sqlstr.append("			         ,        B.SP_REMARK                                                 \n");
        	sqlstr.append("			         ,        B.REMARK                                                    \n");
        	sqlstr.append("			         ,        B.BEF_CONT_AMT                                              \n");
        	sqlstr.append("			         ,        B.BEF_BUG_AMT                                               \n");
        	sqlstr.append("			         ,        B.AFT_CONT_AMT                                              \n");
        	sqlstr.append("			         ,        B.AFT_BUG_AMT                                               \n");
        	sqlstr.append("			         ,    ?                                                               \n");
        	sqlstr.append("			         ,    SYSDATE                                                         \n");
        	sqlstr.append("			  FROM PUR2000T  A                                                            \n");
        	sqlstr.append("			          , PMM_DEMANDED_REQUEST  B                                                       \n");
        	sqlstr.append("			 WHERE   A.PUR_CONT_MOD_ID = B.PUR_CONT_MOD_ID                                \n");
        	sqlstr.append("			 AND     B.DEMANDED_ID = ?                                  						\n");
        	
        	
					
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(valueObject.get("maxPurContid"));
			persistent.addParameter(storage.getUser().get("acct_id"));
			persistent.addParameter(valueObject.get("DEMANDED_ID"));
			persistent.execute();
			
            return true;
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }        
    }	
	
	
	/**
     * 변경 계약 업체 정보 추가
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public boolean addChangeContSupport(Connection connection, ValueObject valueObject) throws Exception {
		//WAFLogger.debug("valueObject : " + valueObject);
        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
			sqlstr.append("INSERT INTO CONT_PUR_SUPP 							\n");
			sqlstr.append("       ( 	PUR_CONT_MOD_ID		\n");
			sqlstr.append("         ,	CORP_ID		\n");
			sqlstr.append("         ,	SIGN_SEQ		\n");
			sqlstr.append("         ,	VENDCD		\n");
			sqlstr.append("         ,	MEMBER_NAME		\n");
			sqlstr.append("         ,	BOSS_NAME		\n");
			sqlstr.append("         ,	POST_CODE		\n");
			sqlstr.append("         ,	ADDRESS		\n");
			sqlstr.append("         ,	TEL_NUM		\n");
			sqlstr.append("         ,	MEMBER_SLNO		\n");
			sqlstr.append("         ,	USER_NAME		\n");
			sqlstr.append("         ,	DIVISION		\n");
			sqlstr.append("         ,	POSITION		\n");
			sqlstr.append("         ,	HP		\n");
			sqlstr.append("         ,	EMAIL		\n");
			sqlstr.append("         ,	SIGN_DATE		\n");
			sqlstr.append("         ,	SIGN_DN		\n");
			sqlstr.append("         ,	SIGN_DATA		\n");
			sqlstr.append("         ,	CRE_BY		\n");
			sqlstr.append("         ,	CRE_DATE	)	\n");

			sqlstr.append("SELECT ?	\n");
			sqlstr.append("         ,	A.CORP_ID		\n");
			sqlstr.append("         ,	A.SIGN_SEQ		\n");
			sqlstr.append("         ,	A.VENDCD		\n");
			sqlstr.append("         ,	DECODE(SIGN_SEQ, 2, NVL(B.CORP_KOR, A.MEMBER_NAME), A.MEMBER_NAME) AS MEMBER_NAME		\n");
			sqlstr.append("         ,	DECODE(SIGN_SEQ, 2, NVL(B.REP_NAME, A.BOSS_NAME), A.BOSS_NAME) AS BOSS_NAME		\n");
			sqlstr.append("         ,	DECODE(SIGN_SEQ, 2, NVL(B.POST_NO, A.POST_CODE), A.POST_CODE) AS POST_CODE		\n");
			sqlstr.append("         ,	DECODE(SIGN_SEQ, 2, NVL(B.ADDRESS, A.ADDRESS), A.ADDRESS) AS ADDRESS		\n");
			sqlstr.append("         ,	DECODE(SIGN_SEQ, 2, NVL(B.CORP_TEL, A.TEL_NUM), A.TEL_NUM) AS TEL_NUM		\n");
			sqlstr.append("         ,	DECODE(SIGN_SEQ, 2, NVL(B.COPR_NO, A.MEMBER_SLNO), A.MEMBER_SLNO) AS MEMBER_SLNO		\n");
			sqlstr.append("         ,	A.USER_NAME		\n");
			sqlstr.append("         ,	A.DIVISION		\n");
			sqlstr.append("         ,	A.POSITION		\n");
			sqlstr.append("         ,	A.HP		\n");
			sqlstr.append("         ,	A.EMAIL		\n");
			sqlstr.append("         ,	NULL		\n");
			sqlstr.append("         ,	NULL		\n");
			sqlstr.append("         ,	NULL		\n");
			sqlstr.append("         ,	?		\n");
			sqlstr.append("         ,	SYSDATE				\n");
			sqlstr.append("  FROM CONT_PUR_SUPP  A, SUPP_INFO B 				\n");
			sqlstr.append(" WHERE A.CORP_ID = B.CORP_ID (+) 					\n");
			sqlstr.append(" AND A.PUR_CONT_MOD_ID= ?								\n");
						
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(valueObject.get("maxPurContid"));
			persistent.addParameter(storage.getUser().get("acct_id"));
			persistent.addParameter(valueObject.get("PUR_CONT_MOD_ID"));
			persistent.execute();
            return true;
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }        
    }
	
	/**
     * 변경 계약 업체 정보 추가
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public boolean addChangeContItem(Connection connection, ValueObject valueObject) throws Exception {
		//WAFLogger.debug("valueObject : " + valueObject);
        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	/**
        	 * 2018.11.19
        	 * 이인오
        	 * 안쓰는소스 경영정보 디비링크삭제
        	 */
        	
			sqlstr.append("INSERT INTO CONT_PUR_ITEM 	\n");
			sqlstr.append("       ( 	PUR_CONT_MOD_ID	\n");
			sqlstr.append("         ,	MATERIAL_CD		\n");
			sqlstr.append("         ,	PUR_CONT_ID		\n");
			sqlstr.append("         ,	ITEM_NAME		\n");
			sqlstr.append("         ,	ITEM_SPEC		\n");
			sqlstr.append("         ,	ITEM_UNIT		\n");
			sqlstr.append("         ,	ITEM_QTY		\n");
			sqlstr.append("         ,	ITEM_PRICE		\n");
			sqlstr.append("         ,	ITEM_AMT		\n");
			sqlstr.append("         ,	CRE_BY			\n");
			sqlstr.append("         ,	CRE_DATE		\n");
			sqlstr.append("		)						\n");
			sqlstr.append("SELECT ?						\n");
			sqlstr.append("         ,	MATERIAL_CD		\n");
			sqlstr.append("         ,	C.PUR_CONT_ID		\n");
			sqlstr.append("         ,	F_GET_MATERIAL_NAME(B.MATERIAL_CD)		\n");
			sqlstr.append("         ,	F_GET_MATL_SPEC_NAME(B.MATERIAL_CD)		\n");
			sqlstr.append("         ,	F_GET_MATL_UNIT_KIND(B.MATERIAL_CD)		\n");
			sqlstr.append("         ,	DEMANDED_QTY		\n");
			sqlstr.append("         ,	DEMANDED_PRI		\n");
			sqlstr.append("         ,	DEMANDED_AMT		\n");
			sqlstr.append("         ,	?				\n");
			sqlstr.append("         ,	SYSDATE			\n");
			sqlstr.append("  FROM PMM_DEMANDED_REQUEST!CCSIF A 		\n");
			sqlstr.append("     , PMM_DEMANDED_ITEM!CCSIF B		\n");
			sqlstr.append("     , PUR2000T   C		\n");
			sqlstr.append(" WHERE A.DEMANDED_ID = B.DEMANDED_ID  		\n");
			sqlstr.append(" AND A.PUR_CONT_MOD_ID = C.PUR_CONT_MOD_ID    		\n");
			sqlstr.append(" AND A.DEMANDED_ID= ?	\n");
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(valueObject.get("maxPurContid"));
			persistent.addParameter(storage.getUser().get("acct_id"));
			persistent.addParameter(valueObject.get("DEMANDED_ID"));
				
        	
			persistent.execute();
            return true;
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }        
    }	

	/**
     * 타절계약 - 사업자번호 변경
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void updateContCorpChg(Connection connection, ValueObject valueObject) throws Exception {
		//WAFLogger.debug("valueObject : " + valueObject);
        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();

        try {
        	sqlstr.append("		UPDATE PUR2000T SET 	\n");
        	sqlstr.append("            CORP_ID = ? 		\n");	
			sqlstr.append(" 	       , UPD_BY = ?  		\n");
        	sqlstr.append(" 	       , UPD_DATE = SYSDATE  	\n");
        	sqlstr.append("		WHERE  PUR_CONT_MOD_ID = "+ valueObject.get("PUR_CONT_MOD_ID") +"	\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("p_aft_corp_id"));
            persistent.addParameter(storage.getUser().get("acct_id"));
            persistent.execute();
            persistent.clearParameters();
            sqlstr.reset();
            
        	sqlstr.append("		UPDATE CONT_PUR_SUPP SET 	\n");
        	sqlstr.append("            CORP_ID = ? 		\n");
        	sqlstr.append("            , VENDCD = ? 		\n");
        	sqlstr.append("            , MEMBER_NAME = ? 		\n");
        	sqlstr.append("            , BOSS_NAME = ? 		\n");
        	sqlstr.append("            , POST_CODE = (SELECT POST_NO FROM SUPP_INFO WHERE CORP_ID = ?) \n");
        	sqlstr.append("            , ADDRESS = (SELECT ADDRESS FROM SUPP_INFO WHERE CORP_ID = ?) \n");
        	sqlstr.append("            , TEL_NUM = (SELECT SUBSTR(CORP_TEL,1,15) FROM SUPP_INFO WHERE CORP_ID = ?) \n");
        	sqlstr.append("            , MEMBER_SLNO = (SELECT COPR_NO FROM SUPP_INFO WHERE CORP_ID = ?) \n");        	
			sqlstr.append(" 	       , UPD_BY = ?  		\n");
        	sqlstr.append(" 	       , UPD_DATE = SYSDATE  	\n");
        	sqlstr.append("		WHERE  PUR_CONT_MOD_ID = "+ valueObject.get("PUR_CONT_MOD_ID") +"	\n");
        	sqlstr.append("		  AND  SIGN_SEQ = 2	\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("p_aft_corp_id"));
            persistent.addParameter(valueObject.get("p_aft_vend_cd").replaceAll("-", ""));
            persistent.addParameter(valueObject.get("p_aft_member_nm"));
            persistent.addParameter(valueObject.get("p_aft_boss_nm"));
            persistent.addParameter(valueObject.get("p_aft_corp_id"));
            persistent.addParameter(valueObject.get("p_aft_corp_id"));
            persistent.addParameter(valueObject.get("p_aft_corp_id"));
            persistent.addParameter(valueObject.get("p_aft_corp_id"));
            persistent.addParameter(storage.getUser().get("acct_id"));
            persistent.execute();
            persistent.clearParameters();
            sqlstr.reset();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            //WAFLogger.debug("Exception : " + e.getMessage());
            throw e;
        }
    }	
	
	private ValueObject getContChgfilelist(String returnid){
		ValueObject vo = new ValueObject();
		String str="";
		
		RowSet totRow = new RowSetImpl();
		RowSet rowSet = FileManager.getFileList("PUR_CONTCHGFILE_GB_" + params.get("PUR_CONT_MOD_ID"), "");
        for(int i=0;i<rowSet.size();i++){
        	totRow.addRow(rowSet.getRow(i));   	
        }

        for(int i=0;i<totRow.size();i++){
        	Row row=totRow.getRow(i);
        	str += (i+1)+" : "+row.get("FILE_NAME")+" ("+ row.get("FILE_SIZE")+")";
        	if(i+1!=totRow.size()){
        		str +="\r\n";
        	}        	
        }
        
        vo.set(returnid, str);
        
		return vo;
	}

    public ValueObject getSuppInfo(String sign_bid_no,String sign_bid_deg, String sign_vendor_cd) {
		Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        ValueObject vo = new ValueObject();
        
    	StrBuffer sqlstr = new StrBuffer();
    	try {
    		sqlstr.append("SELECT A.VENDOR_NAME																													\n");
			sqlstr.append(",A.BID_NO																																		\n");
			sqlstr.append(",A.BID_DEG																																		\n");
			sqlstr.append(",A.VENDOR_CD																																	\n");
			sqlstr.append(",A.ESTI_TOT_AMT																															\n");
			sqlstr.append(",A.FILE_GB																																		\n");
			sqlstr.append(",C.DEMANDED_ID																																\n");
			sqlstr.append(",C.DIV_PO_YN																																	\n");
			sqlstr.append("FROM BID_SUPP A																															\n");
			sqlstr.append(", SUPP_INFO B																																	\n");
			sqlstr.append(", BID_MASTER C																																\n");
			sqlstr.append("WHERE A.VENDOR_CD = B.CORP_ID(+)																									\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.BID_NO = '"+sign_bid_no+"'																											\n");
			sqlstr.append("AND A.BID_DEG = '"+sign_bid_deg+"'																										\n");
			sqlstr.append("AND A.VENDOR_CD = '"+sign_vendor_cd+"'																										\n");
			sqlstr.append("AND A.SUCC_YN = 'Y'																										\n");
    		search.setStatement(sqlstr.toString());
    		rowSet = search.execute();
    		
            if(rowSet.size()>0){
            	vo = RowSetUtility.getValueObject(rowSet.getRow(0));
            }
    	}
    	catch(Exception e) {
    		WAFLogger.error(this.getClass().getName() + " --> getSuppInfo() : " + e.getMessage());
    		WAFLogger.error("SQL : " + search.getStatement());
    		WAFLogger.error(e);
    	}
        finally {    
        	if( vo == null ) vo = new ValueObject();
            return vo;
        }        
    }    
    
	/**
	 * 
	 * @param PUR_CONT_MOD_ID
	 * @return
	 */
	private ValueObject getSignInfo(String PUR_CONT_MOD_ID) {

		Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        ValueObject vo = new ValueObject();
        
     //   String sqlstr = "";
        StrBuffer sqlstr = new StrBuffer();
        try{
        	sqlstr.append("SELECT MAX(B.ERP_SIGN_DOC_ID) DOC_ID, A.PUR_CONT_MOD_ID,  MAX(B.ERP_SIGN_YEAR) AS YEAR                               \n");
        	sqlstr.append("  FROM PUR2000T  A                                                      \n");
        	sqlstr.append("      ,PMM_DEMANDED_REQUEST B                             \n");
        	sqlstr.append(" WHERE A.DEM_ID = B.DEMANDED_ID                                                                                     \n");
        	sqlstr.append("   AND B.PR_TYPE = '30'                             \n");
        	sqlstr.append("   AND A.PUR_CONT_MOD_ID = '" + PUR_CONT_MOD_ID + "'                             \n");
        	sqlstr.append(" GROUP BY A.PUR_CONT_MOD_ID      \n");
        	
        	search.setStatement(sqlstr.toString());
            //System.out.println(sqlstr.toString());
        	rowSet = search.execute();
            if(rowSet.size()>0){
            	vo = 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( vo == null ) vo = new ValueObject();
            return vo;
        }
	}	
}