/**
 * @(#)file    ContTargetBiz.java
 * @(#)author  Kim Myung Ho
 * @(#)version 1.0
 * @(#)date    2014-07-04
 * @(#)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.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Random;

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.StringUtil;
import kr.co.hsnc.common.util.ValueObject;
import kr.co.udapsoft.common.code.CommCodeManager;
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 ContTargetBiz extends Biz {

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

	public void doBiz() throws Exception {
        ValueObject user = new ValueObject();
   //     //WAFLogger.debug("BidIngListBiz :  ~" + storage.getUser());
	//	//WAFLogger.debug("Outside event : #" + storage.getEvent());
		//WAFLogger.debug("Outside params : " + params.get("rmdr_amt"));
		boolean success = false;
		
		if(storage.compareEvent("")){
			RowSet rowSet = getTemplateList_searchCombo(params.get("ChgCont"));
			//시트의 ComboBox데이터 설정 [상태]
			storage.addRowSet("TEMPLATE_LIST", rowSet);
			
		}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);

            RowSet template = getTemplateInfo(params.get("TEMPLATE_CD"));
            storage.addRowSet("template", template);
            
            RowSet itemList = getContItemList(params);
            //WAFLogger.debug("ITE LIST : ++++++++++++++++++++++++++++++++++++++++++ " + itemList.size());
            storage.addRowSet("itemList", itemList);
            
            //변경계약일경우 이전 차수에서 데이터를 가져온다.
            if(params.get("ChgCont").equals("Y")){
            	String oldContModId = getOldContNum(user);
            	if(!oldContModId.isEmpty()){
                    storage.addValueObject("OldContInfo", getContRequestValueObject(oldContModId));            		
            	}
            	
            	//변경계약내역서 추가 2019.08.06
            	params.set("pDemID", user.get("DEM_ID"));
            	params.set("PUR_CONT_ID", user.get("PUR_CONT_ID"));
            	RowSet chgItemList = getChgItemList(params);
            	storage.addRowSet("chgItemList", chgItemList);
            }

		}else if(storage.compareEvent("PARTNER_EMP_CHK")){
        	ValueObject empChk = getEmpChk(params.get("PUR_CONT_MOD_ID"), params.get("C_HP"));
	        storage.addValueObject("VALUEOBJECT", empChk);
        }else if(storage.compareEvent("FORM_SAVE")){
			//계약 정보 저장
			success = saveContProc(super.conn.getConnection(), params);
			
			super.storage.setSuccess(success);
		}else if(storage.compareEvent("FORM_DEL")){
			//변경계약 정보 삭제
			success = deleteContProc(super.conn.getConnection(), params);
			
			super.storage.setSuccess(success);
		}else if(storage.compareEvent("FORM_DEL_CHG")){
			//계약 정보 상태변경. 변경계약대상->변경계약접수로 이동 2017.04.12
				success = deleteContChgProc(super.conn.getConnection(), params);
				super.storage.setSuccess(success);
		}else if(storage.compareEvent("FORM_DELETE")){
			//계약 정보 삭제
			deleteContFile(params);
		}
	}

	private ValueObject getfilelist(String filegb,String id,String returnid){
		ValueObject vo = new ValueObject();
		RowSet rowSet = FileManager.getFileList(filegb, id);
		String str="";
	        for(int i=0;i<rowSet.size();i++){
	        	Row row=rowSet.getRow(i);
	        	str += (i+1)+" : "+row.get("FILE_NAME")+" ("+ row.get("FILE_SIZE")+")";
	        	if(i+1!=rowSet.size()){
	        		str +="\r\n";
	        	}
	        }
	        vo.set(returnid, str);
		return vo;
	}
	
	private String getfileHashlist(String filegb,String id){
		String fileHash="";
		RowSet rowSet = FileManager.getFileList(filegb, id);
		String str="";
		
		if( ("localhost").equals(storage.getRequest().getServerName()) ) {
			return fileHash;
		}
		
		if (rowSet.size()>0){
			PDFMaker pdfMaker = new PDFMaker();

			for(int i=0;i<rowSet.size();i++){
	        	Row row=rowSet.getRow(i);

	        	str = pdfMaker.getHash(WAFConfig.get("waf.repository.path") + row.get("FILE_PATH") +"/"+ row.get("REAL_FILE_NAME"));
	        	fileHash = fileHash + str +"|" ;
	        }
		}
		return fileHash;
	}	
	
	/*계약서 진위확인문자열을 구한다.*/
	public String getTrueRamdom(){
		Random r = new Random();
		int str =  r.nextInt(99999);
		return StringUtils.rightPad(str+"",5,"0");		
	}
	
	 /**
     * 계약서식 조회 combo 조회
	 * @param 
	 * @param 
	 * @return RowSet 
	 */
	public RowSet getTemplateInfo(String template_cd){

        Search search = new SearchImpl();
        RowSet listRowSet = null;
        String sqlstr = "";
        
        try {
            sqlstr += " SELECT            							\n"
            		+ "   TEMPLATE_CD,                              \n"
					+ "	  SEQ,                                      \n"
					+ "	  JOB_DIV,                                  \n"
					+ "	  TEMPLATE_NAME,                            \n"
					+ "	  TEMPLATE_HTML,                            \n"
					+ "	  TEMPLATE_STYLE,                           \n"
					+ "	  CHG_CONT_YN,                              \n"
					+ "	  OPTION_YN,                                \n"
					+ "	  DEFAULT_YN                                \n"
                    + " FROM CONT_TEMPLATE      					\n"
                    //+ " WHERE JOB_DIV = 'O'       					\n"
                    //+ "   AND TEMPLATE_CD =  '"+template_cd+"'		\n"
                    + " WHERE TEMPLATE_CD =  '"+template_cd+"'		\n"
		            + " ORDER BY TEMPLATE_CD 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 getTemplateList_searchCombo(String ChgContYN){

        Search search = new SearchImpl();
        RowSet listRowSet = null;
        String sqlstr = "";
        
        try {
            sqlstr += " SELECT TEMPLATE_CD, TEMPLATE_NAME           \n"
                    + " FROM CONT_TEMPLATE      					\n"
                    + " WHERE JOB_DIV IN ('P')       					\n"
                    + "   AND SEQ = '0'        						\n"
                    + "   AND NVL(CHG_CONT_YN,'N') = '"+ ChgContYN +"'       	\n"
		            + " ORDER BY TEMPLATE_CD 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(" 	     ,DECODE(A.CURRENCY_GB, 'KRW', DECODE(A.MOD_NO,0,DECODE(A.CON_GB,'1','4','2','3',A.CON_GB),6), DECODE(A.MOD_NO,0,9,10)) AS TEMPLATE_CD \n");
        	sqlstr.append(" 	     ,DECODE(DECODE(A.CURRENCY_GB, 'KRW', DECODE(A.MOD_NO,0,DECODE(A.CON_GB,'1','4','2','3',A.CON_GB),6), DECODE(A.MOD_NO,0,9,10)), NULL, 0, 1) AS BTN 	\n");
        	sqlstr.append(" 	     ,A.CURRENCY_GB 	\n");
        	sqlstr.append(" 	  FROM PUR2000T A, CONT_PUR_SUPP F	\n");
        	sqlstr.append("   WHERE 1=1					\n");
    		sqlstr.append("   	AND A.PUR_CONT_MOD_ID = F.PUR_CONT_MOD_ID(+)				\n");
    		sqlstr.append("   	AND F.SIGN_SEQ(+) = 2				\n");
        	if(params.get("ChgCont").equals("Y")){	//변경계약 대상
        		sqlstr.append("   	AND MOD_NO>0					\n");
        	}else{
        		sqlstr.append("   	AND MOD_NO=0					\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 '%"+param.get("P_BUILD_NM").toUpperCase()+"%'				\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 '%'|| '"+param.get("p_dealer_nm").toUpperCase()+"' ||'%'																						\n");
        	//if(!param.get("P_CONT_STATUS").isEmpty())
        	//	sqlstr.append("   AND A.STATUS_CD IN ("+param.get("P_CONT_STATUS")+")	2016.03.17																					\n");
        	sqlstr.append("   AND A.STATUS_CD = decode(A.MOD_NO , 0 , '00', '02') 	\n");
    		sqlstr.append("   	ORDER BY A.ORD_CON_DATE DESC			\n");
			search.setStatement(sqlstr.toString());
		    rowSet = search.execute();
        }
        catch (WAFSQLException se) {
            super.doException(se);
            this.storage.setSuccess(false);  
            this.storage.setMessage(se.getMessage());
            storage.setDetailMessage(se);
        }
        finally {    
            if(rowSet == null){
            	rowSet = new RowSetImpl();
            }
        }
        //WAFLogger.debug("### rowSet size : " + rowSet.size());
        return rowSet;
	}
	

	
	/**
	 * 계약 상세 정보
	 * @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.ORD_DOC_NO	\n");
	        	sqlstr.append(" 	     , A.MOD_NO	 AS 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(" 	     , A.ORD_CON_DATE	\n");	
	        	sqlstr.append(" 	     , A.PUR_CONT_ID	\n");	
	        	sqlstr.append(" 	     , A.ORD_AMT	\n");		
	        	sqlstr.append(" 	     , A.DEALER_NM	\n"); //2018.08.13
	        	sqlstr.append(" 	     , A.ORD_END_DATE	\n");//2018.08.13	
	        	sqlstr.append(" 	     , A.ORD_START_DATE	\n");	
	        	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(" 	     , A.ORD_END_DATE	\n");	
	        	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(" 	     , (SELECT CHG_CODE01 FROM EBID_COM911T WHERE BASECD='911' AND DETAILCD=A.CURRENCY_GB) AS SOSUNUM 	\n");
	        	sqlstr.append(" 	     , (SELECT CHG_CODE02 FROM EBID_COM911T WHERE BASECD='911' AND DETAILCD=A.CURRENCY_GB) AS CURR_STD 	\n");
	        	sqlstr.append(" 	     , (SELECT CHG_CODE06 FROM EBID_COM911T WHERE BASECD='911' AND DETAILCD=A.CURRENCY_GB) AS CURR_STD_NM 	\n");
	        	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-25
	        	sqlstr.append("       	 , A.ORD_SUPPLY_AMT			\n");
	        	sqlstr.append("       	 , A.ORD_SURTAX_AMT			\n");
	        	sqlstr.append("      	 , NVL(A.PREPAY_AMT_RATE,0) AS PREPAY_AMT_RATE			\n");
	        	sqlstr.append("       	 , NVL(A.PREPAY_AMT,0) AS PREPAY_AMT			\n");
	        	sqlstr.append("       	 , NVL(A.MID_AMT_RATE,0) AS MID_AMT_RATE			\n");
	        	sqlstr.append("       	 , NVL(A.MID_AMT,0) AS MID_AMT			\n");
	        	sqlstr.append("       	 , NVL(A.RMDR_AMT_RATE,100) AS RMDR_AMT_RATE			\n");
	        	sqlstr.append("       	 , NVL(A.RMDR_AMT,0) AS 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("          , A.PAY_DIV		\n");									//추가 (2014-09-22) 	
	        	sqlstr.append("          , A.DIV_PO_YN		\n");									//추가 (2014-09-22) 	
	        	sqlstr.append("          , A.PREPAY_GUAR_AMT		\n");									//추가 (2014-09-24) 	
	        	sqlstr.append("          , A.PREPAY_GUAR_AMT_RATE		\n");									//추가 (2014-09-24) 	
	        	sqlstr.append("          ,(SELECT NVL(CHG_CODE10, 'INPUT_VAT')                          \n");															
				sqlstr.append("              FROM EBID_COM911T     										\n");																	
				sqlstr.append("             WHERE BASECD = 'PROOF_CD'   								\n");																	
				sqlstr.append("               AND DETAILCD = NVL(A.GUA_GB, '21')) INPUT_VAT			\n");//2019.05.13 추가	
	        	/*sqlstr.append(" 	     , B.DEMANDED_NO	\n");	
	        	sqlstr.append(" 	     , B.DEMANDED_TITLE	\n");	
	        	sqlstr.append(" 	     , TO_CHAR(TO_DATE(B.DEMANDED_DATE),'YYYY-MM-DD') AS DEMANDED_DATE	\n");	
	        	sqlstr.append(" 	     , B.REQ_DEPT_NM	\n");	
	        	sqlstr.append(" 	     , B.EMP_NO	\n");	
	        	sqlstr.append(" 	     , B.EMP_NM	\n");*/
	        	
	        	sqlstr.append(" 	     , 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(" 	     , NVL(A.GUA_GB,'21') AS 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(" 	     , 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.STAMP_DUTY_GB																	\n");

	        	sqlstr.append(" 	     , A.CON_CHARGE_ID 	\n");	
	        	sqlstr.append(" 	     , A.CON_CHARGE_NAME 	\n");	
	        	
	        	//승인자 추가
	        	sqlstr.append(" 	     , A.CON_CONFIRM_ID 	\n");	
	        	sqlstr.append(" 	     , A.CON_CONFIRM_NAME 	\n");	
	        	
				sqlstr.append("          , A.PREPAY_PAYMENT_NM		\n");
				sqlstr.append("          , A.MID_PAYMENT_NM		\n");
				sqlstr.append("          , A.RMDR_PAYMENT_NM		\n");	        	

				sqlstr.append("          , A.MID_PAYMENT_TXT		\n");	        	
				sqlstr.append("          , A.RMDR_PAYMENT_TXT		\n");	        	
	        	
	        	sqlstr.append(" 	     , A.DEM_ID 	\n");				//변경 발주 번호 : 2014-10-30 김명호 추가
	        	
	        	//결재정보 추가
	        	sqlstr.append(" 	     , A.IN_SPE_INFO 	\n");				//내부특기사항 : 2014-11-26 천호준 추가
	        	sqlstr.append(" 	     , A.IN_CHG_INFO 	\n");				//내부변경사유 : 2014-11-26 천호준 추가
	        	sqlstr.append(" 	     , A.FRST_CON_AMT	\n");				//원_도급금액 : 2014-11-26 천호준 추가
	        	sqlstr.append(" 	     , A.FRST_EXE_AMT	\n");				//원_실행금액 : 2014-11-26 천호준 추가
	        	sqlstr.append(" 	     , A.CHG_CON_AMT	\n");				//현_도급금액 : 2014-11-26 천호준 추가
	        	sqlstr.append(" 	     , A.CHG_EXE_AMT	\n");				//현_실행금액 : 2014-11-26 천호준 추가

	        	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(" 	     , F_GET_CODE_NAME2('CONT_INFO', 'TEL') AS O_TEL_NO	\n");
	        	sqlstr.append(" 	     , F_GET_CODE_NAME2('CONT_INFO', 'FAX') AS O_FAX_NO	\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(" 	     , D.SIGN_DATE AS O_SIGN_DATE	\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.EMAIL AS C_EMAIL	\n");	
	        	sqlstr.append(" 	     , E.SIGN_DATE AS C_SIGN_DATE	\n");		        	
	        	sqlstr.append(" 	     , (SELECT SUM(ITEM_AMT) FROM CONT_PUR_ITEM WHERE PUR_CONT_MOD_ID ='"+PUR_CONT_MOD_ID+"' ) AS ITEM_AMT_SUM 	\n");	
                sqlstr.append(" 	     , NVL(A.ERP_CHECK_YN,'Y') AS ERP_CHECK_YN	\n");	//2016.11.8
	        	sqlstr.append(" 	     , (SELECT IN_OUT_DIV FROM SUPP_INFO WHERE CORP_ID = E.CORP_ID) AS IN_OUT_DIV	\n");
				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.PUR_CONT_MOD_ID = D.PUR_CONT_MOD_ID(+)	\n");
				sqlstr.append("  AND A.DEM_ID = R.DEMANDED_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, nvl(ITEM_PRICE, 0) AS ITEM_PRICE, nvl(ITEM_AMT, 0) AS ITEM_AMT, (nvl(ITEM_QTY,0) * 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 connection
	 * @param valueObject
	 * @throws Exception
	 */
	public boolean saveContProc(Connection connection, ValueObject valueObject) throws Exception {
		//WAFLogger.debug("valueObject : " + valueObject);

        try {
        	conn.begin();

			params.set("TRUE_RANDOM", getTrueRamdom());
			//ArrayList pdfIfno = makeContPdf(params);		// pdf파일 생성
			//WAFLogger.debug("PDF 생성");
			
			margeOrigCorpData(super.conn.getConnection(), params);		//원사업자 업체정보 저장
			margeContCorpData(super.conn.getConnection(), params);		//계약업체정보 저장
			//WAFLogger.debug("계약업체정보 저장");

			CONT_PUR_HTML_del(conn.getConnection(), params);	//ContHTML 삭제
			CONT_PUR_HTML_Save(super.conn.getConnection(), params);	//ContHTML 등록
			//WAFLogger.debug("ContHTML 등록");

			CONT_PUR_FILE_del(conn.getConnection(), params);	//자동생성파일 삭제
			//WAFLogger.debug("자동생성파일 삭제");
			
			String file_hash="";
			String CONT_HASH="";
			/*if (!((params.get("TEMPLATE_CD").equals("9")) || (params.get("TEMPLATE_CD").equals("10")))) {
				for(int i=0; i<pdfIfno.size(); i++){
					file_hash = CONT_PUR_FILE_Save(super.conn.getConnection(), (ValueObject) pdfIfno.get(i));	//자동생성파일 등록
					CONT_HASH = CONT_HASH + file_hash +"|" ;
				}
			}*/
			//첨부파일 hash값 가져오기
			String addFileHash = getfileHashlist("PUR_CONT_MOD_ID", params.get("PUR_CONT_MOD_ID"));
			CONT_HASH = CONT_HASH + addFileHash;
			
			if (CONT_HASH.length()>0){
				params.set("CONT_HASH", CONT_HASH.subSequence(0, CONT_HASH.length()-1));
			}else{
				params.set("CONT_HASH", CONT_HASH.subSequence(0, CONT_HASH.length()));				
			}
			saveContInfo(super.conn.getConnection(), params);		//계약 정보 저장


			//2015.01.08 이인오 인지세 추가
			/*if( !params.get("stamp_duty_issue_gb").equals("00") ){
				mergeStampDuty(super.conn.getConnection(), params);
				
			}else {
				deleteStampDuty(super.conn.getConnection(), params);
				
			}*/
			

			return true;
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> addChangeContProc() : " + e.getMessage());
            WAFLogger.error(e);

            conn.setRollback();
            
            this.storage.setSuccess(false);  
            this.storage.setMessage(e.getMessage());            
            storage.setDetailMessage(e);
            return false;
        }
        finally {
        	super.conn.end();
        }        
    }
	
	/**
     * 원사업자 업체 저장
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public boolean margeOrigCorpData(Connection connection, ValueObject valueObject) throws Exception {
        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("MERGE INTO CONT_PUR_SUPP T1 USING (									\n");
        	sqlstr.append("          SELECT ? AS	PUR_CONT_MOD_ID	\n");
        	sqlstr.append("                ,? AS	CORP_ID	\n");
        	sqlstr.append("                ,'' AS	VENDCD	\n");
        	sqlstr.append("                ,? AS	MEMBER_NAME	\n");
        	sqlstr.append("                ,? AS	BOSS_NAME	\n");
        	sqlstr.append("                ,'' AS	POST_CODE	\n");
        	sqlstr.append("                ,? AS	ADDRESS	\n");
        	sqlstr.append("                ,? AS	TEL_NUM	\n");
        	sqlstr.append("                ,'' AS	MEMBER_SLNO	\n");
        	sqlstr.append("                ,? AS	USER_NAME	\n");
        	sqlstr.append("                ,? AS	DIVISION	\n");
        	sqlstr.append("                ,? AS	POSITION	\n");
        	sqlstr.append("                ,? AS	HP	\n");
        	sqlstr.append("                ,? AS	EMAIL	\n");
        	sqlstr.append("		        FROM DUAL													\n");
        	sqlstr.append("		    ) T ON (T.PUR_CONT_MOD_ID = T1.PUR_CONT_MOD_ID AND T.CORP_ID = T1.CORP_ID)	\n");
        	sqlstr.append("		WHEN MATCHED THEN													\n");
        	sqlstr.append("		    UPDATE SET 				\n");
//        	sqlstr.append("  				, T1.VENDCD	 =	, T.VENDCD	\n");
        	sqlstr.append("  				 T1.MEMBER_NAME	 =	 T.MEMBER_NAME	\n");
        	sqlstr.append("  				, T1.BOSS_NAME	 =	 T.BOSS_NAME	\n");
//        	sqlstr.append("  				, T1.POST_CODE	 =	 T.POST_CODE	\n");
        	sqlstr.append("  				, T1.ADDRESS	 =	 T.ADDRESS	\n");
        	sqlstr.append("  				, T1.TEL_NUM	 =	 T.TEL_NUM	\n");
//        	sqlstr.append("  				, T1.MEMBER_SLNO	 =	 T.MEMBER_SLNO	\n");
        	sqlstr.append("  				, T1.USER_NAME	 =	 T.USER_NAME	\n");
        	sqlstr.append("  				, T1.DIVISION	 =	 T.DIVISION	\n");
        	sqlstr.append("  				, T1.POSITION	 =	 T.POSITION	\n");
        	sqlstr.append("  				, T1.HP	 =	 T.HP	\n");
        	sqlstr.append("  				, T1.EMAIL	 =	 T.EMAIL	\n");
        	sqlstr.append("		WHEN NOT MATCHED THEN											\n");
        	sqlstr.append("			INSERT (T1.PUR_CONT_MOD_ID, T1.CORP_ID, T1.SIGN_SEQ, T1.VENDCD, T1.MEMBER_NAME, T1.BOSS_NAME, T1.POST_CODE, T1.ADDRESS, T1.TEL_NUM, T1.MEMBER_SLNO, T1.USER_NAME, T1.DIVISION, T1.POSITION, T1.HP, T1.EMAIL)									\n");
        	sqlstr.append("			VALUES (T.PUR_CONT_MOD_ID, T.CORP_ID, 1, T.VENDCD, T.MEMBER_NAME, T.BOSS_NAME, T.POST_CODE, T.ADDRESS, T.TEL_NUM, T.MEMBER_SLNO, T.USER_NAME, T.DIVISION, T.POSITION, T.HP, T.EMAIL)											\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("PUR_CONT_MOD_ID"));
            persistent.addParameter(valueObject.get("O_CORP_ID"));
            persistent.addParameter(valueObject.get("O_MEMBER_NAME"));
            persistent.addParameter(valueObject.get("O_BOSS_NAME"));
            persistent.addParameter(valueObject.get("O_ADDRESS"));
            persistent.addParameter(valueObject.get("O_TEL_NUM"));
            persistent.addParameter(valueObject.get("O_USER_NAME"));
            persistent.addParameter(valueObject.get("O_DIVISION"));
            persistent.addParameter(valueObject.get("O_POSITION"));
            persistent.addParameter(valueObject.get("O_HP"));
            persistent.addParameter(valueObject.get("O_EMAIL"));
            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 connection
	 * @param valueObject
	 * @throws Exception
	 */
/*	public boolean mergeStampDuty(Connection connection, ValueObject valueObject) throws Exception {
		Persistent persistent = new PersistentImpl(connection);
		StrBuffer sqlstr = new StrBuffer();
		try {

			sqlstr.append(" MERGE	INTO STAMP_DUTY A													\n");
			sqlstr.append("     USING 	(																\n");
			sqlstr.append("             SELECT	PUR_CONT_MOD_ID	AS CONT_MOD_ID							\n");
			sqlstr.append("             		,ORD_DOC_NO	AS CONT_NO									\n");
			sqlstr.append("                     ,MOD_NO	AS MOD_NO										\n");
			sqlstr.append("                     ,CST_DOC_NAME AS CONT_NAME								\n");
			sqlstr.append("                     ,ORD_AMT AS CONT_AMT									\n");
			sqlstr.append("             FROM	PUR2000T												\n");
			sqlstr.append("             WHERE	PUR_CONT_MOD_ID = ?										\n");
			sqlstr.append("             ) B																\n");
			sqlstr.append("     ON		(A.CONT_MOD_ID = B.CONT_MOD_ID AND A.STAMP_DUTY_TYPE = '10')	\n");
			sqlstr.append(" WHEN MATCHED THEN															\n");
			sqlstr.append(" 	UPDATE	SET																\n");
			sqlstr.append("             STAMP_DUTY_ISSUE_GB = ?											\n");
			sqlstr.append("             ,CORP_REG_NO = ?												\n");
			sqlstr.append("             ,CORP_NAME = ?													\n");
			sqlstr.append("             ,CONT_NO = B.CONT_NO											\n");
			sqlstr.append("             ,MOD_NO = B.MOD_NO												\n");
			sqlstr.append("             ,STAMP_DUTY_NO = ?												\n");
			sqlstr.append("             ,CONT_NAME = B.CONT_NAME										\n");
			sqlstr.append("             ,CONT_AMT = B.CONT_AMT											\n");
			sqlstr.append("             ,STAMP_DUTY_TAX = ?												\n");
			sqlstr.append("             ,STAMP_DUTY_DATE = ?											\n");
			sqlstr.append("             ,REMARK = ?														\n");
			sqlstr.append(" WHEN NOT MATCHED THEN														\n");
			sqlstr.append(" 	INSERT	(																\n");
			sqlstr.append("             STAMP_DUTY_ID													\n");
			sqlstr.append("             ,STAMP_DUTY_TYPE												\n");
			sqlstr.append("             ,STAMP_DUTY_ISSUE_GB											\n");
			sqlstr.append("             ,CONT_MOD_ID													\n");
			sqlstr.append("             ,CORP_REG_NO													\n");
			sqlstr.append("             ,CORP_NAME														\n");
			sqlstr.append("             ,CONT_NO														\n");
			sqlstr.append("             ,MOD_NO															\n");
			sqlstr.append("             ,STAMP_DUTY_NO													\n");
			sqlstr.append("             ,CONT_NAME														\n");
			sqlstr.append("             ,CONT_AMT														\n");
			sqlstr.append("             ,STAMP_DUTY_TAX													\n");
			sqlstr.append("             ,STAMP_DUTY_DATE												\n");
			sqlstr.append("             ,REMARK															\n");
			sqlstr.append(" 			)																\n");
			sqlstr.append("     VALUES	(																\n");
			sqlstr.append("     		STAMP_DUTY_S.NEXTVAL											\n");
			sqlstr.append("             ,'10'															\n");
			sqlstr.append("             ,? --STAMP_DUTY_ISSUE_GB										\n");
			sqlstr.append("             ,? --CONT_MOD_ID												\n");
			sqlstr.append("             ,? --CORP_REG_NO												\n");
			sqlstr.append("             ,? --CORP_NAME													\n");
			sqlstr.append("             ,B.CONT_NO --CONT_NO											\n");
			sqlstr.append("             ,B.MOD_NO --MOD_NO												\n");
			sqlstr.append("             ,? --STAMP_DUTY_NO												\n");
			sqlstr.append("             ,B.CONT_NAME --CONT_NAME										\n");
			sqlstr.append("             ,B.CONT_AMT --CONT_AMT											\n");
			sqlstr.append("             ,? --STAMP_DUTY_TAX												\n");
			sqlstr.append("             ,? --STAMP_DUTY_DATE											\n");
			sqlstr.append("             ,? --REMARK														\n");
			sqlstr.append("     		)																\n");
			    		
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(valueObject.get("PUR_CONT_MOD_ID"));
			persistent.addParameter(valueObject.get("stamp_duty_issue_gb"));
			persistent.addParameter(valueObject.get("O_REG_NO"));
			persistent.addParameter(valueObject.get("O_MEMBER_NAME"));
			persistent.addParameter(valueObject.get("stamp_duty_no"));
			persistent.addParameter(valueObject.get("stamp_duty_tax").replaceAll(",", ""));
			persistent.addParameter(valueObject.get("stamp_duty_date").replaceAll("-", ""));
			persistent.addParameter(valueObject.get("remark"));
			persistent.addParameter(valueObject.get("stamp_duty_issue_gb"));
			persistent.addParameter(valueObject.get("PUR_CONT_MOD_ID"));
			persistent.addParameter(valueObject.get("O_REG_NO"));
			persistent.addParameter(valueObject.get("O_MEMBER_NAME"));
			persistent.addParameter(valueObject.get("stamp_duty_no"));
			persistent.addParameter(valueObject.get("stamp_duty_tax").replaceAll(",", ""));
			persistent.addParameter(valueObject.get("stamp_duty_date").replaceAll("-", ""));
			persistent.addParameter(valueObject.get("remark"));
			persistent.execute();
			
			return true;
		}
		catch(Exception e) {
			WAFLogger.error(this.getClass().getName() + " --> mergeStampDuty() : " + e.getMessage());
			WAFLogger.error("SQL : " + sqlstr);
			WAFLogger.error(e);
			throw e;
		}
	}
*/	
	/**
	 * 인지세 삭제
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
/*	public boolean deleteStampDuty(Connection connection, ValueObject valueObject) throws Exception {
		Persistent persistent = new PersistentImpl(connection);
		StrBuffer sqlstr = new StrBuffer();
		try {
			
			sqlstr.append(" BEGIN														\n");
			sqlstr.append(" 	DELETE	FROM PUB0500T									\n");
			sqlstr.append(" 	WHERE	FILE_ID IN 	(									\n");
			sqlstr.append(" 	                    SELECT	FILE_ID						\n");
			sqlstr.append(" 	                    FROM	PUB0510T					\n");
			sqlstr.append(" 	                    WHERE	FILE_GB = 'PUR_STAMP_DUTY'	\n");
			sqlstr.append(" 	                    AND		ID = ?						\n");
			sqlstr.append(" 	                    );									\n");
			sqlstr.append(" 	DELETE	FROM PUB0510T									\n");
			sqlstr.append(" 	WHERE	FILE_GB = 'PUR_STAMP_DUTY'						\n");
			sqlstr.append(" 	AND		ID = ?;											\n");
			sqlstr.append(" 	DELETE	FROM STAMP_DUTY									\n");
			sqlstr.append(" 	WHERE	CONT_MOD_ID	= ?									\n");
			sqlstr.append(" 	AND		STAMP_DUTY_TYPE = '10';							\n");
			sqlstr.append(" END;														\n");
			
			
			
			persistent.setStatement(sqlstr.toString());
			persistent.addParameter(valueObject.get("PUR_CONT_MOD_ID"));
			persistent.addParameter(valueObject.get("PUR_CONT_MOD_ID"));
			persistent.addParameter(valueObject.get("PUR_CONT_MOD_ID"));
			persistent.execute();
			
			return true;
		}
		catch(Exception e) {
			WAFLogger.error(this.getClass().getName() + " --> deleteStampDuty() : " + e.getMessage());
			WAFLogger.error("SQL : " + sqlstr);
			WAFLogger.error(e);
			throw e;
		}
	}	
*/
	/**
     * 협력사 담당자 정보 조회
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	private ValueObject getEmpChk(String pur_cont_mod_id, String c_hp) {
		
		Search search = new SearchImpl();
		RowSet rowSet = new RowSetImpl();
		ValueObject valueobject = null;
		ValueObject user = storage.getUser();
		StrBuffer sqlstr = new StrBuffer();
		try{
			
			sqlstr.append(" select NVL(COUNT(*),0) EMP_CHK_CNT                  \n");
			sqlstr.append("   from CONT_PUR_SUPP A, SUPP_CHARGE B               \n");
			sqlstr.append("  where A.pur_cont_mod_id = '"+pur_cont_mod_id+"'    \n");
			sqlstr.append("    and A.sign_seq = '2'                             \n");
			sqlstr.append("    AND A.CORP_ID = B.CORP_ID                        \n");
			sqlstr.append("    AND b.hp1 || b.hp2 || b.hp3 = replace('"+c_hp+"','-','')                      \n");
			search.setStatement(sqlstr.toString());
			rowSet = search.execute();
			
			if( rowSet != null && rowSet.size() > 0 ){
				valueobject = RowSetUtility.getValueObject(rowSet.getRow(0));
			}
			
		}
		catch(WAFSQLException se) {
			super.doException(se);
			this.storage.setSuccess(false);
			this.storage.setMessage(se.getMessage());
			storage.setDetailMessage(se);
			//WAFLogger.debug(sqlstr.toString());
			//WAFLogger.debug("WAFSQLException : " + se.getMessage());
		}
		finally {
			
			if( valueobject == null ) valueobject = new ValueObject();
			//WAFLogger.debug("### valueobject size : " + valueobject.size());
			return valueobject;
		}
	}
	
	/**
     * 원사업자 업체 저장
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public boolean margeContCorpData(Connection connection, ValueObject valueObject) throws Exception {
        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("MERGE INTO CONT_PUR_SUPP T1 USING (									\n");
        	sqlstr.append("          SELECT ? AS	PUR_CONT_MOD_ID	\n");
        	sqlstr.append("                ,? AS	CORP_ID	\n");
        	sqlstr.append("                ,'' AS	VENDCD	\n");
        	sqlstr.append("                ,? AS	MEMBER_NAME	\n");
        	sqlstr.append("                ,? AS	BOSS_NAME	\n");
        	sqlstr.append("                ,'' AS	POST_CODE	\n");
        	sqlstr.append("                ,? AS	ADDRESS	\n");
        	sqlstr.append("                ,? AS	TEL_NUM	\n");
        	sqlstr.append("                ,'' AS	MEMBER_SLNO	\n");
        	sqlstr.append("                ,? AS	USER_NAME	\n");
        	sqlstr.append("                ,? AS	DIVISION	\n");
        	sqlstr.append("                ,? AS	POSITION	\n");
        	sqlstr.append("                ,? AS	HP	\n");
        	sqlstr.append("                ,? AS	EMAIL	\n");
        	sqlstr.append("		        FROM DUAL													\n");
        	sqlstr.append("		    ) T ON (T.PUR_CONT_MOD_ID = T1.PUR_CONT_MOD_ID AND T.CORP_ID = T1.CORP_ID)	\n");
        	sqlstr.append("		WHEN MATCHED THEN													\n");
        	sqlstr.append("		    UPDATE SET 				\n");
//        	sqlstr.append("  				, T1.VENDCD	 =	, T.VENDCD	\n");
        	sqlstr.append("  				 T1.MEMBER_NAME	 =	 T.MEMBER_NAME	\n");
        	sqlstr.append("  				, T1.BOSS_NAME	 =	 T.BOSS_NAME	\n");
//        	sqlstr.append("  				, T1.POST_CODE	 =	 T.POST_CODE	\n");
        	sqlstr.append("  				, T1.ADDRESS	 =	 T.ADDRESS	\n");
        	sqlstr.append("  				, T1.TEL_NUM	 =	 T.TEL_NUM	\n");
//        	sqlstr.append("  				, T1.MEMBER_SLNO	 =	 T.MEMBER_SLNO	\n");
        	sqlstr.append("  				, T1.USER_NAME	 =	 T.USER_NAME	\n");
        	sqlstr.append("  				, T1.DIVISION	 =	 T.DIVISION	\n");
        	sqlstr.append("  				, T1.POSITION	 =	 T.POSITION	\n");
        	sqlstr.append("  				, T1.HP	 =	 T.HP	\n");
        	sqlstr.append("  				, T1.EMAIL	 =	 T.EMAIL	\n");
        	sqlstr.append("		WHEN NOT MATCHED THEN											\n");
        	sqlstr.append("			INSERT (T1.PUR_CONT_MOD_ID, T1.CORP_ID, T1.SIGN_SEQ, T1.VENDCD, T1.MEMBER_NAME, T1.BOSS_NAME, T1.POST_CODE, T1.ADDRESS, T1.TEL_NUM, T1.MEMBER_SLNO, T1.USER_NAME, T1.DIVISION, T1.POSITION, T1.HP, T1.EMAIL)									\n");
        	sqlstr.append("			VALUES (T.PUR_CONT_MOD_ID, T.CORP_ID, 2, T.VENDCD, T.MEMBER_NAME, T.BOSS_NAME, T.POST_CODE, T.ADDRESS, T.TEL_NUM, T.MEMBER_SLNO, T.USER_NAME, T.DIVISION, T.POSITION, T.HP, T.EMAIL)											\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("PUR_CONT_MOD_ID"));
            persistent.addParameter(valueObject.get("C_CORP_ID"));
            persistent.addParameter(valueObject.get("C_MEMBER_NAME"));
            persistent.addParameter(valueObject.get("C_BOSS_NAME"));
            persistent.addParameter(valueObject.get("C_ADDRESS"));
            persistent.addParameter(valueObject.get("C_TEL_NUM"));
            persistent.addParameter(valueObject.get("C_USER_NAME"));
            persistent.addParameter(valueObject.get("C_DIVISION"));
            persistent.addParameter(valueObject.get("C_POSITION"));
            persistent.addParameter(valueObject.get("C_HP"));
            persistent.addParameter(valueObject.get("C_EMAIL"));
            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 saveContInfo(Connection connection, ValueObject valueObject) throws Exception {
		//WAFLogger.debug("valueObject : " + valueObject.get("rmdr_amt"));
        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {

        	sqlstr.append("		UPDATE PUR2000T SET 				\n");
        	sqlstr.append("       MOD_GB  =  '"+ valueObject.get("mod_gb") +"' \n");		//계약명
        //	sqlstr.append("       ORD_DOC_NO  =  '"+ valueObject.get("con_doc_no") +"' \n");		// 계약번호
        //  sqlstr.append("      , DEPT_NAME  =  '"+ valueObject.get("dept_name") +"' \n");		//현장명
            sqlstr.append("      , DEALER_NM  =  '"+ valueObject.get("dealer_nm") +"' \n");		//발주처 2018.08.13
        if(!valueObject.get("ord_con_date_year").isEmpty()){
        	sqlstr.append("      , ORD_CON_DATE  =  '"+ valueObject.get("ord_con_date_year") +"-"+ valueObject.get("ord_con_date_month") +"-"+ valueObject.get("ord_con_date_day") +"' \n");		//계약일
        }
        if(!valueObject.get("ord_start_date_year").isEmpty()){
        	sqlstr.append("      , ORD_START_DATE  =  '"+ valueObject.get("ord_start_date_year") +"-"+ valueObject.get("ord_start_date_month") +"-"+ valueObject.get("ord_start_date_day") +"' \n");		//공사기간 시작일
        }
        if(!valueObject.get("ord_end_date_year").isEmpty()){
        	sqlstr.append("      , ORD_END_DATE  =  '"+ valueObject.get("ord_end_date_year") +"-"+ valueObject.get("ord_end_date_month") +"-"+ valueObject.get("ord_end_date_day") +"' \n");		//공사기간 종료일
        }
        	sqlstr.append("      , CST_DOC_NAME  =  ? \n");		//계약명
        	sqlstr.append("      , LEAD_PLACE  =  ? \n");		//공사장소
        	
        	sqlstr.append("      , LEAD_COND_GB  =  ? \n");		//원도급공사명
        	sqlstr.append("      , ORD_AMT  =  ? \n");		// 계약금액
        	sqlstr.append("      , ORD_SUPPLY_AMT  =  ? \n");		//하도급공사명
        	sqlstr.append("      , ORD_SURTAX_AMT  =  ? \n");		//지급방법 현금
        	sqlstr.append("      , PREPAY_AMT_RATE  =  ? \n");		// 지금방법 어음
        	sqlstr.append("      , PREPAY_AMT  =  ? \n");		// 공급가액
        	sqlstr.append("      , MID_AMT_RATE  =  ? \n");		// 공급가액 과세
        	sqlstr.append("      , MID_AMT  =  ? \n");		// 공급가액 비과세
        	sqlstr.append("      , RMDR_AMT_RATE  =  ? \n");		// 계약부과세
        	sqlstr.append("      , RMDR_AMT  =  ? \n");		// 노무비
        	sqlstr.append("      , CON_GUAR_AMT_RATE  =  ? \n");		// 선급금율
        	sqlstr.append("      , CON_GUAR_TERM  =  ? \n");		// 선급금액
        	sqlstr.append("      , CON_GUAR_AMT  =  ? \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("      , MID_PAYMENT_TXT  =  ? \n");		// 계약이행 보증금율
        	sqlstr.append("      , RMDR_PAYMENT_TXT  = ? \n");		// 계약이행 보증금율

        	sqlstr.append("      , TEMPLATE_CD  = ? \n");		// 계약서류코드
        	sqlstr.append("      , CONT_HASH  =  ? \n");		// 지체상급율
        	sqlstr.append("      , TRUE_RANDOM  =  ? \n");		// 지체상급율
        	sqlstr.append("      , CURRENCY_GB  =  ? \n");		// 통화구분 저장
        	        	 	
        	sqlstr.append("      , ELEC_CON_YN  =  ? \n");		// 전자계약여부        	
        	sqlstr.append("      , STATUS_CD  =  '10' \n");		// 계약진행상태

        	/*분개 유형*/
        	sqlstr.append(" 	 , ACCT_GB  =  ? 	\n");	
        	sqlstr.append(" 	 , PAY_GROUP  =  ? 	\n");	
        	sqlstr.append(" 	 , GUA_GB  = ? 	\n");	
        	sqlstr.append(" 	 , PAYMENT_TERMS  =  ? 	\n");	
        	sqlstr.append(" 	 , PAY_ITEM  =  ? 	\n");	
        	sqlstr.append(" 	 , COST_CODE  =  ? 	\n");	
        	sqlstr.append(" 	 , COST_TYPE  =  ?	\n");	

        	sqlstr.append(" 	 , CON_DISPLAY_TXT  =  ? 	\n");	
        	sqlstr.append(" 	 , CON_IN_DATE  =  SYSDATE  	\n");	
        	
        	sqlstr.append("      , PREPAY_GUAR_AMT	 =  ?	\n");									//추가 (2014-09-24) 	
        	sqlstr.append("      , PREPAY_GUAR_AMT_RATE	 =  ?	\n");									//추가 (2014-09-24) 	 
        	
        	sqlstr.append("      , CON_GB	 =  ?	\n");									//추가 (2014-10-08) 	
        	
        	sqlstr.append("      , STAMP_DUTY_GB	 =  ?	\n");									//추가 (2014-10-08) 	
        	
        	//승인자 추가
        	sqlstr.append("      , CON_CONFIRM_ID	 = ?	\n");									//추가 (2014-11-05) 	        	
        	sqlstr.append("      , CON_CONFIRM_NAME	 =  ?	\n");									//추가 (2014-11-05) 	        	
        	
        	sqlstr.append(" 	 , CRE_BY  =  ?  	\n");	
        	sqlstr.append(" 	 , CRE_DATE  =  SYSDATE  	\n");	

			sqlstr.append("      , PREPAY_PAYMENT_NM  =  ? 		\n");
			sqlstr.append("      , MID_PAYMENT_NM	  =  ? 	\n");
			sqlstr.append("      , RMDR_PAYMENT_NM  =  ? 		\n");	        	        	

			sqlstr.append("      , IN_SPE_INFO 		  =  ? 		\n");						//추가(2014-11-26)
			sqlstr.append("      , IN_CHG_INFO		  =  ? 	\n");							//추가(2014-11-26)
			sqlstr.append("      , FRST_CON_AMT		  =  ? 		\n");	        	        //추가(2014-11-26)
			sqlstr.append("      , FRST_EXE_AMT		  =  ? 		\n");	        	        //추가(2014-11-26)
			sqlstr.append("      , CHG_CON_AMT		  =  ? 		\n");	        	        //추가(2014-11-26)
			sqlstr.append("      , CHG_EXE_AMT		  =  ? 		\n");	        	        //추가(2014-11-26)

			sqlstr.append("      , CON_CHARGE_ID  =  ? 		\n");
			sqlstr.append("      , CON_CHARGE_NAME  =  ? 		\n");
			sqlstr.append("      , ERP_CHECK_YN  =  ? 		\n");   //2016.11.8
        	sqlstr.append("		WHERE  PUR_CONT_MOD_ID = "+ valueObject.get("PUR_CONT_MOD_ID") +"	\n");
        	
            persistent.setStatement(sqlstr.toString());
        	persistent.addParameter(valueObject.get("cst_doc_name"));		//계약명
        	persistent.addParameter(valueObject.get("lead_place"));		//공사장소
        	
        	persistent.addParameter(valueObject.get("lead_cond_gb"));		//원도급공사명
        	persistent.addParameter(valueObject.get("ord_amt").replaceAll(",",""));		// 계약금액
        	persistent.addParameter(valueObject.get("ord_supply_amt").replaceAll(",",""));		//하도급공사명
        	persistent.addParameter(valueObject.get("ord_surtax_amt").replaceAll(",",""));		//지급방법 현금
        	persistent.addParameter(valueObject.get("prepay_amt_rate").replaceAll(",",""));		// 지금방법 어음
        	persistent.addParameter(valueObject.get("prepay_amt").replaceAll(",",""));		// 공급가액
        	persistent.addParameter(valueObject.get("mid_amt_rate").replaceAll(",",""));		// 공급가액 과세
        	persistent.addParameter(valueObject.get("mid_amt").replaceAll(",",""));		// 공급가액 비과세
        	persistent.addParameter(valueObject.get("rmdr_amt_rate").replaceAll(",",""));		// 계약부과세
        	persistent.addParameter(valueObject.get("rmdr_amt").replaceAll(",",""));		// 노무비
        	persistent.addParameter(valueObject.get("con_guar_amt_rate").replaceAll(",",""));		// 선급금율
        	persistent.addParameter(valueObject.get("con_guar_term"));		// 선급금액
        	persistent.addParameter(valueObject.get("con_guar_amt").replaceAll(",",""));		// 선급금 공급가액
        	persistent.addParameter(valueObject.get("def_guar_amt_rate").replaceAll(",",""));		// 선급금 과세
        	persistent.addParameter(valueObject.get("def_guar_amt").replaceAll(",",""));		// 선급금 면세
        	persistent.addParameter(valueObject.get("def_guar_terms"));		// 선급금 부과세
        	persistent.addParameter(valueObject.get("def_guar_terms_txt"));		// 선급금 부과세
        	persistent.addParameter(valueObject.get("def_guar_terms2"));		// 선급금 부과세
        	persistent.addParameter(valueObject.get("def_guar_terms_txt2"));		// 선급금 부과세
        	persistent.addParameter(valueObject.get("del_rate_gb"));		// 계약이행 보증금율
        	persistent.addParameter(valueObject.get("mid_payment_txt"));		// 계약이행 보증금율
        	persistent.addParameter(valueObject.get("rmdr_payment_txt"));		// 계약이행 보증금율

        	persistent.addParameter(valueObject.get("TEMPLATE_CD"));		// 계약서류코드
        	persistent.addParameter(valueObject.get("CONT_HASH"));		// 지체상급율
        	persistent.addParameter(valueObject.get("TRUE_RANDOM"));		// 지체상급율
        	persistent.addParameter(valueObject.get("CURRENCY_GB"));		// 통화구분 저장        	        	 	
        	persistent.addParameter(valueObject.get("ELEC_CON_YN"));		// 전자계약여부        	

        	/*분개 유형*/
        	persistent.addParameter(valueObject.get("ACCT_GB"));	
        	persistent.addParameter(valueObject.get("PAY_GROUP"));	
        	persistent.addParameter(valueObject.get("GUA_GB"));	
        	persistent.addParameter(valueObject.get("PAYMENT_TERMS"));	
        	persistent.addParameter(valueObject.get("PAY_ITEM"));	
        	persistent.addParameter(valueObject.get("COST_CODE"));	
        	persistent.addParameter(valueObject.get("COST_TYPE"));	

        	persistent.addParameter(valueObject.get("CON_DISPLAY_TXT"));	
        	
        	persistent.addParameter(valueObject.get("PREPAY_GUAR_AMT").replaceAll(",",""));									//추가 (2014-09-24) 	
        	persistent.addParameter(valueObject.get("PREPAY_GUAR_AMT_RATE"));									//추가 (2014-09-24) 	 
        	
        	persistent.addParameter(valueObject.get("CON_GB"));									//추가 (2014-10-08) 	        	

        	persistent.addParameter(valueObject.get("p_issue_gb"));									//추가 (2014-10-08) 	        	
        	//승인자 추가
        	persistent.addParameter(valueObject.get("CON_CONFIRM_ID"));									//추가 (2014-11-05) 	        	
        	persistent.addParameter(valueObject.get("CON_CONFIRM_NAME"));									//추가 (2014-11-05) 	        	
        	
        	persistent.addParameter(storage.getUser().get("acct_id"));	            

        	persistent.addParameter(valueObject.get("PREPAY_PAYMENT_NM"));									//추가 (2014-11-14) 	        	
        	persistent.addParameter(valueObject.get("MID_PAYMENT_NM"));									//추가 (2014-11-14) 	        	
        	persistent.addParameter(valueObject.get("RMDR_PAYMENT_NM"));									//추가 (2014-11-14) 	        	

        	persistent.addParameter(valueObject.get("IN_SPE_INFO"));													//추가 (2014-11-26) 	        	
        	persistent.addParameter(valueObject.get("IN_CHG_INFO"));													//추가 (2014-11-26)  	        	
        	persistent.addParameter(valueObject.get("FRST_CON_AMT").replaceAll(",",""));								//추가 (2014-11-26) 	        	
        	persistent.addParameter(valueObject.get("FRST_EXE_AMT").replaceAll(",",""));								//추가 (2014-11-26)  	        	
        	persistent.addParameter(valueObject.get("CHG_CON_AMT").replaceAll(",",""));									//추가 (2014-11-26) 	        	
        	persistent.addParameter(valueObject.get("CHG_EXE_AMT").replaceAll(",",""));									//추가 (2014-11-26) 	        
        	
        	persistent.addParameter(valueObject.get("O_ACCT_ID"));
        	persistent.addParameter(valueObject.get("O_USER_NAME"));
        	persistent.addParameter(valueObject.get("ERP_CHECK_YN"));   //2016.11.8
            persistent.execute();
            
            return true;
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }	

	private ArrayList makeContPdf(ValueObject parms) {
		ArrayList<ValueObject> pdfList = new ArrayList();
		if(params.get("PDF_FILE_CNT").equals("")){
			return null;
		}
		String[] template_seq = null;
		String[] template_name = null;
		String[] contHtml = null;
		String[] contHtmlRm = null;
		if(params.getInt("PDF_FILE_CNT")>1){
			template_seq = (String[])params.getObject("template_seq");
			template_name = (String[])params.getObject("template_name");
			contHtml = (String[])params.getObject("cont_html");
			contHtmlRm = (String[])params.getObject("cont_html_rm");
		}else{
			template_seq = new String[]{params.get("template_seq")};
			template_name = new String[]{params.get("template_name")};
			contHtml = new String[]{params.get("cont_html")};
			contHtmlRm = new String[] {params.get("cont_html_rm")};
		}
		for(int i = 0 ; i < params.getInt("PDF_FILE_CNT"); i++){
			String check_yn = params.get("check_yn_"+template_seq[i]);
			if(check_yn.equals("A")||check_yn.equals("Y")){
				ValueObject vo = new ValueObject();
				vo.set("cont_no", params.get("PUR_CONT_MOD_ID"));
				vo.set("cont_chasu", params.get("MOD_NO"));
				vo.set("true_random", params.get("TRUE_RANDOM"));
				vo.set("file_seq", i);
				vo.set("folder", "purchase");
				vo.set("cont_userno", params.get("ORD_DOC_NO"));
				vo.set("html", contHtmlRm[i]);
				PDFMaker pdfMaker = new PDFMaker();
				ValueObject pdfInfo = pdfMaker.makeContPdf(vo);
				pdfInfo.set("cont_no", params.get("PUR_CONT_MOD_ID"));
				pdfInfo.set("template_name", template_name[i]);
				pdfInfo.set("file_seq", i);
				pdfList.add(pdfInfo);
			}
		}
		//WAFLogger.debug("HTML : " + params.get("cont_html"));		
		return pdfList;
	}
	
	/**
     * 계약 htm 삭제
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void CONT_PUR_HTML_del(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("DELETE FROM  CONT_PUR_HTML						\n");
        	sqlstr.append("WHERE PUR_CONT_MOD_ID = ?						\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("PUR_CONT_MOD_ID"));
            persistent.execute();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }	
	/**
     * 계약 htm 등록
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public boolean CONT_PUR_HTML_Save(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
    		if(valueObject.getInt("PDF_FILE_CNT")>1){
        		String[] template_seq = null;
        		String[] contHtml = null;
        		String[] template_name = null;
        		String[] template_style = null;
        		String[] option_yn = null;

        		template_seq = (String[])valueObject.getObject("template_seq");
       			template_name = (String[])valueObject.getObject("template_name");
       			template_style = (String[])valueObject.getObject("template_style");
       			option_yn = (String[])valueObject.getObject("option_yn");
    			contHtml = (String[])valueObject.getObject("cont_html");
    			
    			for(int i = 0 ; i < valueObject.getInt("PDF_FILE_CNT"); i++){
    				sqlstr.append("INSERT INTO CONT_PUR_HTML (PUR_CONT_MOD_ID, SEQ, TEMPLATE_NAME, TEMPLATE_HTML, TEMPLATE_STYLE, CHECK_YN, OPTION_YN)						\n");
    				sqlstr.append("VALUES(?, ?, ?, ?, ?, ?, ?)					\n");
    	            persistent.setStatement(sqlstr.toString());
    	            persistent.addParameter(valueObject.get("PUR_CONT_MOD_ID"));
    	            persistent.addParameter(template_seq[i]);
    	            persistent.addParameter(template_name[i]);
    	            persistent.addParameter(contHtml[i]);
    	            persistent.addParameter(template_style[i]);
    	            persistent.addParameter(valueObject.get("check_yn_"+template_seq[i]));
    	            persistent.addParameter(option_yn[i]);
    	            persistent.execute();  
    	            sqlstr.reset();
    	            persistent.clearParameters();
    			}    			
    		}else{
        		String template_seq = null;
        		String contHtml = null;
        		String template_name = null;
        		String template_style = null;
        		String option_yn = null;
        		
    			template_seq = valueObject.get("template_seq");
    			template_name = valueObject.get("template_name");
    			template_style = valueObject.get("template_style");
    			option_yn = valueObject.get("option_yn");
    			contHtml = valueObject.get("cont_html");
    			
    			WAFLogger.debug("Exception HTML String : " + contHtml.indexOf("Ljava.lang.String"));
				sqlstr.append("INSERT INTO CONT_PUR_HTML (PUR_CONT_MOD_ID, SEQ, TEMPLATE_NAME, TEMPLATE_HTML, TEMPLATE_STYLE, CHECK_YN, OPTION_YN)						\n");
				sqlstr.append("VALUES(?, ?, ?, ?, ?, ?, ?)					\n");
	            persistent.setStatement(sqlstr.toString());
	            persistent.addParameter(valueObject.get("PUR_CONT_MOD_ID"));
	            persistent.addParameter(template_seq);
	            persistent.addParameter(template_name);
	            persistent.addParameter(contHtml);
	            persistent.addParameter(template_style);
	            persistent.addParameter(valueObject.get("check_yn_"+template_seq));
	            persistent.addParameter(option_yn);
	            persistent.execute();  
	            sqlstr.reset();
	            persistent.clearParameters();
    		}
      	
            return true;
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            //WAFLogger.debug("Exception CONT_PUR_HTML_Save : " + e.getMessage());
            throw e;
        }
    }	
	/**
     * 계약 파일 삭제
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void CONT_PUR_FILE_del(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("DELETE FROM  CONT_PUR_FILE						\n");
        	sqlstr.append("WHERE PUR_CONT_MOD_ID = ?						\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("PUR_CONT_MOD_ID"));
            persistent.execute();
        }
        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 String CONT_PUR_FILE_Save(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {

        	sqlstr.append("INSERT INTO CONT_PUR_FILE (PUR_CONT_MOD_ID, FILE_ID, UNIQUE_FILE_NAME, FILE_PATH, FILE_EXT, FILE_SIZE, FILE_NAME, AUTO_YN, CRE_BY, CRE_DATE)						\n");
        	sqlstr.append("VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, SYSDATE)						\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("cont_no"));
            persistent.addParameter(valueObject.get("file_seq"));
            persistent.addParameter(valueObject.get("file_name"));
            persistent.addParameter(valueObject.get("file_path"));
            persistent.addParameter(valueObject.get("file_ext"));
            persistent.addParameter(valueObject.get("file_size"));
            persistent.addParameter(valueObject.get("template_name"));
            persistent.addParameter("Y");
            persistent.addParameter("");
            persistent.execute();
            persistent.clearParameters();
            
            return valueObject.get("file_hash");
        }
        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 deleteContProc(Connection connection, ValueObject valueObject) throws Exception {
		//WAFLogger.debug("valueObject : " + valueObject);

        try {
        	conn.begin();

			CONT_PUR_HTML_del(super.conn.getConnection(), params);	//ContHTML 삭제
			//WAFLogger.debug("ContHTML 삭제");

			CONT_PUR_FILE_del(super.conn.getConnection(), params);	//자동생성파일 삭제
			//WAFLogger.debug("자동생성파일 삭제");

			delContCorpData(super.conn.getConnection(), params);		//계약업체정보 저장
			//WAFLogger.debug("계약업체정보 삭제");

			delContItem(super.conn.getConnection(), params);		//계약상품 정보 저장
			//WAFLogger.debug("계약상품 정보 삭제");
			
			//발주 의뢰번호가 있을경우 타 테이블 업데이트 처리
			
			if(!valueObject.get("pDemID").isEmpty()){
				//2019.04.15 단가계약일경우 제외
				Search search = new SearchImpl();
				Search search2 = new SearchImpl();
		        RowSet listRowSet = null;
		        RowSet listRowSet2 = null;
		        StrBuffer sqlstr = new StrBuffer();
		        StrBuffer sqlstr2 = new StrBuffer();
		        ValueObject rowObject = null;
		        ValueObject rowObject2 = null;
		        String DIV_PO_YN = "";
		        String DEM_ID_CNT = "";
		        try {
		        	sqlstr.append(" 	SELECT NVL(DIV_PO_YN,'N') DIV_PO_YN	                                    \n");
		        	sqlstr.append(" 	  FROM PUR2000T A	                                                    \n");
		        	sqlstr.append("   WHERE 1=1								                                    \n");
		    		sqlstr.append("   	AND A.PUR_CONT_MOD_ID= '"+ params.get("PUR_CONT_MOD_ID") +"'			\n"); 
		             
		    		search.setStatement(sqlstr.toString());
		            listRowSet = search.execute();
		            if(listRowSet.size() != 0){
		            	rowObject = RowSetUtility.getValueObject(listRowSet.getRow(0));
		            	DIV_PO_YN = rowObject.get("DIV_PO_YN");
		            }
		            
		            sqlstr2.append(" 	SELECT COUNT(*) DEM_ID_CNT	                                    \n");
		        	sqlstr2.append(" 	  FROM PUR2000T A	                                                    \n");
		        	sqlstr2.append("   WHERE 1=1								                                    \n");
		    		sqlstr2.append("   	AND A.DEM_ID = '"+ valueObject.get("pDemID") +"'			\n"); 
		             
		    		search2.setStatement(sqlstr2.toString());
		            listRowSet2 = search2.execute();
		            if(listRowSet2.size() != 0){
		            	rowObject2 = RowSetUtility.getValueObject(listRowSet2.getRow(0));
		            	DEM_ID_CNT = rowObject2.get("DEM_ID_CNT");
		            }
		        }catch(Exception e){
					e.printStackTrace();
		        }
		            
		        if (DIV_PO_YN.equals("N") || (DIV_PO_YN.equals("Y") && DEM_ID_CNT.equals("1")) ) {
					upDemandidProc(super.conn.getConnection(), params);  //계획분할(DIV_PO_YN = 'N') 계약이거나, 단가계약(DIV_PO_YN = 'Y')이지만 동일한 DEM_ID의 계약서 정보가 1개만 남았을 경우 삭제	2021.06.01
				}
			}
			delContPayplan(super.conn.getConnection(), params);		//대금계획삭제  2015.12.18
			
			delContInfo(super.conn.getConnection(), params);		//계약 정보 저장
			//WAFLogger.debug("계약정보 삭제");

			return true;
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> deleteContProc() : " + e.getMessage());
            WAFLogger.error(e);

            conn.setRollback();
            
            this.storage.setSuccess(false);  
            this.storage.setMessage(e.getMessage());            
            storage.setDetailMessage(e);
            return false;
        }
        finally {
        	super.conn.end();
        }        
    }	
	
	/**
     * 계약 업체 삭제
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void delContCorpData(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("DELETE FROM  CONT_PUR_SUPP						\n");
        	sqlstr.append("WHERE PUR_CONT_MOD_ID = ?						\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("PUR_CONT_MOD_ID"));
            persistent.execute();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }	
	/**
     * 계약 정보 삭제
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void delContInfo(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("DELETE FROM  PUR2000T						\n");
        	sqlstr.append("WHERE PUR_CONT_MOD_ID = ?						\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("PUR_CONT_MOD_ID"));
            persistent.execute();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }	
	
	/**
     * 계약 대금계획 삭제  2015.12.18
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void delContPayplan(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("DELETE FROM  CONT_PUR_PAYPLAN						\n");
        	sqlstr.append("WHERE PUR_CONT_MOD_ID = ?						\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("PUR_CONT_MOD_ID"));
            persistent.execute();
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }	
	
	/**
     * 계약 정보 내역 삭제
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public void delContItem(Connection connection, ValueObject valueObject) throws Exception {

        Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("DELETE FROM  CONT_PUR_ITEM						\n");
        	sqlstr.append("WHERE PUR_CONT_MOD_ID = ?						\n");
            persistent.setStatement(sqlstr.toString());
            persistent.addParameter(valueObject.get("PUR_CONT_MOD_ID"));
            persistent.execute();
        }
        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 {
        	// 2019.11.28 전자조달에서 변경계약 생성 후 변경계약 삭제 시 원발주내역이 삭제되는 문제가 발생하여 우선 백업테이블로 이관 추가 Start
        	sqlstr.append("INSERT INTO PMM_DEMANDED_REQUEST_DEL \n");
        	sqlstr.append("   (DEMANDED_ID, DEMANDED_NO, REV, DEMANDED_DATE, DEMANDED_TITLE,  \n");
        	sqlstr.append("    DEMANDED_KIND, DEPT_CD, CURRENCY_GB, EMP_NO, DELIVERY_CONDITION,  \n");
        	sqlstr.append("    APP_DATE, APP_NO, PAY_ITEM, COST_CODE, COST_TYPE,  \n");
        	sqlstr.append("    RECEIPT_DATE, SITEDESC_FLAG, SITEDESCCHRGPRSNID, SITEDESCTELNO, SITEDESCDATE,  \n");
        	sqlstr.append("    SITEDESCPLACE, SITEDESCEMAIL, PUREMPNO, INNER_REMARKS, TBE_FLAG,  \n");
        	sqlstr.append("    TBE_DATE, OUTER_REMARKS, REQUEST_DATE, DOC_MR_IN, DOC_FIELD_MANUAL_IN,  \n");
        	sqlstr.append("    DOC_ETC_IN, DOC_MR_OUT, DOC_FIELD_MANUAL_OUT, DOC_ETC_OUT, FILE_GB_IN,  \n");
        	sqlstr.append("    FILE_GB_OUT, CONT_AMT, ACT_AMT, ACT_RATE, ONBID_YN,  \n");
        	sqlstr.append("    DELI_START_DT, DELI_END_DT, DELI_END_PLACE, RTN_REASON, RTN_DATE,  \n");
        	sqlstr.append("    RTN_EMPNO, RTN_EMPNM, RECEIPT_NO, OUT_ITEM_CD, DEMANDED_STATUS,  \n");
        	sqlstr.append("    EBID_STATUS_CD, PR_TYPE, PAY_DIV, CRE_BY, CRE_DATE,  \n");
        	sqlstr.append("    UPD_BY, UPD_DATE, ERP_NO_CORD, ERP_SIGN_DOC_ID, ERP_SIGN_YEAR,  \n");
        	sqlstr.append("    ERP_YM_REQU, ERP_NO_REQU, MOD_GB, BEF_BUG_AMT, AFT_BUG_AMT,  \n");
        	sqlstr.append("    BEF_CONT_DATE, AFT_CONT_DATE, BEF_ETC, AFT_ETC, P_REMARK,  \n");
        	sqlstr.append("    S_REMARK, PUR_CONT_MOD_ID) \n");
        	sqlstr.append("SELECT DEMANDED_ID, DEMANDED_NO, REV, DEMANDED_DATE, DEMANDED_TITLE,  \n");
        	sqlstr.append("    DEMANDED_KIND, DEPT_CD, CURRENCY_GB, EMP_NO, DELIVERY_CONDITION,  \n");
        	sqlstr.append("    APP_DATE, APP_NO, PAY_ITEM, COST_CODE, COST_TYPE,  \n");
        	sqlstr.append("    RECEIPT_DATE, SITEDESC_FLAG, SITEDESCCHRGPRSNID, SITEDESCTELNO, SITEDESCDATE,  \n");
        	sqlstr.append("    SITEDESCPLACE, SITEDESCEMAIL, PUREMPNO, INNER_REMARKS, TBE_FLAG,  \n");
        	sqlstr.append("    TBE_DATE, OUTER_REMARKS, REQUEST_DATE, DOC_MR_IN, DOC_FIELD_MANUAL_IN,  \n");
        	sqlstr.append("    DOC_ETC_IN, DOC_MR_OUT, DOC_FIELD_MANUAL_OUT, DOC_ETC_OUT, FILE_GB_IN,  \n");
        	sqlstr.append("    FILE_GB_OUT, CONT_AMT, ACT_AMT, ACT_RATE, ONBID_YN,  \n");
        	sqlstr.append("    DELI_START_DT, DELI_END_DT, DELI_END_PLACE, RTN_REASON, RTN_DATE,  \n");
        	sqlstr.append("    RTN_EMPNO, RTN_EMPNM, RECEIPT_NO, OUT_ITEM_CD, DEMANDED_STATUS,  \n");
        	sqlstr.append("    EBID_STATUS_CD, PR_TYPE, PAY_DIV, CRE_BY, CRE_DATE,  \n");
        	sqlstr.append("    UPD_BY, UPD_DATE, ERP_NO_CORD, ERP_SIGN_DOC_ID, ERP_SIGN_YEAR,  \n");
        	sqlstr.append("    ERP_YM_REQU, ERP_NO_REQU, MOD_GB, BEF_BUG_AMT, AFT_BUG_AMT,  \n");
        	sqlstr.append("    BEF_CONT_DATE, AFT_CONT_DATE, BEF_ETC, AFT_ETC, P_REMARK,  \n");
        	sqlstr.append("    S_REMARK, PUR_CONT_MOD_ID \n");
        	sqlstr.append("  FROM PMM_DEMANDED_REQUEST \n");
        	sqlstr.append(" WHERE DEMANDED_ID = ? \n");
            persistent.setStatement(sqlstr.toString());  
            persistent.addParameter(valueObject.get("pDemID"));
            persistent.execute();
            persistent.clearParameters();
            sqlstr.reset();

            sqlstr.append("INSERT INTO PMM_DEMANDED_ITEM_DEL \n");
            sqlstr.append("   (ITEM_SEQ, DEMANDED_ID, MATERIAL_CD, REQUEST_DATE, DEMANDED_QTY,  \n");
            sqlstr.append("    CONT_PRI, DEMANDED_PRI, DEMANDED_AMT, SHIPPING_QTY, FINISH_FLAG,  \n");
            sqlstr.append("    PO_NO, YM_REQU, NO_REQU, SQ_REQU) \n");
            sqlstr.append("SELECT ITEM_SEQ, DEMANDED_ID, MATERIAL_CD, REQUEST_DATE, DEMANDED_QTY,  \n");
            sqlstr.append("    CONT_PRI, DEMANDED_PRI, DEMANDED_AMT, SHIPPING_QTY, FINISH_FLAG,  \n");
            sqlstr.append("    PO_NO, YM_REQU, NO_REQU, SQ_REQU \n");
            sqlstr.append("  FROM PMM_DEMANDED_ITEM \n");
            sqlstr.append(" WHERE DEMANDED_ID = ?   \n");
            persistent.setStatement(sqlstr.toString());  
            persistent.addParameter(valueObject.get("pDemID"));
            persistent.execute();
            persistent.clearParameters();
            sqlstr.reset();

            sqlstr.append("INSERT INTO PMM_DEMANDED_ITEM_CONST_DEL \n");
            sqlstr.append("   (ITEM_SEQ, DEMANDED_ID, MATERIAL_CD, SQ_CSTR, CD_CSTR,  \n");
            sqlstr.append("    DL_CSTR, NM_CSTR, SIZE_CSTR, UNIT_CSTR, CRE_BY,  \n");
            sqlstr.append("    CRE_DATE) \n");
            sqlstr.append("SELECT ITEM_SEQ, DEMANDED_ID, MATERIAL_CD, SQ_CSTR, CD_CSTR,  \n");
            sqlstr.append("    DL_CSTR, NM_CSTR, SIZE_CSTR, UNIT_CSTR, CRE_BY,  \n");
            sqlstr.append("    CRE_DATE \n");
            sqlstr.append("  FROM PMM_DEMANDED_ITEM_CONST \n");
            sqlstr.append(" WHERE DEMANDED_ID = ? \n");
            persistent.setStatement(sqlstr.toString());  
            persistent.addParameter(valueObject.get("pDemID"));
            persistent.execute();
            persistent.clearParameters();
            sqlstr.reset();

            sqlstr.append("INSERT INTO PMM_COPR_DEL \n");
            sqlstr.append("   (DEMANDED_ID, VENDOR_SEQ, VENDOR_CD, VENDOR_NAME, PRE_NM,  \n");
            sqlstr.append("    RECOMMEND_REASON, CHARGE_NAME, CHARGE_TEL, CHARGE_EMAIL, VENDOR_ID,  \n");
            sqlstr.append("    CRE_BY, CRE_DATE, UPD_BY, UPD_DATE, ERP_CD_PARTNER) \n");
            sqlstr.append(" SELECT DEMANDED_ID, VENDOR_SEQ, VENDOR_CD, VENDOR_NAME, PRE_NM,  \n");
            sqlstr.append("    RECOMMEND_REASON, CHARGE_NAME, CHARGE_TEL, CHARGE_EMAIL, VENDOR_ID,  \n");
            sqlstr.append("    CRE_BY, CRE_DATE, UPD_BY, UPD_DATE, ERP_CD_PARTNER \n");
            sqlstr.append("   FROM PMM_COPR \n");
            sqlstr.append("  WHERE DEMANDED_ID = ? \n");
            persistent.setStatement(sqlstr.toString());  
            persistent.addParameter(valueObject.get("pDemID"));
            persistent.execute();
            persistent.clearParameters();
            sqlstr.reset();
            // 2019.11.28 전자조달에서 변경계약 생성 후 변경계약 삭제 시 원발주내역이 삭제되는 문제가 발생하여 우선 백업테이블로 이관 추가 End
            
        	sqlstr.append("DELETE FROM PMM_DEMANDED_REQUEST  	\n");
        	sqlstr.append("WHERE DEMANDED_ID = ?						\n");
            persistent.setStatement(sqlstr.toString());  
            persistent.addParameter(valueObject.get("pDemID"));
            persistent.execute();
            persistent.clearParameters();
            sqlstr.reset();           
            
            sqlstr.append("DELETE FROM PMM_DEMANDED_ITEM  	\n");
            sqlstr.append("WHERE DEMANDED_ID = ?						\n");
            persistent.setStatement(sqlstr.toString());  
            persistent.addParameter(valueObject.get("pDemID"));
            persistent.execute();
            persistent.clearParameters();
            sqlstr.reset();
            
            sqlstr.append("DELETE FROM PMM_DEMANDED_ITEM_CONST  	\n");
            sqlstr.append("WHERE DEMANDED_ID = ?						\n");
            persistent.setStatement(sqlstr.toString());  
            persistent.addParameter(valueObject.get("pDemID"));
            persistent.execute();
            persistent.clearParameters();
            sqlstr.reset();

            sqlstr.append("DELETE FROM PMM_COPR  	\n");
            sqlstr.append("WHERE DEMANDED_ID = ?						\n");
            persistent.setStatement(sqlstr.toString());  
            persistent.addParameter(valueObject.get("pDemID"));
            persistent.execute();
            persistent.clearParameters();
            sqlstr.reset();
            
            sqlstr.append("DELETE FROM ETEC_ERPIF.PMM_DEMANDED_REQUEST	\n");
            sqlstr.append("WHERE DEMANDED_ID = ?						\n");
            persistent.setStatement(sqlstr.toString());  
            persistent.addParameter(valueObject.get("pDemID"));
            persistent.execute();
            persistent.clearParameters();
            sqlstr.reset();
            
            sqlstr.append("DELETE FROM ETEC_ERPIF.PMM_DEMANDED_ITEM  	\n");
            sqlstr.append("WHERE DEMANDED_ID = ?						\n");
            persistent.setStatement(sqlstr.toString());  
            persistent.addParameter(valueObject.get("pDemID"));
            persistent.execute();
            persistent.clearParameters();
            sqlstr.reset();
            
            sqlstr.append("DELETE FROM ETEC_ERPIF.PMM_DEMANDED_ITEM_CONST  	\n");
            sqlstr.append("WHERE DEMANDED_ID = ?						\n");
            persistent.setStatement(sqlstr.toString());  
            persistent.addParameter(valueObject.get("pDemID"));
            persistent.execute();
            persistent.clearParameters();
            sqlstr.reset();
			
            sqlstr.append("DELETE FROM ETEC_ERPIF.PMM_COPR  	\n");
            sqlstr.append("WHERE DEMANDED_ID = ?						\n");
            persistent.setStatement(sqlstr.toString());  
            persistent.addParameter(valueObject.get("pDemID"));
            persistent.execute();
            persistent.clearParameters();
            sqlstr.reset();
            
        	sqlstr.append("UPDATE ETECEPC.MR_REQ_PO SET  	\n");
        	sqlstr.append(" EBID_STATUS = '01'					\n");
        	sqlstr.append("WHERE BUYREQNO = ?						\n");
            persistent.setStatement(sqlstr.toString());  
            persistent.addParameter(valueObject.get("pDemID"));
            persistent.execute();

            InterfacePurERPiU.updateChangeContReject(valueObject.get("pDemID"), storage.getUser().get("USER_SABUN"), storage.getUser().get("USER_NAME"));
            
            return true;
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }	
	
    /**
     * 이전 계약번호 조회
	 * @param 
	 * @param 
	 * @return ValueObject
	 */
	public String getOldContNum(ValueObject valueObject){

        Search search = new SearchImpl();
        RowSet listRowSet = null;
        StrBuffer sqlstr = new StrBuffer();
        ValueObject rowObject = null;
        String OldContModId = "";
        Integer old_mod_no = Integer.parseInt(valueObject.get("MOD_NO"))-1;
        
        try {
        	sqlstr.append(" 	SELECT PUR_CONT_MOD_ID	\n");
        	sqlstr.append(" 	  FROM PUR2000T A	\n");
        	sqlstr.append("   WHERE 1=1								\n");
    		sqlstr.append("   	AND A.PUR_CONT_ID = '"+ valueObject.get("PUR_CONT_ID") +"'			\n");
    		sqlstr.append("   	AND A.MOD_NO = '"+ old_mod_no +"'\n");
             
    		search.setStatement(sqlstr.toString());
            listRowSet = search.execute();
            if(listRowSet.size() != 0){
            	rowObject = RowSetUtility.getValueObject(listRowSet.getRow(0));
            	OldContModId = rowObject.get("PUR_CONT_MOD_ID");
            }
            
		}catch(Exception e){
			e.printStackTrace();
		}finally{

			return OldContModId;
		}
	}	
	
	public void deleteContFile(ValueObject params) throws Exception {
		CallableStatement cs 	= null;
		String pssql			= "";
		
		try {
			conn.begin();
			
			pssql = "{call SP_DELETE_PUR_CONT(?,?,?)}";
			
			cs = conn.getConnection().prepareCall(pssql);
			cs.setString(1, params.get("PUR_CONT_MOD_ID"));
    		cs.registerOutParameter(2, java.sql.Types.VARCHAR);
    		cs.registerOutParameter(3, java.sql.Types.VARCHAR);
			cs.execute();
			
			storage.setSuccess(true);
		}catch(Exception e) {
			WAFLogger.error(e);
			storage.setSuccess(false);
			storage.setMessage(e.getMessage());
			throw e;
		}finally{
			try { 
				if (cs != null){ cs.close();}
			}catch (Exception ex_close) {
				WAFLogger.error(ex_close);
			}   
			conn.end();
		}
	}
	
	//구매 변경계약대상->접수로 이동 
	public boolean deleteContChgProc(Connection connection, ValueObject valueObject) throws Exception {
		Persistent persistent = new PersistentImpl(connection);
        StrBuffer sqlstr = new StrBuffer();
        try {

        	sqlstr.append("		UPDATE PUR2000T  				    \n");
        	sqlstr.append("		   SET STATUS_CD = '00'				\n");
        	sqlstr.append("		      ,UPD_DATE  = SYSDATE			\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 Params
	 * @return
	 */
	private RowSet getChgItemList(ValueObject param) {

		Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        
        StrBuffer sql = new StrBuffer();
        try{
        	sql.append(" 	SELECT MATERIAL_CD -- 자재코드 		\n");
        	sql.append(" 	     , ITEM_NAME -- 품명 		\n");
        	sql.append(" 	     , ITEM_SPEC -- 규격 		\n");
        	sql.append(" 	     , ITEM_UNIT -- 단위 		\n");
        	sql.append(" 	     , ITEM_QTY -- 수량(변경전 계약) 		\n");
        	sql.append(" 	     , ITEM_PRICE -- 단가(변경전 계약) 		\n");
        	sql.append(" 	     , ITEM_AMT -- 금액(변경전 계약) 		\n");
        	sql.append(" 	     , CONT_QTY -- 수량(변경후 계약)  		\n");
        	sql.append(" 	     , CONT_PRICE -- 단가(변경후 계약)  		\n");
        	sql.append(" 	     , DECODE(CONT_AMT,0,CONT_QTY*CONT_PRICE,CONT_AMT) CONT_AMT -- 금액(변경후 계약)  		\n");
        	sql.append(" 	     , DEMANDED_QTY --  발주의뢰 수량 		\n");
        	sql.append(" 	     , DEMANDED_PRI -- 발주의뢰 단가 		\n");
        	sql.append(" 	     , DECODE(DEMANDED_AMT,0,DEMANDED_QTY*DEMANDED_PRI,DEMANDED_AMT) DEMANDED_AMT -- 발주의뢰 금액 		\n");
        	sql.append(" 	     , STOCK_QTY		\n");
        	sql.append(" 	     , CHG_MOD_CD 		\n");
        	sql.append(" 	  FROM 		\n");
        	sql.append(" 	       (SELECT NVL (B1.MATERIAL_CD, A1.MATERIAL_CD) MATERIAL_CD -- 자재코드 		\n");
        	sql.append(" 	            , NVL (B1.ITEM_NAME, (SELECT MATERIAL_NAME FROM PMM_COMM_MATERIAL_MASTER WHERE MATERIAL_CD=A1.MATERIAL_CD)) ITEM_NAME -- 품명 		\n");
        	sql.append(" 	            , NVL (B1.ITEM_SPEC, (SELECT MATERIAL_SPEC FROM PMM_COMM_MATERIAL_MASTER WHERE MATERIAL_CD=A1.MATERIAL_CD)) ITEM_SPEC -- 규격 		\n");
        	sql.append(" 	            , NVL (F_GET_CODE_NAME('UNIT_KIND',B1.ITEM_UNIT), (SELECT UNIT_KIND FROM PMM_COMM_MATERIAL_MASTER WHERE MATERIAL_CD=A1.MATERIAL_CD)) ITEM_UNIT -- 단위 		\n");
        	sql.append(" 	            , NVL (B1.ITEM_QTY, 0) ITEM_QTY -- 수량(변경전 계약) 		\n");
        	sql.append(" 	            , B1.ITEM_PRICE -- 단가(변경전 계약) 		\n");
        	sql.append(" 	            , NVL (B1.ITEM_QTY, 0)*B1.ITEM_PRICE ITEM_AMT -- 금액(변경전 계약) 		\n");
        	
        	sql.append(" 	            , NVL (D1.ITEM_QTY, 0) CONT_QTY -- 수량(변경후 계약) 		\n");
        	sql.append(" 	            , CASE 		\n");
        	sql.append(" 	                  WHEN D1.ITEM_PRICE = NULL 		\n");
        	sql.append(" 	                  THEN B1.ITEM_PRICE 		\n");
        	sql.append(" 	                  ELSE D1.ITEM_PRICE 		\n");
        	sql.append(" 	             END CONT_PRICE -- 단가(변경후 계약) 		\n");
        	sql.append(" 	            , NVL(D1.ITEM_AMT,0) CONT_AMT -- 발주의뢰 금액 		\n");
     	
        	sql.append(" 	            , NVL (A1.DEMANDED_QTY, 0) DEMANDED_QTY --  발주의뢰 수량 		\n");
        	sql.append(" 	            , CASE 		\n");
        	sql.append(" 	                  WHEN NVL (A1.DEMANDED_PRI, 0)=0 		\n");
        	sql.append(" 	                  THEN B1.ITEM_PRICE 		\n");
        	sql.append(" 	                  ELSE A1.DEMANDED_PRI 		\n");
        	sql.append(" 	              END DEMANDED_PRI -- 발주의뢰 단가 		\n");
        	sql.append(" 	            , NVL(A1.DEMANDED_AMT,0) DEMANDED_AMT -- 발주의뢰 금액 		\n");
        	sql.append(" 	            , NVL (C1.STOCK_QTY, 0) STOCK_QTY		\n");
        	sql.append(" 	            , CASE 		\n");
        	sql.append(" 	                  WHEN B1.MATERIAL_CD IS NOT NULL 		\n");
        	sql.append(" 	                      AND A1.MATERIAL_CD IS NOT NULL 		\n");
        	sql.append(" 	                  THEN 'MODIFY' 		\n");
        	sql.append(" 	                  WHEN B1.MATERIAL_CD IS NULL 		\n");
        	sql.append(" 	                      AND A1.MATERIAL_CD IS NOT NULL 		\n");
        	sql.append(" 	                  THEN 'NEW' 		\n");
        	sql.append(" 	                  WHEN B1.MATERIAL_CD IS NOT NULL 		\n");
        	sql.append(" 	                      AND A1.MATERIAL_CD IS NULL 		\n");
        	sql.append(" 	                  THEN 'DELETE' 		\n");
        	sql.append(" 	              END CHG_MOD_CD 		\n");
        	sql.append(" 	         FROM 		\n");
        	sql.append(" 	              (SELECT* 		\n");
        	sql.append(" 	                FROM PMM_DEMANDED_ITEM 		\n");
        	sql.append(" 	               WHERE DEMANDED_ID= "+ params.get("pDemID") +" 		\n");
        	sql.append(" 	                     AND DEMANDED_QTY>0		\n");
        	sql.append(" 	              ) A1 		\n");
        	sql.append(" 	          FULL OUTER JOIN 		\n");
        	sql.append(" 	              (SELECT *  FROM CONT_PUR_ITEM WHERE PUR_CONT_MOD_ID=(SELECT MAX(PUR_CONT_MOD_ID) FROM PUR2000T WHERE PUR_CONT_ID="+ params.get("PUR_CONT_ID") +" AND PUR_CONT_MOD_ID !="+ params.get("PUR_CONT_MOD_ID") +")		\n");
        	sql.append(" 	              ) B1 		\n");
        	sql.append(" 	              ON A1.MATERIAL_CD=B1.MATERIAL_CD 		\n");
        	sql.append(" 	          FULL OUTER JOIN 		\n");
        	sql.append(" 	              (SELECT *  FROM CONT_PUR_ITEM WHERE PUR_CONT_MOD_ID="+ params.get("PUR_CONT_MOD_ID") +"		\n");
        	sql.append(" 	              ) D1 		\n");
        	sql.append(" 	              ON NVL(A1.MATERIAL_CD, B1.MATERIAL_CD)=D1.MATERIAL_CD 		\n");
        	sql.append(" 	          LEFT OUTER JOIN 		\n");
        	sql.append(" 	              (SELECT PUR_CONT_MOD_ID, MATERIAL_CD, CEIL (SUM (STOCK_QTY)) STOCK_QTY 		\n");
        	sql.append(" 	                FROM 		\n");
        	sql.append(" 	                     (SELECT T3.PUR_CONT_MOD_ID, T2.ITEM_NO MATERIAL_CD , T2.SHIP_QTY STOCK_QTY 		\n");
        	sql.append(" 	                          FROM ETECEPC.FM_SHIPPING_LIST T1		\n");
        	sql.append(" 	                             , ETECEPC.FM_SHIPPING_DETAIL T2		\n");
        	sql.append(" 	                             , ETEC_EBID.PUR2000T T3 		\n");
        	sql.append(" 	                          WHERE T1.SHIPPING_LIST_ID= T2.SHIPPING_LIST_ID 		\n");
        	sql.append(" 	                            AND T1.ORDER_NO= T3.ORD_DOC_NO 		\n");
        	sql.append(" 	                     UNION ALL 		\n");
        	sql.append(" 	                     SELECT T3.PUR_CONT_MOD_ID, T1.MATERIAL_CD, T1.ITEM_QTY  		\n"); 
        	sql.append(" 	                          FROM PMM_PAYREQ_ITEM T1		\n");
        	sql.append(" 	                             , PUR1100T T2		\n");
        	sql.append(" 	                             , PUR2000T T3 		\n");
        	sql.append(" 	                          WHERE T1.PAYREQ_ID=T2.PAYREQ_ID 		\n");
        	sql.append(" 	                            AND T2.PUR_CONT_mod_ID= T3.PUR_CONT_mod_ID		\n");
        	sql.append(" 	                     ) 		\n");
        	sql.append(" 	               WHERE PUR_CONT_MOD_ID = "+ params.get("PUR_CONT_MOD_ID") +" 		\n");
        	sql.append(" 	               GROUP BY PUR_CONT_MOD_ID, MATERIAL_CD		\n");
        	sql.append(" 	              ) C1 		\n");
        	sql.append(" 	              ON A1.MATERIAL_CD=C1.MATERIAL_CD		\n");
        	sql.append(" 	       )		\n");

            
            search.setStatement(sql.toString());
            WAFLogger.debug(sql.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;
	}	
	

}