package kr.co.udapsoft.ebid.buyer.bid.purchase.biz;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.text.SimpleDateFormat;
import java.util.Date;

import kr.co.hsnc.common.base.WAFLogger;
import kr.co.hsnc.common.config.WAFConfig;
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.util.ValueObject;
import oracle.toplink.internal.ox.StrBuffer;

public class InterfacePurERPiU{
	
	/**
	 * 구매 발주의뢰 반려 상태 업데이트
	 * @param rtnReason
	 * @param userSabun
	 * @param userName
	 * @param demId
	 * @throws Exception
	 */
	public static void updateRejectPMM(String rtnReason, String userSabun, String userName, String demId) throws Exception {

		WAFConnectionImpl erpConn = new WAFConnectionImpl();
		erpConn.setDataSource("jdbc/erpiu");
		erpConn.begin();
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		String toDay = sdf.format(date);
		
        try{
	        	Persistent pstmt = new PersistentImpl(erpConn.getConnection());
	        	StrBuffer sqlstr = new StrBuffer();
	    		sqlstr.append("UPDATE WM_G_REQUEST_H	\n");
	    		sqlstr.append("SET		YN_RT = 'Y'				\n");
	            sqlstr.append("			,DC_RT = ?				\n");
	            sqlstr.append("			,NO_EMP_RT = ?			\n");
	            sqlstr.append("			,NM_EMP_RT = ?			\n");
	            sqlstr.append("			,DT_RT = ?				\n");
	            sqlstr.append("WHERE	DEMANDED_ID = ?			\n");
		       	pstmt.setStatement(sqlstr.toString());
		       	pstmt.addParameter(rtnReason);
		       	pstmt.addParameter(userSabun);
		       	pstmt.addParameter(userName);
		       	pstmt.addParameter(toDay);
		       	pstmt.addParameter(demId);
				pstmt.execute();
				pstmt.clearParameters();
				
				//2020.03.02 발주의뢰 반려수정. WM_Z_ETEC_REQUEST_H, WM_Z_ETEC_REQUEST_D 삭제 
				/*sqlstr = new StringBuffer();
				sqlstr.append("	UPDATE WM_Z_ETEC_REQUEST_H	\n");
				sqlstr.append("SET		YN_RT = 'Y'				\n");
	            sqlstr.append("			,DC_RT = ?				\n");
	            sqlstr.append("			,NO_EMP_RT = ?			\n");
	            sqlstr.append("			,NM_EMP_RT = ?			\n");
	            sqlstr.append("			,DT_RT = ?				\n");
	            sqlstr.append("WHERE	DEMANDED_ID = ?			\n");
		       	pstmt.setStatement(sqlstr.toString());
		       	pstmt.addParameter(rtnReason);
		       	pstmt.addParameter(userSabun);
		       	pstmt.addParameter(userName);
		       	pstmt.addParameter(toDay);
		       	pstmt.addParameter(demId);
				pstmt.execute();*/
				
				//전자조달 구매발주의뢰 반려시 결재상태 반려처리  2021.12.27 최훈석
				sqlstr = new StrBuffer();
	            sqlstr.append("UPDATE SIGN001T	 		                       \n");  
	            sqlstr.append("   SET SIGN_DECI_CLASS = '12'	   		   \n");  
	            sqlstr.append(" WHERE DOC_ID IN(				   \n");  
	            sqlstr.append(" 	  SELECT DOC_ID				   \n");
	            sqlstr.append("         FROM (SELECT DOC_ID, ROW_NUMBER() OVER(PARTITION BY A.KEY_COL1,A.KEY_COL2,A.KEY_COL3,A.KEY_COL4,A.KEY_COL5,A.KEY_COL6 ORDER BY A.CRE_DATE DESC) AS RK				   \n");
	            sqlstr.append("                 FROM SIGN001T A							\n");
	            sqlstr.append("                WHERE KEY_COL1 = 'ETEC'					\n");
	            sqlstr.append("                  AND key_col2 = 'WM'					\n");
	            sqlstr.append("                  AND KEY_COL6 = ?			   			\n");
	            sqlstr.append("                  AND SIGN_CLASS_CD ='ERPIU_prD'			\n");
	            sqlstr.append("                  AND SIGN_DECI_CLASS IS NOT NULL 	) B				   \n");
	            sqlstr.append(" 	   WHERE RK = 1)				   \n");           
	            
	            pstmt.setStatement(sqlstr.toString());  
	            pstmt.addParameter(demId);
	            pstmt.execute();
	            pstmt.clearParameters();
				
	            sqlstr = new StrBuffer();
	            sqlstr.append("DELETE	 		                       \n");  
	            sqlstr.append("  FROM WM_Z_ETEC_REQUEST_H	   		   \n");  
	            sqlstr.append(" WHERE DEMANDED_ID = ?				   \n");  
	            
	            pstmt.setStatement(sqlstr.toString());  
	            pstmt.addParameter(demId);
	            pstmt.execute();
	            pstmt.clearParameters();
	            
	            sqlstr = new StrBuffer();
	            sqlstr.append("DELETE	 		                       \n");  
	            sqlstr.append("  FROM WM_Z_ETEC_REQUEST_D	   		   \n");  
	            sqlstr.append(" WHERE DEMANDED_ID = ?				   \n");  
	            
	            pstmt.setStatement(sqlstr.toString());  
	            pstmt.addParameter(demId);
	            pstmt.execute();
	            pstmt.clearParameters();
	            
        }catch (WAFSQLException e){
			WAFLogger.error("InterfacePurERPiU --> updateRejectPMM() : " + e.getMessage());
			WAFLogger.error(e);
			erpConn.setRollback();
			throw e;
        }finally{
        	erpConn.end();
        }
	}

	/**
	 * ERP거래처 등록
	 * @param connection
	 * @param vo
	 * @throws Exception
	 */
	public static void insertErpSupp(Connection connection, ValueObject vo) throws Exception {
		
		Persistent persistent = new PersistentImpl(connection);
		StrBuffer sqlstr = new StrBuffer();
		try {

			sqlstr.append(" INSERT  INTO MA_PARTNER (															\n");
			sqlstr.append("         CD_PARTNER	,CD_COMPANY	,LN_PARTNER		,USE_YN			,SN_PARTNER			\n");
			sqlstr.append("         ,EN_PARTNER	,TP_PARTNER	,FG_PARTNER		,NM_CEO			,NO_COMPANY			\n");
			sqlstr.append("         ,TP_JOB		,CLS_JOB	,CLS_PARTNER	,CD_NATION		,E_MAIL				\n");
			sqlstr.append("         ,NO_TEL		,NO_TEL1	,NO_FAX1		,CD_EMP_PARTNER	,NO_HPEMP_PARTNER	\n");
			sqlstr.append("         ,ID_INSERT	,DTS_INSERT	,NO_DEPOSIT 	,CD_BANK		,NO_POST1			\n");
			sqlstr.append("         ,DC_ADS1_H																	\n");
			sqlstr.append(" ) VALUES (																			\n");
			sqlstr.append("         ?			,?			,?				,?				,?					\n");
			sqlstr.append("         ,?			,?			,?				,?				,?					\n");
			sqlstr.append("         ,?			,?			,?				,?				,?					\n");
			sqlstr.append("         ,?			,?			,?				,?				,?					\n");
			sqlstr.append("         ,?			,?			,?				,?				,?					\n");
			sqlstr.append("         ,?																			\n");
			sqlstr.append(" )																					\n");
			
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(vo.get("CD_PARTNER",null));
			persistent.addParameter(vo.get("CD_COMPANY",null));
			persistent.addParameter(vo.get("LN_PARTNER",null));
			persistent.addParameter(vo.get("USE_YN",null));
			persistent.addParameter(vo.get("SN_PARTNER",null));
			persistent.addParameter(vo.get("EN_PARTNER",null));
			persistent.addParameter(vo.get("TP_PARTNER",null));
			persistent.addParameter(vo.get("FG_PARTNER",null));
			persistent.addParameter(vo.get("NM_CEO",null));
			persistent.addParameter(vo.get("NO_COMPANY",null));
			persistent.addParameter(vo.get("TP_JOB",null));
			persistent.addParameter(vo.get("CLS_JOB",null));
			persistent.addParameter(vo.get("CLS_PARTNER",null));
			persistent.addParameter(vo.get("CD_NATION",null));
			persistent.addParameter(vo.get("E_MAIL",null));
			persistent.addParameter(vo.get("NO_TEL",null));
			persistent.addParameter(vo.get("NO_TEL1",null));
			persistent.addParameter(vo.get("NO_FAX1",null));
			persistent.addParameter(vo.get("CD_EMP_PARTNER",null));
			persistent.addParameter(vo.get("NO_HPEMP_PARTNER",null));
			persistent.addParameter(vo.get("ID_INSERT",null));
			persistent.addParameter(vo.get("DTS_INSERT",null));
			persistent.addParameter(vo.get("NO_DEPOSIT",null));
			persistent.addParameter(vo.get("CD_BANK",null));
			persistent.addParameter(vo.get("NO_POST1",null));
			persistent.addParameter(vo.get("DC_ADS1_H",null));
			persistent.execute();
			
		}catch(Exception e) {
			WAFLogger.error("InterfacePurERPiU --> insertErpSupp() : " + e.getMessage());
			WAFLogger.error(e);
			throw e;
		}
	}
	
	//2019.04.17 거래처명 수정 추가
    public static void updateErpSupp(Connection connection, ValueObject vo) throws Exception {
		
		Persistent persistent = new PersistentImpl(connection);
		StrBuffer sqlstr = new StrBuffer();
		try {

			sqlstr.append(" UPDATE MA_PARTNER 															\n");
			sqlstr.append("    SET LN_PARTNER = ?   												    \n");
			sqlstr.append("       ,SN_PARTNER = ?                                                       \n");
			sqlstr.append("       ,NM_CEO     = ?                                                       \n");
			sqlstr.append("       ,TP_JOB     = ?                                                       \n");
			sqlstr.append("       ,CLS_JOB    = ?                                                       \n");
			sqlstr.append("       ,NO_POST1   = ?                                                       \n");
			sqlstr.append("       ,DC_ADS1_H  = ?                                                       \n");
			sqlstr.append("       ,NO_DEPOSIT = ?                                                       \n");
			sqlstr.append("       ,CD_BANK    = ?                                                       \n");
			sqlstr.append("       ,E_MAIL     = ?                                                       \n");
			sqlstr.append("       ,USE_YN     = 'N'                                                     \n");
			sqlstr.append("  WHERE CD_PARTNER = ?   												    \n");
			sqlstr.append("    AND CD_COMPANY = 'ETEC' 												    \n");
			 
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(vo.get("LN_PARTNER",null));
			persistent.addParameter(vo.get("SN_PARTNER",null));
			persistent.addParameter(vo.get("NM_CEO",null));
			persistent.addParameter(vo.get("TP_JOB",null));
			persistent.addParameter(vo.get("CLS_JOB",null));
			persistent.addParameter(vo.get("NO_POST1",null));
			persistent.addParameter(vo.get("DC_ADS1_H",null));
			persistent.addParameter(vo.get("NO_DEPOSIT",null));
			persistent.addParameter(vo.get("CD_BANK",null));
			persistent.addParameter(vo.get("E_MAIL",null));
			persistent.addParameter(vo.get("CD_PARTNER",null));  
			persistent.execute();
			
		}catch(Exception e) {
			WAFLogger.error("InterfacePurERPiU --> insertErpSupp() : " + e.getMessage());
			WAFLogger.error(e);
			throw e;
		}
	}

	/**
	 * 구매 계약 마스터 등록
	 * @param connection
	 * @param vo
	 * @throws Exception
	 */
	public static void insertErpContMst(Connection connection, ValueObject vo) throws Exception {
		
		Persistent persistent = new PersistentImpl(connection);
		StrBuffer sqlstr = new StrBuffer();
		try {
			sqlstr.append("INSERT  INTO WM_E_EXECUTE_H (																				\n");
			sqlstr.append("		WM_CM00301		,YM_ECUT			,NO_ECUT			,CD_COMPANY				,CD_SITE				\n");
			sqlstr.append("		,DT_ECUT		,DT_MK_ECUT			,NM_MK_ECUT			,NM_ECUT				,WM_CM00302				\n");
			sqlstr.append("		,WM_CM00303		,DT_DELV			,LOCATE_DELV		,WM_CM00206				,DESC_CM00206			\n");
			sqlstr.append("		,TAG_VAT		,CD_COOP			,NO_COMPANY			,NM_COOP				,AMT_ECUT				\n");
			sqlstr.append("		,VAT_ECUT		,AMT_CONT_ASSURANCE	,RT_CONT_ASSURANCE	,AMT_PREPAY_ASSURANCE	,RT_PREPAY_ASSURANCE	\n");
			sqlstr.append("		,AMT_WARRANTY	,RT_WARRANTY		,DESC_AMT_DELAY		,DESC_ECUT				,ID_USER				\n");
			sqlstr.append("		,WM_CM00301_O	,YM_ECUT_O			,NO_ECUT_O			,ID_INSERT				,DTS_INSERT				\n");
			sqlstr.append("		,ID_UPDATE		,DTS_UPDATE			,CURR_SOUR			,UNT_CURR				,SAMT_CURR				\n");
			sqlstr.append("		,VAMT_CURR		,WM_CM00011			,NO_EMP				,NO_EMP_A				,CD_DEPT_A				\n");
			sqlstr.append("		,NM_KOR_A		,ID_USER_A			,CD_DEPT			,DT_AGREE				,DT_CONT				\n");
			sqlstr.append("		,NO_SEQ			,PUR_CONT_MOD_ID	,PUR_CONT_ID		,MOD_NO					,MOD_GB					\n");
			sqlstr.append("		,ORD_START_DATE	,ORD_END_DATE		,PAY_DIV			,DEM_ID					,ORD_DOC_NO				\n");
			sqlstr.append("		,REQ_DOC_NO		,TAG_UNITY			,WM_CM00205			,YN_CERT				,PROC_COM				\n");
        	sqlstr.append("     ,CD_COMPANY_A	,WM_CM00317			,CD_PROOF          	,CHG_CONT               ,AMT_ACT_ETEC           \n"); //2019.07.16
			sqlstr.append(") VALUES (																									\n");
			sqlstr.append("		?				,?					,?					,?						,?						\n");
			sqlstr.append("		,?				,?					,?					,?						,?						\n");
			sqlstr.append("		,?				,?					,?					,?						,?						\n");
			sqlstr.append("		,?				,?					,?					,?						,?						\n");
			sqlstr.append("		,?				,?					,?					,?						,?						\n");
			sqlstr.append("		,?				,?					,?					,?						,?						\n");
			sqlstr.append("		,?				,?					,?					,?						,?						\n");
			sqlstr.append("		,?				,?					,?					,?						,?						\n");
			sqlstr.append("		,?				,?					,?					,?						,?						\n");
			sqlstr.append("		,?				,?					,?					,?						,?						\n");
			sqlstr.append("		,?				,?					,?					,?						,?						\n");
			sqlstr.append("		,?				,?					,?					,?						,?						\n");
			sqlstr.append("		,?				,?					,?					,?						,?						\n");
			sqlstr.append("		,?				,?					,?					,0						,?						\n");
			sqlstr.append(")																											\n"); //2019.07.16
			
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(vo.get("WM_CM00301",null));
			persistent.addParameter(vo.get("YM_ECUT",null));
			persistent.addParameter(vo.get("NO_ECUT",null));
			persistent.addParameter(vo.get("CD_COMPANY",null));
			persistent.addParameter(vo.get("CD_SITE",null));
			persistent.addParameter(vo.get("DT_ECUT",null));
			persistent.addParameter(vo.get("DT_MK_ECUT",null));
			persistent.addParameter(vo.get("NM_MK_ECUT",null));
			persistent.addParameter(vo.get("NM_ECUT",null));
			persistent.addParameter(vo.get("WM_CM00302",null));
			persistent.addParameter(vo.get("WM_CM00303",null));
			persistent.addParameter(vo.get("DT_DELV",null));
			persistent.addParameter(vo.get("LOCATE_DELV",null));
			persistent.addParameter(vo.get("WM_CM00206",null));
			persistent.addParameter(vo.get("DESC_CM00206",null));
			persistent.addParameter(vo.get("TAG_VAT",null));
			persistent.addParameter(vo.get("CD_COOP",null));
			persistent.addParameter(vo.get("NO_COMPANY",null));
			persistent.addParameter(vo.get("NM_COOP",null));
			persistent.addParameter(vo.get("AMT_ECUT",null));
			persistent.addParameter(vo.get("VAT_ECUT",null));
			persistent.addParameter(vo.get("AMT_CONT_ASSURANCE",null));
			persistent.addParameter(vo.get("RT_CONT_ASSURANCE",null));
			persistent.addParameter(vo.get("AMT_PREPAY_ASSURANCE",null));
			persistent.addParameter(vo.get("RT_PREPAY_ASSURANCE",null));
			persistent.addParameter(vo.get("AMT_WARRANTY",null));
			persistent.addParameter(vo.get("RT_WARRANTY",null));
			persistent.addParameter(vo.get("DESC_AMT_DELAY",null));
			persistent.addParameter(vo.get("DESC_ECUT",null));
			persistent.addParameter(vo.get("ID_USER",null));
			persistent.addParameter(vo.get("WM_CM00301",null));
			persistent.addParameter(vo.get("YM_ECUT",null));
			persistent.addParameter(vo.get("NO_ECUT",null));
			persistent.addParameter(vo.get("ID_INSERT",null));
			persistent.addParameter(vo.get("DTS_INSERT",null));
			persistent.addParameter(vo.get("ID_UPDATE",null));
			persistent.addParameter(vo.get("DTS_UPDATE",null));
			persistent.addParameter(vo.get("CURR_SOUR",null));
			persistent.addParameter(vo.get("UNT_CURR",null));
			persistent.addParameter(vo.get("SAMT_CURR",null));
			persistent.addParameter(vo.get("VAMT_CURR",null));
			persistent.addParameter(vo.get("WM_CM00011",null));
			persistent.addParameter(vo.get("NO_EMP",null));
			persistent.addParameter(vo.get("NO_EMP_A",null));
			persistent.addParameter(vo.get("CD_DEPT_A",null));
			persistent.addParameter(vo.get("NM_KOR_A",null));
			persistent.addParameter(vo.get("ID_USER_A",null));
			persistent.addParameter(vo.get("CD_DEPT",null));
			persistent.addParameter(vo.get("DT_AGREE",null));
			persistent.addParameter(vo.get("DT_CONT",null));
			persistent.addParameter(vo.get("NO_SEQ",null));
			persistent.addParameter(vo.get("PUR_CONT_MOD_ID",null));
			persistent.addParameter(vo.get("PUR_CONT_ID",null));
			persistent.addParameter(vo.get("MOD_NO",null));
			persistent.addParameter(vo.get("MOD_GB",null));
			persistent.addParameter(vo.get("ORD_START_DATE",null));
			persistent.addParameter(vo.get("ORD_END_DATE",null));
			persistent.addParameter(vo.get("PAY_DIV",null));
			persistent.addParameter(vo.get("DEM_ID",null));
			persistent.addParameter(vo.get("ORD_DOC_NO",null));
			persistent.addParameter(vo.get("REQ_DOC_NO",null));
			persistent.addParameter(vo.get("TAG_UNITY",null));
			persistent.addParameter(vo.get("WM_CM00205",null));
			persistent.addParameter(vo.get("YN_CERT",null));
			persistent.addParameter(vo.get("PROC_COM",null));
			persistent.addParameter(vo.get("CD_COMPANY_A",null));
			persistent.addParameter(vo.get("WM_CM00317",null));
			persistent.addParameter(vo.get("CD_PROOF",null));
			persistent.addParameter(vo.get("AMT_ACT_ETEC",null)); //2019.07.16
			persistent.execute();
			
		}catch(Exception e) {
			WAFLogger.error("InterfacePurERPiU --> insertErpContMst() : " + e.getMessage());
			WAFLogger.error("SQL : " + sqlstr);
			WAFLogger.error(e);
			throw e;
		}
	}
	
	/**
	 * 구매 계약 마스터 수정
	 * @param connection
	 * @param vo
	 * @throws Exception
	 */
	public static void updateErpContMst(Connection connection, ValueObject vo) throws Exception {
		
		Persistent persistent = new PersistentImpl(connection);
		StrBuffer sqlstr = new StrBuffer();
		try {
			sqlstr.append("UPDATE	WM_E_EXECUTE_H				\n");
			sqlstr.append("SET		DT_ECUT = ?					\n");
			sqlstr.append("			,DT_MK_ECUT = ?				\n");
			sqlstr.append("			,NM_MK_ECUT = ?				\n");
			sqlstr.append("			,NM_ECUT = ?				\n");
			sqlstr.append("			,WM_CM00302 = ?				\n");
			sqlstr.append("			,WM_CM00303 = ?				\n");
			sqlstr.append("			,DT_DELV = ?				\n");
			sqlstr.append("			,LOCATE_DELV = ?			\n");
			sqlstr.append("			,WM_CM00206 = ?				\n");
			sqlstr.append("			,DESC_CM00206 = ?			\n");
			sqlstr.append("			,TAG_VAT = ?				\n");
			sqlstr.append("			,CD_COOP = ?				\n");
			sqlstr.append("			,NO_COMPANY = ?				\n");
			sqlstr.append("			,NM_COOP = ?				\n");
			sqlstr.append("			,AMT_ECUT = ?				\n");
			sqlstr.append("			,VAT_ECUT = ?				\n");
			sqlstr.append("			,AMT_CONT_ASSURANCE = ?		\n");
			sqlstr.append("			,RT_CONT_ASSURANCE = ?		\n");
			sqlstr.append("			,AMT_PREPAY_ASSURANCE = ?	\n");
			sqlstr.append("			,RT_PREPAY_ASSURANCE = ?	\n");
			sqlstr.append("			,AMT_WARRANTY = ?			\n");
			sqlstr.append("			,RT_WARRANTY = ?			\n");
			sqlstr.append("			,DESC_AMT_DELAY = ?			\n");
			sqlstr.append("			,DESC_ECUT = ?				\n");
			sqlstr.append("			,ID_USER = ?				\n");
			sqlstr.append("			,ID_UPDATE = ?				\n");
			sqlstr.append("			,DTS_UPDATE = ?				\n");
			sqlstr.append("			,CURR_SOUR = ?				\n");
			sqlstr.append("			,UNT_CURR = ?				\n");
			sqlstr.append("			,SAMT_CURR = ?				\n");
			sqlstr.append("			,VAMT_CURR = ?				\n");
			sqlstr.append("			,WM_CM00011 = ?				\n");
			sqlstr.append("			,NO_EMP = ?					\n");
			sqlstr.append("			,NO_EMP_A = ?				\n");
			sqlstr.append("			,CD_DEPT_A = ?				\n");
			sqlstr.append("			,NM_KOR_A = ?				\n");
			sqlstr.append("			,ID_USER_A = ?				\n");
			sqlstr.append("			,CD_DEPT = ?				\n");
			sqlstr.append("			,DT_AGREE = ?				\n");
			sqlstr.append("			,DT_CONT = ?				\n");
			sqlstr.append("			,NO_SEQ = ?					\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("			,ORD_START_DATE = ?			\n");
			sqlstr.append("			,ORD_END_DATE = ?			\n");
			sqlstr.append("			,PAY_DIV = ?				\n");
			sqlstr.append("			,DEM_ID = ?					\n");
			sqlstr.append("			,ORD_DOC_NO = ?				\n");
			sqlstr.append("			,REQ_DOC_NO = ?				\n");
			sqlstr.append("			,AMT_ACT_ETEC = ?			\n"); //2019.07.16
			sqlstr.append("			,CHG_CONT  = (CASE WHEN CHG_CONT = 2 THEN  0 ELSE CHG_CONT END	)	 \n");
			sqlstr.append("WHERE	WM_CM00301 = ?				\n");
			sqlstr.append("AND		YM_ECUT = ?					\n");
			sqlstr.append("AND		NO_ECUT = ?					\n");
			
			
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(vo.get("DT_ECUT",null));
			persistent.addParameter(vo.get("DT_MK_ECUT",null));
			persistent.addParameter(vo.get("NM_MK_ECUT",null));
			persistent.addParameter(vo.get("NM_ECUT",null));
			persistent.addParameter(vo.get("WM_CM00302",null));
			persistent.addParameter(vo.get("WM_CM00303",null));
			persistent.addParameter(vo.get("DT_DELV",null));
			persistent.addParameter(vo.get("LOCATE_DELV",null));
			persistent.addParameter(vo.get("WM_CM00206",null));
			persistent.addParameter(vo.get("DESC_CM00206",null));
			persistent.addParameter(vo.get("TAG_VAT",null));
			persistent.addParameter(vo.get("CD_COOP",null));
			persistent.addParameter(vo.get("NO_COMPANY",null));
			persistent.addParameter(vo.get("NM_COOP",null));
			persistent.addParameter(vo.get("AMT_ECUT",null));
			persistent.addParameter(vo.get("VAT_ECUT",null));
			persistent.addParameter(vo.get("AMT_CONT_ASSURANCE",null));
			persistent.addParameter(vo.get("RT_CONT_ASSURANCE",null));
			persistent.addParameter(vo.get("AMT_PREPAY_ASSURANCE",null));
			persistent.addParameter(vo.get("RT_PREPAY_ASSURANCE",null));
			persistent.addParameter(vo.get("AMT_WARRANTY",null));
			persistent.addParameter(vo.get("RT_WARRANTY",null));
			persistent.addParameter(vo.get("DESC_AMT_DELAY",null));
			persistent.addParameter(vo.get("DESC_ECUT",null));
			persistent.addParameter(vo.get("ID_USER",null));
			persistent.addParameter(vo.get("ID_UPDATE",null));
			persistent.addParameter(vo.get("DTS_UPDATE",null));
			persistent.addParameter(vo.get("CURR_SOUR",null));
			persistent.addParameter(vo.get("UNT_CURR",null));
			persistent.addParameter(vo.get("SAMT_CURR",null));
			persistent.addParameter(vo.get("VAMT_CURR",null));
			persistent.addParameter(vo.get("WM_CM00011",null));
			persistent.addParameter(vo.get("NO_EMP",null));
			persistent.addParameter(vo.get("NO_EMP_A",null));
			persistent.addParameter(vo.get("CD_DEPT_A",null));
			persistent.addParameter(vo.get("NM_KOR_A",null));
			persistent.addParameter(vo.get("ID_USER_A",null));
			persistent.addParameter(vo.get("CD_DEPT",null));
			persistent.addParameter(vo.get("DT_AGREE",null));
			persistent.addParameter(vo.get("DT_CONT",null));
			persistent.addParameter(vo.get("NO_SEQ",null));
			persistent.addParameter(vo.get("PUR_CONT_MOD_ID",null));
			persistent.addParameter(vo.get("PUR_CONT_ID",null));
			persistent.addParameter(vo.get("MOD_NO",null));
			persistent.addParameter(vo.get("MOD_GB",null));
			persistent.addParameter(vo.get("ORD_START_DATE",null));
			persistent.addParameter(vo.get("ORD_END_DATE",null));
			persistent.addParameter(vo.get("PAY_DIV",null));
			persistent.addParameter(vo.get("DEM_ID",null));
			persistent.addParameter(vo.get("ORD_DOC_NO",null));
			persistent.addParameter(vo.get("REQ_DOC_NO",null));
			persistent.addParameter(vo.get("AMT_ACT_ETEC",null)); //2019.07.16
			persistent.addParameter(vo.get("WM_CM00301",null));
			persistent.addParameter(vo.get("YM_ECUT_ORD",null));
			persistent.addParameter(vo.get("NO_ECUT_ORD",null));
			persistent.execute();
			
		}catch(Exception e) {
			WAFLogger.error("InterfacePurERPiU --> updateErpContMst() : " + e.getMessage());
			WAFLogger.error("SQL : " + sqlstr);
			WAFLogger.error(e);
			throw e;
		}
	}
	
	/**
	 * 구매 계약 내역 삭제
	 * @param connection
	 * @param vo
	 * @throws Exception
	 */
	public static void deleteErpContDet(Connection connection, ValueObject vo) throws Exception {
		
		Persistent persistent = new PersistentImpl(connection);
		StrBuffer sqlstr = new StrBuffer();
		try {
			sqlstr.append("DELETE	FROM WM_E_EXECUTE_D	\n");
			sqlstr.append("WHERE	WM_CM00301 = ?		\n");
			sqlstr.append("AND		YM_ECUT = ?			\n");
			sqlstr.append("AND		NO_ECUT = ?			\n");
			
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(vo.get("WM_CM00301"));
			persistent.addParameter(vo.get("YM_ECUT_ORD"));
			persistent.addParameter(vo.get("NO_ECUT_ORD"));
			persistent.execute();
			
		}catch(Exception e) {
			WAFLogger.error("InterfacePurERPiU --> deleteErpContDet() : " + e.getMessage());
			WAFLogger.error("SQL : " + sqlstr);
			WAFLogger.error(e);
			throw e;
		}
	}
	
	/**
	 * 구매 계약 공종 삭제
	 * @param connection
	 * @param vo
	 * @throws Exception
	 */
	public static void deleteErpContDetConst(Connection connection, ValueObject vo) throws Exception {
		
		Persistent persistent = new PersistentImpl(connection);
		StrBuffer sqlstr = new StrBuffer();
		try {
			sqlstr.append("DELETE	FROM WM_E_EXECUTE_C		\n");
			sqlstr.append("WHERE	WM_CM00301 = ?			\n");
			sqlstr.append("AND		YM_ECUT = ?				\n");
			sqlstr.append("AND		NO_ECUT = ?				\n");
			
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(vo.get("WM_CM00301"));
			persistent.addParameter(vo.get("YM_ECUT_ORD"));
			persistent.addParameter(vo.get("NO_ECUT_ORD"));
			persistent.execute();
			
		}catch(Exception e) {
			WAFLogger.error("InterfacePurERPiU --> deleteErpContDet() : " + e.getMessage());
			WAFLogger.error("SQL : " + sqlstr);
			WAFLogger.error(e);
			throw e;
		}
	}
	
	/**
	 * 구매 계약 마스터 이력 등록
	 * @param connection
	 * @param vo
	 * @throws Exception
	 */
	public static void insertErpContMstRev(Connection connection, ValueObject vo) throws Exception {
		
		Persistent persistent = new PersistentImpl(connection);
		StrBuffer sqlstr = new StrBuffer();
		try {
			sqlstr.append("INSERT  INTO WM_Z_ETEC_EXECUTE_H (							                                            	\n");
			sqlstr.append("		WM_CM00301		,YM_ECUT			,NO_ECUT			,CD_COMPANY				,CD_SITE				\n");
			sqlstr.append("		,DT_ECUT		,DT_MK_ECUT			,NM_MK_ECUT			,NM_ECUT				,WM_CM00302				\n");
			sqlstr.append("		,WM_CM00303		,DT_DELV			,LOCATE_DELV		,WM_CM00206				,DESC_CM00206			\n");
			sqlstr.append("		,TAG_VAT		,CD_COOP			,NO_COMPANY			,NM_COOP				,AMT_ECUT				\n");
			sqlstr.append("		,VAT_ECUT		,AMT_CONT_ASSURANCE	,RT_CONT_ASSURANCE	,AMT_PREPAY_ASSURANCE	,RT_PREPAY_ASSURANCE	\n");
			sqlstr.append("		,AMT_WARRANTY	,RT_WARRANTY		,DESC_AMT_DELAY		,DESC_ECUT				,ID_USER				\n");
			sqlstr.append("		,WM_CM00301_O	,YM_ECUT_O			,NO_ECUT_O			,ID_INSERT				,DTS_INSERT				\n");
			sqlstr.append("		,ID_UPDATE		,DTS_UPDATE			,CURR_SOUR			,UNT_CURR				,SAMT_CURR				\n");
			sqlstr.append("		,VAMT_CURR		,WM_CM00011			,NO_EMP				,NO_EMP_A				,CD_DEPT_A				\n");
			sqlstr.append("		,NM_KOR_A		,ID_USER_A			,CD_DEPT			,DT_AGREE				,DT_CONT				\n");
			sqlstr.append("		,NO_SEQ			,PUR_CONT_MOD_ID	,PUR_CONT_ID		,MOD_NO					,MOD_GB					\n");
			sqlstr.append("		,ORD_START_DATE	,ORD_END_DATE		,PAY_DIV			,DEM_ID					,ORD_DOC_NO				\n");
			sqlstr.append("		,REQ_DOC_NO		,TAG_UNITY			,WM_CM00205			,YN_CERT				,PROC_COM				\n");
        	sqlstr.append("     ,CD_COMPANY_A	,WM_CM00317			,CD_PROOF			,CHG_CONT				,AMT_ACT_ETEC		    \n");
			sqlstr.append(") VALUES (																									\n");
			sqlstr.append("     ?				,?					,?					,?						,?						\n");
			sqlstr.append("     ,?				,?					,?					,?						,?						\n");
			sqlstr.append("     ,?				,?					,?					,?						,?						\n");
			sqlstr.append("     ,?				,?					,?					,?						,?						\n");
			sqlstr.append("     ,?				,?					,?					,?						,?						\n");
			sqlstr.append("     ,?				,?					,?					,?						,?						\n");
			sqlstr.append("     ,?				,?					,?					,?						,?						\n");
			sqlstr.append("     ,?				,?					,?					,?						,?						\n");
			sqlstr.append("     ,?				,?					,?					,?						,?						\n");
			sqlstr.append("     ,?				,?					,?					,?						,?						\n");
			sqlstr.append("     ,?				,?					,?					,?						,?						\n");
			sqlstr.append("     ,?				,?					,?					,?						,?						\n");
			sqlstr.append("     ,?				,?					,?					,?						,?						\n");
			sqlstr.append("     ,?				,?					,?					,0  					,?						\n");
			sqlstr.append(")																											\n");
			
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(vo.get("WM_CM00301",null));
			persistent.addParameter(vo.get("YM_ECUT",null));
			persistent.addParameter(vo.get("NO_ECUT",null));
			persistent.addParameter(vo.get("CD_COMPANY",null));
			persistent.addParameter(vo.get("CD_SITE",null));
			persistent.addParameter(vo.get("DT_ECUT",null));
			persistent.addParameter(vo.get("DT_MK_ECUT",null));
			persistent.addParameter(vo.get("NM_MK_ECUT",null));
			persistent.addParameter(vo.get("NM_ECUT",null));
			persistent.addParameter(vo.get("WM_CM00302",null));
			persistent.addParameter(vo.get("WM_CM00303",null));
			persistent.addParameter(vo.get("DT_DELV",null));
			persistent.addParameter(vo.get("LOCATE_DELV",null));
			persistent.addParameter(vo.get("WM_CM00206",null));
			persistent.addParameter(vo.get("DESC_CM00206",null));
			persistent.addParameter(vo.get("TAG_VAT",null));
			persistent.addParameter(vo.get("CD_COOP",null));
			persistent.addParameter(vo.get("NO_COMPANY",null));
			persistent.addParameter(vo.get("NM_COOP",null));
			persistent.addParameter(vo.get("AMT_ECUT",null));
			persistent.addParameter(vo.get("VAT_ECUT",null));
			persistent.addParameter(vo.get("AMT_CONT_ASSURANCE",null));
			persistent.addParameter(vo.get("RT_CONT_ASSURANCE",null));
			persistent.addParameter(vo.get("AMT_PREPAY_ASSURANCE",null));
			persistent.addParameter(vo.get("RT_PREPAY_ASSURANCE",null));
			persistent.addParameter(vo.get("AMT_WARRANTY",null));
			persistent.addParameter(vo.get("RT_WARRANTY",null));
			persistent.addParameter(vo.get("DESC_AMT_DELAY",null));
			persistent.addParameter(vo.get("DESC_ECUT",null));
			persistent.addParameter(vo.get("ID_USER",null));
			persistent.addParameter(vo.get("WM_CM00301",null));
			persistent.addParameter(vo.get("YM_ECUT",null));
			persistent.addParameter(vo.get("NO_ECUT",null));
			persistent.addParameter(vo.get("ID_INSERT",null));
			persistent.addParameter(vo.get("DTS_INSERT",null));
			persistent.addParameter(vo.get("ID_UPDATE",null));
			persistent.addParameter(vo.get("DTS_UPDATE",null));
			persistent.addParameter(vo.get("CURR_SOUR",null));
			persistent.addParameter(vo.get("UNT_CURR",null));
			persistent.addParameter(vo.get("SAMT_CURR",null));
			persistent.addParameter(vo.get("VAMT_CURR",null));
			persistent.addParameter(vo.get("WM_CM00011",null));
			persistent.addParameter(vo.get("NO_EMP",null));
			persistent.addParameter(vo.get("NO_EMP_A",null));
			persistent.addParameter(vo.get("CD_DEPT_A",null));
			persistent.addParameter(vo.get("NM_KOR_A",null));
			persistent.addParameter(vo.get("ID_USER_A",null));
			persistent.addParameter(vo.get("CD_DEPT",null));
			persistent.addParameter(vo.get("DT_AGREE",null));
			persistent.addParameter(vo.get("DT_CONT",null));
			persistent.addParameter(vo.get("NO_SEQ",null));
			persistent.addParameter(vo.get("PUR_CONT_MOD_ID",null));
			persistent.addParameter(vo.get("PUR_CONT_ID",null));
			persistent.addParameter(vo.get("MOD_NO",null));
			persistent.addParameter(vo.get("MOD_GB",null));
			persistent.addParameter(vo.get("ORD_START_DATE",null));
			persistent.addParameter(vo.get("ORD_END_DATE",null));
			persistent.addParameter(vo.get("PAY_DIV",null));
			persistent.addParameter(vo.get("DEM_ID",null));
			persistent.addParameter(vo.get("ORD_DOC_NO",null));
			persistent.addParameter(vo.get("REQ_DOC_NO",null));
			persistent.addParameter(vo.get("TAG_UNITY",null));
			persistent.addParameter(vo.get("WM_CM00205",null));
			persistent.addParameter(vo.get("YN_CERT",null));
			persistent.addParameter(vo.get("PROC_COM",null));
			persistent.addParameter(vo.get("CD_COMPANY_A",null));
			persistent.addParameter(vo.get("WM_CM00317",null));
			persistent.addParameter(vo.get("CD_PROOF",null));
			persistent.addParameter(vo.get("AMT_ACT_ETEC",null));
			persistent.execute();
			
		}catch(Exception e) {
			WAFLogger.error("InterfacePurERPiU --> insertErpContMstRev() : " + e.getMessage());
			WAFLogger.error("SQL : " + sqlstr);
			WAFLogger.error(e);
			throw e;
		}
	}
	
	/**
	 * 구매 계약 내역 등록
	 * @param connection
	 * @param vo
	 * @param mstVo
	 * @throws Exception
	 */
	public static void insertErpContDet(Connection connection, ValueObject vo, ValueObject mstVo) throws Exception {
		
		Persistent persistent = new PersistentImpl(connection);
		StrBuffer sqlstr = new StrBuffer();
		try {
			
			sqlstr.append("INSERT	INTO WM_E_EXECUTE_D (													\n");
			sqlstr.append("		WM_CM00301			,YM_ECUT		,NO_ECUT	,SQ_ECUT	,CD_MAT			\n");
			sqlstr.append("		,NM_MAT				,CD_SORT		,NM_SORT	,CD_SIZE	,SIZE_MAT		\n");
			sqlstr.append("		,UNIT_MAT			,QTY_ECUT		,QTY_REMAIN	,UNT_ECUT	,AMT_ECUT		\n");
			sqlstr.append("		,VAT_ECUT			,CD_COMPANY		,CD_SITE	,YM_REQU	,NO_REQU		\n");
			sqlstr.append("		,SQ_REQU			,ID_INSERT		,DTS_INSERT	,ID_UPDATE	,DTS_UPDATE		\n");
			sqlstr.append("		,UNT_CURR			,UNT_E_CURR		,SAMT_CURR	,VAMT_CURR	,DT_DELV		\n");
			sqlstr.append("		,PUR_CONT_MOD_ID	,DT_ECUT		,WM_CM00302	,WM_CM00303	,CD_COOP		\n");
			sqlstr.append("		,NO_COMPANY			,NM_COOP		,PROC_COM	,NO_REV		,YM_ECUT_ORG	\n");
			sqlstr.append("		,NO_ECUT_ORG		,SQ_ECUT_ORG	,DT_AGREE	,NM_KOR_A	,WM_CM00304		\n");
			sqlstr.append("		,WM_CM00007																	\n");
			sqlstr.append(") VALUES (																		\n");
			sqlstr.append("		?					,?				,?			,?			,?				\n");
			sqlstr.append("		,?					,?				,?			,?			,?				\n");
			sqlstr.append("		,?					,?				,?			,?			,?				\n");
			sqlstr.append("		,?					,?				,?			,?			,?				\n");
			sqlstr.append("		,?					,?				,?			,?			,?				\n");
			sqlstr.append("		,?					,?				,?			,?			,?				\n");
			sqlstr.append("		,?					,?				,?			,?			,?				\n");
			sqlstr.append("		,?					,?				,?			,?			,?				\n");
			sqlstr.append("		,?					,?				,?			,?			,?				\n");
			sqlstr.append("		,?																			\n");
			sqlstr.append(")                                       \n");
			
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(vo.get("WM_CM00301",null));
			persistent.addParameter(vo.get("YM_ECUT",null));
			persistent.addParameter(vo.get("NO_ECUT",null));
			persistent.addParameter(vo.get("SQ_ECUT",null));
			persistent.addParameter(vo.get("CD_MAT",null));
			persistent.addParameter(vo.get("NM_MAT",null));
			persistent.addParameter(vo.get("CD_SORT",null));
			persistent.addParameter(vo.get("NM_SORT",null));
			persistent.addParameter(vo.get("CD_SIZE",null));
			persistent.addParameter(vo.get("SIZE_MAT",null));
			persistent.addParameter(vo.get("UNIT_MAT",null));
			persistent.addParameter(vo.get("QTY_ECUT",null));
			persistent.addParameter(vo.get("QTY_REMAIN",null));
			persistent.addParameter(vo.get("UNT_ECUT",null));
			persistent.addParameter(vo.get("AMT_ECUT",null));
			persistent.addParameter(vo.get("VAT_ECUT",null));
			persistent.addParameter(vo.get("CD_COMPANY",null));
			persistent.addParameter(vo.get("CD_SITE",null));
			persistent.addParameter(vo.get("YM_REQU",null));
			persistent.addParameter(vo.get("NO_REQU",null));
			persistent.addParameter(vo.get("SQ_REQU",null));
			persistent.addParameter(vo.get("ID_INSERT",null));
			persistent.addParameter(vo.get("DTS_INSERT",null));
			persistent.addParameter(vo.get("ID_UPDATE",null));
			persistent.addParameter(vo.get("DTS_UPDATE",null));
			persistent.addParameter(vo.get("UNT_CURR",null));
			persistent.addParameter(vo.get("UNT_E_CURR",null));
			persistent.addParameter(vo.get("SAMT_CURR",null));
			persistent.addParameter(vo.get("VAMT_CURR",null));
			persistent.addParameter(vo.get("DT_DELV",null));
			persistent.addParameter(vo.get("PUR_CONT_MOD_ID",null));
			persistent.addParameter(mstVo.get("DT_ECUT",null));
			persistent.addParameter(mstVo.get("WM_CM00302",null));
			persistent.addParameter(mstVo.get("WM_CM00303",null));
			persistent.addParameter(mstVo.get("CD_COOP",null));
			persistent.addParameter(mstVo.get("NO_COMPANY",null));
			persistent.addParameter(mstVo.get("NM_COOP",null));
			persistent.addParameter(mstVo.get("PROC_COM",null));
			persistent.addParameter(mstVo.get("NO_REV",null));
			persistent.addParameter(mstVo.get("YM_ECUT_ORG",null));
			persistent.addParameter(mstVo.get("NO_ECUT_ORG",null));
			persistent.addParameter(mstVo.get("SQ_ECUT_ORG",null));
			persistent.addParameter(mstVo.get("DT_AGREE",null));
			persistent.addParameter(mstVo.get("NM_KOR_A",null));
			persistent.addParameter(vo.get("WM_CM00304",null));
			persistent.addParameter(vo.get("WM_CM00007",null));
			persistent.execute();
			
		}catch(Exception e) {
			WAFLogger.error("InterfacePurERPiU --> insertErpContDet() : " + e.getMessage());
			WAFLogger.error("SQL : " + sqlstr);
			WAFLogger.error(e);
			throw e;
		}
	}
	
	/**
	 * 구매 계약 내역 이력 등록
	 * @param connection
	 * @param vo
	 * @param mstVo
	 * @throws Exception
	 */
	public static void insertErpContDetRev(Connection connection, ValueObject vo, ValueObject mstVo) throws Exception {
		
		Persistent persistent = new PersistentImpl(connection);
		StrBuffer sqlstr = new StrBuffer();
		try {
			
			sqlstr.append("INSERT	INTO WM_Z_ETEC_EXECUTE_D (												\n");
			sqlstr.append("		WM_CM00301			,YM_ECUT		,NO_ECUT	,SQ_ECUT	,CD_MAT			\n");
			sqlstr.append("		,NM_MAT				,CD_SORT		,NM_SORT	,CD_SIZE	,SIZE_MAT		\n");
			sqlstr.append("		,UNIT_MAT			,QTY_ECUT		,QTY_REMAIN	,UNT_ECUT	,AMT_ECUT		\n");
			sqlstr.append("		,VAT_ECUT			,CD_COMPANY		,CD_SITE	,YM_REQU	,NO_REQU		\n");
			sqlstr.append("		,SQ_REQU			,ID_INSERT		,DTS_INSERT	,ID_UPDATE	,DTS_UPDATE		\n");
			sqlstr.append("		,UNT_CURR			,UNT_E_CURR		,SAMT_CURR	,VAMT_CURR	,DT_DELV		\n");
			sqlstr.append("		,PUR_CONT_MOD_ID	,DT_ECUT		,WM_CM00302	,WM_CM00303	,CD_COOP		\n");
			sqlstr.append("		,NO_COMPANY			,NM_COOP		,PROC_COM	,NO_REV		,YM_ECUT_ORG	\n");
			sqlstr.append("		,NO_ECUT_ORG		,SQ_ECUT_ORG	,DT_AGREE	,NM_KOR_A	,WM_CM00304		\n");
			sqlstr.append("		,WM_CM00007																	\n");
			sqlstr.append(") VALUES (																		\n");
			sqlstr.append("		?					,?				,?			,?			,?				\n");
			sqlstr.append("		,?					,?				,?			,?			,?				\n");
			sqlstr.append("		,?					,?				,?			,?			,?				\n");
			sqlstr.append("		,?					,?				,?			,?			,?				\n");
			sqlstr.append("		,?					,?				,?			,?			,?				\n");
			sqlstr.append("		,?					,?				,?			,?			,?				\n");
			sqlstr.append("		,?					,?				,?			,?			,?				\n");
			sqlstr.append("		,?					,?				,?			,?			,?				\n");
			sqlstr.append("		,?					,?				,?			,?			,?				\n");
			sqlstr.append("		,?																			\n");
			sqlstr.append(")																				\n");
			
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(vo.get("WM_CM00301",null));
			persistent.addParameter(vo.get("YM_ECUT",null));
			persistent.addParameter(vo.get("NO_ECUT",null));
			persistent.addParameter(vo.get("SQ_ECUT",null));
			persistent.addParameter(vo.get("CD_MAT",null));
			persistent.addParameter(vo.get("NM_MAT",null));
			persistent.addParameter(vo.get("CD_SORT",null));
			persistent.addParameter(vo.get("NM_SORT",null));
			persistent.addParameter(vo.get("CD_SIZE",null));
			persistent.addParameter(vo.get("SIZE_MAT",null));
			persistent.addParameter(vo.get("UNIT_MAT",null));
			persistent.addParameter(vo.get("QTY_ECUT",null));
			persistent.addParameter(vo.get("QTY_REMAIN",null));
			persistent.addParameter(vo.get("UNT_ECUT",null));
			persistent.addParameter(vo.get("AMT_ECUT",null));
			persistent.addParameter(vo.get("VAT_ECUT",null));
			persistent.addParameter(vo.get("CD_COMPANY",null));
			persistent.addParameter(vo.get("CD_SITE",null));
			persistent.addParameter(vo.get("YM_REQU",null));
			persistent.addParameter(vo.get("NO_REQU",null));
			persistent.addParameter(vo.get("SQ_REQU",null));
			persistent.addParameter(vo.get("ID_INSERT",null));
			persistent.addParameter(vo.get("DTS_INSERT",null));
			persistent.addParameter(vo.get("ID_UPDATE",null));
			persistent.addParameter(vo.get("DTS_UPDATE",null));
			persistent.addParameter(vo.get("UNT_CURR",null));
			persistent.addParameter(vo.get("UNT_E_CURR",null));
			persistent.addParameter(vo.get("SAMT_CURR",null));
			persistent.addParameter(vo.get("VAMT_CURR",null));
			persistent.addParameter(vo.get("DT_DELV",null));
			persistent.addParameter(vo.get("PUR_CONT_MOD_ID",null));
			persistent.addParameter(mstVo.get("DT_ECUT",null));
			persistent.addParameter(mstVo.get("WM_CM00302",null));
			persistent.addParameter(mstVo.get("WM_CM00303",null));
			persistent.addParameter(mstVo.get("CD_COOP",null));
			persistent.addParameter(mstVo.get("NO_COMPANY",null));
			persistent.addParameter(mstVo.get("NM_COOP",null));
			persistent.addParameter(mstVo.get("PROC_COM",null));
			persistent.addParameter(mstVo.get("NO_REV",null));
			persistent.addParameter(mstVo.get("YM_ECUT_ORG",null));
			persistent.addParameter(mstVo.get("NO_ECUT_ORG",null));
			persistent.addParameter(mstVo.get("SQ_ECUT_ORG",null));
			persistent.addParameter(mstVo.get("DT_AGREE",null));
			persistent.addParameter(mstVo.get("NM_KOR_A",null));
			persistent.addParameter(vo.get("WM_CM00304",null));
			persistent.addParameter(vo.get("WM_CM00007",null));
			persistent.execute();
			
		}catch(Exception e) {
			WAFLogger.error("InterfacePurERPiU --> insertErpContDetRev() : " + e.getMessage());
			WAFLogger.error("SQL : " + sqlstr);
			WAFLogger.error(e);
			throw e;
		}
	}
	
	/**
	 * 구매 계약 내역 이력 등록
	 * @param connection
	 * @param vo
	 * @param mstVo
	 * @throws Exception
	 */
	public static void insertErpContDetConst(Connection connection, ValueObject vo, ValueObject mstVo) throws Exception {
		
		Persistent persistent = new PersistentImpl(connection);
		StrBuffer sqlstr = new StrBuffer();
		try {
			
			sqlstr.append("INSERT	INTO WM_E_EXECUTE_C (    												\n");
			sqlstr.append("		WM_CM00301	,YM_ECUT	,NO_ECUT		,SQ_ECUT		,CD_COMPANY			\n");
			sqlstr.append("		,CD_SITE	,SQ_CSTR	,CD_CSTR		,DL_CSTR		,NM_CSTR			\n");
			sqlstr.append("		,SIZE_CSTR	,UNIT_CSTR	,QTY_ECUT		,QTY_REMAIN		,UNT_ECUT			\n");
			sqlstr.append("		,AMT_ECUT	,VAT_ECUT	,YM_REQU		,NO_REQU		,SQ_REQU			\n");
			sqlstr.append("		,ID_INSERT	,DTS_INSERT	,ID_UPDATE		,DTS_UPDATE		,PUR_CONT_MOD_ID	\n");
			sqlstr.append("		,DT_ECUT	,WM_CM00302	,UNT_CURR		,CURR_SOUR		,QTY_ACT			\n");
			sqlstr.append("		,UNT_ACT	,AMT_ACT	,UNT_ACT_CURR	,AMT_ACT_CURR						\n");
			sqlstr.append(") VALUES (																		\n");
			sqlstr.append("		?			,?			,?				,?				,?					\n");
			sqlstr.append("		,?			,?			,?				,?				,?					\n");
			sqlstr.append("		,?			,?			,?				,?				,?					\n");
			sqlstr.append("		,?			,?			,?				,?				,?					\n");
			sqlstr.append("		,?			,?			,?				,?				,?					\n");
			sqlstr.append("		,?			,?			,?				,?				,?					\n");
			sqlstr.append("		,?			,?			,?				,?									\n");
			sqlstr.append(")																				\n");
			
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(vo.get("WM_CM00301",null));
			persistent.addParameter(vo.get("YM_ECUT",null));
			persistent.addParameter(vo.get("NO_ECUT",null));
			persistent.addParameter(vo.get("SQ_ECUT",null));
			persistent.addParameter(vo.get("CD_COMPANY",null));
			persistent.addParameter(vo.get("CD_SITE",null));
			persistent.addParameter(vo.get("SQ_CSTR",null));
			persistent.addParameter(vo.get("CD_CSTR",null));
			persistent.addParameter(vo.get("DL_CSTR",null));
			persistent.addParameter(vo.get("NM_CSTR",null));
			persistent.addParameter(vo.get("SIZE_CSTR",null));
			persistent.addParameter(vo.get("UNIT_CSTR",null));
			persistent.addParameter(vo.get("QTY_ECUT",null));
			persistent.addParameter(vo.get("QTY_REMAIN",null));
			persistent.addParameter(vo.get("UNT_ECUT",null));
			persistent.addParameter(vo.get("AMT_ECUT",null));
			persistent.addParameter(vo.get("VAT_ECUT",null));
			persistent.addParameter(vo.get("YM_REQU",null));
			persistent.addParameter(vo.get("NO_REQU",null));
			persistent.addParameter(vo.get("SQ_REQU",null));
			persistent.addParameter(vo.get("ID_INSERT",null));
			persistent.addParameter(vo.get("DTS_INSERT",null));
			persistent.addParameter(vo.get("ID_UPDATE",null));
			persistent.addParameter(vo.get("DTS_UPDATE",null));
			persistent.addParameter(vo.get("PUR_CONT_MOD_ID",null));
			persistent.addParameter(mstVo.get("DT_ECUT",null));
			persistent.addParameter(mstVo.get("WM_CM00302",null));
			persistent.addParameter(mstVo.get("UNT_CURR",null));
			persistent.addParameter(mstVo.get("CURR_SOUR",null));
			persistent.addParameter(vo.get("QTY_ACT",null));
			persistent.addParameter(vo.get("UNT_ACT",null));
			persistent.addParameter(vo.get("AMT_ACT",null));
			persistent.addParameter(vo.get("UNT_ACT_CURR",null));
			persistent.addParameter(vo.get("AMT_ACT_CURR",null));
			persistent.execute();
			
		}catch(Exception e) {
			WAFLogger.error("InterfacePurERPiU --> insertErpContDetConst() : " + e.getMessage());
			WAFLogger.error("SQL : " + sqlstr);
			WAFLogger.error(e);
			throw e;
		}
	}
	
	/**
	 * 구매 계약 공종 이력 등록
	 * @param connection
	 * @param vo
	 * @param mstVo
	 * @throws Exception
	 */
	public static void insertErpContDetConstRev(Connection connection, ValueObject vo, ValueObject mstVo) throws Exception {
		
		Persistent persistent = new PersistentImpl(connection);
		StrBuffer sqlstr = new StrBuffer();
		try {
			
			sqlstr.append("INSERT	INTO WM_Z_ETEC_EXECUTE_C (												\n");
			sqlstr.append("		WM_CM00301	,YM_ECUT	,NO_ECUT		,SQ_ECUT		,CD_COMPANY			\n");
			sqlstr.append("		,CD_SITE	,SQ_CSTR	,CD_CSTR		,DL_CSTR		,NM_CSTR			\n");
			sqlstr.append("		,SIZE_CSTR	,UNIT_CSTR	,QTY_ECUT		,QTY_REMAIN		,UNT_ECUT			\n");
			sqlstr.append("		,AMT_ECUT	,VAT_ECUT	,YM_REQU		,NO_REQU		,SQ_REQU			\n");
			sqlstr.append("		,ID_INSERT	,DTS_INSERT	,ID_UPDATE		,DTS_UPDATE		,PUR_CONT_MOD_ID	\n");
			sqlstr.append("		,DT_ECUT	,WM_CM00302	,UNT_CURR		,CURR_SOUR		,QTY_ACT			\n");
			sqlstr.append("		,UNT_ACT	,AMT_ACT	,UNT_ACT_CURR	,AMT_ACT_CURR						\n");
			sqlstr.append(") VALUES (																		\n");
			sqlstr.append("		?			,?			,?				,?				,?					\n");
			sqlstr.append("		,?			,?			,?				,?				,?					\n");
			sqlstr.append("		,?			,?			,?				,?				,?					\n");
			sqlstr.append("		,?			,?			,?				,?				,?					\n");
			sqlstr.append("		,?			,?			,?				,?				,?					\n");
			sqlstr.append("		,?			,?			,?				,?				,?					\n");
			sqlstr.append("		,?			,?			,?				,?									\n");
			sqlstr.append(")																				\n");
			
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(vo.get("WM_CM00301",null));
			persistent.addParameter(vo.get("YM_ECUT",null));
			persistent.addParameter(vo.get("NO_ECUT",null));
			persistent.addParameter(vo.get("SQ_ECUT",null));
			persistent.addParameter(vo.get("CD_COMPANY",null));
			persistent.addParameter(vo.get("CD_SITE",null));
			persistent.addParameter(vo.get("SQ_CSTR",null));
			persistent.addParameter(vo.get("CD_CSTR",null));
			persistent.addParameter(vo.get("DL_CSTR",null));
			persistent.addParameter(vo.get("NM_CSTR",null));
			persistent.addParameter(vo.get("SIZE_CSTR",null));
			persistent.addParameter(vo.get("UNIT_CSTR",null));
			persistent.addParameter(vo.get("QTY_ECUT",null));
			persistent.addParameter(vo.get("QTY_REMAIN",null));
			persistent.addParameter(vo.get("UNT_ECUT",null));
			persistent.addParameter(vo.get("AMT_ECUT",null));
			persistent.addParameter(vo.get("VAT_ECUT",null));
			persistent.addParameter(vo.get("YM_REQU",null));
			persistent.addParameter(vo.get("NO_REQU",null));
			persistent.addParameter(vo.get("SQ_REQU",null));
			persistent.addParameter(vo.get("ID_INSERT",null));
			persistent.addParameter(vo.get("DTS_INSERT",null));
			persistent.addParameter(vo.get("ID_UPDATE",null));
			persistent.addParameter(vo.get("DTS_UPDATE",null));
			persistent.addParameter(vo.get("PUR_CONT_MOD_ID",null));
			persistent.addParameter(mstVo.get("DT_ECUT",null));
			persistent.addParameter(mstVo.get("WM_CM00302",null));
			persistent.addParameter(mstVo.get("UNT_CURR",null));
			persistent.addParameter(mstVo.get("CURR_SOUR",null));
			persistent.addParameter(vo.get("QTY_ACT",null));
			persistent.addParameter(vo.get("UNT_ACT",null));
			persistent.addParameter(vo.get("AMT_ACT",null));
			persistent.addParameter(vo.get("UNT_ACT_CURR",null));
			persistent.addParameter(vo.get("AMT_ACT_CURR",null));
			persistent.execute();
			
		}catch(Exception e) {
			WAFLogger.error("InterfacePurERPiU --> insertErpContDetConstRev() : " + e.getMessage());
			WAFLogger.error("SQL : " + sqlstr);
			WAFLogger.error(e);
			throw e;
		}
	}
 
	//2019.05.16 완료된계약 payment수정 
    public static void updateErpContPayment(Connection connection, ValueObject vo) throws Exception {
		
		Persistent persistent1 = new PersistentImpl(connection);
		Persistent persistent2 = new PersistentImpl(connection);
		
		StrBuffer sqlstr1 = new StrBuffer();
		StrBuffer sqlstr2 = new StrBuffer();
		
		try {
			sqlstr1.append("UPDATE	WM_E_EXECUTE_H				                                    \n");
			sqlstr1.append("SET		WM_CM00206 = ?					                                \n");    
			sqlstr1.append("     ,	CD_PROOF = REPLACE(?,'Z99','')	                                \n");	//구매 계약 증빙종류 변경(자동전표랑 연관) 2022.11.29
			sqlstr1.append("WHERE	PUR_CONT_MOD_ID = ?				                                \n"); 
			persistent1.setStatement(sqlstr1.toString());
			persistent1.addParameter(vo.get("PAYMENT_TERMS",null)); 
			persistent1.addParameter(vo.get("GUA_GB",null));
			persistent1.addParameter(vo.get("PUR_CONT_MOD_ID",null)); 
			persistent1.execute();
			                                                                                        
			sqlstr2.append("UPDATE	WM_Z_ETEC_EXECUTE_H				                                \n");
			sqlstr2.append("SET		WM_CM00206 = ?					                                \n");
			sqlstr2.append("WHERE	PUR_CONT_MOD_ID = ?				                                \n"); 
			persistent2.setStatement(sqlstr2.toString());
			persistent2.addParameter(vo.get("PAYMENT_TERMS",null)); 
			persistent2.addParameter(vo.get("PUR_CONT_MOD_ID",null)); 
			persistent2.execute();
			
			
		}catch(Exception e) {
			WAFLogger.error("InterfacePurERPiU --> updateErpContPayment() : " + e.getMessage());
			WAFLogger.error("SQL : " + sqlstr1);
			WAFLogger.error(e);
			throw e;
		}
	}
	
	/**
	 * 구매 발주의뢰 (납품/설치) 구분 수정
	 * @param connection
	 * @param vo
	 * @throws Exception
	 */
	public static void updateWM_G_REQUEST_H(Connection connection, ValueObject vo) throws Exception {
		
		Persistent persistent = new PersistentImpl(connection);
		StrBuffer sqlstr = new StrBuffer();
		try {
			sqlstr.append("UPDATE	WM_G_REQUEST_H				\n");
			sqlstr.append("SET		PAY_DIV = ?					\n");
			sqlstr.append("WHERE	DEMANDED_ID = ?				\n");
			
			
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(vo.get("PAY_DIV",null));
			persistent.addParameter(vo.get("DEMANDED_ID",null));
			persistent.execute();
			
		}catch(Exception e) {
			WAFLogger.error("InterfacePurERPiU --> updateWM_G_REQUEST_H() : " + e.getMessage());
			WAFLogger.error("SQL : " + sqlstr);
			WAFLogger.error(e);
			throw e;
		}
	}
	
	/**
	 * 구매 발주의뢰 (납품/설치) 구분 수정
	 * @param connection
	 * @param vo
	 * @throws Exception
	 */
	public static void updateWM_Z_ETEC_REQUEST_H(Connection connection, ValueObject vo) throws Exception {
		
		Persistent persistent = new PersistentImpl(connection);
		StrBuffer sqlstr = new StrBuffer();
		try {
			sqlstr.append("UPDATE	WM_Z_ETEC_REQUEST_H				\n");
			sqlstr.append("SET		PAY_DIV = ?					\n");
			sqlstr.append("WHERE	DEMANDED_ID = ?				\n");
			
			
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(vo.get("PAY_DIV",null));
			persistent.addParameter(vo.get("DEMANDED_ID",null));
			persistent.execute();
			
		}catch(Exception e) {
			WAFLogger.error("InterfacePurERPiU --> updateWM_G_REQUEST_H() : " + e.getMessage());
			WAFLogger.error("SQL : " + sqlstr);
			WAFLogger.error(e);
			throw e;
		}
	}

	/**
	 * 변경발주 상태 업데이트
	 * @param demId
	 * @param statusCd
	 * @param chgReqStatus
	 * @throws Exception
	 */
	public static void updateStatusPMM(String demId, String statusCd, String chgReqStatus) throws Exception{
		
		WAFConnectionImpl erpConn = new WAFConnectionImpl();
		try{
			erpConn.setDataSource("jdbc/erpiu");
			erpConn.begin();
			Persistent pstmt = new PersistentImpl(erpConn.getConnection());
        	StrBuffer sqlstr = new StrBuffer();
        	
        	sqlstr.append("UPDATE	WC_Z_ETEC_PMM_DEMANDED_REQUEST	\n");
            sqlstr.append("SET		EBID_STATUS_CD = ?				\n");
            sqlstr.append("			,CHG_REQ_STATUS = ?				\n");
            sqlstr.append("WHERE	DEMANDED_ID = ?					\n");
            pstmt.setStatement(sqlstr.toString());  
            pstmt.addParameter(statusCd);
            pstmt.addParameter(chgReqStatus);
            pstmt.addParameter(demId);
            pstmt.execute();
            
        }catch (WAFSQLException e){
			WAFLogger.error("InterfacePurERPiU --> updateStatusPMM() : " + e.getMessage());
			WAFLogger.error(e);
			erpConn.setRollback();
			throw e;
        }finally{
        	erpConn.end();
        }
		
	}
	

	/**
	 * ERP 거래처 CD_PARTNER 채번
	 * @return
	 * @throws Exception
	 */
	public static String getCdPartner() throws Exception {
		
		Search search = new SearchImpl();
		search.setDSName("jdbc/erpiu");
		RowSet rowSet = new RowSetImpl();
		StrBuffer sqlstr = new StrBuffer();
		String rtnStr = "";
		try{
			sqlstr.append("EXEC UP_FI_Z_ETEC_PARTNERSEQ '"+WAFConfig.get("waf.erp.cdCompany")+"'\n");
			
			search.setStatement(sqlstr.toString());
			rowSet = search.execute();
			if( rowSet != null && rowSet.size() > 0 ){
				rtnStr = rowSet.getRow(0).get(0);
			}
			
			return rtnStr;
			
		}catch(WAFSQLException se) {
			WAFLogger.error("InterfacePurERPiU --> getCdPartner() : " + se.getMessage());
			WAFLogger.error("SQL : " + sqlstr);
			WAFLogger.error(se);
			throw se;
		}
	}
	
	/**
	 * 구매 변경계약요청 반려
	 * @param demId
	 * @param userSabun
	 * @param userName
	 * @return
	 * @throws Exception
	 */
	public static void updateChangeContReject(String demId, String userSabun, String userName) throws Exception{
		
		WAFConnectionImpl erpConn = new WAFConnectionImpl();
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		String toDay = sdf.format(date);
		
		try{
			erpConn.setDataSource("jdbc/erpiu");
			erpConn.begin();
			Persistent pstmt = new PersistentImpl(erpConn.getConnection());
        	StrBuffer sqlstr = new StrBuffer();
            sqlstr.append("UPDATE	WM_G_REQUEST_H			\n");
            sqlstr.append("SET		YN_RT = 'Y'				\n");
            sqlstr.append("			,DC_RT = ?				\n");
            sqlstr.append("			,NO_EMP_RT = ?			\n");
            sqlstr.append("			,NM_EMP_RT = ?			\n");
            sqlstr.append("			,DT_RT = ?				\n");
            sqlstr.append("WHERE	DEMANDED_ID = ?			\n");
            
            pstmt.setStatement(sqlstr.toString());  
            pstmt.addParameter("변경계약요청 반려");
            pstmt.addParameter(userSabun);
            pstmt.addParameter(userName);
            pstmt.addParameter(toDay);
            pstmt.addParameter(demId);
            pstmt.execute();
            pstmt.clearParameters();
            
            //2019.06.21 변경계약 반려수정. WM_Z_ETEC_REQUEST_H, WM_Z_ETEC_REQUEST_D 삭제 
            /*sqlstr = new StrBuffer();
            sqlstr.append("UPDATE	WM_Z_ETEC_REQUEST_H		\n");
            sqlstr.append("SET		YN_RT = 'Y'				\n");
            sqlstr.append("			,DC_RT = ?				\n");
            sqlstr.append("			,NO_EMP_RT = ?			\n");
            sqlstr.append("			,NM_EMP_RT = ?			\n");
            sqlstr.append("			,DT_RT = ?				\n");
            sqlstr.append("WHERE	DEMANDED_ID = ?			\n");
            
            pstmt.setStatement(sqlstr.toString());  
            pstmt.addParameter("변경계약요청 반려");
            pstmt.addParameter(userSabun);
            pstmt.addParameter(userName);
            pstmt.addParameter(toDay);
            pstmt.addParameter(demId);
            pstmt.execute();*/
            sqlstr = new StrBuffer();
            sqlstr.append("DELETE	 		                       \n");  
            sqlstr.append("  FROM WM_Z_ETEC_REQUEST_H	   		   \n");  
            sqlstr.append(" WHERE DEMANDED_ID = ?				   \n");  
            
            pstmt.setStatement(sqlstr.toString());  
            pstmt.addParameter(demId);
            pstmt.execute();
            pstmt.clearParameters();
            
            sqlstr = new StrBuffer();
            sqlstr.append("DELETE	 		                       \n");  
            sqlstr.append("  FROM WM_Z_ETEC_REQUEST_D	   		   \n");  
            sqlstr.append(" WHERE DEMANDED_ID = ?				   \n");  
            
            pstmt.setStatement(sqlstr.toString());  
            pstmt.addParameter(demId);
            pstmt.execute();
            pstmt.clearParameters();
            
        }catch (WAFSQLException e){
			WAFLogger.error("InterfacePurERPiU --> updateChangeContReject() : " + e.getMessage());
			WAFLogger.error(e);
			erpConn.setRollback();
			throw e;
        }finally{
        	erpConn.end();
        }
		
	}
	
	/**
	 * 구매 자금신청 반려
	 * @param connection
	 * @param vo
	 * @throws Exception
	 */
	public static void updateBuiltReject(ValueObject vo, String userSabun, String userName) throws Exception {
		
		WAFConnectionImpl erpConn = new WAFConnectionImpl();
		erpConn.setDataSource("jdbc/erpiu");
		erpConn.begin();
		StrBuffer sqlstr = new StrBuffer();
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		String toDay = sdf.format(date);
		
		try {
			Persistent pstmt = new PersistentImpl(erpConn.getConnection());
			if(vo.get("pageDiv").equals("2")) {
				sqlstr.append("UPDATE	WM_S_STRG_IN_H			\n");
				sqlstr.append("SET		YN_RT = 'Y'				\n");
				sqlstr.append("			,DC_RT = ?				\n");
				sqlstr.append("			,NO_EMP_RT = ?			\n");
				sqlstr.append("			,NM_EMP_RT = ?			\n");
				sqlstr.append("			,DT_RT = ?				\n");
				sqlstr.append("			,DT_CHECK_APP = NULL	\n");
	        	sqlstr.append("			,NM_CHECK_APP = NULL	\n");
	        	sqlstr.append("			,ID_CHECK_APP = NULL	\n");
				sqlstr.append("WHERE	PAYREQ_ID = ?			\n");
			}else {
				sqlstr.append("UPDATE	WM_E_BUILT_H			\n");
				sqlstr.append("SET		YN_RT = 'Y'				\n");
				sqlstr.append("			,DC_RT = ?				\n");
				sqlstr.append("			,NO_EMP_RT = ?			\n");
				sqlstr.append("			,NM_EMP_RT = ?			\n");
				sqlstr.append("			,DT_RT = ?				\n");
				sqlstr.append("			,TAG_CONFIRM = NULL		\n");
				sqlstr.append("WHERE	PAYREQ_ID = ?			\n");
			}
			
			pstmt.setStatement(sqlstr.toString());
			pstmt.addParameter(vo.get("rtnReason1",null));
			pstmt.addParameter(userSabun);
			pstmt.addParameter(userName);
			pstmt.addParameter(toDay);
			pstmt.addParameter(vo.get("prepayId",null));
			pstmt.execute();
			
		}catch (WAFSQLException e){
			WAFLogger.error("InterfacePurERPiU --> updateBuiltReject() : " + e.getMessage());
			WAFLogger.error(e);
			erpConn.setRollback();
			throw e;
        }finally{
        	erpConn.end();
        }
	}

	/**
	 * 구매 선급금 등록
	 * @param vo
	 * @return
	 * @throws Exception
	 */
	public static void insertPrepayInfo(ValueObject vo, RowSet signUserInfo) throws Exception {
		WAFConnectionImpl erpConn = new WAFConnectionImpl();
		
		try{
			erpConn.setDataSource("jdbc/erpiu");
			erpConn.begin();
			Persistent pstmt = new PersistentImpl(erpConn.getConnection());
        	StrBuffer sqlstr = new StrBuffer();
        	
        	sqlstr.append("INSERT	INTO WM_E_EXECUTE_PREPAY (																\n");
        	sqlstr.append("		YY_PREPAY		,NO_PREPAY			,SQ_PREPAY		,CD_COMPANY			,CD_SITE			\n");
        	sqlstr.append("		,WM_CM00308		,DT_PREPAY			,WM_CM00301		,NO_ECUT			,YM_ECUT			\n");
        	sqlstr.append("		,CD_COOP		,NO_COMPANY			,AMT_PREPAY		,VAT_PREPAY			,DT_REQU			\n");
        	sqlstr.append("		,NM_REQU		,DT_CONFIRM			,NM_CONFIRM		,DESC_PREPAY		,ID_INSERT			\n");
        	sqlstr.append("		,DTS_INSERT		,CURR_SOUR			,UNT_CURR		,SAMT_CURR_PREPAY	,VAMT_CURR_PREPAY	\n");
        	sqlstr.append("		,PUR_CONT_ID	,PUR_CONT_MOD_ID	,PAY_SEQ		,PREPAY_ID			,YN_BAN				\n");
        	sqlstr.append("		,DOC_ID			,YN_ISS				,CD_COST_TRADE											\n");
        	sqlstr.append(") VALUES (																						\n");
        	sqlstr.append("		?				,?					,?				,?					,?					\n");
        	sqlstr.append("		,?				,?					,?				,?					,?					\n");
        	sqlstr.append("		,?				,?					,?				,?					,?					\n");
        	sqlstr.append("		,?				,?					,?				,?					,?					\n");
        	sqlstr.append("		,?				,?					,?				,?					,?					\n");
        	sqlstr.append("		,?				,?					,?				,?					,?					\n");
        	sqlstr.append("		,?				,?					,?														\n");
        	sqlstr.append(")																								\n");
        	
	       	pstmt.setStatement(sqlstr.toString());
	       	pstmt.addParameter(vo.get("YY_PREPAY",null));
	       	pstmt.addParameter(vo.get("NO_PREPAY",null));
	       	pstmt.addParameter(vo.get("SQ_PREPAY",null));
	       	pstmt.addParameter(vo.get("CD_COMPANY",null));
	       	pstmt.addParameter(vo.get("CD_SITE",null));
	       	pstmt.addParameter(vo.get("WM_CM00308",null));
	       	pstmt.addParameter(vo.get("DT_PREPAY",null));
	       	pstmt.addParameter(vo.get("WM_CM00301",null));
	       	pstmt.addParameter(vo.get("NO_ECUT",null));
	       	pstmt.addParameter(vo.get("YM_ECUT",null));
	       	pstmt.addParameter(vo.get("CD_COOP",null));
	       	pstmt.addParameter(vo.get("NO_COMPANY",null));
	       	pstmt.addParameter(vo.get("AMT_PREPAY",null));
	       	pstmt.addParameter(vo.get("VAT_PREPAY",null));
	       	pstmt.addParameter(vo.get("DT_REQU",null));
	       	pstmt.addParameter(vo.get("NM_REQU",null));
	       	pstmt.addParameter(vo.get("DT_CONFIRM",null));
	       	pstmt.addParameter(vo.get("NM_CONFIRM",null));
	       	pstmt.addParameter(vo.get("DESC_PREPAY",null));
	       	pstmt.addParameter(vo.get("ID_INSERT",null));
	       	pstmt.addParameter(vo.get("DTS_INSERT",null));
	       	pstmt.addParameter(vo.get("CURR_SOUR",null));
	       	pstmt.addParameter(vo.get("UNT_CURR",null));
	       	pstmt.addParameter(vo.get("SAMT_CURR_PREPAY",null));
	       	pstmt.addParameter(vo.get("VAMT_CURR_PREPAY",null));
	       	pstmt.addParameter(vo.get("PUR_CONT_ID",null));
	       	pstmt.addParameter(vo.get("PUR_CONT_MOD_ID",null));
	       	pstmt.addParameter(vo.get("PAY_SEQ",null));
	       	pstmt.addParameter(vo.get("PREPAY_ID",null));
	       	pstmt.addParameter(vo.get("YN_BAN",null));
	       	pstmt.addParameter(vo.get("DOC_ID",null));
	       	pstmt.addParameter(vo.get("YN_ISS",null));
	       	pstmt.addParameter(vo.get("CD_COST_TRADE",null)); //2019.07.29 ERP 자동분개를 위한 계정코드 추가
	       	pstmt.execute();
	       	pstmt.clearParameters();
	       	
	       	for ( int i = 0 ; i < signUserInfo.size() ; i++ ) {
	        	ValueObject signUser = new ValueObject();
	    		signUser.set("DOC_ID", 				vo.get("DOC_ID"));
	    		signUser.set("APRMEMBERSN", 		""+(i+1));
	    		signUser.set("APRMEMBERJOBTITLE", 	signUserInfo.getRow(i).get("APRMEMBERJOBTITLE"));
	    		signUser.set("APRMEMBERID", 		signUserInfo.getRow(i).get("SABUN"));
	    		signUser.set("APRMEMBERNAME", 		signUserInfo.getRow(i).get("APRMEMBERNAME"));
	        	signUser.set("PROCESSDATE", 		signUserInfo.getRow(i).get("PROCESSDATE"));
	        	insertApprovalLine(erpConn.getConnection(), signUser);
	        }
	       	
        }catch (Exception e){
			WAFLogger.error("InterfacePurERPiU --> insertPrepayInfo() : " + e.getMessage());
			WAFLogger.error(e);
			erpConn.setRollback();
			throw e;
        }finally{
        	erpConn.end();
        }
	}

	/**
	 * 구매 자금청구 확정(납품)
	 * @param vo
	 * @throws Exception
	 */
	public static void updateErpIuItem(ValueObject vo, RowSet signUserInfo) throws Exception {
		
		WAFConnectionImpl erpConn = new WAFConnectionImpl();
		
		try{
			erpConn.setDataSource("jdbc/erpiu");
			erpConn.begin();
			Persistent pstmt = new PersistentImpl(erpConn.getConnection());
        	StrBuffer sqlstr = new StrBuffer();
        	
        	sqlstr.append("UPDATE	WM_S_STRG_IN_H			\n");
        	sqlstr.append("SET		DT_CHECK_APP = ?		\n");
        	sqlstr.append("			,NM_CHECK_APP = ?		\n");
        	sqlstr.append("			,ID_CHECK_APP = ?		\n");
        	sqlstr.append("			,SAMT_DEDUCT = ?		\n");
        	sqlstr.append("			,VAMT_DEDUCT = ?		\n");
        	sqlstr.append("			,AMT_DEDUCT = ?			\n");
        	sqlstr.append("			,AMT_BUILT = ?			\n");//2019.04.03 **
        	sqlstr.append("			,SAMT_BUILT = ?			\n");
        	sqlstr.append("			,VAMT_BUILT = ?			\n");
        	sqlstr.append("			,SAMT_DEDUCT_CURR = ?	\n");
        	sqlstr.append("			,VAMT_DEDUCT_CURR = ?	\n");
        	sqlstr.append("			,AMT_DEDUCT_CURR = ?	\n");
        	sqlstr.append("			,AMT_BUILT_CURR = ?		\n");//2019.04.03 **
        	sqlstr.append("			,SAMT_BUILT_CURR = ?	\n");
        	sqlstr.append("			,VAMT_BUILT_CURR = ?	\n");
        	sqlstr.append("			,YN_ISS = ?				\n");
        	sqlstr.append("			,DOC_ID = ?				\n");
        	sqlstr.append("			,DT_STRG_IN = ?			\n");
        	sqlstr.append("			,CD_COST_TRADE = ?		\n");//2019.07.29 자동전표생성
        	sqlstr.append("WHERE	PAYREQ_ID = ?			\n");
        	
	       	pstmt.setStatement(sqlstr.toString());
	       	pstmt.addParameter(vo.get("DT_CHECK_APP",null));
	       	pstmt.addParameter(vo.get("NM_CHECK_APP",null));
	       	pstmt.addParameter(vo.get("ID_CHECK_APP",null));
	       	pstmt.addParameter(vo.get("SAMT_DEDUCT",null));
	       	pstmt.addParameter(vo.get("VAMT_DEDUCT",null));
	       	pstmt.addParameter(vo.get("AMT_DEDUCT",null));
	       	pstmt.addParameter(vo.get("AMT_BUILT",null));
	       	pstmt.addParameter(vo.get("SAMT_BUILT",null));
	       	pstmt.addParameter(vo.get("VAMT_BUILT",null));
	       	pstmt.addParameter(vo.get("SAMT_DEDUCT_CURR",null));
	       	pstmt.addParameter(vo.get("VAMT_DEDUCT_CURR",null));
	       	pstmt.addParameter(vo.get("AMT_DEDUCT_CURR",null));
	       	pstmt.addParameter(vo.get("AMT_BUILT_CURR",null));
	       	pstmt.addParameter(vo.get("SAMT_BUILT_CURR",null));
	       	pstmt.addParameter(vo.get("VAMT_BUILT_CURR",null));
	       	pstmt.addParameter(vo.get("YN_ISS",null));
	       	pstmt.addParameter(vo.get("DOC_ID",null));
	       	pstmt.addParameter(vo.get("DT_STRG_IN",null));
	       	pstmt.addParameter(vo.get("CD_COST_TRADE",null));
	       	pstmt.addParameter(vo.get("PAYREQ_ID",null));
			pstmt.execute();
			pstmt.clearParameters();
			
			for ( int i = 0 ; i < signUserInfo.size() ; i++ ) {
	        	ValueObject signUser = new ValueObject();
	    		signUser.set("DOC_ID", 				vo.get("DOC_ID"));
	    		signUser.set("APRMEMBERSN", 		""+(i+1));
	    		signUser.set("APRMEMBERJOBTITLE", 	signUserInfo.getRow(i).get("APRMEMBERJOBTITLE"));
	    		signUser.set("APRMEMBERID", 		signUserInfo.getRow(i).get("SABUN"));
	    		signUser.set("APRMEMBERNAME", 		signUserInfo.getRow(i).get("APRMEMBERNAME"));
//	    		signUser.set("APRMEMBERID", 		vo.get("REQ_SABUN",null));
//	    		signUser.set("APRMEMBERNAME", 		vo.get("REQ_NAME",null));
	        	signUser.set("PROCESSDATE", 		signUserInfo.getRow(i).get("PROCESSDATE"));
	        	insertApprovalLine(erpConn.getConnection(), signUser);
	        }
			
        }catch (Exception e){
			WAFLogger.error("InterfacePurERPiU --> updateErpIuItem() : " + e.getMessage());
			WAFLogger.error(e);
			erpConn.setRollback();
			throw e;
        }finally{
        	erpConn.end();
        }
	}
	
	/**
	 * 구매 자금청구 확정(설치)
	 * @param vo
	 * @throws Exception
	 */
	public static void updateErpIuInstall(ValueObject vo, RowSet signUserInfo) throws Exception {
		WAFConnectionImpl erpConn = new WAFConnectionImpl();
		
		try{
			erpConn.setDataSource("jdbc/erpiu");
			erpConn.begin();
			Persistent pstmt = new PersistentImpl(erpConn.getConnection());
			StrBuffer sqlstr = new StrBuffer();
			
			sqlstr.append("UPDATE	WM_E_BUILT_H			\n");
			sqlstr.append("SET		SAMT_DEDUCT = ?			\n");
			sqlstr.append("			,VAMT_DEDUCT = ?		\n");
			sqlstr.append("			,AMT_DEDUCT = ?			\n");
			sqlstr.append("			,AMT_BUILT = ?			\n"); //2019.04.03 **
			sqlstr.append("			,SAMT_BUILT = ?			\n");
			sqlstr.append("			,VAMT_BUILT = ?			\n");	
			sqlstr.append("			,SAMT_DEDUCT_CURR = ?	\n");
			sqlstr.append("			,VAMT_DEDUCT_CURR = ?	\n");
			sqlstr.append("			,AMT_DEDUCT_CURR = ?	\n");
			sqlstr.append("			,AMT_BUILT_CURR = ?		\n");//2019.04.03 **
			sqlstr.append("			,SAMT_BUILT_CURR = ?	\n");
			sqlstr.append("			,VAMT_BUILT_CURR = ?	\n");
			sqlstr.append("			,TAG_CONFIRM = 'Y'		\n");
			sqlstr.append("			,YN_ISS = ?				\n");
			sqlstr.append("			,DOC_ID = ?				\n");
			sqlstr.append("			,DT_BUILT = ?			\n");
			sqlstr.append("			,UNT_CURR = ?			\n");
			sqlstr.append("			,CD_COST_TRADE = ?		\n");//2019.07.29 자동전표생성
			sqlstr.append("WHERE	PAYREQ_ID = ?			\n");
			
			pstmt.setStatement(sqlstr.toString());
			pstmt.addParameter(vo.get("SAMT_DEDUCT",null));
			pstmt.addParameter(vo.get("VAMT_DEDUCT",null));
			pstmt.addParameter(vo.get("AMT_DEDUCT",null));
			pstmt.addParameter(vo.get("AMT_BUILT",null));
			pstmt.addParameter(vo.get("SAMT_BUILT",null));
			pstmt.addParameter(vo.get("VAMT_BUILT",null));
			pstmt.addParameter(vo.get("SAMT_DEDUCT_CURR",null));
			pstmt.addParameter(vo.get("VAMT_DEDUCT_CURR",null));
			pstmt.addParameter(vo.get("AMT_DEDUCT_CURR",null));
			pstmt.addParameter(vo.get("AMT_BUILT_CURR",null));
			pstmt.addParameter(vo.get("SAMT_BUILT_CURR",null));
			pstmt.addParameter(vo.get("VAMT_BUILT_CURR",null));
			pstmt.addParameter(vo.get("YN_ISS",null));
			pstmt.addParameter(vo.get("DOC_ID",null));
			pstmt.addParameter(vo.get("DT_BUILT",null));
			pstmt.addParameter(vo.get("UNT_CURR",null));
			pstmt.addParameter(vo.get("CD_COST_TRADE",null));
			pstmt.addParameter(vo.get("PAYREQ_ID",null));
			pstmt.execute();
			pstmt.clearParameters();
			
			for ( int i = 0 ; i < signUserInfo.size() ; i++ ) {
	        	ValueObject signUser = new ValueObject();
	    		signUser.set("DOC_ID", 				vo.get("DOC_ID"));
	    		signUser.set("APRMEMBERSN", 		""+(i+1));
	    		signUser.set("APRMEMBERJOBTITLE", 	signUserInfo.getRow(i).get("APRMEMBERJOBTITLE"));
	    		signUser.set("APRMEMBERID", 		signUserInfo.getRow(i).get("SABUN"));
	    		signUser.set("APRMEMBERNAME", 		signUserInfo.getRow(i).get("APRMEMBERNAME"));
//	    		signUser.set("APRMEMBERID", 		vo.get("REQ_SABUN",null));
//	    		signUser.set("APRMEMBERNAME", 		vo.get("REQ_NAME",null));
	        	signUser.set("PROCESSDATE", 		signUserInfo.getRow(i).get("PROCESSDATE"));
	        	insertApprovalLine(erpConn.getConnection(), signUser);
	        }
			
		}catch (Exception e){
			WAFLogger.error("InterfacePurERPiU --> updateErpIuInstall() : " + e.getMessage());
			WAFLogger.error(e);
			erpConn.setRollback();
			throw e;
		}finally{
			erpConn.end();
		}
	}
	
	/**
	 * 결재라인 등록
	 * @param connection
	 * @param vo
	 * @throws Exception
	 */
	public static void insertApprovalLine(Connection connection, ValueObject vo) throws Exception {
		
		try{
			Persistent pstmt = new PersistentImpl(connection);
			StrBuffer sqlstr = new StrBuffer();
			
			sqlstr.append(" INSERT	INTO TBENDAPRLINEINFO_EBID (														\n");
			sqlstr.append(" 		DOC_ID			,APRMEMBERSN	,APRMEMBERJOBTITLE	,APRMEMBERID	,APRMEMBERNAME	\n");
			sqlstr.append("     	,PROCESSDATE																		\n");
			sqlstr.append(" ) VALUES (																					\n");
			sqlstr.append("     	?				,?				,?					,?				,?				\n");
			sqlstr.append("     	,?																					\n");
			sqlstr.append(" )																							\n");
			pstmt.setStatement(sqlstr.toString());
			pstmt.addParameter(vo.get("DOC_ID",null));   
			pstmt.addParameter(vo.get("APRMEMBERSN",null));      
			pstmt.addParameter(vo.get("APRMEMBERJOBTITLE",null));   
			pstmt.addParameter(vo.get("APRMEMBERID",null));      
			pstmt.addParameter(vo.get("APRMEMBERNAME",null));    
			pstmt.addParameter(vo.get("PROCESSDATE",null));
			pstmt.execute();
			
		}catch (Exception e){
			WAFLogger.error("InterfacePurERPiU --> insertApprovalLine() : " + e.getMessage());
			WAFLogger.error(e);
			throw e;
		}
	}
	
	public static void ErpContDelete(Connection connection,String pur_cont_mod_id) throws Exception {

		Persistent persistent = new PersistentImpl(connection);
		StrBuffer sqlstr = new StrBuffer();
		try {
			sqlstr.append("DELETE FROM WM_E_EXECUTE_H  WHERE CD_COMPANY = 'ETEC' AND PUR_CONT_MOD_ID = ?           \n"); 
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(pur_cont_mod_id); 
			persistent.execute();
			persistent.clearParameters(); 
			
			sqlstr = new StrBuffer();			
			sqlstr.append("DELETE FROM WM_E_EXECUTE_D  WHERE CD_COMPANY = 'ETEC' AND PUR_CONT_MOD_ID = ?           \n");
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(pur_cont_mod_id); 
			persistent.execute();
			persistent.clearParameters();
			
			sqlstr = new StrBuffer(); 
			sqlstr.append("DELETE FROM WM_E_EXECUTE_C  WHERE CD_COMPANY = 'ETEC' AND PUR_CONT_MOD_ID = ?           \n"); 
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(pur_cont_mod_id); 
			persistent.execute();
			persistent.clearParameters();
			
			sqlstr = new StrBuffer();
			sqlstr.append("DELETE FROM WM_Z_ETEC_EXECUTE_H WHERE CD_COMPANY = 'ETEC' AND PUR_CONT_MOD_ID = ?       \n"); 
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(pur_cont_mod_id); 
			persistent.execute();
			persistent.clearParameters();
			
			sqlstr = new StrBuffer();
			sqlstr.append("DELETE FROM WM_Z_ETEC_EXECUTE_D WHERE CD_COMPANY = 'ETEC' AND PUR_CONT_MOD_ID = ?       \n");
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(pur_cont_mod_id); 
			persistent.execute();
			persistent.clearParameters();
			
			sqlstr = new StrBuffer(); 
			sqlstr.append("DELETE FROM WM_Z_ETEC_EXECUTE_C WHERE CD_COMPANY = 'ETEC' AND PUR_CONT_MOD_ID = ?       \n"); 
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(pur_cont_mod_id); 
			persistent.execute();
			persistent.clearParameters(); 
			
		}catch(Exception e) {
			WAFLogger.error("InterfacePurERPiU --> deleteErpContDet() : " + e.getMessage());
			WAFLogger.error("SQL : " + sqlstr);
			WAFLogger.error(e);
			throw e;
		} 
	}

	/**
	 * 타절계약 사업자번호 변경
	 * @return
	 * @throws Exception
	 */
	public static void execCoopChg(Connection connection, ValueObject vo) throws Exception {		
		CallableStatement cs 	= null;
		String pssql			= "";
		
		try{
			pssql = "{call UP_WC_Z_ETEC_COOP_CHG(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}";
			cs = connection.prepareCall(pssql);
			cs.setString(1, "02"); // 01.외주, 02.자재
			cs.setString(2, vo.get("CD_COMPANY",null)); // 회사코드
			cs.setString(3, vo.get("CD_SITE",null)); // 프로젝트코드
			cs.setString(4, ""); // 품의번호(외주)
			cs.setString(5, ""); // 품의순번(외주)
			cs.setString(6, vo.get("WM_CM00301",null)); // 품의구분(구매)
			cs.setString(7, vo.get("YM_ECUT",null)); // 품의년월(구매)
			cs.setString(8, vo.get("NO_ECUT",null)); // 품의번호(구매)
			cs.setString(9, vo.get("ORG_ERP_CD_PARTNER",null)); // 변경전 사업자번호
			cs.setString(10, vo.get("ERP_CD_PARTNER",null)); // 변경후 사업자번호
			cs.registerOutParameter(11, java.sql.Types.NVARCHAR);
			cs.registerOutParameter(12, java.sql.Types.NVARCHAR);
			cs.execute();

            if("N".equals(cs.getString(11))){
            	throw new Exception(cs.getString(12));
            }
		}catch(WAFSQLException se) {
			WAFLogger.error("InterfacePurERPiU --> execCoopChg() : " + se.getMessage());
			WAFLogger.error("SQL : " + pssql);
			WAFLogger.error(se);
			throw se;
		}		
	}
	
	
}
