/**
 * @(#)file    ContIntBiz.java
 * @(#)author  Kim Myung Ho
 * @(#)version 1.0
 * @(#)date    2014-08-11
 * @(#)since   JDK 1.4.2
 */
package kr.co.udapsoft.ebid.buyer.cont.purchase.biz;


import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;

import oracle.toplink.internal.ox.StrBuffer;
import kr.co.hsnc.common.base.WAFLogger;
import kr.co.hsnc.common.config.WAFConfig;
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.WAFConnectionImpl;
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.common.util.Crosscert;
import kr.co.udapsoft.common.util.PDFMaker;
import kr.co.udapsoft.ebid.buyer.bid.purchase.biz.InterfacePurERPiU;
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.common.ui.InitCombo;
import com.udapsoft.waf.common.util.StringUtils;
import com.udapsoft.waf.system.Biz;
import com.udapsoft.waf.system.HandlerStorage;

   
public class ContResultBiz extends Biz {

	public ContResultBiz(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("SHEET_SELECT")){
			params.set("sheet1", getContList(params));
			
			storage.addObject("ibsheet7Data", IBSheet7Factory.createIBSheet7(params, storage.request));
			
		}else if(storage.compareEvent("FORM_SHEET_SELECT")){
			
			params.set("sheet2", getStampList(params));
			storage.addObject("ibsheet7Data", IBSheet7Factory.createIBSheet7(params, storage.request));
			
		}else if(storage.compareEvent("FORM_SELECT")){
            user = getContRequestValueObject(params.get("PUR_CONT_MOD_ID"));
            storage.addValueObject("ContInfo", user);
            
			//저장된 HTML 정보
            RowSet template = getTemplateInfo(params.get("PUR_CONT_MOD_ID"));
            storage.addRowSet("template", template);
            
			//자동 저장 파일
			RowSet rowSet = getTemplateFile(params.get("PUR_CONT_MOD_ID"));
			storage.addRowSet("AUTOFILE_LIST", rowSet);            

			//인지세구분
			RowSet stampRowSet = getStampIssue();
			storage.addRowSet("stampRowSet", stampRowSet);
			
			//보증 정보 가져오기
			RowSet warrList = getWarrList(params);
			storage.addRowSet("warrList", warrList);       
			
            RowSet itemList = getContItemList(params);
            //WAFLogger.debug("ITE LIST : ++++++++++++++++++++++++++++++++++++++++++ " + itemList.size());
            storage.addRowSet("itemList", itemList);

		}else if(storage.compareEvent("CHANGE_CONT")){		//변경 계약서 작성
			String maxPurContid;
			String pDemID;
			
			//2019.05.13 전자조달에서 변경계약 진행할때 상태확인
			if (!Change_check()) {
				super.storage.setSuccess(false); 			
			}else{
				maxPurContid = getMaxPurCntId();
				pDemID = getDemandedId();
				
				params.set("maxPurContid", maxPurContid);
				params.set("pDemID", pDemID);
				success = addChangeContProc(super.conn.getConnection(), params);	//변경 계약 축
				
				super.storage.setSuccess(success);
			}			
		}else if(storage.compareEvent("SAVE_PAYITEM")){		//분개유형 저장

			success = updatePayItem(super.conn.getConnection(), params);	//분개유형 저장
			
			super.storage.setSuccess(success);
		}else if(storage.compareEvent("ADD_PAY")){		//프로시저 호출
			success = SP_PURCONT_COPY(params);
			super.storage.setSuccess(success);
		}else if(storage.compareEvent("CHG_SUPP_INFO")){		//2017.03.08 완료된계약 업체담당자 정보변경
			success = updateSuppInfo(super.conn.getConnection(), params);	
			super.storage.setSuccess(success);	
		}else if(storage.compareEvent("CONT_BACK")){		//2019.05.14 erp계약서 삭제. 계약서 현황으로. 선급,대금지급내역 있으면 처리 불가
			//2019.05.14 전자조달에서 계약취소 할때 상태확인
			if (!back_check()) {
				super.storage.setSuccess(false); 			
			}else{
				success = BackProcess(super.conn.getConnection());	//전자조달 상태값 변경, erp계약삭제 
				
				super.storage.setSuccess(success);
			}			
		}else if(storage.compareEvent("TRANS_PAY_YN")){		//대금여부 변경(관리자용)
			success = updateContPayPlan(super.conn.getConnection(), params);	
			super.storage.setSuccess(success);	
		}
	}
    
	//2019.05.13 변경계약 생성가능여부 체크 
	public boolean Change_check(){
		Search search = new SearchImpl();
        RowSet listRowSet = null;
        ValueObject valueobject = null;
        String sqlstr = "";
        
        try {
            sqlstr += " SELECT COUNT(*) cnt, NVL(MAX(B.MOD_NO), 99) mod_no           \n"
					+ "	  FROM ETEC_ERPIF.PMM_DEMANDED_REQUEST A                                \n"
					+ "	     , PUR2000T B                                            \n"
					+ "	 WHERE A.DEMANDED_ID = B.DEM_ID                              \n"
					+ "	   AND A.PR_TYPE = '30'                                      \n"
					+ "	   AND B.PUR_CONT_ID = '" + params.get("PUR_CONT_ID") + "'   \n";
					
            search.setStatement(sqlstr);
            listRowSet = search.execute();
            
            if( listRowSet != null && listRowSet.size() > 0 ){
            	valueobject = RowSetUtility.getValueObject(listRowSet.getRow(0));
            	if (valueobject.getDouble(1) == 99) {
            		return true; //청구를 통해 진행된 변경없음 
            	}
                if (valueobject.getDouble(0) > 0 ) {
                	super.storage.setMessage("변경계약 요청을 통해 진행된 계약이 존재합니다.\nERP에서 변경요청 작성 해 주십시요. ");
            		return false;  //청구내역이 있으면 변경계약 생성불가 
            	}
            } 
			return false;
		}catch(Exception e){
			e.printStackTrace();
			super.storage.setMessage(e.getMessage());
			return false;
		}  
    }	
	
	//2019.05.14 계약취소 가능여부 체크 
	public boolean back_check(){
		Search search = new SearchImpl();
        RowSet listRowSet = null;
        ValueObject valueobject = null;
        String sqlstr = "";
        
        try { //0차만 재전송 가능, 선급금 처리 여부, 대금생성 여부
             sqlstr += " SELECT MAX(A.STATUS_CD)                                                       \n"
            	    + "	      ,NVL(MAX(B.PREPAY_PROC_GB), 'N')                                         \n"
            	    + "	      ,NVL(MAX(C.REQ_STATUS), 'N'), MAX(A.MOD_NO)                              \n"
            	    + "	  FROM PUR2000T A                                                              \n"
            		+ "	      ,PUR1030T B                                                              \n"
            		+ "	      ,PUR1100T C                                                              \n"
            		+ "	      ,(SELECT MAX(PUR_CONT_MOD_ID) PUR_CONT_MOD_ID                            \n"
            		+ "	          FROM PUR2000T                                                        \n"
            		+ "	         WHERE PUR_CONT_ID = '" + params.get("PUR_CONT_ID") + "'  ) D          \n"
            		+ "	 WHERE A.PUR_CONT_MOD_ID = D.PUR_CONT_MOD_ID                                   \n"
                    + "	   AND A.PUR_CONT_ID = B.PUR_CONT_ID(+)                                        \n"
                    + "	   AND A.PUR_CONT_ID = C.PUR_CONT_ID(+)                                        \n"
                    + "	   AND A.PUR_CONT_ID = '" + params.get("PUR_CONT_ID") + "'                     \n"
                    + "	  GROUP BY A.PUR_CONT_ID                                                       \n";
                                                                    
            search.setStatement(sqlstr);
            listRowSet = search.execute();
            
            if( listRowSet != null && listRowSet.size() > 0 ){
            	valueobject = RowSetUtility.getValueObject(listRowSet.getRow(0));
            	if (valueobject.getString(0).equals("50") && !valueobject.getString(1).equals("10") && valueobject.getString(2).equals("N")&& valueobject.getString(3).equals("0")) {
            		return true; //선급금 미완료, 대금처리내역 없음 
            	}else{
            		String errMsg = "";
            		errMsg += " 계약서를 취소할수 있는 상태가 아닙니다.\n"
                	       + "(계약상태: " + valueobject.getString(0)
                	       + "선급금:" + valueobject.getString(1)
                	       + "기성:" + valueobject.getString(2) 
            		       + "차수:" + valueobject.getString(3) + ")";
                	       
            		super.storage.setMessage(errMsg);
            		return false;
            	}
            } 
            return false;
		}catch(Exception e){
			e.printStackTrace();
			super.storage.setSuccess(false);
			super.storage.setMessage(e.getMessage());
			return false;
		}  
    }
	//2019.05.14 완료된계약 취소 
	public boolean BackProcess(Connection connection ) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("UPDATE PUR2000T                     	    \n");
        	sqlstr.append("   SET STATUS_CD = '10'					\n");
        	sqlstr.append("      ,CON_CLS_YN = '1'					\n");
        	sqlstr.append("      ,ERP_NO_ECUT = ''					\n");
        	sqlstr.append(" WHERE PUR_CONT_MOD_ID = ?		        \n");
            persistent.setStatement(sqlstr.toString());  
            persistent.addParameter(params.get("PUR_CONT_MOD_ID"));
            persistent.execute();
            
            WAFConnectionImpl erpConn = new WAFConnectionImpl();
			try {
				erpConn.setDataSource("jdbc/erpiu");
				erpConn.begin();
				InterfacePurERPiU.ErpContDelete(erpConn.getConnection(), params.get("PUR_CONT_MOD_ID")); //ERP계약자료 6개 테이블 삭제 
			}catch(Exception e) {
				erpConn.setRollback();
				super.storage.setSuccess(false);
				super.storage.setMessage(e.getMessage());
				throw e;
			}finally {
				erpConn.close();
			}
            return true;
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> BackProcess() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            super.storage.setSuccess(false);
            super.storage.setMessage(e.getMessage());
            throw e;
        }
    }	
	
	 /**
     * 저장된 계약서식 조회 
	 * @param 
	 * @param 
	 * @return RowSet 
	 */
	public RowSet getTemplateInfo(String pur_cont_cd){

        Search search = new SearchImpl();
        RowSet listRowSet = null;
        String sqlstr = "";
        
        try {
            sqlstr += " SELECT            							\n"
					+ "	  SEQ,                                      \n"
					+ "	  TEMPLATE_NAME,                            \n"
					+ "	  TEMPLATE_HTML,                            \n"
					+ "	  TEMPLATE_STYLE,                           \n"
					+ "	  CHECK_YN,                              \n"
					+ "	  OPTION_YN	                                \n"
                    + " FROM CONT_PUR_HTML      					\n"
                    + " WHERE PUR_CONT_MOD_ID =  '"+pur_cont_cd+"'		\n"
		            + " ORDER BY SEQ ASC      				\n";
             
            search.setStatement(sqlstr);
            listRowSet = search.execute();
			
		}catch(Exception e){
			e.printStackTrace();
		}finally{

			if( listRowSet == null ){
            	listRowSet = new RowSetImpl();
            }
            
			return listRowSet;
		}
	}
	
	 /**
     * 계약서식 조회 combo 조회
	 * @param 
	 * @param 
	 * @return RowSet 
	 */
	public RowSet getTemplateFile(String pur_cont_cd){

        Search search = new SearchImpl();
        RowSet listRowSet = null;
        String sqlstr = "";
        
        try {
            sqlstr += " SELECT FILE_ID, UNIQUE_FILE_NAME, FILE_PATH, FILE_EXT,          \n"   
            		+ "		TRIM(          \n"              
            		+ "        CASE                         \n"
				    + "       WHEN FILE_SIZE < 1024 THEN TO_CHAR(FILE_SIZE, '999,999') || ' Byte'          \n"
				    + "       ELSE          \n"
				    + "            CASE                WHEN FILE_SIZE < (1024*1024) THEN TO_CHAR(FLOOR(FILE_SIZE / 1024), '999,999') || ' KByte'          \n"
				    + "             ELSE  TO_CHAR(FLOOR(FILE_SIZE / (1024*1024)), '999,999,999') || ' MByte'          \n"
				    + "            END                           \n"                              
				    + "      END ) AS FILE_SIZE, FILE_NAME         \n"
                    + " FROM CONT_PUR_FILE      					\n"
                    + " WHERE PUR_CONT_MOD_ID =  '"+pur_cont_cd+"'		\n"
		            + " ORDER BY FILE_ID ASC      				\n";
             
            search.setStatement(sqlstr);
            listRowSet = search.execute();
			
		}catch(Exception e){
			e.printStackTrace();
		}finally{

			if( listRowSet == null ){
            	listRowSet = new RowSetImpl();
            }
            
			return listRowSet;
		}
	}

	/**
	 * 계약 결과 리스트 조회
	 * @param Params
	 * @return
	 */
	private RowSet getContList(ValueObject param) {

		Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        
     //   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(" 	     ,A.DEPT_NAME	                                                                                                     \n");
        	sqlstr.append(" 	     ,A.CST_DOC_NAME	                                                                                                 \n");
        	sqlstr.append(" 	     ,TO_CHAR(A.ORD_CON_DATE, 'YYYY-MM-DD') AS ORD_CON_DATE	                                                             \n");
        	sqlstr.append(" 	     ,F.MEMBER_NAME	                                                                                                     \n");
        	sqlstr.append(" 	     ,A.ORD_AMT	                                                                                                         \n");
        	sqlstr.append(" 	     ,F_GET_D_CURRENCY(A.ORD_SUPPLY_AMT, F_GET_CURRENCY_DIGIT(A.CURRENCY_GB)) AS ORD_SUPPLY_AMT	                         \n");
        	sqlstr.append(" 	     ,TO_CHAR(A.ORD_START_DATE, 'YYYY-MM-DD') || '~' || TO_CHAR(A.ORD_END_DATE, 'YYYY-MM-DD') AS WORK_START_END_DATE	 \n");
        	sqlstr.append(" 	     ,A.ORD_START_DATE	                                                                                                 \n");                                                                                
        	sqlstr.append(" 	     ,A.ORD_END_DATE	                                                                                                 \n");                                                                                
        	sqlstr.append(" 	     ,A.CON_GB 	                                                                                                         \n");                                                                                
        	sqlstr.append(" 	     ,A.STATUS_CD 	                                                                                                     \n");                                                                                
        	sqlstr.append(" 	     ,A.TEMPLATE_CD                                                                                                      \n");                                                                                
        	sqlstr.append(" 	     ,NVL(B.TEMPLATE_NAME,'이전 계약') AS TEMPLATE_NAME                                                                    \n");                                                                                
        	sqlstr.append(" 	     ,C.CHG_CONT_YN                                                                                                      \n");                                                                                
        	sqlstr.append(" 	     ,A.CURRENCY_GB 	                                                                                                 \n");                                                                                
        	sqlstr.append(" 	     ,'1' AS IMG_GB	                                                                                                     \n");                                                                                                                                                                                                                                                                                                      
        	sqlstr.append(" 	     ,A.PUR_CONT_ID	                                                                                                     \n");                                                                                                                                                                                                                                                                                                      
        	sqlstr.append(" 	     ,DECODE(A.PAY_DIV, '1', '납품정산', '계획분할') PAY_DIV	                                                             \n");  //2015.3.6 납품/설치구분표기                                                                                                                                                                                                                                                                                                       
        	sqlstr.append("          ,CASE WHEN G.OPTION_YN = 'Y' AND G.CHECK_YN = 'Y' AND H.STATUS_CD = '10' THEN '완료'                                 \n");                                                        
        	sqlstr.append("                WHEN G.OPTION_YN = 'Y' AND G.CHECK_YN = 'Y' AND H.STATUS_CD = '01' THEN '작성중'                               \n");                                                        
        	sqlstr.append("                WHEN G.OPTION_YN = 'Y' AND G.CHECK_YN = 'Y' AND H.STATUS_CD = '09' THEN '반려'                                 \n");                                                        
        	sqlstr.append("                WHEN G.OPTION_YN = 'Y' AND G.CHECK_YN = 'Y' AND H.STATUS_CD = '05' THEN '결재중'                               \n");                                                        
        	sqlstr.append("                ELSE                                                                     \n");                           
        	sqlstr.append("                		CASE WHEN  G.OPTION_YN = 'Y' AND G.CHECK_YN = 'Y' THEN '미신청'      \n");                           
        	sqlstr.append("               		     ELSE '비대상'                                 \n");        
        	sqlstr.append("                     END                                               \n"); 
        	sqlstr.append("           END INSUR_YN                                                \n");
        	sqlstr.append("          ,CASE WHEN I.GUAR_STATUS = '09'  THEN '완료'        \n");
        	sqlstr.append("                ELSE                                         \n");
        	sqlstr.append("                		CASE WHEN D.TEMPLATE_CD = '15' AND A.ORD_AMT >= 10000000  THEN '미신청'                  \n"); 
        	sqlstr.append("               		     ELSE '비대상'       \n");
        	sqlstr.append("                     END       \n");
        	sqlstr.append("           END INSUR_YN1       \n");
        	sqlstr.append(" 	  FROM PUR2000T A, CONT_PUR_HTML B, CONT_TEMPLATE C, PUR2000T D,CONT_PUR_SUPP F	\n");
        	sqlstr.append(" 	  	  ,CONT_PUR_HTML G , CONT_PUR_INSUR H	\n");
        	sqlstr.append(" 	  	  ,CONT_PUR_WARR I	\n");
        	sqlstr.append("   WHERE 1=1					\n");
        	sqlstr.append("   	AND A.PUR_CONT_MOD_ID = B.PUR_CONT_MOD_ID(+)					\n");
        	sqlstr.append("   	AND A.TEMPLATE_CD = C.TEMPLATE_CD(+)					\n");
        	sqlstr.append("   	AND A.PUR_CONT_ID = D.PUR_CONT_ID(+)					\n");
        	sqlstr.append("   	AND A.PUR_CONT_MOD_ID = G.PUR_CONT_MOD_ID(+)					\n");
        	sqlstr.append("   	AND A.PUR_CONT_MOD_ID = H.PUR_CONT_MOD_ID(+)					\n");
        	sqlstr.append("   	AND A.PUR_CONT_MOD_ID = I.PUR_CONT_MOD_ID(+)					\n");
        	sqlstr.append("   	AND B.SEQ(+)=0					\n");
        	sqlstr.append("   	AND C.SEQ(+)=0					\n");
        	sqlstr.append("   	AND D.MOD_NO=0					\n");
        	sqlstr.append("   	AND G.SEQ(+)=DECODE(A.MOD_NO,0,2,1)					\n");
        	sqlstr.append("   	AND I.WARR_GUBUN(+)=2					\n");
        	sqlstr.append("   	AND A.PUR_CONT_MOD_ID = F.PUR_CONT_MOD_ID				\n");
    		sqlstr.append("   	AND F.SIGN_SEQ = 2				\n");
        	// 현장
        	if(!param.get("P_DEPT_CD").isEmpty()) {
        		sqlstr.append(" AND A.DEPT_CD = ?																											 \n");
    			search.addParameter(params.get("P_DEPT_CD"));
        	}
//        		sqlstr.append("   AND A.DEPT_CD = '"+param.get("P_DEPT_CD")+"'				\n");
        	if(!param.get("P_BUILD_NM").isEmpty())
        		sqlstr.append("   AND UPPER(A.CST_DOC_NAME) LIKE UPPER('%"+param.get("P_BUILD_NM")+"%')				\n");
        	if(!param.get("ContFromDt").isEmpty())		//계약기간
        		sqlstr.append("   AND TO_CHAR(A.ORD_CON_DATE, 'YYYY-MM-DD') >= '"+param.get("ContFromDt")+"'				\n");
        	if(!param.get("ContToDt").isEmpty())
        		sqlstr.append("   AND TO_CHAR(A.ORD_CON_DATE, 'YYYY-MM-DD') <= '"+param.get("ContToDt")+"'				\n");
        	if(!param.get("p_dealer_nm").isEmpty())
        		sqlstr.append("   AND UPPER(F.MEMBER_NAME) LIKE '%'|| UPPER('"+param.get("p_dealer_nm")+"') ||'%'																						\n");
        	if(!param.get("P_CONT_STATUS").isEmpty())
        		sqlstr.append("   AND A.STATUS_CD IN ("+param.get("P_CONT_STATUS")+")																						\n");

        	//2016.9.5 결과 조회조건 추가 
        	if(!param.get("p_cont_no").isEmpty())
        		sqlstr.append("   AND A.ORD_DOC_NO LIKE '%'|| UPPER('"+param.get("p_cont_no")+"') ||'%'				 \n");
        	if(!param.get("p_mr_no").isEmpty())
        		sqlstr.append("   AND A.REQ_DOC_NO LIKE '%'|| UPPER('"+param.get("p_mr_no")+"') ||'%'				 \n");
        	
        	sqlstr.append("   	ORDER BY A.ORD_CON_DATE DESC			\n");
			search.setStatement(sqlstr.toString());
			System.out.println(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;
	}
	

	
	/**
	 * 계약 상세 정보
	 * @param Params
	 * @return
	 */
	private ValueObject getContRequestValueObject(String PUR_CONT_MOD_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.PUR_CONT_ID	\n");  //2016.8.22 분개유형저장 오류.
        	sqlstr.append(" 	     , A.ORD_DOC_NO	\n");
        	sqlstr.append(" 	     , A.MOD_NO	\n");	
        	sqlstr.append(" 	     , DECODE(A.MOD_GB, NULL, '00', A.MOD_GB) AS MOD_GB	\n");	
        	sqlstr.append(" 	     , A.DEPT_NAME	\n");	
        	sqlstr.append(" 	     , A.CST_DOC_NAME	\n");	
        	sqlstr.append(" 	     , TO_CHAR(A.ORD_CON_DATE, 'YYYY-MM-DD') AS ORD_CON_DATE	\n");				//수정 (2014-09-19)
        	sqlstr.append(" 	     , A.PUR_CONT_ID	\n");	
        	sqlstr.append(" 	     , A.ORD_AMT	\n");	
        	sqlstr.append(" 	     , TO_CHAR(A.ORD_START_DATE, 'YYYY-MM-DD') AS ORD_START_DATE	\n");					//수정 (2014-09-19)
        	sqlstr.append(" 	     , A.ELEC_CON_YN	\n");	
        	sqlstr.append(" 	     , TO_CHAR(A.ORD_START_DATE,'YYYY') AS ORD_START_DATE_YEAR 	\n");	
        	sqlstr.append(" 	     , TO_CHAR(A.ORD_START_DATE,'MM') AS ORD_START_DATE_MONTH 	\n");	
        	sqlstr.append(" 	     , TO_CHAR(A.ORD_START_DATE,'DD') AS ORD_START_DATE_DAY 	\n");	
        	sqlstr.append(" 	     , TO_CHAR(A.ORD_END_DATE, 'YYYY-MM-DD') AS ORD_END_DATE	\n");					//수정 (2014-09-19)
        	sqlstr.append(" 	     , TO_CHAR(A.ORD_END_DATE,'YYYY') AS ORD_END_DATE_YEAR 	\n");	
        	sqlstr.append(" 	     , TO_CHAR(A.ORD_END_DATE,'MM') AS ORD_END_DATE_MONTH 	\n");	
        	sqlstr.append(" 	     , TO_CHAR(A.ORD_END_DATE,'DD') AS ORD_END_DATE_DAY 	\n");	
        	sqlstr.append(" 	     , A.CON_GB 	\n");	
        	sqlstr.append(" 	     , A.CURRENCY_GB 	\n");														//추가 (2014-09-19)
        	sqlstr.append(" 	     , F_GET_CURRENCY_DIGIT(A.CURRENCY_GB)  AS SOSUNUM	\n");														//추가 (2014-09-19)
        	sqlstr.append(" 	     , A.LEAD_PLACE 	\n");	
        	sqlstr.append("       	 , A.LEAD_COND_GB		 	\n");
        	sqlstr.append("       	 , F_GET_CODE_NAME('PUR_LEAD_GB', A.LEAD_COND_GB) LEAD_COND_GB_NM	 	\n");	 //추가 (2014-09-19)
        	sqlstr.append("       	 , A.ORD_SUPPLY_AMT			\n");
        	sqlstr.append("       	 , A.ORD_SURTAX_AMT			\n");
        	sqlstr.append("      	 , A.PREPAY_AMT_RATE			\n");
        	sqlstr.append("       	 , A.PREPAY_AMT			\n");
        	sqlstr.append("       	 , A.MID_AMT_RATE			\n");
        	sqlstr.append("       	 , A.MID_AMT			\n");
        	sqlstr.append("       	 , A.RMDR_AMT_RATE			\n");
        	sqlstr.append("       	 , A.RMDR_AMT			\n");
        	sqlstr.append("       	 , A.CON_GUAR_AMT_RATE			\n");
        	sqlstr.append("       	 , A.CON_GUAR_TERM			\n");
        	sqlstr.append("       	 , A.CON_GUAR_AMT			\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(" 	     , TO_CHAR(A.ORD_CON_DATE,'YYYY') AS ORD_CON_DATE_YEAR 	\n");	
        	sqlstr.append(" 	     , TO_CHAR(A.ORD_CON_DATE,'MM') AS ORD_CON_DATE_MONTH 	\n");	
        	sqlstr.append(" 	     , TO_CHAR(A.ORD_CON_DATE,'DD') AS ORD_CON_DATE_DAY 	\n");	
        	sqlstr.append(" 	     , A.STATUS_CD 	\n");	
        	sqlstr.append(" 	     , DECODE(A.STATUS_CD,'10','작성중','20','을(乙) 서명요청','30','을(乙) 서명완료','40','수정요청') 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(" 	     , A.CON_CLS_YN 	\n");	        	
        	sqlstr.append(" 	     , A.CON_DISPLAY_TXT 	\n");	       							//추가 (2014-09-19) 	
        	sqlstr.append("          , A.PAY_DIV		\n");									//추가 (2014-09-22) 	
        	sqlstr.append("          , A.DIV_PO_YN		\n");									//추가 (2014-09-22) 	
        	
        	sqlstr.append(" 	     , NVL(B.DEMANDED_ID, R.DEMANDED_ID) AS DEMANDED_ID	\n");	
        	sqlstr.append(" 	     , NVL(B.DEMANDED_NO, R.DEMANDED_NO) AS DEMANDED_NO	\n");	
        	sqlstr.append(" 	     , NVL(B.DEMANDED_TITLE, R.DEMANDED_TITLE) AS DEMANDED_TITLE	\n");	
        	sqlstr.append(" 	     , TO_CHAR(TO_DATE(NVL(B.DEMANDED_DATE, R.DEMANDED_DATE)),'YYYY-MM-DD') AS DEMANDED_DATE	\n");	
        	sqlstr.append(" 	     , NVL(B.REQ_DEPT_NM, (SELECT DEPART_DEPT_NM FROM PUB0120T WHERE USER_SABUN = R.EMP_NO)) AS REQ_DEPT_NM	\n");	
        	sqlstr.append(" 	     , NVL(B.EMP_NO, R.EMP_NO) AS EMP_NO	\n");	
        	sqlstr.append(" 	     , NVL(B.EMP_NM, (SELECT USER_NAME FROM PUB0120T WHERE USER_SABUN = R.EMP_NO)) AS EMP_NM	\n");	
        	/*분개 유형*/
        	sqlstr.append(" 	     , A.ACCT_GB 	\n");	
        	sqlstr.append(" 	     , A.PAY_GROUP 	\n");	
        	sqlstr.append(" 	     , A.GUA_GB 	\n");	
        	sqlstr.append(" 	     , A.PAYMENT_TERMS 	\n");	
        	sqlstr.append(" 	     , A.PAY_ITEM 	\n");	
        	sqlstr.append(" 	     , A.COST_CODE 	\n");	
        	sqlstr.append(" 	     , A.COST_TYPE 	\n");	
        	sqlstr.append(" 	     , A.DEPT_CD 	\n");		        	
        	sqlstr.append(" 	     , A.DEPT_CD AS R_DEPT_CD	\n");		        	
        	sqlstr.append(" 	     , F_GET_PAY_ITEM_EST_DESC(A.PAY_ITEM,A.COST_CODE,A.COST_TYPE, A.DEPT_CD) AS PAY_ITEM_NM    	\n");		        	
        	sqlstr.append(" 	     , (SELECT AC_UNIT_CD FROM ACZ10100V Z WHERE  Z.DEPT_CD = A.DEPT_CD) AS  AC_UNIT_CD	\n");		
        	//승인자 추가
        	sqlstr.append(" 	     , A.CON_CONFIRM_ID 	\n");	
        	sqlstr.append(" 	     , A.CON_CONFIRM_NAME 	\n");	
        	
        	sqlstr.append(" 	     , (SELECT MAX(MOD_NO) FROM PUR2000T WHERE PUR_CONT_ID=A.PUR_CONT_ID) AS MAX_MOD_NO	\n");		//변경 계약을 위해 차수 Max 값을 조회 한다.        	
        	sqlstr.append(" 	     , (SELECT MAX(MOD_NO) FROM PUR2000T WHERE PUR_CONT_ID=A.PUR_CONT_ID AND STATUS_CD = '50') AS MAX_PLAN_NO	\n");//2016.9.6 최종계약 대금계획만 수정      	

        	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(" 	     , NVL(A.ERP_CHECK_YN,'Y') AS ERP_CHECK_YN	\n");	//2016.11.8 onshre,offhore구분 
        	sqlstr.append(" 	     , (SELECT IN_OUT_DIV FROM SUPP_INFO WHERE CORP_ID = E.CORP_ID) AS IN_OUT_DIV	\n");    
        	sqlstr.append(" 	     , A.STAMP_DUTY_GB	\n");
        	sqlstr.append(" 	     , A.FRST_CON_AMT	\n");
        	sqlstr.append(" 	     , A.FRST_EXE_AMT	\n");
        	sqlstr.append(" 	     , A.CHG_CON_AMT	\n");
        	sqlstr.append(" 	     , A.CHG_EXE_AMT	\n");
        	sqlstr.append(" 	     , A.IN_SPE_INFO	\n");
        	sqlstr.append(" 	     , A.IN_CHG_INFO	\n");
        	//sqlstr.append(" 	     , (SELECT COUNT(*) FROM PMM_DEMANDED_REQUEST WHERE DEMANDED_ID = B.DEMANDED_ID AND CHG_REQ_STATUS != '10') CHG_CNT	\n");//2018.12 변경계약은 더존에서 시작
        	sqlstr.append(" 	     , (SELECT COUNT(*) FROM PUR1100T WHERE PUR_CONT_MOD_ID = A.PUR_CONT_MOD_ID ) PUR1100T_CNT	\n");  //2016.4.28대금생성확인 
			sqlstr.append("  FROM PUR2000T A, BID_MASTER B, HEAD_OFFICE_INFO C, CONT_PUR_SUPP D, CONT_PUR_SUPP E, PMM_DEMANDED_REQUEST R 	\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.DEM_ID = R.DEMANDED_ID(+)	\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 A.PUR_CONT_MOD_ID = '"+PUR_CONT_MOD_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);
        }
        finally {

        	if( valueobject == null ) valueobject = new ValueObject();
        	//WAFLogger.debug("### valueobject size : " + valueobject.size());
            return valueobject;
        }
	}

	/**
	 * 품목 리스트
	 * @param Params
	 * @return
	 */
	private RowSet getContItemList(ValueObject ValueObject) {

		Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();

        StrBuffer sqlstr = new StrBuffer();
        try{
        	sqlstr.append(" SELECT MATERIAL_CD, ITEM_NAME, ITEM_SPEC, NVL(ITEM_QTY, 0) as ITEM_QTY, ITEM_UNIT, NVL(F_GET_CODE_NAME('UNIT_KIND_GB',ITEM_UNIT),ITEM_UNIT) AS ITEM_UNIT_NM, TRUNC(nvl(ITEM_PRICE, 0)) AS ITEM_PRICE, TRUNC(nvl(ITEM_AMT, 0)) AS ITEM_AMT, (nvl(ITEM_QTY,0) * TRUNC(nvl(ITEM_PRICE,0))) AS SUM_AMT	\n");
        	sqlstr.append("   FROM CONT_PUR_ITEM										\n");
        	sqlstr.append(" WHERE PUR_CONT_MOD_ID = '"+params.get("PUR_CONT_MOD_ID")+"'	\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);
            WAFLogger.error("SQL : " + sqlstr);
        }
        finally {    
            if(rowSet == null){
            	rowSet = new RowSetImpl();
            }
        }
        //WAFLogger.debug("### rowSet size : " + rowSet.size());
        
        return rowSet;
	}

	/**
	 * 보증 대상리스트 조회
	 * @param Params
	 * @return
	 */
	private RowSet getWarrList(ValueObject param) {

		Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        
     //   String sqlstr = "";
        /*
		보증서 종류
		  002 : 계약이행
		  003 : 하자
		  004 : 선금
		  005 : 근로자재해
		  39 : 하도급대금지급         * 
         * */
        StrBuffer sqlstr = new StrBuffer();
        try{
        	sqlstr.append("	              SELECT WARR_GUBUN	\n");
        	sqlstr.append("	                   , F_GET_CODE_NAME('GAUR_KIND',WARR_GUBUN) AS WARR_GUBUN_NM	\n");
        	sqlstr.append("	                   , MOD_NO	\n");
        	sqlstr.append("	                   , WARR_SEQ	\n");
        	sqlstr.append("	                   , WARR_WAMT	\n");
        	sqlstr.append("	                   , VIEW_DIV	\n");
        	sqlstr.append("	                   , CAUSECODE	\n");
        	sqlstr.append("	                   , F_GET_CODE_NAME('CAUSECODE',CAUSECODE) AS CAUSECODE_NM	\n");
        	sqlstr.append("	                   , GUAR_ORGAN_CODE	\n");
        	sqlstr.append("	                   , F_GET_CODE_NAME('GUAROFFICEID',GUAR_ORGAN_CODE) AS WARR_GOFFICE_ID	\n");
        	sqlstr.append("	                   , F_GET_CODE_NAME('GUARORGAN',GUAR_ORGAN_CODE) AS WARR_GOFFICE	\n");
        	sqlstr.append("	                   , GUAR_STATUS	\n");
        	sqlstr.append("	                   , F_GET_CODE_NAME('GUAR_STATUS',GUAR_STATUS) AS GUAR_STATUS_NM	\n");
        	sqlstr.append("	                   , PAPERDATE	\n");
        	sqlstr.append("	                   , WARR_WGNO	\n");
        	sqlstr.append("	                   , WARR_SDATE	\n");
        	sqlstr.append("	                   , WARR_EDATE 	\n");
        	sqlstr.append("	                   , DECODE(GUAR_ONOFF_YN,'Y','온라인','N','오프라인') AS GUAR_ONOFF_NM	\n");
        	sqlstr.append("	                   , GUAR_ONOFF_YN 	\n");
        	sqlstr.append("	                   , GRTREQNO 	\n");
        	sqlstr.append("	                FROM CONT_PUR_WARR 	\n");
        	sqlstr.append("	               WHERE PUR_CONT_MOD_ID = '"+ param.get("PUR_CONT_MOD_ID") +"' 	\n");
        	sqlstr.append("	                     AND WARR_GUBUN IN ('1','4')	\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;
	}	
	
    /**
     * 새로운(Next) 계약 PUR_CONT_MOD_ID의 MAX번호를 리턴한다.
	 * @param rightID
	 * @return
	 */
	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() + " --> getNextPgmGrSeq() : " + e.getMessage());
            WAFLogger.error("SQL : " + search.getStatement());
            WAFLogger.error(e);
            return null;
        }
    }

    /**
     * 새로운(Next) 계약 PUR_CONT_MOD_ID의 MAX번호를 리턴한다.
	 * @param rightID
	 * @return
	 */
	private String getDemandedId() {
        
        Search search = new SearchImpl();
        StrBuffer sqlstr = new StrBuffer();
        try {
		//	sqlstr.append("	SELECT MAX (DEMANDED_ID) AS DEMANDED_ID  FROM PMM_DEMANDED_REQUEST 				\n");
		//	sqlstr.append("	WHERE DEMANDED_NO= (SELECT B.DEMANDED_NO FROM PUR2000T A, BID_MASTER B WHERE A.PUR_CONT_MOD_ID= '"+ params.get("PUR_CONT_MOD_ID") +"'  AND A.BID_NO=B.BID_NO  AND A.BID_DEG=B.BID_DEG) AND PR_TYPE IN ('20', '30')	\n");
		//	sqlstr.append("		AND NVL(EBID_STATUS_CD, '00') != '05'					\n");	
			sqlstr.append("	SELECT (SELECT MAX(DEMANDED_ID) AS DEMANDED_ID FROM PMM_DEMANDED_REQUEST WHERE DEMANDED_STATUS IN ('3','4') AND DEMANDED_NO = (SELECT MAX(DEMANDED_NO) FROM PMM_DEMANDED_REQUEST A1 WHERE DEMANDED_ID = A.DEMANDED_ID)) AS DEMANDED_ID			\n");
			sqlstr.append("	FROM PMM_DEMANDED_REQUEST A	\n");
			sqlstr.append("	WHERE DEMANDED_ID = (SELECT DEM_ID FROM PUR2000T WHERE DEM_ID IS NOT NULL AND PUR_CONT_MOD_ID = '"+ params.get("PUR_CONT_MOD_ID") +"')		\n");	

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

            WAFLogger.error(this.getClass().getName() + " --> getNextPgmGrSeq() : " + e.getMessage());
            WAFLogger.error("SQL : " + search.getStatement());
            WAFLogger.error(e);
            return null;
        }
    }

	/**
     * 변경 계약 정보 추가
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public boolean addChangeContProc(Connection connection, ValueObject valueObject) throws Exception {
		//WAFLogger.debug("valueObject : " + valueObject);

        try {
        	conn.begin();

        	addChangeContPur(super.conn.getConnection(), params);	//변경 계약 축
        	
			addChangeContSupport(super.conn.getConnection(), params);	//변경 계약 축
			
			addChangeContItem(super.conn.getConnection(), params);	//변경계약 아이템 저장
			
			//DEMANDED_ID 가 있으면 다른쪽 상태값 업데이트를 한다.
			if(!valueObject.get("pDemID").isEmpty()){
				upDemandidProc(super.conn.getConnection(), params);	//다른 테이블 업데이트
			}
			
//			orgContChgStatus(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);
            this.storage.setSuccess(false);
            this.storage.setMessage(e.getMessage());
            storage.setDetailMessage(e);
            
            conn.setRollback();
            return false;
        }
        finally {
        	super.conn.end();
        }        
    }	

	/**
     * 변경 계약 업체 정보 추가
	 * @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("         ,		CONT_HASH		\n");
			sqlstr.append("         ,		CONT_HTML		\n");
			sqlstr.append("         ,		TRUE_RANDOM		\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("         ,		DIV_PO_YN	\n");//2016.11.7 단가계약여부 생성 
			sqlstr.append("         ,		DEM_ID		\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,ERP_NO_ECUT	)	\n");
			sqlstr.append("SELECT ?	\n");
			sqlstr.append("         ,		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("         ,		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("         ,		NULL		\n");
			sqlstr.append("         ,		NULL		\n");
			sqlstr.append("         ,		NULL		\n");
			sqlstr.append("         ,		BID_NO		\n");
			sqlstr.append("         ,		BID_DEG		\n");
			sqlstr.append("         ,		'00'		\n");
			sqlstr.append("         ,		NULL		\n");
			sqlstr.append("         ,		MODI_REQ_REASON		\n");
			sqlstr.append("         ,		MODI_REQ_DT		\n");
			sqlstr.append("         ,		1		\n");
			sqlstr.append("         ,		PAY_DIV		\n");
			sqlstr.append("         ,		DIV_PO_YN	\n"); //2016.11.7 단가계약여부 생성 
			sqlstr.append("         ,		?		\n");
			sqlstr.append("			,        CHG_CON_AMT                                                \n");
        	sqlstr.append("			,        CHG_EXE_AMT                                                \n");
        	sqlstr.append("		    ,        CHG_CON_AMT                                                 \n");
        	sqlstr.append("			,        CHG_EXE_AMT                                                 \n");
			sqlstr.append("         ,	?		\n");
			sqlstr.append("         ,	SYSDATE, ERP_NO_ECUT				\n");
			sqlstr.append("  FROM PUR2000T 				\n");
			sqlstr.append(" WHERE PUR_CONT_MOD_ID= ?									\n");
					
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(valueObject.get("maxPurContid"));
			persistent.addParameter(valueObject.get("pDemID"));
			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 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 {
        	if(valueObject.get("pDemID").isEmpty()){
				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("         ,	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("         ,	?				\n");
				sqlstr.append("         ,	SYSDATE			\n");
				sqlstr.append("  FROM CONT_PUR_ITEM 		\n");
				sqlstr.append(" WHERE 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"));
				
        	}else{				
			
				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("			, A1.MATERIAL_CD				\n");
				sqlstr.append("         ,	?				\n");
				sqlstr.append("		    , (SELECT MATERIAL_NAME FROM PMM_COMM_MATERIAL_MASTER WHERE MATERIAL_CD=A1.MATERIAL_CD) ITEM_NAME -- 품명 				\n");
				sqlstr.append("		    , F_GET_MATL_SPEC_NAME(A1.MATERIAL_CD) ITEM_SPEC -- 규격 				\n");
				sqlstr.append("		    , (SELECT UNIT_KIND FROM PMM_COMM_MATERIAL_MASTER WHERE MATERIAL_CD=A1.MATERIAL_CD) ITEM_UNIT -- 단위 				\n");
				sqlstr.append("		    , A1.DEMANDED_QTY				\n");
				sqlstr.append("		    , A1.DEMANDED_PRI				\n");
				sqlstr.append("		    , A1.DEMANDED_QTY * A1.DEMANDED_PRI AS ITEM_AMT				\n");
				sqlstr.append("         ,	?				\n");
				sqlstr.append("         ,	SYSDATE			\n");
				sqlstr.append("		FROM PMM_DEMANDED_ITEM A1				\n");
				sqlstr.append("		WHERE DEMANDED_ID= ? AND DEMANDED_QTY>0						\n");	
							
				persistent.setStatement(sqlstr.toString());
				persistent.addParameter(valueObject.get("maxPurContid"));
				persistent.addParameter(valueObject.get("PUR_CONT_ID"));
				persistent.addParameter(storage.getUser().get("acct_id"));
				persistent.addParameter(valueObject.get("pDemID"));
        	}
        	
			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 orgContChgStatus(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("UPDATE PUR2000T SET  	\n");
        	sqlstr.append(" CON_CLS_YN = 2					\n");
        	sqlstr.append("WHERE PUR_CONT_MOD_ID = ?						\n");
            persistent.setStatement(sqlstr.toString());  
            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 updatePayItem(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        Persistent persistent2 = new PersistentImpl(connection);
        Persistent persistent3 = new PersistentImpl(connection);
        Persistent persistent4 = new PersistentImpl(connection);
        Persistent persistent5 = new PersistentImpl(connection);
        Persistent persistent6 = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        StrBuffer sqlstr2 = new StrBuffer();
        StrBuffer sqlstr3 = new StrBuffer();
        StrBuffer sqlstr4 = new StrBuffer();
        StrBuffer sqlstr5 = new StrBuffer();
        StrBuffer sqlstr6 = new StrBuffer();
        
        try {
        	sqlstr.append("UPDATE PUR2000T SET  	\n");
        	sqlstr.append(" 	  ACCT_GB  =  '"+ valueObject.get("ACCT_GB") +"' 	\n");	
        	sqlstr.append(" 	 , PAY_GROUP  =  '"+ valueObject.get("PAY_GROUP") +"' 	\n");	
        	sqlstr.append(" 	 , GUA_GB  =  '"+ valueObject.get("GUA_GB") +"' 	\n");	
        	sqlstr.append(" 	 , PAYMENT_TERMS  =  '"+ valueObject.get("PAYMENT_TERMS") +"' 	\n");	
        	sqlstr.append(" 	 , PAY_ITEM  =  '"+ valueObject.get("PAY_ITEM") +"' 	\n");	
        	sqlstr.append(" 	 , COST_CODE  =  '"+ valueObject.get("COST_CODE") +"' 	\n");	
        	sqlstr.append(" 	 , COST_TYPE  =  '"+ valueObject.get("COST_TYPE") +"' 	\n");	
        	sqlstr.append("WHERE PUR_CONT_MOD_ID = ?						\n");
            persistent.setStatement(sqlstr.toString());  
            persistent.addParameter(valueObject.get("PUR_CONT_MOD_ID"));
            persistent.execute();
           
            sqlstr2.append("UPDATE PUR1000T SET  	\n");
            sqlstr2.append(" 	  ACCT_GB  =  '"+ valueObject.get("ACCT_GB") +"' 	\n");	
            sqlstr2.append(" 	 , PAY_GROUP  =  '"+ valueObject.get("PAY_GROUP") +"' 	\n");	
            sqlstr2.append(" 	 , GUA_GB  =  '"+ valueObject.get("GUA_GB") +"' 	\n");	
            sqlstr2.append(" 	 , PAYMENT_TERMS  =  '"+ valueObject.get("PAYMENT_TERMS") +"' 	\n");	
            sqlstr2.append(" 	 , PAY_ITEM  =  '"+ valueObject.get("PAY_ITEM") +"' 	\n");	
            sqlstr2.append(" 	 , COST_CODE  =  '"+ valueObject.get("COST_CODE") +"' 	\n");	
            sqlstr2.append(" 	 , COST_TYPE  =  '"+ valueObject.get("COST_TYPE") +"' 	\n");	
            sqlstr2.append("WHERE PUR_CONT_ID = ?						\n");
            persistent2.setStatement(sqlstr2.toString());  
            persistent2.addParameter(valueObject.get("PUR_CONT_ID"));
            persistent2.execute();
         
            //2019.05.16 ERP계약자료 업데이트
            WAFConnectionImpl erpConn = new WAFConnectionImpl();
			try {
				erpConn.setDataSource("jdbc/erpiu");
				erpConn.begin();
				InterfacePurERPiU.updateErpContPayment(erpConn.getConnection(),valueObject);
			}catch(Exception e) {
				super.conn.setRollback();
				erpConn.setRollback();
				throw e;
			}finally {
				erpConn.close();
			}
            
            //2016.12.26추가
            sqlstr6.append("			UPDATE PMM_DEMANDED_REQUEST SET             							\n");
            sqlstr6.append("			       DEPT_CD = F_GET_R_DEPT_CD('"+ valueObject.get("dept_cd") +"')        \n");
            sqlstr6.append("			    ,  PAY_ITEM =  '"+ valueObject.get("PAY_ITEM") +"'                		\n");
            sqlstr6.append("			    ,  COST_CODE =  '"+ valueObject.get("COST_CODE") +"'                  	\n");
            sqlstr6.append("			    ,  COST_TYPE = '"+ valueObject.get("COST_TYPE") +"'                  	\n");
            sqlstr6.append("			WHERE DEMANDED_ID = ?           											\n");
            persistent6.setStatement(sqlstr6.toString());  
            persistent6.addParameter(valueObject.get("DEMANDED_ID"));
            persistent6.execute();
            return true;
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }	
	
	/**
     * demanded_id가 있을경우(변경 발주) 타 테이블 업데이트 처리
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public boolean upDemandidProc(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("UPDATE PMM_DEMANDED_REQUEST SET  	\n");
        	sqlstr.append("  EBID_STATUS_CD = '05'					\n");
        	sqlstr.append(" ,DEMANDED_STATUS = '4'					\n");
        	sqlstr.append("WHERE DEMANDED_ID = ?						\n");
            persistent.setStatement(sqlstr.toString());  
            persistent.addParameter(valueObject.get("pDemID"));
            persistent.execute();
            persistent.clear();
            
            sqlstr.reset();
            
        	/*sqlstr.append("UPDATE	WC_Z_ETEC_PMM_DEMANDED_REQUEST@ERPIU		\n");
        	sqlstr.append("SET		EBID_STATUS_CD = '05'						\n");
        	sqlstr.append("			,DEMANDED_STATUS = '4'						\n");
        	sqlstr.append("WHERE	DEMANDED_ID = "+valueObject.get("pDemID")+"	\n");
            persistent.setStatement(sqlstr.toString());  
            persistent.execute();
            persistent.clear();

            sqlstr.reset();*/
            
        	sqlstr.append("UPDATE ETECEPC.MR_REQ_PO SET  	\n");
        	sqlstr.append(" EBID_STATUS = '05'					\n");
        	sqlstr.append("WHERE BUYREQNO = ?						\n");
            persistent.setStatement(sqlstr.toString());  
            persistent.addParameter(valueObject.get("pDemID"));
            persistent.execute();

            return true;
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }
	
	/**
     * 인지세 List
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	private RowSet getStampList(ValueObject param) {

		Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        
        StrBuffer sqlstr = new StrBuffer();
        
        try{

        	sqlstr.append("    SELECT                                                                                                      \n");  
			sqlstr.append("            STAMP_DUTY_ID                                                                                       \n");
			sqlstr.append("           ,STAMP_DUTY_ISSUE_GB                                                                                 \n");    
			sqlstr.append("           ,STAMP_DUTY_NO                                                                                       \n");    
			sqlstr.append("           ,STAMP_DUTY_TAX                                                                                      \n");    
			sqlstr.append("           ,STAMP_DUTY_DATE                                                                                     \n");    
			sqlstr.append("           ,REMARK                                                                                              \n");
			sqlstr.append("           ,(SELECT DECODE(MAX(AA.FILE_ID), NULL, '파일첨부', '1') FROM PUB0510T AA, PUB0500T BB                \n");
			sqlstr.append("        		   WHERE AA.FILE_ID = BB.FILE_ID AND FILE_GB = 'PUR_STAMP_DUTY'                                    \n");
			sqlstr.append("        		   AND ID = B.STAMP_DUTY_ID) AS FILE_YN                                                            \n");
			sqlstr.append("           ,(SELECT MAX(AA.FILE_ID) FROM PUB0510T AA, PUB0500T BB                                               \n");
			sqlstr.append("        		   WHERE AA.FILE_ID = BB.FILE_ID AND FILE_GB = 'PUR_STAMP_DUTY'                                    \n");
			sqlstr.append("        		   AND ID = B.STAMP_DUTY_ID) AS FILE_ID                                                            \n");                                  
			sqlstr.append("    FROM PUR2000T A,                                                                                            \n"); 
			sqlstr.append("         STAMP_DUTY B                                                                                           \n"); 
			sqlstr.append("    WHERE A.PUR_CONT_MOD_ID = B.CONT_MOD_ID                                                                     \n");
			sqlstr.append("    AND B.STAMP_DUTY_TYPE(+) = '10'                                                                             \n");
			sqlstr.append("    AND A.PUR_CONT_MOD_ID = '"+params.get("PUR_CONT_MOD_ID")+"'                                                 \n");
			sqlstr.append("    ORDER BY STAMP_DUTY_ID 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);
            WAFLogger.error("### WAFSQLException : " + se.getMessage());
        }
        finally {    
            if(rowSet == null){
            	rowSet = new RowSetImpl();
            }
        }
        return rowSet;
	}
	
	
	/**
	 * 인지세구분 조회
	 * @param 
	 * @param 
	 * @return RowSet 
	 */
	public RowSet getStampIssue(){
		
		Search search = new SearchImpl();
		RowSet listRowSet = null;
		String sqlstr = "";
		
		try {
			sqlstr += " SELECT	DETAILCD, DETAILNM				\n"
					+ "	FROM	EBID_COM911T					\n"
					+ "	WHERE	BASECD = 'STAMP_DUTY_ISSUE_GB'	\n";
			
			search.setStatement(sqlstr);
			listRowSet = search.execute();
			
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			
			if( listRowSet == null ){
				listRowSet = new RowSetImpl();
			}
			
			return listRowSet;
		}
	}
	
	public boolean SP_PURCONT_COPY (ValueObject params) throws Exception{
		CallableStatement cs 	= null;
		String pssql			= "";
	
		pssql = "{call SP_PURCONT_COPY(?,?,?,?,?,?)}";
		try {
			cs = super.conn.getConnection().prepareCall(pssql);
			cs.setString(1, params.get("IN_PUR_CONT_MOD_ID"));
			cs.setString(2, params.get("IN_CORP_ID"));
			cs.setString(3, params.get("IN_ORD_DOC_NO"));
			cs.setString(4, params.get("IN_DEPT_CD"));
			cs.registerOutParameter(5, java.sql.Types.VARCHAR);
			cs.registerOutParameter(6, java.sql.Types.VARCHAR);
		    cs.execute();
		    return true;
		} catch (SQLException e) {
			e.printStackTrace();
			throw e;
		}
	}
	
	/**
     * 완료된계약 업체담당자 정보변경 2017.03.08
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public boolean updateSuppInfo(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        
        try {
        	sqlstr.append("UPDATE CONT_PUR_SUPP                              	\n");
        	sqlstr.append("   SET USER_NAME =  '"+ valueObject.get("C_USER_NAME") +"' 	\n");	
        	sqlstr.append("      ,POSITION  =  '"+ valueObject.get("C_POSITION") +"' 	\n");	
        	sqlstr.append("      ,HP        =  '"+ valueObject.get("C_HP") +"'     	    \n");	
        	sqlstr.append(" 	 ,EMAIL     =  '"+ valueObject.get("C_EMAIL") +"' 	    \n");	
        	sqlstr.append(" 	 ,TEL_NUM   =  '"+ valueObject.get("C_TEL_NUM") +"'     \n");	
        	sqlstr.append(" WHERE PUR_CONT_MOD_ID = ?		 				    \n");
        	sqlstr.append("   AND SIGN_SEQ = 2   						        \n");
        	 
            persistent.setStatement(sqlstr.toString());  
            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 updateContPayPlan(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        
        try {
        	sqlstr.append("UPDATE CONT_PUR_PAYPLAN                              				\n");
        	sqlstr.append("   SET PAY_YN = '"+valueObject.get("p_pay_yn")+"'                    	\n");
        	sqlstr.append(" WHERE PUR_CONT_MOD_ID = '"+valueObject.get("PUR_CONT_MOD_ID")+"'	\n");
        	sqlstr.append("   AND PAY_SEQ = '"+valueObject.get("p_pay_seq")+"'		 		    \n");
            persistent.setStatement(sqlstr.toString());  
            persistent.execute();
            
            return true;
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }
}